summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/arm/arm_api.c508
-rw-r--r--src/arm/do_start_process.c79
-rw-r--r--src/arm/gnunet-arm.c294
-rw-r--r--src/arm/gnunet-service-arm.c744
-rw-r--r--src/arm/gnunet-service-arm.h5
-rw-r--r--src/arm/gnunet-service-arm_interceptor.c1055
-rw-r--r--src/arm/mockup-service.c30
-rw-r--r--src/arm/test_arm_api.c44
-rw-r--r--src/arm/test_exponential_backoff.c292
-rw-r--r--src/arm/test_gnunet_service_manager.c123
-rw-r--r--src/ats/ats_api.c371
-rw-r--r--src/block/block.c132
-rw-r--r--src/block/plugin_block_dht.c83
-rw-r--r--src/block/plugin_block_dns.c105
-rw-r--r--src/block/plugin_block_fs.c408
-rw-r--r--src/block/plugin_block_template.c35
-rw-r--r--src/block/plugin_block_test.c61
-rw-r--r--src/block/test_block.c34
-rw-r--r--src/chat/chat.c564
-rw-r--r--src/chat/gnunet-chat.c354
-rw-r--r--src/chat/gnunet-service-chat.c1196
-rw-r--r--src/chat/test_chat.c331
-rw-r--r--src/chat/test_chat_private.c308
-rw-r--r--src/core/core_api.c1640
-rw-r--r--src/core/core_api_iterate_peers.c135
-rw-r--r--src/core/gnunet-core-list-connections.c84
-rw-r--r--src/core/gnunet-service-core.c3685
-rw-r--r--src/core/test_core_api.c205
-rw-r--r--src/core/test_core_api_preferences.c328
-rw-r--r--src/core/test_core_api_reliability.c339
-rw-r--r--src/core/test_core_api_send_to_self.c123
-rw-r--r--src/core/test_core_api_start_only.c107
-rw-r--r--src/core/test_core_quota_compliance.c551
-rw-r--r--src/datacache/datacache.c174
-rw-r--r--src/datacache/perf_datacache.c119
-rw-r--r--src/datacache/plugin_datacache_mysql.c769
-rw-r--r--src/datacache/plugin_datacache_postgres.c416
-rw-r--r--src/datacache/plugin_datacache_sqlite.c449
-rw-r--r--src/datacache/plugin_datacache_template.c28
-rw-r--r--src/datacache/test_datacache.c98
-rw-r--r--src/datacache/test_datacache_quota.c84
-rw-r--r--src/datastore/datastore.h4
-rw-r--r--src/datastore/datastore_api.c1150
-rw-r--r--src/datastore/gnunet-service-datastore.c1289
-rw-r--r--src/datastore/perf_datastore_api.c340
-rw-r--r--src/datastore/perf_plugin_datastore.c467
-rw-r--r--src/datastore/plugin_datastore_mysql.c1070
-rw-r--r--src/datastore/plugin_datastore_postgres.c791
-rw-r--r--src/datastore/plugin_datastore_sqlite.c1072
-rw-r--r--src/datastore/plugin_datastore_template.c51
-rw-r--r--src/datastore/test_datastore_api.c718
-rw-r--r--src/datastore/test_datastore_api_management.c309
-rw-r--r--src/datastore/test_plugin_datastore.c324
-rw-r--r--src/dht/dht.h4
-rw-r--r--src/dht/dht_api.c534
-rw-r--r--src/dht/dht_api_find_peer.c56
-rw-r--r--src/dht/dht_api_get_put.c163
-rw-r--r--src/dht/dhtlog.c37
-rw-r--r--src/dht/dhtlog.h46
-rw-r--r--src/dht/gnunet-dht-driver.c3415
-rw-r--r--src/dht/gnunet-dht-get-peer.c88
-rw-r--r--src/dht/gnunet-dht-get.c74
-rw-r--r--src/dht/gnunet-dht-put.c50
-rw-r--r--src/dht/gnunet-service-dht.c3691
-rw-r--r--src/dht/plugin_dhtlog_dummy.c59
-rw-r--r--src/dht/plugin_dhtlog_mysql.c1071
-rw-r--r--src/dht/plugin_dhtlog_mysql_dump.c383
-rw-r--r--src/dht/plugin_dhtlog_mysql_dump_load.c638
-rw-r--r--src/dht/test_dht_api.c254
-rw-r--r--src/dht/test_dht_multipeer.c785
-rw-r--r--src/dht/test_dht_twopeer.c331
-rw-r--r--src/dht/test_dht_twopeer_path_tracking.c348
-rw-r--r--src/dht/test_dht_twopeer_put_get.c419
-rw-r--r--src/dht/test_dhtlog.c147
-rw-r--r--src/dv/dv.h15
-rw-r--r--src/dv/dv_api.c347
-rw-r--r--src/dv/gnunet-service-dv.c2271
-rw-r--r--src/dv/plugin_transport_dv.c157
-rw-r--r--src/dv/test_transport_api_dv.c1154
-rw-r--r--src/fragmentation/defragmentation.c313
-rw-r--r--src/fragmentation/fragmentation.c209
-rw-r--r--src/fragmentation/test_fragmentation.c170
-rw-r--r--src/fs/fs.c2804
-rw-r--r--src/fs/fs.h272
-rw-r--r--src/fs/fs_directory.c551
-rw-r--r--src/fs/fs_download.c2467
-rw-r--r--src/fs/fs_file_information.c503
-rw-r--r--src/fs/fs_getopt.c204
-rw-r--r--src/fs/fs_list_indexed.c146
-rw-r--r--src/fs/fs_misc.c99
-rw-r--r--src/fs/fs_namespace.c1063
-rw-r--r--src/fs/fs_publish.c1552
-rw-r--r--src/fs/fs_search.c1159
-rw-r--r--src/fs/fs_test_lib.c580
-rw-r--r--src/fs/fs_test_lib.h63
-rw-r--r--src/fs/fs_tree.c247
-rw-r--r--src/fs/fs_tree.h70
-rw-r--r--src/fs/fs_unindex.c437
-rw-r--r--src/fs/fs_uri.c1357
-rw-r--r--src/fs/gnunet-directory.c125
-rw-r--r--src/fs/gnunet-download.c235
-rw-r--r--src/fs/gnunet-pseudonym.c267
-rw-r--r--src/fs/gnunet-publish.c655
-rw-r--r--src/fs/gnunet-search.c269
-rw-r--r--src/fs/gnunet-service-fs.c255
-rw-r--r--src/fs/gnunet-service-fs.h6
-rw-r--r--src/fs/gnunet-service-fs_cp.c1373
-rw-r--r--src/fs/gnunet-service-fs_cp.h112
-rw-r--r--src/fs/gnunet-service-fs_indexing.c659
-rw-r--r--src/fs/gnunet-service-fs_indexing.h35
-rw-r--r--src/fs/gnunet-service-fs_lc.c306
-rw-r--r--src/fs/gnunet-service-fs_lc.h18
-rw-r--r--src/fs/gnunet-service-fs_pe.c374
-rw-r--r--src/fs/gnunet-service-fs_pe.h15
-rw-r--r--src/fs/gnunet-service-fs_pr.c1486
-rw-r--r--src/fs/gnunet-service-fs_pr.h141
-rw-r--r--src/fs/gnunet-service-fs_push.c385
-rw-r--r--src/fs/gnunet-service-fs_push.h12
-rw-r--r--src/fs/gnunet-service-fs_put.c149
-rw-r--r--src/fs/gnunet-service-fs_put.h6
-rw-r--r--src/fs/gnunet-unindex.c137
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p.c284
-rw-r--r--src/fs/perf_gnunet_service_fs_p2p_trust.c347
-rw-r--r--src/fs/test_fs.c140
-rw-r--r--src/fs/test_fs_directory.c165
-rw-r--r--src/fs/test_fs_download.c335
-rw-r--r--src/fs/test_fs_download_indexed.c355
-rw-r--r--src/fs/test_fs_download_persistence.c408
-rw-r--r--src/fs/test_fs_download_recursive.c311
-rw-r--r--src/fs/test_fs_file_information.c138
-rw-r--r--src/fs/test_fs_getopt.c8
-rw-r--r--src/fs/test_fs_list_indexed.c280
-rw-r--r--src/fs/test_fs_namespace.c384
-rw-r--r--src/fs/test_fs_namespace_list_updateable.c142
-rw-r--r--src/fs/test_fs_publish.c274
-rw-r--r--src/fs/test_fs_publish_persistence.c324
-rw-r--r--src/fs/test_fs_search.c234
-rw-r--r--src/fs/test_fs_search_persistence.c300
-rw-r--r--src/fs/test_fs_search_ranking.c153
-rw-r--r--src/fs/test_fs_start_stop.c55
-rw-r--r--src/fs/test_fs_test_lib.c120
-rw-r--r--src/fs/test_fs_unindex.c265
-rw-r--r--src/fs/test_fs_unindex_persistence.c347
-rw-r--r--src/fs/test_fs_uri.c308
-rw-r--r--src/fs/test_gnunet_service_fs_migration.c178
-rw-r--r--src/fs/test_gnunet_service_fs_p2p.c128
-rw-r--r--src/hello/hello.c243
-rw-r--r--src/hello/test_hello.c8
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c177
-rw-r--r--src/hostlist/hostlist-client.c1377
-rw-r--r--src/hostlist/hostlist-client.h12
-rw-r--r--src/hostlist/hostlist-server.c570
-rw-r--r--src/hostlist/hostlist-server.h11
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.c84
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_learning.c485
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c96
-rw-r--r--src/include/gettext.h22
-rw-r--r--src/include/gnunet_arm_service.h15
-rw-r--r--src/include/gnunet_ats_service.h105
-rw-r--r--src/include/gnunet_bandwidth_lib.h43
-rw-r--r--src/include/gnunet_bio_lib.h74
-rw-r--r--src/include/gnunet_block_lib.h81
-rw-r--r--src/include/gnunet_block_plugin.h28
-rw-r--r--src/include/gnunet_chat_service.h104
-rw-r--r--src/include/gnunet_client_lib.h35
-rw-r--r--src/include/gnunet_common.h31
-rw-r--r--src/include/gnunet_configuration_lib.h95
-rw-r--r--src/include/gnunet_connection_lib.h105
-rw-r--r--src/include/gnunet_container_lib.h326
-rw-r--r--src/include/gnunet_core_service.h185
-rw-r--r--src/include/gnunet_crypto_lib.h166
-rw-r--r--src/include/gnunet_datacache_lib.h38
-rw-r--r--src/include/gnunet_datacache_plugin.h34
-rw-r--r--src/include/gnunet_datastore_plugin.h63
-rw-r--r--src/include/gnunet_datastore_service.h254
-rw-r--r--src/include/gnunet_dht_service.h163
-rw-r--r--src/include/gnunet_disk_lib.h187
-rw-r--r--src/include/gnunet_dv_service.h3
-rw-r--r--src/include/gnunet_fragmentation_lib.h58
-rw-r--r--src/include/gnunet_fs_service.h1161
-rw-r--r--src/include/gnunet_getopt_lib.h10
-rw-r--r--src/include/gnunet_hello_lib.h39
-rw-r--r--src/include/gnunet_load_lib.h16
-rw-r--r--src/include/gnunet_mesh_service.h182
-rw-r--r--src/include/gnunet_mesh_service_new.h111
-rw-r--r--src/include/gnunet_nat_lib.h90
-rw-r--r--src/include/gnunet_network_lib.h27
-rw-r--r--src/include/gnunet_nse_service.h13
-rw-r--r--src/include/gnunet_os_lib.h57
-rw-r--r--src/include/gnunet_peer_lib.h8
-rw-r--r--src/include/gnunet_peerinfo_service.h53
-rw-r--r--src/include/gnunet_pseudonym_lib.h8
-rw-r--r--src/include/gnunet_resolver_service.h64
-rw-r--r--src/include/gnunet_scheduler_lib.h56
-rw-r--r--src/include/gnunet_server_lib.h122
-rw-r--r--src/include/gnunet_service_lib.h26
-rw-r--r--src/include/gnunet_statistics_service.h45
-rw-r--r--src/include/gnunet_strings_lib.h3
-rw-r--r--src/include/gnunet_testing_lib.h254
-rw-r--r--src/include/gnunet_time_lib.h70
-rw-r--r--src/include/gnunet_transport_plugin.h123
-rw-r--r--src/include/gnunet_transport_service.h147
-rw-r--r--src/include/platform.h4
-rw-r--r--src/include/plibc.h1020
-rw-r--r--src/include/winproc.h8
-rw-r--r--src/mesh/gnunet-service-mesh.c3356
-rw-r--r--src/mesh/mesh.h42
-rw-r--r--src/mesh/mesh_api.c718
-rw-r--r--src/mesh/mesh_api_new.c688
-rw-r--r--src/mesh/mesh_protocol.h46
-rw-r--r--src/mesh/test_mesh_api.c188
-rw-r--r--src/mesh/test_mesh_small.c497
-rw-r--r--src/nat/gnunet-helper-nat-client-windows.c303
-rw-r--r--src/nat/gnunet-helper-nat-client.c278
-rw-r--r--src/nat/gnunet-helper-nat-server-windows.c419
-rw-r--r--src/nat/gnunet-helper-nat-server.c401
-rw-r--r--src/nat/gnunet-nat-server.c200
-rw-r--r--src/nat/nat.c1187
-rw-r--r--src/nat/nat.h6
-rw-r--r--src/nat/nat_mini.c423
-rw-r--r--src/nat/nat_test.c289
-rw-r--r--src/nat/test_nat.c32
-rw-r--r--src/nat/test_nat_mini.c34
-rw-r--r--src/nat/test_nat_test.c34
-rw-r--r--src/nse/gnunet-nse-profiler.c615
-rw-r--r--src/nse/gnunet-service-nse.c1097
-rw-r--r--src/nse/nse_api.c156
-rw-r--r--src/nse/test_nse_api.c51
-rw-r--r--src/nse/test_nse_multipeer.c155
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c186
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c332
-rw-r--r--src/peerinfo/peerinfo_api.c376
-rw-r--r--src/peerinfo/peerinfo_api_notify.c128
-rwxr-xr-xsrc/peerinfo/perf_peerinfo_api.c83
-rw-r--r--src/peerinfo/test_peerinfo_api.c96
-rw-r--r--src/statistics/gnunet-service-statistics.c468
-rw-r--r--src/statistics/gnunet-statistics.c57
-rw-r--r--src/statistics/statistics.h2
-rw-r--r--src/statistics/statistics_api.c747
-rw-r--r--src/statistics/test_statistics_api.c89
-rw-r--r--src/statistics/test_statistics_api_loop.c40
-rw-r--r--src/statistics/test_statistics_api_watch.c74
-rw-r--r--src/template/gnunet-service-template.c9
-rw-r--r--src/template/gnunet-template.c3
-rw-r--r--src/testing/test_testing.c32
-rw-r--r--src/testing/test_testing_connect.c47
-rw-r--r--src/testing/test_testing_group.c73
-rw-r--r--src/testing/test_testing_group_remote.c188
-rw-r--r--src/testing/test_testing_large_topology.c826
-rw-r--r--src/testing/test_testing_peergroup.c55
-rw-r--r--src/testing/test_testing_reconnect.c70
-rw-r--r--src/testing/test_testing_topology.c853
-rw-r--r--src/testing/test_testing_topology_blacklist.c357
-rw-r--r--src/testing/test_testing_topology_churn.c114
-rw-r--r--src/testing/testing.c2691
-rw-r--r--src/testing/testing_group.c5809
-rw-r--r--src/testing/testing_peergroup.c849
-rw-r--r--src/topology/gnunet-daemon-topology.c1080
-rw-r--r--src/topology/test_gnunet_daemon_topology.c134
-rw-r--r--src/transport/gnunet-service-transport-new.c324
-rw-r--r--src/transport/gnunet-service-transport.c5612
-rw-r--r--src/transport/gnunet-service-transport_ats.c1826
-rw-r--r--src/transport/gnunet-service-transport_ats.h273
-rw-r--r--src/transport/gnunet-service-transport_blacklist.c611
-rw-r--r--src/transport/gnunet-service-transport_blacklist.h43
-rw-r--r--src/transport/gnunet-service-transport_clients.c533
-rw-r--r--src/transport/gnunet-service-transport_clients.h12
-rw-r--r--src/transport/gnunet-service-transport_hello.c143
-rw-r--r--src/transport/gnunet-service-transport_hello.h28
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c579
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h68
-rw-r--r--src/transport/gnunet-service-transport_plugins.c111
-rw-r--r--src/transport/gnunet-service-transport_plugins.h18
-rw-r--r--src/transport/gnunet-service-transport_validation.c688
-rw-r--r--src/transport/gnunet-service-transport_validation.h45
-rw-r--r--src/transport/gnunet-transport-certificate-creation.c46
-rw-r--r--src/transport/gnunet-transport-list-connections.c23
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c1103
-rw-r--r--src/transport/gnunet-transport-wlan-helper.h3
-rw-r--r--src/transport/ieee80211_radiotap.h164
-rw-r--r--src/transport/perf_transport_ats.c213
-rw-r--r--src/transport/plugin_transport_http.c3934
-rw-r--r--src/transport/plugin_transport_smtp.c568
-rw-r--r--src/transport/plugin_transport_tcp.c1679
-rw-r--r--src/transport/plugin_transport_template.c21
-rw-r--r--src/transport/plugin_transport_udp.c1228
-rw-r--r--src/transport/plugin_transport_unix.c582
-rw-r--r--src/transport/plugin_transport_wlan.c2517
-rw-r--r--src/transport/plugin_transport_wlan.h54
-rw-r--r--src/transport/test_plugin_transport.c52
-rw-r--r--src/transport/test_plugin_transport_http.c1163
-rw-r--r--src/transport/test_plugin_transport_https.c937
-rw-r--r--src/transport/test_plugin_transport_udp.c57
-rw-r--r--src/transport/test_plugin_transport_wlan_dummy.c559
-rw-r--r--src/transport/test_quota_compliance.c910
-rw-r--r--src/transport/test_transport_api.c228
-rw-r--r--src/transport/test_transport_api_disconnect.c208
-rw-r--r--src/transport/test_transport_api_multiaddress.c185
-rw-r--r--src/transport/test_transport_api_reliability.c416
-rw-r--r--src/transport/test_transport_api_unreliability.c753
-rw-r--r--src/transport/test_transport_ats.c137
-rw-r--r--src/transport/test_transport_ats_multiple_peers.c991
-rw-r--r--src/transport/test_transport_testing.c61
-rw-r--r--src/transport/transport-testing.c178
-rw-r--r--src/transport/transport-testing.h32
-rw-r--r--src/transport/transport.h2
-rw-r--r--src/transport/transport_api.c860
-rw-r--r--src/transport/transport_api_address_iterate.c75
-rw-r--r--src/transport/transport_api_address_lookup.c89
-rw-r--r--src/transport/transport_api_blacklist.c97
-rw-r--r--src/transport/transport_api_peer_address_lookup.c80
-rw-r--r--src/transport/wlan/byteorder.h827
-rw-r--r--src/transport/wlan/crctable_osdep.h99
-rw-r--r--src/transport/wlan/helper_common.c82
-rw-r--r--src/transport/wlan/helper_common.h6
-rw-r--r--src/transport/wlan/ieee80211.h532
-rw-r--r--src/transport/wlan/ieee80211_radiotap.h150
-rw-r--r--src/transport/wlan/loopback_helper.h3
-rw-r--r--src/transport/wlan/radiotap-parser.c360
-rw-r--r--src/transport/wlan/radiotap-parser.h31
-rw-r--r--src/util/bandwidth.c182
-rw-r--r--src/util/bio.c262
-rw-r--r--src/util/client.c817
-rw-r--r--src/util/common_allocation.c71
-rw-r--r--src/util/common_logging.c207
-rw-r--r--src/util/configuration.c663
-rw-r--r--src/util/connection.c1020
-rw-r--r--src/util/container_bloomfilter.c235
-rw-r--r--src/util/container_heap.c244
-rw-r--r--src/util/container_meta_data.c889
-rw-r--r--src/util/container_multihashmap.c208
-rw-r--r--src/util/container_slist.c63
-rw-r--r--src/util/crypto_aes.c53
-rw-r--r--src/util/crypto_crc.c15
-rw-r--r--src/util/crypto_hash.c223
-rw-r--r--src/util/crypto_hkdf.c134
-rw-r--r--src/util/crypto_kdf.c32
-rw-r--r--src/util/crypto_ksk.c520
-rw-r--r--src/util/crypto_random.c186
-rw-r--r--src/util/crypto_rsa.c634
-rw-r--r--src/util/disk.c1364
-rw-r--r--src/util/disk.h14
-rw-r--r--src/util/getopt.c990
-rw-r--r--src/util/getopt_helpers.c129
-rw-r--r--src/util/gnunet-config-diff.c24
-rw-r--r--src/util/gnunet-resolver.c17
-rw-r--r--src/util/gnunet-service-resolver.c408
-rw-r--r--src/util/load.c79
-rw-r--r--src/util/network.c576
-rw-r--r--src/util/os_installation.c294
-rw-r--r--src/util/os_network.c351
-rw-r--r--src/util/os_priority.c933
-rw-r--r--src/util/peer.c112
-rw-r--r--src/util/perf_crypto_hash.c15
-rw-r--r--src/util/plugin.c123
-rw-r--r--src/util/program.c99
-rw-r--r--src/util/pseudonym.c223
-rw-r--r--src/util/resolver_api.c662
-rw-r--r--src/util/scheduler.c851
-rw-r--r--src/util/server.c820
-rw-r--r--src/util/server_mst.c297
-rw-r--r--src/util/server_nc.c262
-rw-r--r--src/util/server_tc.c77
-rw-r--r--src/util/service.c1459
-rw-r--r--src/util/signal.c16
-rw-r--r--src/util/strings.c264
-rw-r--r--src/util/test_bio.c20
-rw-r--r--src/util/test_client.c19
-rw-r--r--src/util/test_common_allocation.c22
-rw-r--r--src/util/test_common_logging.c34
-rw-r--r--src/util/test_configuration.c494
-rw-r--r--src/util/test_connection.c33
-rw-r--r--src/util/test_connection_addressing.c39
-rw-r--r--src/util/test_connection_receive_cancel.c10
-rw-r--r--src/util/test_connection_timeout.c23
-rw-r--r--src/util/test_connection_timeout_no_connect.c4
-rw-r--r--src/util/test_connection_transmit_cancel.c6
-rw-r--r--src/util/test_container_bloomfilter.c206
-rw-r--r--src/util/test_container_heap.c178
-rw-r--r--src/util/test_container_meta_data.c377
-rw-r--r--src/util/test_container_multihashmap.c9
-rw-r--r--src/util/test_container_slist.c94
-rw-r--r--src/util/test_crypto_aes.c90
-rw-r--r--src/util/test_crypto_aes_weak.c121
-rw-r--r--src/util/test_crypto_hash.c14
-rw-r--r--src/util/test_crypto_hkdf.c410
-rw-r--r--src/util/test_crypto_ksk.c194
-rw-r--r--src/util/test_crypto_random.c16
-rw-r--r--src/util/test_crypto_rsa.c190
-rw-r--r--src/util/test_disk.c74
-rw-r--r--src/util/test_getopt.c71
-rw-r--r--src/util/test_os_start_process.c99
-rw-r--r--src/util/test_peer.c47
-rw-r--r--src/util/test_program.c2
-rw-r--r--src/util/test_pseudonym.c85
-rw-r--r--src/util/test_resolver_api.c360
-rw-r--r--src/util/test_scheduler.c12
-rw-r--r--src/util/test_scheduler_delay.c12
-rw-r--r--src/util/test_server.c66
-rw-r--r--src/util/test_server_disconnect.c48
-rw-r--r--src/util/test_server_with_client.c43
-rw-r--r--src/util/test_server_with_client_unix.c42
-rw-r--r--src/util/test_service.c37
-rw-r--r--src/util/test_strings.c43
-rw-r--r--src/util/test_time.c111
-rw-r--r--src/util/time.c79
-rw-r--r--src/util/winproc.c170
-rw-r--r--src/vpn/gnunet-daemon-exit.c1271
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.c222
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.h6
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c1002
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.h22
-rw-r--r--src/vpn/gnunet-daemon-vpn.c1572
-rw-r--r--src/vpn/gnunet-daemon-vpn.h40
-rw-r--r--src/vpn/gnunet-dns-parser.c271
-rw-r--r--src/vpn/gnunet-dns-parser.h4
-rw-r--r--src/vpn/gnunet-helper-hijack-dns.c185
-rw-r--r--src/vpn/gnunet-helper-vpn-api.c66
-rw-r--r--src/vpn/gnunet-helper-vpn.c596
-rw-r--r--src/vpn/gnunet-service-dns-p.h116
-rw-r--r--src/vpn/gnunet-service-dns.c1434
-rw-r--r--src/vpn/gnunet-vpn-checksum.c32
-rw-r--r--src/vpn/gnunet-vpn-checksum.h6
-rw-r--r--src/vpn/gnunet-vpn-packet.h411
424 files changed, 81031 insertions, 84514 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index 4114b8528..0db9e5c3e 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -106,61 +106,58 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
struct ShutdownContext *shutdown_ctx = cls;
if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES))
- {
+ {
#if DEBUG_ARM
- /* Means the other side closed the connection and never confirmed a shutdown */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service handle shutdown before ACK!\n");
+ /* Means the other side closed the connection and never confirmed a shutdown */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service handle shutdown before ACK!\n");
#endif
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ }
else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES))
- {
+ {
#if DEBUG_ARM
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Service shutdown complete.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
#endif
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO);
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ }
else
+ {
+ GNUNET_assert (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader));
+ switch (ntohs (msg->type))
{
- GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
- switch (ntohs(msg->type))
- {
- case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK:
+ case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK:
#if DEBUG_ARM
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received confirmation for service shutdown.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received confirmation for service shutdown.\n");
#endif
- shutdown_ctx->confirmed = GNUNET_YES;
- GNUNET_CLIENT_receive (shutdown_ctx->sock,
- &service_shutdown_handler,
- shutdown_ctx,
- GNUNET_TIME_UNIT_FOREVER_REL);
- break;
- default: /* Fall through */
+ shutdown_ctx->confirmed = GNUNET_YES;
+ GNUNET_CLIENT_receive (shutdown_ctx->sock,
+ &service_shutdown_handler,
+ shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
+ break;
+ default: /* Fall through */
#if DEBUG_ARM
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Service shutdown refused!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown refused!\n");
#endif
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES);
-
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- break;
- }
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES);
+
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ break;
}
+ }
}
/**
@@ -169,16 +166,18 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
* @param cls closure
* @param tc context information (why was this task triggered now)
*/
-void service_shutdown_cancel (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+void
+service_shutdown_cancel (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ShutdownContext *shutdown_ctx = cls;
+
#if DEBUG_ARM
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "service_shutdown_cancel called!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "service_shutdown_cancel called!\n");
#endif
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
+ GNUNET_free (shutdown_ctx);
}
@@ -198,21 +197,22 @@ write_shutdown (void *cls, size_t size, void *buf)
struct ShutdownContext *shutdown_ctx = cls;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to transmit shutdown request to client.\n"));
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- return 0; /* client disconnected */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to transmit shutdown request to client.\n"));
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ return 0; /* client disconnected */
+ }
GNUNET_CLIENT_receive (shutdown_ctx->sock,
- &service_shutdown_handler, shutdown_ctx,
- GNUNET_TIME_UNIT_FOREVER_REL);
- shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout),
- &service_shutdown_cancel,
- shutdown_ctx);
+ &service_shutdown_handler, shutdown_ctx,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ shutdown_ctx->cancel_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (shutdown_ctx->timeout),
+ &service_shutdown_cancel, shutdown_ctx);
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -235,22 +235,22 @@ write_shutdown (void *cls, size_t size, void *buf)
*/
static void
arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CLIENT_ShutdownTask cont,
- void *cont_cls)
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CLIENT_ShutdownTask cont, void *cont_cls)
{
struct ShutdownContext *shutdown_ctx;
- shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext));
+
+ shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
shutdown_ctx->cont = cont;
shutdown_ctx->cont_cls = cont_cls;
shutdown_ctx->sock = sock;
- shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout);
+ shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
GNUNET_CLIENT_notify_transmit_ready (sock,
- sizeof (struct
- GNUNET_MessageHeader),
- timeout,
- GNUNET_YES,
- &write_shutdown, shutdown_ctx);
+ sizeof (struct
+ GNUNET_MessageHeader),
+ timeout,
+ GNUNET_YES,
+ &write_shutdown, shutdown_ctx);
}
@@ -266,7 +266,7 @@ arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
*/
struct GNUNET_ARM_Handle *
GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *service)
+ const char *service)
{
struct GNUNET_ARM_Handle *ret;
@@ -351,8 +351,7 @@ struct RequestContext
* @param tc why were we called (reason says if ARM is running)
*/
static void
-arm_service_report (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct RequestContext *pos = cls;
struct GNUNET_OS_Process *proc;
@@ -362,111 +361,91 @@ arm_service_report (void *cls,
char *lopostfix;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Looks like `%s' is already running.\n",
- "gnunet-service-arm");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Looks like `%s' is already running.\n", "gnunet-service-arm");
#endif
- /* arm is running! */
- if (pos->callback != NULL)
- pos->callback (pos->cls, GNUNET_YES);
- GNUNET_free (pos);
- return;
- }
+ /* arm is running! */
+ if (pos->callback != NULL)
+ pos->callback (pos->cls, GNUNET_YES);
+ GNUNET_free (pos);
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Looks like `%s' is not running, will start it.\n",
- "gnunet-service-arm");
+ "Looks like `%s' is not running, will start it.\n",
+ "gnunet-service-arm");
#endif
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (pos->h->cfg,
- "arm", "PREFIX", &loprefix))
+ "arm", "PREFIX", &loprefix))
loprefix = GNUNET_strdup ("");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (pos->h->cfg,
- "arm", "OPTIONS", &lopostfix))
+ "arm", "OPTIONS", &lopostfix))
lopostfix = GNUNET_strdup ("");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (pos->h->cfg,
- "arm",
- "BINARY",
- &binary))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Configuration failes to specify option `%s' in section `%s'!\n"),
- "BINARY",
- "arm");
- if (pos->callback != NULL)
- pos->callback (pos->cls, GNUNET_SYSERR);
- GNUNET_free (pos);
- GNUNET_free (loprefix);
- GNUNET_free (lopostfix);
- return;
- }
+ "arm", "BINARY", &binary))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Configuration failes to specify option `%s' in section `%s'!\n"),
+ "BINARY", "arm");
+ if (pos->callback != NULL)
+ pos->callback (pos->cls, GNUNET_SYSERR);
+ GNUNET_free (pos);
+ GNUNET_free (loprefix);
+ GNUNET_free (lopostfix);
+ return;
+ }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg,
- "arm", "CONFIG", &config))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Configuration fails to specify option `%s' in section `%s'!\n"),
- "CONFIG",
- "arm");
- if (pos->callback != NULL)
- pos->callback (pos->cls, GNUNET_SYSERR);
- GNUNET_free (binary);
- GNUNET_free (pos);
- GNUNET_free (loprefix);
- GNUNET_free (lopostfix);
- return;
- }
- if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (pos->h->cfg,
- "TESTING",
- "WEAKRANDOM")) &&
- (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pos->h->cfg,
- "TESTING",
- "WEAKRANDOM")) &&
- (GNUNET_NO == GNUNET_CONFIGURATION_have_value (pos->h->cfg,
- "TESTING",
- "HOSTFILE")) /* Means we are ONLY running locally */
- )
- {
- /* we're clearly running a test, don't daemonize */
- proc = do_start_process (NULL,
- loprefix,
- binary,
- "-c", config,
+ "arm", "CONFIG", &config))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Configuration fails to specify option `%s' in section `%s'!\n"),
+ "CONFIG", "arm");
+ if (pos->callback != NULL)
+ pos->callback (pos->cls, GNUNET_SYSERR);
+ GNUNET_free (binary);
+ GNUNET_free (pos);
+ GNUNET_free (loprefix);
+ GNUNET_free (lopostfix);
+ return;
+ }
+ if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pos->h->cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_NO == GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "HOSTFILE")) /* Means we are ONLY running locally */
+ )
+ {
+ /* we're clearly running a test, don't daemonize */
+ proc = do_start_process (NULL, loprefix, binary, "-c", config,
#if DEBUG_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- /* no daemonization! */
- lopostfix,
- NULL);
- }
+ /* no daemonization! */
+ lopostfix, NULL);
+ }
else
- {
- proc = do_start_process (NULL,
- loprefix,
- binary,
- "-c", config,
+ {
+ proc = do_start_process (NULL, loprefix, binary, "-c", config,
#if DEBUG_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-d",
- lopostfix,
- NULL);
- }
+ "-d", lopostfix, NULL);
+ }
GNUNET_free (binary);
GNUNET_free (config);
GNUNET_free (loprefix);
GNUNET_free (lopostfix);
if (proc == NULL)
- {
- if (pos->callback != NULL)
- pos->callback (pos->cls, GNUNET_SYSERR);
- GNUNET_free (pos);
- return;
- }
+ {
+ if (pos->callback != NULL)
+ pos->callback (pos->cls, GNUNET_SYSERR);
+ GNUNET_free (pos);
+ return;
+ }
if (pos->callback != NULL)
pos->callback (pos->cls, GNUNET_YES);
GNUNET_free (proc);
@@ -488,44 +467,41 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
int ret;
if (msg == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error receiving response to `%s' request from ARM for service `%s'\n"),
- (sc->type == GNUNET_MESSAGE_TYPE_ARM_START)
- ? "START"
- : "STOP",
- (const char*) &sc[1]);
- GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
- sc->h->client = GNUNET_CLIENT_connect ("arm",
- sc->h->cfg);
- GNUNET_assert (NULL != sc->h->client);
- GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES);
- if (sc->callback != NULL)
- sc->callback (sc->cls, GNUNET_SYSERR);
- GNUNET_free (sc);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Error receiving response to `%s' request from ARM for service `%s'\n"),
+ (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) ? "START" : "STOP",
+ (const char *) &sc[1]);
+ GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
+ sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg);
+ GNUNET_assert (NULL != sc->h->client);
+ GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES);
+ if (sc->callback != NULL)
+ sc->callback (sc->cls, GNUNET_SYSERR);
+ GNUNET_free (sc);
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received response from ARM for service `%s': %u\n",
- (const char*) &sc[1],
- ntohs(msg->type));
+ (const char *) &sc[1], ntohs (msg->type));
#endif
switch (ntohs (msg->type))
- {
- case GNUNET_MESSAGE_TYPE_ARM_IS_UP:
- ret = GNUNET_YES;
- break;
- case GNUNET_MESSAGE_TYPE_ARM_IS_DOWN:
- ret = GNUNET_NO;
- break;
- case GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN:
- ret = GNUNET_SYSERR;
- break;
- default:
- GNUNET_break (0);
- ret = GNUNET_SYSERR;
- }
+ {
+ case GNUNET_MESSAGE_TYPE_ARM_IS_UP:
+ ret = GNUNET_YES;
+ break;
+ case GNUNET_MESSAGE_TYPE_ARM_IS_DOWN:
+ ret = GNUNET_NO;
+ break;
+ case GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN:
+ ret = GNUNET_SYSERR;
+ break;
+ default:
+ GNUNET_break (0);
+ ret = GNUNET_SYSERR;
+ }
if (sc->callback != NULL)
sc->callback (sc->cls, ret);
GNUNET_free (sc);
@@ -544,7 +520,7 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
*/
static void
change_service (struct GNUNET_ARM_Handle *h,
- const char *service_name,
+ const char *service_name,
struct GNUNET_TIME_Relative timeout,
GNUNET_ARM_Callback cb, void *cb_cls, uint16_t type)
{
@@ -553,19 +529,19 @@ change_service (struct GNUNET_ARM_Handle *h,
struct GNUNET_MessageHeader *msg;
slen = strlen (service_name) + 1;
- if (slen + sizeof (struct GNUNET_MessageHeader) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- if (cb != NULL)
- cb (cb_cls, GNUNET_NO);
- return;
- }
+ if (slen + sizeof (struct GNUNET_MessageHeader) >=
+ GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
+ if (cb != NULL)
+ cb (cb_cls, GNUNET_NO);
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
(type == GNUNET_MESSAGE_TYPE_ARM_START)
- ? _("Requesting start of service `%s'.\n")
- : _("Requesting termination of service `%s'.\n"),
- service_name);
+ ? _("Requesting start of service `%s'.\n")
+ : _("Requesting termination of service `%s'.\n"), service_name);
#endif
sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
sctx->h = h;
@@ -580,23 +556,26 @@ change_service (struct GNUNET_ARM_Handle *h,
memcpy (&msg[1], service_name, slen);
if (GNUNET_OK !=
GNUNET_CLIENT_transmit_and_get_response (sctx->h->client,
- msg,
- GNUNET_TIME_absolute_get_remaining (sctx->timeout),
- GNUNET_YES,
- &handle_response,
- sctx))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- (type == GNUNET_MESSAGE_TYPE_ARM_START)
- ? _("Error while trying to transmit request to start `%s' to ARM\n")
- : _("Error while trying to transmit request to stop `%s' to ARM\n"),
- (const char*) &service_name);
- if (cb != NULL)
- cb (cb_cls, GNUNET_SYSERR);
- GNUNET_free (sctx);
- GNUNET_free (msg);
- return;
- }
+ msg,
+ GNUNET_TIME_absolute_get_remaining
+ (sctx->timeout), GNUNET_YES,
+ &handle_response, sctx))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ (type == GNUNET_MESSAGE_TYPE_ARM_START)
+ ?
+ _
+ ("Error while trying to transmit request to start `%s' to ARM\n")
+ :
+ _
+ ("Error while trying to transmit request to stop `%s' to ARM\n"),
+ (const char *) &service_name);
+ if (cb != NULL)
+ cb (cb_cls, GNUNET_SYSERR);
+ GNUNET_free (sctx);
+ GNUNET_free (msg);
+ return;
+ }
GNUNET_free (msg);
}
@@ -612,7 +591,7 @@ change_service (struct GNUNET_ARM_Handle *h,
*/
void
GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
- const char *service_name,
+ const char *service_name,
struct GNUNET_TIME_Relative timeout,
GNUNET_ARM_Callback cb, void *cb_cls)
{
@@ -623,39 +602,42 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Asked to start service `%s' within %llu ms\n"), service_name,
- (unsigned long long) timeout.rel_value);
+ (unsigned long long) timeout.rel_value);
#endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Asked to start service `%s' within %llu ms\n"), service_name,
(unsigned long long) timeout.rel_value);
if (0 == strcasecmp ("arm", service_name))
- {
- slen = strlen ("arm") + 1;
- sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
- sctx->h = h;
- sctx->callback = cb;
- sctx->cls = cb_cls;
- sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- memcpy (&sctx[1], service_name, slen);
- GNUNET_CLIENT_service_test ("arm",
- h->cfg, timeout, &arm_service_report, sctx);
- return;
- }
+ {
+ slen = strlen ("arm") + 1;
+ sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
+ sctx->h = h;
+ sctx->callback = cb;
+ sctx->cls = cb_cls;
+ sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ memcpy (&sctx[1], service_name, slen);
+ GNUNET_CLIENT_service_test ("arm",
+ h->cfg, timeout, &arm_service_report, sctx);
+ return;
+ }
if (h->client == NULL)
+ {
+ client = GNUNET_CLIENT_connect ("arm", h->cfg);
+ if (client == NULL)
{
- client = GNUNET_CLIENT_connect ("arm", h->cfg);
- if (client == NULL)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, GNUNET_CLIENT_connect returned NULL\n");
- cb (cb_cls, GNUNET_SYSERR);
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
- GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
- h->client = client;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "arm_api, GNUNET_CLIENT_connect returned NULL\n");
+ cb (cb_cls, GNUNET_SYSERR);
+ return;
}
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n");
- change_service (h, service_name, timeout, cb, cb_cls, GNUNET_MESSAGE_TYPE_ARM_START);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
+ GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
+ h->client = client;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n");
+ change_service (h, service_name, timeout, cb, cb_cls,
+ GNUNET_MESSAGE_TYPE_ARM_START);
}
/**
@@ -666,15 +648,15 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
* @param reason reason for callback, GNUNET_NO if arm is shutdown
* GNUNET_YES if arm remains running, and GNUNET_SYSERR on error
*/
-void arm_shutdown_callback (void *cls,
- int reason)
+void
+arm_shutdown_callback (void *cls, int reason)
{
struct ARM_ShutdownContext *arm_shutdown_ctx = cls;
if (arm_shutdown_ctx->cb != NULL)
arm_shutdown_ctx->cb (arm_shutdown_ctx->cb_cls, reason);
- GNUNET_free(arm_shutdown_ctx);
+ GNUNET_free (arm_shutdown_ctx);
}
@@ -698,28 +680,30 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Stopping service `%s' within %llu ms\n"), service_name,
- (unsigned long long) timeout.rel_value);
+ (unsigned long long) timeout.rel_value);
if (h->client == NULL)
+ {
+ client = GNUNET_CLIENT_connect ("arm", h->cfg);
+ if (client == NULL)
{
- client = GNUNET_CLIENT_connect ("arm", h->cfg);
- if (client == NULL)
- {
- cb (cb_cls, GNUNET_SYSERR);
- return;
- }
- GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
- h->client = client;
- }
- if (0 == strcasecmp ("arm", service_name))
- {
- arm_shutdown_ctx = GNUNET_malloc(sizeof(struct ARM_ShutdownContext));
- arm_shutdown_ctx->cb = cb;
- arm_shutdown_ctx->cb_cls = cb_cls;
- arm_service_shutdown (h->client, timeout, &arm_shutdown_callback, arm_shutdown_ctx);
- h->client = NULL;
+ cb (cb_cls, GNUNET_SYSERR);
return;
}
- change_service (h, service_name, timeout, cb, cb_cls, GNUNET_MESSAGE_TYPE_ARM_STOP);
+ GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES);
+ h->client = client;
+ }
+ if (0 == strcasecmp ("arm", service_name))
+ {
+ arm_shutdown_ctx = GNUNET_malloc (sizeof (struct ARM_ShutdownContext));
+ arm_shutdown_ctx->cb = cb;
+ arm_shutdown_ctx->cb_cls = cb_cls;
+ arm_service_shutdown (h->client, timeout, &arm_shutdown_callback,
+ arm_shutdown_ctx);
+ h->client = NULL;
+ return;
+ }
+ change_service (h, service_name, timeout, cb, cb_cls,
+ GNUNET_MESSAGE_TYPE_ARM_STOP);
}
diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c
index a2aca9dea..19b3bc224 100644
--- a/src/arm/do_start_process.c
+++ b/src/arm/do_start_process.c
@@ -13,8 +13,7 @@
* @return PID of the started process, -1 on error
*/
static struct GNUNET_OS_Process *
-do_start_process (const int *lsocks,
- const char *first_arg, ...)
+do_start_process (const int *lsocks, const char *first_arg, ...)
{
va_list ap;
char **argv;
@@ -34,24 +33,24 @@ do_start_process (const int *lsocks,
do
{
/* *INDENT-ON* */
- rpos = arg;
- while ('\0' != *rpos)
- {
- if (' ' == *rpos)
- {
- if (last != NULL)
- argv_size++;
- last = NULL;
- while (' ' == *rpos)
- rpos++;
- }
- if ( (last == NULL) && (*rpos != '\0') )
- last = rpos;
- if (*rpos != '\0')
- rpos++;
- }
+ rpos = arg;
+ while ('\0' != *rpos)
+ {
+ if (' ' == *rpos)
+ {
if (last != NULL)
- argv_size++;
+ argv_size++;
+ last = NULL;
+ while (' ' == *rpos)
+ rpos++;
+ }
+ if ((last == NULL) && (*rpos != '\0'))
+ last = rpos;
+ if (*rpos != '\0')
+ rpos++;
+ }
+ if (last != NULL)
+ argv_size++;
/* *INDENT-OFF* */
}
while (NULL != (arg = (va_arg (ap, const char*))));
@@ -67,29 +66,29 @@ do_start_process (const int *lsocks,
do
{
/* *INDENT-ON* */
- cp = GNUNET_strdup (arg);
- pos = cp;
- while ('\0' != *pos)
- {
- if (' ' == *pos)
- {
- *pos = '\0';
- if (last != NULL)
- argv[argv_size++] = GNUNET_strdup (last);
- last = NULL;
- pos++;
- while (' ' == *pos)
- pos++;
- }
- if ( (last == NULL) && (*pos != '\0') )
- last = pos;
- if (*pos != '\0')
- pos++;
- }
+ cp = GNUNET_strdup (arg);
+ pos = cp;
+ while ('\0' != *pos)
+ {
+ if (' ' == *pos)
+ {
+ *pos = '\0';
if (last != NULL)
- argv[argv_size++] = GNUNET_strdup (last);
+ argv[argv_size++] = GNUNET_strdup (last);
last = NULL;
- GNUNET_free (cp);
+ pos++;
+ while (' ' == *pos)
+ pos++;
+ }
+ if ((last == NULL) && (*pos != '\0'))
+ last = pos;
+ if (*pos != '\0')
+ pos++;
+ }
+ if (last != NULL)
+ argv[argv_size++] = GNUNET_strdup (last);
+ last = NULL;
+ GNUNET_free (cp);
/* *INDENT-OFF* */
}
while (NULL != (arg = (va_arg (ap, const char*))));
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c
index ccad0f21f..f7ff536be 100644
--- a/src/arm/gnunet-arm.c
+++ b/src/arm/gnunet-arm.c
@@ -138,9 +138,7 @@ static struct GNUNET_TIME_Relative timeout;
* @param cls closure, unused
* @param tc context, unused
*/
-static void
-cps_loop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -154,39 +152,39 @@ static void
confirm_cb (void *cls, int success)
{
const char *service = cls;
+
switch (success)
+ {
+ case GNUNET_OK:
+ if (quiet != GNUNET_YES)
+ fprintf (stdout, _("Service `%s' has been started.\n"), service);
+ if ((phase - 1 != 2) && (phase - 1 != 3))
{
- case GNUNET_OK:
- if (quiet != GNUNET_YES)
- fprintf(stdout, _("Service `%s' has been started.\n"), service);
- if ((phase - 1 != 2) && (phase - 1 != 3))
- {
- if (quiet != GNUNET_YES)
- fprintf(stdout, _("Failed to stop service `%s'!\n"), service);
- ret = 1;
- }
- break;
- case GNUNET_NO:
if (quiet != GNUNET_YES)
- fprintf(stdout, _("Service `%s' has been stopped.\n"), service);
- if ((phase - 1 != 0) && (phase - 1 != 1))
- {
- if (quiet != GNUNET_YES)
- fprintf(stdout, _("Failed to start service `%s'!\n"), service);
- ret = 1;
- }
- break;
- case GNUNET_SYSERR:
+ fprintf (stdout, _("Failed to stop service `%s'!\n"), service);
+ ret = 1;
+ }
+ break;
+ case GNUNET_NO:
+ if (quiet != GNUNET_YES)
+ fprintf (stdout, _("Service `%s' has been stopped.\n"), service);
+ if ((phase - 1 != 0) && (phase - 1 != 1))
+ {
if (quiet != GNUNET_YES)
- fprintf(stdout,
- _("Some error communicating with service `%s'.\n"), service);
+ fprintf (stdout, _("Failed to start service `%s'!\n"), service);
ret = 1;
- break;
}
+ break;
+ case GNUNET_SYSERR:
+ if (quiet != GNUNET_YES)
+ fprintf (stdout,
+ _("Some error communicating with service `%s'.\n"), service);
+ ret = 1;
+ break;
+ }
GNUNET_SCHEDULER_add_continuation (&cps_loop,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -203,18 +201,17 @@ confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
const char *service = cls;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
- {
- if (quiet != GNUNET_YES)
- fprintf(stdout, _("Service `%s' is running.\n"), service);
- }
+ {
+ if (quiet != GNUNET_YES)
+ fprintf (stdout, _("Service `%s' is running.\n"), service);
+ }
else
- {
- if (quiet != GNUNET_YES)
- fprintf(stdout, _("Service `%s' is not running.\n"), service);
- }
+ {
+ if (quiet != GNUNET_YES)
+ fprintf (stdout, _("Service `%s' is not running.\n"), service);
+ }
GNUNET_SCHEDULER_add_continuation (&cps_loop,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -229,30 +226,29 @@ confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
config_file = cfgfile;
- if (GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "SERVICEHOME", &dir) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Fatal configuration error: `%s' option in section `%s' missing.\n"),
- "SERVICEHOME",
- "PATHS");
- return;
- }
+ if (GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &dir)
+ != GNUNET_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Fatal configuration error: `%s' option in section `%s' missing.\n"),
+ "SERVICEHOME", "PATHS");
+ return;
+ }
h = GNUNET_ARM_connect (cfg, NULL);
if (h == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Fatal error initializing ARM API.\n"));
- ret = 1;
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Fatal error initializing ARM API.\n"));
+ ret = 1;
+ return;
+ }
GNUNET_SCHEDULER_add_continuation (&cps_loop,
- NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
/**
@@ -260,20 +256,23 @@ run (void *cls,
* on arm shutdown provided the end and delete options
* were specified when gnunet-arm was run.
*/
-static void delete_files()
+static void
+delete_files ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will attempt to remove configuration file %s and service directory %s\n", config_file, dir);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Will attempt to remove configuration file %s and service directory %s\n",
+ config_file, dir);
- if (UNLINK(config_file) != 0)
+ if (UNLINK (config_file) != 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to remove configuration file %s\n"), config_file);
+ _("Failed to remove configuration file %s\n"), config_file);
}
- if (GNUNET_DISK_directory_remove(dir) != GNUNET_OK)
+ if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to remove servicehome directory %s\n"), dir);
+ _("Failed to remove servicehome directory %s\n"), dir);
}
}
@@ -286,75 +285,89 @@ static void delete_files()
* @param tc context, unused
*/
static void
-cps_loop (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
while (1)
+ {
+ switch (phase++)
{
- switch (phase++)
- {
- case 0:
- if (term != NULL)
- {
- GNUNET_ARM_stop_service (h, term, (0 == timeout.rel_value) ? STOP_TIMEOUT : timeout, &confirm_cb, term);
- return;
- }
- break;
- case 1:
- if ((end) || (restart))
- {
- GNUNET_ARM_stop_service (h, "arm", (0 == timeout.rel_value) ? STOP_TIMEOUT_ARM : timeout, &confirm_cb, "arm");
- return;
- }
- break;
- case 2:
- if (start)
- {
- GNUNET_ARM_start_service (h, "arm", (0 == timeout.rel_value) ? START_TIMEOUT : timeout, &confirm_cb, "arm");
- return;
- }
- break;
- case 3:
- if (init != NULL)
- {
- GNUNET_ARM_start_service (h, init, (0 == timeout.rel_value) ? START_TIMEOUT : timeout, &confirm_cb, init);
- return;
- }
- break;
- case 4:
- if (test != NULL)
- {
- GNUNET_CLIENT_service_test (test, cfg, (0 == timeout.rel_value) ? TEST_TIMEOUT : timeout, &confirm_task, test);
- return;
- }
- break;
- case 5:
- if (restart)
- {
- GNUNET_ARM_disconnect (h);
- phase = 0;
- end = 0;
- start = 1;
- restart = 0;
- h = GNUNET_ARM_connect (cfg, NULL);
- if (h == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Fatal error initializing ARM API.\n"));
- ret = 1;
- return;
- }
- GNUNET_SCHEDULER_add_now(&cps_loop, NULL);
- return;
- }
- /* Fall through */
- default: /* last phase */
- GNUNET_ARM_disconnect (h);
- if ((end == GNUNET_YES) && (delete == GNUNET_YES))
- delete_files();
- return;
- }
+ case 0:
+ if (term != NULL)
+ {
+ GNUNET_ARM_stop_service (h, term,
+ (0 ==
+ timeout.rel_value) ? STOP_TIMEOUT : timeout,
+ &confirm_cb, term);
+ return;
+ }
+ break;
+ case 1:
+ if ((end) || (restart))
+ {
+ GNUNET_ARM_stop_service (h, "arm",
+ (0 ==
+ timeout.rel_value) ? STOP_TIMEOUT_ARM :
+ timeout, &confirm_cb, "arm");
+ return;
+ }
+ break;
+ case 2:
+ if (start)
+ {
+ GNUNET_ARM_start_service (h, "arm",
+ (0 ==
+ timeout.rel_value) ? START_TIMEOUT : timeout,
+ &confirm_cb, "arm");
+ return;
+ }
+ break;
+ case 3:
+ if (init != NULL)
+ {
+ GNUNET_ARM_start_service (h, init,
+ (0 ==
+ timeout.rel_value) ? START_TIMEOUT : timeout,
+ &confirm_cb, init);
+ return;
+ }
+ break;
+ case 4:
+ if (test != NULL)
+ {
+ GNUNET_CLIENT_service_test (test, cfg,
+ (0 ==
+ timeout.rel_value) ? TEST_TIMEOUT :
+ timeout, &confirm_task, test);
+ return;
+ }
+ break;
+ case 5:
+ if (restart)
+ {
+ GNUNET_ARM_disconnect (h);
+ phase = 0;
+ end = 0;
+ start = 1;
+ restart = 0;
+ h = GNUNET_ARM_connect (cfg, NULL);
+ if (h == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Fatal error initializing ARM API.\n"));
+ ret = 1;
+ return;
+ }
+ GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
+ return;
+ }
+ /* Fall through */
+ default: /* last phase */
+ GNUNET_ARM_disconnect (h);
+ if ((end == GNUNET_YES) && (delete == GNUNET_YES))
+ delete_files ();
+ return;
}
+ }
}
@@ -379,16 +392,19 @@ main (int argc, char *const *argv)
GNUNET_YES, &GNUNET_GETOPT_set_string, &term},
{'s', "start", NULL, gettext_noop ("start all GNUnet default services"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &start},
- {'r', "restart", NULL, gettext_noop ("stop and start all GNUnet default services"),
+ {'r', "restart", NULL,
+ gettext_noop ("stop and start all GNUnet default services"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &restart},
{'t', "test", "SERVICE",
gettext_noop ("test if a particular service is running"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &test},
- {'d', "delete", NULL, gettext_noop ("delete config file and directory on exit"),
+ {'d', "delete", NULL,
+ gettext_noop ("delete config file and directory on exit"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &delete},
{'q', "quiet", NULL, gettext_noop ("don't print status messages"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &quiet},
- {'T', "timeout", NULL, gettext_noop ("timeout for completing current operation"),
+ {'T', "timeout", NULL,
+ gettext_noop ("timeout for completing current operation"),
GNUNET_YES, &GNUNET_GETOPT_set_ulong, &temp_timeout_ms},
GNUNET_GETOPT_OPTION_END
};
@@ -397,16 +413,16 @@ main (int argc, char *const *argv)
timeout.rel_value = temp_timeout_ms;
if (GNUNET_OK == GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-arm",
- gettext_noop
- ("Control services and the Automated Restart Manager (ARM)"),
- options, &run, NULL))
- {
- return ret;
- }
+ argv,
+ "gnunet-arm",
+ gettext_noop
+ ("Control services and the Automated Restart Manager (ARM)"),
+ options, &run, NULL))
+ {
+ return ret;
+ }
- return 1;
+ return 1;
}
/* end of gnunet-arm.c */
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 05c6fb438..e4a8e7c6c 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -188,7 +188,7 @@ static struct GNUNET_SERVER_Handle *server;
* @param cls closure, NULL if we need to self-restart
* @param tc context
*/
-static void
+static void
config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceList *pos;
@@ -196,21 +196,21 @@ config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
pos = running_head;
while (pos != NULL)
+ {
+ /* FIXME: this test for config change may be a bit too coarse grained */
+ if ((0 == STAT (pos->config, &sbuf)) &&
+ (pos->mtime < sbuf.st_mtime) && (pos->proc != NULL))
{
- /* FIXME: this test for config change may be a bit too coarse grained */
- if ( (0 == STAT (pos->config, &sbuf)) &&
- (pos->mtime < sbuf.st_mtime) &&
- (pos->proc != NULL) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Restarting service `%s' due to configuration file change.\n"));
- if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- else
- pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
- }
- pos = pos->next;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Restarting service `%s' due to configuration file change.\n"));
+ if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ else
+ pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
}
+ pos = pos->next;
+ }
}
@@ -229,15 +229,14 @@ write_result (void *cls, size_t size, void *buf)
struct GNUNET_MessageHeader *msg;
if (buf == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not send status result to client\n"));
- return 0; /* error, not much we can do */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not send status result to client\n"));
+ return 0; /* error, not much we can do */
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending status response %u to client\n",
- (unsigned int) *res);
+ "Sending status response %u to client\n", (unsigned int) *res);
#endif
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
msg = buf;
@@ -259,29 +258,27 @@ write_result (void *cls, size_t size, void *buf)
*/
static void
signal_result (struct GNUNET_SERVER_Client *client,
- const char *name, uint16_t result)
+ const char *name, uint16_t result)
{
uint16_t *res;
if (NULL == client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Not sending status result to client: no client known\n"));
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Not sending status result to client: no client known\n"));
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Telling client that service `%s' is now %s\n",
- name,
- result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up");
+ "Telling client that service `%s' is now %s\n",
+ name, result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up");
#endif
res = GNUNET_malloc (sizeof (uint16_t));
*res = result;
GNUNET_SERVER_notify_transmit_ready (client,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &write_result, res);
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &write_result, res);
}
@@ -299,11 +296,11 @@ find_service (const char *name)
pos = running_head;
while (pos != NULL)
- {
- if (0 == strcmp (pos->name, name))
- return pos;
- pos = pos->next;
- }
+ {
+ if (0 == strcmp (pos->name, name))
+ return pos;
+ pos = pos->next;
+ }
return NULL;
}
@@ -316,9 +313,7 @@ find_service (const char *name)
static void
free_service (struct ServiceList *pos)
{
- GNUNET_CONTAINER_DLL_remove (running_head,
- running_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (running_head, running_tail, pos);
GNUNET_free_non_null (pos->config);
GNUNET_free_non_null (pos->binary);
GNUNET_free (pos->name);
@@ -336,8 +331,7 @@ free_service (struct ServiceList *pos)
* @param lsocks -1 terminated list of listen sockets to pass (systemd style), or NULL
*/
static void
-start_process (struct ServiceList *sl,
- const int *lsocks)
+start_process (struct ServiceList *sl, const int *lsocks)
{
char *loprefix;
char *options;
@@ -351,85 +345,70 @@ start_process (struct ServiceList *sl,
/* start service */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- sl->name, "PREFIX", &loprefix))
+ sl->name, "PREFIX", &loprefix))
loprefix = GNUNET_strdup (prefix_command);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- sl->name, "OPTIONS", &options))
- {
- options = GNUNET_strdup (final_option);
- if (NULL == strstr (options, "%"))
- {
- /* replace '{}' with service name */
- while (NULL != (optpos = strstr (options, "{}")))
- {
- optpos[0] = '%';
- optpos[1] = 's';
- GNUNET_asprintf (&optpos,
- options,
- sl->name);
- GNUNET_free (options);
- options = optpos;
- }
- /* replace '$PATH' with value associated with "PATH" */
- while (NULL != (optpos = strstr (options, "$")))
- {
- optend = optpos + 1;
- while (isupper ( (unsigned char) *optend)) optend++;
- b = *optend;
- if ('\0' == b)
- next = "";
- else
- next = optend+1;
- *optend = '\0';
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
- optpos+1,
- &val))
- val = GNUNET_strdup ("");
- *optpos = '\0';
- GNUNET_asprintf (&optpos,
- "%s%s%c%s",
- options,
- val,
- b,
- next);
- GNUNET_free (options);
- GNUNET_free (val);
- options = optpos;
- }
- }
+ sl->name, "OPTIONS", &options))
+ {
+ options = GNUNET_strdup (final_option);
+ if (NULL == strstr (options, "%"))
+ {
+ /* replace '{}' with service name */
+ while (NULL != (optpos = strstr (options, "{}")))
+ {
+ optpos[0] = '%';
+ optpos[1] = 's';
+ GNUNET_asprintf (&optpos, options, sl->name);
+ GNUNET_free (options);
+ options = optpos;
+ }
+ /* replace '$PATH' with value associated with "PATH" */
+ while (NULL != (optpos = strstr (options, "$")))
+ {
+ optend = optpos + 1;
+ while (isupper ((unsigned char) *optend))
+ optend++;
+ b = *optend;
+ if ('\0' == b)
+ next = "";
+ else
+ next = optend + 1;
+ *optend = '\0';
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
+ optpos + 1, &val))
+ val = GNUNET_strdup ("");
+ *optpos = '\0';
+ GNUNET_asprintf (&optpos, "%s%s%c%s", options, val, b, next);
+ GNUNET_free (options);
+ GNUNET_free (val);
+ options = optpos;
+ }
}
+ }
use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG");
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting service `%s' using binary `%s' and configuration `%s'\n",
- sl->name, sl->binary, sl->config);
+ "Starting service `%s' using binary `%s' and configuration `%s'\n",
+ sl->name, sl->binary, sl->config);
#endif
if (GNUNET_YES == use_debug)
sl->proc = do_start_process (lsocks,
- loprefix,
- sl->binary,
- "-c", sl->config,
- "-L", "DEBUG",
- options,
- NULL);
+ loprefix,
+ sl->binary,
+ "-c", sl->config,
+ "-L", "DEBUG", options, NULL);
else
sl->proc = do_start_process (lsocks,
- loprefix,
- sl->binary,
- "-c", sl->config,
- options,
- NULL);
+ loprefix,
+ sl->binary, "-c", sl->config, options, NULL);
if (sl->proc == NULL)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to start service `%s'\n"),
- sl->name);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to start service `%s'\n"), sl->name);
else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Starting service `%s'\n"),
- sl->name);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting service `%s'\n"), sl->name);
GNUNET_free (loprefix);
GNUNET_free (options);
}
@@ -444,9 +423,8 @@ start_process (struct ServiceList *sl,
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-start_service (struct GNUNET_SERVER_Client *client,
- const char *servicename,
- const int *lsocks)
+start_service (struct GNUNET_SERVER_Client *client,
+ const char *servicename, const int *lsocks)
{
struct ServiceList *sl;
char *binary;
@@ -454,46 +432,46 @@ start_service (struct GNUNET_SERVER_Client *client,
struct stat sbuf;
if (GNUNET_YES == in_shutdown)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("ARM is shutting down, service `%s' not started.\n"),
- servicename);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("ARM is shutting down, service `%s' not started.\n"),
+ servicename);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ return GNUNET_SYSERR;
+ }
sl = find_service (servicename);
if (sl != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Service `%s' already running.\n"), servicename);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Service `%s' already running.\n"), servicename);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
+ return GNUNET_SYSERR;
+ }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- servicename, "BINARY", &binary))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Binary implementing service `%s' not known!\n"),
- servicename);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- return GNUNET_SYSERR;
- }
+ servicename, "BINARY", &binary))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Binary implementing service `%s' not known!\n"),
+ servicename);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ return GNUNET_SYSERR;
+ }
if ((GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- servicename,
- "CONFIG",
- &config)) ||
+ servicename,
+ "CONFIG",
+ &config)) ||
(0 != STAT (config, &sbuf)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Configuration file `%s' for service `%s' not known!\n"),
- config, servicename);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_free (binary);
- GNUNET_free_non_null (config);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Configuration file `%s' for service `%s' not known!\n"),
+ config, servicename);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_free (binary);
+ GNUNET_free_non_null (config);
+ return GNUNET_SYSERR;
+ }
(void) stop_listening (servicename);
sl = GNUNET_malloc (sizeof (struct ServiceList));
sl->name = GNUNET_strdup (servicename);
@@ -502,9 +480,7 @@ start_service (struct GNUNET_SERVER_Client *client,
sl->mtime = sbuf.st_mtime;
sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
sl->restartAt = GNUNET_TIME_UNIT_FOREVER_ABS;
- GNUNET_CONTAINER_DLL_insert (running_head,
- running_tail,
- sl);
+ GNUNET_CONTAINER_DLL_insert (running_head, running_tail, sl);
start_process (sl, lsocks);
if (NULL != client)
signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
@@ -519,58 +495,57 @@ start_service (struct GNUNET_SERVER_Client *client,
* @param servicename name of the service to stop
*/
static void
-stop_service (struct GNUNET_SERVER_Client *client,
- const char *servicename)
+stop_service (struct GNUNET_SERVER_Client *client, const char *servicename)
{
struct ServiceList *pos;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Preparing to stop `%s'\n"), servicename);
+ _("Preparing to stop `%s'\n"), servicename);
pos = find_service (servicename);
if (pos == NULL)
- {
- if (GNUNET_OK == stop_listening (servicename))
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- else
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ {
+ if (GNUNET_OK == stop_listening (servicename))
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ else
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
if (pos->killing_client != NULL)
- {
- /* killing already in progress */
+ {
+ /* killing already in progress */
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' is already down\n", servicename);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' is already down\n", servicename);
#endif
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
if (GNUNET_YES == in_shutdown)
- {
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Termination request already sent to `%s' (since ARM is in shutdown).\n",
- servicename);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Termination request already sent to `%s' (since ARM is in shutdown).\n",
+ servicename);
#endif
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
if (pos->proc == NULL)
- {
- /* process is in delayed restart, simply remove it! */
- free_service (pos);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ {
+ /* process is in delayed restart, simply remove it! */
+ free_service (pos);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending kill signal to service `%s', waiting for process to die.\n",
- servicename);
+ "Sending kill signal to service `%s', waiting for process to die.\n",
+ servicename);
#endif
if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
@@ -590,8 +565,8 @@ stop_service (struct GNUNET_SERVER_Client *client,
*/
static void
handle_start (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const char *servicename;
uint16_t size;
@@ -600,11 +575,11 @@ handle_start (void *cls,
size -= sizeof (struct GNUNET_MessageHeader);
servicename = (const char *) &message[1];
if ((size == 0) || (servicename[size - 1] != '\0'))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
start_service (client, servicename, NULL);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -621,8 +596,8 @@ handle_start (void *cls,
*/
static void
handle_stop (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const char *servicename;
uint16_t size;
@@ -631,11 +606,11 @@ handle_stop (void *cls,
size -= sizeof (struct GNUNET_MessageHeader);
servicename = (const char *) &message[1];
if ((size == 0) || (servicename[size - 1] != '\0'))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
stop_service (client, servicename);
}
@@ -650,14 +625,14 @@ clean_up_running ()
{
struct ServiceList *pos;
struct ServiceList *next;
-
+
next = running_head;
while (NULL != (pos = next))
- {
- next = pos->next;
- if (pos->proc == NULL)
- free_service (pos);
- }
+ {
+ next = pos->next;
+ if (pos->proc == NULL)
+ free_service (pos);
+ }
}
@@ -669,15 +644,15 @@ static void
do_shutdown ()
{
if (NULL != server)
- {
- GNUNET_SERVER_destroy (server);
- server = NULL;
- }
+ {
+ GNUNET_SERVER_destroy (server);
+ server = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != child_death_task)
- {
- GNUNET_SCHEDULER_cancel (child_death_task);
- child_death_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (child_death_task);
+ child_death_task = GNUNET_SCHEDULER_NO_TASK;
+ }
}
@@ -688,35 +663,31 @@ do_shutdown ()
* @param tc context
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceList *pos;
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Stopping all services\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Stopping all services\n"));
#endif
if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
- {
- GNUNET_SCHEDULER_cancel (child_restart_task);
- child_restart_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (child_restart_task);
+ child_restart_task = GNUNET_SCHEDULER_NO_TASK;
+ }
in_shutdown = GNUNET_YES;
stop_listening (NULL);
pos = running_head;
while (NULL != pos)
+ {
+ if (pos->proc != NULL)
{
- if (pos->proc != NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Stopping service `%s'\n",
- pos->name);
- if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- }
- pos = pos->next;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n", pos->name);
+ if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
}
+ pos = pos->next;
+ }
if (running_head == NULL)
do_shutdown ();
}
@@ -741,40 +712,39 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
/* check for services that need to be restarted due to
- configuration changes or because the last restart failed */
+ * configuration changes or because the last restart failed */
pos = running_head;
while (pos != NULL)
+ {
+ if (pos->proc == NULL)
{
- if (pos->proc == NULL)
- {
- if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Restarting service `%s'.\n"), pos->name);
- start_process (pos, NULL);
- }
- else
- {
- lowestRestartDelay
- = GNUNET_TIME_relative_min (lowestRestartDelay,
- GNUNET_TIME_absolute_get_remaining
- (pos->restartAt));
- }
- }
- pos = pos->next;
- }
+ if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Restarting service `%s'.\n"), pos->name);
+ start_process (pos, NULL);
+ }
+ else
+ {
+ lowestRestartDelay
+ = GNUNET_TIME_relative_min (lowestRestartDelay,
+ GNUNET_TIME_absolute_get_remaining
+ (pos->restartAt));
+ }
+ }
+ pos = pos->next;
+ }
if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
- {
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Will restart process in %llums\n",
- (unsigned long long) lowestRestartDelay.rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Will restart process in %llums\n",
+ (unsigned long long) lowestRestartDelay.rel_value);
#endif
- child_restart_task
- = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay,
- &delayed_restart_task,
- NULL);
- }
+ child_restart_task
+ = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay,
+ &delayed_restart_task, NULL);
+ }
}
@@ -786,8 +756,7 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
* @param tc context
*/
static void
-maint_child_death (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceList *pos;
struct ServiceList *next;
@@ -800,93 +769,89 @@ maint_child_death (void *cls,
child_death_task = GNUNET_SCHEDULER_NO_TASK;
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
- {
- /* shutdown scheduled us, ignore! */
- child_death_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
- &maint_child_death, NULL);
- return;
- }
+ {
+ /* shutdown scheduled us, ignore! */
+ child_death_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
+ &maint_child_death, NULL);
+ return;
+ }
/* consume the signal */
GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
/* check for services that died (WAITPID) */
next = running_head;
while (NULL != (pos = next))
+ {
+ next = pos->next;
+ if (pos->proc == NULL)
+ continue;
+ if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
+ &statusType,
+ &statusCode))) ||
+ ((ret == GNUNET_NO) ||
+ (statusType == GNUNET_OS_PROCESS_STOPPED) ||
+ (statusType == GNUNET_OS_PROCESS_RUNNING)))
+ continue;
+
+ if (statusType == GNUNET_OS_PROCESS_EXITED)
{
- next = pos->next;
- if (pos->proc == NULL)
- continue;
- if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
- &statusType,
- &statusCode))) ||
- ( (ret == GNUNET_NO) ||
- (statusType == GNUNET_OS_PROCESS_STOPPED) ||
- (statusType == GNUNET_OS_PROCESS_RUNNING)) )
- continue;
-
- if (statusType == GNUNET_OS_PROCESS_EXITED)
- {
- statstr = _( /* process termination method */ "exit");
- statcode = statusCode;
- }
- else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
- {
- statstr = _( /* process termination method */ "signal");
- statcode = statusCode;
- }
- else
- {
- statstr = _( /* process termination method */ "unknown");
- statcode = 0;
- }
- GNUNET_OS_process_close (pos->proc);
- pos->proc = NULL;
- if (NULL != pos->killing_client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' stopped\n"),
- pos->name);
- signal_result (pos->killing_client,
- pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
- GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
- GNUNET_SERVER_client_drop (pos->killing_client);
- free_service (pos);
- continue;
- }
- if (GNUNET_YES != in_shutdown)
- {
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Service `%s' terminated with status %s/%d, will try to restart it!\n"),
- pos->name, statstr, statcode);
- /* schedule restart */
- pos->restartAt
- = GNUNET_TIME_relative_to_absolute (pos->backoff);
- if (pos->backoff.rel_value < EXPONENTIAL_BACKOFF_THRESHOLD)
- pos->backoff
- = GNUNET_TIME_relative_multiply (pos->backoff, 2);
- if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
- GNUNET_SCHEDULER_cancel (child_restart_task);
- child_restart_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delayed_restart_task,
- NULL);
- }
+ statstr = _( /* process termination method */ "exit");
+ statcode = statusCode;
+ }
+ else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
+ {
+ statstr = _( /* process termination method */ "signal");
+ statcode = statusCode;
+ }
+ else
+ {
+ statstr = _( /* process termination method */ "unknown");
+ statcode = 0;
+ }
+ GNUNET_OS_process_close (pos->proc);
+ pos->proc = NULL;
+ if (NULL != pos->killing_client)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Service `%s' stopped\n"), pos->name);
+ signal_result (pos->killing_client,
+ pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
+ GNUNET_SERVER_client_drop (pos->killing_client);
+ free_service (pos);
+ continue;
+ }
+ if (GNUNET_YES != in_shutdown)
+ {
+ if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Service `%s' terminated with status %s/%d, will try to restart it!\n"),
+ pos->name, statstr, statcode);
+ /* schedule restart */
+ pos->restartAt = GNUNET_TIME_relative_to_absolute (pos->backoff);
+ if (pos->backoff.rel_value < EXPONENTIAL_BACKOFF_THRESHOLD)
+ pos->backoff = GNUNET_TIME_relative_multiply (pos->backoff, 2);
+ if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
+ GNUNET_SCHEDULER_cancel (child_restart_task);
+ child_restart_task
+ = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delayed_restart_task, NULL);
+ }
#if DEBUG_ARM
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' terminated with status %s/%d\n",
- pos->name, statstr, statcode);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' terminated with status %s/%d\n",
+ pos->name, statstr, statcode);
#endif
- }
+ }
child_death_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
- &maint_child_death, NULL);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
+ &maint_child_death, NULL);
if (GNUNET_YES == in_shutdown)
clean_up_running ();
- if ( (NULL == running_head) &&
- (GNUNET_YES == in_shutdown) )
+ if ((NULL == running_head) && (GNUNET_YES == in_shutdown))
do_shutdown ();
}
@@ -898,25 +863,24 @@ transmit_shutdown_ack (void *cls, size_t size, void *buf)
struct GNUNET_MessageHeader *msg;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Failed to transmit shutdown ACK.\n"));
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return 0; /* client disconnected */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Failed to transmit shutdown ACK.\n"));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return 0; /* client disconnected */
+ }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Transmitting shutdown ACK.\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting shutdown ACK.\n"));
/* Make the connection flushing for the purpose of ACK transmitting,
- needed on W32 to ensure that the message is even received, harmless
- on other platforms... */
+ * needed on W32 to ensure that the message is even received, harmless
+ * on other platforms... */
GNUNET_break (GNUNET_OK == GNUNET_SERVER_client_disable_corking (client));
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_SERVER_client_drop(client);
+ GNUNET_SERVER_client_drop (client);
return sizeof (struct GNUNET_MessageHeader);
}
@@ -933,11 +897,11 @@ handle_shutdown (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_SERVER_client_keep(client);
+ GNUNET_SERVER_client_keep (client);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Initiating shutdown as requested by client.\n"));
GNUNET_SERVER_notify_transmit_ready (client,
- sizeof(struct GNUNET_MessageHeader),
+ sizeof (struct GNUNET_MessageHeader),
GNUNET_TIME_UNIT_FOREVER_REL,
&transmit_shutdown_ack, client);
GNUNET_SERVER_client_persist_ (client);
@@ -953,12 +917,13 @@ static void
sighandler_child_death ()
{
static char c;
- int old_errno = errno; /* back-up errno */
- GNUNET_break (1 ==
- GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
- (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c,
- sizeof (c)));
- errno = old_errno; /* restore errno */
+ int old_errno = errno; /* back-up errno */
+
+ GNUNET_break (1 ==
+ GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
+ (sigpipe, GNUNET_DISK_PIPE_END_WRITE),
+ &c, sizeof (c)));
+ errno = old_errno; /* restore errno */
}
@@ -991,63 +956,59 @@ run (void *cls,
GNUNET_assert (pr != NULL);
GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ &shutdown_task, NULL);
child_death_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
- &maint_child_death, NULL);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
+ &maint_child_death, NULL);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "GLOBAL_PREFIX",
- &prefix_command))
+ "ARM",
+ "GLOBAL_PREFIX", &prefix_command))
prefix_command = GNUNET_strdup ("");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "GLOBAL_POSTFIX",
- &final_option))
+ "ARM",
+ "GLOBAL_POSTFIX", &final_option))
final_option = GNUNET_strdup ("");
/* start default services... */
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "DEFAULTSERVICES",
- &defaultservices))
- {
+ "ARM",
+ "DEFAULTSERVICES",
+ &defaultservices))
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting default services `%s'\n", defaultservices);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting default services `%s'\n", defaultservices);
#endif
- if (0 < strlen (defaultservices))
- {
- pos = strtok (defaultservices, " ");
- while (pos != NULL)
- {
- start_service (NULL, pos, NULL);
- pos = strtok (NULL, " ");
- }
- }
- GNUNET_free (defaultservices);
+ if (0 < strlen (defaultservices))
+ {
+ pos = strtok (defaultservices, " ");
+ while (pos != NULL)
+ {
+ start_service (NULL, pos, NULL);
+ pos = strtok (NULL, " ");
+ }
}
+ GNUNET_free (defaultservices);
+ }
else
- {
+ {
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No default services configured.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No default services configured.\n");
#endif
- }
+ }
- /* create listening sockets for future services*/
+ /* create listening sockets for future services */
prepareServices (cfg);
-
+
/* process client requests */
GNUNET_SERVER_add_handlers (server, handlers);
/* manage services */
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &config_change_task, NULL);
+ &config_change_task, NULL);
}
@@ -1066,10 +1027,11 @@ main (int argc, char *const *argv)
sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
GNUNET_assert (sigpipe != NULL);
- shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
- ret = (GNUNET_OK ==
- GNUNET_SERVICE_run (argc,
- argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1;
+ shc_chld =
+ GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
+ ret =
+ (GNUNET_OK ==
+ GNUNET_SERVICE_run (argc, argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1;
GNUNET_SIGNAL_handler_uninstall (shc_chld);
shc_chld = NULL;
GNUNET_DISK_pipe_close (sigpipe);
@@ -1085,8 +1047,8 @@ main (int argc, char *const *argv)
*/
void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
{
- mallopt (M_TRIM_THRESHOLD, 4*1024);
- mallopt (M_TOP_PAD, 1*1024);
+ mallopt (M_TRIM_THRESHOLD, 4 * 1024);
+ mallopt (M_TOP_PAD, 1 * 1024);
malloc_trim (0);
}
#endif
diff --git a/src/arm/gnunet-service-arm.h b/src/arm/gnunet-service-arm.h
index 0ef557157..a9f72b512 100644
--- a/src/arm/gnunet-service-arm.h
+++ b/src/arm/gnunet-service-arm.h
@@ -36,8 +36,7 @@
* @return GNUNET_OK on success
*/
int start_service (struct GNUNET_SERVER_Client *client,
- const char *servicename,
- const int *lsocks);
+ const char *servicename, const int *lsocks);
/**
* Stop listening for connections to a service.
@@ -49,6 +48,6 @@ int start_service (struct GNUNET_SERVER_Client *client,
int stop_listening (const char *serviceName);
void prepareServices (const struct GNUNET_CONFIGURATION_Handle
- *configurationHandle);
+ *configurationHandle);
#endif
diff --git a/src/arm/gnunet-service-arm_interceptor.c b/src/arm/gnunet-service-arm_interceptor.c
index 8f4a4731c..b99b076da 100644
--- a/src/arm/gnunet-service-arm_interceptor.c
+++ b/src/arm/gnunet-service-arm_interceptor.c
@@ -153,12 +153,12 @@ struct ForwardedConnection
* Timeout for forwarding.
*/
struct GNUNET_TIME_Absolute timeout;
-
+
/**
* Current back-off value.
*/
struct GNUNET_TIME_Relative back_off;
-
+
/**
* Task that tries to initiate forwarding.
*/
@@ -243,10 +243,10 @@ addDefaultServicesToList (const char *services)
s = GNUNET_strdup (services);
token = strtok (s, " ");
while (NULL != token)
- {
- numDefaultServices++;
- token = strtok (NULL, " ");
- }
+ {
+ numDefaultServices++;
+ token = strtok (NULL, " ");
+ }
GNUNET_free (s);
defaultServicesList = GNUNET_malloc (numDefaultServices * sizeof (char *));
@@ -254,10 +254,10 @@ addDefaultServicesToList (const char *services)
s = GNUNET_strdup (services);
token = strtok (s, " ");
while (NULL != token)
- {
- defaultServicesList[i++] = GNUNET_strdup (token);
- token = strtok (NULL, " ");
- }
+ {
+ defaultServicesList[i++] = GNUNET_strdup (token);
+ token = strtok (NULL, " ");
+ }
GNUNET_free (s);
GNUNET_assert (i == numDefaultServices);
}
@@ -272,9 +272,10 @@ static int
isInDefaultList (const char *serviceName)
{
unsigned int i;
+
for (i = 0; i < numDefaultServices; i++)
if (strcmp (serviceName, defaultServicesList[i]) == 0)
- return GNUNET_YES;
+ return GNUNET_YES;
return GNUNET_NO;
}
@@ -286,52 +287,45 @@ isInDefaultList (const char *serviceName)
* @param reason which direction to close
*/
static void
-closeClientAndServiceSockets (struct ForwardedConnection *fc,
- int reason)
+closeClientAndServiceSockets (struct ForwardedConnection *fc, int reason)
{
- if (0 != (REASON_SERVICE_TO_CLIENT & reason))
- {
+ if (0 != (REASON_SERVICE_TO_CLIENT & reason))
+ {
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping forwarding from service to client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping forwarding from service to client\n");
#endif
- if (fc->armClientSocket != NULL)
- GNUNET_NETWORK_socket_shutdown (fc->armClientSocket,
- SHUT_WR);
- if (fc->armServiceSocket != NULL)
- GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket,
- SHUT_RD);
- }
- if (0 != (REASON_CLIENT_TO_SERVICE & reason))
- {
+ if (fc->armClientSocket != NULL)
+ GNUNET_NETWORK_socket_shutdown (fc->armClientSocket, SHUT_WR);
+ if (fc->armServiceSocket != NULL)
+ GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket, SHUT_RD);
+ }
+ if (0 != (REASON_CLIENT_TO_SERVICE & reason))
+ {
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping forwarding from client to service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping forwarding from client to service\n");
#endif
- if (fc->armClientSocket != NULL)
- GNUNET_NETWORK_socket_shutdown (fc->armClientSocket,
- SHUT_RD);
- if (fc->armServiceSocket != NULL)
- GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket,
- SHUT_WR);
- }
+ if (fc->armClientSocket != NULL)
+ GNUNET_NETWORK_socket_shutdown (fc->armClientSocket, SHUT_RD);
+ if (fc->armServiceSocket != NULL)
+ GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket, SHUT_WR);
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Closing forwarding connection (done with both directions)\n");
+ "Closing forwarding connection (done with both directions)\n");
#endif
fc->reference_count -= 1;
if (fc->reference_count <= 0)
{
- if ( (NULL != fc->armClientSocket) &&
- (GNUNET_SYSERR ==
- GNUNET_NETWORK_socket_close (fc->armClientSocket)) )
+ if ((NULL != fc->armClientSocket) &&
+ (GNUNET_SYSERR == GNUNET_NETWORK_socket_close (fc->armClientSocket)))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close");
fc->armClientSocket = NULL;
}
- if ( (NULL != fc->armServiceSocket) &&
- (GNUNET_SYSERR ==
- GNUNET_NETWORK_socket_close (fc->armServiceSocket)) )
+ if ((NULL != fc->armServiceSocket) &&
+ (GNUNET_SYSERR == GNUNET_NETWORK_socket_close (fc->armServiceSocket)))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close");
fc->armServiceSocket = NULL;
@@ -380,8 +374,7 @@ receiveFromService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
*
*/
static void
-start_forwarding (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+start_forwarding (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
@@ -399,54 +392,46 @@ forwardToClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK;
if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready,
- fc->armClientSocket))
- {
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &forwardToClient, fc);
- return;
- }
+ fc->armClientSocket))
+ {
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &forwardToClient, fc);
+ return;
+ }
/* Forwarding service response to client */
numberOfBytesSent =
- GNUNET_NETWORK_socket_send (fc->armClientSocket,
- fc->service_to_client_bufferPos,
- fc->service_to_client_bufferDataLength);
+ GNUNET_NETWORK_socket_send (fc->armClientSocket,
+ fc->service_to_client_bufferPos,
+ fc->service_to_client_bufferDataLength);
if (numberOfBytesSent <= 0)
- {
- if ( (errno != EPIPE) &&
- (errno != ECONNRESET) )
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to forward %u bytes of data to client: %s\n",
- fc->service_to_client_bufferDataLength,
- STRERROR (errno));
- closeClientAndServiceSockets (fc,
- REASON_SERVICE_TO_CLIENT);
- return;
- }
+ {
+ if ((errno != EPIPE) && (errno != ECONNRESET))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to forward %u bytes of data to client: %s\n",
+ fc->service_to_client_bufferDataLength, STRERROR (errno));
+ closeClientAndServiceSockets (fc, REASON_SERVICE_TO_CLIENT);
+ return;
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Forwarded %d bytes to client\n",
- numberOfBytesSent);
+ "Forwarded %d bytes to client\n", numberOfBytesSent);
#endif
if (numberOfBytesSent < fc->service_to_client_bufferDataLength)
- {
- fc->service_to_client_bufferPos += numberOfBytesSent;
- fc->service_to_client_bufferDataLength -= numberOfBytesSent;
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &forwardToClient,
- fc);
- return;
- }
+ {
+ fc->service_to_client_bufferPos += numberOfBytesSent;
+ fc->service_to_client_bufferDataLength -= numberOfBytesSent;
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &forwardToClient, fc);
+ return;
+ }
fc->service_to_client_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &receiveFromService,
- fc);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &receiveFromService, fc);
}
@@ -457,98 +442,92 @@ forwardToClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
* @param tc scheduler context
*/
static void
-receiveFromService (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+receiveFromService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ForwardedConnection *fc = cls;
struct GNUNET_TIME_Relative rem;
fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
- (fc->first_write_done != GNUNET_YES) )
- {
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- }
+ if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
+ (fc->first_write_done != GNUNET_YES))
+ {
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready,
- fc->armServiceSocket))
- {
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_read_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &receiveFromService, fc);
- return;
- }
+ fc->armServiceSocket))
+ {
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &receiveFromService, fc);
+ return;
+ }
fc->service_to_client_bufferPos = fc->service_to_client_buffer;
fc->service_to_client_bufferDataLength =
- GNUNET_NETWORK_socket_recv (fc->armServiceSocket,
- fc->service_to_client_buffer,
- BUFFER_SIZE);
+ GNUNET_NETWORK_socket_recv (fc->armServiceSocket,
+ fc->service_to_client_buffer, BUFFER_SIZE);
if (fc->service_to_client_bufferDataLength <= 0)
- {
+ {
#if DEBUG_SERVICE_MANAGER
- if (fc->service_to_client_bufferDataLength == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' stopped sending data.\n",
- fc->listen_info->serviceName);
- }
+ if (fc->service_to_client_bufferDataLength == 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' stopped sending data.\n",
+ fc->listen_info->serviceName);
+ }
#endif
- if (fc->first_write_done != GNUNET_YES)
- {
- fc->service_to_client_bufferDataLength = 0;
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (fc->armServiceSocket));
- fc->armServiceSocket = NULL;
- if ( (fc->client_to_service_bufferDataLength > 0) &&
- (fc->client_to_service_task != GNUNET_SCHEDULER_NO_TASK) )
- {
- GNUNET_SCHEDULER_cancel (fc->client_to_service_task);
- fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK;
- }
- fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2);
+ if (fc->first_write_done != GNUNET_YES)
+ {
+ fc->service_to_client_bufferDataLength = 0;
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (fc->armServiceSocket));
+ fc->armServiceSocket = NULL;
+ if ((fc->client_to_service_bufferDataLength > 0) &&
+ (fc->client_to_service_task != GNUNET_SCHEDULER_NO_TASK))
+ {
+ GNUNET_SCHEDULER_cancel (fc->client_to_service_task);
+ fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2);
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connected to service `%s' at `%s', will try again in %llu ms\n",
- fc->listen_info->serviceName,
- GNUNET_a2s (fc->listen_info->service_addr,
- fc->listen_info->service_addr_len),
- (unsigned long long) GNUNET_TIME_relative_min (fc->back_off,
- rem).rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connected to service `%s' at `%s', will try again in %llu ms\n",
+ fc->listen_info->serviceName,
+ GNUNET_a2s (fc->listen_info->service_addr,
+ fc->listen_info->service_addr_len),
+ (unsigned long long) GNUNET_TIME_relative_min (fc->back_off,
+ rem).rel_value);
#endif
- rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
- fc->start_task
- = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_min (fc->back_off,
- rem),
- &start_forwarding,
- fc);
- }
- else
- {
+ rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
+ fc->start_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min
+ (fc->back_off, rem), &start_forwarding,
+ fc);
+ }
+ else
+ {
#if DEBUG_SERVICE_MANAGER
- if (fc->service_to_client_bufferDataLength != 0)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error receiving from service: %s\n",
- STRERROR (errno));
+ if (fc->service_to_client_bufferDataLength != 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error receiving from service: %s\n", STRERROR (errno));
#endif
- closeClientAndServiceSockets (fc, REASON_SERVICE_TO_CLIENT);
- }
- return;
+ closeClientAndServiceSockets (fc, REASON_SERVICE_TO_CLIENT);
}
+ return;
+ }
fc->first_write_done = GNUNET_YES;
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received %d bytes for client\n",
- fc->service_to_client_bufferDataLength);
+ "Received %d bytes for client\n",
+ fc->service_to_client_bufferDataLength);
#endif
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &forwardToClient, fc);
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &forwardToClient, fc);
}
@@ -559,98 +538,92 @@ receiveFromService (void *cls,
* @param tc scheduler context
*/
static void
-forwardToService (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+forwardToService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ForwardedConnection *fc = cls;
ssize_t numberOfBytesSent;
struct GNUNET_TIME_Relative rem;
fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
- (fc->first_write_done != GNUNET_YES) )
- {
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- }
+ if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
+ (fc->first_write_done != GNUNET_YES))
+ {
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready,
- fc->armServiceSocket))
- {
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &forwardToService, fc);
- return;
- }
+ fc->armServiceSocket))
+ {
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &forwardToService, fc);
+ return;
+ }
numberOfBytesSent =
- GNUNET_NETWORK_socket_send (fc->armServiceSocket,
- fc->client_to_service_bufferPos,
- fc->client_to_service_bufferDataLength);
+ GNUNET_NETWORK_socket_send (fc->armServiceSocket,
+ fc->client_to_service_bufferPos,
+ fc->client_to_service_bufferDataLength);
if (numberOfBytesSent <= 0)
+ {
+ if (GNUNET_YES != fc->first_write_done)
{
- if (GNUNET_YES != fc->first_write_done)
- {
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (fc->armServiceSocket));
- fc->armServiceSocket = NULL;
- if ( (fc->service_to_client_bufferDataLength == 0) &&
- (fc->service_to_client_task != GNUNET_SCHEDULER_NO_TASK) )
- {
- GNUNET_SCHEDULER_cancel (fc->service_to_client_task);
- fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK;
- }
- fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (fc->armServiceSocket));
+ fc->armServiceSocket = NULL;
+ if ((fc->service_to_client_bufferDataLength == 0) &&
+ (fc->service_to_client_task != GNUNET_SCHEDULER_NO_TASK))
+ {
+ GNUNET_SCHEDULER_cancel (fc->service_to_client_task);
+ fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2);
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect to service `%s' at `%s', will try again in %llu ms\n",
- fc->listen_info->serviceName,
- GNUNET_a2s (fc->listen_info->service_addr,
- fc->listen_info->service_addr_len),
- (unsigned long long) GNUNET_TIME_relative_min (fc->back_off,
- rem).rel_value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect to service `%s' at `%s', will try again in %llu ms\n",
+ fc->listen_info->serviceName,
+ GNUNET_a2s (fc->listen_info->service_addr,
+ fc->listen_info->service_addr_len),
+ (unsigned long long) GNUNET_TIME_relative_min (fc->back_off,
+ rem).rel_value);
#endif
- rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
- fc->start_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min (fc->back_off,
- rem),
- &start_forwarding,
- fc);
- }
- else
- {
- if ( (errno != EPIPE) &&
- (errno != ECONNRESET) )
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to forward data to service: %s\n",
- STRERROR (errno));
- closeClientAndServiceSockets (fc,
- REASON_CLIENT_TO_SERVICE);
- }
- return;
+ rem = GNUNET_TIME_absolute_get_remaining (fc->timeout);
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
+ fc->start_task
+ =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min
+ (fc->back_off, rem), &start_forwarding,
+ fc);
+ }
+ else
+ {
+ if ((errno != EPIPE) && (errno != ECONNRESET))
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to forward data to service: %s\n",
+ STRERROR (errno));
+ closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE);
}
+ return;
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Forwarded %d bytes to service\n",
- numberOfBytesSent);
+ "Forwarded %d bytes to service\n", numberOfBytesSent);
#endif
fc->first_write_done = GNUNET_YES;
if (numberOfBytesSent < fc->client_to_service_bufferDataLength)
- {
- fc->client_to_service_bufferPos += numberOfBytesSent;
- fc->client_to_service_bufferDataLength -= numberOfBytesSent;
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &forwardToService, fc);
- return;
- }
+ {
+ fc->client_to_service_bufferPos += numberOfBytesSent;
+ fc->client_to_service_bufferDataLength -= numberOfBytesSent;
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &forwardToService, fc);
+ return;
+ }
fc->client_to_service_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &receiveFromClient, fc);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &receiveFromClient, fc);
}
@@ -667,76 +640,73 @@ receiveFromClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK;
if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready,
- fc->armClientSocket))
- {
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &receiveFromClient, fc);
- return;
- }
+ fc->armClientSocket))
+ {
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &receiveFromClient, fc);
+ return;
+ }
fc->client_to_service_bufferPos = fc->client_to_service_buffer;
fc->client_to_service_bufferDataLength =
- GNUNET_NETWORK_socket_recv (fc->armClientSocket,
- fc->client_to_service_buffer,
- BUFFER_SIZE);
+ GNUNET_NETWORK_socket_recv (fc->armClientSocket,
+ fc->client_to_service_buffer, BUFFER_SIZE);
if (fc->client_to_service_bufferDataLength <= 0)
+ {
+ if (fc->client_to_service_bufferDataLength == 0)
{
- if (fc->client_to_service_bufferDataLength == 0)
- {
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client closed connection with service `%s'\n",
- fc->listen_info->serviceName);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client closed connection with service `%s'\n",
+ fc->listen_info->serviceName);
#endif
- }
- else
- {
+ }
+ else
+ {
#if DEBUG_SERVICE_MANAGER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error receiving from client: %s\n",
- STRERROR (errno));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error receiving from client: %s\n", STRERROR (errno));
#endif
- }
- closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE);
- return;
}
+ closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE);
+ return;
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received %d bytes for service\n",
- fc->client_to_service_bufferDataLength);
+ "Received %d bytes for service\n",
+ fc->client_to_service_bufferDataLength);
#endif
- if (fc->armServiceSocket != NULL)
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_write_net (
- GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &forwardToService, fc);
+ if (fc->armServiceSocket != NULL)
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &forwardToService, fc);
else
- /* We have not added any task with fc as a closure, so we're
- * dropping our reference to fc
- */
+ /* We have not added any task with fc as a closure, so we're
+ * dropping our reference to fc
+ */
fc->reference_count -= 1;
}
static void
-fc_acceptConnection (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+fc_acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceListeningInfo *sli = cls;
struct ForwardedConnection *fc = sli->fc;
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
- {
- GNUNET_assert (GNUNET_OK == GNUNET_NETWORK_socket_close (sli->listeningSocket));
- closeClientAndServiceSockets (fc, REASON_ERROR);
- GNUNET_free (sli);
- return;
- }
+ {
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (sli->listeningSocket));
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ GNUNET_free (sli);
+ return;
+ }
#if DEBUG_SERVICE_MANAGER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to service, now starting forwarding\n");
+ "Connected to service, now starting forwarding\n");
#endif
fc->armServiceSocket = sli->listeningSocket;
GNUNET_free (fc->listen_info->service_addr);
@@ -749,72 +719,70 @@ fc_acceptConnection (void *cls,
*/
fc->reference_count -= 1;
if (fc->client_to_service_task == GNUNET_SCHEDULER_NO_TASK)
- {
- if (fc->client_to_service_bufferDataLength == 0)
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &receiveFromClient, fc);
- else
- fc->client_to_service_task =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &forwardToService, fc);
- fc->reference_count += 1;
- }
+ {
+ if (fc->client_to_service_bufferDataLength == 0)
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &receiveFromClient, fc);
+ else
+ fc->client_to_service_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &forwardToService, fc);
+ fc->reference_count += 1;
+ }
if (fc->service_to_client_task == GNUNET_SCHEDULER_NO_TASK)
- {
- if (fc->service_to_client_bufferDataLength == 0)
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armServiceSocket,
- &receiveFromService, fc);
- else
- fc->service_to_client_task =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &forwardToClient, fc);
- fc->reference_count += 1;
- }
+ {
+ if (fc->service_to_client_bufferDataLength == 0)
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armServiceSocket,
+ &receiveFromService, fc);
+ else
+ fc->service_to_client_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &forwardToClient, fc);
+ fc->reference_count += 1;
+ }
GNUNET_free (sli);
}
static struct ServiceListeningInfo *
-service_try_to_connect (const struct sockaddr *addr,
- int pf,
- socklen_t addrlen,
- struct ForwardedConnection *fc)
+service_try_to_connect (const struct sockaddr *addr,
+ int pf,
+ socklen_t addrlen, struct ForwardedConnection *fc)
{
struct GNUNET_NETWORK_Handle *sock;
struct ServiceListeningInfo *serviceListeningInfo;
sock = GNUNET_NETWORK_socket_create (pf, SOCK_STREAM, 0);
if (sock == NULL)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
- return NULL;
- }
- if ( (GNUNET_SYSERR == GNUNET_NETWORK_socket_connect (sock, addr, addrlen)) &&
- (errno != EINPROGRESS) )
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect");
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- return NULL;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
+ return NULL;
+ }
+ if ((GNUNET_SYSERR == GNUNET_NETWORK_socket_connect (sock, addr, addrlen)) &&
+ (errno != EINPROGRESS))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect");
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ return NULL;
+ }
serviceListeningInfo = GNUNET_malloc (sizeof (struct ServiceListeningInfo));
serviceListeningInfo->serviceName = NULL;
serviceListeningInfo->service_addr = GNUNET_malloc (addrlen);
- memcpy (serviceListeningInfo->service_addr,
- addr,
- addrlen);
+ memcpy (serviceListeningInfo->service_addr, addr, addrlen);
serviceListeningInfo->service_addr_len = addrlen;
serviceListeningInfo->listeningSocket = sock;
serviceListeningInfo->fc = fc;
serviceListeningInfo->acceptTask =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- serviceListeningInfo->listeningSocket,
- &fc_acceptConnection, serviceListeningInfo);
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ serviceListeningInfo->listeningSocket,
+ &fc_acceptConnection,
+ serviceListeningInfo);
return serviceListeningInfo;
}
@@ -823,8 +791,7 @@ service_try_to_connect (const struct sockaddr *addr,
*
*/
static void
-start_forwarding (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+start_forwarding (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ForwardedConnection *fc = cls;
struct ServiceListeningInfo *sc;
@@ -835,91 +802,80 @@ start_forwarding (void *cls,
char listen_address[INET6_ADDRSTRLEN];
fc->start_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (NULL != tc) &&
- (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Unable to forward to service `%s': shutdown\n"),
- fc->listen_info->serviceName);
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- }
+ if ((NULL != tc) && (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Unable to forward to service `%s': shutdown\n"),
+ fc->listen_info->serviceName);
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
if (0 == GNUNET_TIME_absolute_get_remaining (fc->timeout).rel_value)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to forward to service `%s': timeout before connect\n"),
- fc->listen_info->serviceName);
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Unable to forward to service `%s': timeout before connect\n"),
+ fc->listen_info->serviceName);
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
switch (fc->listen_info->service_addr->sa_family)
+ {
+ case AF_UNSPEC:
+ GNUNET_break (0);
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ case AF_INET:
+ v4 = (const struct sockaddr_in *) fc->listen_info->service_addr;
+ inet_ntop (fc->listen_info->service_addr->sa_family,
+ (const void *) &v4->sin_addr, listen_address, INET_ADDRSTRLEN);
+ if (0 == strncmp (listen_address, "0.0.0.0", 7))
{
- case AF_UNSPEC:
- GNUNET_break (0);
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- case AF_INET:
- v4 = (const struct sockaddr_in *) fc->listen_info->service_addr;
- inet_ntop (fc->listen_info->service_addr->sa_family,
- (const void *) &v4->sin_addr,
- listen_address,
- INET_ADDRSTRLEN);
- if (0 == strncmp (listen_address, "0.0.0.0", 7))
- {
- /* connect to [::1] and 127.0.0.1 instead of [::] and 0.0.0.0 */
- memset (&target_ipv4, 0, sizeof (target_ipv4));
- GNUNET_assert (1 ==
- inet_pton (AF_INET,
- "127.0.0.1",
- &target_ipv4.sin_addr));
- target_ipv4.sin_family = AF_INET;
- target_ipv4.sin_port = v4->sin_port;
- v4 = &target_ipv4;
- }
- sc = service_try_to_connect ((const struct sockaddr*) v4,
- PF_INET,
- sizeof (struct sockaddr_in),
- fc);
- break;
- case AF_INET6:
- v6 = (struct sockaddr_in6 *)fc->listen_info->service_addr;
- inet_ntop (fc->listen_info->service_addr->sa_family,
- (const void *) &v6->sin6_addr,
- listen_address,
- INET6_ADDRSTRLEN);
- if ( (strncmp (listen_address, "[::]:", 5) == 0) || (strncmp (listen_address, "::", 2) == 0) )
- {
- memset (&target_ipv6, 0, sizeof (target_ipv6));
- target_ipv6.sin6_addr = in6addr_loopback;
- target_ipv6.sin6_family = AF_INET6;
- target_ipv6.sin6_port = v6->sin6_port;
- v6 = &target_ipv6;
- }
- sc = service_try_to_connect ((const struct sockaddr*) v6,
- PF_INET6,
- sizeof (struct sockaddr_in6),
- fc);
- break;
- case AF_UNIX:
- sc = service_try_to_connect (fc->listen_info->service_addr,
- PF_UNIX,
- fc->listen_info->service_addr_len,
- fc);
- break;
- default:
- GNUNET_break (0);
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
- }
- if (NULL == sc)
+ /* connect to [::1] and 127.0.0.1 instead of [::] and 0.0.0.0 */
+ memset (&target_ipv4, 0, sizeof (target_ipv4));
+ GNUNET_assert (1 ==
+ inet_pton (AF_INET, "127.0.0.1", &target_ipv4.sin_addr));
+ target_ipv4.sin_family = AF_INET;
+ target_ipv4.sin_port = v4->sin_port;
+ v4 = &target_ipv4;
+ }
+ sc = service_try_to_connect ((const struct sockaddr *) v4,
+ PF_INET, sizeof (struct sockaddr_in), fc);
+ break;
+ case AF_INET6:
+ v6 = (struct sockaddr_in6 *) fc->listen_info->service_addr;
+ inet_ntop (fc->listen_info->service_addr->sa_family,
+ (const void *) &v6->sin6_addr, listen_address, INET6_ADDRSTRLEN);
+ if ((strncmp (listen_address, "[::]:", 5) == 0) ||
+ (strncmp (listen_address, "::", 2) == 0))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("Unable to start service `%s': %s\n"),
- fc->listen_info->serviceName,
- STRERROR (errno));
- closeClientAndServiceSockets (fc, REASON_ERROR);
- return;
+ memset (&target_ipv6, 0, sizeof (target_ipv6));
+ target_ipv6.sin6_addr = in6addr_loopback;
+ target_ipv6.sin6_family = AF_INET6;
+ target_ipv6.sin6_port = v6->sin6_port;
+ v6 = &target_ipv6;
}
+ sc = service_try_to_connect ((const struct sockaddr *) v6,
+ PF_INET6, sizeof (struct sockaddr_in6), fc);
+ break;
+ case AF_UNIX:
+ sc = service_try_to_connect (fc->listen_info->service_addr,
+ PF_UNIX,
+ fc->listen_info->service_addr_len, fc);
+ break;
+ default:
+ GNUNET_break (0);
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
+ if (NULL == sc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to start service `%s': %s\n"),
+ fc->listen_info->serviceName, STRERROR (errno));
+ closeClientAndServiceSockets (fc, REASON_ERROR);
+ return;
+ }
}
@@ -932,27 +888,25 @@ stop_listening (const char *serviceName)
struct ServiceListeningInfo *pos;
struct ServiceListeningInfo *next;
int ret;
-
+
ret = GNUNET_NO;
next = serviceListeningInfoList_head;
while (NULL != (pos = next))
- {
- next = pos->next;
- if ( (serviceName != NULL) &&
- (strcmp (pos->serviceName, serviceName) != 0) )
- continue;
- if (pos->acceptTask != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (pos->acceptTask);
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (pos->listeningSocket));
- GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- pos);
- GNUNET_free (pos->serviceName);
- GNUNET_free (pos->service_addr);
- GNUNET_free (pos);
- ret = GNUNET_OK;
- }
+ {
+ next = pos->next;
+ if ((serviceName != NULL) && (strcmp (pos->serviceName, serviceName) != 0))
+ continue;
+ if (pos->acceptTask != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (pos->acceptTask);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (pos->listeningSocket));
+ GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
+ serviceListeningInfoList_tail, pos);
+ GNUNET_free (pos->serviceName);
+ GNUNET_free (pos->service_addr);
+ GNUNET_free (pos);
+ ret = GNUNET_OK;
+ }
return ret;
}
@@ -978,46 +932,44 @@ accept_and_forward (struct ServiceListeningInfo *serviceListeningInfo)
fc->service_to_client_bufferPos = fc->service_to_client_buffer;
fc->client_to_service_bufferPos = fc->client_to_service_buffer;
fc->client_addr_len = sizeof (fc->client_addr);
- fc->armClientSocket = GNUNET_NETWORK_socket_accept (serviceListeningInfo->listeningSocket,
- (struct sockaddr*) fc->client_addr,
- &fc->client_addr_len);
+ fc->armClientSocket =
+ GNUNET_NETWORK_socket_accept (serviceListeningInfo->listeningSocket,
+ (struct sockaddr *) fc->client_addr,
+ &fc->client_addr_len);
if (NULL == fc->armClientSocket)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to accept connection for service `%s': %s\n"),
- serviceListeningInfo->serviceName,
- STRERROR (errno));
- GNUNET_free (fc);
- GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- serviceListeningInfo);
- serviceListeningInfo->acceptTask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- serviceListeningInfo->listeningSocket,
- &acceptConnection,
- serviceListeningInfo);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to accept connection for service `%s': %s\n"),
+ serviceListeningInfo->serviceName, STRERROR (errno));
+ GNUNET_free (fc);
+ GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head,
+ serviceListeningInfoList_tail,
+ serviceListeningInfo);
+ serviceListeningInfo->acceptTask =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ serviceListeningInfo->listeningSocket,
+ &acceptConnection, serviceListeningInfo);
+ return;
+ }
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (serviceListeningInfo->listeningSocket));
+ GNUNET_NETWORK_socket_close
+ (serviceListeningInfo->listeningSocket));
start_service (NULL, serviceListeningInfo->serviceName, NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' started\n"),
- fc->listen_info->serviceName);
- fc->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_SERVICE_TIMEOUT);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Service `%s' started\n"), fc->listen_info->serviceName);
+ fc->timeout =
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_SERVICE_TIMEOUT);
fc->back_off = GNUNET_TIME_UNIT_MILLISECONDS;
fc->client_to_service_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- fc->armClientSocket,
- &receiveFromClient, fc);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ fc->armClientSocket,
+ &receiveFromClient, fc);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task);
/* We're creating another chain of tasks for this fc that
* will have its own reference to it.
*/
fc->reference_count += 1;
- fc->start_task
- = GNUNET_SCHEDULER_add_now (&start_forwarding,
- fc);
+ fc->start_task = GNUNET_SCHEDULER_add_now (&start_forwarding, fc);
}
@@ -1042,59 +994,54 @@ acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
return;
GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- sli);
+ serviceListeningInfoList_tail, sli);
#ifndef MINGW
use_lsocks = GNUNET_NO;
if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg,
- sli->serviceName,
- "DISABLE_SOCKET_FORWARDING"))
+ sli->serviceName,
+ "DISABLE_SOCKET_FORWARDING"))
use_lsocks = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- sli->serviceName,
- "DISABLE_SOCKET_FORWARDING");
+ sli->serviceName,
+ "DISABLE_SOCKET_FORWARDING");
#else
use_lsocks = GNUNET_YES;
#endif
if (GNUNET_NO != use_lsocks)
- {
- accept_and_forward (sli);
- return;
- }
+ {
+ accept_and_forward (sli);
+ return;
+ }
lsocks = NULL;
ls = 0;
next = serviceListeningInfoList_head;
while (NULL != (pos = next))
+ {
+ next = pos->next;
+ if (0 == strcmp (pos->serviceName, sli->serviceName))
{
- next = pos->next;
- if (0 == strcmp (pos->serviceName,
- sli->serviceName))
- {
- GNUNET_array_append (lsocks, ls,
- GNUNET_NETWORK_get_fd (pos->listeningSocket));
- GNUNET_free (pos->listeningSocket); /* deliberately no closing! */
- GNUNET_free (pos->service_addr);
- GNUNET_free (pos->serviceName);
- GNUNET_SCHEDULER_cancel (pos->acceptTask);
- GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- pos);
- GNUNET_free (pos);
- }
+ GNUNET_array_append (lsocks, ls,
+ GNUNET_NETWORK_get_fd (pos->listeningSocket));
+ GNUNET_free (pos->listeningSocket); /* deliberately no closing! */
+ GNUNET_free (pos->service_addr);
+ GNUNET_free (pos->serviceName);
+ GNUNET_SCHEDULER_cancel (pos->acceptTask);
+ GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head,
+ serviceListeningInfoList_tail, pos);
+ GNUNET_free (pos);
}
- GNUNET_array_append (lsocks, ls,
- GNUNET_NETWORK_get_fd (sli->listeningSocket));
- GNUNET_free (sli->listeningSocket); /* deliberately no closing! */
+ }
+ GNUNET_array_append (lsocks, ls,
+ GNUNET_NETWORK_get_fd (sli->listeningSocket));
+ GNUNET_free (sli->listeningSocket); /* deliberately no closing! */
GNUNET_free (sli->service_addr);
GNUNET_array_append (lsocks, ls, -1);
- start_service (NULL,
- sli->serviceName,
- lsocks);
+ start_service (NULL, sli->serviceName, lsocks);
ls = 0;
while (lsocks[ls] != -1)
- GNUNET_break (0 == close (lsocks[ls++]));
+ GNUNET_break (0 == close (lsocks[ls++]));
GNUNET_array_grow (lsocks, ls, 0);
GNUNET_free (sli->serviceName);
- GNUNET_free (sli);
+ GNUNET_free (sli);
}
@@ -1107,89 +1054,84 @@ acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
* @param serviceName the name of the service in question
*/
static void
-createListeningSocket(struct sockaddr *sa, socklen_t addr_len,
- const char *serviceName)
+createListeningSocket (struct sockaddr *sa, socklen_t addr_len,
+ const char *serviceName)
{
const static int on = 1;
struct GNUNET_NETWORK_Handle *sock;
struct ServiceListeningInfo *serviceListeningInfo;
switch (sa->sa_family)
- {
- case AF_INET:
- sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
- break;
- case AF_INET6:
- sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
- break;
- case AF_UNIX:
- if (strcmp(GNUNET_a2s (sa, addr_len), "@") == 0) /* Do not bind to blank UNIX path! */
- return;
- sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
- break;
- default:
- GNUNET_break (0);
- sock = NULL;
- errno = EAFNOSUPPORT;
- break;
- }
- if (NULL == sock)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to create socket for service `%s': %s\n"),
- serviceName,
- STRERROR (errno));
- GNUNET_free (sa);
+ {
+ case AF_INET:
+ sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
+ break;
+ case AF_INET6:
+ sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
+ break;
+ case AF_UNIX:
+ if (strcmp (GNUNET_a2s (sa, addr_len), "@") == 0) /* Do not bind to blank UNIX path! */
return;
- }
+ sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
+ break;
+ default:
+ GNUNET_break (0);
+ sock = NULL;
+ errno = EAFNOSUPPORT;
+ break;
+ }
+ if (NULL == sock)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to create socket for service `%s': %s\n"),
+ serviceName, STRERROR (errno));
+ GNUNET_free (sa);
+ return;
+ }
if (GNUNET_NETWORK_socket_setsockopt
(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"setsockopt");
#ifdef IPV6_V6ONLY
- if ( (sa->sa_family == AF_INET6) &&
- (GNUNET_NETWORK_socket_setsockopt
- (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK))
+ if ((sa->sa_family == AF_INET6) &&
+ (GNUNET_NETWORK_socket_setsockopt
+ (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ "setsockopt");
#endif
if (GNUNET_NETWORK_socket_bind
(sock, (const struct sockaddr *) sa, addr_len) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Unable to bind listening socket for service `%s' to address `%s': %s\n"),
- serviceName,
- GNUNET_a2s (sa, addr_len),
- STRERROR (errno));
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- GNUNET_free (sa);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Unable to bind listening socket for service `%s' to address `%s': %s\n"),
+ serviceName, GNUNET_a2s (sa, addr_len), STRERROR (errno));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ GNUNET_free (sa);
+ return;
+ }
if (GNUNET_NETWORK_socket_listen (sock, 5) != GNUNET_OK)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "listen");
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- GNUNET_free (sa);
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ GNUNET_free (sa);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("ARM now monitors connections to service `%s' at `%s'\n"),
- serviceName,
- GNUNET_a2s (sa, addr_len));
+ _("ARM now monitors connections to service `%s' at `%s'\n"),
+ serviceName, GNUNET_a2s (sa, addr_len));
serviceListeningInfo = GNUNET_malloc (sizeof (struct ServiceListeningInfo));
serviceListeningInfo->serviceName = GNUNET_strdup (serviceName);
serviceListeningInfo->service_addr = sa;
serviceListeningInfo->service_addr_len = addr_len;
serviceListeningInfo->listeningSocket = sock;
serviceListeningInfo->acceptTask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sock,
- &acceptConnection,
- serviceListeningInfo);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sock,
+ &acceptConnection, serviceListeningInfo);
GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head,
- serviceListeningInfoList_tail,
- serviceListeningInfo);
+ serviceListeningInfoList_tail,
+ serviceListeningInfo);
}
@@ -1204,22 +1146,20 @@ createListeningSocket(struct sockaddr *sa, socklen_t addr_len,
*/
static void
checkPortNumberCB (void *cls,
- const char *section,
- const char *option,
- const char *value)
+ const char *section, const char *option, const char *value)
{
struct sockaddr **addrs;
socklen_t *addr_lens;
int ret;
unsigned int i;
-
- if ( (strcasecmp (section, "arm") == 0) ||
- (strcasecmp (option, "AUTOSTART") != 0) ||
- (strcasecmp (value, "YES") != 0) ||
- (isInDefaultList (section) == GNUNET_YES) )
+
+ if ((strcasecmp (section, "arm") == 0) ||
+ (strcasecmp (option, "AUTOSTART") != 0) ||
+ (strcasecmp (value, "YES") != 0) ||
+ (isInDefaultList (section) == GNUNET_YES))
return;
if (0 >= (ret = GNUNET_SERVICE_get_server_addresses (section, cfg, &addrs,
- &addr_lens)))
+ &addr_lens)))
return;
/* this will free (or capture) addrs[i] */
for (i = 0; i < ret; i++)
@@ -1235,8 +1175,7 @@ checkPortNumberCB (void *cls,
* @param configurationHandle configuration to use to get services
*/
void
-prepareServices (const struct GNUNET_CONFIGURATION_Handle
- *configurationHandle)
+prepareServices (const struct GNUNET_CONFIGURATION_Handle *configurationHandle)
{
char *defaultServicesString;
@@ -1244,13 +1183,13 @@ prepareServices (const struct GNUNET_CONFIGURATION_Handle
/* Split the default services into a list */
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, "arm", "DEFAULTSERVICES",
- &defaultServicesString))
- {
- addDefaultServicesToList (defaultServicesString);
- GNUNET_free (defaultServicesString);
- }
+ &defaultServicesString))
+ {
+ addDefaultServicesToList (defaultServicesString);
+ GNUNET_free (defaultServicesString);
+ }
/* Spot the services from the configuration and create a listening
- socket for each */
+ * socket for each */
GNUNET_CONFIGURATION_iterate (cfg, &checkPortNumberCB, NULL);
}
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c
index 4dae8ffb4..0a0e1de5a 100644
--- a/src/arm/mockup-service.c
+++ b/src/arm/mockup-service.c
@@ -36,21 +36,20 @@ transmit_shutdown_ack (void *cls, size_t size, void *buf)
struct GNUNET_MessageHeader *msg;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Failed to transmit shutdown ACK.\n"));
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return 0; /* client disconnected */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Failed to transmit shutdown ACK.\n"));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return 0; /* client disconnected */
+ }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Transmitting shutdown ACK.\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting shutdown ACK.\n"));
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
GNUNET_SERVER_receive_done (client, GNUNET_OK);
- GNUNET_SERVER_client_drop(client);
+ GNUNET_SERVER_client_drop (client);
return sizeof (struct GNUNET_MessageHeader);
}
@@ -66,12 +65,12 @@ handle_shutdown (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_SERVER_client_keep(client);
+ GNUNET_SERVER_client_keep (client);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Initiating shutdown as requested by client.\n"));
GNUNET_SERVER_notify_transmit_ready (client,
- sizeof(struct GNUNET_MessageHeader),
+ sizeof (struct GNUNET_MessageHeader),
GNUNET_TIME_UNIT_FOREVER_REL,
&transmit_shutdown_ack, client);
GNUNET_SERVER_client_persist_ (client);
@@ -95,14 +94,15 @@ run (void *cls,
}
-int main(int argc, char *const *argv)
+int
+main (int argc, char *const *argv)
{
int ret;
-
+
ret = (GNUNET_OK ==
- GNUNET_SERVICE_run (argc,
+ GNUNET_SERVICE_run (argc,
argv,
"do-nothing", GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ &run, NULL)) ? 0 : 1;
return ret;
}
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c
index cce5867f1..1e9d84202 100644
--- a/src/arm/test_arm_api.c
+++ b/src/arm/test_arm_api.c
@@ -47,7 +47,7 @@ static int ok = 1;
static void
arm_stopped (void *cls, int success)
{
- if (success != GNUNET_NO)
+ if (success != GNUNET_NO)
ok = 3;
else if (ok == 1)
ok = 0;
@@ -67,15 +67,15 @@ static void
dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
if (addr == NULL)
+ {
+ if (ok != 0)
{
- if (ok != 0)
- {
- GNUNET_break (0);
- ok = 2;
- }
- GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop, NULL);
- return;
+ GNUNET_break (0);
+ ok = 2;
}
+ GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop, NULL);
+ return;
+ }
GNUNET_assert (addr != NULL);
ok = 0;
}
@@ -85,14 +85,14 @@ static void
resolver_notify (void *cls, int success)
{
if (success != GNUNET_YES)
- {
- GNUNET_break (0);
- ok = 2;
+ {
+ GNUNET_break (0);
+ ok = 2;
#if START_ARM
- GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+ GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
#endif
- return;
- }
+ return;
+ }
GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL);
}
@@ -101,22 +101,22 @@ static void
arm_notify (void *cls, int success)
{
if (success != GNUNET_YES)
- {
- GNUNET_break (0);
- ok = 2;
+ {
+ GNUNET_break (0);
+ ok = 2;
#if START_ARM
- GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+ GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
#endif
- }
- GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify, NULL);
+ }
+ GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify,
+ NULL);
}
static void
task (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
arm = GNUNET_ARM_connect (cfg, NULL);
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c
index f40252a03..eb6421d5f 100644
--- a/src/arm/test_exponential_backoff.c
+++ b/src/arm/test_exponential_backoff.c
@@ -102,58 +102,55 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct ShutdownContext *shutdown_ctx = cls;
- if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES))
- {
- /* Means the other side closed the connection and never confirmed a shutdown */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Service handle shutdown before ACK!\n");
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
+ if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES))
+ {
+ /* Means the other side closed the connection and never confirmed a shutdown */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Service handle shutdown before ACK!\n");
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ }
else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES))
- {
+ {
#if VERBOSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Service shutdown complete.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
#endif
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO);
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO);
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- }
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ }
else
+ {
+ GNUNET_assert (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader));
+ switch (ntohs (msg->type))
{
- GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
- switch (ntohs(msg->type))
- {
- case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK:
+ case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK:
#if VERBOSE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received confirmation for service shutdown.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received confirmation for service shutdown.\n");
#endif
- shutdown_ctx->confirmed = GNUNET_YES;
- GNUNET_CLIENT_receive (shutdown_ctx->sock,
- &service_shutdown_handler,
- shutdown_ctx,
- GNUNET_TIME_UNIT_FOREVER_REL);
- break;
- default: /* Fall through */
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Service shutdown refused!\n");
- if (shutdown_ctx->cont != NULL)
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES);
-
- GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- break;
- }
+ shutdown_ctx->confirmed = GNUNET_YES;
+ GNUNET_CLIENT_receive (shutdown_ctx->sock,
+ &service_shutdown_handler,
+ shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
+ break;
+ default: /* Fall through */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Service shutdown refused!\n");
+ if (shutdown_ctx->cont != NULL)
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES);
+
+ GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ break;
}
+ }
}
/**
@@ -162,14 +159,16 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
* @param cls closure
* @param tc context information (why was this task triggered now)
*/
-void service_shutdown_cancel (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext * tc)
+void
+service_shutdown_cancel (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ShutdownContext *shutdown_ctx = cls;
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n");
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n");
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
+ GNUNET_free (shutdown_ctx);
}
@@ -189,21 +188,22 @@ write_shutdown (void *cls, size_t size, void *buf)
struct ShutdownContext *shutdown_ctx = cls;
if (size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to transmit shutdown request to client.\n"));
- shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
- GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
- GNUNET_free(shutdown_ctx);
- return 0; /* client disconnected */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to transmit shutdown request to client.\n"));
+ shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
+ GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
+ GNUNET_free (shutdown_ctx);
+ return 0; /* client disconnected */
+ }
GNUNET_CLIENT_receive (shutdown_ctx->sock,
- &service_shutdown_handler, shutdown_ctx,
- GNUNET_TIME_UNIT_FOREVER_REL);
- shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout),
- &service_shutdown_cancel,
- shutdown_ctx);
+ &service_shutdown_handler, shutdown_ctx,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ shutdown_ctx->cancel_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (shutdown_ctx->timeout),
+ &service_shutdown_cancel, shutdown_ctx);
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -226,22 +226,22 @@ write_shutdown (void *cls, size_t size, void *buf)
*/
static void
arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CLIENT_ShutdownTask cont,
- void *cont_cls)
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CLIENT_ShutdownTask cont, void *cont_cls)
{
struct ShutdownContext *shutdown_ctx;
- shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext));
+
+ shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext));
shutdown_ctx->cont = cont;
shutdown_ctx->cont_cls = cont_cls;
shutdown_ctx->sock = sock;
- shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout);
+ shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
GNUNET_CLIENT_notify_transmit_ready (sock,
- sizeof (struct
- GNUNET_MessageHeader),
- timeout,
- GNUNET_NO,
- &write_shutdown, shutdown_ctx);
+ sizeof (struct
+ GNUNET_MessageHeader),
+ timeout,
+ GNUNET_NO,
+ &write_shutdown, shutdown_ctx);
}
@@ -256,8 +256,7 @@ arm_notify_stop (void *cls, int success)
static void
-kill_task (void *cbData,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
@@ -265,65 +264,55 @@ do_nothing_notify (void *cls, int success)
{
GNUNET_assert (success == GNUNET_YES);
ok = 1;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &kill_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL);
}
static void
arm_notify (void *cls, int success)
-{
+{
GNUNET_assert (success == GNUNET_YES);
- GNUNET_ARM_start_service (arm,
- "do-nothing", TIMEOUT,
- &do_nothing_notify, NULL);
+ GNUNET_ARM_start_service (arm,
+ "do-nothing", TIMEOUT, &do_nothing_notify, NULL);
}
static void
-kill_task (void *cbData,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc);
static void
do_nothing_restarted_notify_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
static char a;
-
+
trialCount++;
-#if LOG_BACKOFF
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- {
- fprintf(killLogFilePtr,
- "%d.Reason is shutdown!\n",
- trialCount);
- }
- else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
- {
- fprintf(killLogFilePtr,
- "%d.Reason is timeout!\n",
- trialCount);
- }
- else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0)
- {
- fprintf(killLogFilePtr,
- "%d.Service is running!\n",
- trialCount);
- }
+#if LOG_BACKOFF
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
+ fprintf (killLogFilePtr, "%d.Reason is shutdown!\n", trialCount);
+ }
+ else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0)
+ {
+ fprintf (killLogFilePtr, "%d.Reason is timeout!\n", trialCount);
+ }
+ else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0)
+ {
+ fprintf (killLogFilePtr, "%d.Service is running!\n", trialCount);
+ }
#endif
GNUNET_SCHEDULER_add_now (&kill_task, &a);
}
static void
-do_test (void *cbData,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- GNUNET_CLIENT_service_test("do-nothing",
- cfg, TIMEOUT,
- &do_nothing_restarted_notify_task, NULL);
+do_test (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_CLIENT_service_test ("do-nothing",
+ cfg, TIMEOUT,
+ &do_nothing_restarted_notify_task, NULL);
}
@@ -331,63 +320,56 @@ static void
shutdown_cont (void *cls, int reason)
{
trialCount++;
- startedWaitingAt = GNUNET_TIME_absolute_get();
- GNUNET_SCHEDULER_add_delayed (waitedFor,
- &do_test,
- NULL);
+ startedWaitingAt = GNUNET_TIME_absolute_get ();
+ GNUNET_SCHEDULER_add_delayed (waitedFor, &do_test, NULL);
}
static void
-kill_task (void *cbData,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- static struct GNUNET_CLIENT_Connection * doNothingConnection = NULL;
+ static struct GNUNET_CLIENT_Connection *doNothingConnection = NULL;
+
+ if (NULL != cbData)
+ {
+ waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);
- if (NULL != cbData)
- {
- waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);
-
#if LOG_BACKOFF
- fprintf(killLogFilePtr,
- "Waited for: %llu ms\n",
- (unsigned long long) waitedFor.rel_value);
+ fprintf (killLogFilePtr,
+ "Waited for: %llu ms\n", (unsigned long long) waitedFor.rel_value);
#endif
- }
+ }
else
- {
- waitedFor.rel_value = 0;
- }
+ {
+ waitedFor.rel_value = 0;
+ }
/* Connect to the doNothing task */
doNothingConnection = GNUNET_CLIENT_connect ("do-nothing", cfg);
GNUNET_assert (doNothingConnection != NULL);
- if (trialCount == 12) {
+ if (trialCount == 12)
+ {
GNUNET_CLIENT_disconnect (doNothingConnection, GNUNET_NO);
- GNUNET_ARM_stop_service (arm,
- "do-nothing",
- TIMEOUT,
- &arm_notify_stop, NULL);
+ GNUNET_ARM_stop_service (arm,
+ "do-nothing", TIMEOUT, &arm_notify_stop, NULL);
ok = 0;
return;
}
/* Use the created connection to kill the doNothingTask */
- arm_service_shutdown(doNothingConnection,
- TIMEOUT,
- &shutdown_cont, NULL);
+ arm_service_shutdown (doNothingConnection, TIMEOUT, &shutdown_cont, NULL);
}
-
+
static void
task (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
-
- arm = GNUNET_ARM_connect (cfg,NULL);
+
+ arm = GNUNET_ARM_connect (cfg, NULL);
#if START_ARM
- GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify, NULL);
+ GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify,
+ NULL);
#else
arm_do_nothing (NULL, GNUNET_YES);
#endif
@@ -407,39 +389,41 @@ check ()
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
-
+
/* Running ARM and running the do_nothing task */
GNUNET_assert (GNUNET_OK ==
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
argv,
"test-exponential-backoff",
"nohelp", options, &task, NULL));
-
-
+
+
return ok;
}
static int
-init()
+init ()
{
#if LOG_BACKOFF
- killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log");
- if (NULL == (killLogFilePtr = FOPEN(killLogFileName, "w"))) {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", killLogFileName);
+ killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log");
+ if (NULL == (killLogFilePtr = FOPEN (killLogFileName, "w")))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen",
+ killLogFileName);
GNUNET_free (killLogFileName);
return GNUNET_SYSERR;
- }
+ }
#endif
return GNUNET_OK;
}
static void
-houseKeep()
+houseKeep ()
{
#if LOG_BACKOFF
GNUNET_assert (0 == fclose (killLogFilePtr));
- GNUNET_free(killLogFileName);
+ GNUNET_free (killLogFileName);
#endif
}
@@ -456,10 +440,10 @@ main (int argc, char *argv[])
"WARNING",
#endif
NULL);
-
- init();
+
+ init ();
ret = check ();
- houseKeep();
+ houseKeep ();
return ret;
}
diff --git a/src/arm/test_gnunet_service_manager.c b/src/arm/test_gnunet_service_manager.c
index 087e01ccb..4c4de9242 100644
--- a/src/arm/test_gnunet_service_manager.c
+++ b/src/arm/test_gnunet_service_manager.c
@@ -53,41 +53,36 @@ static struct GNUNET_ARM_Handle *arm;
static void
arm_stopped (void *cls, int success)
{
- if (success != GNUNET_NO)
- {
- GNUNET_break (0);
- ret = 4;
- }
+ if (success != GNUNET_NO)
+ {
+ GNUNET_break (0);
+ ret = 4;
+ }
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM stopped\n");
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM stopped\n");
+ }
#if START_ARM
GNUNET_ARM_disconnect (arm);
arm = NULL;
#endif
}
-static void
-hostNameResolveCB(void *cls,
- const struct sockaddr *addr,
- socklen_t addrlen)
+static void
+hostNameResolveCB (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
- if ( (ret == 0) || (ret == 4) )
+ if ((ret == 0) || (ret == 4))
return;
if (NULL == addr)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Name not resolved!\n");
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Name not resolved!\n");
#if START_ARM
- GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+ GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
#endif
- ret = 3;
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Resolved hostname, now stopping ARM\n");
+ ret = 3;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolved hostname, now stopping ARM\n");
ret = 0;
#if START_ARM
GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
@@ -99,34 +94,31 @@ static void
arm_notify (void *cls, int success)
{
if (success != GNUNET_YES)
- {
- GNUNET_break (0);
- ret = 1;
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to resolve our own hostname!\n");
+ {
+ GNUNET_break (0);
+ ret = 1;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to resolve our own hostname!\n");
/* connect to the resolver service */
if (NULL == GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC,
- TIMEOUT,
- &hostNameResolveCB,
- NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable initiate connection to resolver service\n");
- ret = 2;
+ TIMEOUT,
+ &hostNameResolveCB, NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unable initiate connection to resolver service\n");
+ ret = 2;
#if START_ARM
- GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+ GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
#endif
- }
+ }
}
static void
-run(void *cls,
- char * const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+run (void *cls,
+ char *const *args,
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
#if START_ARM
@@ -139,7 +131,7 @@ run(void *cls,
static void
-check()
+check ()
{
char *const argv[] = {
"test-gnunet-service-manager",
@@ -153,39 +145,40 @@ check()
GNUNET_GETOPT_OPTION_END
};
GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv,
- "test-gnunet-service-manager",
- "nohelp", options, &run, NULL));
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+ argv,
+ "test-gnunet-service-manager",
+ "nohelp", options, &run, NULL));
}
int
main (int argc, char *argv[])
{
- char hostname[GNUNET_OS_get_hostname_max_length() + 1];
+ char hostname[GNUNET_OS_get_hostname_max_length () + 1];
if (0 != gethostname (hostname, sizeof (hostname) - 1))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
- GNUNET_ERROR_TYPE_BULK, "gethostname");
- fprintf (stderr, "Failed to determine my own hostname, testcase not run.\n");
- return 0;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
+ GNUNET_ERROR_TYPE_BULK, "gethostname");
+ fprintf (stderr,
+ "Failed to determine my own hostname, testcase not run.\n");
+ return 0;
+ }
if (NULL == gethostbyname (hostname))
- {
- fprintf (stderr, "Failed to resolve my hostname `%s', testcase not run.\n",
- hostname);
- return 0;
- }
+ {
+ fprintf (stderr, "Failed to resolve my hostname `%s', testcase not run.\n",
+ hostname);
+ return 0;
+ }
- GNUNET_log_setup("test-gnunet-service-manager",
+ GNUNET_log_setup ("test-gnunet-service-manager",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
- check();
+ NULL);
+ check ();
return ret;
}
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c
index 9400b1f30..6cd8a82ba 100644
--- a/src/ats/ats_api.c
+++ b/src/ats/ats_api.c
@@ -67,7 +67,7 @@ struct AllocationRecord
/**
* Number of bytes in plugin_addr.
*/
- size_t plugin_addr_len;
+ size_t plugin_addr_len;
/**
* Number of entries in 'ats'.
@@ -105,12 +105,12 @@ struct GNUNET_ATS_SuggestionContext
/**
* Global ATS handle.
- */
+ */
struct GNUNET_ATS_Handle *atc;
/**
* Which peer are we monitoring?
- */
+ */
struct GNUNET_PeerIdentity target;
};
@@ -169,13 +169,11 @@ struct GNUNET_ATS_Handle
* @return GNUNET_YES (continue iteration)
*/
static int
-count_connections (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+count_connections (void *cls, const GNUNET_HashCode * key, void *value)
{
unsigned int *ac = cls;
struct AllocationRecord *ar = value;
-
+
if (GNUNET_YES == ar->connected)
(*ac)++;
return GNUNET_YES;
@@ -208,35 +206,29 @@ struct SetBandwidthContext
* @return GNUNET_YES (continue iteration)
*/
static int
-set_bw_connections (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
{
struct SetBandwidthContext *sbc = cls;
struct AllocationRecord *ar = value;
-
+
if (GNUNET_YES == ar->connected)
- {
- ar->bandwidth = sbc->bw;
- sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
- (const struct GNUNET_PeerIdentity*) key,
- ar->plugin_name,
- ar->session,
- ar->plugin_addr,
- ar->plugin_addr_len,
- ar->bandwidth);
- }
- else if (ntohl(ar->bandwidth.value__) > 0)
- {
- ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
- sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
- (const struct GNUNET_PeerIdentity*) key,
- ar->plugin_name,
- ar->session,
- ar->plugin_addr,
- ar->plugin_addr_len,
- ar->bandwidth);
- }
+ {
+ ar->bandwidth = sbc->bw;
+ sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
+ (const struct GNUNET_PeerIdentity *) key,
+ ar->plugin_name,
+ ar->session,
+ ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
+ }
+ else if (ntohl (ar->bandwidth.value__) > 0)
+ {
+ ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
+ sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
+ (const struct GNUNET_PeerIdentity *) key,
+ ar->plugin_name,
+ ar->session,
+ ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
+ }
return GNUNET_YES;
}
@@ -246,10 +238,9 @@ set_bw_connections (void *cls,
*
* @param cls the 'struct GNUNET_ATS_Handle'
* @param tc scheduler context
- */
+ */
static void
-update_bandwidth_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_ATS_Handle *atc = cls;
unsigned int ac;
@@ -257,14 +248,10 @@ update_bandwidth_task (void *cls,
atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
/* FIXME: update calculations NICELY; what follows is a naive version */
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &count_connections,
- &ac);
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &count_connections, &ac);
bwc.atc = atc;
bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac);
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &set_bw_connections,
- &bwc);
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &set_bw_connections, &bwc);
}
@@ -276,12 +263,11 @@ update_bandwidth_task (void *cls,
*/
static void
update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc,
- struct AllocationRecord *change)
+ struct AllocationRecord *change)
{
/* FIXME: based on the 'change', update the LP-problem... */
if (atc->ba_task == GNUNET_SCHEDULER_NO_TASK)
- atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task,
- atc);
+ atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task, atc);
}
@@ -294,21 +280,19 @@ update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc,
* @return GNUNET_NO if we're done, GNUNET_YES if we did not suggest an address yet
*/
static int
-suggest_address (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_ATS_SuggestionContext *asc = cls;
struct AllocationRecord *ar = value;
-
+
/* trivial strategy: pick first available address... */
asc->cb (asc->cb_cls,
- &asc->target,
- ar->plugin_name,
- ar->plugin_addr,
- ar->plugin_addr_len,
- GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
- ar->ats, ar->ats_count);
+ &asc->target,
+ ar->plugin_name,
+ ar->plugin_addr,
+ ar->plugin_addr_len,
+ GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
+ ar->ats, ar->ats_count);
asc->cb = NULL;
return GNUNET_NO;
}
@@ -325,9 +309,9 @@ suggest_address (void *cls,
*/
struct GNUNET_ATS_SuggestionContext *
GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- GNUNET_ATS_AddressSuggestionCallback cb,
- void *cb_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ GNUNET_ATS_AddressSuggestionCallback cb,
+ void *cb_cls)
{
struct GNUNET_ATS_SuggestionContext *asc;
@@ -338,17 +322,16 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
asc->target = *peer;
GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
&peer->hashPubKey,
- &suggest_address,
- asc);
+ &suggest_address, asc);
if (NULL == asc->cb)
- {
- GNUNET_free (asc);
- return NULL;
- }
+ {
+ GNUNET_free (asc);
+ return NULL;
+ }
GNUNET_CONTAINER_multihashmap_put (atc->notify_map,
- &peer->hashPubKey,
- asc,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ &peer->hashPubKey,
+ asc,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
return asc;
}
@@ -362,9 +345,9 @@ void
GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc)
{
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map,
- &asc->target.hashPubKey,
- asc));
+ GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map,
+ &asc->target.hashPubKey,
+ asc));
GNUNET_free (asc);
}
@@ -379,8 +362,8 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc)
*/
struct GNUNET_ATS_Handle *
GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
- void *alloc_cb_cls)
+ GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb,
+ void *alloc_cb_cls)
{
struct GNUNET_ATS_Handle *atc;
@@ -390,9 +373,8 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
atc->alloc_cb_cls = alloc_cb_cls;
atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
GNUNET_CONFIGURATION_get_value_number (cfg,
- "core",
- "TOTAL_QUOTA_OUT",
- &atc->total_bps);
+ "core",
+ "TOTAL_QUOTA_OUT", &atc->total_bps);
return atc;
}
@@ -406,9 +388,7 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @return GNUNET_OK (continue to iterate)
*/
static int
-destroy_allocation_record (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+destroy_allocation_record (void *cls, const GNUNET_HashCode * key, void *value)
{
struct AllocationRecord *ar = value;
@@ -428,13 +408,12 @@ void
GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc)
{
if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task)
- {
- GNUNET_SCHEDULER_cancel (atc->ba_task);
- atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (atc->ba_task);
+ atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &destroy_allocation_record,
- NULL);
+ &destroy_allocation_record, NULL);
GNUNET_CONTAINER_multihashmap_destroy (atc->peers);
GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0);
GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map);
@@ -470,9 +449,7 @@ struct UpdateSessionContext
* GNUNET_NO if the record do match and 'old' was updated
*/
static int
-update_session (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+update_session (void *cls, const GNUNET_HashCode * key, void *value)
{
struct UpdateSessionContext *usc = cls;
struct AllocationRecord *arnew = usc->arnew;
@@ -481,32 +458,30 @@ update_session (void *cls,
if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
return GNUNET_YES;
- if ( (arnew->session == arold->session) ||
- ( (arold->session == NULL) &&
- (arold->plugin_addr_len == arnew->plugin_addr_len) &&
- (0 == memcmp (arold->plugin_addr,
- arnew->plugin_addr,
- arnew->plugin_addr_len)) ) )
+ if ((arnew->session == arold->session) ||
+ ((arold->session == NULL) &&
+ (arold->plugin_addr_len == arnew->plugin_addr_len) &&
+ (0 == memcmp (arold->plugin_addr,
+ arnew->plugin_addr, arnew->plugin_addr_len))))
+ {
+ change = GNUNET_NO;
+ /* records match */
+ if (arnew->session != arold->session)
+ {
+ arold->session = arnew->session;
+ change = GNUNET_YES;
+ }
+ if ((arnew->connected == GNUNET_YES) && (arold->connected == GNUNET_NO))
{
- change = GNUNET_NO;
- /* records match */
- if (arnew->session != arold->session)
- {
- arold->session = arnew->session;
- change = GNUNET_YES;
- }
- if ( (arnew->connected == GNUNET_YES) &&
- (arold->connected == GNUNET_NO) )
- {
- arold->connected = GNUNET_YES;
- change = GNUNET_YES;
- }
- // FIXME: merge ats arrays of (arold, arnew);
-
- if (GNUNET_YES == change)
- update_bandwidth_assignment (usc->atc, arold);
- return GNUNET_NO;
+ arold->connected = GNUNET_YES;
+ change = GNUNET_YES;
}
+ // FIXME: merge ats arrays of (arold, arnew);
+
+ if (GNUNET_YES == change)
+ update_bandwidth_assignment (usc->atc, arold);
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -523,11 +498,11 @@ update_session (void *cls,
*/
static struct AllocationRecord *
create_allocation_record (const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct AllocationRecord *ar;
@@ -537,12 +512,9 @@ create_allocation_record (const char *plugin_name,
memcpy (&ar[1], plugin_addr, plugin_addr_len);
ar->session = session;
ar->plugin_addr_len = plugin_addr_len;
- GNUNET_array_grow (ar->ats,
- ar->ats_count,
- ats_count);
- memcpy (ar->ats,
- ats,
- ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
+ memcpy (ar->ats,
+ ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
return ar;
}
@@ -556,18 +528,16 @@ create_allocation_record (const char *plugin_name,
* @return GNUNET_OK (continue to iterate)
*/
static int
-disconnect_peer (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+disconnect_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_ATS_Handle *atc = cls;
struct AllocationRecord *ar = value;
if (GNUNET_YES == ar->connected)
- {
- ar->connected = GNUNET_NO;
- update_bandwidth_assignment (atc, ar);
- }
+ {
+ ar->connected = GNUNET_NO;
+ update_bandwidth_assignment (atc, ar);
+ }
return GNUNET_OK;
}
@@ -588,42 +558,36 @@ disconnect_peer (void *cls,
*/
void
GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct AllocationRecord *ar;
struct UpdateSessionContext usc;
(void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &disconnect_peer,
- atc);
+ &disconnect_peer, atc);
ar = create_allocation_record (plugin_name,
- session,
- plugin_addr,
- plugin_addr_len,
- ats,
- ats_count);
+ session,
+ plugin_addr, plugin_addr_len, ats, ats_count);
ar->connected = GNUNET_YES;
usc.atc = atc;
usc.arnew = ar;
if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &update_session,
- &usc))
- {
- destroy_allocation_record (NULL, &peer->hashPubKey, ar);
- return;
- }
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session, &usc))
+ {
+ destroy_allocation_record (NULL, &peer->hashPubKey, ar);
+ return;
+ }
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (atc->peers,
- &peer->hashPubKey,
- ar,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (atc->peers,
+ &peer->hashPubKey,
+ ar,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
}
@@ -637,12 +601,11 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
*/
void
GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer)
{
(void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
- &peer->hashPubKey,
- &disconnect_peer,
- atc);
+ &peer->hashPubKey,
+ &disconnect_peer, atc);
}
@@ -672,9 +635,7 @@ struct SessionDestroyContext
* @return GNUNET_OK (continue to iterate)
*/
static int
-destroy_session (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+destroy_session (void *cls, const GNUNET_HashCode * key, void *value)
{
struct SessionDestroyContext *sdc = cls;
struct AllocationRecord *ar = value;
@@ -685,14 +646,13 @@ destroy_session (void *cls,
if (ar->plugin_addr != NULL)
return GNUNET_OK;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
- key,
- ar));
- if (GNUNET_YES == ar->connected);
- {
- /* FIXME: is this supposed to be allowed? What to do then? */
- GNUNET_break (0);
- }
+ GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
+ key, ar));
+ if (GNUNET_YES == ar->connected) ;
+ {
+ /* FIXME: is this supposed to be allowed? What to do then? */
+ GNUNET_break (0);
+ }
destroy_allocation_record (NULL, key, ar);
return GNUNET_OK;
}
@@ -707,16 +667,15 @@ destroy_session (void *cls,
*/
void
GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- const struct Session *session)
+ const struct GNUNET_PeerIdentity *peer,
+ const struct Session *session)
{
struct SessionDestroyContext sdc;
sdc.atc = atc;
sdc.session = session;
(void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &destroy_session,
- &sdc);
+ &destroy_session, &sdc);
}
@@ -729,20 +688,18 @@ GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
* @return GNUNET_YES (continue to iterate)
*/
static int
-notify_valid (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+notify_valid (void *cls, const GNUNET_HashCode * key, void *value)
{
struct AllocationRecord *ar = cls;
struct GNUNET_ATS_SuggestionContext *asc = value;
asc->cb (asc->cb_cls,
- &asc->target,
- ar->plugin_name,
- ar->plugin_addr,
- ar->plugin_addr_len,
- GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
- ar->ats, ar->ats_count);
+ &asc->target,
+ ar->plugin_name,
+ ar->plugin_addr,
+ ar->plugin_addr_len,
+ GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32),
+ ar->ats, ar->ats_count);
GNUNET_ATS_suggest_address_cancel (asc);
return GNUNET_OK;
}
@@ -768,43 +725,37 @@ notify_valid (void *cls,
*/
void
GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Absolute valid_until,
- const char *plugin_name,
- struct Session *session,
- const void *plugin_addr,
- size_t plugin_addr_len,
- const struct GNUNET_TRANSPORT_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_TIME_Absolute valid_until,
+ const char *plugin_name,
+ struct Session *session,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count)
{
struct AllocationRecord *ar;
struct UpdateSessionContext usc;
- ar = create_allocation_record (plugin_name,
- session,
- plugin_addr,
- plugin_addr_len,
- ats,
- ats_count);
+ ar = create_allocation_record (plugin_name,
+ session,
+ plugin_addr, plugin_addr_len, ats, ats_count);
usc.atc = atc;
- usc.arnew = ar;
+ usc.arnew = ar;
if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
- &update_session,
- &usc))
- {
- destroy_allocation_record (NULL, &peer->hashPubKey, ar);
- return;
- }
+ GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &update_session, &usc))
+ {
+ destroy_allocation_record (NULL, &peer->hashPubKey, ar);
+ return;
+ }
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (atc->peers,
- &peer->hashPubKey,
- ar,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_CONTAINER_multihashmap_put (atc->peers,
+ &peer->hashPubKey,
+ ar,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map,
- &peer->hashPubKey,
- &notify_valid,
- ar);
+ &peer->hashPubKey,
+ &notify_valid, ar);
}
/* end of file gnunet-service-transport_ats.c */
diff --git a/src/block/block.c b/src/block/block.c
index 24bde02ac..bdef55aa3 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -37,9 +37,9 @@ struct Plugin
{
/**
* Name of the shared library.
- */
+ */
char *library_name;
-
+
/**
* Plugin API.
*/
@@ -59,7 +59,7 @@ struct GNUNET_BLOCK_Context
/**
* Our configuration.
- */
+ */
const struct GNUNET_CONFIGURATION_Handle *cfg;
};
@@ -73,14 +73,11 @@ struct GNUNET_BLOCK_Context
*/
void
GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in,
- uint32_t mingle_number,
- GNUNET_HashCode * hc)
+ uint32_t mingle_number, GNUNET_HashCode * hc)
{
GNUNET_HashCode m;
- GNUNET_CRYPTO_hash (&mingle_number,
- sizeof (uint32_t),
- &m);
+ GNUNET_CRYPTO_hash (&mingle_number, sizeof (uint32_t), &m);
GNUNET_CRYPTO_hash_xor (&m, in, hc);
}
@@ -106,39 +103,33 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
ctx->cfg = cfg;
num_plugins = 0;
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "block", "PLUGINS", &plugs))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "block", "PLUGINS", &plugs))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Loading block plugins `%s'\n"), plugs);
+ pos = strtok (plugs, " ");
+ while (pos != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading block plugins `%s'\n"), plugs);
- pos = strtok (plugs, " ");
- while (pos != NULL)
- {
- GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos);
- api = GNUNET_PLUGIN_load (libname, NULL);
- if (api == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load block plugin `%s'\n"),
- pos);
- GNUNET_free (libname);
- }
- else
- {
- plugin = GNUNET_malloc (sizeof (struct Plugin));
- plugin->api = api;
- plugin->library_name = libname;
- GNUNET_array_append (ctx->plugins,
- num_plugins,
- plugin);
- }
- pos = strtok (NULL, " ");
- }
- GNUNET_free (plugs);
+ GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos);
+ api = GNUNET_PLUGIN_load (libname, NULL);
+ if (api == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to load block plugin `%s'\n"), pos);
+ GNUNET_free (libname);
+ }
+ else
+ {
+ plugin = GNUNET_malloc (sizeof (struct Plugin));
+ plugin->api = api;
+ plugin->library_name = libname;
+ GNUNET_array_append (ctx->plugins, num_plugins, plugin);
+ }
+ pos = strtok (NULL, " ");
}
- GNUNET_array_append (ctx->plugins,
- num_plugins,
- NULL);
+ GNUNET_free (plugs);
+ }
+ GNUNET_array_append (ctx->plugins, num_plugins, NULL);
return ctx;
}
@@ -156,14 +147,13 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
i = 0;
while (NULL != (plugin = ctx->plugins[i]))
- {
- GNUNET_break (NULL ==
- GNUNET_PLUGIN_unload (plugin->library_name,
- plugin->api));
- GNUNET_free (plugin->library_name);
- GNUNET_free (plugin);
- i++;
- }
+ {
+ GNUNET_break (NULL ==
+ GNUNET_PLUGIN_unload (plugin->library_name, plugin->api));
+ GNUNET_free (plugin->library_name);
+ GNUNET_free (plugin);
+ i++;
+ }
GNUNET_free (ctx->plugins);
GNUNET_free (ctx);
}
@@ -177,8 +167,7 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
* @return NULL if no matching plugin exists
*/
static struct GNUNET_BLOCK_PluginFunctions *
-find_plugin (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type)
+find_plugin (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
{
struct Plugin *plugin;
unsigned int i;
@@ -186,16 +175,16 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx,
i = 0;
while (NULL != (plugin = ctx->plugins[i]))
+ {
+ j = 0;
+ while (0 != (plugin->api->types[j]))
{
- j = 0;
- while (0 != (plugin->api->types[j]))
- {
- if (type == plugin->api->types[j])
- return plugin->api;
- j++;
- }
- i++;
+ if (type == plugin->api->types[j])
+ return plugin->api;
+ j++;
}
+ i++;
+ }
return NULL;
}
@@ -220,22 +209,21 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx,
*/
enum GNUNET_BLOCK_EvaluationResult
GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
if (plugin == NULL)
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
return plugin->evaluate (plugin->cls,
- type, query, bf, bf_mutator,
- xquery, xquery_size, reply_block, reply_block_size);
+ type, query, bf, bf_mutator,
+ xquery, xquery_size, reply_block, reply_block_size);
}
@@ -252,17 +240,15 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
*/
int
GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
if (plugin == NULL)
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
- return plugin->get_key (plugin->cls,
- type, block, block_size, key);
+ return plugin->get_key (plugin->cls, type, block, block_size, key);
}
diff --git a/src/block/plugin_block_dht.c b/src/block/plugin_block_dht.c
index 0e499b821..1fe51e1a3 100644
--- a/src/block/plugin_block_dht.c
+++ b/src/block/plugin_block_dht.c
@@ -50,14 +50,13 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_dht_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
switch (type)
{
@@ -67,7 +66,7 @@ block_plugin_dht_evaluate (void *cls,
if (reply_block_size == 0)
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
GNUNET_break (NULL == *bf);
- return GNUNET_BLOCK_EVALUATION_OK_LAST;
+ return GNUNET_BLOCK_EVALUATION_OK_LAST;
default:
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
}
@@ -87,10 +86,9 @@ block_plugin_dht_evaluate (void *cls,
*/
static int
block_plugin_dht_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
const struct GNUNET_MessageHeader *msg;
const struct GNUNET_HELLO_Message *hello;
@@ -99,37 +97,34 @@ block_plugin_dht_get_key (void *cls,
if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
return GNUNET_SYSERR;
if (block_size < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "block-dht",
- _("Block not of type %u\n"),
- GNUNET_BLOCK_TYPE_DHT_HELLO);
- return GNUNET_NO;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "block-dht",
+ _("Block not of type %u\n"), GNUNET_BLOCK_TYPE_DHT_HELLO);
+ return GNUNET_NO;
+ }
msg = block;
if (block_size != ntohs (msg->size))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "block-dht",
- _("Size mismatch for block\n"),
- GNUNET_BLOCK_TYPE_DHT_HELLO);
- return GNUNET_NO;
- }
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "block-dht",
+ _("Size mismatch for block\n"),
+ GNUNET_BLOCK_TYPE_DHT_HELLO);
+ return GNUNET_NO;
+ }
hello = block;
- pid = (struct GNUNET_PeerIdentity*) key;
- if (GNUNET_OK !=
- GNUNET_HELLO_get_id (hello,
- pid))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "block-dht",
- _("Block of type %u is malformed\n"),
- GNUNET_BLOCK_TYPE_DHT_HELLO);
- return GNUNET_NO;
- }
+ pid = (struct GNUNET_PeerIdentity *) key;
+ if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "block-dht",
+ _("Block of type %u is malformed\n"),
+ GNUNET_BLOCK_TYPE_DHT_HELLO);
+ return GNUNET_NO;
+ }
return GNUNET_OK;
}
-
+
/**
* Entry point for the plugin.
@@ -137,11 +132,11 @@ block_plugin_dht_get_key (void *cls,
void *
libgnunet_plugin_block_dht_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- GNUNET_BLOCK_TYPE_DHT_HELLO,
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_DHT_HELLO,
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/plugin_block_dns.c b/src/block/plugin_block_dns.c
index 681a659ae..0cf8c50e9 100644
--- a/src/block/plugin_block_dns.c
+++ b/src/block/plugin_block_dns.c
@@ -48,14 +48,13 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_dns_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
switch (type)
{
@@ -66,37 +65,43 @@ block_plugin_dns_evaluate (void *cls,
if (reply_block_size == 0)
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- if (reply_block_size != sizeof(struct GNUNET_DNS_Record))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: reply_block_size=%d != %d\n", reply_block_size, sizeof(struct GNUNET_DNS_Record));
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
-
- const struct GNUNET_DNS_Record* rec = reply_block;
-
- if (ntohl(rec->purpose.size) != sizeof(struct GNUNET_DNS_Record) - sizeof(struct GNUNET_CRYPTO_RsaSignature))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "DNS-Block is invalid: rec->purpose.size=%d != %d\n",
- ntohl(rec->purpose.size),
- sizeof(struct GNUNET_DNS_Record) - sizeof(struct GNUNET_CRYPTO_RsaSignature));
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
-
- if (GNUNET_TIME_relative_get_zero().rel_value == GNUNET_TIME_absolute_get_remaining(rec->expiration_time).rel_value)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n");
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
-
- if (GNUNET_OK != GNUNET_CRYPTO_rsa_verify (htonl(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD),
- &rec->purpose,
- &rec->signature,
- &rec->peer))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: invalid signature\n");
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
+ if (reply_block_size != sizeof (struct GNUNET_DNS_Record))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DNS-Block is invalid: reply_block_size=%d != %d\n",
+ reply_block_size, sizeof (struct GNUNET_DNS_Record));
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
+
+ const struct GNUNET_DNS_Record *rec = reply_block;
+
+ if (ntohl (rec->purpose.size) !=
+ sizeof (struct GNUNET_DNS_Record) -
+ sizeof (struct GNUNET_CRYPTO_RsaSignature))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DNS-Block is invalid: rec->purpose.size=%d != %d\n",
+ ntohl (rec->purpose.size),
+ sizeof (struct GNUNET_DNS_Record) -
+ sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
+
+ if (GNUNET_TIME_relative_get_zero ().rel_value ==
+ GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n");
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
+
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (htonl (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD),
+ &rec->purpose, &rec->signature, &rec->peer))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "DNS-Block is invalid: invalid signature\n");
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
/* How to decide whether there are no more? */
return GNUNET_BLOCK_EVALUATION_OK_MORE;
@@ -119,15 +124,15 @@ block_plugin_dns_evaluate (void *cls,
*/
static int
block_plugin_dns_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
if (type != GNUNET_BLOCK_TYPE_DNS)
return GNUNET_SYSERR;
- const struct GNUNET_DNS_Record* rec = block;
- memcpy(key, &rec->service_descriptor, sizeof(GNUNET_HashCode));
+ const struct GNUNET_DNS_Record *rec = block;
+
+ memcpy (key, &rec->service_descriptor, sizeof (GNUNET_HashCode));
return GNUNET_OK;
}
@@ -137,11 +142,11 @@ block_plugin_dns_get_key (void *cls,
void *
libgnunet_plugin_block_dns_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- GNUNET_BLOCK_TYPE_DNS,
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_DNS,
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/plugin_block_fs.c b/src/block/plugin_block_fs.c
index caf009ddf..db8e59991 100644
--- a/src/block/plugin_block_fs.c
+++ b/src/block/plugin_block_fs.c
@@ -57,14 +57,13 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_fs_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
const struct SBlock *sb;
GNUNET_HashCode chash;
@@ -73,92 +72,81 @@ block_plugin_fs_evaluate (void *cls,
GNUNET_HashCode sh;
switch (type)
+ {
+ case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+ case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+ if (xquery_size != 0)
{
- case GNUNET_BLOCK_TYPE_FS_DBLOCK:
- case GNUNET_BLOCK_TYPE_FS_IBLOCK:
- if (xquery_size != 0)
- {
- GNUNET_break_op (0);
- return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
- }
- if (reply_block == NULL)
- return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- return GNUNET_BLOCK_EVALUATION_OK_LAST;
- case GNUNET_BLOCK_TYPE_FS_KBLOCK:
- case GNUNET_BLOCK_TYPE_FS_NBLOCK:
- if (xquery_size != 0)
- {
- GNUNET_break_op (0);
- return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
- }
- if (reply_block == NULL)
- return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- GNUNET_CRYPTO_hash (reply_block,
- reply_block_size,
- &chash);
- GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
- if (NULL != *bf)
- {
- if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf,
- &mhash))
- return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
- }
- else
- {
- *bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
- 8,
- BLOOMFILTER_K);
- }
- GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
- return GNUNET_BLOCK_EVALUATION_OK_MORE;
- case GNUNET_BLOCK_TYPE_FS_SBLOCK:
- if (xquery_size != sizeof (GNUNET_HashCode))
- {
- GNUNET_break_op (0);
- return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
- }
- if (reply_block == NULL)
- return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- nsid = xquery;
- if (reply_block_size < sizeof (struct SBlock))
- {
- GNUNET_break_op (0);
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
- sb = reply_block;
- GNUNET_CRYPTO_hash (&sb->subspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &sh);
- if (0 != memcmp (nsid,
- &sh,
- sizeof (GNUNET_HashCode)))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "block-fs",
- _("Reply mismatched in terms of namespace. Discarded.\n"));
- return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
- }
- GNUNET_CRYPTO_hash (reply_block,
- reply_block_size,
- &chash);
- GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
- if (NULL != *bf)
- {
- if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf,
- &mhash))
- return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
- }
- else
- {
- *bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
- 8,
- BLOOMFILTER_K);
- }
- GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
- return GNUNET_BLOCK_EVALUATION_OK_MORE;
- default:
- return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
}
+ if (reply_block == NULL)
+ return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+ return GNUNET_BLOCK_EVALUATION_OK_LAST;
+ case GNUNET_BLOCK_TYPE_FS_KBLOCK:
+ case GNUNET_BLOCK_TYPE_FS_NBLOCK:
+ if (xquery_size != 0)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+ }
+ if (reply_block == NULL)
+ return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+ GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
+ GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
+ if (NULL != *bf)
+ {
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
+ return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+ }
+ else
+ {
+ *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
+ }
+ GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ return GNUNET_BLOCK_EVALUATION_OK_MORE;
+ case GNUNET_BLOCK_TYPE_FS_SBLOCK:
+ if (xquery_size != sizeof (GNUNET_HashCode))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
+ }
+ if (reply_block == NULL)
+ return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
+ nsid = xquery;
+ if (reply_block_size < sizeof (struct SBlock))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
+ sb = reply_block;
+ GNUNET_CRYPTO_hash (&sb->subspace,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &sh);
+ if (0 != memcmp (nsid, &sh, sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "block-fs",
+ _
+ ("Reply mismatched in terms of namespace. Discarded.\n"));
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
+ GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
+ GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
+ if (NULL != *bf)
+ {
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
+ return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+ }
+ else
+ {
+ *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
+ }
+ GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ return GNUNET_BLOCK_EVALUATION_OK_MORE;
+ default:
+ return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
+ }
}
@@ -175,126 +163,122 @@ block_plugin_fs_evaluate (void *cls,
*/
static int
block_plugin_fs_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
const struct KBlock *kb;
const struct SBlock *sb;
const struct NBlock *nb;
switch (type)
+ {
+ case GNUNET_BLOCK_TYPE_FS_DBLOCK:
+ case GNUNET_BLOCK_TYPE_FS_IBLOCK:
+ GNUNET_CRYPTO_hash (block, block_size, key);
+ return GNUNET_OK;
+ case GNUNET_BLOCK_TYPE_FS_KBLOCK:
+ if (block_size < sizeof (struct KBlock))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ kb = block;
+ if (block_size - sizeof (struct KBlock) !=
+ ntohl (kb->purpose.size)
+ - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
+ - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
+ &kb->purpose, &kb->signature, &kb->keyspace))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (key != NULL)
+ GNUNET_CRYPTO_hash (&kb->keyspace,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ key);
+ return GNUNET_OK;
+ case GNUNET_BLOCK_TYPE_FS_SBLOCK:
+ if (block_size < sizeof (struct SBlock))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ sb = block;
+ if (block_size !=
+ ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
{
- case GNUNET_BLOCK_TYPE_FS_DBLOCK:
- case GNUNET_BLOCK_TYPE_FS_IBLOCK:
- GNUNET_CRYPTO_hash (block, block_size, key);
- return GNUNET_OK;
- case GNUNET_BLOCK_TYPE_FS_KBLOCK:
- if (block_size < sizeof (struct KBlock))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- kb = block;
- if (block_size - sizeof (struct KBlock) !=
- ntohl (kb->purpose.size)
- - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
- - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
- &kb->purpose,
- &kb->signature,
- &kb->keyspace))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (key != NULL)
- GNUNET_CRYPTO_hash (&kb->keyspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- key);
- return GNUNET_OK;
- case GNUNET_BLOCK_TYPE_FS_SBLOCK:
- if (block_size < sizeof (struct SBlock))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- sb = block;
- if (block_size !=
- ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
- &sb->purpose,
- &sb->signature,
- &sb->subspace))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (key != NULL)
- *key = sb->identifier;
- return GNUNET_OK;
- case GNUNET_BLOCK_TYPE_FS_NBLOCK:
- if (block_size < sizeof (struct NBlock))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- nb = block;
- if (block_size - sizeof (struct NBlock) !=
- ntohl (nb->ns_purpose.size)
- - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
- - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (block_size !=
- ntohl (nb->ksk_purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
- &nb->ksk_purpose,
- &nb->ksk_signature,
- &nb->keyspace))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
- &nb->ns_purpose,
- &nb->ns_signature,
- &nb->subspace))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
- /* FIXME: we used to xor ID with NSID,
- why not here? */
- if (key != NULL)
- GNUNET_CRYPTO_hash (&nb->keyspace,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- key);
- return GNUNET_OK;
- default:
- return GNUNET_SYSERR;
+ GNUNET_break_op (0);
+ return GNUNET_NO;
}
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
+ &sb->purpose, &sb->signature, &sb->subspace))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (key != NULL)
+ *key = sb->identifier;
+ return GNUNET_OK;
+ case GNUNET_BLOCK_TYPE_FS_NBLOCK:
+ if (block_size < sizeof (struct NBlock))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ nb = block;
+ if (block_size - sizeof (struct NBlock) !=
+ ntohl (nb->ns_purpose.size)
+ - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
+ - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (block_size !=
+ ntohl (nb->ksk_purpose.size) +
+ sizeof (struct GNUNET_CRYPTO_RsaSignature))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
+ &nb->ksk_purpose,
+ &nb->ksk_signature, &nb->keyspace))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
+ &nb->ns_purpose,
+ &nb->ns_signature, &nb->subspace))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+ /* FIXME: we used to xor ID with NSID,
+ * why not here? */
+ if (key != NULL)
+ GNUNET_CRYPTO_hash (&nb->keyspace,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ key);
+ return GNUNET_OK;
+ default:
+ return GNUNET_SYSERR;
+ }
}
-
+
/**
* Entry point for the plugin.
@@ -302,15 +286,15 @@ block_plugin_fs_get_key (void *cls,
void *
libgnunet_plugin_block_fs_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- GNUNET_BLOCK_TYPE_FS_IBLOCK,
- GNUNET_BLOCK_TYPE_FS_KBLOCK,
- GNUNET_BLOCK_TYPE_FS_SBLOCK,
- GNUNET_BLOCK_TYPE_FS_NBLOCK,
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ GNUNET_BLOCK_TYPE_FS_IBLOCK,
+ GNUNET_BLOCK_TYPE_FS_KBLOCK,
+ GNUNET_BLOCK_TYPE_FS_SBLOCK,
+ GNUNET_BLOCK_TYPE_FS_NBLOCK,
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c
index 77e7c0ab9..9eb84ac4b 100644
--- a/src/block/plugin_block_template.c
+++ b/src/block/plugin_block_template.c
@@ -47,14 +47,14 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_template_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block,
+ size_t reply_block_size)
{
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
}
@@ -73,14 +73,13 @@ block_plugin_template_evaluate (void *cls,
*/
static int
block_plugin_template_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
return GNUNET_SYSERR;
}
-
+
/**
* Entry point for the plugin.
@@ -88,11 +87,11 @@ block_plugin_template_get_key (void *cls,
void *
libgnunet_plugin_block_template_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- /* FIXME: insert supported block types here */
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ /* FIXME: insert supported block types here */
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c
index 639a5c46e..b5c03eea9 100644
--- a/src/block/plugin_block_test.c
+++ b/src/block/plugin_block_test.c
@@ -54,42 +54,36 @@
*/
static enum GNUNET_BLOCK_EvaluationResult
block_plugin_test_evaluate (void *cls,
- enum GNUNET_BLOCK_Type type,
- const GNUNET_HashCode *query,
- struct GNUNET_CONTAINER_BloomFilter **bf,
- int32_t bf_mutator,
- const void *xquery,
- size_t xquery_size,
- const void *reply_block,
- size_t reply_block_size)
+ enum GNUNET_BLOCK_Type type,
+ const GNUNET_HashCode * query,
+ struct GNUNET_CONTAINER_BloomFilter **bf,
+ int32_t bf_mutator,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block, size_t reply_block_size)
{
GNUNET_HashCode chash;
GNUNET_HashCode mhash;
- if (type != GNUNET_BLOCK_TYPE_TEST)
+ if (type != GNUNET_BLOCK_TYPE_TEST)
return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
if (xquery_size != 0)
return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
if (reply_block_size == 0)
return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
- GNUNET_CRYPTO_hash (reply_block,
- reply_block_size,
- &chash);
+ GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
if (NULL != *bf)
- {
- if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf,
- &mhash))
- return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
- }
+ {
+ if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
+ return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
+ }
else
- {
- *bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
- 8,
- BLOOMFILTER_K);
- }
- GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
+ {
+ *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
+ }
+ GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
return GNUNET_BLOCK_EVALUATION_OK_MORE;
}
@@ -107,16 +101,15 @@ block_plugin_test_evaluate (void *cls,
*/
static int
block_plugin_test_get_key (void *cls,
- enum GNUNET_BLOCK_Type type,
- const void *block,
- size_t block_size,
- GNUNET_HashCode *key)
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size, GNUNET_HashCode * key)
{
/* always fails since there is no fixed relationship between
- keys and values for test values */
+ * keys and values for test values */
return GNUNET_SYSERR;
}
-
+
/**
* Entry point for the plugin.
@@ -124,11 +117,11 @@ block_plugin_test_get_key (void *cls,
void *
libgnunet_plugin_block_test_init (void *cls)
{
- static enum GNUNET_BLOCK_Type types[] =
- {
- GNUNET_BLOCK_TYPE_TEST,
- GNUNET_BLOCK_TYPE_ANY /* end of list */
- };
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_TEST,
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
struct GNUNET_BLOCK_PluginFunctions *api;
api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/test_block.c b/src/block/test_block.c
index bb9a1f01b..4bfd63ceb 100644
--- a/src/block/test_block.c
+++ b/src/block/test_block.c
@@ -38,35 +38,24 @@ test_fs (struct GNUNET_BLOCK_Context *ctx)
memset (block, 1, sizeof (block));
if (GNUNET_OK !=
GNUNET_BLOCK_get_key (ctx,
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- block,
- sizeof (block),
- &key))
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ block, sizeof (block), &key))
return 1;
if (GNUNET_BLOCK_EVALUATION_OK_LAST !=
GNUNET_BLOCK_evaluate (ctx,
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- &key,
- NULL, 0,
- NULL, 0,
- block, sizeof (block)))
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ &key, NULL, 0, NULL, 0, block, sizeof (block)))
return 2;
if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID !=
GNUNET_BLOCK_evaluate (ctx,
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- &key,
- NULL, 0,
- NULL, 0,
- NULL, 0))
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ &key, NULL, 0, NULL, 0, NULL, 0))
return 4;
GNUNET_log_skip (1, GNUNET_NO);
- if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID !=
+ if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID !=
GNUNET_BLOCK_evaluate (ctx,
- GNUNET_BLOCK_TYPE_FS_DBLOCK,
- &key,
- NULL, 0,
- "bogus", 5,
- NULL, 0))
+ GNUNET_BLOCK_TYPE_FS_DBLOCK,
+ &key, NULL, 0, "bogus", 5, NULL, 0))
return 8;
GNUNET_log_skip (0, GNUNET_YES);
return 0;
@@ -81,10 +70,7 @@ main (int argc, char *argv[])
GNUNET_log_setup ("test-block", "WARNING", NULL);
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_set_value_string (cfg,
- "block",
- "PLUGINS",
- "fs");
+ GNUNET_CONFIGURATION_set_value_string (cfg, "block", "PLUGINS", "fs");
ctx = GNUNET_BLOCK_context_create (cfg);
ret = test_fs (ctx);
GNUNET_BLOCK_context_destroy (ctx);
diff --git a/src/chat/chat.c b/src/chat/chat.c
index 8e35d10b5..1e90a6369 100644
--- a/src/chat/chat.c
+++ b/src/chat/chat.c
@@ -148,8 +148,7 @@ struct GNUNET_CHAT_SendReceiptContext
/**
* Ask client to send a join request.
*/
-static int
-rejoin_room (struct GNUNET_CHAT_Room *chat_room);
+static int rejoin_room (struct GNUNET_CHAT_Room *chat_room);
/**
@@ -161,9 +160,7 @@ rejoin_room (struct GNUNET_CHAT_Room *chat_room);
* @return number of bytes written to buf
*/
static size_t
-transmit_acknowledge_request (void *cls,
- size_t size,
- void *buf)
+transmit_acknowledge_request (void *cls, size_t size, void *buf)
{
struct GNUNET_CHAT_SendReceiptContext *src = cls;
struct ConfirmationReceiptMessage *receipt;
@@ -172,11 +169,11 @@ transmit_acknowledge_request (void *cls,
size_t msg_size;
if (NULL == buf)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not transmit confirmation receipt\n"));
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not transmit confirmation receipt\n"));
+ return 0;
+ }
#if DEBUG_CHAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting confirmation receipt to the service\n");
@@ -185,8 +182,7 @@ transmit_acknowledge_request (void *cls,
GNUNET_assert (size >= msg_size);
receipt = buf;
receipt->header.size = htons (msg_size);
- receipt->header.type =
- htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT);
+ receipt->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT);
receipt->reserved = htonl (0);
receipt->sequence_number = src->received_msg->sequence_number;
receipt->reserved2 = htonl (0);
@@ -196,17 +192,15 @@ transmit_acknowledge_request (void *cls,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&receipt->target);
receipt->author = src->received_msg->sender;
- receipt->purpose.purpose =
- htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT);
+ receipt->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT);
receipt->purpose.size =
- htonl (msg_size -
- sizeof (struct GNUNET_MessageHeader) -
- sizeof (uint32_t) -
- sizeof (struct GNUNET_CRYPTO_RsaSignature));
+ htonl (msg_size -
+ sizeof (struct GNUNET_MessageHeader) -
+ sizeof (uint32_t) - sizeof (struct GNUNET_CRYPTO_RsaSignature));
msg_len = ntohs (src->received_msg->header.size) -
- sizeof (struct ReceiveNotificationMessage);
+ sizeof (struct ReceiveNotificationMessage);
GNUNET_CRYPTO_hash (&src->received_msg[1], msg_len, &receipt->content);
- GNUNET_assert (GNUNET_OK ==
+ GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_rsa_sign (src->chat_room->my_private_key,
&receipt->purpose,
&receipt->signature));
@@ -244,187 +238,186 @@ process_result (struct GNUNET_CHAT_Room *room,
size = ntohs (reply->size);
switch (ntohs (reply->type))
- {
- case GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION:
+ {
+ case GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION:
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a join notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a join notification\n");
#endif
- if (size < sizeof (struct JoinNotificationMessage))
- {
- GNUNET_break (0);
- return;
- }
- join_msg = (struct JoinNotificationMessage *) reply;
- meta_len = size - sizeof (struct JoinNotificationMessage);
- meta =
+ if (size < sizeof (struct JoinNotificationMessage))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ join_msg = (struct JoinNotificationMessage *) reply;
+ meta_len = size - sizeof (struct JoinNotificationMessage);
+ meta =
GNUNET_CONTAINER_meta_data_deserialize ((const char *) &join_msg[1],
meta_len);
- if (NULL == meta)
- {
- GNUNET_break (0);
- return;
- }
- pos = GNUNET_malloc (sizeof (struct MemberList));
- pos->meta = meta;
- GNUNET_CRYPTO_hash (&join_msg->public_key,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &pos->id);
- GNUNET_PSEUDONYM_add (room->cfg, &pos->id, meta);
- pos->next = room->members;
- room->members = pos;
- if (GNUNET_NO == room->is_joined)
- {
- GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey);
- if (0 == memcmp (&join_msg->public_key,
- &pkey,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
- {
- room->join_callback (room->join_callback_cls);
- room->is_joined = GNUNET_YES;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("The current user must be the the first one joined\n"));
- GNUNET_break (0);
- return;
- }
- }
- else
+ if (NULL == meta)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ pos = GNUNET_malloc (sizeof (struct MemberList));
+ pos->meta = meta;
+ GNUNET_CRYPTO_hash (&join_msg->public_key,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &pos->id);
+ GNUNET_PSEUDONYM_add (room->cfg, &pos->id, meta);
+ pos->next = room->members;
+ room->members = pos;
+ if (GNUNET_NO == room->is_joined)
+ {
+ GNUNET_CRYPTO_rsa_key_get_public (room->my_private_key, &pkey);
+ if (0 == memcmp (&join_msg->public_key,
+ &pkey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
+ {
+ room->join_callback (room->join_callback_cls);
+ room->is_joined = GNUNET_YES;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("The current user must be the the first one joined\n"));
+ GNUNET_break (0);
+ return;
+ }
+ }
+ else
room->member_list_callback (room->member_list_callback_cls,
meta, &join_msg->public_key,
ntohl (join_msg->msg_options));
- break;
- case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION:
+ break;
+ case GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION:
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a leave notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a leave notification\n");
#endif
- if (size < sizeof (struct LeaveNotificationMessage))
- {
- GNUNET_break (0);
- return;
- }
- leave_msg = (struct LeaveNotificationMessage *) reply;
- room->member_list_callback (room->member_list_callback_cls,
- NULL, &leave_msg->user,
- GNUNET_CHAT_MSG_OPTION_NONE);
- GNUNET_CRYPTO_hash (&leave_msg->user,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &id);
- prev = NULL;
- pos = room->members;
- while ((NULL != pos) &&
- (0 != memcmp (&pos->id, &id, sizeof (GNUNET_HashCode))))
- {
- prev = pos;
- pos = pos->next;
- }
- GNUNET_assert (NULL != pos);
- if (NULL == prev)
- room->members = pos->next;
- else
- prev->next = pos->next;
- GNUNET_CONTAINER_meta_data_destroy (pos->meta);
- GNUNET_free (pos);
- break;
- case GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION:
+ if (size < sizeof (struct LeaveNotificationMessage))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ leave_msg = (struct LeaveNotificationMessage *) reply;
+ room->member_list_callback (room->member_list_callback_cls,
+ NULL, &leave_msg->user,
+ GNUNET_CHAT_MSG_OPTION_NONE);
+ GNUNET_CRYPTO_hash (&leave_msg->user,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &id);
+ prev = NULL;
+ pos = room->members;
+ while ((NULL != pos) &&
+ (0 != memcmp (&pos->id, &id, sizeof (GNUNET_HashCode))))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
+ GNUNET_assert (NULL != pos);
+ if (NULL == prev)
+ room->members = pos->next;
+ else
+ prev->next = pos->next;
+ GNUNET_CONTAINER_meta_data_destroy (pos->meta);
+ GNUNET_free (pos);
+ break;
+ case GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION:
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a message notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a message notification\n");
#endif
- if (size <= sizeof (struct ReceiveNotificationMessage))
- {
- GNUNET_break (0);
- return;
- }
- received_msg = (struct ReceiveNotificationMessage *) reply;
- if (0 !=
- (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ACKNOWLEDGED))
- {
- src = GNUNET_malloc (sizeof (struct GNUNET_CHAT_SendReceiptContext));
- src->chat_room = room;
- src->received_msg = GNUNET_memdup (received_msg, size);
- GNUNET_CLIENT_notify_transmit_ready (room->client,
- sizeof (struct ConfirmationReceiptMessage),
- GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_YES,
- &transmit_acknowledge_request,
- src);
- }
- msg_len = size - sizeof (struct ReceiveNotificationMessage);
- if (0 !=
- (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE))
- {
- if (-1 == GNUNET_CRYPTO_rsa_decrypt (room->my_private_key,
- &received_msg->encrypted_key,
- &key,
- sizeof (struct GNUNET_CRYPTO_AesSessionKey)))
- {
- GNUNET_break (0);
- return;
- }
- msg_len = GNUNET_CRYPTO_aes_decrypt (&received_msg[1],
- msg_len,
- &key,
- (const struct GNUNET_CRYPTO_AesInitializationVector *) INITVALUE,
- decrypted_msg);
- message_content = decrypted_msg;
- }
- else
- {
- message_content = GNUNET_malloc (msg_len + 1);
- memcpy (message_content, &received_msg[1], msg_len);
- }
- message_content[msg_len] = '\0';
- if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS))
- {
- sender = NULL;
- meta = NULL;
- }
- else
- {
+ if (size <= sizeof (struct ReceiveNotificationMessage))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ received_msg = (struct ReceiveNotificationMessage *) reply;
+ if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ACKNOWLEDGED))
+ {
+ src = GNUNET_malloc (sizeof (struct GNUNET_CHAT_SendReceiptContext));
+ src->chat_room = room;
+ src->received_msg = GNUNET_memdup (received_msg, size);
+ GNUNET_CLIENT_notify_transmit_ready (room->client,
+ sizeof (struct
+ ConfirmationReceiptMessage),
+ GNUNET_CONSTANTS_SERVICE_TIMEOUT,
+ GNUNET_YES,
+ &transmit_acknowledge_request, src);
+ }
+ msg_len = size - sizeof (struct ReceiveNotificationMessage);
+ if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_PRIVATE))
+ {
+ if (-1 == GNUNET_CRYPTO_rsa_decrypt (room->my_private_key,
+ &received_msg->encrypted_key,
+ &key,
+ sizeof (struct
+ GNUNET_CRYPTO_AesSessionKey)))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ msg_len = GNUNET_CRYPTO_aes_decrypt (&received_msg[1],
+ msg_len,
+ &key,
+ (const struct
+ GNUNET_CRYPTO_AesInitializationVector
+ *) INITVALUE, decrypted_msg);
+ message_content = decrypted_msg;
+ }
+ else
+ {
+ message_content = GNUNET_malloc (msg_len + 1);
+ memcpy (message_content, &received_msg[1], msg_len);
+ }
+ message_content[msg_len] = '\0';
+ if (0 != (ntohl (received_msg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS))
+ {
+ sender = NULL;
+ meta = NULL;
+ }
+ else
+ {
pos = room->members;
while ((NULL != pos) &&
(0 != memcmp (&pos->id,
- &received_msg->sender,
- sizeof (GNUNET_HashCode))))
+ &received_msg->sender, sizeof (GNUNET_HashCode))))
pos = pos->next;
GNUNET_assert (NULL != pos);
- sender = &received_msg->sender;
- meta = pos->meta;
- }
- room->message_callback (room->message_callback_cls,
- room,
- sender,
- meta,
- message_content,
- GNUNET_TIME_absolute_ntoh (received_msg->timestamp),
- ntohl (received_msg->msg_options));
- if (message_content != decrypted_msg)
- GNUNET_free (message_content);
- break;
- case GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION:
+ sender = &received_msg->sender;
+ meta = pos->meta;
+ }
+ room->message_callback (room->message_callback_cls,
+ room,
+ sender,
+ meta,
+ message_content,
+ GNUNET_TIME_absolute_ntoh (received_msg->timestamp),
+ ntohl (received_msg->msg_options));
+ if (message_content != decrypted_msg)
+ GNUNET_free (message_content);
+ break;
+ case GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION:
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a confirmation receipt\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a confirmation receipt\n");
#endif
- if (size < sizeof (struct ConfirmationReceiptMessage))
- {
- GNUNET_break (0);
- return;
- }
- receipt = (struct ConfirmationReceiptMessage *) reply;
- if (NULL != room->confirmation_callback)
- room->confirmation_callback (room->confirmation_cls,
- room,
- ntohl (receipt->sequence_number),
- GNUNET_TIME_absolute_ntoh (receipt->timestamp),
- &receipt->target);
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unknown message type: '%u'\n"), ntohs (reply->type));
- GNUNET_break_op (0);
- break;
+ if (size < sizeof (struct ConfirmationReceiptMessage))
+ {
+ GNUNET_break (0);
+ return;
}
+ receipt = (struct ConfirmationReceiptMessage *) reply;
+ if (NULL != room->confirmation_callback)
+ room->confirmation_callback (room->confirmation_cls,
+ room,
+ ntohl (receipt->sequence_number),
+ GNUNET_TIME_absolute_ntoh
+ (receipt->timestamp), &receipt->target);
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unknown message type: '%u'\n"), ntohs (reply->type));
+ GNUNET_break_op (0);
+ break;
+ }
}
@@ -435,9 +428,8 @@ process_result (struct GNUNET_CHAT_Room *room,
* @param cls closure, pointer to the 'struct GNUNET_CHAT_Room'
* @param msg message received, NULL on timeout or fatal error
*/
-static void
-receive_results (void *cls,
- const struct GNUNET_MessageHeader *msg)
+static void
+receive_results (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CHAT_Room *chat_room = cls;
@@ -447,19 +439,18 @@ receive_results (void *cls,
if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & GNUNET_SCHEDULER_get_reason ()))
return;
if (NULL == msg)
- {
- GNUNET_break (0);
- rejoin_room (chat_room);
- return;
- }
+ {
+ GNUNET_break (0);
+ rejoin_room (chat_room);
+ return;
+ }
process_result (chat_room, msg);
if (NULL == chat_room->client)
- return; /* fatal error */
+ return; /* fatal error */
/* continue receiving */
GNUNET_CLIENT_receive (chat_room->client,
&receive_results,
- chat_room,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ chat_room, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -480,30 +471,25 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing private key\n");
#endif
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "chat",
- "HOME",
- &home))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Configuration option `%s' in section `%s' missing\n"),
- "HOME",
- "chat");
- return NULL;
- }
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "chat", "HOME", &home))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Configuration option `%s' in section `%s' missing\n"),
+ "HOME", "chat");
+ return NULL;
+ }
GNUNET_DISK_directory_create (home);
if (GNUNET_OK != GNUNET_DISK_directory_test (home))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to access chat home directory `%s'\n"),
- home);
- GNUNET_free (home);
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to access chat home directory `%s'\n"), home);
+ GNUNET_free (home);
+ return NULL;
+ }
/* read or create private key */
keyfile =
- GNUNET_malloc (strlen (home) + strlen (NICK_IDENTITY_PREFIX) +
- strlen (nick_name) + 2);
+ GNUNET_malloc (strlen (home) + strlen (NICK_IDENTITY_PREFIX) +
+ strlen (nick_name) + 2);
strcpy (keyfile, home);
GNUNET_free (home);
if (keyfile[strlen (keyfile) - 1] != DIR_SEPARATOR)
@@ -512,11 +498,10 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg,
strcat (keyfile, nick_name);
privKey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
if (NULL == privKey)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create/open key in file `%s'\n"),
- keyfile);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to create/open key in file `%s'\n"), keyfile);
+ }
GNUNET_free (keyfile);
return privKey;
}
@@ -531,9 +516,7 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @return number of bytes written to buf
*/
static size_t
-transmit_join_request (void *cls,
- size_t size,
- void *buf)
+transmit_join_request (void *cls, size_t size, void *buf)
{
struct GNUNET_CHAT_Room *chat_room = cls;
struct JoinRequestMessage *join_msg;
@@ -544,20 +527,21 @@ transmit_join_request (void *cls,
size_t size_of_join;
if (NULL == buf)
- {
+ {
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not transmit join request, retrying...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Could not transmit join request, retrying...\n");
#endif
- rejoin_room (chat_room);
- return 0;
- }
+ rejoin_room (chat_room);
+ return 0;
+ }
#if DEBUG_CHAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting join request to the service\n");
#endif
room_len = strlen (chat_room->room_name);
- meta_len = GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info);
+ meta_len =
+ GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info);
size_of_join = sizeof (struct JoinRequestMessage) + meta_len + room_len;
GNUNET_assert (size >= size_of_join);
join_msg = buf;
@@ -567,7 +551,8 @@ transmit_join_request (void *cls,
join_msg->room_name_len = htons (room_len);
join_msg->reserved = htons (0);
join_msg->reserved2 = htonl (0);
- GNUNET_CRYPTO_rsa_key_get_public (chat_room->my_private_key, &join_msg->public_key);
+ GNUNET_CRYPTO_rsa_key_get_public (chat_room->my_private_key,
+ &join_msg->public_key);
room = (char *) &join_msg[1];
memcpy (room, chat_room->room_name, room_len);
meta = &room[room_len];
@@ -576,15 +561,13 @@ transmit_join_request (void *cls,
&meta,
meta_len,
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not serialize metadata\n"));
- return 0;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not serialize metadata\n"));
+ return 0;
+ }
GNUNET_CLIENT_receive (chat_room->client,
&receive_results,
- chat_room,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ chat_room, GNUNET_TIME_UNIT_FOREVER_REL);
return size_of_join;
}
@@ -598,15 +581,14 @@ rejoin_room (struct GNUNET_CHAT_Room *chat_room)
size_t size_of_join;
size_of_join = sizeof (struct JoinRequestMessage) +
- GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info) +
- strlen (chat_room->room_name);
+ GNUNET_CONTAINER_meta_data_get_serialized_size (chat_room->member_info) +
+ strlen (chat_room->room_name);
if (NULL ==
GNUNET_CLIENT_notify_transmit_ready (chat_room->client,
size_of_join,
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
GNUNET_YES,
- &transmit_join_request,
- chat_room))
+ &transmit_join_request, chat_room))
return GNUNET_SYSERR;
return GNUNET_OK;
}
@@ -629,12 +611,12 @@ GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room)
GNUNET_CONTAINER_meta_data_destroy (chat_room->member_info);
GNUNET_CRYPTO_rsa_key_free (chat_room->my_private_key);
while (NULL != chat_room->members)
- {
- pos = chat_room->members;
- chat_room->members = pos->next;
- GNUNET_CONTAINER_meta_data_destroy (pos->meta);
- GNUNET_free (pos);
- }
+ {
+ pos = chat_room->members;
+ chat_room->members = pos->next;
+ GNUNET_CONTAINER_meta_data_destroy (pos->meta);
+ GNUNET_free (pos);
+ }
GNUNET_free (chat_room);
}
@@ -675,8 +657,7 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_CHAT_MemberListCallback memberCallback,
void *member_cls,
GNUNET_CHAT_MessageConfirmation confirmationCallback,
- void *confirmation_cls,
- GNUNET_HashCode *me)
+ void *confirmation_cls, GNUNET_HashCode * me)
{
struct GNUNET_CHAT_Room *chat_room;
struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
@@ -696,29 +677,29 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_PSEUDONYM_add (cfg, me, member_info);
client = GNUNET_CLIENT_connect ("chat", cfg);
if (NULL == client)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to the chat service\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to connect to the chat service\n"));
+ return NULL;
+ }
if (NULL == joinCallback)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Undefined mandatory parameter: joinCallback\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Undefined mandatory parameter: joinCallback\n"));
+ return NULL;
+ }
if (NULL == messageCallback)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Undefined mandatory parameter: messageCallback\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Undefined mandatory parameter: messageCallback\n"));
+ return NULL;
+ }
if (NULL == memberCallback)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Undefined mandatory parameter: memberCallback\n"));
- return NULL;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Undefined mandatory parameter: memberCallback\n"));
+ return NULL;
+ }
chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room));
chat_room->msg_options = msg_options;
chat_room->room_name = GNUNET_strdup (room_name);
@@ -737,10 +718,10 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg,
chat_room->client = client;
chat_room->members = NULL;
if (GNUNET_SYSERR == rejoin_room (chat_room))
- {
- GNUNET_CHAT_leave_room (chat_room);
- return NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (chat_room);
+ return NULL;
+ }
return chat_room;
}
@@ -754,22 +735,19 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @return number of bytes written to buf
*/
static size_t
-transmit_send_request (void *cls,
- size_t size,
- void *buf)
+transmit_send_request (void *cls, size_t size, void *buf)
{
struct GNUNET_CHAT_SendMessageContext *smc = cls;
struct TransmitRequestMessage *msg_to_send;
size_t msg_size;
if (NULL == buf)
- {
+ {
#if DEBUG_CHAT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Could not transmit a chat message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not transmit a chat message\n");
#endif
- return 0;
- }
+ return 0;
+ }
#if DEBUG_CHAT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting a chat message to the service\n");
@@ -782,7 +760,7 @@ transmit_send_request (void *cls,
msg_to_send->msg_options = htonl (smc->options);
msg_to_send->sequence_number = htonl (smc->sequence_number);
msg_to_send->timestamp =
- GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
msg_to_send->reserved = htonl (0);
if (NULL == smc->receiver)
memset (&msg_to_send->target, 0, sizeof (GNUNET_HashCode));
@@ -796,18 +774,18 @@ transmit_send_request (void *cls,
* stored on the service side.
*/
if (smc->options & GNUNET_CHAT_MSG_AUTHENTICATED)
- {
- msg_to_send->purpose.purpose =
+ {
+ msg_to_send->purpose.purpose =
htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
- msg_to_send->purpose.size =
+ msg_to_send->purpose.size =
htonl (msg_size -
sizeof (struct GNUNET_MessageHeader) -
sizeof (struct GNUNET_CRYPTO_RsaSignature));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key,
- &msg_to_send->purpose,
- &msg_to_send->signature));
- }
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_rsa_sign (smc->chat_room->my_private_key,
+ &msg_to_send->purpose,
+ &msg_to_send->signature));
+ }
GNUNET_free (smc->message);
GNUNET_free (smc);
return msg_size;
@@ -827,8 +805,8 @@ void
GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room,
const char *message,
enum GNUNET_CHAT_MsgOptions options,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *receiver,
- uint32_t *sequence_number)
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
+ *receiver, uint32_t * sequence_number)
{
size_t msg_size;
struct GNUNET_CHAT_SendMessageContext *smc;
@@ -849,9 +827,7 @@ GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room,
GNUNET_CLIENT_notify_transmit_ready (room->client,
msg_size,
GNUNET_CONSTANTS_SERVICE_TIMEOUT,
- GNUNET_YES,
- &transmit_send_request,
- smc);
+ GNUNET_YES, &transmit_send_request, smc);
}
/* end of chat.c */
diff --git a/src/chat/gnunet-chat.c b/src/chat/gnunet-chat.c
index 85d266534..6dba4dda5 100644
--- a/src/chat/gnunet-chat.c
+++ b/src/chat/gnunet-chat.c
@@ -44,7 +44,8 @@ static struct GNUNET_CONTAINER_MetaData *meta;
static struct GNUNET_CHAT_Room *room;
-static GNUNET_SCHEDULER_TaskIdentifier handle_cmd_task = GNUNET_SCHEDULER_NO_TASK;
+static GNUNET_SCHEDULER_TaskIdentifier handle_cmd_task =
+ GNUNET_SCHEDULER_NO_TASK;
struct ChatCommand
{
@@ -66,12 +67,13 @@ static void
free_user_list ()
{
struct UserList *next;
+
while (NULL != users)
- {
- next = users->next;
- GNUNET_free (users);
- users = next;
- }
+ {
+ next = users->next;
+ GNUNET_free (users);
+ users = next;
+ }
}
static int do_help (const char *args, const void *xtra);
@@ -107,7 +109,7 @@ join_cb (void *cls)
static int
receive_cb (void *cls,
struct GNUNET_CHAT_Room *room,
- const GNUNET_HashCode *sender,
+ const GNUNET_HashCode * sender,
const struct GNUNET_CONTAINER_MetaData *member_info,
const char *message,
struct GNUNET_TIME_Absolute timestamp,
@@ -122,43 +124,45 @@ receive_cb (void *cls,
else
nick = GNUNET_strdup (_("anonymous"));
fmt = NULL;
- switch ( (int) options)
- {
- case GNUNET_CHAT_MSG_OPTION_NONE:
- case GNUNET_CHAT_MSG_ANONYMOUS:
- fmt = _("(%s) `%s' said: %s\n");
- break;
- case GNUNET_CHAT_MSG_PRIVATE:
- fmt = _("(%s) `%s' said to you: %s\n");
- break;
- case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS:
- fmt = _("(%s) `%s' said to you: %s\n");
- break;
- case GNUNET_CHAT_MSG_AUTHENTICATED:
- fmt = _("(%s) `%s' said for sure: %s\n");
- break;
- case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED:
- fmt = _("(%s) `%s' said to you for sure: %s\n");
- break;
- case GNUNET_CHAT_MSG_ACKNOWLEDGED:
- fmt = _("(%s) `%s' was confirmed that you received: %s\n");
- break;
- case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
- fmt = _("(%s) `%s' was confirmed that you and only you received: %s\n");
- break;
- case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED:
- fmt = _("(%s) `%s' was confirmed that you received from him or her: %s\n");
- break;
- case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
- fmt = _("(%s) `%s' was confirmed that you and only you received from him or her: %s\n");
- break;
- case GNUNET_CHAT_MSG_OFF_THE_RECORD:
- fmt = _("(%s) `%s' said off the record: %s\n");
- break;
- default:
- fmt = _("(%s) <%s> said using an unknown message type: %s\n");
- break;
- }
+ switch ((int) options)
+ {
+ case GNUNET_CHAT_MSG_OPTION_NONE:
+ case GNUNET_CHAT_MSG_ANONYMOUS:
+ fmt = _("(%s) `%s' said: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_PRIVATE:
+ fmt = _("(%s) `%s' said to you: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ANONYMOUS:
+ fmt = _("(%s) `%s' said to you: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_AUTHENTICATED:
+ fmt = _("(%s) `%s' said for sure: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_AUTHENTICATED:
+ fmt = _("(%s) `%s' said to you for sure: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_ACKNOWLEDGED:
+ fmt = _("(%s) `%s' was confirmed that you received: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
+ fmt = _("(%s) `%s' was confirmed that you and only you received: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_ACKNOWLEDGED:
+ fmt = _("(%s) `%s' was confirmed that you received from him or her: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_AUTHENTICATED | GNUNET_CHAT_MSG_PRIVATE | GNUNET_CHAT_MSG_ACKNOWLEDGED:
+ fmt =
+ _
+ ("(%s) `%s' was confirmed that you and only you received from him or her: %s\n");
+ break;
+ case GNUNET_CHAT_MSG_OFF_THE_RECORD:
+ fmt = _("(%s) `%s' said off the record: %s\n");
+ break;
+ default:
+ fmt = _("(%s) <%s> said using an unknown message type: %s\n");
+ break;
+ }
time = GNUNET_STRINGS_absolute_time_to_string (timestamp);
fprintf (stdout, fmt, time, nick, message);
GNUNET_free (nick);
@@ -183,7 +187,7 @@ confirmation_cb (void *cls,
struct GNUNET_CHAT_Room *room,
uint32_t orig_seq_number,
struct GNUNET_TIME_Absolute timestamp,
- const GNUNET_HashCode *receiver)
+ const GNUNET_HashCode * receiver)
{
char *nick;
@@ -222,40 +226,41 @@ member_list_cb (void *cls,
? _("`%s' entered the room\n") : _("`%s' left the room\n"), nick);
GNUNET_free (nick);
if (NULL != member_info)
+ {
+ /* user joining */
+ pos = GNUNET_malloc (sizeof (struct UserList));
+ pos->next = users;
+ pos->pkey = *member_id;
+ pos->ignored = GNUNET_NO;
+ users = pos;
+ }
+ else
+ {
+ /* user leaving */
+ prev = NULL;
+ pos = users;
+ while ((NULL != pos) &&
+ (0 != memcmp (&pos->pkey,
+ member_id,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))))
{
- /* user joining */
- pos = GNUNET_malloc (sizeof (struct UserList));
- pos->next = users;
- pos->pkey = *member_id;
- pos->ignored = GNUNET_NO;
- users = pos;
+ prev = pos;
+ pos = pos->next;
}
- else
+ if (NULL == pos)
{
- /* user leaving */
- prev = NULL;
- pos = users;
- while ((NULL != pos) &&
- (0 != memcmp (&pos->pkey,
- member_id,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))))
- {
- prev = pos;
- pos = pos->next;
- }
- if (NULL == pos)
- {
- GNUNET_break (0);
- }
+ GNUNET_break (0);
+ }
+ else
+ {
+ if (NULL == prev)
+ users = pos->next;
else
- {
- if (NULL == prev)
- users = pos->next;
- else
- prev->next = pos->next;
- GNUNET_free (pos);
- }
+ prev->next = pos->next;
+ GNUNET_free (pos);
}
+ }
return GNUNET_OK;
}
@@ -282,12 +287,13 @@ do_join (const char *arg, const void *xtra)
&member_list_cb, NULL,
&confirmation_cb, NULL, &me);
if (NULL == room)
- {
- fprintf (stdout, _("Could not change username\n"));
- return GNUNET_SYSERR;
- }
+ {
+ fprintf (stdout, _("Could not change username\n"));
+ return GNUNET_SYSERR;
+ }
my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me);
- fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, my_name);
+ fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name,
+ my_name);
GNUNET_free (my_name);
return GNUNET_OK;
}
@@ -310,8 +316,7 @@ do_nick (const char *msg, const void *xtra)
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- nickname,
- strlen(nickname)+1);
+ nickname, strlen (nickname) + 1);
room = GNUNET_CHAT_join_room (cfg,
nickname,
meta,
@@ -322,10 +327,10 @@ do_nick (const char *msg, const void *xtra)
&member_list_cb, NULL,
&confirmation_cb, NULL, &me);
if (NULL == room)
- {
- fprintf (stdout, _("Could not change username\n"));
- return GNUNET_SYSERR;
- }
+ {
+ fprintf (stdout, _("Could not change username\n"));
+ return GNUNET_SYSERR;
+ }
my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me);
fprintf (stdout, _("Changed username to `%s'\n"), my_name);
GNUNET_free (my_name);
@@ -343,15 +348,15 @@ do_names (const char *msg, const void *xtra)
fprintf (stdout, _("Users in room `%s': "), room_name);
pos = users;
while (NULL != pos)
- {
- GNUNET_CRYPTO_hash (&pos->pkey,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &pid);
- name = GNUNET_PSEUDONYM_id_to_name (cfg, &pid);
- fprintf (stdout, "`%s' ", name);
- GNUNET_free (name);
- pos = pos->next;
- }
+ {
+ GNUNET_CRYPTO_hash (&pos->pkey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &pid);
+ name = GNUNET_PSEUDONYM_id_to_name (cfg, &pid);
+ fprintf (stdout, "`%s' ", name);
+ GNUNET_free (name);
+ pos = pos->next;
+ }
fprintf (stdout, "\n");
return GNUNET_OK;
}
@@ -361,10 +366,8 @@ static int
do_send (const char *msg, const void *xtra)
{
uint32_t seq;
- GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_OPTION_NONE,
- NULL, &seq);
+
+ GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_OPTION_NONE, NULL, &seq);
return GNUNET_OK;
}
@@ -379,40 +382,37 @@ do_send_pm (const char *msg, const void *xtra)
struct UserList *pos;
if (NULL == strstr (msg, " "))
- {
- fprintf (stderr, _("Syntax: /msg USERNAME MESSAGE"));
- return GNUNET_OK;
- }
+ {
+ fprintf (stderr, _("Syntax: /msg USERNAME MESSAGE"));
+ return GNUNET_OK;
+ }
user = GNUNET_strdup (msg);
strstr (user, " ")[0] = '\0';
msg += strlen (user) + 1;
if (GNUNET_OK != GNUNET_PSEUDONYM_name_to_id (cfg, user, &uid))
- {
- fprintf (stderr, _("Unknown user `%s'\n"), user);
- GNUNET_free (user);
- return GNUNET_OK;
- }
+ {
+ fprintf (stderr, _("Unknown user `%s'\n"), user);
+ GNUNET_free (user);
+ return GNUNET_OK;
+ }
pos = users;
while (NULL != pos)
- {
- GNUNET_CRYPTO_hash (&pos->pkey,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &pid);
- if (0 == memcmp (&pid, &uid, sizeof (GNUNET_HashCode)))
- break;
- pos = pos->next;
- }
+ {
+ GNUNET_CRYPTO_hash (&pos->pkey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &pid);
+ if (0 == memcmp (&pid, &uid, sizeof (GNUNET_HashCode)))
+ break;
+ pos = pos->next;
+ }
if (NULL == pos)
- {
- fprintf (stderr, _("User `%s' is currently not in the room!\n"), user);
- GNUNET_free (user);
- return GNUNET_OK;
- }
+ {
+ fprintf (stderr, _("User `%s' is currently not in the room!\n"), user);
+ GNUNET_free (user);
+ return GNUNET_OK;
+ }
GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_PRIVATE,
- &pos->pkey,
- &seq);
+ msg, GNUNET_CHAT_MSG_PRIVATE, &pos->pkey, &seq);
GNUNET_free (user);
return GNUNET_OK;
}
@@ -422,10 +422,9 @@ static int
do_send_sig (const char *msg, const void *xtra)
{
uint32_t seq;
+
GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_AUTHENTICATED,
- NULL, &seq);
+ msg, GNUNET_CHAT_MSG_AUTHENTICATED, NULL, &seq);
return GNUNET_OK;
}
@@ -434,10 +433,9 @@ static int
do_send_ack (const char *msg, const void *xtra)
{
uint32_t seq;
+
GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_ACKNOWLEDGED,
- NULL, &seq);
+ msg, GNUNET_CHAT_MSG_ACKNOWLEDGED, NULL, &seq);
return GNUNET_OK;
}
@@ -446,10 +444,8 @@ static int
do_send_anonymous (const char *msg, const void *xtra)
{
uint32_t seq;
- GNUNET_CHAT_send_message (room,
- msg,
- GNUNET_CHAT_MSG_ANONYMOUS,
- NULL, &seq);
+
+ GNUNET_CHAT_send_message (room, msg, GNUNET_CHAT_MSG_ANONYMOUS, NULL, &seq);
return GNUNET_OK;
}
@@ -509,8 +505,8 @@ static struct ChatCommand commands[] = {
{"/help", &do_help,
gettext_noop ("Use `/help command' to get help for a specific command")},
/* Add standard commands:
- /whois (print metadata),
- /ignore (set flag, check on receive!) */
+ * /whois (print metadata),
+ * /ignore (set flag, check on receive!) */
/* the following three commands must be last! */
{"/", &do_unknown, NULL},
{"", &do_send, NULL},
@@ -522,41 +518,40 @@ static int
do_help (const char *args, const void *xtra)
{
int i;
+
i = 0;
while ((NULL != args) &&
(0 != strlen (args)) && (commands[i].Action != &do_help))
+ {
+ if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
{
- if (0 ==
- strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1))
- {
- fprintf (stdout, "%s\n", gettext (commands[i].helptext));
- return GNUNET_OK;
- }
- i++;
+ fprintf (stdout, "%s\n", gettext (commands[i].helptext));
+ return GNUNET_OK;
}
+ i++;
+ }
i = 0;
fprintf (stdout, "Available commands:");
while (commands[i].Action != &do_help)
- {
- fprintf (stdout, " %s", gettext (commands[i].command));
- i++;
- }
+ {
+ fprintf (stdout, " %s", gettext (commands[i].command));
+ i++;
+ }
fprintf (stdout, "\n");
fprintf (stdout, "%s\n", gettext (commands[i].helptext));
return GNUNET_OK;
}
-static void
-do_stop_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+static void
+do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_CHAT_leave_room (room);
if (handle_cmd_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (handle_cmd_task);
- handle_cmd_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (handle_cmd_task);
+ handle_cmd_task = GNUNET_SCHEDULER_NO_TASK;
+ }
free_user_list ();
GNUNET_CONTAINER_meta_data_destroy (meta);
GNUNET_free (room_name);
@@ -591,10 +586,9 @@ handle_command (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
next:
handle_cmd_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- 100),
- &handle_command,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 100),
+ &handle_command, NULL);
return;
out:
@@ -614,8 +608,7 @@ out:
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
GNUNET_HashCode me;
char *my_name;
@@ -623,11 +616,11 @@ run (void *cls,
cfg = c;
/* check arguments */
if (NULL == nickname)
- {
- fprintf (stderr, _("You must specify a nickname\n"));
- ret = -1;
- return;
- }
+ {
+ fprintf (stderr, _("You must specify a nickname\n"));
+ ret = -1;
+ return;
+ }
if (NULL == room_name)
room_name = GNUNET_strdup ("gnunet");
meta = GNUNET_CONTAINER_meta_data_create ();
@@ -636,8 +629,7 @@ run (void *cls,
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- nickname,
- strlen(nickname)+1);
+ nickname, strlen (nickname) + 1);
room = GNUNET_CHAT_join_room (cfg,
nickname,
meta,
@@ -648,24 +640,23 @@ run (void *cls,
&member_list_cb, NULL,
&confirmation_cb, NULL, &me);
if (NULL == room)
- {
- fprintf (stderr, _("Failed to join room `%s'\n"), room_name);
- GNUNET_free (room_name);
- GNUNET_free (nickname);
- GNUNET_CONTAINER_meta_data_destroy (meta);
- ret = -1;
- return;
- }
+ {
+ fprintf (stderr, _("Failed to join room `%s'\n"), room_name);
+ GNUNET_free (room_name);
+ GNUNET_free (nickname);
+ GNUNET_CONTAINER_meta_data_destroy (meta);
+ ret = -1;
+ return;
+ }
my_name = GNUNET_PSEUDONYM_id_to_name (cfg, &me);
- fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name, my_name);
+ fprintf (stdout, _("Joining room `%s' as user `%s'...\n"), room_name,
+ my_name);
GNUNET_free (my_name);
handle_cmd_task =
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
- &handle_command,
- NULL);
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
+ &handle_command, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_stop_task,
- NULL);
+ &do_stop_task, NULL);
}
@@ -680,6 +671,7 @@ int
main (int argc, char *const *argv)
{
int flags;
+
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'n', "nick", "NAME",
gettext_noop ("set the nickname to use (required)"),
diff --git a/src/chat/gnunet-service-chat.c b/src/chat/gnunet-service-chat.c
index 470b4ad0b..7afa18d68 100644
--- a/src/chat/gnunet-service-chat.c
+++ b/src/chat/gnunet-service-chat.c
@@ -105,7 +105,7 @@ struct ConnectedPeer
/**
* The peer's identity.
*/
- GNUNET_PEER_Id pid;
+ GNUNET_PEER_Id pid;
};
/**
@@ -157,10 +157,11 @@ static struct AnonymousMessage *anonymous_list_head = NULL;
* Map of peer identifiers to "struct ConnectedPeer" (for that peer).
*/
static struct GNUNET_CONTAINER_MultiHashMap *connected_peers;
-
+
static void
-remember_anonymous_message (const struct P2PReceiveNotificationMessage *p2p_rnmsg)
+remember_anonymous_message (const struct P2PReceiveNotificationMessage
+ *p2p_rnmsg)
{
static GNUNET_HashCode hash;
struct AnonymousMessage *anon_msg;
@@ -175,17 +176,17 @@ remember_anonymous_message (const struct P2PReceiveNotificationMessage *p2p_rnms
anon_list_len = 1;
prev = NULL;
while ((NULL != anon_msg->next))
- {
- prev = anon_msg;
- anon_msg = anon_msg->next;
- anon_list_len++;
- }
+ {
+ prev = anon_msg;
+ anon_msg = anon_msg->next;
+ anon_list_len++;
+ }
if (anon_list_len == MAX_ANONYMOUS_MSG_LIST_LENGTH)
- {
- GNUNET_free (anon_msg);
- if (NULL != prev)
- prev->next = NULL;
- }
+ {
+ GNUNET_free (anon_msg);
+ if (NULL != prev)
+ prev->next = NULL;
+ }
}
@@ -213,9 +214,7 @@ lookup_anonymous_message (const struct P2PReceiveNotificationMessage *p2p_rnmsg)
* @return number of bytes written to buf
*/
static size_t
-transmit_message_notification_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_message_notification_to_peer (void *cls, size_t size, void *buf)
{
struct P2PReceiveNotificationMessage *my_msg = cls;
struct P2PReceiveNotificationMessage *m = buf;
@@ -226,14 +225,14 @@ transmit_message_notification_to_peer (void *cls,
"Transmitting P2P message notification\n");
#endif
if (buf == NULL)
- {
- /* client disconnected */
+ {
+ /* client disconnected */
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Buffer is NULL, dropping the message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Buffer is NULL, dropping the message\n");
#endif
- return 0;
- }
+ return 0;
+ }
msg_size = ntohs (my_msg->header.size);
GNUNET_assert (size >= msg_size);
memcpy (m, my_msg, msg_size);
@@ -246,9 +245,7 @@ transmit_message_notification_to_peer (void *cls,
* Ask to send a message notification to the peer.
*/
static int
-send_message_noficiation (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
{
struct P2PReceiveNotificationMessage *msg = cls;
struct ConnectedPeer *cp = value;
@@ -262,7 +259,7 @@ send_message_noficiation (void *cls,
#endif
my_msg = GNUNET_memdup (msg, ntohs (msg->header.size));
if (NULL == GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_NO,
+ GNUNET_NO,
1,
MAX_TRANSMIT_DELAY,
&pid,
@@ -304,35 +301,36 @@ handle_transmit_request (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client sent a chat message\n");
if (ntohs (message->size) <= sizeof (struct TransmitRequestMessage))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
trmsg = (const struct TransmitRequestMessage *) message;
msg_len = ntohs (trmsg->header.size) - sizeof (struct TransmitRequestMessage);
is_priv = (0 != (ntohl (trmsg->msg_options) & GNUNET_CHAT_MSG_PRIVATE));
if (is_priv)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n");
#endif
- GNUNET_CRYPTO_aes_create_session_key (&key);
- msg_len = GNUNET_CRYPTO_aes_encrypt (&trmsg[1],
- msg_len,
- &key,
- (const struct GNUNET_CRYPTO_AesInitializationVector *) INITVALUE,
- encrypted_msg);
- if (-1 == msg_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not encrypt the message text\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ GNUNET_CRYPTO_aes_create_session_key (&key);
+ msg_len = GNUNET_CRYPTO_aes_encrypt (&trmsg[1],
+ msg_len,
+ &key,
+ (const struct
+ GNUNET_CRYPTO_AesInitializationVector
+ *) INITVALUE, encrypted_msg);
+ if (-1 == msg_len)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not encrypt the message text\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
}
+ }
rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len);
rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) +
msg_len);
@@ -343,134 +341,134 @@ handle_transmit_request (void *cls,
while ((NULL != pos) && (pos->client != client))
pos = pos->next;
if (NULL == pos)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "The client is not a member of a chat room. Client has to "
- "join a chat room first\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (rnmsg);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "The client is not a member of a chat room. Client has to "
+ "join a chat room first\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (rnmsg);
+ return;
+ }
room = pos->room;
pos->msg_sequence_number = ntohl (trmsg->sequence_number);
is_anon = (0 != (ntohl (trmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS));
if (is_anon)
- {
+ {
memset (&rnmsg->sender, 0, sizeof (GNUNET_HashCode));
- rnmsg->sequence_number = 0;
- }
+ rnmsg->sequence_number = 0;
+ }
else
- {
- rnmsg->sender = pos->id;
- rnmsg->sequence_number = trmsg->sequence_number;
- }
+ {
+ rnmsg->sender = pos->id;
+ rnmsg->sequence_number = trmsg->sequence_number;
+ }
if (is_priv)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypting the session key using the public key of '%s'\n",
- GNUNET_h2s (&trmsg->target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Encrypting the session key using the public key of '%s'\n",
+ GNUNET_h2s (&trmsg->target));
#endif
- if (0 == memcmp (&all_zeros, &trmsg->target, sizeof (GNUNET_HashCode)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed message: private, but no target\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (rnmsg);
- return;
- }
- memcpy (&rnmsg[1], encrypted_msg, msg_len);
- target = client_list_head;
- while ((NULL != target) &&
- (0 != memcmp (&target->id,
- &trmsg->target,
- sizeof (GNUNET_HashCode))))
- target = target->next;
- if (NULL == target)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown target of the private message\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (rnmsg);
- return;
- }
- if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&key,
- sizeof (struct GNUNET_CRYPTO_AesSessionKey),
- &target->public_key,
- &rnmsg->encrypted_key))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not encrypt the session key\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- GNUNET_free (rnmsg);
- return;
- }
+ if (0 == memcmp (&all_zeros, &trmsg->target, sizeof (GNUNET_HashCode)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Malformed message: private, but no target\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (rnmsg);
+ return;
}
- else
+ memcpy (&rnmsg[1], encrypted_msg, msg_len);
+ target = client_list_head;
+ while ((NULL != target) &&
+ (0 != memcmp (&target->id,
+ &trmsg->target, sizeof (GNUNET_HashCode))))
+ target = target->next;
+ if (NULL == target)
{
- memcpy (&rnmsg[1], &trmsg[1], msg_len);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown target of the private message\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (rnmsg);
+ return;
}
+ if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&key,
+ sizeof (struct
+ GNUNET_CRYPTO_AesSessionKey),
+ &target->public_key,
+ &rnmsg->encrypted_key))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not encrypt the session key\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (rnmsg);
+ return;
+ }
+ }
+ else
+ {
+ memcpy (&rnmsg[1], &trmsg[1], msg_len);
+ }
pos = client_list_head;
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message to local room members\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message to local room members\n");
#endif
while (NULL != pos)
+ {
+ if ((0 == strcmp (room, pos->room)) &&
+ (NULL != pos->client) && (pos->client != client))
{
- if ((0 == strcmp (room, pos->room)) &&
- (NULL != pos->client) &&
- (pos->client != client))
- {
- if (((!is_priv) ||
- (0 == memcmp (&trmsg->target,
- &pos->id,
- sizeof (GNUNET_HashCode)))) &&
- (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options))))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- pos->client,
- &rnmsg->header,
- GNUNET_NO);
- }
- }
- pos = pos->next;
+ if (((!is_priv) ||
+ (0 == memcmp (&trmsg->target,
+ &pos->id,
+ sizeof (GNUNET_HashCode)))) &&
+ (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options))))
+ {
+ GNUNET_SERVER_notification_context_unicast (nc,
+ pos->client,
+ &rnmsg->header, GNUNET_NO);
+ }
}
+ pos = pos->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting message to neighbour peers\n");
#endif
if (is_anon)
- {
- room_len = strlen (room);
- p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) +
- msg_len + room_len);
- p2p_rnmsg->header.size =
+ {
+ room_len = strlen (room);
+ p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) +
+ msg_len + room_len);
+ p2p_rnmsg->header.size =
htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len +
room_len);
- p2p_rnmsg->room_name_len = htons (room_len);
- memcpy ((char *) &p2p_rnmsg[1], room, room_len);
- memcpy ((char *) &p2p_rnmsg[1] + room_len, &trmsg[1], msg_len);
- }
+ p2p_rnmsg->room_name_len = htons (room_len);
+ memcpy ((char *) &p2p_rnmsg[1], room, room_len);
+ memcpy ((char *) &p2p_rnmsg[1] + room_len, &trmsg[1], msg_len);
+ }
else
- {
- p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) +
- msg_len);
- p2p_rnmsg->header.size =
+ {
+ p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) +
+ msg_len);
+ p2p_rnmsg->header.size =
htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len);
- if (is_priv)
+ if (is_priv)
{
memcpy (&p2p_rnmsg[1], encrypted_msg, msg_len);
memcpy (&p2p_rnmsg->encrypted_key,
&rnmsg->encrypted_key,
sizeof (struct GNUNET_CRYPTO_RsaEncryptedData));
}
- else
+ else
memcpy (&p2p_rnmsg[1], &trmsg[1], msg_len);
- }
- p2p_rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION);
+ }
+ p2p_rnmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION);
p2p_rnmsg->msg_options = trmsg->msg_options;
p2p_rnmsg->sequence_number = trmsg->sequence_number;
p2p_rnmsg->timestamp = trmsg->timestamp;
@@ -480,8 +478,7 @@ handle_transmit_request (void *cls,
if (is_anon)
remember_anonymous_message (p2p_rnmsg);
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_message_noficiation,
- p2p_rnmsg);
+ &send_message_noficiation, p2p_rnmsg);
GNUNET_free (p2p_rnmsg);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
GNUNET_free (rnmsg);
@@ -497,9 +494,7 @@ handle_transmit_request (void *cls,
* @return number of bytes written to buf
*/
static size_t
-transmit_join_notification_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_join_notification_to_peer (void *cls, size_t size, void *buf)
{
struct ChatClient *entry = cls;
struct P2PJoinNotificationMessage *m = buf;
@@ -509,8 +504,7 @@ transmit_join_notification_to_peer (void *cls,
char *roomptr;
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting P2P join notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting P2P join notification\n");
#endif
room_len = strlen (entry->room);
meta_len = entry->meta_len;
@@ -537,9 +531,7 @@ transmit_join_notification_to_peer (void *cls,
* Ask to send a join notification to the peer.
*/
static int
-send_join_noficiation (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ChatClient *entry = cls;
struct ConnectedPeer *cp = value;
@@ -552,10 +544,9 @@ send_join_noficiation (void *cls,
"Sending join notification to `%s'\n", GNUNET_i2s (&pid));
#endif
msg_size = sizeof (struct P2PJoinNotificationMessage) +
- strlen (entry->room) +
- entry->meta_len;
+ strlen (entry->room) + entry->meta_len;
if (NULL == GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_NO,
+ GNUNET_NO,
1,
MAX_TRANSMIT_DELAY,
&pid,
@@ -594,26 +585,24 @@ handle_join_request (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Client sent a join request\n");
if (ntohs (message->size) <= sizeof (struct JoinRequestMessage))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
jrmsg = (const struct JoinRequestMessage *) message;
header_size = ntohs (jrmsg->header.size);
room_name_len = ntohs (jrmsg->room_name_len);
- if (header_size - sizeof (struct JoinRequestMessage) <=
- room_name_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed message: wrong length of the room name\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- meta_len =
- header_size - sizeof (struct JoinRequestMessage) - room_name_len;
+ if (header_size - sizeof (struct JoinRequestMessage) <= room_name_len)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Malformed message: wrong length of the room name\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ meta_len = header_size - sizeof (struct JoinRequestMessage) - room_name_len;
roomptr = (const char *) &jrmsg[1];
room_name = GNUNET_malloc (room_name_len + 1);
memcpy (room_name, roomptr, room_name_len);
@@ -625,10 +614,10 @@ handle_join_request (void *cls,
new_entry->public_key = jrmsg->public_key;
new_entry->meta_len = meta_len;
if (meta_len > 0)
- {
- new_entry->member_info = GNUNET_malloc (meta_len);
- memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len);
- }
+ {
+ new_entry->member_info = GNUNET_malloc (meta_len);
+ memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len);
+ }
else
new_entry->member_info = NULL;
GNUNET_CRYPTO_hash (&new_entry->public_key,
@@ -644,50 +633,47 @@ handle_join_request (void *cls,
jnmsg = GNUNET_malloc (sizeof (struct JoinNotificationMessage) + meta_len);
jnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION);
jnmsg->header.size =
- htons (sizeof (struct JoinNotificationMessage) + meta_len);
+ htons (sizeof (struct JoinNotificationMessage) + meta_len);
jnmsg->msg_options = jrmsg->msg_options;
jnmsg->public_key = new_entry->public_key;
memcpy (&jnmsg[1], &roomptr[room_name_len], meta_len);
GNUNET_SERVER_notification_context_add (nc, client);
entry = client_list_head;
while (NULL != entry)
+ {
+ if (0 == strcmp (room_name, entry->room))
{
- if (0 == strcmp (room_name, entry->room))
- {
- if (NULL != entry->client)
- GNUNET_SERVER_notification_context_unicast (nc,
- entry->client,
- &jnmsg->header,
- GNUNET_NO);
- if (entry->client != client)
- {
- entry_jnmsg =
- GNUNET_malloc (sizeof (struct JoinNotificationMessage) +
- entry->meta_len);
- entry_jnmsg->header.type =
- htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION);
- entry_jnmsg->header.size =
- htons (sizeof (struct JoinNotificationMessage) +
- entry->meta_len);
- entry_jnmsg->msg_options = entry->msg_options;
- entry_jnmsg->public_key = entry->public_key;
- memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len);
- GNUNET_SERVER_notification_context_unicast (nc,
- client,
- &entry_jnmsg->header,
- GNUNET_NO);
- GNUNET_free (entry_jnmsg);
- }
- }
- entry = entry->next;
+ if (NULL != entry->client)
+ GNUNET_SERVER_notification_context_unicast (nc,
+ entry->client,
+ &jnmsg->header, GNUNET_NO);
+ if (entry->client != client)
+ {
+ entry_jnmsg =
+ GNUNET_malloc (sizeof (struct JoinNotificationMessage) +
+ entry->meta_len);
+ entry_jnmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION);
+ entry_jnmsg->header.size =
+ htons (sizeof (struct JoinNotificationMessage) + entry->meta_len);
+ entry_jnmsg->msg_options = entry->msg_options;
+ entry_jnmsg->public_key = entry->public_key;
+ memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len);
+ GNUNET_SERVER_notification_context_unicast (nc,
+ client,
+ &entry_jnmsg->header,
+ GNUNET_NO);
+ GNUNET_free (entry_jnmsg);
+ }
}
+ entry = entry->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting join notification to neighbour peers\n");
#endif
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_join_noficiation,
- new_entry);
+ &send_join_noficiation, new_entry);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
GNUNET_free (jnmsg);
}
@@ -701,9 +687,7 @@ handle_join_request (void *cls,
* @return number of bytes written to buf
*/
static size_t
-transmit_confirmation_receipt_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_confirmation_receipt_to_peer (void *cls, size_t size, void *buf)
{
struct P2PConfirmationReceiptMessage *receipt = cls;
size_t msg_size;
@@ -714,14 +698,14 @@ transmit_confirmation_receipt_to_peer (void *cls,
GNUNET_h2s (&receipt->target));
#endif
if (buf == NULL)
- {
- /* client disconnected */
+ {
+ /* client disconnected */
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Buffer is NULL, dropping the message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Buffer is NULL, dropping the message\n");
#endif
- return 0;
- }
+ return 0;
+ }
msg_size = sizeof (struct P2PConfirmationReceiptMessage);
GNUNET_assert (size >= msg_size);
memcpy (buf, receipt, msg_size);
@@ -734,9 +718,7 @@ transmit_confirmation_receipt_to_peer (void *cls,
* Ask to send a confirmation receipt to the peer.
*/
static int
-send_confirmation_receipt (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value)
{
struct P2PConfirmationReceiptMessage *receipt = cls;
struct ConnectedPeer *cp = value;
@@ -753,7 +735,7 @@ send_confirmation_receipt (void *cls,
my_receipt = GNUNET_memdup (receipt,
sizeof (struct P2PConfirmationReceiptMessage));
if (NULL == GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_YES,
+ GNUNET_YES,
1,
MAX_TRANSMIT_DELAY,
&pid,
@@ -791,86 +773,84 @@ handle_acknowledge_request (void *cls,
author = client_list_head;
while ((NULL != author) &&
(0 != memcmp (&receipt->author,
- &author->id,
- sizeof (GNUNET_HashCode))))
+ &author->id, sizeof (GNUNET_HashCode))))
author = author->next;
if (NULL == author)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown author of the original message\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown author of the original message\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
target = client_list_head;
while ((NULL != target) &&
(0 != memcmp (&receipt->target,
- &target->id,
- sizeof (GNUNET_HashCode))))
+ &target->id, sizeof (GNUNET_HashCode))))
target = target->next;
if (NULL == target)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown target of the confirmation receipt\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown target of the confirmation receipt\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
if (NULL == author->client)
- {
- target->rcpt_sequence_number++;
+ {
+ target->rcpt_sequence_number++;
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Broadcasting %s's receipt #%u to neighbour peers\n",
- GNUNET_h2s (&target->id), target->rcpt_sequence_number);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Broadcasting %s's receipt #%u to neighbour peers\n",
+ GNUNET_h2s (&target->id), target->rcpt_sequence_number);
#endif
- p2p_crmsg = GNUNET_malloc (sizeof (struct P2PConfirmationReceiptMessage));
- p2p_crmsg->header.size = htons (sizeof (struct P2PConfirmationReceiptMessage));
- p2p_crmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT);
- p2p_crmsg->reserved = htonl (0);
- p2p_crmsg->signature = receipt->signature;
- p2p_crmsg->purpose = receipt->purpose;
- p2p_crmsg->msg_sequence_number = receipt->sequence_number;
- p2p_crmsg->timestamp = receipt->timestamp;
- p2p_crmsg->target = receipt->target;
- p2p_crmsg->author = receipt->author;
- p2p_crmsg->content = receipt->content;
- p2p_crmsg->sequence_number = htonl (target->rcpt_sequence_number);
- GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_confirmation_receipt,
- p2p_crmsg);
- GNUNET_free (p2p_crmsg);
- }
+ p2p_crmsg = GNUNET_malloc (sizeof (struct P2PConfirmationReceiptMessage));
+ p2p_crmsg->header.size =
+ htons (sizeof (struct P2PConfirmationReceiptMessage));
+ p2p_crmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT);
+ p2p_crmsg->reserved = htonl (0);
+ p2p_crmsg->signature = receipt->signature;
+ p2p_crmsg->purpose = receipt->purpose;
+ p2p_crmsg->msg_sequence_number = receipt->sequence_number;
+ p2p_crmsg->timestamp = receipt->timestamp;
+ p2p_crmsg->target = receipt->target;
+ p2p_crmsg->author = receipt->author;
+ p2p_crmsg->content = receipt->content;
+ p2p_crmsg->sequence_number = htonl (target->rcpt_sequence_number);
+ GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
+ &send_confirmation_receipt,
+ p2p_crmsg);
+ GNUNET_free (p2p_crmsg);
+ }
else
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Verifying signature of the receipt\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Verifying signature of the receipt\n");
#endif
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
- &receipt->purpose,
- &receipt->signature,
- &target->public_key))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Invalid signature of the receipt\n");
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
+ &receipt->purpose,
+ &receipt->signature, &target->public_key))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid signature of the receipt\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending receipt to the client which sent the original message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending receipt to the client which sent the original message\n");
#endif
- crmsg = GNUNET_memdup (receipt, sizeof (struct ConfirmationReceiptMessage));
- crmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION);
- GNUNET_SERVER_notification_context_unicast (nc,
- author->client,
- &crmsg->header,
- GNUNET_NO);
- GNUNET_free (crmsg);
- }
+ crmsg = GNUNET_memdup (receipt, sizeof (struct ConfirmationReceiptMessage));
+ crmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION);
+ GNUNET_SERVER_notification_context_unicast (nc, author->client,
+ &crmsg->header, GNUNET_NO);
+ GNUNET_free (crmsg);
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -885,27 +865,24 @@ handle_acknowledge_request (void *cls,
* @return number of bytes written to buf
*/
static size_t
-transmit_leave_notification_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_leave_notification_to_peer (void *cls, size_t size, void *buf)
{
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key = cls;
struct P2PLeaveNotificationMessage *m = buf;
size_t msg_size;
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting P2P leave notification\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting P2P leave notification\n");
#endif
if (buf == NULL)
- {
- /* client disconnected */
+ {
+ /* client disconnected */
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Buffer is NULL, dropping the message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Buffer is NULL, dropping the message\n");
#endif
- return 0;
- }
+ return 0;
+ }
msg_size = sizeof (struct P2PLeaveNotificationMessage);
GNUNET_assert (size >= msg_size);
m = buf;
@@ -922,9 +899,7 @@ transmit_leave_notification_to_peer (void *cls,
* Ask to send a leave notification to the peer.
*/
static int
-send_leave_noficiation (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_leave_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ChatClient *entry = cls;
struct ConnectedPeer *cp = value;
@@ -939,15 +914,13 @@ send_leave_noficiation (void *cls,
#endif
msg_size = sizeof (struct P2PLeaveNotificationMessage);
public_key = GNUNET_memdup (&entry->public_key,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- if (NULL == GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_YES,
- 1,
- MAX_TRANSMIT_DELAY,
- &pid,
- msg_size,
- &transmit_leave_notification_to_peer,
- public_key))
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ if (NULL ==
+ GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1,
+ MAX_TRANSMIT_DELAY, &pid, msg_size,
+ &transmit_leave_notification_to_peer,
+ public_key))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Failed to queue a leave notification\n"));
return GNUNET_YES;
@@ -962,8 +935,7 @@ send_leave_noficiation (void *cls,
* @param client identification of the client
*/
static void
-handle_client_disconnect (void *cls,
- struct GNUNET_SERVER_Client *client)
+handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
struct ChatClient *entry;
struct ChatClient *pos;
@@ -974,18 +946,18 @@ handle_client_disconnect (void *cls,
pos = client_list_head;
prev = NULL;
while ((NULL != pos) && (pos->client != client))
- {
- prev = pos;
- pos = pos->next;
- }
+ {
+ prev = pos;
+ pos = pos->next;
+ }
if (NULL == pos)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No such client. There is nothing to do\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No such client. There is nothing to do\n");
#endif
- return;
- }
+ return;
+ }
if (NULL == prev)
client_list_head = pos->next;
else
@@ -1000,24 +972,21 @@ handle_client_disconnect (void *cls,
lnmsg.reserved = htonl (0);
lnmsg.user = pos->public_key;
while (NULL != entry)
+ {
+ if ((0 == strcmp (pos->room, entry->room)) && (NULL != entry->client))
{
- if ((0 == strcmp (pos->room, entry->room)) &&
- (NULL != entry->client))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- entry->client,
- &lnmsg.header,
- GNUNET_NO);
- }
- entry = entry->next;
+ GNUNET_SERVER_notification_context_unicast (nc,
+ entry->client,
+ &lnmsg.header, GNUNET_NO);
}
+ entry = entry->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting leave notification to neighbour peers\n");
#endif
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_leave_noficiation,
- pos);
+ &send_leave_noficiation, pos);
GNUNET_free (pos->room);
GNUNET_free_non_null (pos->member_info);
GNUNET_free (pos);
@@ -1038,7 +1007,8 @@ static int
handle_p2p_join_notification (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
const struct P2PJoinNotificationMessage *p2p_jnmsg;
char *room_name;
@@ -1053,40 +1023,39 @@ handle_p2p_join_notification (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got P2P join notification\n");
if (ntohs (message->size) <= sizeof (struct P2PJoinNotificationMessage))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
p2p_jnmsg = (const struct P2PJoinNotificationMessage *) message;
header_size = ntohs (p2p_jnmsg->header.size);
room_name_len = ntohs (p2p_jnmsg->room_name_len);
- if (header_size - sizeof (struct P2PJoinNotificationMessage) <=
- room_name_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed message: wrong length of the room name\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ if (header_size - sizeof (struct P2PJoinNotificationMessage) <= room_name_len)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Malformed message: wrong length of the room name\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_CRYPTO_hash (&p2p_jnmsg->public_key,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&id);
entry = client_list_head;
while (NULL != entry)
+ {
+ if (0 == memcmp (&entry->id, &id, sizeof (GNUNET_HashCode)))
{
- if (0 == memcmp (&entry->id, &id, sizeof (GNUNET_HashCode)))
- {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The client has already joined. There is nothing to do\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The client has already joined. There is nothing to do\n");
#endif
- return GNUNET_OK;
- }
- entry = entry->next;
+ return GNUNET_OK;
}
+ entry = entry->next;
+ }
meta_len =
- header_size - sizeof (struct P2PJoinNotificationMessage) - room_name_len;
+ header_size - sizeof (struct P2PJoinNotificationMessage) - room_name_len;
roomptr = (const char *) &p2p_jnmsg[1];
room_name = GNUNET_malloc (room_name_len + 1);
memcpy (room_name, roomptr, room_name_len);
@@ -1099,10 +1068,10 @@ handle_p2p_join_notification (void *cls,
new_entry->public_key = p2p_jnmsg->public_key;
new_entry->meta_len = meta_len;
if (meta_len > 0)
- {
- new_entry->member_info = GNUNET_malloc (meta_len);
- memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len);
- }
+ {
+ new_entry->member_info = GNUNET_malloc (meta_len);
+ memcpy (new_entry->member_info, &roomptr[room_name_len], meta_len);
+ }
else
new_entry->member_info = NULL;
new_entry->msg_options = ntohl (p2p_jnmsg->msg_options);
@@ -1115,30 +1084,27 @@ handle_p2p_join_notification (void *cls,
jnmsg = GNUNET_malloc (sizeof (struct JoinNotificationMessage) + meta_len);
jnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION);
jnmsg->header.size =
- htons (sizeof (struct JoinNotificationMessage) + meta_len);
+ htons (sizeof (struct JoinNotificationMessage) + meta_len);
jnmsg->msg_options = p2p_jnmsg->msg_options;
jnmsg->public_key = new_entry->public_key;
memcpy (&jnmsg[1], &roomptr[room_name_len], meta_len);
entry = client_list_head;
while (NULL != entry)
+ {
+ if ((0 == strcmp (room_name, entry->room)) && (NULL != entry->client))
{
- if ((0 == strcmp (room_name, entry->room)) &&
- (NULL != entry->client))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- entry->client,
- &jnmsg->header,
- GNUNET_NO);
- }
- entry = entry->next;
+ GNUNET_SERVER_notification_context_unicast (nc,
+ entry->client,
+ &jnmsg->header, GNUNET_NO);
}
+ entry = entry->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting join notification to neighbour peers\n");
#endif
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_join_noficiation,
- new_entry);
+ &send_join_noficiation, new_entry);
GNUNET_free (jnmsg);
return GNUNET_OK;
}
@@ -1158,7 +1124,8 @@ static int
handle_p2p_leave_notification (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
const struct P2PLeaveNotificationMessage *p2p_lnmsg;
GNUNET_HashCode id;
@@ -1175,20 +1142,20 @@ handle_p2p_leave_notification (void *cls,
pos = client_list_head;
prev = NULL;
while (NULL != pos)
- {
- if (0 == memcmp (&pos->id, &id, sizeof (GNUNET_HashCode)))
- break;
- prev = pos;
- pos = pos->next;
- }
+ {
+ if (0 == memcmp (&pos->id, &id, sizeof (GNUNET_HashCode)))
+ break;
+ prev = pos;
+ pos = pos->next;
+ }
if (NULL == pos)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No such client. There is nothing to do\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No such client. There is nothing to do\n");
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
if (NULL == prev)
client_list_head = pos->next;
else
@@ -1203,24 +1170,21 @@ handle_p2p_leave_notification (void *cls,
lnmsg.user = pos->public_key;
entry = client_list_head;
while (NULL != entry)
+ {
+ if (0 == strcmp (pos->room, entry->room) && (NULL != entry->client))
{
- if (0 == strcmp (pos->room, entry->room) &&
- (NULL != entry->client))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- entry->client,
- &lnmsg.header,
- GNUNET_NO);
- }
- entry = entry->next;
+ GNUNET_SERVER_notification_context_unicast (nc,
+ entry->client,
+ &lnmsg.header, GNUNET_NO);
}
+ entry = entry->next;
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Broadcasting leave notification to neighbour peers\n");
#endif
GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_leave_noficiation,
- pos);
+ &send_leave_noficiation, pos);
GNUNET_free (pos->room);
GNUNET_free_non_null (pos->member_info);
GNUNET_free (pos);
@@ -1242,7 +1206,8 @@ static int
handle_p2p_message_notification (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
const struct P2PReceiveNotificationMessage *p2p_rnmsg;
struct P2PReceiveNotificationMessage *my_p2p_rnmsg;
@@ -1259,74 +1224,73 @@ handle_p2p_message_notification (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got P2P message notification\n");
if (ntohs (message->size) <= sizeof (struct P2PReceiveNotificationMessage))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed message: wrong size\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
p2p_rnmsg = (const struct P2PReceiveNotificationMessage *) message;
msg_len = ntohs (p2p_rnmsg->header.size) -
- sizeof (struct P2PReceiveNotificationMessage);
+ sizeof (struct P2PReceiveNotificationMessage);
is_anon = (0 != (ntohl (p2p_rnmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS));
if (is_anon)
+ {
+ room_name_len = ntohs (p2p_rnmsg->room_name_len);
+ if (msg_len <= room_name_len)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Malformed message: wrong length of the room name\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ msg_len -= room_name_len;
+ if (lookup_anonymous_message (p2p_rnmsg))
{
- room_name_len = ntohs (p2p_rnmsg->room_name_len);
- if (msg_len <= room_name_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed message: wrong length of the room name\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- msg_len -= room_name_len;
- if (lookup_anonymous_message (p2p_rnmsg))
- {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "This anonymous message has already been handled.");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "This anonymous message has already been handled.");
#endif
- return GNUNET_OK;
- }
- remember_anonymous_message (p2p_rnmsg);
- room_name = GNUNET_malloc (room_name_len + 1);
- memcpy (room_name, (char *) &p2p_rnmsg[1], room_name_len);
- room_name[room_name_len] = '\0';
- text = (char *) &p2p_rnmsg[1] + room_name_len;
+ return GNUNET_OK;
}
+ remember_anonymous_message (p2p_rnmsg);
+ room_name = GNUNET_malloc (room_name_len + 1);
+ memcpy (room_name, (char *) &p2p_rnmsg[1], room_name_len);
+ room_name[room_name_len] = '\0';
+ text = (char *) &p2p_rnmsg[1] + room_name_len;
+ }
else
+ {
+ sender = client_list_head;
+ while ((NULL != sender) &&
+ (0 != memcmp (&sender->id,
+ &p2p_rnmsg->sender, sizeof (GNUNET_HashCode))))
+ sender = sender->next;
+ if (NULL == sender)
{
- sender = client_list_head;
- while ((NULL != sender) &&
- (0 != memcmp (&sender->id,
- &p2p_rnmsg->sender,
- sizeof (GNUNET_HashCode))))
- sender = sender->next;
- if (NULL == sender)
- {
- /* not an error since the sender may have left before we got the
- message */
+ /* not an error since the sender may have left before we got the
+ * message */
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Unknown source. Rejecting the message\n");
#endif
- return GNUNET_OK;
+ return GNUNET_OK;
}
- if (sender->msg_sequence_number >= ntohl (p2p_rnmsg->sequence_number))
+ if (sender->msg_sequence_number >= ntohl (p2p_rnmsg->sequence_number))
{
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"This message has already been handled."
" Sequence numbers (msg/sender): %u/%u\n",
- ntohl (p2p_rnmsg->sequence_number),
- sender->msg_sequence_number);
+ ntohl (p2p_rnmsg->sequence_number),
+ sender->msg_sequence_number);
#endif
return GNUNET_OK;
}
- sender->msg_sequence_number = ntohl (p2p_rnmsg->sequence_number);
- room_name = sender->room;
- text = (char *) &p2p_rnmsg[1];
- }
+ sender->msg_sequence_number = ntohl (p2p_rnmsg->sequence_number);
+ room_name = sender->room;
+ text = (char *) &p2p_rnmsg[1];
+ }
#if DEBUG_CHAT_SERVICE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1341,7 +1305,7 @@ handle_p2p_message_notification (void *cls,
rnmsg->reserved = htonl (0);
rnmsg->timestamp = p2p_rnmsg->timestamp;
is_priv = (0 != memcmp (&all_zeros,
- &p2p_rnmsg->target, sizeof (GNUNET_HashCode)));
+ &p2p_rnmsg->target, sizeof (GNUNET_HashCode)));
if (is_priv)
memcpy (&rnmsg->encrypted_key,
&p2p_rnmsg->encrypted_key,
@@ -1350,24 +1314,22 @@ handle_p2p_message_notification (void *cls,
memcpy (&rnmsg[1], text, msg_len);
pos = client_list_head;
while (NULL != pos)
+ {
+ if ((0 == strcmp (room_name, pos->room)) && (NULL != pos->client))
{
- if ((0 == strcmp (room_name, pos->room)) &&
- (NULL != pos->client))
- {
- if (((!is_priv) ||
- (0 == memcmp (&p2p_rnmsg->target,
- &pos->id,
- sizeof (GNUNET_HashCode)))) &&
- (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options))))
- {
- GNUNET_SERVER_notification_context_unicast (nc,
- pos->client,
- &rnmsg->header,
- GNUNET_NO);
- }
- }
- pos = pos->next;
+ if (((!is_priv) ||
+ (0 == memcmp (&p2p_rnmsg->target,
+ &pos->id,
+ sizeof (GNUNET_HashCode)))) &&
+ (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options))))
+ {
+ GNUNET_SERVER_notification_context_unicast (nc,
+ pos->client,
+ &rnmsg->header, GNUNET_NO);
+ }
}
+ pos = pos->next;
+ }
if (is_anon)
GNUNET_free (room_name);
#if DEBUG_CHAT_SERVICE
@@ -1410,21 +1372,20 @@ handle_p2p_sync_request (void *cls,
#endif
entry = client_list_head;
while (NULL != entry)
- {
- msg_size = sizeof (struct P2PJoinNotificationMessage) +
- strlen (entry->room) +
- entry->meta_len;
- th = GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_NO,
- 1,
- MAX_TRANSMIT_DELAY,
- other,
- msg_size,
- &transmit_join_notification_to_peer,
- entry);
- GNUNET_assert (NULL != th);
- entry = entry->next;
- }
+ {
+ msg_size = sizeof (struct P2PJoinNotificationMessage) +
+ strlen (entry->room) + entry->meta_len;
+ th = GNUNET_CORE_notify_transmit_ready (core,
+ GNUNET_NO,
+ 1,
+ MAX_TRANSMIT_DELAY,
+ other,
+ msg_size,
+ &transmit_join_notification_to_peer,
+ entry);
+ GNUNET_assert (NULL != th);
+ entry = entry->next;
+ }
return GNUNET_OK;
}
@@ -1443,7 +1404,8 @@ static int
handle_p2p_confirmation_receipt (void *cls,
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_TRANSPORT_ATS_Information
+ *atsi)
{
const struct P2PConfirmationReceiptMessage *p2p_crmsg;
struct P2PConfirmationReceiptMessage *my_p2p_crmsg;
@@ -1456,94 +1418,94 @@ handle_p2p_confirmation_receipt (void *cls,
target = client_list_head;
while ((NULL != target) &&
(0 != memcmp (&target->id,
- &p2p_crmsg->target,
- sizeof (GNUNET_HashCode))))
+ &p2p_crmsg->target, sizeof (GNUNET_HashCode))))
target = target->next;
if (NULL == target)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown source of the receipt. Rejecting the message\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown source of the receipt. Rejecting the message\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if (target->rcpt_sequence_number >= ntohl (p2p_crmsg->sequence_number))
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "This receipt has already been handled."
- " Sequence numbers (msg/sender): %u/%u\n",
- ntohl (p2p_crmsg->sequence_number), target->rcpt_sequence_number);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "This receipt has already been handled."
+ " Sequence numbers (msg/sender): %u/%u\n",
+ ntohl (p2p_crmsg->sequence_number),
+ target->rcpt_sequence_number);
#endif
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
target->rcpt_sequence_number = ntohl (p2p_crmsg->sequence_number);
author = client_list_head;
while ((NULL != author) &&
(0 != memcmp (&author->id,
- &p2p_crmsg->author,
- sizeof (GNUNET_HashCode))))
+ &p2p_crmsg->author, sizeof (GNUNET_HashCode))))
author = author->next;
if (NULL == author)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unknown addressee. Rejecting the receipt\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unknown addressee. Rejecting the receipt\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if (NULL == author->client)
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The author of the original message is not a local client."
- " Broadcasting receipt to neighbour peers\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The author of the original message is not a local client."
+ " Broadcasting receipt to neighbour peers\n");
#endif
- my_p2p_crmsg = GNUNET_memdup (p2p_crmsg, sizeof (struct P2PConfirmationReceiptMessage));
- GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &send_confirmation_receipt,
- my_p2p_crmsg);
- GNUNET_free (my_p2p_crmsg);
- }
+ my_p2p_crmsg =
+ GNUNET_memdup (p2p_crmsg,
+ sizeof (struct P2PConfirmationReceiptMessage));
+ GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
+ &send_confirmation_receipt,
+ my_p2p_crmsg);
+ GNUNET_free (my_p2p_crmsg);
+ }
else
- {
+ {
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The author of the original message is a local client."
- " Verifying signature of the receipt\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The author of the original message is a local client."
+ " Verifying signature of the receipt\n");
#endif
- crmsg = GNUNET_malloc (sizeof (struct ConfirmationReceiptMessage));
- crmsg->header.size = htons (sizeof (struct ConfirmationReceiptMessage));
- crmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION);
- crmsg->signature = p2p_crmsg->signature;
- crmsg->purpose = p2p_crmsg->purpose;
- crmsg->sequence_number = p2p_crmsg->msg_sequence_number;
- crmsg->reserved2 = 0;
- crmsg->timestamp = p2p_crmsg->timestamp;
- crmsg->target = p2p_crmsg->target;
- crmsg->author = p2p_crmsg->author;
- crmsg->content = p2p_crmsg->content;
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
- &crmsg->purpose,
- &crmsg->signature,
- &target->public_key))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Invalid signature of the receipt\n");
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ crmsg = GNUNET_malloc (sizeof (struct ConfirmationReceiptMessage));
+ crmsg->header.size = htons (sizeof (struct ConfirmationReceiptMessage));
+ crmsg->header.type =
+ htons (GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION);
+ crmsg->signature = p2p_crmsg->signature;
+ crmsg->purpose = p2p_crmsg->purpose;
+ crmsg->sequence_number = p2p_crmsg->msg_sequence_number;
+ crmsg->reserved2 = 0;
+ crmsg->timestamp = p2p_crmsg->timestamp;
+ crmsg->target = p2p_crmsg->target;
+ crmsg->author = p2p_crmsg->author;
+ crmsg->content = p2p_crmsg->content;
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT,
+ &crmsg->purpose,
+ &crmsg->signature, &target->public_key))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid signature of the receipt\n");
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
#if DEBUG_CHAT_SERVICE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The author of the original message is a local client."
- " Sending receipt to the client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "The author of the original message is a local client."
+ " Sending receipt to the client\n");
#endif
- GNUNET_SERVER_notification_context_unicast (nc,
- author->client,
- &crmsg->header,
- GNUNET_NO);
- GNUNET_free (crmsg);
- }
+ GNUNET_SERVER_notification_context_unicast (nc,
+ author->client,
+ &crmsg->header, GNUNET_NO);
+ GNUNET_free (crmsg);
+ }
return GNUNET_OK;
}
@@ -1557,9 +1519,7 @@ handle_p2p_confirmation_receipt (void *cls,
* @return number of bytes written to buf
*/
static size_t
-transmit_sync_request_to_peer (void *cls,
- size_t size,
- void *buf)
+transmit_sync_request_to_peer (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader *m = buf;
size_t msg_size;
@@ -1584,7 +1544,7 @@ transmit_sync_request_to_peer (void *cls,
* @param peer peer identity this notification is about
* @param atsi performance data
*/
-static void
+static void
peer_connect_handler (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
@@ -1597,21 +1557,19 @@ peer_connect_handler (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Peer connected: %s\n", GNUNET_i2s (peer));
th = GNUNET_CORE_notify_transmit_ready (core,
- GNUNET_YES,
+ GNUNET_YES,
1,
MAX_TRANSMIT_DELAY,
peer,
sizeof (struct GNUNET_MessageHeader),
- &transmit_sync_request_to_peer,
- NULL);
+ &transmit_sync_request_to_peer, NULL);
GNUNET_assert (NULL != th);
- cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
- &peer->hashPubKey);
+ cp = GNUNET_CONTAINER_multihashmap_get (connected_peers, &peer->hashPubKey);
if (NULL != cp)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
cp = GNUNET_malloc (sizeof (struct ConnectedPeer));
cp->pid = GNUNET_PEER_intern (peer);
GNUNET_break (GNUNET_OK ==
@@ -1630,22 +1588,19 @@ peer_connect_handler (void *cls,
* @param value value in the hash map (peer entry)
* @return GNUNET_YES (we should continue to iterate)
*/
-static int
-clean_peer (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+clean_peer (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ConnectedPeer *cp;
- const struct GNUNET_PeerIdentity *peer = (const struct GNUNET_PeerIdentity *) key;
+ const struct GNUNET_PeerIdentity *peer =
+ (const struct GNUNET_PeerIdentity *) key;
- cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
- &peer->hashPubKey);
+ cp = GNUNET_CONTAINER_multihashmap_get (connected_peers, &peer->hashPubKey);
if (cp == NULL)
return GNUNET_YES;
GNUNET_break (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (connected_peers,
- &peer->hashPubKey,
- cp));
+ &peer->hashPubKey, cp));
GNUNET_PEER_change_rc (cp->pid, -1);
GNUNET_free (cp);
return GNUNET_YES;
@@ -1659,8 +1614,7 @@ clean_peer (void *cls,
* @param peer peer identity this notification is about
*/
static void
-peer_disconnect_handler (void *cls,
- const struct GNUNET_PeerIdentity *peer)
+peer_disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
{
if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity)))
@@ -1678,40 +1632,37 @@ peer_disconnect_handler (void *cls,
* @param tc unused
*/
static void
-cleanup_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct AnonymousMessage *next_msg;
struct ChatClient *next_client;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Cleaning up\n");
if (NULL != core)
- {
- GNUNET_CORE_disconnect (core);
- core = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (core);
+ core = NULL;
+ }
if (NULL != nc)
- {
- GNUNET_SERVER_notification_context_destroy (nc);
- nc = NULL;
- }
+ {
+ GNUNET_SERVER_notification_context_destroy (nc);
+ nc = NULL;
+ }
while (NULL != client_list_head)
- {
- next_client = client_list_head->next;
- GNUNET_free (client_list_head->room);
- GNUNET_free_non_null (client_list_head->member_info);
- GNUNET_free (client_list_head);
- client_list_head = next_client;
- }
+ {
+ next_client = client_list_head->next;
+ GNUNET_free (client_list_head->room);
+ GNUNET_free_non_null (client_list_head->member_info);
+ GNUNET_free (client_list_head);
+ client_list_head = next_client;
+ }
while (NULL != anonymous_list_head)
- {
- next_msg = anonymous_list_head->next;
- GNUNET_free (anonymous_list_head);
- anonymous_list_head = next_msg;
- }
- GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
- &clean_peer,
- NULL);
+ {
+ next_msg = anonymous_list_head->next;
+ GNUNET_free (anonymous_list_head);
+ anonymous_list_head = next_msg;
+ }
+ GNUNET_CONTAINER_multihashmap_iterate (connected_peers, &clean_peer, NULL);
GNUNET_CONTAINER_multihashmap_destroy (connected_peers);
connected_peers = NULL;
}
@@ -1748,34 +1699,32 @@ run (void *cls,
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
- static const struct GNUNET_SERVER_MessageHandler handlers[] =
- {
- { &handle_join_request, NULL,
- GNUNET_MESSAGE_TYPE_CHAT_JOIN_REQUEST, 0 },
- { &handle_transmit_request, NULL,
- GNUNET_MESSAGE_TYPE_CHAT_TRANSMIT_REQUEST, 0 },
- { &handle_acknowledge_request, NULL,
- GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT,
- sizeof (struct ConfirmationReceiptMessage) },
- { NULL, NULL, 0, 0 }
- };
- static const struct GNUNET_CORE_MessageHandler p2p_handlers[] =
- {
- { &handle_p2p_join_notification,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_JOIN_NOTIFICATION, 0 },
- { &handle_p2p_leave_notification,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_LEAVE_NOTIFICATION,
- sizeof (struct P2PLeaveNotificationMessage) },
- { &handle_p2p_message_notification,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION, 0 },
- { &handle_p2p_sync_request,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_SYNC_REQUEST,
- sizeof (struct GNUNET_MessageHeader) },
- { &handle_p2p_confirmation_receipt,
- GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT,
- sizeof (struct P2PConfirmationReceiptMessage) },
- { NULL, 0, 0 }
- };
+ static const struct GNUNET_SERVER_MessageHandler handlers[] = {
+ {&handle_join_request, NULL,
+ GNUNET_MESSAGE_TYPE_CHAT_JOIN_REQUEST, 0},
+ {&handle_transmit_request, NULL,
+ GNUNET_MESSAGE_TYPE_CHAT_TRANSMIT_REQUEST, 0},
+ {&handle_acknowledge_request, NULL,
+ GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT,
+ sizeof (struct ConfirmationReceiptMessage)},
+ {NULL, NULL, 0, 0}
+ };
+ static const struct GNUNET_CORE_MessageHandler p2p_handlers[] = {
+ {&handle_p2p_join_notification,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_JOIN_NOTIFICATION, 0},
+ {&handle_p2p_leave_notification,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_LEAVE_NOTIFICATION,
+ sizeof (struct P2PLeaveNotificationMessage)},
+ {&handle_p2p_message_notification,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION, 0},
+ {&handle_p2p_sync_request,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_SYNC_REQUEST,
+ sizeof (struct GNUNET_MessageHeader)},
+ {&handle_p2p_confirmation_receipt,
+ GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT,
+ sizeof (struct P2PConfirmationReceiptMessage)},
+ {NULL, 0, 0}
+ };
GNUNET_log_setup ("gnunet-service-chat",
#if DEBUG_CHAT_SERVICE
@@ -1786,7 +1735,8 @@ run (void *cls,
NULL);
cfg = c;
nc = GNUNET_SERVER_notification_context_create (server, 16);
- connected_peers = GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT);
+ connected_peers =
+ GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT);
GNUNET_SERVER_add_handlers (server, handlers);
core = GNUNET_CORE_connect (cfg,
QUEUE_SIZE,
@@ -1795,15 +1745,10 @@ run (void *cls,
&peer_connect_handler,
&peer_disconnect_handler,
NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- p2p_handlers);
- GNUNET_SERVER_disconnect_notify (server,
- &handle_client_disconnect,
- NULL);
+ NULL, GNUNET_NO, NULL, GNUNET_NO, p2p_handlers);
+ GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup_task,
- NULL);
+ &cleanup_task, NULL);
}
@@ -1821,8 +1766,7 @@ main (int argc, char *const *argv)
GNUNET_SERVICE_run (argc,
argv,
"chat",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
}
/* end of gnunet-service-chat.c */
diff --git a/src/chat/test_chat.c b/src/chat/test_chat.c
index 7a20c0331..0953a895b 100644
--- a/src/chat/test_chat.c
+++ b/src/chat/test_chat.c
@@ -119,11 +119,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -135,10 +135,11 @@ stop_arm (struct PeerContext *p)
#if START_ARM
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -147,36 +148,34 @@ stop_arm (struct PeerContext *p)
static void
-abort_test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (alice_room != NULL)
- {
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ }
if (bob_room != NULL)
- {
- GNUNET_CHAT_leave_room (bob_room);
- bob_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (bob_room);
+ bob_room = NULL;
+ }
err = 1;
}
static void
-timeout_kill (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_kill (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Timed out, stopping the test.\n");
#endif
kill_task = GNUNET_SCHEDULER_NO_TASK;
if (wait_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (wait_task);
- wait_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (wait_task);
+ wait_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_SCHEDULER_add_continuation (&abort_test, NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -207,11 +206,11 @@ member_list_cb (void *cls,
#if VERBOSE
printf ("%s - told that %s has %s\n",
- want->me,
- member_info == NULL ? NULL
- : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
- EXTRACTOR_METATYPE_TITLE),
- member_info == NULL ? "left" : "joined");
+ want->me,
+ member_info == NULL ? NULL
+ : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
+ EXTRACTOR_METATYPE_TITLE),
+ member_info == NULL ? "left" : "joined");
#endif
GNUNET_CRYPTO_hash (member_id,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
@@ -225,16 +224,16 @@ member_list_cb (void *cls,
(GNUNET_CONTAINER_meta_data_test_equal (member_info,
want->meta)))) &&
(options == want->opt))
- {
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
+ {
+ if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
@@ -242,7 +241,7 @@ member_list_cb (void *cls,
static int
receive_cb (void *cls,
struct GNUNET_CHAT_Room *room,
- const GNUNET_HashCode *sender,
+ const GNUNET_HashCode * sender,
const struct GNUNET_CONTAINER_MetaData *meta,
const char *message,
struct GNUNET_TIME_Absolute timestamp,
@@ -269,16 +268,16 @@ receive_cb (void *cls,
* slightly greater
*/
(timestamp.abs_value >= want->timestamp.abs_value))
- {
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
+ {
+ if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
@@ -288,7 +287,7 @@ confirmation_cb (void *cls,
struct GNUNET_CHAT_Room *room,
uint32_t orig_seq_number,
struct GNUNET_TIME_Absolute timestamp,
- const GNUNET_HashCode *receiver)
+ const GNUNET_HashCode * receiver)
{
struct Wanted *want = cls;
@@ -303,23 +302,22 @@ confirmation_cb (void *cls,
sizeof (GNUNET_HashCode))) &&
(orig_seq_number == want->sequence_number) &&
(timestamp.abs_value >= want->timestamp.abs_value))
- {
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
+ {
+ if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
static void
-wait_until_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+wait_until_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SCHEDULER_Task task = cls;
@@ -327,22 +325,20 @@ wait_until_ready (void *cls,
printf ("Waiting...\n");
#endif
if (is_ready)
- {
- wait_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (task, NULL);
- }
+ {
+ wait_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (task, NULL);
+ }
else
wait_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- 50),
- &wait_until_ready,
- task);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 50),
+ &wait_until_ready, task);
}
static void
-disconnect_alice (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Alice is leaving.\n");
@@ -357,8 +353,7 @@ disconnect_alice (void *cls,
static void
-disconnect_bob (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bod is leaving.\n");
@@ -375,16 +370,14 @@ disconnect_bob (void *cls,
static void
-set_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+set_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
is_ready = GNUNET_YES;
}
static void
-send_to_alice (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_to_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bob says 'Hi!'\n");
@@ -399,15 +392,12 @@ send_to_alice (void *cls,
alice_wanted.next_task_cls = NULL;
GNUNET_CHAT_send_message (bob_room,
"Hi Alice!",
- GNUNET_CHAT_MSG_OPTION_NONE,
- NULL,
- NULL);
+ GNUNET_CHAT_MSG_OPTION_NONE, NULL, NULL);
}
static void
-send_to_bob (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_to_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
enum GNUNET_CHAT_MsgOptions options;
uint32_t *seq = NULL;
@@ -416,39 +406,39 @@ send_to_bob (void *cls,
printf ("Alice says 'Hi!'\n");
#endif
if (is_ackn)
- {
- options = GNUNET_CHAT_MSG_ACKNOWLEDGED;
- alice_wanted.meta = bob_meta;
- alice_wanted.sender = &bob;
- alice_wanted.timestamp = GNUNET_TIME_absolute_get ();
- alice_wanted.next_task = &disconnect_bob;
- alice_wanted.next_task_cls = NULL;
- bob_wanted.meta = alice_meta;
- bob_wanted.sender = &alice;
- bob_wanted.next_task = NULL;
- seq = &(alice_wanted.sequence_number);
- }
+ {
+ options = GNUNET_CHAT_MSG_ACKNOWLEDGED;
+ alice_wanted.meta = bob_meta;
+ alice_wanted.sender = &bob;
+ alice_wanted.timestamp = GNUNET_TIME_absolute_get ();
+ alice_wanted.next_task = &disconnect_bob;
+ alice_wanted.next_task_cls = NULL;
+ bob_wanted.meta = alice_meta;
+ bob_wanted.sender = &alice;
+ bob_wanted.next_task = NULL;
+ seq = &(alice_wanted.sequence_number);
+ }
else if (is_anon)
- {
- options = GNUNET_CHAT_MSG_ANONYMOUS;
- bob_wanted.meta = NULL;
- bob_wanted.sender = NULL;
- bob_wanted.next_task = &disconnect_bob;
- }
+ {
+ options = GNUNET_CHAT_MSG_ANONYMOUS;
+ bob_wanted.meta = NULL;
+ bob_wanted.sender = NULL;
+ bob_wanted.next_task = &disconnect_bob;
+ }
else if (is_auth)
- {
- options = GNUNET_CHAT_MSG_AUTHENTICATED;
- bob_wanted.meta = alice_meta;
- bob_wanted.sender = &alice;
- bob_wanted.next_task = &disconnect_bob;
- }
+ {
+ options = GNUNET_CHAT_MSG_AUTHENTICATED;
+ bob_wanted.meta = alice_meta;
+ bob_wanted.sender = &alice;
+ bob_wanted.next_task = &disconnect_bob;
+ }
else
- {
- options = GNUNET_CHAT_MSG_OPTION_NONE;
- bob_wanted.meta = alice_meta;
- bob_wanted.sender = &alice;
- bob_wanted.next_task = &send_to_alice;
- }
+ {
+ options = GNUNET_CHAT_MSG_OPTION_NONE;
+ bob_wanted.meta = alice_meta;
+ bob_wanted.sender = &alice;
+ bob_wanted.next_task = &send_to_alice;
+ }
bob_wanted.msg = "Hi Bob!";
bob_wanted.opt = options;
bob_wanted.timestamp = GNUNET_TIME_absolute_get ();
@@ -471,8 +461,7 @@ prepare_for_alice_task (void *cls,
static void
-join_bob_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bob joining\n");
@@ -487,27 +476,25 @@ join_bob_task (void *cls,
bob_wanted.next_task_cls = NULL;
is_ready = GNUNET_NO;
bob_room =
- GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
- "test", -1,
- &join_cb, &bob_wanted,
- &receive_cb, &bob_wanted,
- &member_list_cb, &bob_wanted,
- &confirmation_cb, &bob_wanted,
- &bob);
+ GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
+ "test", -1,
+ &join_cb, &bob_wanted,
+ &receive_cb, &bob_wanted,
+ &member_list_cb, &bob_wanted,
+ &confirmation_cb, &bob_wanted, &bob);
if (NULL == bob_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ err = 1;
+ }
}
static void
-join_alice_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Alice joining\n");
@@ -515,33 +502,31 @@ join_alice_task (void *cls,
alice_wanted.next_task = &join_bob_task;
alice_wanted.next_task_cls = NULL;
alice_room =
- GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
- "test", -1,
- &join_cb, &alice_wanted,
- &receive_cb, &alice_wanted,
- &member_list_cb, &alice_wanted,
- &confirmation_cb, &alice_wanted,
- &alice);
+ GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
+ "test", -1,
+ &join_cb, &alice_wanted,
+ &receive_cb, &alice_wanted,
+ &member_list_cb, &alice_wanted,
+ &confirmation_cb, &alice_wanted, &alice);
if (NULL == alice_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ err = 1;
+ }
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
if (is_p2p)
- {
- setup_peer (&p1, "test_chat_peer1.conf");
- setup_peer (&p2, "test_chat_peer2.conf");
- }
+ {
+ setup_peer (&p1, "test_chat_peer1.conf");
+ setup_peer (&p2, "test_chat_peer2.conf");
+ }
else
setup_peer (&p1, "test_chat_data.conf");
@@ -555,19 +540,14 @@ run (void *cls,
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- "Alice",
- strlen("Alice")+1);
+ "Alice", strlen ("Alice") + 1);
bob_meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (bob_meta,
"<gnunet>",
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "Bob",
- strlen("Bob")+1);
- kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &timeout_kill,
- NULL);
+ "text/plain", "Bob", strlen ("Bob") + 1);
+ kill_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_kill, NULL);
GNUNET_SCHEDULER_add_now (&join_alice_task, NULL);
}
@@ -575,7 +555,7 @@ run (void *cls,
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-chat",
"-c",
"test_chat_data.conf",
@@ -588,40 +568,39 @@ main (int argc, char *argv[])
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_chat",
+ GNUNET_log_setup ("test_chat",
#if VERBOSE
"DEBUG",
#else
"WARNING",
#endif
NULL);
- if (strstr(argv[0], "p2p") != NULL)
- {
- is_p2p = GNUNET_YES;
- }
- if (strstr(argv[0], "acknowledgment") != NULL)
- {
- is_ackn = GNUNET_YES;
- }
- else if (strstr(argv[0], "anonymous") != NULL)
- {
- is_anon = GNUNET_YES;
- }
- else if (strstr(argv[0], "authentication") != NULL)
- {
- is_auth = GNUNET_YES;
- }
+ if (strstr (argv[0], "p2p") != NULL)
+ {
+ is_p2p = GNUNET_YES;
+ }
+ if (strstr (argv[0], "acknowledgment") != NULL)
+ {
+ is_ackn = GNUNET_YES;
+ }
+ else if (strstr (argv[0], "anonymous") != NULL)
+ {
+ is_anon = GNUNET_YES;
+ }
+ else if (strstr (argv[0], "authentication") != NULL)
+ {
+ is_auth = GNUNET_YES;
+ }
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-chat",
- "nohelp", options, &run, NULL);
+ argvx, "test-chat", "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_CONTAINER_meta_data_destroy (alice_meta);
GNUNET_CONTAINER_meta_data_destroy (bob_meta);
if (is_p2p)
- {
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
- }
+ {
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
+ }
else
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/");
return err;
diff --git a/src/chat/test_chat_private.c b/src/chat/test_chat_private.c
index c14de0a88..507e333c9 100644
--- a/src/chat/test_chat_private.c
+++ b/src/chat/test_chat_private.c
@@ -133,11 +133,11 @@ setup_peer (struct PeerContext *p, const char *cfgname)
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
}
@@ -149,10 +149,11 @@ stop_arm (struct PeerContext *p)
#if START_ARM
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
+ if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc));
+ "ARM process %u stopped\n",
+ GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
#endif
@@ -161,41 +162,39 @@ stop_arm (struct PeerContext *p)
static void
-abort_test (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+abort_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (alice_room != NULL)
- {
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ }
if (bob_room != NULL)
- {
- GNUNET_CHAT_leave_room (bob_room);
- bob_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (bob_room);
+ bob_room = NULL;
+ }
if (carol_room != NULL)
- {
- GNUNET_CHAT_leave_room (carol_room);
- carol_room = NULL;
- }
+ {
+ GNUNET_CHAT_leave_room (carol_room);
+ carol_room = NULL;
+ }
err = 1;
}
static void
-timeout_kill (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_kill (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Timed out, stopping the test.\n");
#endif
kill_task = GNUNET_SCHEDULER_NO_TASK;
if (wait_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (wait_task);
- wait_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (wait_task);
+ wait_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_SCHEDULER_add_continuation (&abort_test, NULL,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -226,11 +225,11 @@ member_list_cb (void *cls,
#if VERBOSE
printf ("%s - told that %s has %s\n",
- want->me,
- member_info == NULL ? NULL
- : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
- EXTRACTOR_METATYPE_TITLE),
- member_info == NULL ? "left" : "joined");
+ want->me,
+ member_info == NULL ? NULL
+ : GNUNET_CONTAINER_meta_data_get_by_type (member_info,
+ EXTRACTOR_METATYPE_TITLE),
+ member_info == NULL ? "left" : "joined");
#endif
GNUNET_CRYPTO_hash (member_id,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
@@ -248,34 +247,34 @@ member_list_cb (void *cls,
GNUNET_CONTAINER_meta_data_test_equal (member_info,
want->meta2))))) &&
(options == want->opt))
- {
- /* remember Bob's public key, we need it to send private message */
- if (NULL == bob_public_key &&
- (0 == memcmp (&bob, want->sender, sizeof (GNUNET_HashCode))))
- bob_public_key =
+ {
+ /* remember Bob's public key, we need it to send private message */
+ if (NULL == bob_public_key &&
+ (0 == memcmp (&bob, want->sender, sizeof (GNUNET_HashCode))))
+ bob_public_key =
GNUNET_memdup (member_id,
- sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- if (want->sender2 != NULL)
- {
- /* flush alternative sender */
- if (0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode)))
- {
- want->sender = want->sender2;
- want->meta = want->meta2;
- }
- want->sender2 = NULL;
- want->meta2 = NULL;
- }
- else
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
- else
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ if (want->sender2 != NULL)
{
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ /* flush alternative sender */
+ if (0 == memcmp (&sender, want->sender, sizeof (GNUNET_HashCode)))
+ {
+ want->sender = want->sender2;
+ want->meta = want->meta2;
+ }
+ want->sender2 = NULL;
+ want->meta2 = NULL;
}
+ else if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
+ else
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
@@ -283,7 +282,7 @@ member_list_cb (void *cls,
static int
receive_cb (void *cls,
struct GNUNET_CHAT_Room *room,
- const GNUNET_HashCode *sender,
+ const GNUNET_HashCode * sender,
const struct GNUNET_CONTAINER_MetaData *meta,
const char *message,
struct GNUNET_TIME_Absolute timestamp,
@@ -311,25 +310,24 @@ receive_cb (void *cls,
* slightly greater
*/
(timestamp.abs_value >= want->timestamp.abs_value))
- {
- if (NULL != want->next_task)
- GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
- }
+ {
+ if (NULL != want->next_task)
+ GNUNET_SCHEDULER_add_now (want->next_task, want->next_task_cls);
+ }
else
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_cancel (finish_task);
- finish_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (&abort_test, NULL);
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_cancel (finish_task);
+ finish_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (&abort_test, NULL);
+ }
return GNUNET_OK;
}
static void
-wait_until_all_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+wait_until_all_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_SCHEDULER_Task task = cls;
@@ -337,38 +335,34 @@ wait_until_all_ready (void *cls,
printf ("Waiting...\n");
#endif
if (alice_ready && bob_ready)
- {
- wait_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_SCHEDULER_add_now (task, NULL);
- }
+ {
+ wait_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_SCHEDULER_add_now (task, NULL);
+ }
else
wait_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- 5000),
- &wait_until_all_ready,
- task);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 5000),
+ &wait_until_all_ready, task);
}
static void
-set_alice_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+set_alice_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
alice_ready = GNUNET_YES;
}
static void
-set_bob_ready (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+set_bob_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
bob_ready = GNUNET_YES;
}
static void
-disconnect_alice (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_alice (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Alice is leaving.\n");
@@ -383,8 +377,7 @@ disconnect_alice (void *cls,
static void
-disconnect_bob (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_bob (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bod is leaving.\n");
@@ -403,8 +396,7 @@ disconnect_bob (void *cls,
static void
-disconnect_carol (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_carol (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Carol is leaving.\n");
@@ -454,8 +446,7 @@ send_from_alice_to_bob (void *cls,
carol_wanted.next_task_cls = NULL;
GNUNET_CHAT_send_message (alice_room,
"Hi Bob!",
- GNUNET_CHAT_MSG_PRIVATE,
- bob_public_key, &seq);
+ GNUNET_CHAT_MSG_PRIVATE, bob_public_key, &seq);
finish_task = GNUNET_SCHEDULER_add_delayed (PM_TIMEOUT,
&wait_until_all_ready,
&disconnect_carol);
@@ -477,12 +468,13 @@ prepare_bob_for_alice_task (void *cls,
static void
prepare_carol_for_alice_and_bob_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext
+ *tc)
{
carol_wanted.meta = alice_meta;
carol_wanted.sender = &alice;
/* set alternative meta/sender since we don't know from which peer
- notification will come first */
+ * notification will come first */
carol_wanted.meta2 = bob_meta;
carol_wanted.sender2 = &bob;
carol_wanted.msg = NULL;
@@ -493,8 +485,7 @@ prepare_carol_for_alice_and_bob_task (void *cls,
static void
-join_carol_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_carol_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Carol joining\n");
@@ -516,28 +507,27 @@ join_carol_task (void *cls,
carol_wanted.next_task = &prepare_carol_for_alice_and_bob_task;
carol_wanted.next_task_cls = NULL;
carol_room =
- GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta,
- "test", -1,
- &join_cb, &carol_wanted,
- &receive_cb, &carol_wanted,
- &member_list_cb, &carol_wanted,
- NULL, NULL, &carol);
+ GNUNET_CHAT_join_room (is_p2p ? p3.cfg : p1.cfg, "carol", carol_meta,
+ "test", -1,
+ &join_cb, &carol_wanted,
+ &receive_cb, &carol_wanted,
+ &member_list_cb, &carol_wanted,
+ NULL, NULL, &carol);
if (NULL == carol_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- GNUNET_CHAT_leave_room (bob_room);
- bob_room = NULL;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ GNUNET_CHAT_leave_room (bob_room);
+ bob_room = NULL;
+ err = 1;
+ }
}
static void
-join_bob_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_bob_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Bob joining\n");
@@ -553,26 +543,24 @@ join_bob_task (void *cls,
bob_wanted.next_task_cls = NULL;
bob_ready = GNUNET_NO;
bob_room =
- GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
- "test", -1,
- &join_cb, &bob_wanted,
- &receive_cb, &bob_wanted,
- &member_list_cb, &bob_wanted,
- NULL, NULL, &bob);
+ GNUNET_CHAT_join_room (is_p2p ? p2.cfg : p1.cfg, "bob", bob_meta,
+ "test", -1,
+ &join_cb, &bob_wanted,
+ &receive_cb, &bob_wanted,
+ &member_list_cb, &bob_wanted, NULL, NULL, &bob);
if (NULL == bob_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_CHAT_leave_room (alice_room);
- alice_room = NULL;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_CHAT_leave_room (alice_room);
+ alice_room = NULL;
+ err = 1;
+ }
}
static void
-join_alice_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+join_alice_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
#if VERBOSE
printf ("Alice joining\n");
@@ -580,33 +568,32 @@ join_alice_task (void *cls,
alice_wanted.next_task = &join_bob_task;
alice_wanted.next_task_cls = NULL;
alice_room =
- GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
- "test", -1,
- &join_cb, &alice_wanted,
- &receive_cb, &alice_wanted,
- &member_list_cb, &alice_wanted,
- NULL, NULL, &alice);
+ GNUNET_CHAT_join_room (p1.cfg, "alice", alice_meta,
+ "test", -1,
+ &join_cb, &alice_wanted,
+ &receive_cb, &alice_wanted,
+ &member_list_cb, &alice_wanted,
+ NULL, NULL, &alice);
if (NULL == alice_room)
- {
- GNUNET_SCHEDULER_cancel (kill_task);
- kill_task = GNUNET_SCHEDULER_NO_TASK;
- err = 1;
- }
+ {
+ GNUNET_SCHEDULER_cancel (kill_task);
+ kill_task = GNUNET_SCHEDULER_NO_TASK;
+ err = 1;
+ }
}
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
if (is_p2p)
- {
- setup_peer (&p1, "test_chat_peer1.conf");
- setup_peer (&p2, "test_chat_peer2.conf");
- setup_peer (&p3, "test_chat_peer3.conf");
- }
+ {
+ setup_peer (&p1, "test_chat_peer1.conf");
+ setup_peer (&p2, "test_chat_peer2.conf");
+ setup_peer (&p3, "test_chat_peer3.conf");
+ }
else
setup_peer (&p1, "test_chat_data.conf");
@@ -622,24 +609,20 @@ run (void *cls,
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- "Alice",
- strlen("Alice")+1);
+ "Alice", strlen ("Alice") + 1);
bob_meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (bob_meta,
"<gnunet>",
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
- "text/plain",
- "Bob",
- strlen("Bob")+1);
+ "text/plain", "Bob", strlen ("Bob") + 1);
carol_meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_insert (carol_meta,
"<gnunet>",
EXTRACTOR_METATYPE_TITLE,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
- "Carol",
- strlen("Carol")+1);
+ "Carol", strlen ("Carol") + 1);
kill_task = GNUNET_SCHEDULER_add_delayed (KILL_TIMEOUT, &timeout_kill, NULL);
GNUNET_SCHEDULER_add_now (&join_alice_task, NULL);
}
@@ -648,7 +631,7 @@ run (void *cls,
int
main (int argc, char *argv[])
{
- char *const argvx[] = {
+ char *const argvx[] = {
"test-chat",
"-c",
"test_chat_data.conf",
@@ -661,30 +644,29 @@ main (int argc, char *argv[])
GNUNET_GETOPT_OPTION_END
};
- GNUNET_log_setup ("test_chat",
+ GNUNET_log_setup ("test_chat",
#if VERBOSE
"DEBUG",
#else
"WARNING",
#endif
NULL);
- if (strstr(argv[0], "p2p") != NULL)
- {
- is_p2p = GNUNET_YES;
- }
+ if (strstr (argv[0], "p2p") != NULL)
+ {
+ is_p2p = GNUNET_YES;
+ }
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
- argvx, "test-chat",
- "nohelp", options, &run, NULL);
+ argvx, "test-chat", "nohelp", options, &run, NULL);
stop_arm (&p1);
GNUNET_CONTAINER_meta_data_destroy (alice_meta);
GNUNET_CONTAINER_meta_data_destroy (bob_meta);
GNUNET_CONTAINER_meta_data_destroy (carol_meta);
if (is_p2p)
- {
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
- GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-3/");
- }
+ {
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-1/");
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-2/");
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat-peer-3/");
+ }
else
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-chat/");
return err;
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 7f7928fd3..c6fcc0b47 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -116,7 +116,7 @@ struct PeerRecord
* SendMessageRequest ID generator for this peer.
*/
uint16_t smr_id_gen;
-
+
};
@@ -143,7 +143,7 @@ struct ControlMessage
* Function to run after transmission failed/succeeded.
*/
GNUNET_CORE_ControlContinuation cont;
-
+
/**
* Closure for 'cont'.
*/
@@ -190,9 +190,9 @@ struct GNUNET_CORE_Handle
/**
* Function to call whenever we're notified about a peer changing status.
- */
+ */
GNUNET_CORE_PeerStatusEventHandler status_events;
-
+
/**
* Function to call whenever we receive an inbound message.
*/
@@ -371,8 +371,7 @@ struct GNUNET_CORE_TransmitHandle
*
* @param h our handle to the core service
*/
-static void
-reconnect (struct GNUNET_CORE_Handle *h);
+static void reconnect (struct GNUNET_CORE_Handle *h);
/**
@@ -382,15 +381,14 @@ reconnect (struct GNUNET_CORE_Handle *h);
* @param tc task context
*/
static void
-reconnect_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_CORE_Handle *h = cls;
h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to CORE service after delay\n");
+ "Connecting to CORE service after delay\n");
#endif
reconnect (h);
}
@@ -407,8 +405,7 @@ reconnect_task (void *cls,
*/
static int
disconnect_and_free_peer_entry (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
static struct GNUNET_BANDWIDTH_Value32NBO zero;
struct GNUNET_CORE_Handle *h = cls;
@@ -418,61 +415,47 @@ disconnect_and_free_peer_entry (void *cls,
void *pcic_cls;
if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pr->timeout_task);
- pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pr->timeout_task);
+ pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (pr->ntr_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pr->ntr_task);
- pr->ntr_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (h->ready_peer_head == pr) )
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
+ {
+ GNUNET_SCHEDULER_cancel (pr->ntr_task);
+ pr->ntr_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if ((pr->prev != NULL) || (pr->next != NULL) || (h->ready_peer_head == pr))
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
if (h->disconnects != NULL)
- h->disconnects (h->cls,
- &pr->peer);
+ h->disconnects (h->cls, &pr->peer);
/* all requests should have been cancelled, clean up anyway, just in case */
GNUNET_break (pr->queue_size == 0);
if (NULL != (pcic = pr->pcic))
- {
- GNUNET_break (0);
- pcic_cls = pr->pcic_cls;
- GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
- pcic (pcic_cls,
- &pr->peer,
- zero,
- 0,
- GNUNET_TIME_UNIT_FOREVER_REL,
- 0);
- }
+ {
+ GNUNET_break (0);
+ pcic_cls = pr->pcic_cls;
+ GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
+ pcic (pcic_cls, &pr->peer, zero, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0);
+ }
while (NULL != (th = pr->pending_head))
- {
- GNUNET_break (0);
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- th);
- pr->queue_size--;
- if (th->cm != NULL)
- th->cm->th = NULL;
- GNUNET_free (th);
- }
+ {
+ GNUNET_break (0);
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th);
+ pr->queue_size--;
+ if (th->cm != NULL)
+ th->cm->th = NULL;
+ GNUNET_free (th);
+ }
/* done with 'voluntary' cleanups, now on to normal freeing */
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (h->peers,
- key,
- pr));
+ GNUNET_CONTAINER_multihashmap_remove (h->peers, key, pr));
GNUNET_assert (pr->pending_head == NULL);
GNUNET_assert (pr->pending_tail == NULL);
GNUNET_assert (pr->ch = h);
GNUNET_assert (pr->queue_size == 0);
GNUNET_assert (pr->timeout_task == GNUNET_SCHEDULER_NO_TASK);
GNUNET_assert (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK);
- GNUNET_free (pr);
+ GNUNET_free (pr);
return GNUNET_YES;
}
@@ -491,41 +474,36 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
if (NULL != h->cth)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
- h->cth = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
+ h->cth = NULL;
+ }
if (h->client != NULL)
- {
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
+ h->client = NULL;
+ }
h->currently_down = GNUNET_YES;
GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
- &reconnect_task,
- h);
+ &reconnect_task, h);
while (NULL != (cm = h->control_pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- cm);
- if (cm->th != NULL)
- cm->th->cm = NULL;
- if (cm->cont != NULL)
- cm->cont (cm->cont_cls, GNUNET_NO);
- GNUNET_free (cm);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
+ h->control_pending_tail, cm);
+ if (cm->th != NULL)
+ cm->th->cm = NULL;
+ if (cm->cont != NULL)
+ cm->cont (cm->cont_cls, GNUNET_NO);
+ GNUNET_free (cm);
+ }
GNUNET_CONTAINER_multihashmap_iterate (h->peers,
- &disconnect_and_free_peer_entry,
- h);
- while (NULL != (pr = h->ready_peer_head))
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
+ &disconnect_and_free_peer_entry, h);
+ while (NULL != (pr = h->ready_peer_head))
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
GNUNET_assert (h->control_pending_head == NULL);
h->retry_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
- h->retry_backoff);
+ h->retry_backoff);
h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2);
}
@@ -538,8 +516,7 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
* @param ignore_currently_down transmit message even if not initialized?
*/
static void
-trigger_next_request (struct GNUNET_CORE_Handle *h,
- int ignore_currently_down);
+trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down);
/**
@@ -550,8 +527,7 @@ trigger_next_request (struct GNUNET_CORE_Handle *h,
* @param tc context, can be NULL (!)
*/
static void
-transmission_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -569,27 +545,27 @@ request_next_transmission (struct PeerRecord *pr)
struct GNUNET_CORE_TransmitHandle *th;
if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pr->timeout_task);
- pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (pr->timeout_task);
+ pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL == (th = pr->pending_head))
- {
- trigger_next_request (h, GNUNET_NO);
- return;
- }
+ {
+ trigger_next_request (h, GNUNET_NO);
+ return;
+ }
if (th->cm != NULL)
- return; /* already done */
+ return; /* already done */
GNUNET_assert (pr->prev == NULL);
GNUNET_assert (pr->next == NULL);
- pr->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (th->timeout),
- &transmission_timeout,
- pr);
- cm = GNUNET_malloc (sizeof (struct ControlMessage) +
- sizeof (struct SendMessageRequest));
+ pr->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
+ (th->timeout), &transmission_timeout, pr);
+ cm = GNUNET_malloc (sizeof (struct ControlMessage) +
+ sizeof (struct SendMessageRequest));
th->cm = cm;
cm->th = th;
- smr = (struct SendMessageRequest*) &cm[1];
+ smr = (struct SendMessageRequest *) &cm[1];
smr->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST);
smr->header.size = htons (sizeof (struct SendMessageRequest));
smr->priority = htonl (th->priority);
@@ -599,12 +575,11 @@ request_next_transmission (struct PeerRecord *pr)
smr->size = htons (th->msize);
smr->smr_id = htons (th->smr_id = pr->smr_id_gen++);
GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding SEND REQUEST for peer `%s' to message queue\n",
- GNUNET_i2s (&pr->peer));
+ "Adding SEND REQUEST for peer `%s' to message queue\n",
+ GNUNET_i2s (&pr->peer));
#endif
trigger_next_request (h, GNUNET_NO);
}
@@ -618,33 +593,26 @@ request_next_transmission (struct PeerRecord *pr)
* @param tc context, can be NULL (!)
*/
static void
-transmission_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+transmission_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerRecord *pr = cls;
struct GNUNET_CORE_Handle *h = pr->ch;
struct GNUNET_CORE_TransmitHandle *th;
-
+
pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
th = pr->pending_head;
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- th);
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th);
pr->queue_size--;
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (pr == h->ready_peer_head) )
- {
- /* the request that was 'approved' by core was
- canceled before it could be transmitted; remove
- us from the 'ready' list */
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
- }
+ if ((pr->prev != NULL) || (pr->next != NULL) || (pr == h->ready_peer_head))
+ {
+ /* the request that was 'approved' by core was
+ * canceled before it could be transmitted; remove
+ * us from the 'ready' list */
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Signalling timeout of request for transmission to CORE service\n");
+ "Signalling timeout of request for transmission to CORE service\n");
#endif
request_next_transmission (pr);
GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL));
@@ -656,9 +624,7 @@ transmission_timeout (void *cls,
* Transmit the next message to the core service.
*/
static size_t
-transmit_message (void *cls,
- size_t size,
- void *buf)
+transmit_message (void *cls, size_t size, void *buf)
{
struct GNUNET_CORE_Handle *h = cls;
struct ControlMessage *cm;
@@ -672,117 +638,108 @@ transmit_message (void *cls,
GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
h->cth = NULL;
if (buf == NULL)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed, initiating reconnect\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed, initiating reconnect\n");
#endif
- reconnect_later (h);
- return 0;
- }
+ reconnect_later (h);
+ return 0;
+ }
/* first check for control messages */
if (NULL != (cm = h->control_pending_head))
+ {
+ hdr = (const struct GNUNET_MessageHeader *) &cm[1];
+ msize = ntohs (hdr->size);
+ if (size < msize)
{
- hdr = (const struct GNUNET_MessageHeader*) &cm[1];
- msize = ntohs (hdr->size);
- if (size < msize)
- {
- trigger_next_request (h, GNUNET_NO);
- return 0;
- }
-#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting control message with %u bytes of type %u to core.\n",
- (unsigned int) msize,
- (unsigned int) ntohs (hdr->type));
-#endif
- memcpy (buf, hdr, msize);
- GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- cm);
- if (cm->th != NULL)
- cm->th->cm = NULL;
- if (NULL != cm->cont)
- cm->cont (cm->cont_cls, GNUNET_OK);
- GNUNET_free (cm);
trigger_next_request (h, GNUNET_NO);
- return msize;
+ return 0;
}
+#if DEBUG_CORE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting control message with %u bytes of type %u to core.\n",
+ (unsigned int) msize, (unsigned int) ntohs (hdr->type));
+#endif
+ memcpy (buf, hdr, msize);
+ GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
+ h->control_pending_tail, cm);
+ if (cm->th != NULL)
+ cm->th->cm = NULL;
+ if (NULL != cm->cont)
+ cm->cont (cm->cont_cls, GNUNET_OK);
+ GNUNET_free (cm);
+ trigger_next_request (h, GNUNET_NO);
+ return msize;
+ }
/* now check for 'ready' P2P messages */
if (NULL != (pr = h->ready_peer_head))
+ {
+ GNUNET_assert (pr->pending_head != NULL);
+ th = pr->pending_head;
+ if (size < th->msize + sizeof (struct SendMessage))
+ {
+ trigger_next_request (h, GNUNET_NO);
+ return 0;
+ }
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th);
+ pr->queue_size--;
+ if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_assert (pr->pending_head != NULL);
- th = pr->pending_head;
- if (size < th->msize + sizeof (struct SendMessage))
- {
- trigger_next_request (h, GNUNET_NO);
- return 0;
- }
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- th);
- pr->queue_size--;
- if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (pr->timeout_task);
- pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ GNUNET_SCHEDULER_cancel (pr->timeout_task);
+ pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting SEND request to `%s' with %u bytes.\n",
- GNUNET_i2s (&pr->peer),
- (unsigned int) th->msize);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting SEND request to `%s' with %u bytes.\n",
+ GNUNET_i2s (&pr->peer), (unsigned int) th->msize);
#endif
- sm = (struct SendMessage *) buf;
- sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND);
- sm->priority = htonl (th->priority);
- sm->deadline = GNUNET_TIME_absolute_hton (th->timeout);
- sm->peer = pr->peer;
- sm->cork = htonl ((uint32_t) th->cork);
- sm->reserved = htonl (0);
- ret = th->get_message (th->get_message_cls,
- size - sizeof (struct SendMessage),
- &sm[1]);
-
+ sm = (struct SendMessage *) buf;
+ sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND);
+ sm->priority = htonl (th->priority);
+ sm->deadline = GNUNET_TIME_absolute_hton (th->timeout);
+ sm->peer = pr->peer;
+ sm->cork = htonl ((uint32_t) th->cork);
+ sm->reserved = htonl (0);
+ ret = th->get_message (th->get_message_cls,
+ size - sizeof (struct SendMessage), &sm[1]);
+
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting SEND request to `%s' yielded %u bytes.\n",
- GNUNET_i2s (&pr->peer),
- ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting SEND request to `%s' yielded %u bytes.\n",
+ GNUNET_i2s (&pr->peer), ret);
#endif
- GNUNET_free (th);
- if (0 == ret)
- {
+ GNUNET_free (th);
+ if (0 == ret)
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Size of clients message to peer %s is 0!\n",
- GNUNET_i2s(&pr->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Size of clients message to peer %s is 0!\n",
+ GNUNET_i2s (&pr->peer));
#endif
- /* client decided to send nothing! */
- request_next_transmission (pr);
- return 0;
- }
+ /* client decided to send nothing! */
+ request_next_transmission (pr);
+ return 0;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Produced SEND message to core with %u bytes payload\n",
- (unsigned int) ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Produced SEND message to core with %u bytes payload\n",
+ (unsigned int) ret);
#endif
- GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader));
- if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- request_next_transmission (pr);
- return 0;
- }
- ret += sizeof (struct SendMessage);
- sm->header.size = htons (ret);
- GNUNET_assert (ret <= size);
+ GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader));
+ if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break (0);
request_next_transmission (pr);
- return ret;
+ return 0;
}
+ ret += sizeof (struct SendMessage);
+ sm->header.size = htons (ret);
+ GNUNET_assert (ret <= size);
+ request_next_transmission (pr);
+ return ret;
+ }
return 0;
}
@@ -795,45 +752,46 @@ transmit_message (void *cls,
* @param ignore_currently_down transmit message even if not initialized?
*/
static void
-trigger_next_request (struct GNUNET_CORE_Handle *h,
- int ignore_currently_down)
+trigger_next_request (struct GNUNET_CORE_Handle *h, int ignore_currently_down)
{
uint16_t msize;
- if ( (GNUNET_YES == h->currently_down) &&
- (ignore_currently_down == GNUNET_NO) )
- {
+ if ((GNUNET_YES == h->currently_down) && (ignore_currently_down == GNUNET_NO))
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core connection down, not processing queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core connection down, not processing queue\n");
#endif
- return;
- }
+ return;
+ }
if (NULL != h->cth)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Request pending, not processing queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Request pending, not processing queue\n");
#endif
- return;
- }
+ return;
+ }
if (h->control_pending_head != NULL)
- msize = ntohs (((struct GNUNET_MessageHeader*) &h->control_pending_head[1])->size);
- else if (h->ready_peer_head != NULL)
- msize = h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage);
+ msize =
+ ntohs (((struct GNUNET_MessageHeader *) &h->
+ control_pending_head[1])->size);
+ else if (h->ready_peer_head != NULL)
+ msize =
+ h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage);
else
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Request queue empty, not processing queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Request queue empty, not processing queue\n");
#endif
- return; /* no pending message */
- }
+ return; /* no pending message */
+ }
h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client,
- msize,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO,
- &transmit_message, h);
+ msize,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO,
+ &transmit_message, h);
}
@@ -844,8 +802,7 @@ trigger_next_request (struct GNUNET_CORE_Handle *h,
* @param msg the message received from the core service
*/
static void
-main_notify_handler (void *cls,
- const struct GNUNET_MessageHeader *msg)
+main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CORE_Handle *h = cls;
const struct InitReplyMessage *m;
@@ -868,13 +825,13 @@ main_notify_handler (void *cls,
uint32_t ats_count;
if (msg == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Client was disconnected from core service, trying to reconnect.\n"));
- reconnect_later (h);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Client was disconnected from core service, trying to reconnect.\n"));
+ reconnect_later (h);
+ return;
+ }
msize = ntohs (msg->size);
#if DEBUG_CORE > 2
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -882,425 +839,401 @@ main_notify_handler (void *cls,
ntohs (msg->type), msize);
#endif
switch (ntohs (msg->type))
+ {
+ case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY:
+ if (ntohs (msg->size) != sizeof (struct InitReplyMessage))
{
- case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY:
- if (ntohs (msg->size) != sizeof (struct InitReplyMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- m = (const struct InitReplyMessage *) msg;
- GNUNET_break (0 == ntohl (m->reserved));
- /* start our message processing loop */
- if (GNUNET_YES == h->currently_down)
- {
- h->currently_down = GNUNET_NO;
- trigger_next_request (h, GNUNET_NO);
- }
- h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
- GNUNET_CRYPTO_hash (&m->publicKey,
- sizeof (struct
- GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &h->me.hashPubKey);
- if (NULL != (init = h->init))
- {
- /* mark so we don't call init on reconnect */
- h->init = NULL;
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ m = (const struct InitReplyMessage *) msg;
+ GNUNET_break (0 == ntohl (m->reserved));
+ /* start our message processing loop */
+ if (GNUNET_YES == h->currently_down)
+ {
+ h->currently_down = GNUNET_NO;
+ trigger_next_request (h, GNUNET_NO);
+ }
+ h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
+ GNUNET_CRYPTO_hash (&m->publicKey,
+ sizeof (struct
+ GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &h->me.hashPubKey);
+ if (NULL != (init = h->init))
+ {
+ /* mark so we don't call init on reconnect */
+ h->init = NULL;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connected to core service of peer `%s'.\n",
- GNUNET_i2s (&h->me));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connected to core service of peer `%s'.\n",
+ GNUNET_i2s (&h->me));
#endif
- init (h->cls, h, &h->me, &m->publicKey);
- }
- else
- {
+ init (h->cls, h, &h->me, &m->publicKey);
+ }
+ else
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Successfully reconnected to core service.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully reconnected to core service.\n");
#endif
- }
- /* fake 'connect to self' */
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &h->me.hashPubKey);
- GNUNET_assert (pr == NULL);
- pr = GNUNET_malloc (sizeof (struct PeerRecord));
- pr->peer = h->me;
- pr->ch = h;
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_put (h->peers,
- &h->me.hashPubKey,
- pr,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
- if (NULL != h->connects)
- h->connects (h->cls,
- &h->me,
- NULL);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
- if (msize < sizeof (struct ConnectNotifyMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- cnm = (const struct ConnectNotifyMessage *) msg;
- ats_count = ntohl (cnm->ats_count);
- if ( (msize != sizeof (struct ConnectNotifyMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&cnm->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
+ }
+ /* fake 'connect to self' */
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &h->me.hashPubKey);
+ GNUNET_assert (pr == NULL);
+ pr = GNUNET_malloc (sizeof (struct PeerRecord));
+ pr->peer = h->me;
+ pr->ch = h;
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_put (h->peers,
+ &h->me.hashPubKey,
+ pr,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ if (NULL != h->connects)
+ h->connects (h->cls, &h->me, NULL);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
+ if (msize < sizeof (struct ConnectNotifyMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ cnm = (const struct ConnectNotifyMessage *) msg;
+ ats_count = ntohl (cnm->ats_count);
+ if ((msize !=
+ sizeof (struct ConnectNotifyMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&cnm->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about connection from `%s'.\n",
- GNUNET_i2s (&cnm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about connection from `%s'.\n",
+ GNUNET_i2s (&cnm->peer));
#endif
- if (0 == memcmp (&h->me,
- &cnm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* connect to self!? */
- GNUNET_break (0);
- return;
- }
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &cnm->peer.hashPubKey);
- if (pr != NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- pr = GNUNET_malloc (sizeof (struct PeerRecord));
- pr->peer = cnm->peer;
- pr->ch = h;
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_put (h->peers,
- &cnm->peer.hashPubKey,
- pr,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
- if (NULL != h->connects)
- h->connects (h->cls,
- &cnm->peer,
- &cnm->ats);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
- if (msize != sizeof (struct DisconnectNotifyMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- dnm = (const struct DisconnectNotifyMessage *) msg;
- if (0 == memcmp (&h->me,
- &dnm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* connection to self!? */
- GNUNET_break (0);
- return;
- }
- GNUNET_break (0 == ntohl (dnm->reserved));
+ if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* connect to self!? */
+ GNUNET_break (0);
+ return;
+ }
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &cnm->peer.hashPubKey);
+ if (pr != NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ pr = GNUNET_malloc (sizeof (struct PeerRecord));
+ pr->peer = cnm->peer;
+ pr->ch = h;
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_put (h->peers,
+ &cnm->peer.hashPubKey,
+ pr,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ if (NULL != h->connects)
+ h->connects (h->cls, &cnm->peer, &cnm->ats);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
+ if (msize != sizeof (struct DisconnectNotifyMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ dnm = (const struct DisconnectNotifyMessage *) msg;
+ if (0 == memcmp (&h->me, &dnm->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* connection to self!? */
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_break (0 == ntohl (dnm->reserved));
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about disconnect from `%s'.\n",
- GNUNET_i2s (&dnm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about disconnect from `%s'.\n",
+ GNUNET_i2s (&dnm->peer));
#endif
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &dnm->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- trigger = ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (h->ready_peer_head == pr) );
- disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr);
- if (trigger)
- trigger_next_request (h, GNUNET_NO);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE:
- if (NULL == h->status_events)
- {
- GNUNET_break (0);
- return;
- }
- if (msize < sizeof (struct PeerStatusNotifyMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- psnm = (const struct PeerStatusNotifyMessage *) msg;
- if (0 == memcmp (&h->me,
- &psnm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* self-change!? */
- GNUNET_break (0);
- return;
- }
- ats_count = ntohl (psnm->ats_count);
- if ( (msize != sizeof (struct PeerStatusNotifyMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&psnm->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &dnm->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ trigger = ((pr->prev != NULL) ||
+ (pr->next != NULL) || (h->ready_peer_head == pr));
+ disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr);
+ if (trigger)
+ trigger_next_request (h, GNUNET_NO);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE:
+ if (NULL == h->status_events)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (msize < sizeof (struct PeerStatusNotifyMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ psnm = (const struct PeerStatusNotifyMessage *) msg;
+ if (0 == memcmp (&h->me, &psnm->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
+ ats_count = ntohl (psnm->ats_count);
+ if ((msize !=
+ sizeof (struct PeerStatusNotifyMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&psnm->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
#if DEBUG_CORE > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about status change by `%s'.\n",
- GNUNET_i2s (&psnm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about status change by `%s'.\n",
+ GNUNET_i2s (&psnm->peer));
#endif
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &psnm->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- h->status_events (h->cls,
- &psnm->peer,
- psnm->bandwidth_in,
- psnm->bandwidth_out,
- GNUNET_TIME_absolute_ntoh (psnm->timeout),
- &psnm->ats);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND:
- if (msize < sizeof (struct NotifyTrafficMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- ntm = (const struct NotifyTrafficMessage *) msg;
-
- ats_count = ntohl (ntm->ats_count);
- if ( (msize < sizeof (struct NotifyTrafficMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)
- + sizeof (struct GNUNET_MessageHeader)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count+1];
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &psnm->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ h->status_events (h->cls,
+ &psnm->peer,
+ psnm->bandwidth_in,
+ psnm->bandwidth_out,
+ GNUNET_TIME_absolute_ntoh (psnm->timeout), &psnm->ats);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND:
+ if (msize < sizeof (struct NotifyTrafficMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ ntm = (const struct NotifyTrafficMessage *) msg;
+
+ ats_count = ntohl (ntm->ats_count);
+ if ((msize <
+ sizeof (struct NotifyTrafficMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
+ sizeof (struct GNUNET_MessageHeader)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&ntm->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1];
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u and size %u from peer `%4s'\n",
- ntohs (em->type),
- ntohs (em->size),
- GNUNET_i2s (&ntm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message of type %u and size %u from peer `%4s'\n",
+ ntohs (em->type), ntohs (em->size), GNUNET_i2s (&ntm->peer));
#endif
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &ntm->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- if ((GNUNET_NO == h->inbound_hdr_only) &&
- (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) +
- + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- et = ntohs (em->type);
- for (hpos = 0; hpos < h->hcnt; hpos++)
- {
- mh = &h->handlers[hpos];
- if (mh->type != et)
- continue;
- if ((mh->expected_size != ntohs (em->size)) &&
- (mh->expected_size != 0))
- {
- GNUNET_break (0);
- continue;
- }
- if (GNUNET_OK !=
- h->handlers[hpos].callback (h->cls, &ntm->peer, em,
- &ntm->ats))
- {
- /* error in processing, do not process other messages! */
- break;
- }
- }
- if (NULL != h->inbound_notify)
- h->inbound_notify (h->cls, &ntm->peer, em,
- &ntm->ats);
- break;
- case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
- if (msize < sizeof (struct NotifyTrafficMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- ntm = (const struct NotifyTrafficMessage *) msg;
- if (0 == memcmp (&h->me,
- &ntm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* self-change!? */
- GNUNET_break (0);
- return;
- }
- ats_count = ntohl (ntm->ats_count);
- if ( (msize < sizeof (struct NotifyTrafficMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)
- + sizeof (struct GNUNET_MessageHeader)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count+1];
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &ntm->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ if ((GNUNET_NO == h->inbound_hdr_only) &&
+ (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage) +
+ +ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ et = ntohs (em->type);
+ for (hpos = 0; hpos < h->hcnt; hpos++)
+ {
+ mh = &h->handlers[hpos];
+ if (mh->type != et)
+ continue;
+ if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0))
+ {
+ GNUNET_break (0);
+ continue;
+ }
+ if (GNUNET_OK !=
+ h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats))
+ {
+ /* error in processing, do not process other messages! */
+ break;
+ }
+ }
+ if (NULL != h->inbound_notify)
+ h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
+ if (msize < sizeof (struct NotifyTrafficMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ ntm = (const struct NotifyTrafficMessage *) msg;
+ if (0 == memcmp (&h->me, &ntm->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
+ ats_count = ntohl (ntm->ats_count);
+ if ((msize <
+ sizeof (struct NotifyTrafficMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
+ sizeof (struct GNUNET_MessageHeader)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&ntm->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1];
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &ntm->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about transmission to `%s'.\n",
- GNUNET_i2s (&ntm->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about transmission to `%s'.\n",
+ GNUNET_i2s (&ntm->peer));
#endif
- if ((GNUNET_NO == h->outbound_hdr_only) &&
- (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)
- + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) )
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- if (NULL == h->outbound_notify)
- {
- GNUNET_break (0);
- break;
- }
- h->outbound_notify (h->cls, &ntm->peer, em,
- &ntm->ats);
+ if ((GNUNET_NO == h->outbound_hdr_only) &&
+ (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)
+ + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ if (NULL == h->outbound_notify)
+ {
+ GNUNET_break (0);
break;
- case GNUNET_MESSAGE_TYPE_CORE_SEND_READY:
- if (msize != sizeof (struct SendMessageReady))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- smr = (const struct SendMessageReady *) msg;
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &smr->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
+ }
+ h->outbound_notify (h->cls, &ntm->peer, em, &ntm->ats);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_SEND_READY:
+ if (msize != sizeof (struct SendMessageReady))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ smr = (const struct SendMessageReady *) msg;
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &smr->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about transmission readiness to `%s'.\n",
- GNUNET_i2s (&smr->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about transmission readiness to `%s'.\n",
+ GNUNET_i2s (&smr->peer));
#endif
- if (pr->pending_head == NULL)
- {
- /* request must have been cancelled between the original request
- and the response from core, ignore core's readiness */
- break;
- }
-
- th = pr->pending_head;
- if (ntohs (smr->smr_id) != th->smr_id)
- {
- /* READY message is for expired or cancelled message,
- ignore! (we should have already sent another request) */
- break;
- }
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (h->ready_peer_head == pr) )
- {
- /* we should not already be on the ready list... */
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- GNUNET_CONTAINER_DLL_insert (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
- trigger_next_request (h, GNUNET_NO);
+ if (pr->pending_head == NULL)
+ {
+ /* request must have been cancelled between the original request
+ * and the response from core, ignore core's readiness */
+ break;
+ }
+
+ th = pr->pending_head;
+ if (ntohs (smr->smr_id) != th->smr_id)
+ {
+ /* READY message is for expired or cancelled message,
+ * ignore! (we should have already sent another request) */
break;
- case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO:
- if (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage))
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- cim = (const struct ConfigurationInfoMessage*) msg;
- if (0 == memcmp (&h->me,
- &cim->peer,
- sizeof (struct GNUNET_PeerIdentity)))
- {
- /* self-change!? */
- GNUNET_break (0);
- return;
- }
+ }
+ if ((pr->prev != NULL) || (pr->next != NULL) || (h->ready_peer_head == pr))
+ {
+ /* we should not already be on the ready list... */
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_insert (h->ready_peer_head, h->ready_peer_tail, pr);
+ trigger_next_request (h, GNUNET_NO);
+ break;
+ case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO:
+ if (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage))
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ cim = (const struct ConfigurationInfoMessage *) msg;
+ if (0 == memcmp (&h->me, &cim->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received notification about configuration update for `%s' with RIM %u.\n",
- GNUNET_i2s (&cim->peer),
- (unsigned int) ntohl (cim->rim_id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received notification about configuration update for `%s' with RIM %u.\n",
+ GNUNET_i2s (&cim->peer), (unsigned int) ntohl (cim->rim_id));
#endif
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &cim->peer.hashPubKey);
- if (pr == NULL)
- {
- GNUNET_break (0);
- reconnect_later (h);
- return;
- }
- if (pr->rim_id != ntohl (cim->rim_id))
- {
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &cim->peer.hashPubKey);
+ if (pr == NULL)
+ {
+ GNUNET_break (0);
+ reconnect_later (h);
+ return;
+ }
+ if (pr->rim_id != ntohl (cim->rim_id))
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reservation ID mismatch in notification...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Reservation ID mismatch in notification...\n");
#endif
- break;
- }
- pcic = pr->pcic;
- pr->pcic = NULL;
- GNUNET_free_non_null (pr->pcic_ptr);
- pr->pcic_ptr = NULL;
- if (pcic != NULL)
- pcic (pr->pcic_cls,
- &pr->peer,
- cim->bw_out,
- ntohl (cim->reserved_amount),
- GNUNET_TIME_relative_ntoh (cim->reserve_delay),
- GNUNET_ntohll (cim->preference));
break;
- default:
- reconnect_later (h);
- return;
}
+ pcic = pr->pcic;
+ pr->pcic = NULL;
+ GNUNET_free_non_null (pr->pcic_ptr);
+ pr->pcic_ptr = NULL;
+ if (pcic != NULL)
+ pcic (pr->pcic_cls,
+ &pr->peer,
+ cim->bw_out,
+ ntohl (cim->reserved_amount),
+ GNUNET_TIME_relative_ntoh (cim->reserve_delay),
+ GNUNET_ntohll (cim->preference));
+ break;
+ default:
+ reconnect_later (h);
+ return;
+ }
GNUNET_CLIENT_receive (h->client,
- &main_notify_handler, h,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -1312,27 +1245,24 @@ main_notify_handler (void *cls,
* @param success were we successful
*/
static void
-init_done_task (void *cls,
- int success)
+init_done_task (void *cls, int success)
{
struct GNUNET_CORE_Handle *h = cls;
if (success == GNUNET_SYSERR)
- return; /* shutdown */
+ return; /* shutdown */
if (success == GNUNET_NO)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to exchange INIT with core, retrying\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to exchange INIT with core, retrying\n");
#endif
- if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK)
- reconnect_later (h);
- return;
- }
+ if (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK)
+ reconnect_later (h);
+ return;
+ }
GNUNET_CLIENT_receive (h->client,
- &main_notify_handler,
- h,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -1353,49 +1283,46 @@ reconnect (struct GNUNET_CORE_Handle *h)
unsigned int hpos;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reconnecting to CORE service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to CORE service\n");
#endif
GNUNET_assert (h->client == NULL);
GNUNET_assert (h->currently_down == GNUNET_YES);
h->client = GNUNET_CLIENT_connect ("core", h->cfg);
if (h->client == NULL)
- {
- reconnect_later (h);
- return;
- }
+ {
+ reconnect_later (h);
+ return;
+ }
msize = h->hcnt * sizeof (uint16_t) + sizeof (struct InitMessage);
- cm = GNUNET_malloc (sizeof (struct ControlMessage) +
- msize);
+ cm = GNUNET_malloc (sizeof (struct ControlMessage) + msize);
cm->cont = &init_done_task;
cm->cont_cls = h;
- init = (struct InitMessage*) &cm[1];
+ init = (struct InitMessage *) &cm[1];
init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT);
init->header.size = htons (msize);
opt = GNUNET_CORE_OPTION_SEND_CONNECT | GNUNET_CORE_OPTION_SEND_DISCONNECT;
if (h->status_events != NULL)
opt |= GNUNET_CORE_OPTION_SEND_STATUS_CHANGE;
if (h->inbound_notify != NULL)
- {
- if (h->inbound_hdr_only)
- opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND;
- else
- opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND;
- }
+ {
+ if (h->inbound_hdr_only)
+ opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND;
+ else
+ opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND;
+ }
if (h->outbound_notify != NULL)
- {
- if (h->outbound_hdr_only)
- opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND;
- else
- opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND;
- }
+ {
+ if (h->outbound_hdr_only)
+ opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND;
+ else
+ opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND;
+ }
init->options = htonl (opt);
- ts = (uint16_t *) &init[1];
+ ts = (uint16_t *) & init[1];
for (hpos = 0; hpos < h->hcnt; hpos++)
ts[hpos] = htons (h->handlers[hpos].type);
GNUNET_CONTAINER_DLL_insert (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
trigger_next_request (h, GNUNET_YES);
}
@@ -1427,12 +1354,12 @@ reconnect (struct GNUNET_CORE_Handle *h)
*/
struct GNUNET_CORE_Handle *
GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int queue_size,
+ unsigned int queue_size,
void *cls,
GNUNET_CORE_StartupCallback init,
GNUNET_CORE_ConnectEventHandler connects,
GNUNET_CORE_DisconnectEventHandler disconnects,
- GNUNET_CORE_PeerStatusEventHandler status_events,
+ GNUNET_CORE_PeerStatusEventHandler status_events,
GNUNET_CORE_MessageCallback inbound_notify,
int inbound_hdr_only,
GNUNET_CORE_MessageCallback outbound_notify,
@@ -1464,8 +1391,7 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
(GNUNET_SERVER_MAX_MESSAGE_SIZE -
sizeof (struct InitMessage)) / sizeof (uint16_t));
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to CORE service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n");
#endif
reconnect (h);
return h;
@@ -1483,40 +1409,38 @@ void
GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
{
struct ControlMessage *cm;
-
+
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from CORE service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n");
#endif
if (handle->cth != NULL)
- {
- GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth);
- handle->cth = NULL;
- }
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth);
+ handle->cth = NULL;
+ }
while (NULL != (cm = handle->control_pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (handle->control_pending_head,
- handle->control_pending_tail,
- cm);
- if (cm->th != NULL)
- cm->th->cm = NULL;
- if (cm->cont != NULL)
- cm->cont (cm->cont_cls, GNUNET_SYSERR);
- GNUNET_free (cm);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (handle->control_pending_head,
+ handle->control_pending_tail, cm);
+ if (cm->th != NULL)
+ cm->th->cm = NULL;
+ if (cm->cont != NULL)
+ cm->cont (cm->cont_cls, GNUNET_SYSERR);
+ GNUNET_free (cm);
+ }
if (handle->client != NULL)
- {
- GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
- handle->client = NULL;
- }
+ {
+ GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
+ handle->client = NULL;
+ }
GNUNET_CONTAINER_multihashmap_iterate (handle->peers,
- &disconnect_and_free_peer_entry,
- handle);
+ &disconnect_and_free_peer_entry,
+ handle);
if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (handle->reconnect_task);
- handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (handle->reconnect_task);
+ handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_CONTAINER_multihashmap_destroy (handle->peers);
handle->peers = NULL;
GNUNET_break (handle->ready_peer_head == NULL);
@@ -1532,7 +1456,7 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
*/
static void
run_request_next_transmission (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PeerRecord *pr = cls;
@@ -1562,7 +1486,7 @@ run_request_next_transmission (void *cls,
*/
struct GNUNET_CORE_TransmitHandle *
GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
- int cork,
+ int cork,
uint32_t priority,
struct GNUNET_TIME_Relative maxdelay,
const struct GNUNET_PeerIdentity *target,
@@ -1576,22 +1500,21 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
struct GNUNET_CORE_TransmitHandle *prev;
struct GNUNET_CORE_TransmitHandle *minp;
- pr = GNUNET_CONTAINER_multihashmap_get (handle->peers,
- &target->hashPubKey);
+ pr = GNUNET_CONTAINER_multihashmap_get (handle->peers, &target->hashPubKey);
if (NULL == pr)
- {
- /* attempt to send to peer that is not connected */
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Attempting to send to peer `%s' from peer `%s', but not connected!\n",
- GNUNET_i2s(target), GNUNET_h2s(&handle->me.hashPubKey));
- GNUNET_break (0);
- return NULL;
- }
+ {
+ /* attempt to send to peer that is not connected */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Attempting to send to peer `%s' from peer `%s', but not connected!\n",
+ GNUNET_i2s (target), GNUNET_h2s (&handle->me.hashPubKey));
+ GNUNET_break (0);
+ return NULL;
+ }
GNUNET_assert (notify_size + sizeof (struct SendMessage) <
GNUNET_SERVER_MAX_MESSAGE_SIZE);
th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle));
th->peer = pr;
- GNUNET_assert(NULL != notify);
+ GNUNET_assert (NULL != notify);
th->get_message = notify;
th->get_message_cls = notify_cls;
th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
@@ -1600,81 +1523,72 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
th->cork = cork;
/* bound queue size */
if (pr->queue_size == handle->queue_size)
+ {
+ /* find lowest-priority entry, but skip the head of the list */
+ minp = pr->pending_head->next;
+ prev = minp;
+ while (prev != NULL)
+ {
+ if (prev->priority < minp->priority)
+ minp = prev;
+ prev = prev->next;
+ }
+ if (minp == NULL)
{
- /* find lowest-priority entry, but skip the head of the list */
- minp = pr->pending_head->next;
- prev = minp;
- while (prev != NULL)
- {
- if (prev->priority < minp->priority)
- minp = prev;
- prev = prev->next;
- }
- if (minp == NULL)
- {
- GNUNET_break (handle->queue_size != 0);
- GNUNET_break (pr->queue_size == 1);
- GNUNET_free(th);
+ GNUNET_break (handle->queue_size != 0);
+ GNUNET_break (pr->queue_size == 1);
+ GNUNET_free (th);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping transmission request: cannot drop queue head and limit is one\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping transmission request: cannot drop queue head and limit is one\n");
#endif
- return NULL;
- }
- if (priority <= minp->priority)
- {
+ return NULL;
+ }
+ if (priority <= minp->priority)
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping transmission request: priority too low\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping transmission request: priority too low\n");
#endif
- GNUNET_free(th);
- return NULL; /* priority too low */
- }
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- minp);
- pr->queue_size--;
- GNUNET_assert (0 ==
- minp->get_message (minp->get_message_cls,
- 0, NULL));
- GNUNET_free (minp);
+ GNUNET_free (th);
+ return NULL; /* priority too low */
}
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, minp);
+ pr->queue_size--;
+ GNUNET_assert (0 == minp->get_message (minp->get_message_cls, 0, NULL));
+ GNUNET_free (minp);
+ }
/* Order entries by deadline, but SKIP 'HEAD' if
- we're in the 'ready_peer_*' DLL */
+ * we're in the 'ready_peer_*' DLL */
pos = pr->pending_head;
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (pr == handle->ready_peer_head) )
- {
- GNUNET_assert (pos != NULL);
- pos = pos->next; /* skip head */
- }
+ if ((pr->prev != NULL) ||
+ (pr->next != NULL) || (pr == handle->ready_peer_head))
+ {
+ GNUNET_assert (pos != NULL);
+ pos = pos->next; /* skip head */
+ }
/* insertion sort */
prev = pos;
- while ( (pos != NULL) &&
- (pos->timeout.abs_value < th->timeout.abs_value) )
- {
- prev = pos;
- pos = pos->next;
- }
+ while ((pos != NULL) && (pos->timeout.abs_value < th->timeout.abs_value))
+ {
+ prev = pos;
+ pos = pos->next;
+ }
GNUNET_CONTAINER_DLL_insert_after (pr->pending_head,
- pr->pending_tail,
- prev,
- th);
+ pr->pending_tail, prev, th);
pr->queue_size++;
/* was the request queue previously empty? */
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission request added to queue\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission request added to queue\n");
#endif
- if ( (pr->pending_head == th) &&
- (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) &&
- (pr->next == NULL) &&
- (pr->prev == NULL) &&
- (handle->ready_peer_head != pr) )
- pr->ntr_task = GNUNET_SCHEDULER_add_now (&run_request_next_transmission, pr);
+ if ((pr->pending_head == th) &&
+ (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK) &&
+ (pr->next == NULL) &&
+ (pr->prev == NULL) && (handle->ready_peer_head != pr))
+ pr->ntr_task =
+ GNUNET_SCHEDULER_add_now (&run_request_next_transmission, pr);
return th;
}
@@ -1685,42 +1599,34 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
* @param th handle that was returned by "notify_transmit_ready".
*/
void
-GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle
- *th)
+GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle *th)
{
struct PeerRecord *pr = th->peer;
struct GNUNET_CORE_Handle *h = pr->ch;
int was_head;
was_head = (pr->pending_head == th);
- GNUNET_CONTAINER_DLL_remove (pr->pending_head,
- pr->pending_tail,
- th);
+ GNUNET_CONTAINER_DLL_remove (pr->pending_head, pr->pending_tail, th);
pr->queue_size--;
if (th->cm != NULL)
- {
- /* we're currently in the control queue, remove */
- GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- th->cm);
- GNUNET_free (th->cm);
- }
+ {
+ /* we're currently in the control queue, remove */
+ GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
+ h->control_pending_tail, th->cm);
+ GNUNET_free (th->cm);
+ }
GNUNET_free (th);
if (was_head)
+ {
+ if ((pr->prev != NULL) || (pr->next != NULL) || (pr == h->ready_peer_head))
{
- if ( (pr->prev != NULL) ||
- (pr->next != NULL) ||
- (pr == h->ready_peer_head) )
- {
- /* the request that was 'approved' by core was
- canceled before it could be transmitted; remove
- us from the 'ready' list */
- GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
- h->ready_peer_tail,
- pr);
- }
- request_next_transmission (pr);
+ /* the request that was 'approved' by core was
+ * canceled before it could be transmitted; remove
+ * us from the 'ready' list */
+ GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
}
+ request_next_transmission (pr);
+ }
}
@@ -1766,13 +1672,12 @@ struct GNUNET_CORE_PeerRequestHandle
* @param success was the request transmitted?
*/
static void
-peer_request_connect_cont (void *cls,
- int success)
+peer_request_connect_cont (void *cls, int success)
{
struct GNUNET_CORE_PeerRequestHandle *ret = cls;
-
+
if (ret->cont != NULL)
- ret->cont (ret->cont_cls, success);
+ ret->cont (ret->cont_cls, success);
GNUNET_free (ret);
}
@@ -1798,34 +1703,31 @@ peer_request_connect_cont (void *cls,
*/
struct GNUNET_CORE_PeerRequestHandle *
GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
- const struct GNUNET_PeerIdentity * peer,
- GNUNET_CORE_ControlContinuation cont,
- void *cont_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ GNUNET_CORE_ControlContinuation cont,
+ void *cont_cls)
{
struct GNUNET_CORE_PeerRequestHandle *ret;
struct ControlMessage *cm;
struct ConnectMessage *msg;
- if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers,
- &peer->hashPubKey))
- {
+ if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey))
+ {
#if DEBUG_CORE
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Peers are already connected!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers are already connected!\n");
#endif
- return NULL;
- }
-
- cm = GNUNET_malloc (sizeof (struct ControlMessage) +
- sizeof (struct ConnectMessage));
- msg = (struct ConnectMessage*) &cm[1];
+ return NULL;
+ }
+
+ cm = GNUNET_malloc (sizeof (struct ControlMessage) +
+ sizeof (struct ConnectMessage));
+ msg = (struct ConnectMessage *) &cm[1];
msg->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT);
msg->header.size = htons (sizeof (struct ConnectMessage));
msg->reserved = htonl (0);
msg->peer = *peer;
GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle));
ret->h = h;
ret->cm = cm;
@@ -1834,8 +1736,7 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
cm->cont = &peer_request_connect_cont;
cm->cont_cls = ret;
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing REQUEST_CONNECT request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing REQUEST_CONNECT request\n");
#endif
trigger_next_request (h, GNUNET_NO);
return ret;
@@ -1849,18 +1750,18 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
* @param req request handle that was returned for the original request
*/
void
-GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req)
+GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle
+ *req)
{
struct GNUNET_CORE_Handle *h = req->h;
struct ControlMessage *cm = req->cm;
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "A CHANGE PREFERENCE request was cancelled!\n");
+ "A CHANGE PREFERENCE request was cancelled!\n");
#endif
GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
GNUNET_free (cm);
GNUNET_free (req);
}
@@ -1869,9 +1770,9 @@ GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *r
/* ****************** GNUNET_CORE_peer_change_preference ******************** */
-struct GNUNET_CORE_InformationRequestContext
+struct GNUNET_CORE_InformationRequestContext
{
-
+
/**
* Our connection to the service.
*/
@@ -1879,7 +1780,7 @@ struct GNUNET_CORE_InformationRequestContext
/**
* Link to control message, NULL if CM was sent.
- */
+ */
struct ControlMessage *cm;
/**
@@ -1896,8 +1797,7 @@ struct GNUNET_CORE_InformationRequestContext
* @param success were we successful?
*/
static void
-change_preference_send_continuation (void *cls,
- int success)
+change_preference_send_continuation (void *cls, int success)
{
struct GNUNET_CORE_InformationRequestContext *irc = cls;
@@ -1931,61 +1831,58 @@ change_preference_send_continuation (void *cls,
*/
struct GNUNET_CORE_InformationRequestContext *
GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Relative timeout,
- struct GNUNET_BANDWIDTH_Value32NBO bw_out,
- int32_t amount,
- uint64_t preference,
- GNUNET_CORE_PeerConfigurationInfoCallback info,
- void *info_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_TIME_Relative timeout,
+ struct GNUNET_BANDWIDTH_Value32NBO bw_out,
+ int32_t amount,
+ uint64_t preference,
+ GNUNET_CORE_PeerConfigurationInfoCallback
+ info, void *info_cls)
{
struct GNUNET_CORE_InformationRequestContext *irc;
struct PeerRecord *pr;
struct RequestInfoMessage *rim;
struct ControlMessage *cm;
- pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
- &peer->hashPubKey);
+ pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey);
if (NULL == pr)
- {
- /* attempt to change preference on peer that is not connected */
- GNUNET_assert (0);
- return NULL;
- }
+ {
+ /* attempt to change preference on peer that is not connected */
+ GNUNET_assert (0);
+ return NULL;
+ }
if (pr->pcic != NULL)
- {
- /* second change before first one is done */
- GNUNET_break (0);
- return NULL;
- }
+ {
+ /* second change before first one is done */
+ GNUNET_break (0);
+ return NULL;
+ }
irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext));
irc->h = h;
irc->pr = pr;
cm = GNUNET_malloc (sizeof (struct ControlMessage) +
- sizeof (struct RequestInfoMessage));
+ sizeof (struct RequestInfoMessage));
cm->cont = &change_preference_send_continuation;
cm->cont_cls = irc;
irc->cm = cm;
- rim = (struct RequestInfoMessage*) &cm[1];
+ rim = (struct RequestInfoMessage *) &cm[1];
rim->header.size = htons (sizeof (struct RequestInfoMessage));
rim->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO);
rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++);
rim->limit_outbound = bw_out;
rim->reserve_inbound = htonl (amount);
- rim->preference_change = GNUNET_htonll(preference);
+ rim->preference_change = GNUNET_htonll (preference);
rim->peer = *peer;
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing CHANGE PREFERENCE request for peer `%s' with RIM %u\n",
- GNUNET_i2s (peer),
- (unsigned int) pr->rim_id);
+ "Queueing CHANGE PREFERENCE request for peer `%s' with RIM %u\n",
+ GNUNET_i2s (peer), (unsigned int) pr->rim_id);
#endif
GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
- h->control_pending_tail,
- cm);
+ h->control_pending_tail, cm);
pr->pcic = info;
pr->pcic_cls = info_cls;
- pr->pcic_ptr = irc; /* for free'ing irc */
+ pr->pcic_ptr = irc; /* for free'ing irc */
if (NULL != h->client)
trigger_next_request (h, GNUNET_NO);
return irc;
@@ -2004,19 +1901,20 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
* @param irc context returned by the original GNUNET_CORE_peer_get_info call
*/
void
-GNUNET_CORE_peer_change_preference_cancel (struct GNUNET_CORE_InformationRequestContext *irc)
+GNUNET_CORE_peer_change_preference_cancel (struct
+ GNUNET_CORE_InformationRequestContext
+ *irc)
{
struct GNUNET_CORE_Handle *h = irc->h;
struct PeerRecord *pr = irc->pr;
GNUNET_assert (pr->pcic_ptr == irc);
if (irc->cm != NULL)
- {
- GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
- h->control_pending_tail,
- irc->cm);
- GNUNET_free (irc->cm);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
+ h->control_pending_tail, irc->cm);
+ GNUNET_free (irc->cm);
+ }
pr->pcic = NULL;
pr->pcic_cls = NULL;
pr->pcic_ptr = NULL;
diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c
index 967580f83..1bad9a768 100644
--- a/src/core/core_api_iterate_peers.c
+++ b/src/core/core_api_iterate_peers.c
@@ -66,8 +66,7 @@ struct GNUNET_CORE_RequestContext
* @param msg NULL on error or last entry
*/
static void
-receive_info (void *cls,
- const struct GNUNET_MessageHeader *msg)
+receive_info (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CORE_RequestContext *request_context = cls;
const struct ConnectNotifyMessage *connect_message;
@@ -75,53 +74,51 @@ receive_info (void *cls,
uint16_t msize;
/* Handle last message or error case, disconnect and clean up */
- if ( (msg == NULL) ||
+ if ((msg == NULL) ||
((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END) &&
- (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader))) )
- {
- if (request_context->peer_cb != NULL)
- request_context->peer_cb (request_context->cb_cls,
- NULL, NULL);
- GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
- GNUNET_free (request_context);
- return;
- }
+ (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader))))
+ {
+ if (request_context->peer_cb != NULL)
+ request_context->peer_cb (request_context->cb_cls, NULL, NULL);
+ GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
+ GNUNET_free (request_context);
+ return;
+ }
msize = ntohs (msg->size);
/* Handle incorrect message type or size, disconnect and clean up */
- if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) ||
- (msize < sizeof (struct ConnectNotifyMessage)) )
- {
- GNUNET_break (0);
- if (request_context->peer_cb != NULL)
- request_context->peer_cb (request_context->cb_cls,
- NULL, NULL);
- GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
- GNUNET_free (request_context);
- return;
- }
+ if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) ||
+ (msize < sizeof (struct ConnectNotifyMessage)))
+ {
+ GNUNET_break (0);
+ if (request_context->peer_cb != NULL)
+ request_context->peer_cb (request_context->cb_cls, NULL, NULL);
+ GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
+ GNUNET_free (request_context);
+ return;
+ }
connect_message = (const struct ConnectNotifyMessage *) msg;
ats_count = ntohl (connect_message->ats_count);
- if ( (msize != sizeof (struct ConnectNotifyMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
- (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&connect_message->ats)[ats_count].type)) )
- {
- GNUNET_break (0);
- if (request_context->peer_cb != NULL)
- request_context->peer_cb (request_context->cb_cls,
- NULL, NULL);
- GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
- GNUNET_free (request_context);
- return;
- }
+ if ((msize !=
+ sizeof (struct ConnectNotifyMessage) +
+ ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
+ (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR !=
+ ntohl ((&connect_message->ats)[ats_count].type)))
+ {
+ GNUNET_break (0);
+ if (request_context->peer_cb != NULL)
+ request_context->peer_cb (request_context->cb_cls, NULL, NULL);
+ GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
+ GNUNET_free (request_context);
+ return;
+ }
/* Normal case */
if (request_context->peer_cb != NULL)
request_context->peer_cb (request_context->cb_cls,
- &connect_message->peer,
- &connect_message->ats);
- GNUNET_CLIENT_receive(request_context->client,
- &receive_info,
- request_context,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ &connect_message->peer, &connect_message->ats);
+ GNUNET_CLIENT_receive (request_context->client,
+ &receive_info,
+ request_context, GNUNET_TIME_UNIT_FOREVER_REL);
}
/**
@@ -136,28 +133,29 @@ receive_info (void *cls,
* @return number of bytes written to buf
*/
static size_t
-transmit_request(void *cls,
- size_t size, void *buf)
+transmit_request (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader *msg;
struct GNUNET_PeerIdentity *peer = cls;
int msize;
if (peer == NULL)
- msize = sizeof(struct GNUNET_MessageHeader);
+ msize = sizeof (struct GNUNET_MessageHeader);
else
- msize = sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_PeerIdentity);
+ msize =
+ sizeof (struct GNUNET_MessageHeader) +
+ sizeof (struct GNUNET_PeerIdentity);
if ((size < msize) || (buf == NULL))
return 0;
- msg = (struct GNUNET_MessageHeader *)buf;
+ msg = (struct GNUNET_MessageHeader *) buf;
msg->size = htons (msize);
if (peer != NULL)
- {
- msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED);
- memcpy(&msg[1], peer, sizeof(struct GNUNET_PeerIdentity));
- }
+ {
+ msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED);
+ memcpy (&msg[1], peer, sizeof (struct GNUNET_PeerIdentity));
+ }
else
msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS);
@@ -189,21 +187,26 @@ GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg,
client = GNUNET_CLIENT_connect ("core", cfg);
if (client == NULL)
return GNUNET_SYSERR;
- GNUNET_assert(peer != NULL);
+ GNUNET_assert (peer != NULL);
request_context = GNUNET_malloc (sizeof (struct GNUNET_CORE_RequestContext));
request_context->client = client;
request_context->peer_cb = peer_cb;
request_context->cb_cls = cb_cls;
request_context->peer = peer;
- request_context->th = GNUNET_CLIENT_notify_transmit_ready(client,
- sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_PeerIdentity),
- GNUNET_TIME_relative_get_forever(),
- GNUNET_YES,
- &transmit_request,
- peer);
- GNUNET_assert(request_context->th != NULL);
- GNUNET_CLIENT_receive(client, &receive_info, request_context, GNUNET_TIME_relative_get_forever());
+ request_context->th = GNUNET_CLIENT_notify_transmit_ready (client,
+ sizeof (struct
+ GNUNET_MessageHeader)
+ +
+ sizeof (struct
+ GNUNET_PeerIdentity),
+ GNUNET_TIME_relative_get_forever
+ (), GNUNET_YES,
+ &transmit_request,
+ peer);
+ GNUNET_assert (request_context->th != NULL);
+ GNUNET_CLIENT_receive (client, &receive_info, request_context,
+ GNUNET_TIME_relative_get_forever ());
return GNUNET_OK;
}
@@ -235,14 +238,16 @@ GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
request_context->peer_cb = peer_cb;
request_context->cb_cls = cb_cls;
- request_context->th = GNUNET_CLIENT_notify_transmit_ready(client,
- sizeof(struct GNUNET_MessageHeader),
- GNUNET_TIME_relative_get_forever(),
- GNUNET_YES,
- &transmit_request,
- NULL);
+ request_context->th = GNUNET_CLIENT_notify_transmit_ready (client,
+ sizeof (struct
+ GNUNET_MessageHeader),
+ GNUNET_TIME_relative_get_forever
+ (), GNUNET_YES,
+ &transmit_request,
+ NULL);
- GNUNET_CLIENT_receive(client, &receive_info, request_context, GNUNET_TIME_relative_get_forever());
+ GNUNET_CLIENT_receive (client, &receive_info, request_context,
+ GNUNET_TIME_relative_get_forever ());
return GNUNET_OK;
}
diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c
index 8b0f6773a..284a79f69 100644
--- a/src/core/gnunet-core-list-connections.c
+++ b/src/core/gnunet-core-list-connections.c
@@ -36,7 +36,7 @@
static int no_resolve;
#if VERBOSE
- static unsigned int peer_count;
+static unsigned int peer_count;
#endif
static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -74,15 +74,15 @@ dump_pc (struct PrintContext *pc)
struct AddressStringList *address;
GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc);
- printf (_("Peer `%s'\n"),
- (const char *) &enc);
+ printf (_("Peer `%s'\n"), (const char *) &enc);
while (NULL != (address = pc->address_list_head))
- {
- printf ("\t%s\n", address->address_string);
- GNUNET_free(address->address_string);
- GNUNET_CONTAINER_DLL_remove(pc->address_list_head, pc->address_list_tail, address);
- GNUNET_free(address);
- }
+ {
+ printf ("\t%s\n", address->address_string);
+ GNUNET_free (address->address_string);
+ GNUNET_CONTAINER_DLL_remove (pc->address_list_head, pc->address_list_tail,
+ address);
+ GNUNET_free (address);
+ }
printf ("\n");
@@ -97,24 +97,24 @@ dump_pc (struct PrintContext *pc)
* @param address NULL on error, otherwise 0-terminated printable UTF-8 string
*/
static void
-process_resolved_address (void *cls,
- const char *address)
+process_resolved_address (void *cls, const char *address)
{
struct PrintContext *pc = cls;
struct AddressStringList *new_address;
if (address == NULL)
- {
- dump_pc (pc);
- return;
- }
+ {
+ dump_pc (pc);
+ return;
+ }
- new_address = GNUNET_malloc(sizeof(struct AddressStringList));
+ new_address = GNUNET_malloc (sizeof (struct AddressStringList));
#if VERBOSE
- fprintf(stderr, "Received address %s\n", address);
+ fprintf (stderr, "Received address %s\n", address);
#endif
- new_address->address_string = GNUNET_strdup(address);
- GNUNET_CONTAINER_DLL_insert(pc->address_list_head, pc->address_list_tail, new_address);
+ new_address->address_string = GNUNET_strdup (address);
+ GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail,
+ new_address);
}
@@ -127,23 +127,23 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
{
struct PrintContext *pc;
- if (peer != NULL) /* Not yet finished */
- {
+ if (peer != NULL) /* Not yet finished */
+ {
#if VERBOSE
- fprintf(stderr, "Learned about peer %s\n", GNUNET_i2s(peer));
- peer_count++;
+ fprintf (stderr, "Learned about peer %s\n", GNUNET_i2s (peer));
+ peer_count++;
#endif
- pc = GNUNET_malloc (sizeof (struct PrintContext));
- pc->peer = *peer;
- GNUNET_TRANSPORT_peer_address_lookup (cfg, peer,
- GNUNET_TIME_UNIT_MINUTES,
- &process_resolved_address, pc);
- }
+ pc = GNUNET_malloc (sizeof (struct PrintContext));
+ pc->peer = *peer;
+ GNUNET_TRANSPORT_peer_address_lookup (cfg, peer,
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_resolved_address, pc);
+ }
#if VERBOSE
else
- {
- fprintf(stderr, "Counted %u total connected peers.\n", peer_count);
- }
+ {
+ fprintf (stderr, "Counted %u total connected peers.\n", peer_count);
+ }
#endif
}
@@ -159,22 +159,17 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
static void
run (void *cls,
char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
if (args[0] != NULL)
- {
- fprintf (stderr,
- _("Invalid command line argument `%s'\n"),
- args[0]);
- return;
- }
+ {
+ fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]);
+ return;
+ }
- GNUNET_CORE_iterate_peers (cfg,
- &connected_peer_callback,
- NULL);
+ GNUNET_CORE_iterate_peers (cfg, &connected_peer_callback, NULL);
}
@@ -199,7 +194,8 @@ main (int argc, char *const *argv)
GNUNET_PROGRAM_run (argc,
argv,
"gnunet-list-connections",
- gettext_noop ("Print information about connected peers."),
+ gettext_noop
+ ("Print information about connected peers."),
options, &run, NULL)) ? 0 : 1;
}
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 2e68571a4..95e182448 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -164,7 +164,7 @@ enum PeerStateMachine
* We've sent our session key.
*/
PEER_STATE_KEY_SENT,
-
+
/**
* We've received the other peers session key.
*/
@@ -241,7 +241,7 @@ struct PingMessage
* Message type is CORE_PING.
*/
struct GNUNET_MessageHeader header;
-
+
/**
* Seed for the IV
*/
@@ -271,7 +271,7 @@ struct PongMessage
* Message type is CORE_PONG.
*/
struct GNUNET_MessageHeader header;
-
+
/**
* Seed for the IV
*/
@@ -489,7 +489,7 @@ struct Neighbour
/**
* Performance data for the peer.
- */
+ */
struct GNUNET_TRANSPORT_ATS_Information *ats;
/**
@@ -578,7 +578,7 @@ struct Neighbour
/**
* Number of entries in 'ats'.
- */
+ */
unsigned int ats_count;
/**
@@ -601,12 +601,12 @@ struct Neighbour
/**
* Available bandwidth in for this peer (current target).
*/
- struct GNUNET_BANDWIDTH_Value32NBO bw_in;
+ struct GNUNET_BANDWIDTH_Value32NBO bw_in;
/**
* Available bandwidth out for this peer (current target).
*/
- struct GNUNET_BANDWIDTH_Value32NBO bw_out;
+ struct GNUNET_BANDWIDTH_Value32NBO bw_out;
/**
* Internal bandwidth limit set for this peer (initially typically
@@ -634,7 +634,7 @@ struct Neighbour
/**
* Are we currently connected to this neighbour?
- */
+ */
int is_connected;
};
@@ -731,7 +731,7 @@ struct ClientActiveRequest
* Unique request ID (in big endian).
*/
uint16_t smr_id;
-
+
};
@@ -754,7 +754,7 @@ static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
/**
* Bitmap of message types this peer is able to handle.
*/
-static uint32_t my_type_map[(UINT16_MAX + 1)/32];
+static uint32_t my_type_map[(UINT16_MAX + 1) / 32];
/**
* Handle to peerinfo service.
@@ -821,9 +821,8 @@ static unsigned long long bandwidth_target_out_bps;
*/
static void
derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
- const struct GNUNET_CRYPTO_AesSessionKey *skey,
- uint32_t seed,
- struct GNUNET_TIME_Absolute creation_time)
+ const struct GNUNET_CRYPTO_AesSessionKey *skey,
+ uint32_t seed, struct GNUNET_TIME_Absolute creation_time)
{
static const char ctx[] = "authentication key";
struct GNUNET_TIME_AbsoluteNBO ctbe;
@@ -833,13 +832,10 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
GNUNET_CRYPTO_hmac_derive_key (akey,
skey,
&seed,
- sizeof(seed),
+ sizeof (seed),
&skey->key,
- sizeof(skey->key),
- &ctbe,
- sizeof(ctbe),
- ctx,
- sizeof(ctx), NULL);
+ sizeof (skey->key),
+ &ctbe, sizeof (ctbe), ctx, sizeof (ctx), NULL);
}
@@ -848,19 +844,18 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
*/
static void
derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
- const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
- const struct GNUNET_PeerIdentity *identity)
+ const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
+ const struct GNUNET_PeerIdentity *identity)
{
static const char ctx[] = "initialization vector";
GNUNET_CRYPTO_aes_derive_iv (iv,
skey,
&seed,
- sizeof(seed),
+ sizeof (seed),
&identity->hashPubKey.bits,
- sizeof(identity->hashPubKey.bits),
- ctx,
- sizeof(ctx), NULL);
+ sizeof (identity->hashPubKey.bits),
+ ctx, sizeof (ctx), NULL);
}
/**
@@ -868,21 +863,19 @@ derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
*/
static void
derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
- const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
- uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
+ const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
+ uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
{
static const char ctx[] = "pong initialization vector";
GNUNET_CRYPTO_aes_derive_iv (iv,
skey,
&seed,
- sizeof(seed),
+ sizeof (seed),
&identity->hashPubKey.bits,
- sizeof(identity->hashPubKey.bits),
+ sizeof (identity->hashPubKey.bits),
&challenge,
- sizeof(challenge),
- ctx,
- sizeof(ctx), NULL);
+ sizeof (challenge), ctx, sizeof (ctx), NULL);
}
@@ -893,11 +886,11 @@ derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
* @param n neighbour in question
* @return absolute timeout
*/
-static struct GNUNET_TIME_Absolute
+static struct GNUNET_TIME_Absolute
get_neighbour_timeout (struct Neighbour *n)
{
return GNUNET_TIME_absolute_add (n->last_activity,
- GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
}
@@ -905,9 +898,7 @@ get_neighbour_timeout (struct Neighbour *n)
* Helper function for update_preference_sum.
*/
static int
-update_preference (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+update_preference (void *cls, const GNUNET_HashCode * key, void *value)
{
unsigned long long *ps = cls;
struct Neighbour *n = value;
@@ -915,7 +906,7 @@ update_preference (void *cls,
n->current_preference /= 2;
*ps += n->current_preference;
return GNUNET_OK;
-}
+}
/**
@@ -932,13 +923,13 @@ update_preference_sum (unsigned long long inc)
os = preference_sum;
preference_sum += inc;
if (preference_sum >= os)
- return; /* done! */
+ return; /* done! */
/* overflow! compensate by cutting all values in half! */
preference_sum = 0;
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &update_preference,
- &preference_sum);
- GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"), preference_sum, GNUNET_NO);
+ &update_preference, &preference_sum);
+ GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"),
+ preference_sum, GNUNET_NO);
}
@@ -966,19 +957,17 @@ find_neighbour (const struct GNUNET_PeerIdentity *peer)
*/
static void
send_to_client (struct Client *client,
- const struct GNUNET_MessageHeader *msg,
- int can_drop)
+ const struct GNUNET_MessageHeader *msg, int can_drop)
{
-#if DEBUG_CORE_CLIENT
+#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Preparing to send %u bytes of message of type %u to client.\n",
- (unsigned int) ntohs (msg->size),
+ (unsigned int) ntohs (msg->size),
(unsigned int) ntohs (msg->type));
-#endif
+#endif
GNUNET_SERVER_notification_context_unicast (notifier,
- client->client_handle,
- msg,
- can_drop);
+ client->client_handle,
+ msg, can_drop);
}
@@ -991,26 +980,25 @@ send_to_client (struct Client *client,
* @param options mask to use
*/
static void
-send_to_all_clients (const struct GNUNET_MessageHeader *msg,
- int can_drop,
- int options)
+send_to_all_clients (const struct GNUNET_MessageHeader *msg,
+ int can_drop, int options)
{
struct Client *c;
c = clients;
while (c != NULL)
+ {
+ if (0 != (c->options & options))
{
- if (0 != (c->options & options))
- {
#if DEBUG_CORE_CLIENT > 1
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message of type %u to client.\n",
- (unsigned int) ntohs (msg->type));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message of type %u to client.\n",
+ (unsigned int) ntohs (msg->type));
#endif
- send_to_client (c, msg, can_drop);
- }
- c = c->next;
+ send_to_client (c, msg, can_drop);
}
+ c = c->next;
+ }
}
@@ -1028,27 +1016,23 @@ handle_peer_status_change (struct Neighbour *n)
struct GNUNET_TRANSPORT_ATS_Information *ats;
size_t size;
- if ( (! n->is_connected) ||
- (n->status != PEER_STATE_KEY_CONFIRMED) )
+ if ((!n->is_connected) || (n->status != PEER_STATE_KEY_CONFIRMED))
return;
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%4s' changed status\n",
- GNUNET_i2s (&n->peer));
+ "Peer `%4s' changed status\n", GNUNET_i2s (&n->peer));
#endif
size = sizeof (struct PeerStatusNotifyMessage) +
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- /* recovery strategy: throw away performance data */
- GNUNET_array_grow (n->ats,
- n->ats_count,
- 0);
- size = sizeof (struct PeerStatusNotifyMessage) +
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
- }
- psnm = (struct PeerStatusNotifyMessage*) buf;
+ {
+ GNUNET_break (0);
+ /* recovery strategy: throw away performance data */
+ GNUNET_array_grow (n->ats, n->ats_count, 0);
+ size = sizeof (struct PeerStatusNotifyMessage) +
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ }
+ psnm = (struct PeerStatusNotifyMessage *) buf;
psnm->header.size = htons (size);
psnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE);
psnm->timeout = GNUNET_TIME_absolute_hton (get_neighbour_timeout (n));
@@ -1058,17 +1042,15 @@ handle_peer_status_change (struct Neighbour *n)
psnm->ats_count = htonl (n->ats_count);
ats = &psnm->ats;
memcpy (ats,
- n->ats,
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ n->ats,
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
ats[n->ats_count].type = htonl (0);
ats[n->ats_count].value = htonl (0);
- send_to_all_clients (&psnm->header,
- GNUNET_YES,
- GNUNET_CORE_OPTION_SEND_STATUS_CHANGE);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peer status changes"),
- 1,
- GNUNET_NO);
+ send_to_all_clients (&psnm->header,
+ GNUNET_YES, GNUNET_CORE_OPTION_SEND_STATUS_CHANGE);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# peer status changes"),
+ 1, GNUNET_NO);
}
@@ -1088,55 +1070,53 @@ schedule_peer_messages (struct Neighbour *n)
struct Client *c;
struct MessageEntry *mqe;
unsigned int queue_size;
-
+
/* check if neighbour queue is empty enough! */
if (n != &self)
+ {
+ queue_size = 0;
+ mqe = n->messages;
+ while (mqe != NULL)
+ {
+ queue_size++;
+ mqe = mqe->next;
+ }
+ if (queue_size >= MAX_PEER_QUEUE_SIZE)
{
- queue_size = 0;
- mqe = n->messages;
- while (mqe != NULL)
- {
- queue_size++;
- mqe = mqe->next;
- }
- if (queue_size >= MAX_PEER_QUEUE_SIZE)
- {
#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not considering client transmission requests: queue full\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Not considering client transmission requests: queue full\n");
#endif
- return; /* queue still full */
- }
- /* find highest priority request */
- pos = n->active_client_request_head;
- car = NULL;
- while (pos != NULL)
- {
- if ( (car == NULL) ||
- (pos->priority > car->priority) )
- car = pos;
- pos = pos->next;
- }
+ return; /* queue still full */
}
- else
+ /* find highest priority request */
+ pos = n->active_client_request_head;
+ car = NULL;
+ while (pos != NULL)
{
- car = n->active_client_request_head;
+ if ((car == NULL) || (pos->priority > car->priority))
+ car = pos;
+ pos = pos->next;
}
+ }
+ else
+ {
+ car = n->active_client_request_head;
+ }
if (car == NULL)
- return; /* no pending requests */
+ return; /* no pending requests */
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Permitting client transmission request to `%s'\n",
- GNUNET_i2s (&n->peer));
+ "Permitting client transmission request to `%s'\n",
+ GNUNET_i2s (&n->peer));
#endif
c = car->client;
GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
- n->active_client_request_tail,
- car);
+ n->active_client_request_tail, car);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (c->requests,
- &n->peer.hashPubKey,
- car));
+ GNUNET_CONTAINER_multihashmap_remove (c->requests,
+ &n->peer.hashPubKey,
+ car));
smr.header.size = htons (sizeof (struct SendMessageReady));
smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
smr.size = htons (car->msize);
@@ -1160,27 +1140,28 @@ compute_type_map_message ()
struct GNUNET_MessageHeader *hdr;
#ifdef compressBound
- dlen = compressBound (sizeof(my_type_map));
+ dlen = compressBound (sizeof (my_type_map));
#else
- dlen = sizeof(my_type_map) + (sizeof(my_type_map) / 100) + 20;
+ dlen = sizeof (my_type_map) + (sizeof (my_type_map) / 100) + 20;
/* documentation says 100.1% oldSize + 12 bytes, but we
- should be able to overshoot by more to be safe */
+ * should be able to overshoot by more to be safe */
#endif
hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader));
hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader));
- tmp = (char*) &hdr[1];
- if ( (Z_OK != compress2 ((Bytef *) tmp,
- &dlen, (const Bytef *) my_type_map, sizeof (my_type_map), 9)) ||
- (dlen >= sizeof(my_type_map)) )
- {
- dlen = sizeof (my_type_map);
- memcpy (tmp, my_type_map, sizeof (my_type_map));
- hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
- }
+ tmp = (char *) &hdr[1];
+ if ((Z_OK != compress2 ((Bytef *) tmp,
+ &dlen, (const Bytef *) my_type_map,
+ sizeof (my_type_map), 9)) ||
+ (dlen >= sizeof (my_type_map)))
+ {
+ dlen = sizeof (my_type_map);
+ memcpy (tmp, my_type_map, sizeof (my_type_map));
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
+ }
else
- {
- hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
- }
+ {
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
+ }
return hdr;
}
@@ -1194,9 +1175,7 @@ compute_type_map_message ()
* @return always GNUNET_OK
*/
static int
-send_type_map_to_neighbour (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+send_type_map_to_neighbour (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_MessageHeader *hdr = cls;
struct Neighbour *n = value;
@@ -1225,15 +1204,14 @@ send_type_map_to_neighbour (void *cls,
*/
static void
broadcast_my_type_map ()
-{
+{
struct GNUNET_MessageHeader *hdr;
if (NULL == neighbours)
return;
hdr = compute_type_map_message ();
GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &send_type_map_to_neighbour,
- hdr);
+ &send_type_map_to_neighbour, hdr);
GNUNET_free (hdr);
}
@@ -1243,72 +1221,68 @@ broadcast_my_type_map ()
*/
static void
handle_client_send_request (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct SendMessageRequest *req;
struct Neighbour *n;
struct Client *c;
struct ClientActiveRequest *car;
- req = (const struct SendMessageRequest*) message;
+ req = (const struct SendMessageRequest *) message;
if (0 == memcmp (&req->peer,
- &my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
+ &my_identity, sizeof (struct GNUNET_PeerIdentity)))
n = &self;
else
n = find_neighbour (&req->peer);
- if ( (n == NULL) ||
- (GNUNET_YES != n->is_connected) ||
- (n->status != PEER_STATE_KEY_CONFIRMED) )
- {
- /* neighbour must have disconnected since request was issued,
- ignore (client will realize it once it processes the
- disconnect notification) */
+ if ((n == NULL) ||
+ (GNUNET_YES != n->is_connected) ||
+ (n->status != PEER_STATE_KEY_CONFIRMED))
+ {
+ /* neighbour must have disconnected since request was issued,
+ * ignore (client will realize it once it processes the
+ * disconnect notification) */
#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropped client request for transmission (am disconnected)\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropped client request for transmission (am disconnected)\n");
#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# send requests dropped (disconnected)"),
- 1,
- GNUNET_NO);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# send requests dropped (disconnected)"), 1,
+ GNUNET_NO);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
c = clients;
- while ( (c != NULL) &&
- (c->client_handle != client) )
+ while ((c != NULL) && (c->client_handle != client))
c = c->next;
if (c == NULL)
- {
- /* client did not send INIT first! */
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ /* client did not send INIT first! */
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
if (c->requests == NULL)
c->requests = GNUNET_CONTAINER_multihashmap_create (16);
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received client transmission request. queueing\n");
#endif
- car = GNUNET_CONTAINER_multihashmap_get (c->requests,
- &req->peer.hashPubKey);
+ car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey);
if (car == NULL)
- {
- /* create new entry */
- car = GNUNET_malloc (sizeof (struct ClientActiveRequest));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (c->requests,
- &req->peer.hashPubKey,
- car,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
- GNUNET_CONTAINER_DLL_insert (n->active_client_request_head,
- n->active_client_request_tail,
- car);
- car->client = c;
- }
+ {
+ /* create new entry */
+ car = GNUNET_malloc (sizeof (struct ClientActiveRequest));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (c->requests,
+ &req->peer.hashPubKey,
+ car,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ GNUNET_CONTAINER_DLL_insert (n->active_client_request_head,
+ n->active_client_request_tail, car);
+ car->client = c;
+ }
car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline);
car->priority = ntohl (req->priority);
car->queue_size = ntohl (req->queue_size);
@@ -1324,8 +1298,7 @@ handle_client_send_request (void *cls,
*/
static int
notify_client_about_neighbour (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
struct Client *c = cls;
struct Neighbour *n = value;
@@ -1335,36 +1308,34 @@ notify_client_about_neighbour (void *cls,
struct ConnectNotifyMessage *cnm;
size = sizeof (struct ConnectNotifyMessage) +
- (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- /* recovery strategy: throw away performance data */
- GNUNET_array_grow (n->ats,
- n->ats_count,
- 0);
- size = sizeof (struct ConnectNotifyMessage) +
- (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
- }
- cnm = (struct ConnectNotifyMessage*) buf;
+ {
+ GNUNET_break (0);
+ /* recovery strategy: throw away performance data */
+ GNUNET_array_grow (n->ats, n->ats_count, 0);
+ size = sizeof (struct ConnectNotifyMessage) +
+ (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ }
+ cnm = (struct ConnectNotifyMessage *) buf;
cnm->header.size = htons (size);
cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
cnm->ats_count = htonl (n->ats_count);
ats = &cnm->ats;
memcpy (ats,
- n->ats,
- sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count);
+ n->ats,
+ sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count);
ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
ats[n->ats_count].value = htonl (0);
if (n->status == PEER_STATE_KEY_CONFIRMED)
- {
+ {
#if DEBUG_CORE_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message to client.\n", "NOTIFY_CONNECT");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending `%s' message to client.\n", "NOTIFY_CONNECT");
#endif
- cnm->peer = n->peer;
- send_to_client (c, &cnm->header, GNUNET_NO);
- }
+ cnm->peer = n->peer;
+ send_to_client (c, &cnm->header, GNUNET_NO);
+ }
return GNUNET_OK;
}
@@ -1388,28 +1359,27 @@ handle_client_init (void *cls,
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client connecting to core service with `%s' message\n",
- "INIT");
+ "Client connecting to core service with `%s' message\n", "INIT");
#endif
/* check that we don't have an entry already */
c = clients;
while (c != NULL)
- {
- if (client == c->client_handle)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- c = c->next;
- }
- msize = ntohs (message->size);
- if (msize < sizeof (struct InitMessage))
+ {
+ if (client == c->client_handle)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
+ c = c->next;
+ }
+ msize = ntohs (message->size);
+ if (msize < sizeof (struct InitMessage))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
GNUNET_SERVER_notification_context_add (notifier, client);
im = (const struct InitMessage *) message;
types = (const uint16_t *) &im[1];
@@ -1420,20 +1390,19 @@ handle_client_init (void *cls,
clients = c;
c->tcnt = msize / sizeof (uint16_t);
c->types = (const uint16_t *) &c[1];
- wtypes = (uint16_t *) &c[1];
- for (i=0;i<c->tcnt;i++)
- {
- wtypes[i] = ntohs (types[i]);
- my_type_map[wtypes[i]/32] |= (1 << (wtypes[i] % 32));
- }
+ wtypes = (uint16_t *) & c[1];
+ for (i = 0; i < c->tcnt; i++)
+ {
+ wtypes[i] = ntohs (types[i]);
+ my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32));
+ }
if (c->tcnt > 0)
broadcast_my_type_map ();
c->options = ntohl (im->options);
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p is interested in %u message types\n",
- c,
- (unsigned int) c->tcnt);
+ "Client %p is interested in %u message types\n",
+ c, (unsigned int) c->tcnt);
#endif
/* send init reply message */
irm.header.size = htons (sizeof (struct InitReplyMessage));
@@ -1448,12 +1417,11 @@ handle_client_init (void *cls,
#endif
send_to_client (c, &irm.header, GNUNET_NO);
if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT))
- {
- /* notify new client about existing neighbours */
- GNUNET_CONTAINER_multihashmap_iterate (neighbours,
- &notify_client_about_neighbour,
- c);
- }
+ {
+ /* notify new client about existing neighbours */
+ GNUNET_CONTAINER_multihashmap_iterate (neighbours,
+ &notify_client_about_neighbour, c);
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -1468,8 +1436,7 @@ handle_client_init (void *cls,
*/
static int
destroy_active_client_request (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+ const GNUNET_HashCode * key, void *value)
{
struct ClientActiveRequest *car = value;
struct Neighbour *n;
@@ -1479,8 +1446,7 @@ destroy_active_client_request (void *cls,
n = find_neighbour (&peer);
GNUNET_assert (NULL != n);
GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
- n->active_client_request_tail,
- car);
+ n->active_client_request_tail, car);
GNUNET_free (car);
return GNUNET_YES;
}
@@ -1504,44 +1470,43 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
return;
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p has disconnected from core service.\n",
- client);
+ "Client %p has disconnected from core service.\n", client);
#endif
prev = NULL;
pos = clients;
while (pos != NULL)
- {
- if (client == pos->client_handle)
- break;
- prev = pos;
- pos = pos->next;
- }
+ {
+ if (client == pos->client_handle)
+ break;
+ prev = pos;
+ pos = pos->next;
+ }
if (pos == NULL)
- {
- /* client never sent INIT */
- return;
- }
+ {
+ /* client never sent INIT */
+ return;
+ }
if (prev == NULL)
clients = pos->next;
else
prev->next = pos->next;
if (pos->requests != NULL)
- {
- GNUNET_CONTAINER_multihashmap_iterate (pos->requests,
- &destroy_active_client_request,
- NULL);
- GNUNET_CONTAINER_multihashmap_destroy (pos->requests);
- }
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (pos->requests,
+ &destroy_active_client_request,
+ NULL);
+ GNUNET_CONTAINER_multihashmap_destroy (pos->requests);
+ }
GNUNET_free (pos);
/* rebuild my_type_map */
memset (my_type_map, 0, sizeof (my_type_map));
for (pos = clients; NULL != pos; pos = pos->next)
- {
- wtypes = (const uint16_t *) &pos[1];
- for (i=0;i<pos->tcnt;i++)
- my_type_map[wtypes[i]/32] |= (1 << (wtypes[i] % 32));
- }
+ {
+ wtypes = (const uint16_t *) &pos[1];
+ for (i = 0; i < pos->tcnt; i++)
+ my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32));
+ }
broadcast_my_type_map ();
}
@@ -1555,9 +1520,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
* @return GNUNET_OK (continue to iterate)
*/
static int
-queue_connect_message (void *cls,
- const GNUNET_HashCode *key,
- void *value)
+queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
struct Neighbour *n = value;
@@ -1566,39 +1529,35 @@ queue_connect_message (void *cls,
size_t size;
struct ConnectNotifyMessage *cnm;
- cnm = (struct ConnectNotifyMessage*) buf;
+ cnm = (struct ConnectNotifyMessage *) buf;
if (n->status != PEER_STATE_KEY_CONFIRMED)
return GNUNET_OK;
size = sizeof (struct ConnectNotifyMessage) +
- (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- /* recovery strategy: throw away performance data */
- GNUNET_array_grow (n->ats,
- n->ats_count,
- 0);
- size = sizeof (struct PeerStatusNotifyMessage) +
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
- }
- cnm = (struct ConnectNotifyMessage*) buf;
+ {
+ GNUNET_break (0);
+ /* recovery strategy: throw away performance data */
+ GNUNET_array_grow (n->ats, n->ats_count, 0);
+ size = sizeof (struct PeerStatusNotifyMessage) +
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ }
+ cnm = (struct ConnectNotifyMessage *) buf;
cnm->header.size = htons (size);
cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
cnm->ats_count = htonl (n->ats_count);
ats = &cnm->ats;
memcpy (ats,
- n->ats,
- n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
+ n->ats,
+ n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
- ats[n->ats_count].value = htonl (0);
+ ats[n->ats_count].value = htonl (0);
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending `%s' message to client.\n",
- "NOTIFY_CONNECT");
+ "Sending `%s' message to client.\n", "NOTIFY_CONNECT");
#endif
cnm->peer = n->peer;
- GNUNET_SERVER_transmit_context_append_message (tc,
- &cnm->header);
+ GNUNET_SERVER_transmit_context_append_message (tc, &cnm->header);
return GNUNET_OK;
}
@@ -1612,27 +1571,27 @@ queue_connect_message (void *cls,
*/
static void
handle_client_iterate_peers (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MessageHeader done_msg;
struct GNUNET_SERVER_TransmitContext *tc;
int msize;
+
/* notify new client about existing neighbours */
- msize = ntohs(message->size);
+ msize = ntohs (message->size);
tc = GNUNET_SERVER_transmit_context_create (client);
- if (msize == sizeof(struct GNUNET_MessageHeader))
- GNUNET_CONTAINER_multihashmap_iterate (neighbours, &queue_connect_message, tc);
+ if (msize == sizeof (struct GNUNET_MessageHeader))
+ GNUNET_CONTAINER_multihashmap_iterate (neighbours, &queue_connect_message,
+ tc);
else
- GNUNET_break(0);
+ GNUNET_break (0);
done_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END);
GNUNET_SERVER_transmit_context_append_message (tc, &done_msg);
- GNUNET_SERVER_transmit_context_run (tc,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -1645,9 +1604,8 @@ handle_client_iterate_peers (void *cls,
*/
static void
handle_client_have_peer (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
-
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MessageHeader done_msg;
struct GNUNET_SERVER_TransmitContext *tc;
@@ -1655,15 +1613,13 @@ handle_client_have_peer (void *cls,
tc = GNUNET_SERVER_transmit_context_create (client);
peer = (struct GNUNET_PeerIdentity *) &message[1];
- GNUNET_CONTAINER_multihashmap_get_multiple(neighbours,
- &peer->hashPubKey,
- &queue_connect_message,
- tc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (neighbours,
+ &peer->hashPubKey,
+ &queue_connect_message, tc);
done_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END);
GNUNET_SERVER_transmit_context_append_message (tc, &done_msg);
- GNUNET_SERVER_transmit_context_run (tc,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
@@ -1676,8 +1632,8 @@ handle_client_have_peer (void *cls,
*/
static void
handle_client_request_info (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
const struct RequestInfoMessage *rcm;
struct Client *pos;
@@ -1688,97 +1644,94 @@ handle_client_request_info (void *cls,
unsigned long long old_preference;
struct GNUNET_TIME_Relative rdelay;
- rdelay = GNUNET_TIME_relative_get_zero();
+ rdelay = GNUNET_TIME_relative_get_zero ();
#if DEBUG_CORE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core service receives `%s' request.\n", "REQUEST_INFO");
#endif
pos = clients;
while (pos != NULL)
- {
- if (client == pos->client_handle)
- break;
- pos = pos->next;
- }
+ {
+ if (client == pos->client_handle)
+ break;
+ pos = pos->next;
+ }
if (pos == NULL)
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
rcm = (const struct RequestInfoMessage *) message;
n = find_neighbour (&rcm->peer);
memset (&cim, 0, sizeof (cim));
- if ( (n != NULL) && (GNUNET_YES == n->is_connected) )
+ if ((n != NULL) && (GNUNET_YES == n->is_connected))
+ {
+ want_reserv = ntohl (rcm->reserve_inbound);
+ if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__)
{
- want_reserv = ntohl (rcm->reserve_inbound);
- if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__)
- {
- n->bw_out_internal_limit = rcm->limit_outbound;
- if (n->bw_out.value__ != GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
- n->bw_out_external_limit).value__)
- {
- n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
- n->bw_out_external_limit);
- GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window,
- n->bw_out);
- GNUNET_TRANSPORT_set_quota (transport,
- &n->peer,
- n->bw_in,
- n->bw_out);
- handle_peer_status_change (n);
- }
- }
- if (want_reserv < 0)
- {
- got_reserv = want_reserv;
- }
- else if (want_reserv > 0)
- {
- rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window,
- want_reserv);
- if (rdelay.rel_value == 0)
- got_reserv = want_reserv;
- else
- got_reserv = 0; /* all or nothing */
- }
+ n->bw_out_internal_limit = rcm->limit_outbound;
+ if (n->bw_out.value__ !=
+ GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
+ n->bw_out_external_limit).value__)
+ {
+ n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit,
+ n->bw_out_external_limit);
+ GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window,
+ n->bw_out);
+ GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out);
+ handle_peer_status_change (n);
+ }
+ }
+ if (want_reserv < 0)
+ {
+ got_reserv = want_reserv;
+ }
+ else if (want_reserv > 0)
+ {
+ rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window,
+ want_reserv);
+ if (rdelay.rel_value == 0)
+ got_reserv = want_reserv;
else
- got_reserv = 0;
- GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window,
- got_reserv);
- old_preference = n->current_preference;
- n->current_preference += GNUNET_ntohll(rcm->preference_change);
- if (old_preference > n->current_preference)
- {
- /* overflow; cap at maximum value */
- n->current_preference = ULLONG_MAX;
- }
- update_preference_sum (n->current_preference - old_preference);
-#if DEBUG_CORE_QUOTA
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n",
- (int) want_reserv,
- GNUNET_i2s (&rcm->peer),
- (int) got_reserv,
- (unsigned long long) rdelay.rel_value);
-#endif
- cim.reserved_amount = htonl (got_reserv);
- cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay);
- cim.bw_out = n->bw_out;
- cim.preference = n->current_preference;
+ got_reserv = 0; /* all or nothing */
}
- else
+ else
+ got_reserv = 0;
+ GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window, got_reserv);
+ old_preference = n->current_preference;
+ n->current_preference += GNUNET_ntohll (rcm->preference_change);
+ if (old_preference > n->current_preference)
{
- /* Technically, this COULD happen (due to asynchronous behavior),
- but it should be rare, so we should generate an info event
- to help diagnosis of serious errors that might be masked by this */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Client asked for preference change with peer `%s', which is not connected!\n"),
- GNUNET_i2s (&rcm->peer));
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
- return;
+ /* overflow; cap at maximum value */
+ n->current_preference = ULLONG_MAX;
}
+ update_preference_sum (n->current_preference - old_preference);
+#if DEBUG_CORE_QUOTA
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n",
+ (int) want_reserv,
+ GNUNET_i2s (&rcm->peer),
+ (int) got_reserv, (unsigned long long) rdelay.rel_value);
+#endif
+ cim.reserved_amount = htonl (got_reserv);
+ cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay);
+ cim.bw_out = n->bw_out;
+ cim.preference = n->current_preference;
+ }
+ else
+ {
+ /* Technically, this COULD happen (due to asynchronous behavior),
+ * but it should be rare, so we should generate an info event
+ * to help diagnosis of serious errors that might be masked by this */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Client asked for preference change with peer `%s', which is not connected!\n"),
+ GNUNET_i2s (&rcm->peer));
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ return;
+ }
cim.header.size = htons (sizeof (struct ConfigurationInfoMessage));
cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO);
cim.peer = rcm->peer;
@@ -1806,47 +1759,44 @@ free_neighbour (struct Neighbour *n)
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Destroying neighbour entry for peer `%4s'\n",
- GNUNET_i2s (&n->peer));
+ "Destroying neighbour entry for peer `%4s'\n",
+ GNUNET_i2s (&n->peer));
#endif
if (n->pitr != NULL)
- {
- GNUNET_PEERINFO_iterate_cancel (n->pitr);
- n->pitr = NULL;
- }
+ {
+ GNUNET_PEERINFO_iterate_cancel (n->pitr);
+ n->pitr = NULL;
+ }
if (n->skm != NULL)
- {
- GNUNET_free (n->skm);
- n->skm = NULL;
- }
+ {
+ GNUNET_free (n->skm);
+ n->skm = NULL;
+ }
while (NULL != (m = n->messages))
- {
- n->messages = m->next;
- GNUNET_free (m);
- }
+ {
+ n->messages = m->next;
+ GNUNET_free (m);
+ }
while (NULL != (m = n->encrypted_head))
- {
- GNUNET_CONTAINER_DLL_remove (n->encrypted_head,
- n->encrypted_tail,
- m);
- GNUNET_free (m);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m);
+ GNUNET_free (m);
+ }
while (NULL != (car = n->active_client_request_head))
- {
- GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
- n->active_client_request_tail,
- car);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (car->client->requests,
- &n->peer.hashPubKey,
- car));
- GNUNET_free (car);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (n->active_client_request_head,
+ n->active_client_request_tail, car);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (car->client->requests,
+ &n->peer.hashPubKey,
+ car));
+ GNUNET_free (car);
+ }
if (NULL != n->th)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th);
- n->th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th);
+ n->th = NULL;
+ }
if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (n->retry_plaintext_task);
if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
@@ -1855,13 +1805,12 @@ free_neighbour (struct Neighbour *n)
GNUNET_SCHEDULER_cancel (n->quota_update_task);
if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (n->dead_clean_task);
- if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (n->keep_alive_task);
+ if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (n->keep_alive_task);
if (n->status == PEER_STATE_KEY_CONFIRMED)
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# established sessions"),
- -1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# established sessions"),
+ -1, GNUNET_NO);
GNUNET_array_grow (n->ats, n->ats_count, 0);
GNUNET_free_non_null (n->public_key);
GNUNET_free_non_null (n->pending_ping);
@@ -1893,27 +1842,27 @@ static void process_encrypted_neighbour_queue (struct Neighbour *n);
*/
static int
do_encrypt (struct Neighbour *n,
- const struct GNUNET_CRYPTO_AesInitializationVector * iv,
+ const struct GNUNET_CRYPTO_AesInitializationVector *iv,
const void *in, void *out, size_t size)
{
if (size != (uint16_t) size)
- {
- GNUNET_break (0);
- return GNUNET_NO;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
GNUNET_assert (size ==
GNUNET_CRYPTO_aes_encrypt (in,
(uint16_t) size,
- &n->encrypt_key,
- iv, out));
- GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, GNUNET_NO);
+ &n->encrypt_key, iv, out));
+ GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size,
+ GNUNET_NO);
#if DEBUG_CORE > 2
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypted %u bytes for `%4s' using key %u, IV %u\n",
- (unsigned int) size,
+ (unsigned int) size,
GNUNET_i2s (&n->peer),
- (unsigned int) n->encrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (iv, sizeof(iv)));
+ (unsigned int) n->encrypt_key.crc32,
+ GNUNET_CRYPTO_crc32_n (iv, sizeof (iv)));
#endif
return GNUNET_OK;
}
@@ -1925,8 +1874,7 @@ do_encrypt (struct Neighbour *n,
*
* @param n neighbour to consider discarding
*/
-static void
-consider_free_neighbour (struct Neighbour *n);
+static void consider_free_neighbour (struct Neighbour *n);
/**
@@ -1937,8 +1885,7 @@ consider_free_neighbour (struct Neighbour *n);
* @param tc scheduler context (not used)
*/
static void
-send_keep_alive (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Neighbour *n = cls;
struct GNUNET_TIME_Relative retry;
@@ -1956,26 +1903,23 @@ send_keep_alive (void *cls,
me->priority = PING_PRIORITY;
me->size = sizeof (struct PingMessage);
GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head,
- n->encrypted_tail,
- n->encrypted_tail,
- me);
+ n->encrypted_tail, n->encrypted_tail, me);
pm = (struct PingMessage *) &me[1];
pm->header.size = htons (sizeof (struct PingMessage));
pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
pm->iv_seed = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- UINT32_MAX);
+ UINT32_MAX);
derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer);
pp.challenge = n->ping_challenge;
pp.target = n->peer;
#if DEBUG_HANDSHAKE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n",
- "PING",
- (unsigned int) n->ping_challenge,
- GNUNET_i2s (&n->peer),
- (unsigned int) n->encrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)),
- pm->iv_seed);
+ "PING",
+ (unsigned int) n->ping_challenge,
+ GNUNET_i2s (&n->peer),
+ (unsigned int) n->encrypt_key.crc32,
+ GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed);
#endif
do_encrypt (n,
&iv,
@@ -1987,11 +1931,9 @@ send_keep_alive (void *cls,
/* reschedule PING job */
left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n));
retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
- MIN_PING_FREQUENCY);
- n->keep_alive_task
- = GNUNET_SCHEDULER_add_delayed (retry,
- &send_keep_alive,
- n);
+ MIN_PING_FREQUENCY);
+ n->keep_alive_task
+ = GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n);
}
@@ -2003,8 +1945,7 @@ send_keep_alive (void *cls,
* @param tc scheduler context (not used)
*/
static void
-consider_free_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+consider_free_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct Neighbour *n = cls;
@@ -2021,33 +1962,29 @@ consider_free_task (void *cls,
*/
static void
consider_free_neighbour (struct Neighbour *n)
-{
+{
struct GNUNET_TIME_Relative left;
- if ( (n->th != NULL) ||
- (n->pitr != NULL) ||
- (GNUNET_YES == n->is_connected) )
- return; /* no chance */
-
+ if ((n->th != NULL) || (n->pitr != NULL) || (GNUNET_YES == n->is_connected))
+ return; /* no chance */
+
left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n));
if (left.rel_value > 0)
- {
- if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (n->dead_clean_task);
- n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left,
- &consider_free_task,
- n);
- return;
- }
+ {
+ if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (n->dead_clean_task);
+ n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left,
+ &consider_free_task, n);
+ return;
+ }
/* actually free the neighbour... */
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (neighbours,
- &n->peer.hashPubKey,
- n));
+ GNUNET_CONTAINER_multihashmap_remove (neighbours,
+ &n->peer.hashPubKey, n));
GNUNET_STATISTICS_set (stats,
- gettext_noop ("# neighbour entries allocated"),
- GNUNET_CONTAINER_multihashmap_size (neighbours),
- GNUNET_NO);
+ gettext_noop ("# neighbour entries allocated"),
+ GNUNET_CONTAINER_multihashmap_size (neighbours),
+ GNUNET_NO);
free_neighbour (n);
}
@@ -2062,9 +1999,7 @@ consider_free_neighbour (struct Neighbour *n)
* @return number of bytes transmitted
*/
static size_t
-notify_encrypted_transmit_ready (void *cls,
- size_t size,
- void *buf)
+notify_encrypted_transmit_ready (void *cls, size_t size, void *buf)
{
struct Neighbour *n = cls;
struct MessageEntry *m;
@@ -2074,50 +2009,48 @@ notify_encrypted_transmit_ready (void *cls,
n->th = NULL;
m = n->encrypted_head;
if (m == NULL)
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted message queue empty, no messages added to buffer for `%4s'\n",
- GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Encrypted message queue empty, no messages added to buffer for `%4s'\n",
+ GNUNET_i2s (&n->peer));
#endif
- return 0;
- }
- GNUNET_CONTAINER_DLL_remove (n->encrypted_head,
- n->encrypted_tail,
- m);
+ return 0;
+ }
+ GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m);
ret = 0;
cbuf = buf;
if (buf != NULL)
- {
- GNUNET_assert (size >= m->size);
- memcpy (cbuf, &m[1], m->size);
- ret = m->size;
- GNUNET_BANDWIDTH_tracker_consume (&n->available_send_window,
- m->size);
+ {
+ GNUNET_assert (size >= m->size);
+ memcpy (cbuf, &m[1], m->size);
+ ret = m->size;
+ GNUNET_BANDWIDTH_tracker_consume (&n->available_send_window, m->size);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Copied message of type %u and size %u into transport buffer for `%4s'\n",
- (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
- (unsigned int) ret,
- GNUNET_i2s (&n->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Copied message of type %u and size %u into transport buffer for `%4s'\n",
+ (unsigned int)
+ ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
+ (unsigned int) ret, GNUNET_i2s (&n->peer));
#endif
- process_encrypted_neighbour_queue (n);
- }
+ process_encrypted_neighbour_queue (n);
+ }
else
- {
+ {
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission of message of type %u and size %u failed\n",
- (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
- (unsigned int) m->size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission of message of type %u and size %u failed\n",
+ (unsigned int)
+ ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
+ (unsigned int) m->size);
#endif
- }
+ }
GNUNET_free (m);
consider_free_neighbour (n);
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# encrypted bytes given to transport"),
- ret,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# encrypted bytes given to transport"), ret,
+ GNUNET_NO);
return ret;
}
@@ -2143,47 +2076,46 @@ static void
process_encrypted_neighbour_queue (struct Neighbour *n)
{
struct MessageEntry *m;
-
+
if (n->th != NULL)
- return; /* request already pending */
+ return; /* request already pending */
if (GNUNET_YES != n->is_connected)
- {
- GNUNET_break (0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
m = n->encrypted_head;
if (m == NULL)
- {
- /* encrypted queue empty, try plaintext instead */
- process_plaintext_neighbour_queue (n);
- return;
- }
+ {
+ /* encrypted queue empty, try plaintext instead */
+ process_plaintext_neighbour_queue (n);
+ return;
+ }
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n",
(unsigned int) m->size,
GNUNET_i2s (&n->peer),
- (unsigned long long) GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value);
+ (unsigned long long)
+ GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value);
#endif
n->th =
- GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer,
- m->size,
- m->priority,
- GNUNET_TIME_absolute_get_remaining
- (m->deadline),
- &notify_encrypted_transmit_ready,
- n);
+ GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer,
+ m->size,
+ m->priority,
+ GNUNET_TIME_absolute_get_remaining
+ (m->deadline),
+ &notify_encrypted_transmit_ready,
+ n);
if (n->th == NULL)
- {
- /* message request too large or duplicate request */
- GNUNET_break (0);
- /* discard encrypted message */
- GNUNET_CONTAINER_DLL_remove (n->encrypted_head,
- n->encrypted_tail,
- m);
- GNUNET_free (m);
- process_encrypted_neighbour_queue (n);
- }
+ {
+ /* message request too large or duplicate request */
+ GNUNET_break (0);
+ /* discard encrypted message */
+ GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m);
+ GNUNET_free (m);
+ process_encrypted_neighbour_queue (n);
+ }
}
@@ -2201,41 +2133,36 @@ process_encrypted_neighbour_queue (struct Neighbour *n)
*/
static int
do_decrypt (struct Neighbour *n,
- const struct GNUNET_CRYPTO_AesInitializationVector * iv,
+ const struct GNUNET_CRYPTO_AesInitializationVector *iv,
const void *in, void *out, size_t size)
{
if (size != (uint16_t) size)
- {
- GNUNET_break (0);
- return GNUNET_NO;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
if ((n->status != PEER_STATE_KEY_RECEIVED) &&
(n->status != PEER_STATE_KEY_CONFIRMED))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
if (size !=
- GNUNET_CRYPTO_aes_decrypt (in,
- (uint16_t) size,
- &n->decrypt_key,
- iv,
- out))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# bytes decrypted"),
- size,
- GNUNET_NO);
+ GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &n->decrypt_key, iv, out))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# bytes decrypted"),
+ size, GNUNET_NO);
#if DEBUG_CORE > 1
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Decrypted %u bytes from `%4s' using key %u, IV %u\n",
- (unsigned int) size,
- GNUNET_i2s (&n->peer),
- (unsigned int) n->decrypt_key.crc32,
- GNUNET_CRYPTO_crc32_n (iv, sizeof(*iv)));
+ (unsigned int) size,
+ GNUNET_i2s (&n->peer),
+ (unsigned int) n->decrypt_key.crc32,
+ GNUNET_CRYPTO_crc32_n (iv, sizeof (*iv)));
#endif
return GNUNET_OK;
}
@@ -2270,7 +2197,7 @@ select_messages (struct Neighbour *n,
struct GNUNET_TIME_Absolute now;
struct GNUNET_TIME_Relative delta;
uint64_t avail;
- struct GNUNET_TIME_Relative slack; /* how long could we wait before missing deadlines? */
+ struct GNUNET_TIME_Relative slack; /* how long could we wait before missing deadlines? */
size_t off;
uint64_t tsize;
unsigned int queue_size;
@@ -2281,171 +2208,172 @@ select_messages (struct Neighbour *n,
/* last entry in linked list of messages processed */
last = NULL;
/* should we remove the entry with the lowest
- priority from consideration for scheduling at the
- end of the loop? */
+ * priority from consideration for scheduling at the
+ * end of the loop? */
queue_size = 0;
tsize = 0;
pos = n->messages;
while (pos != NULL)
- {
- queue_size++;
- tsize += pos->size;
- pos = pos->next;
- }
+ {
+ queue_size++;
+ tsize += pos->size;
+ pos = pos->next;
+ }
discard_low_prio = GNUNET_YES;
while (GNUNET_YES == discard_low_prio)
+ {
+ min = NULL;
+ min_prio = UINT_MAX;
+ discard_low_prio = GNUNET_NO;
+ /* calculate number of bytes available for transmission at time "t" */
+ avail = GNUNET_BANDWIDTH_tracker_get_available (&n->available_send_window);
+ t = now;
+ /* how many bytes have we (hypothetically) scheduled so far */
+ off = 0;
+ /* maximum time we can wait before transmitting anything
+ * and still make all of our deadlines */
+ slack = GNUNET_TIME_UNIT_FOREVER_REL;
+ pos = n->messages;
+ /* note that we use "*2" here because we want to look
+ * a bit further into the future; much more makes no
+ * sense since new message might be scheduled in the
+ * meantime... */
+ while ((pos != NULL) && (off < size * 2))
{
- min = NULL;
- min_prio = UINT_MAX;
- discard_low_prio = GNUNET_NO;
- /* calculate number of bytes available for transmission at time "t" */
- avail = GNUNET_BANDWIDTH_tracker_get_available (&n->available_send_window);
- t = now;
- /* how many bytes have we (hypothetically) scheduled so far */
- off = 0;
- /* maximum time we can wait before transmitting anything
- and still make all of our deadlines */
- slack = GNUNET_TIME_UNIT_FOREVER_REL;
- pos = n->messages;
- /* note that we use "*2" here because we want to look
- a bit further into the future; much more makes no
- sense since new message might be scheduled in the
- meantime... */
- while ((pos != NULL) && (off < size * 2))
- {
- if (pos->do_transmit == GNUNET_YES)
- {
- /* already removed from consideration */
- pos = pos->next;
- continue;
- }
- if (discard_low_prio == GNUNET_NO)
- {
- delta = GNUNET_TIME_absolute_get_difference (t, pos->deadline);
- if (delta.rel_value > 0)
- {
- // FIXME: HUH? Check!
- t = pos->deadline;
- avail += GNUNET_BANDWIDTH_value_get_available_until (n->bw_out,
- delta);
- }
- if (avail < pos->size)
- {
- // FIXME: HUH? Check!
- discard_low_prio = GNUNET_YES; /* we could not schedule this one! */
- }
- else
- {
- avail -= pos->size;
- /* update slack, considering both its absolute deadline
- and relative deadlines caused by other messages
- with their respective load */
- slack = GNUNET_TIME_relative_min (slack,
- GNUNET_BANDWIDTH_value_get_delay_for (n->bw_out,
- avail));
- if (pos->deadline.abs_value <= now.abs_value)
- {
- /* now or never */
- slack = GNUNET_TIME_UNIT_ZERO;
- }
- else if (GNUNET_YES == pos->got_slack)
- {
- /* should be soon now! */
- slack = GNUNET_TIME_relative_min (slack,
- GNUNET_TIME_absolute_get_remaining (pos->slack_deadline));
- }
- else
- {
- slack =
- GNUNET_TIME_relative_min (slack,
- GNUNET_TIME_absolute_get_difference (now, pos->deadline));
- pos->got_slack = GNUNET_YES;
- pos->slack_deadline = GNUNET_TIME_absolute_min (pos->deadline,
- GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY));
- }
- }
- }
- off += pos->size;
- t = GNUNET_TIME_absolute_max (pos->deadline, t); // HUH? Check!
- if (pos->priority <= min_prio)
- {
- /* update min for discard */
- min_prio = pos->priority;
- min = pos;
- }
- pos = pos->next;
+ if (pos->do_transmit == GNUNET_YES)
+ {
+ /* already removed from consideration */
+ pos = pos->next;
+ continue;
+ }
+ if (discard_low_prio == GNUNET_NO)
+ {
+ delta = GNUNET_TIME_absolute_get_difference (t, pos->deadline);
+ if (delta.rel_value > 0)
+ {
+ // FIXME: HUH? Check!
+ t = pos->deadline;
+ avail += GNUNET_BANDWIDTH_value_get_available_until (n->bw_out,
+ delta);
}
- if (discard_low_prio)
+ if (avail < pos->size)
{
- GNUNET_assert (min != NULL);
- /* remove lowest-priority entry from consideration */
- min->do_transmit = GNUNET_YES; /* means: discard (for now) */
+ // FIXME: HUH? Check!
+ discard_low_prio = GNUNET_YES; /* we could not schedule this one! */
}
- last = pos;
+ else
+ {
+ avail -= pos->size;
+ /* update slack, considering both its absolute deadline
+ * and relative deadlines caused by other messages
+ * with their respective load */
+ slack = GNUNET_TIME_relative_min (slack,
+ GNUNET_BANDWIDTH_value_get_delay_for
+ (n->bw_out, avail));
+ if (pos->deadline.abs_value <= now.abs_value)
+ {
+ /* now or never */
+ slack = GNUNET_TIME_UNIT_ZERO;
+ }
+ else if (GNUNET_YES == pos->got_slack)
+ {
+ /* should be soon now! */
+ slack = GNUNET_TIME_relative_min (slack,
+ GNUNET_TIME_absolute_get_remaining
+ (pos->slack_deadline));
+ }
+ else
+ {
+ slack =
+ GNUNET_TIME_relative_min (slack,
+ GNUNET_TIME_absolute_get_difference
+ (now, pos->deadline));
+ pos->got_slack = GNUNET_YES;
+ pos->slack_deadline = GNUNET_TIME_absolute_min (pos->deadline,
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_CONSTANTS_MAX_CORK_DELAY));
+ }
+ }
+ }
+ off += pos->size;
+ t = GNUNET_TIME_absolute_max (pos->deadline, t); // HUH? Check!
+ if (pos->priority <= min_prio)
+ {
+ /* update min for discard */
+ min_prio = pos->priority;
+ min = pos;
+ }
+ pos = pos->next;
}
+ if (discard_low_prio)
+ {
+ GNUNET_assert (min != NULL);
+ /* remove lowest-priority entry from consideration */
+ min->do_transmit = GNUNET_YES; /* means: discard (for now) */
+ }
+ last = pos;
+ }
/* guard against sending "tiny" messages with large headers without
- urgent deadlines */
- if ( (slack.rel_value > GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value) &&
- (size > 4 * off) &&
- (queue_size <= MAX_PEER_QUEUE_SIZE - 2) )
+ * urgent deadlines */
+ if ((slack.rel_value > GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value) &&
+ (size > 4 * off) && (queue_size <= MAX_PEER_QUEUE_SIZE - 2))
+ {
+ /* less than 25% of message would be filled with deadlines still
+ * being met if we delay by one second or more; so just wait for
+ * more data; but do not wait longer than 1s (since we don't want
+ * to delay messages for a really long time either). */
+ *retry_time = GNUNET_CONSTANTS_MAX_CORK_DELAY;
+ /* reset do_transmit values for next time */
+ while (pos != last)
{
- /* less than 25% of message would be filled with deadlines still
- being met if we delay by one second or more; so just wait for
- more data; but do not wait longer than 1s (since we don't want
- to delay messages for a really long time either). */
- *retry_time = GNUNET_CONSTANTS_MAX_CORK_DELAY;
- /* reset do_transmit values for next time */
- while (pos != last)
- {
- pos->do_transmit = GNUNET_NO;
- pos = pos->next;
- }
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# transmissions delayed due to corking"),
- 1, GNUNET_NO);
+ pos->do_transmit = GNUNET_NO;
+ pos = pos->next;
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop
+ ("# transmissions delayed due to corking"), 1,
+ GNUNET_NO);
#if DEBUG_CORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deferring transmission for %llums due to underfull message buffer size (%u/%u)\n",
- (unsigned long long) ret