+Fri Sep 6 00:00:00 UTC 2019
+ Remove plibc, closes #5877 as discussed in
+ https://lists.gnu.org/archive/html/gnunet-developers/2019-09/msg00002.html
+ -ng0
+
Sun Sep 1 13:25:07 2019 +0200
Improved support for external applications/services wrt
localization/gettext.
src/arm/gnunet-arm.c
src/arm/gnunet-service-arm.c
src/arm/mockup-service.c
+src/ats-tests/ats-testing-experiment.c
+src/ats-tests/ats-testing-log.c
+src/ats-tests/ats-testing-preferences.c
+src/ats-tests/ats-testing-traffic.c
+src/ats-tests/ats-testing.c
+src/ats-tests/gnunet-ats-sim.c
+src/ats-tests/gnunet-solver-eval.c
+src/ats-tool/gnunet-ats.c
src/ats/ats_api2_application.c
src/ats/ats_api2_transport.c
src/ats/ats_api_connectivity.c
src/ats/ats_api_scanner.c
src/ats/ats_api_scheduling.c
src/ats/gnunet-ats-solver-eval.c
-src/ats/gnunet-service-ats_addresses.c
+src/ats/gnunet-service-ats-new.c
src/ats/gnunet-service-ats.c
+src/ats/gnunet-service-ats_addresses.c
src/ats/gnunet-service-ats_connectivity.c
-src/ats/gnunet-service-ats-new.c
src/ats/gnunet-service-ats_normalization.c
src/ats/gnunet-service-ats_performance.c
src/ats/gnunet-service-ats_plugins.c
src/ats/plugin_ats_mlp.c
src/ats/plugin_ats_proportional.c
src/ats/plugin_ats_ril.c
-src/ats-tests/ats-testing.c
-src/ats-tests/ats-testing-experiment.c
-src/ats-tests/ats-testing-log.c
-src/ats-tests/ats-testing-preferences.c
-src/ats-tests/ats-testing-traffic.c
-src/ats-tests/gnunet-ats-sim.c
-src/ats-tests/gnunet-solver-eval.c
-src/ats-tool/gnunet-ats.c
src/auction/gnunet-auction-create.c
src/auction/gnunet-auction-info.c
src/auction/gnunet-auction-join.c
src/cadet/cadet_api_list_tunnels.c
src/cadet/cadet_test_lib.c
src/cadet/desirability_table.c
-src/cadet/gnunet-cadet.c
src/cadet/gnunet-cadet-profiler.c
+src/cadet/gnunet-cadet.c
src/cadet/gnunet-service-cadet.c
src/cadet/gnunet-service-cadet_channel.c
src/cadet/gnunet-service-cadet_connection.c
src/consensus/plugin_block_consensus.c
src/conversation/conversation_api.c
src/conversation/conversation_api_call.c
-src/conversation/gnunet-conversation.c
src/conversation/gnunet-conversation-test.c
-src/conversation/gnunet_gst.c
-src/conversation/gnunet_gst_test.c
-src/conversation/gnunet-helper-audio-playback.c
+src/conversation/gnunet-conversation.c
src/conversation/gnunet-helper-audio-playback-gst.c
-src/conversation/gnunet-helper-audio-record.c
+src/conversation/gnunet-helper-audio-playback.c
src/conversation/gnunet-helper-audio-record-gst.c
+src/conversation/gnunet-helper-audio-record.c
src/conversation/gnunet-service-conversation.c
+src/conversation/gnunet_gst.c
+src/conversation/gnunet_gst_test.c
src/conversation/microphone.c
src/conversation/plugin_gnsrecord_conversation.c
src/conversation/speaker.c
src/dht/dht_test_lib.c
src/dht/gnunet-dht-get.c
src/dht/gnunet-dht-monitor.c
-src/dht/gnunet_dht_profiler.c
src/dht/gnunet-dht-put.c
src/dht/gnunet-service-dht.c
src/dht/gnunet-service-dht_clients.c
src/dht/gnunet-service-dht_neighbours.c
src/dht/gnunet-service-dht_nse.c
src/dht/gnunet-service-dht_routing.c
+src/dht/gnunet_dht_profiler.c
src/dht/plugin_block_dht.c
src/dns/dns_api.c
src/dns/gnunet-dns-monitor.c
src/dns/gnunet-zonewalk.c
src/dns/plugin_block_dns.c
src/exit/gnunet-daemon-exit.c
-src/exit/gnunet-helper-exit.c
src/exit/gnunet-helper-exit-windows.c
+src/exit/gnunet-helper-exit.c
src/fragmentation/defragmentation.c
src/fragmentation/fragmentation.c
src/fs/fs_api.c
src/fs/gnunet-daemon-fsprofiler.c
src/fs/gnunet-directory.c
src/fs/gnunet-download.c
-src/fs/gnunet-fs.c
src/fs/gnunet-fs-profiler.c
+src/fs/gnunet-fs.c
src/fs/gnunet-helper-fs-publish.c
src/fs/gnunet-publish.c
src/fs/gnunet-search.c
src/gns/gnunet-bcd.c
src/gns/gnunet-dns2gns.c
src/gns/gnunet-gns-benchmark.c
-src/gns/gnunet-gns.c
src/gns/gnunet-gns-helper-service-w32.c
src/gns/gnunet-gns-import.c
src/gns/gnunet-gns-proxy.c
+src/gns/gnunet-gns.c
src/gns/gnunet-service-gns.c
src/gns/gnunet-service-gns_interceptor.c
src/gns/gnunet-service-gns_resolver.c
src/gns/plugin_block_gns.c
src/gns/plugin_gnsrecord_gns.c
src/gns/plugin_rest_gns.c
+src/gns/w32nsp-install.c
+src/gns/w32nsp-resolve.c
+src/gns/w32nsp-uninstall.c
+src/gns/w32nsp.c
src/gnsrecord/gnsrecord.c
src/gnsrecord/gnsrecord_crypto.c
src/gnsrecord/gnsrecord_misc.c
src/gnsrecord/gnsrecord_serialization.c
src/gnsrecord/plugin_gnsrecord_dns.c
-src/gns/w32nsp.c
-src/gns/w32nsp-install.c
-src/gns/w32nsp-resolve.c
-src/gns/w32nsp-uninstall.c
src/hello/address.c
src/hello/gnunet-hello.c
-src/hello/hello.c
src/hello/hello-ng.c
+src/hello/hello.c
src/hostlist/gnunet-daemon-hostlist.c
src/hostlist/gnunet-daemon-hostlist_client.c
src/hostlist/gnunet-daemon-hostlist_server.c
src/namecache/plugin_namecache_flat.c
src/namecache/plugin_namecache_postgres.c
src/namecache/plugin_namecache_sqlite.c
-src/namestore/gnunet-namestore.c
src/namestore/gnunet-namestore-fcfsd.c
+src/namestore/gnunet-namestore.c
src/namestore/gnunet-service-namestore.c
src/namestore/gnunet-zoneimport.c
src/namestore/namestore_api.c
src/nat-auto/gnunet-service-nat-auto_legacy.c
src/nat-auto/nat_auto_api.c
src/nat-auto/nat_auto_api_test.c
-src/nat/gnunet-helper-nat-client.c
src/nat/gnunet-helper-nat-client-windows.c
-src/nat/gnunet-helper-nat-server.c
+src/nat/gnunet-helper-nat-client.c
src/nat/gnunet-helper-nat-server-windows.c
+src/nat/gnunet-helper-nat-server.c
src/nat/gnunet-nat.c
src/nat/gnunet-service-nat.c
src/nat/gnunet-service-nat_externalip.c
src/nat/gnunet-service-nat_stun.c
src/nat/nat_api.c
src/nat/nat_api_stun.c
-src/nse/gnunet-nse.c
src/nse/gnunet-nse-profiler.c
+src/nse/gnunet-nse.c
src/nse/gnunet-service-nse.c
src/nse/nse_api.c
src/nt/nt.c
-src/peerinfo/gnunet-service-peerinfo.c
-src/peerinfo/peerinfo_api.c
-src/peerinfo/peerinfo_api_notify.c
src/peerinfo-tool/gnunet-peerinfo.c
src/peerinfo-tool/gnunet-peerinfo_plugins.c
src/peerinfo-tool/plugin_rest_peerinfo.c
+src/peerinfo/gnunet-service-peerinfo.c
+src/peerinfo/peerinfo_api.c
+src/peerinfo/peerinfo_api_notify.c
src/peerstore/gnunet-peerstore.c
src/peerstore/gnunet-service-peerstore.c
src/peerstore/peerstore_api.c
src/revocation/gnunet-service-revocation.c
src/revocation/plugin_block_revocation.c
src/revocation/revocation_api.c
-src/rps/gnunet-rps.c
src/rps/gnunet-rps-profiler.c
+src/rps/gnunet-rps.c
src/rps/gnunet-service-rps.c
src/rps/gnunet-service-rps_custommap.c
src/rps/gnunet-service-rps_sampler.c
src/rps/gnunet-service-rps_sampler_elem.c
src/rps/gnunet-service-rps_view.c
-src/rps/rps_api.c
src/rps/rps-sampler_client.c
src/rps/rps-sampler_common.c
src/rps/rps-test_util.c
+src/rps/rps_api.c
src/scalarproduct/gnunet-scalarproduct.c
-src/scalarproduct/gnunet-service-scalarproduct_alice.c
-src/scalarproduct/gnunet-service-scalarproduct_bob.c
src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
+src/scalarproduct/gnunet-service-scalarproduct_alice.c
+src/scalarproduct/gnunet-service-scalarproduct_bob.c
src/scalarproduct/scalarproduct_api.c
src/secretsharing/gnunet-secretsharing-profiler.c
src/secretsharing/gnunet-service-secretsharing.c
src/statistics/statistics_api.c
src/template/gnunet-service-template.c
src/template/gnunet-template.c
+src/testbed-logger/gnunet-service-testbed-logger.c
+src/testbed-logger/testbed_logger_api.c
src/testbed/generate-underlay-topology.c
src/testbed/gnunet-daemon-latency-logger.c
src/testbed/gnunet-daemon-testbed-blacklist.c
src/testbed/gnunet-daemon-testbed-underlay.c
src/testbed/gnunet-helper-testbed.c
-src/testbed/gnunet_mpi_test.c
src/testbed/gnunet-service-test-barriers.c
-src/testbed/gnunet-service-testbed_barriers.c
src/testbed/gnunet-service-testbed.c
+src/testbed/gnunet-service-testbed_barriers.c
src/testbed/gnunet-service-testbed_cache.c
src/testbed/gnunet-service-testbed_connectionpool.c
src/testbed/gnunet-service-testbed_cpustatus.c
src/testbed/gnunet-service-testbed_meminfo.c
src/testbed/gnunet-service-testbed_oc.c
src/testbed/gnunet-service-testbed_peers.c
-src/testbed/gnunet_testbed_mpi_spawn.c
src/testbed/gnunet-testbed-profiler.c
-src/testbed-logger/gnunet-service-testbed-logger.c
-src/testbed-logger/testbed_logger_api.c
-src/testbed/testbed_api_barriers.c
+src/testbed/gnunet_mpi_test.c
+src/testbed/gnunet_testbed_mpi_spawn.c
src/testbed/testbed_api.c
+src/testbed/testbed_api_barriers.c
src/testbed/testbed_api_hosts.c
src/testbed/testbed_api_operations.c
src/testbed/testbed_api_peers.c
src/testbed/testbed_api_sd.c
src/testbed/testbed_api_services.c
src/testbed/testbed_api_statistics.c
-src/testbed/testbed_api_testbed.c
src/testbed/testbed_api_test.c
+src/testbed/testbed_api_testbed.c
src/testbed/testbed_api_topology.c
src/testbed/testbed_api_underlay.c
src/testing/gnunet-testing.c
src/transport/gnunet-communicator-udp.c
src/transport/gnunet-communicator-unix.c
src/transport/gnunet-helper-transport-bluetooth.c
-src/transport/gnunet-helper-transport-wlan.c
src/transport/gnunet-helper-transport-wlan-dummy.c
+src/transport/gnunet-helper-transport-wlan.c
src/transport/gnunet-service-tng.c
-src/transport/gnunet-service-transport_ats.c
src/transport/gnunet-service-transport.c
+src/transport/gnunet-service-transport_ats.c
src/transport/gnunet-service-transport_hello.c
src/transport/gnunet-service-transport_manipulation.c
src/transport/gnunet-service-transport_neighbours.c
src/transport/gnunet-service-transport_plugins.c
src/transport/gnunet-service-transport_validation.c
-src/transport/gnunet-transport.c
src/transport/gnunet-transport-profiler.c
src/transport/gnunet-transport-wlan-receiver.c
src/transport/gnunet-transport-wlan-sender.c
+src/transport/gnunet-transport.c
src/transport/plugin_transport_http_client.c
src/transport/plugin_transport_http_common.c
src/transport/plugin_transport_http_server.c
src/transport/plugin_transport_smtp.c
src/transport/plugin_transport_tcp.c
src/transport/plugin_transport_template.c
-src/transport/plugin_transport_udp_broadcasting.c
src/transport/plugin_transport_udp.c
+src/transport/plugin_transport_udp_broadcasting.c
src/transport/plugin_transport_unix.c
src/transport/plugin_transport_wlan.c
src/transport/tcp_connection_legacy.c
src/transport/tcp_server_legacy.c
src/transport/tcp_server_mst_legacy.c
src/transport/tcp_service_legacy.c
+src/transport/transport-testing-filenames.c
+src/transport/transport-testing-loggers.c
+src/transport/transport-testing-main.c
+src/transport/transport-testing-send.c
+src/transport/transport-testing.c
+src/transport/transport-testing2.c
src/transport/transport_api2_application.c
src/transport/transport_api2_communication.c
src/transport/transport_api2_core.c
src/transport/transport_api_monitor_peers.c
src/transport/transport_api_monitor_plugins.c
src/transport/transport_api_offer_hello.c
-src/transport/transport-testing2.c
-src/transport/transport-testing.c
-src/transport/transport-testing-filenames.c
-src/transport/transport-testing-loggers.c
-src/transport/transport-testing-main.c
-src/transport/transport-testing-send.c
src/util/bandwidth.c
src/util/benchmark.c
src/util/bio.c
src/util/container_bloomfilter.c
src/util/container_heap.c
src/util/container_meta_data.c
-src/util/container_multihashmap32.c
src/util/container_multihashmap.c
+src/util/container_multihashmap32.c
src/util/container_multipeermap.c
src/util/container_multishortmap.c
src/util/container_multiuuidmap.c
src/util/dnsstub.c
src/util/getopt.c
src/util/getopt_helpers.c
-src/util/gnunet-config.c
src/util/gnunet-config-diff.c
+src/util/gnunet-config.c
src/util/gnunet-ecc.c
src/util/gnunet-helper-w32-console.c
src/util/gnunet-qr.c
src/util/gnunet-resolver.c
src/util/gnunet-scrypt.c
src/util/gnunet-service-resolver.c
-src/util/gnunet-timeout.c
src/util/gnunet-timeout-w32.c
+src/util/gnunet-timeout.c
src/util/gnunet-uri.c
src/util/helper.c
src/util/load.c
src/util/w32cat.c
src/util/win.c
src/util/winproc.c
-src/vpn/gnunet-helper-vpn.c
src/vpn/gnunet-helper-vpn-windows.c
+src/vpn/gnunet-helper-vpn.c
src/vpn/gnunet-service-vpn.c
src/vpn/gnunet-vpn.c
src/vpn/vpn_api.c
-src/zonemaster/gnunet-service-zonemaster.c
src/zonemaster/gnunet-service-zonemaster-monitor.c
+src/zonemaster/gnunet-service-zonemaster.c
src/fs/fs_api.h
src/include/compat.h
src/include/gnunet_common.h
--- /dev/null
+-- Tests for gnunet-arm
+
+syntax(2)
+
+-- name of the test suite
+test_suite('arm')
+
+-- test programs
+atf_test_program{name='atf_tests.sh'}
"Will attempt to remove configuration file %s and service directory %s\n",
config_file,
dir);
- if (0 != UNLINK (config_file))
+ if (0 != unlink (config_file))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_ ("Failed to remove configuration file %s\n"),
op = NULL;
if (GNUNET_ARM_REQUEST_SENT_OK != rs)
{
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Failed to start the ARM service: %s\n"),
req_string (rs));
GNUNET_SCHEDULER_shutdown ();
if ((GNUNET_ARM_RESULT_STARTING != result) &&
(GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
{
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Failed to start the ARM service: %s\n"),
ret_string (result));
GNUNET_SCHEDULER_shutdown ();
"%s",
_ (
"Failed to send a stop request to the ARM service: %s\n"));
- FPRINTF (stdout, msg, req_string (rs));
+ fprintf (stdout, msg, req_string (rs));
GNUNET_free (msg);
GNUNET_SCHEDULER_shutdown ();
return;
(GNUNET_ARM_RESULT_STOPPED != result) &&
(GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
{
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Failed to stop the ARM service: %s\n"),
ret_string (result));
GNUNET_SCHEDULER_shutdown ();
op = NULL;
if (GNUNET_ARM_REQUEST_SENT_OK != rs)
{
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Failed to send a request to start the `%s' service: %s\n"),
init,
req_string (rs));
if ((GNUNET_ARM_RESULT_STARTING != result) &&
(GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
{
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Failed to start the `%s' service: %s\n"),
init,
ret_string (result));
_ (
"Failed to send a request to kill the `%s' service: %%s\n"),
term);
- FPRINTF (stdout, msg, req_string (rs));
+ fprintf (stdout, msg, req_string (rs));
GNUNET_free (msg);
GNUNET_SCHEDULER_shutdown ();
return;
if ((GNUNET_ARM_RESULT_STOPPED != result) &&
(GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
{
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Failed to kill the `%s' service: %s\n"),
term,
ret_string (result));
GNUNET_asprintf (&msg,
"%s",
_ ("Failed to request a list of services: %s\n"));
- FPRINTF (stdout, msg, req_string (rs));
+ fprintf (stdout, msg, req_string (rs));
GNUNET_free (msg);
ret = 3;
GNUNET_SCHEDULER_shutdown ();
}
if (NULL == list)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
_ ("Error communicating with ARM. ARM not running?\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
if (! quiet)
- FPRINTF (stdout, "%s", _ ("Running services:\n"));
+ fprintf (stdout, "%s", _ ("Running services:\n"));
for (unsigned int i = 0; i < count; i++)
- FPRINTF (stdout, "%s\n", list[i]);
+ fprintf (stdout, "%s\n", list[i]);
al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
if (! quiet)
{
if (NULL != msg)
- FPRINTF (stderr, msg, service);
+ fprintf (stderr, msg, service);
else
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Unknown status %u for service %s.\n"),
status,
service);
#include "gnunet_protocols.h"
#include "arm.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
+#define LOG_strerror(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util", syscall)
#if HAVE_WAIT4
* Task doing the accepting.
*/
struct GNUNET_SCHEDULER_Task *accept_task;
-
};
*/
static int
get_server_addresses (const char *service_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct sockaddr ***addrs,
- socklen_t ** addr_lens)
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct sockaddr ***addrs,
+ socklen_t **addr_lens)
{
int disablev6;
struct GNUNET_NETWORK_Handle *desc;
*addrs = NULL;
*addr_lens = NULL;
desc = NULL;
- if (GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "DISABLEV6"))
+ if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
{
if (GNUNET_SYSERR ==
- (disablev6 =
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- service_name,
- "DISABLEV6")))
+ (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ service_name,
+ "DISABLEV6")))
return GNUNET_SYSERR;
}
else
if (! disablev6)
{
/* probe IPv6 support */
- desc = GNUNET_NETWORK_socket_create (PF_INET6,
- SOCK_STREAM,
- 0);
+ desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
if (NULL == desc)
{
- if ( (ENOBUFS == errno) ||
- (ENOMEM == errno) ||
- (ENFILE == errno) ||
- (EACCES == errno) )
+ if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
+ (EACCES == errno))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "socket");
+ LOG_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
+ _ (
+ "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
service_name,
- STRERROR (errno));
+ strerror (errno));
disablev6 = GNUNET_YES;
}
else
}
port = 0;
- if (GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "PORT"))
+ if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- service_name,
- "PORT",
- &port))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ service_name,
+ "PORT",
+ &port))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
}
if (port > 65535)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
return GNUNET_SYSERR;
}
}
- if (GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "BINDTO"))
+ if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
{
GNUNET_break (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg,
- service_name,
+ service_name,
"BINDTO",
- &hostname));
+ &hostname));
}
else
hostname = NULL;
abstract = GNUNET_NO;
#ifdef AF_UNIX
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "UNIXPATH")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- service_name,
- "UNIXPATH",
- &unixpath)) &&
+ GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
+ service_name,
+ "UNIXPATH",
+ &unixpath)) &&
(0 < strlen (unixpath)))
{
/* probe UNIX support */
if (strlen (unixpath) >= sizeof (s_un.sun_path))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("UNIXPATH `%s' too long, maximum length is %llu\n"),
- unixpath,
+ _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
+ unixpath,
(unsigned long long) sizeof (s_un.sun_path));
unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Using `%s' instead\n"),
- unixpath);
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
}
#ifdef LINUX
abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
if (GNUNET_SYSERR == abstract)
abstract = GNUNET_NO;
#endif
- if ( (GNUNET_YES != abstract) &&
- (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (unixpath)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "mkdir",
- unixpath);
+ if ((GNUNET_YES != abstract) &&
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
}
if (NULL != unixpath)
{
desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
if (NULL == desc)
{
- if ( (ENOBUFS == errno) ||
- (ENOMEM == errno) ||
- (ENFILE == errno) ||
- (EACCES == errno) )
+ if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
+ (EACCES == errno))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
+ LOG_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
GNUNET_free_non_null (hostname);
GNUNET_free (unixpath);
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
+ _ (
+ "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
service_name,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (unixpath);
unixpath = NULL;
}
}
#endif
- if ( (0 == port) &&
- (NULL == unixpath) )
+ if ((0 == port) && (NULL == unixpath))
{
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- service_name,
- "START_ON_DEMAND"))
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ service_name,
+ "START_ON_DEMAND"))
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
- service_name);
+ _ (
+ "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
+ service_name);
GNUNET_free_non_null (hostname);
return GNUNET_SYSERR;
}
if (0 == port)
{
- saddrs = GNUNET_new_array (2,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (2,
- socklen_t);
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ saddrs = GNUNET_new_array (2, struct sockaddr *);
+ saddrlens = GNUNET_new_array (2, socklen_t);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
GNUNET_free_non_null (unixpath);
GNUNET_free_non_null (hostname);
*addrs = saddrs;
if (disablev6)
hints.ai_family = AF_INET;
hints.ai_protocol = IPPROTO_TCP;
- if ((0 != (ret = getaddrinfo (hostname,
- NULL,
- &hints,
- &res))) ||
+ if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
(NULL == res))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to resolve `%s': %s\n"),
+ _ ("Failed to resolve `%s': %s\n"),
hostname,
gai_strerror (ret));
GNUNET_free (hostname);
if (0 == i)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to find %saddress for `%s'.\n"),
+ _ ("Failed to find %saddress for `%s'.\n"),
disablev6 ? "IPv4 " : "",
hostname);
freeaddrinfo (res);
resi = i;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1, socklen_t);
i = 0;
if (NULL != unixpath)
{
if ((disablev6) && (AF_INET6 == pos->ai_family))
continue;
if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
- continue; /* not TCP */
+ continue; /* not TCP */
if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
- continue; /* huh? */
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
- service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
+ continue; /* huh? */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' will bind to `%s'\n",
+ service_name,
+ GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
if (AF_INET == pos->ai_family)
{
GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
if (NULL != unixpath)
resi++;
i = 0;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1, socklen_t);
if (NULL != unixpath)
{
add_unixpath (saddrs, saddrlens, unixpath, abstract);
resi = 2;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1, socklen_t);
i = 0;
if (NULL != unixpath)
{
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in6);
*/
static void
signal_result (struct GNUNET_SERVICE_Client *client,
- const char *name,
- uint64_t request_id,
- enum GNUNET_ARM_Result result)
+ const char *name,
+ uint64_t request_id,
+ enum GNUNET_ARM_Result result)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_ARM_ResultMessage *msg;
(void) name;
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_ARM_RESULT);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_RESULT);
msg->result = htonl (result);
msg->arm_msg.request_id = GNUNET_htonll (request_id);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
}
*/
static void
broadcast_status (const char *name,
- enum GNUNET_ARM_ServiceStatus status,
- struct GNUNET_SERVICE_Client *unicast)
+ enum GNUNET_ARM_ServiceStatus status,
+ struct GNUNET_SERVICE_Client *unicast)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_ARM_StatusMessage *msg;
(unsigned int) status,
name);
namelen = strlen (name) + 1;
- env = GNUNET_MQ_msg_extra (msg,
- namelen,
- GNUNET_MESSAGE_TYPE_ARM_STATUS);
+ env = GNUNET_MQ_msg_extra (msg, namelen, GNUNET_MESSAGE_TYPE_ARM_STATUS);
msg->status = htonl ((uint32_t) (status));
- GNUNET_memcpy ((char *) &msg[1],
- name,
- namelen);
+ GNUNET_memcpy ((char *) &msg[1], name, namelen);
if (NULL == unicast)
{
if (NULL != notifier)
}
else
{
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (unicast),
- env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (unicast), env);
}
}
lsocks = NULL;
ls = 0;
for (sli = sl->listen_head; NULL != sli; sli = sli->next)
+ {
+ GNUNET_array_append (lsocks,
+ ls,
+ GNUNET_NETWORK_get_fd (sli->listen_socket));
+ if (NULL != sli->accept_task)
{
- GNUNET_array_append (lsocks, ls,
- GNUNET_NETWORK_get_fd (sli->listen_socket));
- if (NULL != sli->accept_task)
- {
- GNUNET_SCHEDULER_cancel (sli->accept_task);
- sli->accept_task = NULL;
- }
+ GNUNET_SCHEDULER_cancel (sli->accept_task);
+ sli->accept_task = NULL;
}
+ }
#if WINDOWS
- GNUNET_array_append (lsocks,
- ls,
- INVALID_SOCKET);
+ GNUNET_array_append (lsocks, ls, INVALID_SOCKET);
#else
- GNUNET_array_append (lsocks,
- ls,
- -1);
+ GNUNET_array_append (lsocks, ls, -1);
#endif
/* obtain configuration */
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- sl->name,
- "PREFIX",
- &loprefix))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ sl->name,
+ "PREFIX",
+ &loprefix))
loprefix = GNUNET_strdup (prefix_command);
else
- loprefix = GNUNET_CONFIGURATION_expand_dollar (cfg,
- loprefix);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- sl->name,
- "OPTIONS",
- &options))
+ loprefix = GNUNET_CONFIGURATION_expand_dollar (cfg, loprefix);
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ sl->name,
+ "OPTIONS",
+ &options))
options = NULL;
else
- options = GNUNET_CONFIGURATION_expand_dollar (cfg,
- options);
+ options = GNUNET_CONFIGURATION_expand_dollar (cfg, options);
{
char *new_options;
char *optpos;
fin_options = GNUNET_strdup (final_option);
/* replace '{}' with service name */
- while (NULL != (optpos = strstr (fin_options,
- "{}")))
+ while (NULL != (optpos = strstr (fin_options, "{}")))
{
/* terminate string at opening parenthesis */
*optpos = 0;
{
/* combine "fin_options" with "options" */
optpos = options;
- GNUNET_asprintf (&options,
- "%s %s",
- fin_options,
- optpos);
+ GNUNET_asprintf (&options, "%s %s", fin_options, optpos);
GNUNET_free (fin_options);
GNUNET_free (optpos);
}
options = fin_options;
}
}
- options = GNUNET_CONFIGURATION_expand_dollar (cfg,
- options);
- use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- sl->name,
- "DEBUG");
+ options = GNUNET_CONFIGURATION_expand_dollar (cfg, options);
+ use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG");
{
const char *service_type = NULL;
- const char *choices[] = { "GNUNET", "SIMPLE", NULL };
+ const char *choices[] = {"GNUNET", "SIMPLE", NULL};
is_simple_service = GNUNET_NO;
- if ( (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_choice (cfg,
- sl->name,
- "TYPE",
- choices,
- &service_type)) &&
- (0 == strcasecmp (service_type, "SIMPLE")) )
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_choice (cfg,
+ sl->name,
+ "TYPE",
+ choices,
+ &service_type)) &&
+ (0 == strcasecmp (service_type, "SIMPLE")))
is_simple_service = GNUNET_YES;
}
command line options. */
binary = GNUNET_strdup (sl->binary);
binary = GNUNET_CONFIGURATION_expand_dollar (cfg, binary);
- GNUNET_asprintf ("edbinary,
- "\"%s\"",
- sl->binary);
+ GNUNET_asprintf ("edbinary, "\"%s\"", sl->binary);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting simple service `%s' using binary `%s'\n",
- sl->name, sl->binary);
+ sl->name,
+ sl->binary);
/* FIXME: dollar expansion should only be done outside
* of ''-quoted strings, escaping should be considered. */
if (NULL != options)
options = GNUNET_CONFIGURATION_expand_dollar (cfg, options);
- sl->proc =
- GNUNET_OS_start_process_s (sl->pipe_control,
- GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- lsocks,
- loprefix,
- quotedbinary,
- options,
- NULL);
+ sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
+ GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+ lsocks,
+ loprefix,
+ quotedbinary,
+ options,
+ NULL);
}
else
{
/* actually start process */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting service `%s' using binary `%s' and configuration `%s'\n",
- sl->name, sl->binary, sl->config);
+ sl->name,
+ sl->binary,
+ sl->config);
binary = GNUNET_OS_get_libexec_binary_path (sl->binary);
- GNUNET_asprintf ("edbinary,
- "\"%s\"",
- binary);
+ GNUNET_asprintf ("edbinary, "\"%s\"", binary);
if (GNUNET_YES == use_debug)
{
if (NULL == sl->config)
- sl->proc =
- GNUNET_OS_start_process_s (sl->pipe_control,
- GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- lsocks,
- loprefix,
- quotedbinary,
- "-L", "DEBUG",
- options,
- NULL);
+ sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
+ GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+ lsocks,
+ loprefix,
+ quotedbinary,
+ "-L",
+ "DEBUG",
+ options,
+ NULL);
else
- sl->proc =
- GNUNET_OS_start_process_s (sl->pipe_control,
- GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- lsocks,
- loprefix,
- quotedbinary,
- "-c", sl->config,
- "-L", "DEBUG",
- options,
- NULL);
+ sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
+ GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+ lsocks,
+ loprefix,
+ quotedbinary,
+ "-c",
+ sl->config,
+ "-L",
+ "DEBUG",
+ options,
+ NULL);
}
else
{
if (NULL == sl->config)
- sl->proc =
- GNUNET_OS_start_process_s (sl->pipe_control,
- GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- lsocks,
- loprefix,
- quotedbinary,
- options,
- NULL);
+ sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
+ GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+ lsocks,
+ loprefix,
+ quotedbinary,
+ options,
+ NULL);
else
- sl->proc =
- GNUNET_OS_start_process_s (sl->pipe_control,
- GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- lsocks,
- loprefix,
- quotedbinary,
- "-c", sl->config,
- options,
- NULL);
+ sl->proc = GNUNET_OS_start_process_s (sl->pipe_control,
+ GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+ lsocks,
+ loprefix,
+ quotedbinary,
+ "-c",
+ sl->config,
+ options,
+ NULL);
}
}
GNUNET_free (binary);
if (NULL == sl->proc)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to start service `%s'\n"),
- sl->name);
+ _ ("Failed to start service `%s'\n"),
+ sl->name);
if (client)
signal_result (client,
sl->name,
else
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Starting service `%s'\n"),
- sl->name);
- broadcast_status (sl->name,
- GNUNET_ARM_SERVICE_STARTING,
- NULL);
+ _ ("Starting service `%s'\n"),
+ sl->name);
+ broadcast_status (sl->name, GNUNET_ARM_SERVICE_STARTING, NULL);
if (client)
- signal_result (client,
- sl->name,
- request_id,
- GNUNET_ARM_RESULT_STARTING);
+ signal_result (client, sl->name, request_id, GNUNET_ARM_RESULT_STARTING);
}
/* clean up */
GNUNET_free (loprefix);
GNUNET_free (options);
- GNUNET_array_grow (lsocks,
- ls,
- 0);
+ GNUNET_array_grow (lsocks, ls, 0);
}
sl = running_head;
while (sl != NULL)
- {
- if (0 == strcasecmp (sl->name, name))
- return sl;
- sl = sl->next;
- }
+ {
+ if (0 == strcasecmp (sl->name, name))
+ return sl;
+ sl = sl->next;
+ }
return NULL;
}
static void
create_listen_socket (struct sockaddr *sa,
socklen_t addr_len,
- struct ServiceList *sl)
+ struct ServiceList *sl)
{
static int on = 1;
struct GNUNET_NETWORK_Handle *sock;
switch (sa->sa_family)
{
case AF_INET:
- sock = GNUNET_NETWORK_socket_create (PF_INET,
- SOCK_STREAM,
- 0);
+ sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
break;
case AF_INET6:
- sock = GNUNET_NETWORK_socket_create (PF_INET6,
- SOCK_STREAM,
- 0);
+ sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
break;
case AF_UNIX:
- if (0 == strcmp (GNUNET_a2s (sa,
- addr_len),
- "@")) /* Do not bind to blank UNIX path! */
+ if (0 == strcmp (GNUNET_a2s (sa, addr_len),
+ "@")) /* Do not bind to blank UNIX path! */
return;
- sock = GNUNET_NETWORK_socket_create (PF_UNIX,
- SOCK_STREAM,
- 0);
+ sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
break;
default:
GNUNET_break (0);
if (NULL == sock)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to create socket for service `%s': %s\n"),
+ _ ("Unable to create socket for service `%s': %s\n"),
sl->name,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (sa);
return;
}
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_setsockopt (sock,
- SOL_SOCKET,
- SO_REUSEADDR,
- &on,
- sizeof (on)))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (sock,
+ SOL_SOCKET,
+ SO_REUSEADDR,
+ &on,
+ sizeof (on)))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ "setsockopt");
#ifdef IPV6_V6ONLY
- if ( (sa->sa_family == AF_INET6) &&
- (GNUNET_OK !=
- GNUNET_NETWORK_socket_setsockopt (sock,
- IPPROTO_IPV6,
- IPV6_V6ONLY,
- &on,
- sizeof (on))) )
+ if ((sa->sa_family == AF_INET6) &&
+ (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (sock,
+ IPPROTO_IPV6,
+ IPV6_V6ONLY,
+ &on,
+ sizeof (on))))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "setsockopt");
+ "setsockopt");
#endif
#ifndef WINDOWS
if (AF_UNIX == sa->sa_family)
GNUNET_NETWORK_unix_precheck ((struct sockaddr_un *) sa);
#endif
if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (sock,
- (const struct sockaddr *) sa,
- addr_len))
+ GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) sa, addr_len))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Unable to bind listening socket for service `%s' to address `%s': %s\n"),
- sl->name,
- GNUNET_a2s (sa,
- addr_len),
- STRERROR (errno));
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Unable to bind listening socket for service `%s' to address `%s': %s\n"),
+ sl->name,
+ GNUNET_a2s (sa, addr_len),
+ strerror (errno));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
GNUNET_free (sa);
return;
}
if ((AF_UNIX == sa->sa_family)
#ifdef LINUX
/* Permission settings are not required when abstract sockets are used */
- && ('\0' != ((const struct sockaddr_un *)sa)->sun_path[0])
+ && ('\0' != ((const struct sockaddr_un *) sa)->sun_path[0])
#endif
- )
+ )
{
match_uid =
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- sl->name,
- "UNIX_MATCH_UID");
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "UNIX_MATCH_UID");
match_gid =
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- sl->name,
- "UNIX_MATCH_GID");
- GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sa)->sun_path,
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "UNIX_MATCH_GID");
+ GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) sa)->sun_path,
match_uid,
match_gid);
-
}
#endif
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_listen (sock, 5))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "listen");
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ 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"),
- sl->name,
- GNUNET_a2s (sa,
- addr_len));
+ _ ("ARM now monitors connections to service `%s' at `%s'\n"),
+ sl->name,
+ GNUNET_a2s (sa, addr_len));
sli = GNUNET_new (struct ServiceListeningInfo);
sli->service_addr = sa;
sli->service_addr_len = addr_len;
sli->listen_socket = sock;
sli->sl = sl;
- sli->accept_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- sock,
- &accept_connection, sli);
- GNUNET_CONTAINER_DLL_insert (sl->listen_head,
- sl->listen_tail,
- sli);
+ sli->accept_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ sock,
+ &accept_connection,
+ sli);
+ GNUNET_CONTAINER_DLL_insert (sl->listen_head, sl->listen_tail, sli);
}
free_service (struct ServiceList *sl)
{
GNUNET_assert (GNUNET_YES == in_shutdown);
- GNUNET_CONTAINER_DLL_remove (running_head,
- running_tail,
- sl);
+ GNUNET_CONTAINER_DLL_remove (running_head, running_tail, sl);
GNUNET_assert (NULL == sl->listen_head);
GNUNET_free_non_null (sl->config);
GNUNET_free_non_null (sl->binary);
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
-check_start (void *cls,
- const struct GNUNET_ARM_Message *amsg)
+check_start (void *cls, const struct GNUNET_ARM_Message *amsg)
{
(void) cls;
GNUNET_MQ_check_zero_termination (amsg);
* @param amsg the actual message
*/
static void
-handle_start (void *cls,
- const struct GNUNET_ARM_Message *amsg)
+handle_start (void *cls, const struct GNUNET_ARM_Message *amsg)
{
struct GNUNET_SERVICE_Client *client = cls;
const char *servicename;
signal_result (client,
servicename,
request_id,
- GNUNET_ARM_RESULT_IN_SHUTDOWN);
+ GNUNET_ARM_RESULT_IN_SHUTDOWN);
return;
}
sl = find_service (servicename);
signal_result (client,
servicename,
request_id,
- GNUNET_ARM_RESULT_IS_NOT_KNOWN);
+ GNUNET_ARM_RESULT_IS_NOT_KNOWN);
return;
}
sl->force_start = GNUNET_YES;
signal_result (client,
servicename,
request_id,
- GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
+ GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
return;
}
- start_process (sl,
- client,
- request_id);
+ start_process (sl, client, request_id);
}
trigger_shutdown (void *cls)
{
(void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Triggering shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Triggering shutdown\n");
GNUNET_SCHEDULER_shutdown ();
}
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
-check_stop (void *cls,
- const struct GNUNET_ARM_Message *amsg)
+check_stop (void *cls, const struct GNUNET_ARM_Message *amsg)
{
(void) cls;
GNUNET_MQ_check_zero_termination (amsg);
* @param amsg the actual message
*/
static void
-handle_stop (void *cls,
- const struct GNUNET_ARM_Message *amsg)
+handle_stop (void *cls, const struct GNUNET_ARM_Message *amsg)
{
struct GNUNET_SERVICE_Client *client = cls;
struct ServiceList *sl;
request_id = GNUNET_ntohll (amsg->request_id);
servicename = (const char *) &amsg[1];
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Preparing to stop `%s'\n"),
- servicename);
+ _ ("Preparing to stop `%s'\n"),
+ servicename);
GNUNET_SERVICE_client_continue (client);
- if (0 == strcasecmp (servicename,
- "arm"))
+ if (0 == strcasecmp (servicename, "arm"))
{
- broadcast_status (servicename,
- GNUNET_ARM_SERVICE_STOPPING,
- NULL);
- signal_result (client,
- servicename,
- request_id,
- GNUNET_ARM_RESULT_STOPPING);
+ broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
+ signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_STOPPING);
GNUNET_SERVICE_client_persist (client);
- GNUNET_SCHEDULER_add_now (&trigger_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_now (&trigger_shutdown, NULL);
return;
}
sl = find_service (servicename);
{
/* killing already in progress */
signal_result (client,
- servicename,
- request_id,
- GNUNET_ARM_RESULT_IS_STOPPING_ALREADY);
+ servicename,
+ request_id,
+ GNUNET_ARM_RESULT_IS_STOPPING_ALREADY);
return;
}
if (NULL == sl->proc)
{
/* process is down */
signal_result (client,
- servicename,
- request_id,
- GNUNET_ARM_RESULT_IS_STOPPED_ALREADY);
+ servicename,
+ request_id,
+ GNUNET_ARM_RESULT_IS_STOPPED_ALREADY);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending kill signal to service `%s', waiting for process to die.\n",
- servicename);
- broadcast_status (servicename,
- GNUNET_ARM_SERVICE_STOPPING,
- NULL);
+ "Sending kill signal to service `%s', waiting for process to die.\n",
+ servicename);
+ broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
/* no signal_start - only when it's STOPPED */
sl->killed_at = GNUNET_TIME_absolute_get ();
- if (0 != GNUNET_OS_process_kill (sl->proc,
- GNUNET_TERM_SIG))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "kill");
+ if (0 != GNUNET_OS_process_kill (sl->proc, GNUNET_TERM_SIG))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
sl->killing_client = client;
sl->killing_client_request_id = request_id;
}
* @param message the actual message
*/
static void
-handle_list (void *cls,
- const struct GNUNET_ARM_Message *request)
+handle_list (void *cls, const struct GNUNET_ARM_Message *request)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_MQ_Envelope *env;
if (NULL != sl->proc)
{
size_t s = strlen (sl->name) + strlen (sl->binary) + 4;
- GNUNET_snprintf (pos,
- s,
- "%s (%s)",
- sl->name,
- sl->binary);
+ GNUNET_snprintf (pos, s, "%s (%s)", sl->name, sl->binary);
pos += s;
}
}
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
GNUNET_SERVICE_client_continue (client);
}
* @param message the actual message
*/
static void
-handle_test (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_test (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
(void) message;
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_ARM_TEST);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_TEST);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
GNUNET_SERVICE_client_continue (client);
}
static void
do_shutdown ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Last shutdown phase\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Last shutdown phase\n");
if (NULL != notifier)
{
GNUNET_notification_context_destroy (notifier);
unsigned int res;
for (res = 0, i = running_head; NULL != i; i = i->next, res++)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s\n",
- i->name);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s\n", i->name);
return res;
}
struct ServiceListeningInfo *sli;
(void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "First shutdown phase\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First shutdown phase\n");
if (NULL != child_restart_task)
{
GNUNET_SCHEDULER_cancel (child_restart_task);
{
while (NULL != (sli = pos->listen_head))
{
- GNUNET_CONTAINER_DLL_remove (pos->listen_head,
- pos->listen_tail,
- sli);
+ GNUNET_CONTAINER_DLL_remove (pos->listen_head, pos->listen_tail, sli);
if (NULL != sli->accept_task)
{
GNUNET_SCHEDULER_cancel (sli->accept_task);
nxt = pos->next;
if (NULL != pos->proc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Stopping service `%s'\n",
- pos->name);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n", pos->name);
pos->killed_at = GNUNET_TIME_absolute_get ();
- if (0 != GNUNET_OS_process_kill (pos->proc,
- GNUNET_TERM_SIG))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "kill");
+ if (0 != GNUNET_OS_process_kill (pos->proc, GNUNET_TERM_SIG))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
}
else
{
do_shutdown ();
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delaying shutdown, have %u childs still running\n",
- list_count (running_head));
+ "Delaying shutdown, have %u childs still running\n",
+ list_count (running_head));
}
/* restart is now allowed */
if (sl->force_start)
{
- /* process should run by default, start immediately */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Restarting service `%s'.\n"),
+ /* process should run by default, start immediately */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _ ("Restarting service `%s'.\n"),
sl->name);
- start_process (sl,
- NULL,
- 0);
+ start_process (sl, NULL, 0);
}
else
{
- /* process is run on-demand, ensure it is re-started if there is demand */
- for (sli = sl->listen_head; NULL != sli; sli = sli->next)
- if (NULL == sli->accept_task)
- {
- /* accept was actually paused, so start it again */
- sli->accept_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- sli->listen_socket,
- &accept_connection,
- sli);
- }
+ /* process is run on-demand, ensure it is re-started if there is demand */
+ for (sli = sl->listen_head; NULL != sli; sli = sli->next)
+ if (NULL == sli->accept_task)
+ {
+ /* accept was actually paused, so start it again */
+ sli->accept_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ sli->listen_socket,
+ &accept_connection,
+ sli);
+ }
}
}
else
{
/* update calculation for earliest time to reactivate a service */
lowestRestartDelay =
- GNUNET_TIME_relative_min (lowestRestartDelay,
- GNUNET_TIME_absolute_get_remaining
- (sl->restart_at));
+ GNUNET_TIME_relative_min (lowestRestartDelay,
+ GNUNET_TIME_absolute_get_remaining (
+ sl->restart_at));
}
}
- if (lowestRestartDelay.rel_value_us != GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
+ if (lowestRestartDelay.rel_value_us !=
+ GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Will restart process in %s\n",
- GNUNET_STRINGS_relative_time_to_string (lowestRestartDelay,
+ "Will restart process in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (lowestRestartDelay,
GNUNET_YES));
child_restart_task =
GNUNET_SCHEDULER_add_delayed_with_priority (lowestRestartDelay,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delayed_restart_task,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delayed_restart_task,
NULL);
}
}
const struct GNUNET_DISK_FileHandle *pr;
(void) cls;
- pr = GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_READ);
+ pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
child_death_task = NULL;
/* consume the signal */
- GNUNET_break (0 < GNUNET_DISK_file_read (pr,
- &c,
- sizeof (c)));
+ GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
/* check for services that died (WAITPID) */
next = running_head;
pid_t pid;
pid = GNUNET_OS_process_get_pid (pos->proc);
- ret = wait4 (pid,
- &status,
- WNOHANG,
- &ru);
+ ret = wait4 (pid, &status, WNOHANG, &ru);
if (ret <= 0)
continue; /* no process done */
if (WIFEXITED (status))
statusType = GNUNET_OS_PROCESS_UNKNOWN;
statusCode = 0;
}
- if ( (GNUNET_OS_PROCESS_EXITED == statusType) ||
- (GNUNET_OS_PROCESS_SIGNALED == statusType) )
+ if ((GNUNET_OS_PROCESS_EXITED == statusType) ||
+ (GNUNET_OS_PROCESS_SIGNALED == statusType))
{
double utime = ru.ru_utime.tv_sec + (ru.ru_utime.tv_usec / 10e6);
double stime = ru.ru_stime.tv_sec + (ru.ru_stime.tv_usec / 10e6);
}
else /* continue with JUST this "if" as "else" (intentionally no brackets!) */
#endif
- if ( (GNUNET_SYSERR ==
- (ret =
- GNUNET_OS_process_status (pos->proc,
- &statusType,
- &statusCode))) ||
- (ret == GNUNET_NO) ||
- (statusType == GNUNET_OS_PROCESS_STOPPED) ||
- (statusType == GNUNET_OS_PROCESS_UNKNOWN) ||
- (statusType == GNUNET_OS_PROCESS_RUNNING) )
+ if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
+ &statusType,
+ &statusCode))) ||
+ (ret == GNUNET_NO) || (statusType == GNUNET_OS_PROCESS_STOPPED) ||
+ (statusType == GNUNET_OS_PROCESS_UNKNOWN) ||
+ (statusType == GNUNET_OS_PROCESS_RUNNING))
continue;
if (statusType == GNUNET_OS_PROCESS_EXITED)
{
- statstr = _( /* process termination method */ "exit");
+ statstr = _ (/* process termination method */ "exit");
statcode = statusCode;
}
else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
{
- statstr = _( /* process termination method */ "signal");
+ statstr = _ (/* process termination method */ "signal");
statcode = statusCode;
}
else
{
- statstr = _( /* process termination method */ "unknown");
+ statstr = _ (/* process termination method */ "unknown");
statcode = 0;
}
if (0 != pos->killed_at.abs_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' took %s to terminate\n"),
+ _ ("Service `%s' took %s to terminate\n"),
pos->name,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->killed_at),
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_duration (pos->killed_at),
+ GNUNET_YES));
}
GNUNET_OS_process_destroy (pos->proc);
pos->proc = NULL;
- broadcast_status (pos->name,
- GNUNET_ARM_SERVICE_STOPPED,
- NULL);
+ broadcast_status (pos->name, GNUNET_ARM_SERVICE_STOPPED, NULL);
if (NULL != pos->killing_client)
{
- signal_result (pos->killing_client, pos->name,
+ signal_result (pos->killing_client,
+ pos->name,
pos->killing_client_request_id,
GNUNET_ARM_RESULT_STOPPED);
pos->killing_client = NULL;
}
if (GNUNET_YES != in_shutdown)
{
- if ( (statusType == GNUNET_OS_PROCESS_EXITED) &&
- (statcode == 0) )
+ if ((statusType == GNUNET_OS_PROCESS_EXITED) && (statcode == 0))
{
/* process terminated normally, allow restart at any time */
pos->restart_at.abs_value_us = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' terminated normally, will restart at any time\n"),
- pos->name);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ ("Service `%s' terminated normally, will restart at any time\n"),
+ pos->name);
/* process can still be re-started on-demand, ensure it is re-started if there is demand */
for (sli = pos->listen_head; NULL != sli; sli = sli->next)
{
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' terminated with status %s/%d, will restart in %s\n"),
- pos->name,
- statstr,
- statcode,
- GNUNET_STRINGS_relative_time_to_string (pos->backoff,
- GNUNET_YES));
- {
- /* Reduce backoff based on runtime of the process,
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ ("Service `%s' terminated with status %s/%d, will restart in %s\n"),
+ pos->name,
+ statstr,
+ statcode,
+ GNUNET_STRINGS_relative_time_to_string (pos->backoff, GNUNET_YES));
+ {
+ /* Reduce backoff based on runtime of the process,
so that there is a cool-down if a process actually
runs for a while. */
- struct GNUNET_TIME_Relative runtime;
- unsigned int minutes;
-
- runtime = GNUNET_TIME_absolute_get_duration (pos->restart_at);
- minutes = runtime.rel_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us;
- if (minutes > 31)
- pos->backoff = GNUNET_TIME_UNIT_ZERO;
- else
- pos->backoff.rel_value_us <<= minutes;
- }
- /* schedule restart */
+ struct GNUNET_TIME_Relative runtime;
+ unsigned int minutes;
+
+ runtime = GNUNET_TIME_absolute_get_duration (pos->restart_at);
+ minutes =
+ runtime.rel_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us;
+ if (minutes > 31)
+ pos->backoff = GNUNET_TIME_UNIT_ZERO;
+ else
+ pos->backoff.rel_value_us <<= minutes;
+ }
+ /* schedule restart */
pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff);
pos->backoff = GNUNET_TIME_STD_BACKOFF (pos->backoff);
if (NULL != 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);
+ child_restart_task =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delayed_restart_task,
+ NULL);
}
}
else
free_service (pos);
}
}
- child_death_task = GNUNET_SCHEDULER_add_read_file (
- GNUNET_TIME_UNIT_FOREVER_REL,
- pr,
- &maint_child_death, NULL);
+ child_death_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ pr,
+ &maint_child_death,
+ NULL);
if ((NULL == running_head) && (GNUNET_YES == in_shutdown))
do_shutdown ();
else if (GNUNET_YES == in_shutdown)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delaying shutdown after child's death, still have %u children\n",
- list_count (running_head));
-
+ "Delaying shutdown after child's death, still have %u children\n",
+ list_count (running_head));
}
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 */
}
* @return #GNUNET_OK (continue)
*/
static void
-setup_service (void *cls,
- const char *section)
+setup_service (void *cls, const char *section)
{
struct ServiceList *sl;
char *binary;
int ret;
(void) cls;
- if (0 == strcasecmp (section,
- "arm"))
+ if (0 == strcasecmp (section, "arm"))
return;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- section,
- "BINARY",
- &binary))
+ GNUNET_CONFIGURATION_get_value_string (cfg, section, "BINARY", &binary))
{
/* not a service section */
return;
}
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg,
- section,
- "RUN_PER_USER")) &&
+ GNUNET_CONFIGURATION_have_value (cfg, section, "RUN_PER_USER")) &&
(GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- section,
- "RUN_PER_USER")))
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "RUN_PER_USER")))
{
if (GNUNET_NO == start_user)
{
return;
}
config = NULL;
- if (( (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- section,
- "CONFIG",
- &config)) &&
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "PATHS",
- "DEFAULTCONFIG",
- &config)) ) ||
- (0 != STAT (config, &sbuf)))
+ if (((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ section,
+ "CONFIG",
+ &config)) &&
+ (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PATHS",
+ "DEFAULTCONFIG",
+ &config))) ||
+ (0 != stat (config, &sbuf)))
{
if (NULL != config)
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
- section, "CONFIG",
- STRERROR (errno));
+ section,
+ "CONFIG",
+ strerror (errno));
GNUNET_free (config);
config = NULL;
}
#if WINDOWS
sl->pipe_control = GNUNET_YES;
#else
- if (GNUNET_CONFIGURATION_have_value (cfg,
- section,
- "PIPECONTROL"))
- sl->pipe_control = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- section,
- "PIPECONTROL");
+ if (GNUNET_CONFIGURATION_have_value (cfg, section, "PIPECONTROL"))
+ sl->pipe_control =
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "PIPECONTROL");
#endif
- GNUNET_CONTAINER_DLL_insert (running_head,
- running_tail,
- sl);
+ GNUNET_CONTAINER_DLL_insert (running_head, running_tail, sl);
if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- section,
- "IMMEDIATE_START"))
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "IMMEDIATE_START"))
{
sl->force_start = GNUNET_YES;
if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- section,
- "NOARMBIND"))
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "NOARMBIND"))
return;
}
else
{
if (GNUNET_YES !=
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- section,
- "START_ON_DEMAND"))
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "START_ON_DEMAND"))
return;
}
- if (0 >= (ret = get_server_addresses (section,
- cfg,
- &addrs,
- &addr_lens)))
+ if (0 >= (ret = get_server_addresses (section, cfg, &addrs, &addr_lens)))
return;
/* this will free (or capture) addrs[i] */
for (unsigned int i = 0; i < (unsigned int) ret; i++)
- create_listen_socket (addrs[i],
- addr_lens[i],
- sl);
+ create_listen_socket (addrs[i], addr_lens[i], sl);
GNUNET_free (addrs);
GNUNET_free (addr_lens);
}
* #GNUNET_SYSERR to close it (signal serious error)
*/
static void
-handle_monitor (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_monitor (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
/* Removal is handled by the server implementation, internally. */
GNUNET_notification_context_add (notifier,
GNUNET_SERVICE_client_get_mq (client));
- broadcast_status ("arm",
- GNUNET_ARM_SERVICE_MONITORING_STARTED,
- client);
+ broadcast_status ("arm", GNUNET_ARM_SERVICE_MONITORING_STARTED, client);
GNUNET_SERVICE_client_continue (client);
}
(void) cls;
cfg = c;
service = serv;
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
- child_death_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_READ),
- &maint_child_death,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
+ child_death_task = GNUNET_SCHEDULER_add_read_file (
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
+ &maint_child_death,
+ NULL);
#if HAVE_WAIT4
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_filename (cfg,
"RESOURCE_DIAGNOSTICS",
&wait_filename))
{
- wait_file = fopen (wait_filename,
- "w");
+ wait_file = fopen (wait_filename, "w");
if (NULL == wait_file)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
}
}
#endif
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "GLOBAL_PREFIX",
- &prefix_command))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ "ARM",
+ "GLOBAL_PREFIX",
+ &prefix_command))
prefix_command = GNUNET_strdup ("");
else
- prefix_command = GNUNET_CONFIGURATION_expand_dollar (cfg,
- prefix_command);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "GLOBAL_POSTFIX",
- &final_option))
+ prefix_command = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix_command);
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ "ARM",
+ "GLOBAL_POSTFIX",
+ &final_option))
final_option = GNUNET_strdup ("");
else
- final_option = GNUNET_CONFIGURATION_expand_dollar (cfg,
- final_option);
- start_user = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "ARM",
- "START_USER_SERVICES");
- start_system = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "ARM",
- "START_SYSTEM_SERVICES");
- if ( (GNUNET_NO == start_user) &&
- (GNUNET_NO == start_system) )
+ final_option = GNUNET_CONFIGURATION_expand_dollar (cfg, final_option);
+ start_user =
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, "ARM", "START_USER_SERVICES");
+ start_system =
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, "ARM", "START_SYSTEM_SERVICES");
+ if ((GNUNET_NO == start_user) && (GNUNET_NO == start_system))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Please configure either START_USER_SERVICES or START_SYSTEM_SERVICES or both.\n");
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ "Please configure either START_USER_SERVICES or START_SYSTEM_SERVICES or both.\n");
GNUNET_SCHEDULER_shutdown ();
global_ret = 1;
return;
}
- GNUNET_CONFIGURATION_iterate_sections (cfg,
- &setup_service,
- NULL);
+ GNUNET_CONFIGURATION_iterate_sections (cfg, &setup_service, NULL);
/* start default services... */
for (sl = running_head; NULL != sl; sl = sl->next)
if (GNUNET_YES == sl->force_start)
- start_process (sl,
- NULL,
- 0);
+ start_process (sl, NULL, 0);
notifier = GNUNET_notification_context_create (MAX_NOTIFY_QUEUE);
}
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
struct GNUNET_SIGNAL_Context *shc_chld;
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_var_size (start,
- GNUNET_MESSAGE_TYPE_ARM_START,
- struct GNUNET_ARM_Message,
- NULL),
- GNUNET_MQ_hd_var_size (stop,
- GNUNET_MESSAGE_TYPE_ARM_STOP,
- struct GNUNET_ARM_Message,
- NULL),
- GNUNET_MQ_hd_fixed_size (monitor,
- GNUNET_MESSAGE_TYPE_ARM_MONITOR,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_hd_fixed_size (list,
- GNUNET_MESSAGE_TYPE_ARM_LIST,
- struct GNUNET_ARM_Message,
- NULL),
- GNUNET_MQ_hd_fixed_size (test,
- GNUNET_MESSAGE_TYPE_ARM_TEST,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ()
- };
-
- sigpipe = GNUNET_DISK_pipe (GNUNET_NO,
- GNUNET_NO,
- GNUNET_NO,
- GNUNET_NO);
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_var_size (start,
+ GNUNET_MESSAGE_TYPE_ARM_START,
+ struct GNUNET_ARM_Message,
+ NULL),
+ GNUNET_MQ_hd_var_size (stop,
+ GNUNET_MESSAGE_TYPE_ARM_STOP,
+ struct GNUNET_ARM_Message,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (monitor,
+ GNUNET_MESSAGE_TYPE_ARM_MONITOR,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (list,
+ GNUNET_MESSAGE_TYPE_ARM_LIST,
+ struct GNUNET_ARM_Message,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (test,
+ GNUNET_MESSAGE_TYPE_ARM_TEST,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ()};
+
+ sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO);
GNUNET_assert (NULL != sigpipe);
shc_chld =
- GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD,
- &sighandler_child_death);
- if (0 !=
- GNUNET_SERVICE_run_ (argc,
- argv,
- "arm",
- GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- handlers))
+ GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
+ if (0 != GNUNET_SERVICE_run_ (argc,
+ argv,
+ "arm",
+ GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ handlers))
global_ret = 2;
#if HAVE_WAIT4
if (NULL != wait_file)
#if LOG_BACKOFF
killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log");
- if (NULL == (killLogFilePtr = FOPEN (killLogFileName,
+ if (NULL == (killLogFilePtr = fopen (killLogFileName,
"w")))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai)))
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Failed to resolve `%s', testcase not run.\n",
hostname);
return 77;
host = gethostbyname2 (hostname, AF_INET6);
if (NULL == host)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Failed to resolve `%s', testcase not run.\n",
hostname);
return 77;
host = gethostbyname (hostname);
if (NULL == host)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Failed to resolve `%s', testcase not run.\n",
hostname);
return 77;
}
}
#else
- FPRINTF (stderr,
+ fprintf (stderr,
"libc fails to have resolver function, testcase not run.\n");
return 77;
#endif
* Is this an active address?
*/
int active;
-
};
* @return #GNUNET_YES (always)
*/
static int
-free_addr_it (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+free_addr_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
{
struct ATSAddress *a = value;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_remove (addresses,
- key,
- value));
+ GNUNET_CONTAINER_multipeermap_remove (addresses, key, value));
GNUNET_HELLO_address_free (a->address);
GNUNET_free (a);
return GNUNET_OK;
static void
end (void *cls)
{
- struct PendingResolutions * pr;
- struct PendingResolutions * next;
+ struct PendingResolutions *pr;
+ struct PendingResolutions *next;
unsigned int pending;
if (NULL != alh)
while (NULL != (pr = next))
{
next = pr->next;
- GNUNET_CONTAINER_DLL_remove(head, tail, pr);
+ GNUNET_CONTAINER_DLL_remove (head, tail, pr);
GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx);
- GNUNET_free(pr->address);
- GNUNET_free(pr);
+ GNUNET_free (pr->address);
+ GNUNET_free (pr);
pending++;
}
- GNUNET_CONTAINER_multipeermap_iterate (addresses,
- &free_addr_it,
- NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (addresses, &free_addr_it, NULL);
GNUNET_CONTAINER_multipeermap_destroy (addresses);
addresses = NULL;
if (0 < pending)
- FPRINTF (stdout,
- _("%u address resolutions had a timeout\n"),
- pending);
+ fprintf (stdout, _ ("%u address resolutions had a timeout\n"), pending);
if (opt_list_used || opt_list_all)
- FPRINTF (stdout,
- _("ATS returned stat_results for %u addresses\n"),
+ fprintf (stdout,
+ _ ("ATS returned stat_results for %u addresses\n"),
stat_results);
if (NULL != ats_sh)
* if #GNUNET_SYSERR: communication error (IPC error)
*/
static void
-transport_addr_to_str_cb (void *cls,
- const char *address,
- int res)
+transport_addr_to_str_cb (void *cls, const char *address, int res)
{
struct PendingResolutions *pr = cls;
if (NULL == address)
{
/* We're done */
- GNUNET_CONTAINER_DLL_remove (head,
- tail,
- pr);
+ GNUNET_CONTAINER_DLL_remove (head, tail, pr);
GNUNET_free (pr->address);
GNUNET_free (pr);
stat_pending--;
switch (res)
{
case GNUNET_SYSERR:
- FPRINTF (stderr,
- "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n",
- GNUNET_i2s (&pr->address->peer),
- pr->address->transport_name,
- (unsigned int) pr->address->address_length);
+ fprintf (
+ stderr,
+ "Failed to convert address for peer `%s' plugin `%s' length %u to string (communication error)\n",
+ GNUNET_i2s (&pr->address->peer),
+ pr->address->transport_name,
+ (unsigned int) pr->address->address_length);
return;
case GNUNET_NO:
- FPRINTF (stderr,
- "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n",
- GNUNET_i2s (&pr->address->peer),
- pr->address->transport_name,
- (unsigned int) pr->address->address_length);
+ fprintf (
+ stderr,
+ "Failed to convert address for peer `%s' plugin `%s' length %u to string (address invalid or not supported)\n",
+ GNUNET_i2s (&pr->address->peer),
+ pr->address->transport_name,
+ (unsigned int) pr->address->address_length);
return;
case GNUNET_OK:
/* continues below */
return;
}
- FPRINTF (stdout,
- _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
- GNUNET_i2s (&pr->address->peer),
- pr->address->transport_name,
- address,
- GNUNET_NT_to_string (pr->properties.scope),
- ntohl (pr->bandwidth_out.value__),
- ntohl (pr->bandwidth_in.value__),
- pr->active ? _("active ") : _("inactive "));
+ fprintf (
+ stdout,
+ _ (
+ "Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
+ GNUNET_i2s (&pr->address->peer),
+ pr->address->transport_name,
+ address,
+ GNUNET_NT_to_string (pr->properties.scope),
+ ntohl (pr->bandwidth_out.value__),
+ ntohl (pr->bandwidth_in.value__),
+ pr->active ? _ ("active ") : _ ("inactive "));
}
* @return #GNUNET_NO if we found a match, #GNUNET_YES if not
*/
static int
-find_address_it (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+find_address_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
{
struct AddressFindCtx *actx = cls;
struct ATSAddress *exist = value;
}
-
/**
* Signature of a function that is called with QoS information about an address.
*
GNUNET_HELLO_address_free (cur->address);
GNUNET_free (cur);
}
- GNUNET_CONTAINER_multipeermap_iterate (addresses,
- &free_addr_it,
- NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (addresses, &free_addr_it, NULL);
return;
}
if (GNUNET_SYSERR == active)
GNUNET_break (0);
return;
}
- GNUNET_break(GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_remove (addresses,
- &address->peer,
- actx.res));
- FPRINTF (stdout,
- _("Removed address of peer `%s' with plugin `%s'\n"),
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_remove (addresses,
+ &address->peer,
+ actx.res));
+ fprintf (stdout,
+ _ ("Removed address of peer `%s' with plugin `%s'\n"),
GNUNET_i2s (&address->peer),
actx.res->address->transport_name);
GNUNET_HELLO_address_free (actx.res);
{
a = GNUNET_new (struct ATSAddress);
- a->address = GNUNET_HELLO_address_copy(address);
+ a->address = GNUNET_HELLO_address_copy (address);
a->bandwidth_in = bandwidth_in;
a->bandwidth_out = bandwidth_out;
a->active = active;
- GNUNET_CONTAINER_multipeermap_put (addresses,
- &address->peer,
- a,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_CONTAINER_multipeermap_put (
+ addresses,
+ &address->peer,
+ a,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
}
}
pr->bandwidth_in = bandwidth_in;
pr->bandwidth_out = bandwidth_out;
pr->active = active;
- pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address,
- opt_resolve_addresses_numeric,
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
- &transport_addr_to_str_cb,
- pr);
+ pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (
+ cfg,
+ address,
+ opt_resolve_addresses_numeric,
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
+ &transport_addr_to_str_cb,
+ pr);
GNUNET_CONTAINER_DLL_insert (head, tail, pr);
stat_results++;
stat_pending++;
pr->bandwidth_in = bandwidth_in;
pr->bandwidth_out = bandwidth_out;
pr->active = active;
- pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address,
- opt_resolve_addresses_numeric,
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
- &transport_addr_to_str_cb, pr);
+ pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (
+ cfg,
+ address,
+ opt_resolve_addresses_numeric,
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
+ &transport_addr_to_str_cb,
+ pr);
GNUNET_CONTAINER_DLL_insert (head, tail, pr);
stat_results++;
stat_pending++;
static unsigned int
print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- char * entry_in = NULL;
- char * entry_out = NULL;
- char * quota_out_str;
- char * quota_in_str;
+ char *entry_in = NULL;
+ char *entry_out = NULL;
+ char *quota_out_str;
+ char *quota_in_str;
unsigned long long int quota_out;
unsigned long long int quota_in;
int c;
for (c = 0; (c < GNUNET_NT_COUNT); c++)
{
- GNUNET_asprintf (&entry_out,
- "%s_QUOTA_OUT",
- GNUNET_NT_to_string (c));
- GNUNET_asprintf (&entry_in,
- "%s_QUOTA_IN",
- GNUNET_NT_to_string (c));
+ GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", GNUNET_NT_to_string (c));
+ GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", GNUNET_NT_to_string (c));
/* quota out */
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "ats",
- entry_out,
- "a_out_str))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
+ "ats",
+ entry_out,
+ "a_out_str))
{
- if (0 == strcmp (quota_out_str, UNLIMITED_STRING)
- || (GNUNET_SYSERR ==
- GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str,
- "a_out)))
+ if (0 == strcmp (quota_out_str, UNLIMITED_STRING) ||
+ (GNUNET_SYSERR ==
+ GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, "a_out)))
quota_out = UINT32_MAX;
- GNUNET_free(quota_out_str);
+ GNUNET_free (quota_out_str);
GNUNET_asprintf ("a_out_str, "%llu", quota_out);
}
else
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Outbound quota for network `%11s' not configured!\n",
GNUNET_NT_to_string (c));
GNUNET_asprintf ("a_out_str, "-");
GNUNET_free (entry_out);
/* quota in */
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "ats",
- entry_in,
- "a_in_str))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
+ "ats",
+ entry_in,
+ "a_in_str))
{
- if (0 == strcmp (quota_in_str, UNLIMITED_STRING)
- || (GNUNET_SYSERR ==
- GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, "a_in)))
+ if (0 == strcmp (quota_in_str, UNLIMITED_STRING) ||
+ (GNUNET_SYSERR ==
+ GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, "a_in)))
quota_in = UINT32_MAX;
GNUNET_free (quota_in_str);
GNUNET_asprintf ("a_in_str, "%llu", quota_in);
}
else
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Inbound quota for network `%11s' not configured!\n",
GNUNET_NT_to_string (c));
GNUNET_asprintf ("a_in_str, "-");
}
- GNUNET_free(entry_in);
+ GNUNET_free (entry_in);
- FPRINTF (stdout,
- _("Quota for network `%11s' (in/out): %10s / %10s\n"),
+ fprintf (stdout,
+ _ ("Quota for network `%11s' (in/out): %10s / %10s\n"),
GNUNET_NT_to_string (c),
quota_in_str,
quota_out_str);
- GNUNET_free(quota_out_str);
- GNUNET_free(quota_in_str);
+ GNUNET_free (quota_out_str);
+ GNUNET_free (quota_in_str);
}
return GNUNET_NT_COUNT;
}
*/
static void
run (void *cls,
- char * const *args,
+ char *const *args,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *my_cfg)
{
strlen (opt_pid_str),
&pid.public_key))
{
- FPRINTF (stderr,
- _("Failed to parse peer identity `%s'\n"),
- opt_pid_str);
+ fprintf (stderr, _ ("Failed to parse peer identity `%s'\n"), opt_pid_str);
return;
}
}
strlen (cpid_str),
&cpid.public_key))
{
- FPRINTF (stderr,
- _("Failed to parse peer identity `%s'\n"),
- cpid_str);
+ fprintf (stderr, _ ("Failed to parse peer identity `%s'\n"), cpid_str);
return;
}
c++;
if (1 < c)
{
- FPRINTF (stderr,
- _("Please select one operation: %s or %s or %s or %s or %s\n"),
+ fprintf (stderr,
+ _ ("Please select one operation: %s or %s or %s or %s or %s\n"),
"--used",
"--all",
"--monitor",
ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
if (NULL == ph)
{
- FPRINTF (stderr,
- "%s",
- _("Cannot connect to ATS service, exiting...\n"));
+ fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
return;
}
alh = GNUNET_ATS_performance_list_addresses (ph,
- (NULL == opt_pid_str) ? NULL : &pid,
+ (NULL == opt_pid_str) ? NULL
+ : &pid,
GNUNET_YES,
- &ats_perf_cb, NULL);
+ &ats_perf_cb,
+ NULL);
if (NULL == alh)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
- _("Cannot issue request to ATS service, exiting...\n"));
+ _ ("Cannot issue request to ATS service, exiting...\n"));
shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
return;
}
- shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
- NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
return;
}
if (opt_list_used)
{
ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
if (NULL == ph)
- FPRINTF (stderr,
- "%s",
- _("Cannot connect to ATS service, exiting...\n"));
+ fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
alh = GNUNET_ATS_performance_list_addresses (ph,
- (NULL == opt_pid_str)
- ? NULL
- : &pid,
+ (NULL == opt_pid_str) ? NULL
+ : &pid,
GNUNET_NO,
- &ats_perf_cb, NULL);
+ &ats_perf_cb,
+ NULL);
if (NULL == alh)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
- _("Cannot issue request to ATS service, exiting...\n"));
+ _ ("Cannot issue request to ATS service, exiting...\n"));
shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
return;
}
- shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
- NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
return;
}
if (opt_monitor)
{
- ph = GNUNET_ATS_performance_init (cfg,
- &ats_perf_mon_cb,
- NULL);
- shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
- NULL);
+ ph = GNUNET_ATS_performance_init (cfg, &ats_perf_mon_cb, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end, NULL);
if (NULL == ph)
{
- FPRINTF (stderr,
- "%s",
- _("Cannot connect to ATS service, exiting...\n"));
+ fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
GNUNET_SCHEDULER_shutdown ();
}
return;
{
if (NULL == opt_type_str)
{
- FPRINTF (stderr,
- "%s",
- _("No preference type given!\n"));
+ fprintf (stderr, "%s", _ ("No preference type given!\n"));
return;
}
if (NULL == opt_pid_str)
{
- FPRINTF (stderr,
- "%s",
- _("No peer given!\n"));
+ fprintf (stderr, "%s", _ ("No peer given!\n"));
return;
}
type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
else
{
- FPRINTF (stderr,
- "%s",
- _("Valid type required\n"));
+ fprintf (stderr, "%s", _ ("Valid type required\n"));
return;
}
/* set */
ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
if (NULL == ph)
- FPRINTF (stderr,
- "%s",
- _("Cannot connect to ATS service, exiting...\n"));
+ fprintf (stderr, "%s", _ ("Cannot connect to ATS service, exiting...\n"));
GNUNET_ATS_performance_change_preference (ph,
&pid,
(double) opt_pref_value,
GNUNET_ATS_PREFERENCE_END);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &end,
- NULL);
+ shutdown_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
return;
}
if (NULL != cpid_str)
{
ats_ch = GNUNET_ATS_connectivity_init (cfg);
- ats_sh = GNUNET_ATS_connectivity_suggest (ats_ch,
- &cpid,
- 1000);
- shutdown_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &end,
- NULL);
+ ats_sh = GNUNET_ATS_connectivity_suggest (ats_ch, &cpid, 1000);
+ shutdown_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
return;
}
ret = 1;
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char * const *argv)
+main (int argc, char *const *argv)
{
int res;
stat_receive_done = GNUNET_NO;
opt_type_str = NULL;
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('u',
- "used",
- gettext_noop ("get list of active addresses currently used"),
- &opt_list_used),
- GNUNET_GETOPT_option_flag ('a',
- "all",
- gettext_noop ("get list of all active addresses"),
- &opt_list_all),
-
- GNUNET_GETOPT_option_string ('C',
- "connect",
- NULL,
- gettext_noop ("connect to PEER"),
- &cpid_str),
- GNUNET_GETOPT_option_flag ('n',
- "numeric",
- gettext_noop ("do not resolve IP addresses to hostnames"),
- &opt_resolve_addresses_numeric),
-
- GNUNET_GETOPT_option_flag ('m',
- "monitor",
- gettext_noop ("monitor mode"),
- &opt_monitor),
-
- GNUNET_GETOPT_option_flag ('p',
- "preference",
- gettext_noop ("set preference for the given peer"),
- &opt_set_pref),
-
- GNUNET_GETOPT_option_flag ('q',
- "quotas",
- gettext_noop ("print all configured quotas"),
- &opt_print_quotas),
- GNUNET_GETOPT_option_string ('i',
- "id",
- "TYPE",
- gettext_noop ("peer id"),
- &opt_pid_str),
-
- GNUNET_GETOPT_option_string ('t',
- "type",
- "TYPE",
- gettext_noop ("preference type to set: latency | bandwidth"),
- &opt_type_str),
-
- GNUNET_GETOPT_option_uint ('k',
- "value",
- "VALUE",
- gettext_noop ("preference value"),
- &opt_pref_value),
-
- GNUNET_GETOPT_option_flag ('V',
- "verbose",
- gettext_noop ("verbose output (include ATS address properties)"),
- &opt_verbose),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag ('u',
+ "used",
+ gettext_noop (
+ "get list of active addresses currently used"),
+ &opt_list_used),
+ GNUNET_GETOPT_option_flag ('a',
+ "all",
+ gettext_noop (
+ "get list of all active addresses"),
+ &opt_list_all),
+
+ GNUNET_GETOPT_option_string ('C',
+ "connect",
+ NULL,
+ gettext_noop ("connect to PEER"),
+ &cpid_str),
+ GNUNET_GETOPT_option_flag ('n',
+ "numeric",
+ gettext_noop (
+ "do not resolve IP addresses to hostnames"),
+ &opt_resolve_addresses_numeric),
+
+ GNUNET_GETOPT_option_flag ('m',
+ "monitor",
+ gettext_noop ("monitor mode"),
+ &opt_monitor),
+
+ GNUNET_GETOPT_option_flag ('p',
+ "preference",
+ gettext_noop (
+ "set preference for the given peer"),
+ &opt_set_pref),
+
+ GNUNET_GETOPT_option_flag ('q',
+ "quotas",
+ gettext_noop ("print all configured quotas"),
+ &opt_print_quotas),
+ GNUNET_GETOPT_option_string ('i',
+ "id",
+ "TYPE",
+ gettext_noop ("peer id"),
+ &opt_pid_str),
+
+ GNUNET_GETOPT_option_string ('t',
+ "type",
+ "TYPE",
+ gettext_noop (
+ "preference type to set: latency | bandwidth"),
+ &opt_type_str),
+
+ GNUNET_GETOPT_option_uint ('k',
+ "value",
+ "VALUE",
+ gettext_noop ("preference value"),
+ &opt_pref_value),
+
+ GNUNET_GETOPT_option_flag (
+ 'V',
+ "verbose",
+ gettext_noop ("verbose output (include ATS address properties)"),
+ &opt_verbose),
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- res = GNUNET_PROGRAM_run (argc, argv,
+ res = GNUNET_PROGRAM_run (argc,
+ argv,
"gnunet-ats",
gettext_noop ("Print information about ATS state"),
options,
- &run, NULL);
- GNUNET_free_non_null(opt_pid_str);
- GNUNET_free_non_null(opt_type_str);
- GNUNET_free((void *) argv);
+ &run,
+ NULL);
+ GNUNET_free_non_null (opt_pid_str);
+ GNUNET_free_non_null (opt_type_str);
+ GNUNET_free ((void *) argv);
if (GNUNET_OK == res)
return ret;
for (j = 0; j < peers_pinging; j++)
{
peer = &peers[j];
- FPRINTF (stdout,
+ fprintf (stdout,
"ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
peer->pings[i], peer->pongs[i]);
#include "gnunet_cadet_service.h"
#include "cadet.h"
-#define STREAM_BUFFER_SIZE 1024 // Pakets
+#define STREAM_BUFFER_SIZE 1024 // Pakets
/**
* Option -P.
{
switch (status)
{
- case 0:
- return "NULL ";
- case 1:
- return "KSENT";
- case 2:
- return "KRECV";
- case 3:
- return "READY";
- default:
- return "";
+ case 0:
+ return "NULL ";
+ case 1:
+ return "KSENT";
+ case 2:
+ return "KRECV";
+ case 3:
+ return "READY";
+ default:
+ return "";
}
}
{
switch (status)
{
- case 0:
- return "NEW ";
- case 1:
- return "SRCH ";
- case 2:
- return "WAIT ";
- case 3:
- return "READY";
- case 4:
- return "SHUTD";
- default:
- return "";
+ case 0:
+ return "NEW ";
+ case 1:
+ return "SRCH ";
+ case 2:
+ return "WAIT ";
+ case 3:
+ return "READY";
+ case 4:
+ return "SHUTD";
+ default:
+ return "";
}
}
-
/**
* Task to shut down this application.
*
static void
shutdown_task (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
if (NULL != lp)
{
GNUNET_CADET_close_port (lp);
}
void
-mq_cb(void *cls)
+mq_cb (void *cls)
{
listen_stdio ();
}
ssize_t data_size;
rd_task = NULL;
- data_size = read (0,
- buf,
- 60000);
+ data_size = read (0, buf, 60000);
if (data_size < 1)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "read() returned %s\n", strerror(errno));
- GNUNET_SCHEDULER_shutdown();
+ "read() returned %s\n",
+ strerror (errno));
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Read %u bytes from stdio\n",
(unsigned int) data_size);
- env = GNUNET_MQ_msg_extra (msg,
- data_size,
- GNUNET_MESSAGE_TYPE_CADET_CLI);
- GNUNET_memcpy (&msg[1],
- buf,
- data_size);
- GNUNET_MQ_send (GNUNET_CADET_get_mq (ch),
- env);
+ env = GNUNET_MQ_msg_extra (msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
+ GNUNET_memcpy (&msg[1], buf, data_size);
+ GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
sent_pkt++;
/* FIXME: why use 'rs' here, seems overly complicated... */
rs = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_set_native (rs,
- 0); /* STDIN */
+ GNUNET_NETWORK_fdset_set_native (rs, 0); /* STDIN */
rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
GNUNET_TIME_UNIT_FOREVER_REL,
rs,
* @param channel connection to the other end (henceforth invalid)
*/
static void
-channel_ended (void *cls,
- const struct GNUNET_CADET_Channel *channel)
+channel_ended (void *cls, const struct GNUNET_CADET_Channel *channel)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Channel ended!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n");
GNUNET_assert (channel == ch);
ch = NULL;
GNUNET_SCHEDULER_shutdown ();
echo_task = NULL;
if (NULL == ch)
return;
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_CADET_CLI);
- GNUNET_MQ_send (GNUNET_CADET_get_mq (ch),
- env);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CLI);
+ GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
}
* #GNUNET_SYSERR to close it (signal serious error).
*/
static int
-check_data (void *cls,
- const struct GNUNET_MessageHeader *message)
+check_data (void *cls, const struct GNUNET_MessageHeader *message)
{
return GNUNET_OK; /* all is well-formed */
}
* @param message The actual message.
*/
static void
-handle_data (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_data (void *cls, const struct GNUNET_MessageHeader *message)
{
size_t payload_size = ntohs (message->size) - sizeof (*message);
uint16_t len;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
- env = GNUNET_MQ_msg_extra (msg,
- payload_size,
- GNUNET_MESSAGE_TYPE_CADET_CLI);
- GNUNET_memcpy (&msg[1],
- &message[1],
- payload_size);
- GNUNET_MQ_send (GNUNET_CADET_get_mq (ch),
- env);
+ env =
+ GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
+ GNUNET_memcpy (&msg[1], &message[1], payload_size);
+ GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
return;
}
else
echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
"time: %s\n",
- GNUNET_STRINGS_relative_time_to_string (latency,
- GNUNET_NO));
+ GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
&send_echo,
NULL);
}
len = ntohs (message->size) - sizeof (*message);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got %u bytes\n",
- len);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len);
buf = (const char *) &message[1];
off = 0;
while (off < len)
{
- done = write (1,
- &buf[off],
- len - off);
+ done = write (1, &buf[off], len - off);
if (done <= 0)
{
if (-1 == done)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "write");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
GNUNET_SCHEDULER_shutdown ();
return;
}
* @param ple information about peer, or NULL on "EOF".
*/
static void
-peers_callback (void *cls,
- const struct GNUNET_CADET_PeerListEntry *ple)
+peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
{
if (NULL == ple)
{
plo = NULL;
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- FPRINTF (stdout,
+ fprintf (stdout,
"%s tunnel: %c, paths: %u\n",
GNUNET_i2s_full (&ple->peer),
ple->have_tunnel ? 'Y' : 'N',
* @param ppd path detail
*/
static void
-path_callback (void *cls,
- const struct GNUNET_CADET_PeerPathDetail *ppd)
+path_callback (void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
{
if (NULL == ppd)
{
gpo = NULL;
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- FPRINTF (stdout,
- "Path of length %u: ",
- ppd->path_length);
+ fprintf (stdout, "Path of length %u: ", ppd->path_length);
for (unsigned int i = 0; i < ppd->path_length; i++)
- FPRINTF (stdout,
- (i == ppd->target_offset) ? "*%s* " : "%s ",
- GNUNET_i2s (&ppd->path[i]));
- FPRINTF (stdout,
- "\n");
+ fprintf (stdout,
+ (i == ppd->target_offset) ? "*%s* " : "%s ",
+ GNUNET_i2s (&ppd->path[i]));
+ fprintf (stdout, "\n");
}
* @param td tunnel details
*/
static void
-tunnels_callback (void *cls,
- const struct GNUNET_CADET_TunnelDetails *td)
+tunnels_callback (void *cls, const struct GNUNET_CADET_TunnelDetails *td)
{
if (NULL == td)
{
tio = NULL;
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- FPRINTF (stdout,
+ fprintf (stdout,
"%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
GNUNET_i2s_full (&td->peer),
enc_2s (td->estate),
get_peers (void *cls)
{
job = NULL;
- plo = GNUNET_CADET_list_peers (my_cfg,
- &peers_callback,
- NULL);
+ plo = GNUNET_CADET_list_peers (my_cfg, &peers_callback, NULL);
}
struct GNUNET_PeerIdentity pid;
job = NULL;
- if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
- strlen (peer_id),
- &pid.public_key))
+ if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
+ strlen (peer_id),
+ &pid.public_key))
{
- fprintf (stderr,
- _("Invalid peer ID `%s'\n"),
- peer_id);
- GNUNET_SCHEDULER_shutdown();
+ fprintf (stderr, _ ("Invalid peer ID `%s'\n"), peer_id);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- gpo = GNUNET_CADET_get_path (my_cfg,
- &pid,
- &path_callback,
- NULL);
+ gpo = GNUNET_CADET_get_path (my_cfg, &pid, &path_callback, NULL);
}
get_tunnels (void *cls)
{
job = NULL;
- tio = GNUNET_CADET_list_tunnels (my_cfg,
- &tunnels_callback,
- NULL);
+ tio = GNUNET_CADET_list_tunnels (my_cfg, &tunnels_callback, NULL);
}
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_var_size (data,
- GNUNET_MESSAGE_TYPE_CADET_CLI,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_var_size (data,
+ GNUNET_MESSAGE_TYPE_CADET_CLI,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ()};
/* FIXME add option to monitor apps */
my_cfg = cfg;
if (target_id && args[1])
target_port = args[1];
- if ( (0 != (request_peers | request_tunnels)
- || NULL != conn_id
- || NULL != channel_id)
- && target_id != NULL)
+ if ((0 != (request_peers | request_tunnels) || NULL != conn_id ||
+ NULL != channel_id) &&
+ target_id != NULL)
{
- FPRINTF (stderr,
- _("Extra arguments are not applicable "
- "in combination with this option.\n"));
+ fprintf (stderr,
+ _ ("Extra arguments are not applicable "
+ "in combination with this option.\n"));
return;
}
if (NULL != peer_id)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Show peer\n");
- job = GNUNET_SCHEDULER_add_now (&show_peer,
- NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
+ job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
}
else if (NULL != channel_id)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Show channel\n");
- job = GNUNET_SCHEDULER_add_now (&show_channel,
- NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
+ job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
}
else if (NULL != conn_id)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Show connection\n");
- job = GNUNET_SCHEDULER_add_now (&show_connection,
- NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
+ job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
}
else if (GNUNET_YES == request_peers)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Show all peers\n");
- job = GNUNET_SCHEDULER_add_now (&get_peers,
- NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
+ job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
}
else if (GNUNET_YES == request_tunnels)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Show all tunnels\n");
- job = GNUNET_SCHEDULER_add_now (&get_tunnels,
- NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
+ job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to CADET service\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n");
mh = GNUNET_CADET_connect (cfg);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
if (NULL == mh)
{
GNUNET_SCHEDULER_shutdown ();
}
if (NULL != listen_port)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Opening CADET listen port\n");
- GNUNET_CRYPTO_hash (listen_port,
- strlen (listen_port),
- &porthash);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n");
+ GNUNET_CRYPTO_hash (listen_port, strlen (listen_port), &porthash);
lp = GNUNET_CADET_open_port (mh,
&porthash,
&channel_incoming,
&pid.public_key))
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- _("Invalid target `%s'\n"),
+ _ ("Invalid target `%s'\n"),
target_id);
GNUNET_SCHEDULER_shutdown ();
return;
"Connecting to `%s:%s'\n",
target_id,
target_port);
- GNUNET_CRYPTO_hash (target_port,
- strlen(target_port),
- &porthash);
+ GNUNET_CRYPTO_hash (target_port, strlen (target_port), &porthash);
ch = GNUNET_CADET_channel_create (mh,
NULL,
&pid,
handlers);
if (GNUNET_YES == echo)
{
- echo_task = GNUNET_SCHEDULER_add_now (&send_echo,
- NULL);
+ echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
}
else
{
}
}
- if ( (NULL == lp) &&
- (NULL == job) &&
- (NULL == ch) )
+ if ((NULL == lp) && (NULL == job) && (NULL == ch))
{
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- _("No action requested\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _ ("No action requested\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
int res;
- const char helpstr[] = "Create tunnels and retrieve info about CADET's status.";
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- /* I would use the terminology 'circuit' here... --lynX */
- GNUNET_GETOPT_option_string ('C',
- "connection",
- "CONNECTION_ID",
- gettext_noop ("Provide information about a particular connection"),
- &conn_id),
- GNUNET_GETOPT_option_flag ('e',
- "echo",
- gettext_noop ("Activate echo mode"),
- &echo),
- GNUNET_GETOPT_option_string ('o',
- "open-port",
- "SHARED_SECRET",
- gettext_noop ("Listen for connections using a shared secret among sender and recipient"),
- &listen_port),
- GNUNET_GETOPT_option_string ('p',
- "peer",
- "PEER_ID",
- gettext_noop ("Provide information about a patricular peer"),
- &peer_id),
- GNUNET_GETOPT_option_flag ('P',
- "peers",
- gettext_noop ("Provide information about all peers"),
- &request_peers),
- GNUNET_GETOPT_option_flag ('T',
- "tunnels",
- gettext_noop ("Provide information about all tunnels"),
- &request_tunnels),
- GNUNET_GETOPT_OPTION_END
- };
-
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ const char helpstr[] =
+ "Create tunnels and retrieve info about CADET's status.";
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {/* I would use the terminology 'circuit' here... --lynX */
+ GNUNET_GETOPT_option_string (
+ 'C',
+ "connection",
+ "CONNECTION_ID",
+ gettext_noop ("Provide information about a particular connection"),
+ &conn_id),
+ GNUNET_GETOPT_option_flag ('e',
+ "echo",
+ gettext_noop ("Activate echo mode"),
+ &echo),
+ GNUNET_GETOPT_option_string (
+ 'o',
+ "open-port",
+ "SHARED_SECRET",
+ gettext_noop (
+ "Listen for connections using a shared secret among sender and recipient"),
+ &listen_port),
+ GNUNET_GETOPT_option_string ('p',
+ "peer",
+ "PEER_ID",
+ gettext_noop (
+ "Provide information about a patricular peer"),
+ &peer_id),
+ GNUNET_GETOPT_option_flag ('P',
+ "peers",
+ gettext_noop (
+ "Provide information about all peers"),
+ &request_peers),
+ GNUNET_GETOPT_option_flag ('T',
+ "tunnels",
+ gettext_noop (
+ "Provide information about all tunnels"),
+ &request_tunnels),
+ GNUNET_GETOPT_OPTION_END};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- res = GNUNET_PROGRAM_run (argc, argv,
+ res = GNUNET_PROGRAM_run (argc,
+ argv,
"gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)",
gettext_noop (helpstr),
- options, &run, NULL);
+ options,
+ &run,
+ NULL);
GNUNET_free ((void *) argv);
end_time = GNUNET_TIME_absolute_get ();
total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time);
- FPRINTF (stderr,
+ fprintf (stderr,
"\nResults of test \"%s\"\n",
test_name);
- FPRINTF (stderr,
+ fprintf (stderr,
"Test time %s\n",
GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES));
- FPRINTF (stderr,
+ fprintf (stderr,
"Test bandwidth: %f kb/s\n",
4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms
- FPRINTF (stderr,
+ fprintf (stderr,
"Test throughput: %f packets/s\n\n",
total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms
GAUGER ("CADET",
short_time = SHORT_TIME;
if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv))
{
- FPRINTF (stderr, "test failed: problem with CLI parameters\n");
+ fprintf (stderr, "test failed: problem with CLI parameters\n");
exit (1);
}
end_time = GNUNET_TIME_absolute_get ();
total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time);
- FPRINTF (stderr,
+ fprintf (stderr,
"\nResults of test \"%s\"\n",
test_name);
- FPRINTF (stderr,
+ fprintf (stderr,
"Test time %s\n",
GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES));
- FPRINTF (stderr,
+ fprintf (stderr,
"Test bandwidth: %f kb/s\n",
4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms
- FPRINTF (stderr,
+ fprintf (stderr,
"Test throughput: %f packets/s\n\n",
total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms
GAUGER ("CADET",
argc,
argv))
{
- FPRINTF (stderr,
+ fprintf (stderr,
"test failed: problem with CLI parameters\n");
return 1;
}
*/
#define MAX_MESSAGE_LENGTH 1024
-#define XSTRINGIFY(x) STRINGIFY(x)
+#define XSTRINGIFY(x) STRINGIFY (x)
#define STRINGIFY(x) (#x)
* Unique number of the call.
*/
unsigned int caller_num;
-
};
-
/**
* Phone handle
*/
/**
* Task which handles the commands
*/
-static struct GNUNET_SCHEDULER_Task * handle_cmd_task;
+static struct GNUNET_SCHEDULER_Task *handle_cmd_task;
/**
* Our speaker.
*
* see https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html on how to play a wav using the gst framework being used here
*/
- FPRINTF (stdout,
- _("Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"),
- GNUNET_GNSRECORD_pkey_to_zkey (caller_id),
- caller_num_gen,
- caller_num_gen);
+ fprintf (
+ stdout,
+ _ (
+ "Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"),
+ GNUNET_GNSRECORD_pkey_to_zkey (caller_id),
+ caller_num_gen,
+ caller_num_gen);
cl = GNUNET_new (struct CallList);
cl->caller = caller;
cl->caller_id = *caller_id;
cl->caller_num = caller_num_gen++;
- GNUNET_CONTAINER_DLL_insert (cl_head,
- cl_tail,
- cl);
+ GNUNET_CONTAINER_DLL_insert (cl_head, cl_tail, cl);
break;
case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP:
for (cl = cl_head; NULL != cl; cl = cl->next)
if (caller == cl->caller)
break;
- if ( (NULL == cl) &&
- (caller == cl_active->caller) )
+ if ((NULL == cl) && (caller == cl_active->caller))
cl = cl_active;
if (NULL == cl)
{
GNUNET_break (0);
return;
}
- FPRINTF (stdout,
- _("Call from `%s' terminated\n"),
+ fprintf (stdout,
+ _ ("Call from `%s' terminated\n"),
GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
if (cl == cl_active)
{
}
else
{
- GNUNET_CONTAINER_DLL_remove (cl_head,
- cl_tail,
- cl);
+ GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl);
}
GNUNET_free (cl);
break;
* @param code type of the event issued by the caller
*/
static void
-caller_event_handler (void *cls,
- enum GNUNET_CONVERSATION_CallerEventCode code)
+caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code)
{
struct CallList *cl = cls;
switch (code)
{
case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
- FPRINTF (stdout,
- _("Call from `%s' suspended by other user\n"),
+ fprintf (stdout,
+ _ ("Call from `%s' suspended by other user\n"),
GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
break;
case GNUNET_CONVERSATION_EC_CALLER_RESUME:
- FPRINTF (stdout,
- _("Call from `%s' resumed by other user\n"),
+ fprintf (stdout,
+ _ ("Call from `%s' resumed by other user\n"),
GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
break;
}
if (NULL == my_caller_id)
{
- FPRINTF (stderr,
- _("Ego `%s' no longer available, phone is now down.\n"),
+ fprintf (stderr,
+ _ ("Ego `%s' no longer available, phone is now down.\n"),
ego_name);
phone_state = PS_LOOKUP_EGO;
return;
/* FIXME: get record and print full GNS record info later here... */
if (NULL == phone)
{
- FPRINTF (stderr,
- "%s",
- _("Failed to setup phone (internal error)\n"));
+ fprintf (stderr, "%s", _ ("Failed to setup phone (internal error)\n"));
phone_state = PS_ERROR;
}
else
{
- GNUNET_CONVERSATION_phone_get_record (phone,
- &rd);
+ GNUNET_CONVERSATION_phone_get_record (phone, &rd);
GNUNET_free_non_null (address);
- address = GNUNET_GNSRECORD_value_to_string (rd.record_type,
- rd.data,
- rd.data_size);
- FPRINTF (stdout,
- _("Phone active at `%s'. Type `/help' for a list of available commands\n"),
- address);
+ address =
+ GNUNET_GNSRECORD_value_to_string (rd.record_type, rd.data, rd.data_size);
+ fprintf (
+ stdout,
+ _ (
+ "Phone active at `%s'. Type `/help' for a list of available commands\n"),
+ address);
phone_state = PS_LISTEN;
}
}
* @param code type of the event on the call
*/
static void
-call_event_handler (void *cls,
- enum GNUNET_CONVERSATION_CallEventCode code)
+call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code)
{
(void) cls;
-
+
switch (code)
{
case GNUNET_CONVERSATION_EC_CALL_RINGING:
GNUNET_break (CS_RESOLVING == call_state);
- FPRINTF (stdout,
- _("Resolved address of `%s'. Now ringing other party.\n"),
+ fprintf (stdout,
+ _ ("Resolved address of `%s'. Now ringing other party.\n"),
peer_name);
call_state = CS_RINGING;
break;
case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
GNUNET_break (CS_RINGING == call_state);
- FPRINTF (stdout,
- _("Connection established to `%s'\n"),
- peer_name);
+ fprintf (stdout, _ ("Connection established to `%s'\n"), peer_name);
call_state = CS_CONNECTED;
break;
case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
GNUNET_break (CS_RESOLVING == call_state);
- FPRINTF (stdout,
- _("Failed to resolve `%s'\n"),
- peer_name);
+ fprintf (stdout, _ ("Failed to resolve `%s'\n"), peer_name);
GNUNET_free (peer_name);
peer_name = NULL;
call = NULL;
break;
case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
- FPRINTF (stdout,
- _("Call to `%s' terminated\n"),
- peer_name);
+ fprintf (stdout, _ ("Call to `%s' terminated\n"), peer_name);
GNUNET_free (peer_name);
peer_name = NULL;
call = NULL;
break;
case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
GNUNET_break (CS_CONNECTED == call_state);
- FPRINTF (stdout,
- _("Connection to `%s' suspended (by other user)\n"),
+ fprintf (stdout,
+ _ ("Connection to `%s' suspended (by other user)\n"),
peer_name);
break;
case GNUNET_CONVERSATION_EC_CALL_RESUMED:
GNUNET_break (CS_CONNECTED == call_state);
- FPRINTF (stdout,
- _("Connection to `%s' resumed (by other user)\n"),
+ fprintf (stdout,
+ _ ("Connection to `%s' resumed (by other user)\n"),
peer_name);
break;
case GNUNET_CONVERSATION_EC_CALL_ERROR:
- FPRINTF (stdout,
- _("Error with the call, restarting it\n"));
+ fprintf (stdout, _ ("Error with the call, restarting it\n"));
GNUNET_free (peer_name);
peer_name = NULL;
call = NULL;
*
* @param arguments arguments given to the function
*/
-typedef void
-(*ActionFunction) (const char *arguments);
+typedef void (*ActionFunction) (const char *arguments);
/**
static void
do_unknown (const char *msg)
{
- FPRINTF (stderr,
- _("Unknown command `%s'\n"),
- msg);
+ fprintf (stderr, _ ("Unknown command `%s'\n"), msg);
}
{
if (NULL == my_caller_id)
{
- FPRINTF (stderr,
- _("Ego `%s' not available\n"),
- ego_name);
+ fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name);
return;
}
if (NULL != call)
{
- FPRINTF (stderr,
- _("You are calling someone else already, hang up first!\n"));
+ fprintf (stderr,
+ _ ("You are calling someone else already, hang up first!\n"));
return;
}
switch (phone_state)
{
case PS_LOOKUP_EGO:
- FPRINTF (stderr,
- _("Ego `%s' not available\n"),
- ego_name);
+ fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name);
return;
case PS_LISTEN:
/* ok to call! */
break;
case PS_ACCEPTED:
- FPRINTF (stderr,
- _("You are answering call from `%s', hang up or suspend that call first!\n"),
- GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
+ fprintf (
+ stderr,
+ _ (
+ "You are answering call from `%s', hang up or suspend that call first!\n"),
+ GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
return;
case PS_ERROR:
/* ok to call */
}
if (NULL == arg)
{
- FPRINTF (stderr,
- _("Call recipient missing.\n"));
+ fprintf (stderr, _ ("Call recipient missing.\n"));
do_help ("/call");
return;
}
arg,
speaker,
mic,
- &call_event_handler, NULL);
+ &call_event_handler,
+ NULL);
}
struct CallList *cl;
char buf[32];
- if ( (NULL != call) &&
- (CS_SUSPENDED != call_state) )
+ if ((NULL != call) && (CS_SUSPENDED != call_state))
{
- FPRINTF (stderr,
- _("You are calling someone else already, hang up first!\n"));
+ fprintf (stderr,
+ _ ("You are calling someone else already, hang up first!\n"));
return;
}
switch (phone_state)
/* this is the expected state */
break;
case PS_ACCEPTED:
- FPRINTF (stderr,
- _("You are answering call from `%s', hang up or suspend that call first!\n"),
- GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
+ fprintf (
+ stderr,
+ _ (
+ "You are answering call from `%s', hang up or suspend that call first!\n"),
+ GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
return;
case PS_ERROR:
GNUNET_break (0);
cl = cl_head;
if (NULL == cl)
{
- FPRINTF (stderr,
- _("There is no incoming call to accept here!\n"));
+ fprintf (stderr, _ ("There is no incoming call to accept here!\n"));
return;
}
- if ( (NULL != cl->next) || (NULL != args) )
+ if ((NULL != cl->next) || (NULL != args))
{
for (cl = cl_head; NULL != cl; cl = cl->next)
{
- GNUNET_snprintf (buf, sizeof (buf),
- "%u",
- cl->caller_num);
+ GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num);
if (0 == strcmp (buf, args))
break;
}
}
if (NULL == cl)
{
- FPRINTF (stderr,
- _("There is no incoming call `%s' to accept right now!\n"),
+ fprintf (stderr,
+ _ ("There is no incoming call `%s' to accept right now!\n"),
args);
return;
}
- GNUNET_CONTAINER_DLL_remove (cl_head,
- cl_tail,
- cl);
+ GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl);
cl_active = cl;
peer_key = cl->caller_id;
phone_state = PS_ACCEPTED;
(void) args;
if (NULL == address)
{
- FPRINTF (stdout,
- "%s",
- _("We currently do not have an address.\n"));
+ fprintf (stdout, "%s", _ ("We currently do not have an address.\n"));
return;
}
- FPRINTF (stdout,
- "%s\n",
- address);
+ fprintf (stdout, "%s\n", address);
}
switch (phone_state)
{
case PS_LOOKUP_EGO:
- FPRINTF (stdout,
- _("We are currently trying to locate the private key for the ego `%s'.\n"),
- ego_name);
+ fprintf (
+ stdout,
+ _ (
+ "We are currently trying to locate the private key for the ego `%s'.\n"),
+ ego_name);
break;
case PS_LISTEN:
- FPRINTF (stdout,
- _("We are listening for incoming calls for ego `%s' on line `%s'.\n"),
+ fprintf (stdout,
+ _ (
+ "We are listening for incoming calls for ego `%s' on line `%s'.\n"),
ego_name,
line);
break;
case PS_ACCEPTED:
- FPRINTF (stdout,
- _("You are having a conversation with `%s'.\n"),
- GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));;
+ fprintf (stdout,
+ _ ("You are having a conversation with `%s'.\n"),
+ GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
+ ;
break;
case PS_ERROR:
- FPRINTF (stdout,
- _("We had an internal error setting up our phone line. You can still make calls.\n"));
+ fprintf (
+ stdout,
+ _ (
+ "We had an internal error setting up our phone line. You can still make calls.\n"));
break;
}
if (NULL != call)
switch (call_state)
{
case CS_RESOLVING:
- FPRINTF (stdout,
- _("We are trying to find the network address to call `%s'.\n"),
+ fprintf (stdout,
+ _ ("We are trying to find the network address to call `%s'.\n"),
peer_name);
break;
case CS_RINGING:
- FPRINTF (stdout,
- _("We are calling `%s', their phone should be ringing.\n"),
+ fprintf (stdout,
+ _ ("We are calling `%s', their phone should be ringing.\n"),
peer_name);
break;
case CS_CONNECTED:
- FPRINTF (stdout,
- _("You are having a conversation with `%s'.\n"),
+ fprintf (stdout,
+ _ ("You are having a conversation with `%s'.\n"),
peer_name);
break;
case CS_SUSPENDED:
break;
}
}
- if ( (NULL != cl_head) &&
- ( (cl_head != cl_active) ||
- (cl_head != cl_tail) ) )
+ if ((NULL != cl_head) && ((cl_head != cl_active) || (cl_head != cl_tail)))
{
- FPRINTF (stdout,
- "%s",
- _("Calls waiting:\n"));
+ fprintf (stdout, "%s", _ ("Calls waiting:\n"));
for (cl = cl_head; NULL != cl; cl = cl->next)
{
if (cl == cl_active)
continue;
- FPRINTF (stdout,
- _("#%u: `%s'\n"),
+ fprintf (stdout,
+ _ ("#%u: `%s'\n"),
cl->caller_num,
GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id));
}
- FPRINTF (stdout,
- "%s",
- "\n");
+ fprintf (stdout, "%s", "\n");
}
}
case CS_RESOLVING:
case CS_RINGING:
case CS_SUSPENDED:
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
- _("There is no call that could be suspended right now.\n"));
+ _ ("There is no call that could be suspended right now.\n"));
return;
case CS_CONNECTED:
call_state = CS_SUSPENDED;
case PS_LOOKUP_EGO:
case PS_LISTEN:
case PS_ERROR:
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
- _("There is no call that could be suspended right now.\n"));
+ _ ("There is no call that could be suspended right now.\n"));
return;
case PS_ACCEPTED:
/* expected state, do rejection logic */
case CS_RESOLVING:
case CS_RINGING:
case CS_CONNECTED:
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
- _("There is no call that could be resumed right now.\n"));
+ _ ("There is no call that could be resumed right now.\n"));
return;
case CS_SUSPENDED:
call_state = CS_CONNECTED;
- GNUNET_CONVERSATION_call_resume (call,
- speaker,
- mic);
+ GNUNET_CONVERSATION_call_resume (call, speaker, mic);
return;
}
}
{
case PS_LOOKUP_EGO:
case PS_ERROR:
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
- _("There is no call that could be resumed right now.\n"));
+ _ ("There is no call that could be resumed right now.\n"));
return;
case PS_LISTEN:
/* expected state, do resume logic */
break;
case PS_ACCEPTED:
- FPRINTF (stderr,
- _("Already talking with `%s', cannot resume a call right now.\n"),
+ fprintf (stderr,
+ _ ("Already talking with `%s', cannot resume a call right now.\n"),
GNUNET_GNSRECORD_pkey_to_zkey (&peer_key));
return;
}
cl = cl_head;
if (NULL == cl)
{
- FPRINTF (stderr,
- _("There is no incoming call to resume here!\n"));
+ fprintf (stderr, _ ("There is no incoming call to resume here!\n"));
return;
}
- if ( (NULL != cl->next) || (NULL != args) )
+ if ((NULL != cl->next) || (NULL != args))
{
for (cl = cl_head; NULL != cl; cl = cl->next)
{
- GNUNET_snprintf (buf, sizeof (buf),
- "%u",
- cl->caller_num);
+ GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num);
if (0 == strcmp (buf, args))
break;
}
}
if (NULL == cl)
{
- FPRINTF (stderr,
- _("There is no incoming call `%s' to resume right now!\n"),
+ fprintf (stderr,
+ _ ("There is no incoming call `%s' to resume right now!\n"),
args);
return;
}
cl_active = cl;
- GNUNET_CONVERSATION_caller_resume (cl_active->caller,
- speaker,
- mic);
+ GNUNET_CONVERSATION_caller_resume (cl_active->caller, speaker, mic);
phone_state = PS_ACCEPTED;
}
{
case PS_LOOKUP_EGO:
case PS_ERROR:
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
- _("There is no call that could be cancelled right now.\n"));
+ _ ("There is no call that could be cancelled right now.\n"));
return;
case PS_LISTEN:
/* look for active incoming calls to refuse */
cl = cl_head;
if (NULL == cl)
{
- FPRINTF (stderr,
- _("There is no incoming call to refuse here!\n"));
+ fprintf (stderr, _ ("There is no incoming call to refuse here!\n"));
return;
}
- if ( (NULL != cl->next) || (NULL != args) )
+ if ((NULL != cl->next) || (NULL != args))
{
for (cl = cl_head; NULL != cl; cl = cl->next)
{
- GNUNET_snprintf (buf, sizeof (buf),
- "%u",
- cl->caller_num);
+ GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num);
if (0 == strcmp (buf, args))
break;
}
}
if (NULL == cl)
{
- FPRINTF (stderr,
- _("There is no incoming call `%s' to refuse right now!\n"),
+ fprintf (stderr,
+ _ ("There is no incoming call `%s' to refuse right now!\n"),
args);
return;
}
GNUNET_CONVERSATION_caller_hang_up (cl->caller);
- GNUNET_CONTAINER_DLL_remove (cl_head,
- cl_tail,
- cl);
+ GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl);
GNUNET_free (cl);
break;
case PS_ACCEPTED:
* List of supported commands.
*/
static struct VoipCommand commands[] = {
- {"/address", &do_address,
- gettext_noop ("Use `/address' to find out which address this phone should have in GNS")},
- {"/call", &do_call,
- gettext_noop ("Use `/call USER.gnu' to call USER")},
- {"/accept", &do_accept,
+ {"/address",
+ &do_address,
+ gettext_noop (
+ "Use `/address' to find out which address this phone should have in GNS")},
+ {"/call", &do_call, gettext_noop ("Use `/call USER.gnu' to call USER")},
+ {"/accept",
+ &do_accept,
gettext_noop ("Use `/accept #NUM' to accept incoming call #NUM")},
- {"/suspend", &do_suspend,
+ {"/suspend",
+ &do_suspend,
gettext_noop ("Use `/suspend' to suspend the active call")},
- {"/resume", &do_resume,
- gettext_noop ("Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.")},
- {"/cancel", &do_reject,
+ {"/resume",
+ &do_resume,
+ gettext_noop (
+ "Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.")},
+ {"/cancel",
+ &do_reject,
gettext_noop ("Use `/cancel' to reject or terminate a call")},
- {"/status", &do_status,
+ {"/status",
+ &do_status,
gettext_noop ("Use `/status' to print status information")},
- {"/quit", &do_quit,
+ {"/quit",
+ &do_quit,
gettext_noop ("Use `/quit' to terminate gnunet-conversation")},
- {"/help", &do_help,
+ {"/help",
+ &do_help,
gettext_noop ("Use `/help command' to get help for a specific command")},
- {"", &do_unknown,
- NULL},
+ {"", &do_unknown, NULL},
{NULL, NULL, NULL},
};
unsigned int i;
i = 0;
- while ( (NULL != args) &&
- (0 != strlen (args)) &&
- (commands[i].Action != &do_help))
+ 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));
+ fprintf (stdout, "%s\n", gettext (commands[i].helptext));
return;
}
i++;
}
i = 0;
- FPRINTF (stdout,
- "%s",
- "Available commands:\n");
+ fprintf (stdout, "%s", "Available commands:\n");
while (commands[i].Action != &do_help)
{
- FPRINTF (stdout,
- "%s\n",
- gettext (commands[i].command));
+ fprintf (stdout, "%s\n", gettext (commands[i].command));
i++;
}
- FPRINTF (stdout,
- "%s",
- "\n");
- FPRINTF (stdout,
- "%s\n",
- gettext (commands[i].helptext));
+ fprintf (stdout, "%s", "\n");
+ fprintf (stdout, "%s\n", gettext (commands[i].helptext));
}
* @param str_len number of bytes to process in @a message
*/
static void
-handle_command_string (char *message,
- size_t str_len)
+handle_command_string (char *message, size_t str_len)
{
size_t i;
const char *ptr;
if (0 == strlen (message))
return;
i = 0;
- while ((NULL != commands[i].command) &&
- (0 != strncasecmp (commands[i].command, message,
- strlen (commands[i].command))))
+ while (
+ (NULL != commands[i].command) &&
+ (0 !=
+ strncasecmp (commands[i].command, message, strlen (commands[i].command))))
i++;
ptr = &message[strlen (commands[i].command)];
while (isspace ((unsigned char) *ptr))
handle_cmd_task =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
stdin_fh,
- &handle_command, NULL);
+ &handle_command,
+ NULL);
/* read message from command line and handle it */
- memset (message,
- 0,
- MAX_MESSAGE_LENGTH + 1);
- if (NULL == fgets (message,
- MAX_MESSAGE_LENGTH,
- stdin))
+ memset (message, 0, MAX_MESSAGE_LENGTH + 1);
+ if (NULL == fgets (message, MAX_MESSAGE_LENGTH, stdin))
return;
- handle_command_string (message,
- strlen (message));
+ handle_command_string (message, strlen (message));
}
if (ego == my_caller_id)
{
if (verbose)
- FPRINTF (stdout,
- _("Name of our ego changed to `%s'\n"),
- name);
+ fprintf (stdout, _ ("Name of our ego changed to `%s'\n"), name);
GNUNET_free (ego_name);
ego_name = GNUNET_strdup (name);
return;
}
- if (0 != strcmp (name,
- ego_name))
+ if (0 != strcmp (name, ego_name))
return;
if (NULL == ego)
{
if (verbose)
- FPRINTF (stdout,
- _("Our ego `%s' was deleted!\n"),
- ego_name);
+ fprintf (stdout, _ ("Our ego `%s' was deleted!\n"), ego_name);
my_caller_id = NULL;
return;
}
my_caller_id = ego;
- GNUNET_CONFIGURATION_set_value_string (cfg,
- "CONVERSATION",
- "LINE",
- line);
+ GNUNET_CONFIGURATION_set_value_string (cfg, "CONVERSATION", "LINE", line);
start_phone ();
}
mic = GNUNET_MICROPHONE_create_from_hardware (cfg);
if (NULL == ego_name)
{
- FPRINTF (stderr,
- "%s",
- _("You must specify the NAME of an ego to use\n"));
+ fprintf (stderr, "%s", _ ("You must specify the NAME of an ego to use\n"));
return;
}
- id = GNUNET_IDENTITY_connect (cfg,
- &identity_cb,
- NULL);
+ id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
#ifdef WINDOWS
if (stdin_fh == NULL)
{
static char cpid[64];
- static char *args[] = {"gnunet-helper-w32-console.exe", "chars",
- XSTRINGIFY (MAX_MESSAGE_LENGTH), cpid, NULL};
+ static char *args[] = {"gnunet-helper-w32-console.exe",
+ "chars",
+ XSTRINGIFY (MAX_MESSAGE_LENGTH),
+ cpid,
+ NULL};
snprintf (cpid, 64, "%d", GetCurrentProcessId ());
- stdin_hlp = GNUNET_HELPER_start (
- GNUNET_NO,
- "gnunet-helper-w32-console",
- args,
- console_reader_chars,
- NULL,
- NULL);
+ stdin_hlp = GNUNET_HELPER_start (GNUNET_NO,
+ "gnunet-helper-w32-console",
+ args,
+ console_reader_chars,
+ NULL,
+ NULL);
if (NULL == stdin_hlp)
{
- FPRINTF (stderr,
- "%s",
- _("Failed to start gnunet-helper-w32-console\n"));
+ fprintf (stderr, "%s", _ ("Failed to start gnunet-helper-w32-console\n"));
return;
}
}
else
#endif
- handle_cmd_task =
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
- &handle_command, NULL);
- GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
- NULL);
+ handle_cmd_task =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
+ &handle_command,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL);
}
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_string ('e',
- "ego",
- "NAME",
- gettext_noop ("sets the NAME of the ego to use for the caller ID"),
- &ego_name),
- GNUNET_GETOPT_option_string ('p',
- "phone",
- "LINE",
- gettext_noop ("sets the LINE to use for the phone"),
- &line),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_string (
+ 'e',
+ "ego",
+ "NAME",
+ gettext_noop ("sets the NAME of the ego to use for the caller ID"),
+ &ego_name),
+ GNUNET_GETOPT_option_string ('p',
+ "phone",
+ "LINE",
+ gettext_noop (
+ "sets the LINE to use for the phone"),
+ &line),
+ GNUNET_GETOPT_OPTION_END};
int ret;
#ifndef WINDOWS
int flags;
flags = fcntl (0, F_GETFL, 0);
flags |= O_NONBLOCK;
if (0 != fcntl (0, F_SETFL, flags))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "fcntl");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0);
#else
if (FILE_TYPE_CHAR == GetFileType ((HANDLE) _get_osfhandle (0)))
stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0);
#endif
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-conversation",
- gettext_noop ("Enables having a conversation with other GNUnet users."),
- options,
- &run, NULL);
+ ret =
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-conversation",
+ gettext_noop (
+ "Enables having a conversation with other GNUnet users."),
+ options,
+ &run,
+ NULL);
GNUNET_free ((void *) argv);
if (NULL != cfg)
{
case GNUNET_CORE_KX_ITERATION_FINISHED:
return;
case GNUNET_CORE_KX_CORE_DISCONNECT:
- FPRINTF (stderr,
+ fprintf (stderr,
"%s\n",
_ ("Connection to CORE service lost (reconnecting)"));
return;
break;
}
now_str = GNUNET_STRINGS_absolute_time_to_string (now);
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("%24s: %-30s %4s (timeout in %6s)\n"),
now_str,
state_str,
(void) cfgfile;
if (NULL != args[0])
{
- FPRINTF (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
+ fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
return;
}
mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL);
if (NULL == mh)
{
- FPRINTF (stderr, "%s", _ ("Failed to connect to CORE service!\n"));
+ fprintf (stderr, "%s", _ ("Failed to connect to CORE service!\n"));
return;
}
GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
if (0 == delta)
delta = 1;
- FPRINTF (stderr,
+ fprintf (stderr,
"\nThroughput was %llu kb/s\n",
total_bytes * 1000000LL / 1024 / delta);
GAUGER ("CORE",
(unsigned int) ntohs (hdr->header.size));
n++;
if (0 == (n % (TOTAL_MSGS / 100)))
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
".");
if (n == TOTAL_MSGS)
static void
timeout_task (void *cls)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Timeout.\n");
if (NULL != p1.ch)
enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG;
measure_task = NULL;
- FPRINTF (stdout, "%s", "\n");
+ fprintf (stdout, "%s", "\n");
running = GNUNET_NO;
delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
ntohl (hdr->num));
n++;
if (0 == (n % 10))
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
if (GNUNET_YES == running)
do_transmit (NULL);
#include "gnunet_datacache_plugin.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "datacache", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "datacache", __VA_ARGS__)
-#define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache", op, fn)
+#define LOG_STRERROR_FILE(kind, op, fn) \
+ GNUNET_log_from_strerror_file (kind, "datacache", op, fn)
/**
* Internal state of the datacache library.
* How much space is in use right now?
*/
unsigned long long utilization;
-
};
* @param size number of bytes that were made available
*/
static void
-env_delete_notify (void *cls,
- const struct GNUNET_HashCode *key,
- size_t size)
+env_delete_notify (void *cls, const struct GNUNET_HashCode *key, size_t size)
{
struct GNUNET_DATACACHE_Handle *h = cls;
GNUNET_h2s (key));
GNUNET_assert (h->utilization >= size);
h->utilization -= size;
- GNUNET_CONTAINER_bloomfilter_remove (h->filter,
- key);
+ GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
GNUNET_STATISTICS_update (h->stats,
gettext_noop ("# bytes stored"),
- - (long long) size,
+ -(long long) size,
GNUNET_NO);
GNUNET_STATISTICS_update (h->stats,
gettext_noop ("# items stored"),
char *name;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_size (cfg,
- section,
- "QUOTA",
- "a))
+ GNUNET_CONFIGURATION_get_value_size (cfg, section, "QUOTA", "a))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- section,
- "QUOTA");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, "QUOTA");
return NULL;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- section,
- "DATABASE",
- &name))
+ GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- section,
- "DATABASE");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, "DATABASE");
return NULL;
}
- bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
+ bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
ret = GNUNET_new (struct GNUNET_DATACACHE_Handle);
if (GNUNET_YES !=
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- section,
- "DISABLE_BF"))
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "DISABLE_BF"))
{
if (GNUNET_YES !=
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- section,
- "DISABLE_BF_RC"))
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "DISABLE_BF_RC"))
{
ret->bloom_name = GNUNET_DISK_mktemp ("gnunet-datacachebloom");
}
if (NULL != ret->bloom_name)
{
- ret->filter = GNUNET_CONTAINER_bloomfilter_load (ret->bloom_name,
- quota / 1024, /* 8 bit per entry in DB, expect 1k entries */
- 5);
+ ret->filter = GNUNET_CONTAINER_bloomfilter_load (
+ ret->bloom_name,
+ quota / 1024, /* 8 bit per entry in DB, expect 1k entries */
+ 5);
}
if (NULL == ret->filter)
{
- ret->filter = GNUNET_CONTAINER_bloomfilter_init (NULL,
- bf_size,
- 5); /* approx. 3% false positives at max use */
+ ret->filter =
+ GNUNET_CONTAINER_bloomfilter_init (NULL,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
}
}
ret->stats = GNUNET_STATISTICS_create ("datacache", cfg);
ret->env.cls = ret;
ret->env.delete_notify = &env_delete_notify;
ret->env.quota = quota;
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Loading `%s' datacache plugin\n"),
- name);
- GNUNET_asprintf (&libname,
- "libgnunet_plugin_datacache_%s",
- name);
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("Loading `%s' datacache plugin\n"), name);
+ GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name);
ret->short_name = name;
ret->lib_name = libname;
ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
if (ret->api == NULL)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load datacache plugin for `%s'\n"),
+ _ ("Failed to load datacache plugin for `%s'\n"),
name);
GNUNET_DATACACHE_destroy (ret);
return NULL;
if (NULL != h->filter)
GNUNET_CONTAINER_bloomfilter_free (h->filter);
if (NULL != h->api)
- GNUNET_break (NULL ==
- GNUNET_PLUGIN_unload (h->lib_name,
- h->api));
+ GNUNET_break (NULL == GNUNET_PLUGIN_unload (h->lib_name, h->api));
GNUNET_free (h->lib_name);
GNUNET_free (h->short_name);
GNUNET_free (h->section);
if (NULL != h->bloom_name)
{
- if (0 != UNLINK (h->bloom_name))
+ if (0 != unlink (h->bloom_name))
GNUNET_log_from_strerror_file (GNUNET_ERROR_TYPE_WARNING,
"datacache",
"unlink",
h->bloom_name);
GNUNET_free (h->bloom_name);
}
- GNUNET_STATISTICS_destroy (h->stats,
- GNUNET_NO);
+ GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
GNUNET_free (h);
}
const char *data,
enum GNUNET_BLOCK_Type type,
struct GNUNET_TIME_Absolute discard_time,
- unsigned int path_info_len,
- const struct GNUNET_PeerIdentity *path_info)
+ unsigned int path_info_len,
+ const struct GNUNET_PeerIdentity *path_info)
{
ssize_t used;
used = h->api->put (h->api->cls,
key,
xor_distance,
- data_size,
+ data_size,
data,
- type,
+ type,
discard_time,
- path_info_len,
+ path_info_len,
path_info);
if (-1 == used)
{
"Stored data under key `%s' in cache\n",
GNUNET_h2s (key));
if (NULL != h->filter)
- GNUNET_CONTAINER_bloomfilter_add (h->filter,
- key);
+ GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
GNUNET_STATISTICS_update (h->stats,
gettext_noop ("# bytes stored"),
used,
1,
GNUNET_NO);
while (h->utilization + used > h->env.quota)
- GNUNET_assert (GNUNET_OK ==
- h->api->del (h->api->cls));
+ GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
h->utilization += used;
return GNUNET_OK;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Processing request for key `%s'\n",
GNUNET_h2s (key));
- if ( (NULL != h->filter) &&
- (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key)) )
+ if ((NULL != h->filter) &&
+ (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key)))
{
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# requests filtered by bloom filter"),
+ gettext_noop (
+ "# requests filtered by bloom filter"),
1,
GNUNET_NO);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Bloomfilter filters request for key `%s'\n",
GNUNET_h2s (key));
- return 0; /* can not be present */
+ return 0; /* can not be present */
}
- return h->api->get (h->api->cls,
- key,
- type,
- iter,
- iter_cls);
+ return h->api->get (h->api->cls, key, type, iter, iter_cls);
}
void *iter_cls)
{
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# requests for random value received"),
+ gettext_noop (
+ "# requests for random value received"),
1,
GNUNET_NO);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Processing request for random value\n");
- return h->api->get_random (h->api->cls,
- iter,
- iter_cls);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing request for random value\n");
+ return h->api->get_random (h->api->cls, iter, iter_cls);
}
void *iter_cls)
{
GNUNET_STATISTICS_update (h->stats,
- gettext_noop ("# proximity search requests received"),
+ gettext_noop (
+ "# proximity search requests received"),
1,
GNUNET_NO);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Processing proximity search at `%s'\n",
GNUNET_h2s (key));
- return h->api->get_closest (h->api->cls,
- key,
- num_results,
- iter,
- iter_cls);
+ return h->api->get_closest (h->api->cls, key, num_results, iter, iter_cls);
}
if (h == NULL)
{
- FPRINTF (stderr, "%s", "Failed to initialize datacache. Database likely not setup, skipping test.\n");
+ fprintf (stderr, "%s", "Failed to initialize datacache. Database likely not setup, skipping test.\n");
ok = 77; /* mark test as skipped */
return;
}
for (i = 0; i < ITERATIONS; i++)
{
if (0 == i % (ITERATIONS / 80))
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
ASSERT (GNUNET_OK ==
GNUNET_DATACACHE_put (h, &k, sizeof (struct GNUNET_HashCode),
0, NULL));
k = n;
}
- FPRINTF (stderr, "%s", "\n");
- FPRINTF (stdout, "Stored %u items in %s\n", ITERATIONS,
+ fprintf (stderr, "%s", "\n");
+ fprintf (stdout, "Stored %u items in %s\n", ITERATIONS,
GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES));
GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name);
GAUGER (gstr, "Time to PUT item in datacache",
for (i = 0; i < ITERATIONS; i++)
{
if (0 == i % (ITERATIONS / 80))
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n);
k = n;
}
- FPRINTF (stderr, "%s", "\n");
- FPRINTF (stdout,
+ fprintf (stderr, "%s", "\n");
+ fprintf (stdout,
"Found %u/%u items in %s (%u were deleted during storage processing)\n",
found, ITERATIONS,
GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES),
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
"perf-datacache", "nohelp", options, &run, NULL);
if ( (0 != ok) && (77 != ok) )
- FPRINTF (stderr, "Missed some perfcases: %d\n", ok);
+ fprintf (stderr, "Missed some perfcases: %d\n", ok);
return ok;
}
#include "gnunet_sq_lib.h"
#include <sqlite3.h>
-#define LOG(kind,...) GNUNET_log_from (kind, "datacache-sqlite", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "datacache-sqlite", __VA_ARGS__)
-#define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache-sqlite", op, fn)
+#define LOG_STRERROR_FILE(kind, op, fn) \
+ GNUNET_log_from_strerror_file (kind, "datacache-sqlite", op, fn)
/**
* How much overhead do we assume per entry in the
* datacache?
*/
-#define OVERHEAD (sizeof(struct GNUNET_HashCode) + 36)
+#define OVERHEAD (sizeof (struct GNUNET_HashCode) + 36)
/**
* Context for all functions in this plugin.
* @param level log level
* @param cmd failed command
*/
-#define LOG_SQLITE(db, level, cmd) do { LOG (level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); } while(0)
+#define LOG_SQLITE(db, level, cmd) \
+ do \
+ { \
+ LOG (level, \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ sqlite3_errmsg (db)); \
+ } while (0)
/**
* @param db database handle
* @param cmd SQL command to execute
*/
-#define SQLITE3_EXEC(db, cmd) do { emsg = NULL; if (SQLITE_OK != sqlite3_exec(db, cmd, NULL, NULL, &emsg)) { LOG (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_exec", __FILE__, __LINE__, emsg); sqlite3_free(emsg); } } while(0)
+#define SQLITE3_EXEC(db, cmd) \
+ do \
+ { \
+ emsg = NULL; \
+ if (SQLITE_OK != sqlite3_exec (db, cmd, NULL, NULL, &emsg)) \
+ { \
+ LOG (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ "sqlite3_exec", \
+ __FILE__, \
+ __LINE__, \
+ emsg); \
+ sqlite3_free (emsg); \
+ } \
+ } while (0)
/**
*/
static int
sq_prepare (sqlite3 *dbh,
- const char *zSql, /* SQL statement, UTF-8 encoded */
+ const char *zSql, /* SQL statement, UTF-8 encoded */
sqlite3_stmt **ppStmt)
-{ /* OUT: Statement handle */
+{ /* OUT: Statement handle */
char *dummy;
return sqlite3_prepare (dbh,
*/
static ssize_t
sqlite_plugin_put (void *cls,
- const struct GNUNET_HashCode *key,
+ const struct GNUNET_HashCode *key,
uint32_t xor_distance,
- size_t size,
+ size_t size,
const char *data,
- enum GNUNET_BLOCK_Type type,
+ enum GNUNET_BLOCK_Type type,
struct GNUNET_TIME_Absolute discard_time,
- unsigned int path_info_len,
- const struct GNUNET_PeerIdentity *path_info)
+ unsigned int path_info_len,
+ const struct GNUNET_PeerIdentity *path_info)
{
struct Plugin *plugin = cls;
uint32_t type32 = type;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint32 (&type32),
- GNUNET_SQ_query_param_absolute_time (&discard_time),
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_uint32 (&xor_distance),
- GNUNET_SQ_query_param_fixed_size (data, size),
- GNUNET_SQ_query_param_fixed_size (path_info,
- path_info_len * sizeof (struct GNUNET_PeerIdentity)),
- GNUNET_SQ_query_param_end
- };
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_uint32 (&type32),
+ GNUNET_SQ_query_param_absolute_time (&discard_time),
+ GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_uint32 (&xor_distance),
+ GNUNET_SQ_query_param_fixed_size (data, size),
+ GNUNET_SQ_query_param_fixed_size (path_info,
+ path_info_len *
+ sizeof (struct GNUNET_PeerIdentity)),
+ GNUNET_SQ_query_param_end};
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Processing PUT of %u bytes with key `%s' and expiration %s\n",
(unsigned int) size,
GNUNET_h2s (key),
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (discard_time),
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
+ discard_time),
GNUNET_YES));
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->insert_stmt,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->insert_stmt, params))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_xxx");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->insert_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->insert_stmt);
return -1;
}
- if (SQLITE_DONE !=
- sqlite3_step (plugin->insert_stmt))
+ if (SQLITE_DONE != sqlite3_step (plugin->insert_stmt))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->insert_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->insert_stmt);
return -1;
}
plugin->num_items++;
- GNUNET_SQ_reset (plugin->dbh,
- plugin->insert_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->insert_stmt);
return size + OVERHEAD;
}
unsigned int total;
size_t psize;
struct GNUNET_PeerIdentity *path;
- struct GNUNET_SQ_QueryParam params_count[] = {
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_uint32 (&type32),
- GNUNET_SQ_query_param_absolute_time (&now),
- GNUNET_SQ_query_param_end
- };
- struct GNUNET_SQ_QueryParam params_select[] = {
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_uint32 (&type32),
- GNUNET_SQ_query_param_absolute_time (&now),
- GNUNET_SQ_query_param_uint32 (&off),
- GNUNET_SQ_query_param_end
- };
- struct GNUNET_SQ_ResultSpec rs[] = {
- GNUNET_SQ_result_spec_variable_size (&dat,
- &size),
- GNUNET_SQ_result_spec_absolute_time (&exp),
- GNUNET_SQ_result_spec_variable_size ((void **) &path,
- &psize),
- GNUNET_SQ_result_spec_end
- };
+ struct GNUNET_SQ_QueryParam params_count[] =
+ {GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_uint32 (&type32),
+ GNUNET_SQ_query_param_absolute_time (&now),
+ GNUNET_SQ_query_param_end};
+ struct GNUNET_SQ_QueryParam params_select[] =
+ {GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_uint32 (&type32),
+ GNUNET_SQ_query_param_absolute_time (&now),
+ GNUNET_SQ_query_param_uint32 (&off),
+ GNUNET_SQ_query_param_end};
+ struct GNUNET_SQ_ResultSpec rs[] =
+ {GNUNET_SQ_result_spec_variable_size (&dat, &size),
+ GNUNET_SQ_result_spec_absolute_time (&exp),
+ GNUNET_SQ_result_spec_variable_size ((void **) &path, &psize),
+ GNUNET_SQ_result_spec_end};
now = GNUNET_TIME_absolute_get ();
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Processing GET for key `%s'\n",
GNUNET_h2s (key));
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->get_count_stmt,
- params_count))
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->get_count_stmt, params_count))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_xxx");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_count_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_count_stmt);
return 0;
}
- if (SQLITE_ROW !=
- sqlite3_step (plugin->get_count_stmt))
+ if (SQLITE_ROW != sqlite3_step (plugin->get_count_stmt))
{
- LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ LOG_SQLITE (plugin->dbh,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_count_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_count_stmt);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"No content found when processing GET for key `%s'\n",
GNUNET_h2s (key));
return 0;
}
- total = sqlite3_column_int (plugin->get_count_stmt,
- 0);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_count_stmt);
- if ( (0 == total) ||
- (NULL == iter) )
+ total = sqlite3_column_int (plugin->get_count_stmt, 0);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_count_stmt);
+ if ((0 == total) || (NULL == iter))
{
if (0 == total)
LOG (GNUNET_ERROR_TYPE_DEBUG,
}
cnt = 0;
- off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- total);
+ off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, total);
while (cnt < total)
{
off = (off + 1) % total;
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->get_stmt,
- params_select))
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->get_stmt, params_select))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_xxx");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
return cnt;
}
- if (SQLITE_ROW !=
- sqlite3_step (plugin->get_stmt))
+ if (SQLITE_ROW != sqlite3_step (plugin->get_stmt))
break;
- if (GNUNET_OK !=
- GNUNET_SQ_extract_result (plugin->get_stmt,
- rs))
+ if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->get_stmt, rs))
{
GNUNET_break (0);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
break;
}
if (0 != psize % sizeof (struct GNUNET_PeerIdentity))
"Found %u-byte result when processing GET for key `%s'\n",
(unsigned int) size,
GNUNET_h2s (key));
- if (GNUNET_OK != iter (iter_cls,
- key,
- size,
- dat,
- type,
- exp,
- psize,
- path))
+ if (GNUNET_OK != iter (iter_cls, key, size, dat, type, exp, psize, path))
{
GNUNET_SQ_cleanup_result (rs);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
break;
}
GNUNET_SQ_cleanup_result (rs);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
}
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_stmt);
return cnt;
}
size_t dsize;
struct GNUNET_HashCode hc;
struct GNUNET_TIME_Absolute now;
- struct GNUNET_SQ_ResultSpec rs[] = {
- GNUNET_SQ_result_spec_uint64 (&rowid),
- GNUNET_SQ_result_spec_auto_from_type (&hc),
- GNUNET_SQ_result_spec_variable_size ((void **) &data,
- &dsize),
- GNUNET_SQ_result_spec_end
- };
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint64 (&rowid),
- GNUNET_SQ_query_param_end
- };
- struct GNUNET_SQ_QueryParam time_params[] = {
- GNUNET_SQ_query_param_absolute_time (&now),
- GNUNET_SQ_query_param_end
- };
-
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Processing DEL\n");
+ struct GNUNET_SQ_ResultSpec rs[] =
+ {GNUNET_SQ_result_spec_uint64 (&rowid),
+ GNUNET_SQ_result_spec_auto_from_type (&hc),
+ GNUNET_SQ_result_spec_variable_size ((void **) &data, &dsize),
+ GNUNET_SQ_result_spec_end};
+ struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (&rowid),
+ GNUNET_SQ_query_param_end};
+ struct GNUNET_SQ_QueryParam time_params[] =
+ {GNUNET_SQ_query_param_absolute_time (&now), GNUNET_SQ_query_param_end};
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing DEL\n");
now = GNUNET_TIME_absolute_get ();
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->del_expired_stmt,
- time_params))
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->del_expired_stmt, time_params))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->del_expired_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->del_expired_stmt);
return GNUNET_SYSERR;
}
- if ( (SQLITE_ROW !=
- sqlite3_step (plugin->del_expired_stmt)) ||
- (GNUNET_OK !=
- GNUNET_SQ_extract_result (plugin->del_expired_stmt,
- rs)) )
+ if ((SQLITE_ROW != sqlite3_step (plugin->del_expired_stmt)) ||
+ (GNUNET_OK != GNUNET_SQ_extract_result (plugin->del_expired_stmt, rs)))
{
- GNUNET_SQ_reset (plugin->dbh,
- plugin->del_expired_stmt);
- if (SQLITE_ROW !=
- sqlite3_step (plugin->del_select_stmt))
+ GNUNET_SQ_reset (plugin->dbh, plugin->del_expired_stmt);
+ if (SQLITE_ROW != sqlite3_step (plugin->del_select_stmt))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->del_select_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->del_select_stmt);
return GNUNET_SYSERR;
}
- if (GNUNET_OK !=
- GNUNET_SQ_extract_result (plugin->del_select_stmt,
- rs))
+ if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->del_select_stmt, rs))
{
- GNUNET_SQ_reset (plugin->dbh,
- plugin->del_select_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->del_select_stmt);
GNUNET_break (0);
return GNUNET_SYSERR;
}
}
GNUNET_SQ_cleanup_result (rs);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->del_select_stmt);
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->del_stmt,
- params))
+ GNUNET_SQ_reset (plugin->dbh, plugin->del_select_stmt);
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->del_stmt, params))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->del_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->del_stmt);
return GNUNET_SYSERR;
}
- if (SQLITE_DONE !=
- sqlite3_step (plugin->del_stmt))
+ if (SQLITE_DONE != sqlite3_step (plugin->del_stmt))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->del_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->del_stmt);
return GNUNET_SYSERR;
}
plugin->num_items--;
- plugin->env->delete_notify (plugin->env->cls,
- &hc,
- dsize + OVERHEAD);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->del_stmt);
+ plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD);
+ GNUNET_SQ_reset (plugin->dbh, plugin->del_stmt);
return GNUNET_OK;
}
uint32_t type;
struct GNUNET_PeerIdentity *path;
struct GNUNET_HashCode key;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint32 (&off),
- GNUNET_SQ_query_param_end
- };
- struct GNUNET_SQ_ResultSpec rs[] = {
- GNUNET_SQ_result_spec_variable_size (&dat,
- &size),
- GNUNET_SQ_result_spec_absolute_time (&exp),
- GNUNET_SQ_result_spec_variable_size ((void **) &path,
- &psize),
- GNUNET_SQ_result_spec_auto_from_type (&key),
- GNUNET_SQ_result_spec_uint32 (&type),
- GNUNET_SQ_result_spec_end
- };
+ struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint32 (&off),
+ GNUNET_SQ_query_param_end};
+ struct GNUNET_SQ_ResultSpec rs[] =
+ {GNUNET_SQ_result_spec_variable_size (&dat, &size),
+ GNUNET_SQ_result_spec_absolute_time (&exp),
+ GNUNET_SQ_result_spec_variable_size ((void **) &path, &psize),
+ GNUNET_SQ_result_spec_auto_from_type (&key),
+ GNUNET_SQ_result_spec_uint32 (&type),
+ GNUNET_SQ_result_spec_end};
if (0 == plugin->num_items)
return 0;
if (NULL == iter)
return 1;
- off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- plugin->num_items);
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->get_random_stmt,
- params))
+ off =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, plugin->num_items);
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->get_random_stmt, params))
{
return 0;
}
- if (SQLITE_ROW !=
- sqlite3_step (plugin->get_random_stmt))
+ if (SQLITE_ROW != sqlite3_step (plugin->get_random_stmt))
{
GNUNET_break (0);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_random_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_random_stmt);
return 0;
}
- if (GNUNET_OK !=
- GNUNET_SQ_extract_result (plugin->get_random_stmt,
- rs))
+ if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->get_random_stmt, rs))
{
GNUNET_break (0);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_random_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_random_stmt);
return 0;
}
if (0 != psize % sizeof (struct GNUNET_PeerIdentity))
psize,
path);
GNUNET_SQ_cleanup_result (rs);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_random_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_random_stmt);
return 1;
}
uint32_t type;
struct GNUNET_HashCode hc;
struct GNUNET_PeerIdentity *path;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_absolute_time (&now),
- GNUNET_SQ_query_param_uint32 (&num_results32),
- GNUNET_SQ_query_param_end
- };
- struct GNUNET_SQ_ResultSpec rs[] = {
- GNUNET_SQ_result_spec_variable_size (&dat,
- &size),
- GNUNET_SQ_result_spec_absolute_time (&exp),
- GNUNET_SQ_result_spec_variable_size ((void **) &path,
- &psize),
- GNUNET_SQ_result_spec_uint32 (&type),
- GNUNET_SQ_result_spec_auto_from_type (&hc),
- GNUNET_SQ_result_spec_end
- };
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_absolute_time (&now),
+ GNUNET_SQ_query_param_uint32 (&num_results32),
+ GNUNET_SQ_query_param_end};
+ struct GNUNET_SQ_ResultSpec rs[] =
+ {GNUNET_SQ_result_spec_variable_size (&dat, &size),
+ GNUNET_SQ_result_spec_absolute_time (&exp),
+ GNUNET_SQ_result_spec_variable_size ((void **) &path, &psize),
+ GNUNET_SQ_result_spec_uint32 (&type),
+ GNUNET_SQ_result_spec_auto_from_type (&hc),
+ GNUNET_SQ_result_spec_end};
now = GNUNET_TIME_absolute_get ();
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Processing GET_CLOSEST for key `%s'\n",
GNUNET_h2s (key));
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->get_closest_stmt,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->get_closest_stmt, params))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_bind_xxx");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_closest_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_closest_stmt);
return 0;
}
cnt = 0;
- while (SQLITE_ROW ==
- sqlite3_step (plugin->get_closest_stmt))
+ while (SQLITE_ROW == sqlite3_step (plugin->get_closest_stmt))
{
- if (GNUNET_OK !=
- GNUNET_SQ_extract_result (plugin->get_closest_stmt,
- rs))
+ if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->get_closest_stmt, rs))
{
GNUNET_break (0);
break;
"Found %u-byte result at %s when processing GET_CLOSE\n",
(unsigned int) size,
GNUNET_h2s (&hc));
- if (GNUNET_OK != iter (iter_cls,
- &hc,
- size,
- dat,
- type,
- exp,
- psize,
- path))
+ if (GNUNET_OK != iter (iter_cls, &hc, size, dat, type, exp, psize, path))
{
GNUNET_SQ_cleanup_result (rs);
break;
}
GNUNET_SQ_cleanup_result (rs);
}
- GNUNET_SQ_reset (plugin->dbh,
- plugin->get_closest_stmt);
+ GNUNET_SQ_reset (plugin->dbh, plugin->get_closest_stmt);
return cnt;
}
sqlite3 *dbh;
char *emsg;
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- "datacache-sqlite",
- "IN_MEMORY"))
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "datacache-sqlite",
+ "IN_MEMORY"))
{
if (SQLITE_OK != sqlite3_open (":memory:", &dbh))
return NULL;
{
fn = GNUNET_DISK_mktemp ("gnunet-datacache");
if (fn == NULL)
- {
- GNUNET_break (0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
/* fn should be UTF-8-encoded. If it isn't, it's a bug. */
fn_utf8 = GNUNET_strdup (fn);
if (SQLITE_OK != sqlite3_open (fn_utf8, &dbh))
SQLITE3_EXEC (dbh, "PRAGMA journal_mode=OFF");
SQLITE3_EXEC (dbh, "PRAGMA synchronous=OFF");
SQLITE3_EXEC (dbh, "PRAGMA page_size=4092");
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- "datacache-sqlite",
- "IN_MEMORY"))
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "datacache-sqlite",
+ "IN_MEMORY"))
SQLITE3_EXEC (dbh, "PRAGMA sqlite_temp_store=3");
SQLITE3_EXEC (dbh,
" key BLOB NOT NULL DEFAULT '',"
" prox INTEGER NOT NULL,"
" value BLOB NOT NULL,"
- " path BLOB DEFAULT '')");
+ " path BLOB DEFAULT '')");
SQLITE3_EXEC (dbh, "CREATE INDEX idx_hashidx ON ds091 (key,type,expire)");
SQLITE3_EXEC (dbh, "CREATE INDEX idx_prox_expire ON ds091 (prox,expire)");
SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire_only ON ds091 (expire)");
plugin->dbh = dbh;
plugin->fn = fn_utf8;
- if ( (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "INSERT INTO ds091 (type, expire, key, prox, value, path) "
- "VALUES (?, ?, ?, ?, ?, ?)",
- &plugin->insert_stmt)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT count(*) FROM ds091 "
- "WHERE key=? AND type=? AND expire >= ?",
- &plugin->get_count_stmt)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT value,expire,path FROM ds091"
- " WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET ?",
- &plugin->get_stmt)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT _ROWID_,key,value FROM ds091"
- " WHERE expire < ?"
- " ORDER BY expire ASC LIMIT 1",
- &plugin->del_expired_stmt)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT _ROWID_,key,value FROM ds091"
- " ORDER BY prox ASC, expire ASC LIMIT 1",
- &plugin->del_select_stmt)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "DELETE FROM ds091 WHERE _ROWID_=?",
- &plugin->del_stmt)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT value,expire,path,key,type FROM ds091 "
- "ORDER BY key LIMIT 1 OFFSET ?",
- &plugin->get_random_stmt)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT value,expire,path,type,key FROM ds091 "
- "WHERE key>=? AND expire >= ? ORDER BY KEY ASC LIMIT ?",
- &plugin->get_closest_stmt))
- )
+ if ((SQLITE_OK !=
+ sq_prepare (plugin->dbh,
+ "INSERT INTO ds091 (type, expire, key, prox, value, path) "
+ "VALUES (?, ?, ?, ?, ?, ?)",
+ &plugin->insert_stmt)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT count(*) FROM ds091 "
+ "WHERE key=? AND type=? AND expire >= ?",
+ &plugin->get_count_stmt)) ||
+ (SQLITE_OK !=
+ sq_prepare (plugin->dbh,
+ "SELECT value,expire,path FROM ds091"
+ " WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET ?",
+ &plugin->get_stmt)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT _ROWID_,key,value FROM ds091"
+ " WHERE expire < ?"
+ " ORDER BY expire ASC LIMIT 1",
+ &plugin->del_expired_stmt)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT _ROWID_,key,value FROM ds091"
+ " ORDER BY prox ASC, expire ASC LIMIT 1",
+ &plugin->del_select_stmt)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "DELETE FROM ds091 WHERE _ROWID_=?",
+ &plugin->del_stmt)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT value,expire,path,key,type FROM ds091 "
+ "ORDER BY key LIMIT 1 OFFSET ?",
+ &plugin->get_random_stmt)) ||
+ (SQLITE_OK !=
+ sq_prepare (plugin->dbh,
+ "SELECT value,expire,path,type,key FROM ds091 "
+ "WHERE key>=? AND expire >= ? ORDER BY KEY ASC LIMIT ?",
+ &plugin->get_closest_stmt)))
{
LOG_SQLITE (plugin->dbh,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sq_prepare");
- GNUNET_break (SQLITE_OK ==
- sqlite3_close (plugin->dbh));
+ GNUNET_break (SQLITE_OK == sqlite3_close (plugin->dbh));
GNUNET_free (plugin);
return NULL;
}
api->del = &sqlite_plugin_del;
api->get_random = &sqlite_plugin_get_random;
api->get_closest = &sqlite_plugin_get_closest;
- LOG (GNUNET_ERROR_TYPE_INFO,
- "Sqlite datacache running\n");
+ LOG (GNUNET_ERROR_TYPE_INFO, "Sqlite datacache running\n");
return api;
}
sqlite3_stmt *stmt;
#endif
-#if !WINDOWS || defined(__CYGWIN__)
- if ( (NULL != plugin->fn) &&
- (0 != UNLINK (plugin->fn)) )
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- plugin->fn);
+#if ! WINDOWS || defined(__CYGWIN__)
+ if ((NULL != plugin->fn) && (0 != unlink (plugin->fn)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn);
GNUNET_free_non_null (plugin->fn);
#endif
sqlite3_finalize (plugin->insert_stmt);
if (SQLITE_BUSY == result)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Tried to close sqlite without finalizing all prepared statements.\n"));
+ _ (
+ "Tried to close sqlite without finalizing all prepared statements.\n"));
stmt = sqlite3_next_stmt (plugin->dbh, NULL);
while (NULL != stmt)
{
}
#endif
if (SQLITE_OK != result)
- LOG_SQLITE (plugin->dbh,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_close");
-
-#if WINDOWS && !defined(__CYGWIN__)
- if ( (NULL != plugin->fn) &&
- (0 != UNLINK (plugin->fn)) )
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- plugin->fn);
+ LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
+
+#if WINDOWS && ! defined(__CYGWIN__)
+ if ((NULL != plugin->fn) && (0 != unlink (plugin->fn)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn);
GNUNET_free_non_null (plugin->fn);
#endif
GNUNET_free (plugin);
}
-
/* end of plugin_datacache_sqlite.c */
"testcache");
if (h == NULL)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Failed to initialize datacache. Database likely not setup, skipping test.\n");
ok = 77; /* mark test as skipped */
&run,
NULL);
if ( (0 != ok) && (77 != ok) )
- FPRINTF (stderr,
+ fprintf (stderr,
"Missed some testcases: %d\n",
ok);
return ok;
if (h == NULL)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Failed to initialize datacache. Database likely not setup, skipping test.\n");
return;
memset (&k, 0, sizeof (struct GNUNET_HashCode));
for (unsigned int i = 0; i < 10; i++)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
".");
GNUNET_CRYPTO_hash (&k,
}
k = n;
}
- FPRINTF (stderr, "%s", "\n");
+ fprintf (stderr, "%s", "\n");
memset (&k, 0, sizeof (struct GNUNET_HashCode));
for (unsigned int i = 0; i < 10; i++)
{
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
if (i < 2)
ASSERT (0 == GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL));
k = n;
}
- FPRINTF (stderr, "%s", "\n");
+ fprintf (stderr, "%s", "\n");
GNUNET_DATACACHE_destroy (h);
return;
FAILURE:
&run,
NULL);
if (0 != ok)
- FPRINTF (stderr,
+ fprintf (stderr,
"Missed some testcases: %d\n",
ok);
return ok;
* Key under which the item can be found.
*/
struct GNUNET_HashCode key;
-
};
GNUNET_NETWORK_STRUCT_END
qe = NULL;
if (NULL == key)
{
- FPRINTF (stderr,
- _("Dumped %" PRIu64 " records\n"),
- record_count);
+ fprintf (stderr, _ ("Dumped %" PRIu64 " records\n"), record_count);
GNUNET_DISK_file_close (file_handle);
file_handle = NULL;
if (insert)
- start_insert();
+ start_insert ();
else
{
ret = 0;
len = GNUNET_DISK_file_write (file_handle, &dr, sizeof (dr));
if (sizeof (dr) != len)
{
- FPRINTF (stderr,
- _("Short write to file: %zd bytes expecting %zd\n"),
+ fprintf (stderr,
+ _ ("Short write to file: %zd bytes expecting %zd\n"),
len,
sizeof (dr));
ret = 1;
len = GNUNET_DISK_file_write (file_handle, data, size);
if (size != len)
{
- FPRINTF (stderr,
- _("Short write to file: %zd bytes expecting %zd\n"),
+ fprintf (stderr,
+ _ ("Short write to file: %zd bytes expecting %zd\n"),
len,
size);
ret = 1;
}
record_count++;
- do_get(uid + 1);
+ do_get (uid + 1);
}
NULL /* proc_cls */);
if (NULL == qe)
{
- FPRINTF (stderr,
- _("Error queueing datastore GET operation\n"));
+ fprintf (stderr, _ ("Error queueing datastore GET operation\n"));
ret = 1;
GNUNET_SCHEDULER_shutdown ();
}
{
file_handle = GNUNET_DISK_file_open (file_name,
GNUNET_DISK_OPEN_WRITE |
- GNUNET_DISK_OPEN_TRUNCATE |
- GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE,
GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == file_handle)
{
- FPRINTF (stderr,
- _("Unable to open dump file: %s\n"),
- file_name);
+ fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO);
}
GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN);
- do_get(0);
+ do_get (0);
}
qe = NULL;
if (GNUNET_SYSERR == success)
{
- FPRINTF (stderr,
- _("Failed to store item: %s, aborting\n"),
- msg);
+ fprintf (stderr, _ ("Failed to store item: %s, aborting\n"), msg);
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
len = GNUNET_DISK_file_read (file_handle, &dr, sizeof (dr));
if (0 == len)
{
- FPRINTF (stderr,
- _("Inserted %" PRIu64 " records\n"),
- record_count);
+ fprintf (stderr, _ ("Inserted %" PRIu64 " records\n"), record_count);
ret = 0;
GNUNET_SCHEDULER_shutdown ();
return;
}
else if (sizeof (dr) != len)
{
- FPRINTF (stderr,
- _("Short read from file: %zd bytes expecting %zd\n"),
+ fprintf (stderr,
+ _ ("Short read from file: %zd bytes expecting %zd\n"),
len,
sizeof (dr));
ret = 1;
len = GNUNET_DISK_file_read (file_handle, data, size);
if (size != len)
{
- FPRINTF (stderr,
- _("Short read from file: %zd bytes expecting %zd\n"),
+ fprintf (stderr,
+ _ ("Short read from file: %zd bytes expecting %zd\n"),
len,
size);
ret = 1;
NULL);
if (NULL == qe)
{
- FPRINTF (stderr,
- _("Error queueing datastore PUT operation\n"));
+ fprintf (stderr, _ ("Error queueing datastore PUT operation\n"));
ret = 1;
GNUNET_SCHEDULER_shutdown ();
}
GNUNET_DISK_PERM_NONE);
if (NULL == file_handle)
{
- FPRINTF (stderr,
- _("Unable to open dump file: %s\n"),
- file_name);
+ fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
ssize_t len;
len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN);
- if (len != MAGIC_LEN ||
- 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN))
+ if (len != MAGIC_LEN || 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN))
{
- FPRINTF (stderr,
- _("Input file is not of a supported format\n"));
+ fprintf (stderr, _ ("Input file is not of a supported format\n"));
return;
}
put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
datastore = GNUNET_DATASTORE_connect (cfg);
if (NULL == datastore)
{
- FPRINTF (stderr,
- _("Failed connecting to the datastore.\n"));
+ fprintf (stderr, _ ("Failed connecting to the datastore.\n"));
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
}
if (dump)
- start_dump();
+ start_dump ();
else if (insert)
- start_insert();
+ start_insert ();
else
{
- FPRINTF (stderr,
- _("Please choose at least one operation: %s, %s\n"),
+ fprintf (stderr,
+ _ ("Please choose at least one operation: %s, %s\n"),
"dump",
"insert");
ret = 1;
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('d',
- "dump",
- gettext_noop ("Dump all records from the datastore"),
- &dump),
- GNUNET_GETOPT_option_flag ('i',
- "insert",
- gettext_noop ("Insert records into the datastore"),
- &insert),
- GNUNET_GETOPT_option_filename ('f',
- "file",
- "FILENAME",
- gettext_noop ("File to dump or insert"),
- &file_name),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag ('d',
+ "dump",
+ gettext_noop (
+ "Dump all records from the datastore"),
+ &dump),
+ GNUNET_GETOPT_option_flag ('i',
+ "insert",
+ gettext_noop (
+ "Insert records into the datastore"),
+ &insert),
+ GNUNET_GETOPT_option_filename ('f',
+ "file",
+ "FILENAME",
+ gettext_noop ("File to dump or insert"),
+ &file_name),
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
if (GNUNET_OK !=
- GNUNET_PROGRAM_run (argc, argv, "gnunet-datastore",
- gettext_noop ("Manipulate GNUnet datastore"),
- options, &run, NULL))
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-datastore",
+ gettext_noop ("Manipulate GNUnet datastore"),
+ options,
+ &run,
+ NULL))
ret = 1;
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
return ret;
}
* How long are we at most keeping "expired" content
* past the expiration date in the database?
*/
-#define MAX_EXPIRE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+#define MAX_EXPIRE_DELAY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
/**
* How fast are we allowed to query the database for deleting
* expired content? (1 item per second).
*/
-#define MIN_EXPIRE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+#define MIN_EXPIRE_DELAY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
/**
* Name under which we store current space consumption.
* for this plugin.
*/
struct GNUNET_DATASTORE_PluginEnvironment env;
-
};
* Reservation identifier.
*/
int32_t rid;
-
};
-
/**
* Our datastore plugin (NULL if not available).
*/
static void
sync_stats ()
{
- GNUNET_STATISTICS_set (stats,
- quota_stat_name,
- payload,
- GNUNET_YES);
+ GNUNET_STATISTICS_set (stats, quota_stat_name, payload, GNUNET_YES);
GNUNET_STATISTICS_set (stats,
"# utilization by current datastore",
payload,
if (NULL == key)
{
expired_kill_task =
- GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired, NULL);
+ GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired,
+ NULL);
return GNUNET_SYSERR;
}
now = GNUNET_TIME_absolute_get ();
{
/* finished processing */
expired_kill_task =
- GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired, NULL);
+ GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired,
+ NULL);
return GNUNET_SYSERR;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Deleting content `%s' of type %u that expired %s ago\n",
- GNUNET_h2s (key), type,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (expiration,
- now),
- GNUNET_YES));
+ GNUNET_h2s (key),
+ type,
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_difference (expiration, now),
+ GNUNET_YES));
min_expiration = now;
GNUNET_STATISTICS_update (stats,
gettext_noop ("# bytes expired"),
GNUNET_YES);
GNUNET_CONTAINER_bloomfilter_remove (filter, key);
expired_kill_task =
- GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired, NULL);
+ GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired,
+ NULL);
return GNUNET_NO;
}
delete_expired (void *cls)
{
expired_kill_task = NULL;
- plugin->api->get_expiration (plugin->api->cls,
- &expired_processor,
- NULL);
+ plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL);
}
if (NULL == key)
return GNUNET_SYSERR;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n",
- (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
- (unsigned int) priority,
- GNUNET_h2s (key), type,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration),
- GNUNET_YES),
- *need);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n",
+ (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
+ (unsigned int) priority,
+ GNUNET_h2s (key),
+ type,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
+ expiration),
+ GNUNET_YES),
+ *need);
if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need)
*need = 0;
else
min_expiration = expiration;
GNUNET_STATISTICS_update (stats,
gettext_noop ("# bytes purged (low-priority)"),
- size, GNUNET_YES);
+ size,
+ GNUNET_YES);
GNUNET_CONTAINER_bloomfilter_remove (filter, key);
return GNUNET_NO;
}
while ((need > 0) && (last != need))
{
last = need;
- plugin->api->get_expiration (plugin->api->cls,
- "a_processor,
- &need);
+ plugin->api->get_expiration (plugin->api->cls, "a_processor, &need);
}
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting `%s' message with value %d and message `%s'\n",
- "STATUS", code, msg != NULL ? msg : "(none)");
+ "STATUS",
+ code,
+ msg != NULL ? msg : "(none)");
slen = (msg == NULL) ? 0 : strlen (msg) + 1;
- env = GNUNET_MQ_msg_extra (sm,
- slen,
- GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
+ env = GNUNET_MQ_msg_extra (sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
sm->status = htonl (code);
sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration);
- GNUNET_memcpy (&sm[1],
- msg,
- slen);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_memcpy (&sm[1], msg, slen);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
}
if (NULL == key)
{
/* transmit 'DATA_END' */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting DATA_END message\n");
- env = GNUNET_MQ_msg (end,
- GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n");
+ env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
return GNUNET_OK;
}
- GNUNET_assert (sizeof (struct DataMessage) + size <
- GNUNET_MAX_MESSAGE_SIZE);
- env = GNUNET_MQ_msg_extra (dm,
- size,
- GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
+ GNUNET_assert (sizeof (struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE);
+ env = GNUNET_MQ_msg_extra (dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
dm->rid = htonl (0);
dm->size = htonl (size);
dm->type = htonl (type);
dm->expiration = GNUNET_TIME_absolute_hton (expiration);
dm->uid = GNUNET_htonll (uid);
dm->key = *key;
- GNUNET_memcpy (&dm[1],
- data,
- size);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n",
- GNUNET_h2s (key),
- type,
- GNUNET_STRINGS_absolute_time_to_string (expiration),
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration),
- GNUNET_YES));
+ GNUNET_memcpy (&dm[1], data, size);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n",
+ GNUNET_h2s (key),
+ type,
+ GNUNET_STRINGS_absolute_time_to_string (expiration),
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
+ expiration),
+ GNUNET_YES));
GNUNET_STATISTICS_update (stats,
gettext_noop ("# results found"),
1,
GNUNET_NO);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
return GNUNET_OK;
}
* @param message the actual message
*/
static void
-handle_reserve (void *cls,
- const struct ReserveMessage *msg)
+handle_reserve (void *cls, const struct ReserveMessage *msg)
{
/**
* Static counter to produce reservation identifiers.
uint64_t amount;
uint32_t entries;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing RESERVE request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n");
amount = GNUNET_ntohll (msg->amount);
entries = ntohl (msg->entries);
used = payload + reserved;
- req = amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
+ req =
+ amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
if (used + req > quota)
{
if (quota < used)
- used = quota; /* cheat a bit for error message (to avoid negative numbers) */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"),
- quota - used,
- req);
+ used =
+ quota; /* cheat a bit for error message (to avoid negative numbers) */
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"),
+ quota - used,
+ req);
if (cache_size < req)
{
/* TODO: document this in the FAQ; essentially, if this
* by less-important content from migration because it is
* larger than 1/8th of the overall available space, and
* we only reserve 1/8th for "fresh" insertions */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
- req,
- cache_size);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
+ req,
+ cache_size);
transmit_status (client,
0,
- gettext_noop
- ("Insufficient space to satisfy request and "
- "requested amount is larger than cache size"));
+ gettext_noop (
+ "Insufficient space to satisfy request and "
+ "requested amount is larger than cache size"));
}
else
{
e->entries = entries;
e->rid = ++reservation_gen;
if (reservation_gen < 0)
- reservation_gen = 0; /* wrap around */
- transmit_status (client,
- e->rid,
- NULL);
+ reservation_gen = 0; /* wrap around */
+ transmit_status (client, e->rid, NULL);
GNUNET_SERVICE_client_continue (client);
}
* @param message the actual message
*/
static void
-handle_release_reserve (void *cls,
- const struct ReleaseReserveMessage *msg)
+handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
struct ReservationList *pos;
int rid = ntohl (msg->rid);
unsigned long long rem;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing RELEASE_RESERVE request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n");
next = reservations;
prev = NULL;
while (NULL != (pos = next))
else
prev->next = next;
rem =
- pos->amount +
- ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
+ pos->amount +
+ ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
GNUNET_assert (reserved >= rem);
reserved -= rem;
GNUNET_STATISTICS_set (stats,
"Returning %llu remaining reserved bytes to storage pool\n",
rem);
GNUNET_free (pos);
- transmit_status (client,
- GNUNET_OK,
- NULL);
+ transmit_status (client, GNUNET_OK, NULL);
GNUNET_SERVICE_client_continue (client);
return;
}
gettext_noop ("# bytes stored"),
size,
GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_add (filter,
- key);
+ GNUNET_CONTAINER_bloomfilter_add (filter, key);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Successfully stored %u bytes under key `%s'\n",
size,
if (quota - reserved - cache_size < payload)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Need %llu bytes more space (%llu allowed, using %llu)\n"),
+ _ ("Need %llu bytes more space (%llu allowed, using %llu)\n"),
(unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
(unsigned long long) (quota - reserved - cache_size),
(unsigned long long) payload);
* @return #GNUNET_OK if @a dm is well-formed
*/
static int
-check_put (void *cls,
- const struct DataMessage *dm)
+check_put (void *cls, const struct DataMessage *dm)
{
if (GNUNET_OK != check_data (dm))
{
* @param message the actual message
*/
static void
-handle_put (void *cls,
- const struct DataMessage *dm)
+handle_put (void *cls, const struct DataMessage *dm)
{
struct GNUNET_SERVICE_Client *client = cls;
int rid;
GNUNET_NO);
}
}
- bool absent = GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter,
- &dm->key);
+ bool absent =
+ GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key);
plugin->api->put (plugin->api->cls,
&dm->key,
absent,
* @param msg the actual message
*/
static void
-handle_get (void *cls,
- const struct GetMessage *msg)
+handle_get (void *cls, const struct GetMessage *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
* @param msg the actual message
*/
static void
-handle_get_key (void *cls,
- const struct GetKeyMessage *msg)
+handle_get_key (void *cls, const struct GetKeyMessage *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
gettext_noop ("# GET KEY requests received"),
1,
GNUNET_NO);
- if (GNUNET_YES !=
- GNUNET_CONTAINER_bloomfilter_test (filter,
- &msg->key))
+ if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key))
{
/* don't bother database... */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Empty result set for GET request for `%s' (bloomfilter).\n",
GNUNET_h2s (&msg->key));
GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("# requests filtered by bloomfilter"),
+ gettext_noop (
+ "# requests filtered by bloomfilter"),
1,
GNUNET_NO);
transmit_item (client,
- NULL, 0, NULL, 0, 0, 0, 0,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ 0,
+ 0,
+ 0,
GNUNET_TIME_UNIT_ZERO_ABS,
0);
GNUNET_SERVICE_client_continue (client);
* @param message the actual message
*/
static void
-handle_get_replication (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing GET_REPLICATION request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n");
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET REPLICATION requests received"),
+ gettext_noop (
+ "# GET REPLICATION requests received"),
1,
GNUNET_NO);
- plugin->api->get_replication (plugin->api->cls,
- &transmit_item,
- client);
+ plugin->api->get_replication (plugin->api->cls, &transmit_item, client);
GNUNET_SERVICE_client_continue (client);
}
* @param message the actual message
*/
static void
-handle_get_zero_anonymity (void *cls,
- const struct GetZeroAnonymityMessage *msg)
+handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
enum GNUNET_BLOCK_Type type;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Processing GET_ZERO_ANONYMITY request\n");
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET ZERO ANONYMITY requests received"),
+ gettext_noop (
+ "# GET ZERO ANONYMITY requests received"),
1,
GNUNET_NO);
plugin->api->get_zero_anonymity (plugin->api->cls,
if (GNUNET_SYSERR == status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "REMOVE request failed: %s.\n",
- msg);
- transmit_status (client,
- GNUNET_NO,
- msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg);
+ transmit_status (client, GNUNET_NO, msg);
return;
}
if (GNUNET_NO == status)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Content not found for REMOVE request.\n");
- transmit_status (client,
- GNUNET_NO,
- _("Content not found"));
+ transmit_status (client, GNUNET_NO, _ ("Content not found"));
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
gettext_noop ("# bytes removed (explicit request)"),
size,
GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_remove (filter,
- key);
- transmit_status (client,
- GNUNET_OK,
- NULL);
+ GNUNET_CONTAINER_bloomfilter_remove (filter, key);
+ transmit_status (client, GNUNET_OK, NULL);
}
* @return #GNUNET_OK if @a dm is well-formed
*/
static int
-check_remove (void *cls,
- const struct DataMessage *dm)
+check_remove (void *cls, const struct DataMessage *dm)
{
if (GNUNET_OK != check_data (dm))
{
* @param message the actual message
*/
static void
-handle_remove (void *cls,
- const struct DataMessage *dm)
+handle_remove (void *cls, const struct DataMessage *dm)
{
struct GNUNET_SERVICE_Client *client = cls;
GNUNET_STATISTICS_update (stats,
gettext_noop ("# REMOVE requests received"),
- 1, GNUNET_NO);
+ 1,
+ GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Processing REMOVE request for `%s'\n",
GNUNET_h2s (&dm->key));
* @param message the actual message
*/
static void
-handle_drop (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_drop (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing DROP request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n");
do_drop = GNUNET_YES;
GNUNET_SERVICE_client_continue (client);
}
* 0 for "reset to empty"
*/
static void
-disk_utilization_change_cb (void *cls,
- int delta)
+disk_utilization_change_cb (void *cls, int delta)
{
if ((delta < 0) && (payload < -delta))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"),
- (long long) payload,
- (long long) -delta);
- plugin->api->estimate_size (plugin->api->cls,
- &payload);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"),
+ (long long) payload,
+ (long long) -delta);
+ plugin->api->estimate_size (plugin->api->cls, &payload);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("New payload: %lld\n"),
+ _ ("New payload: %lld\n"),
(long long) payload);
- sync_stats ();
+ sync_stats ();
return;
}
payload += delta;
GNUNET_assert (GNUNET_NO == stats_worked);
stats_worked = GNUNET_YES;
payload += value;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notification from statistics about existing payload (%llu), new payload is %llu\n",
- (unsigned long long) value,
- (unsigned long long) payload);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Notification from statistics about existing payload (%llu), new payload is %llu\n",
+ (unsigned long long) value,
+ (unsigned long long) payload);
return GNUNET_OK;
}
ret->env.duc = &disk_utilization_change_cb;
ret->env.cls = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading `%s' datastore plugin\n"),
+ _ ("Loading `%s' datastore plugin\n"),
plugin_name);
- GNUNET_asprintf (&libname,
- "libgnunet_plugin_datastore_%s",
- plugin_name);
+ GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", plugin_name);
ret->short_name = GNUNET_strdup (plugin_name);
ret->lib_name = libname;
- ret->api = GNUNET_PLUGIN_load (libname,
- &ret->env);
+ ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
if (NULL == ret->api)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load datastore plugin for `%s'\n"),
+ _ ("Failed to load datastore plugin for `%s'\n"),
plugin_name);
GNUNET_free (ret->short_name);
GNUNET_free (libname);
begin_service ()
{
GNUNET_SERVICE_resume (service);
- expired_kill_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired,
- NULL);
+ expired_kill_task =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired,
+ NULL);
}
*/
static void
add_key_to_bloomfilter (void *cls,
- const struct GNUNET_HashCode *key,
- unsigned int count)
+ const struct GNUNET_HashCode *key,
+ unsigned int count)
{
struct GNUNET_CONTAINER_BloomFilter *bf = cls;
if (NULL == key)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Bloomfilter construction complete.\n"));
+ _ ("Bloomfilter construction complete.\n"));
begin_service ();
return;
}
while (0 < count--)
- GNUNET_CONTAINER_bloomfilter_add (bf,
- key);
+ GNUNET_CONTAINER_bloomfilter_add (bf, key);
}
* @param success #GNUNET_NO if we failed to read the stat
*/
static void
-process_stat_done (void *cls,
- int success)
+process_stat_done (void *cls, int success)
{
stat_get = NULL;
if (NULL != stat_timeout_task)
filter = NULL;
if (NULL != stats)
{
- GNUNET_STATISTICS_destroy (stats,
- GNUNET_YES);
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
stats = NULL;
}
return;
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Failed to obtain value from statistics service, recomputing it\n");
- plugin->api->estimate_size (plugin->api->cls,
- &payload);
+ plugin->api->estimate_size (plugin->api->cls, &payload);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("New payload: %lld\n"),
+ _ ("New payload: %lld\n"),
(long long) payload);
}
if (GNUNET_YES == refresh_bf)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Rebuilding bloomfilter. Please be patient.\n"));
+ _ ("Rebuilding bloomfilter. Please be patient.\n"));
if (NULL != plugin->api->get_keys)
{
- plugin->api->get_keys (plugin->api->cls,
- &add_key_to_bloomfilter,
- filter);
+ plugin->api->get_keys (plugin->api->cls, &add_key_to_bloomfilter, filter);
return;
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Plugin does not support get_keys function. Please fix!\n"));
+ _ (
+ "Plugin does not support get_keys function. Please fix!\n"));
}
}
begin_service ();
{
stat_timeout_task = NULL;
GNUNET_STATISTICS_get_cancel (stat_get);
- process_stat_done (NULL,
- GNUNET_NO);
+ process_stat_done (NULL, GNUNET_NO);
}
}
if (GNUNET_YES == do_drop)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping database!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n");
plugin->api->drop (plugin->api->cls);
payload = 0;
last_sync++;
sync_stats ();
if (NULL != stats)
{
- GNUNET_STATISTICS_destroy (stats,
- GNUNET_YES);
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
stats = NULL;
}
GNUNET_free (quota_stat_name);
*/
static void *
client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
{
return client;
}
*/
static void
client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *app_ctx)
+ struct GNUNET_SERVICE_Client *client,
+ void *app_ctx)
{
struct ReservationList *pos;
struct ReservationList *prev;
gettext_noop ("# reserved"),
reserved,
GNUNET_NO);
-
}
service = serv;
cfg = c;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "DATASTORE",
- "DATABASE",
- &plugin_name))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ "DATASTORE",
+ "DATABASE",
+ &plugin_name))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"DATABASE",
return;
}
GNUNET_asprintf ("a_stat_name,
- _("# bytes used in file-sharing datastore `%s'"),
- plugin_name);
+ _ ("# bytes used in file-sharing datastore `%s'"),
+ plugin_name);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_size (cfg,
- "DATASTORE",
- "QUOTA",
- "a))
+ GNUNET_CONFIGURATION_get_value_size (cfg, "DATASTORE", "QUOTA", "a))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "QUOTA",
- "DATASTORE");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE");
return;
}
- stats = GNUNET_STATISTICS_create ("datastore",
- cfg);
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# quota"),
- quota,
- GNUNET_NO);
- cache_size = quota / 8; /* Or should we make this an option? */
+ stats = GNUNET_STATISTICS_create ("datastore", cfg);
+ GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO);
+ cache_size = quota / 8; /* Or should we make this an option? */
GNUNET_STATISTICS_set (stats,
gettext_noop ("# cache size"),
cache_size,
if (quota / (32 * 1024LL) > MAX_BF_SIZE)
bf_size = MAX_BF_SIZE;
else
- bf_size = quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */
+ bf_size =
+ quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */
fn = NULL;
- if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "DATASTORE",
- "BLOOMFILTER",
- &fn)) ||
+ if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "DATASTORE",
+ "BLOOMFILTER",
+ &fn)) ||
(GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not use specified filename `%s' for bloomfilter.\n"),
+ _ ("Could not use specified filename `%s' for bloomfilter.\n"),
NULL != fn ? fn : "");
GNUNET_free_non_null (fn);
fn = NULL;
GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name);
if (GNUNET_YES == GNUNET_DISK_file_test (pfn))
{
- filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */
+ filter =
+ GNUNET_CONTAINER_bloomfilter_load (pfn,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
if (NULL == filter)
{
- /* file exists but not valid, remove and try again, but refresh */
- if (0 != UNLINK (pfn))
- {
- /* failed to remove, run without file */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to remove bogus bloomfilter file `%s'\n"),
- pfn);
- GNUNET_free (pfn);
- pfn = NULL;
- filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */
- refresh_bf = GNUNET_YES;
- }
- else
- {
- /* try again after remove */
- filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */
- refresh_bf = GNUNET_YES;
- if (NULL == filter)
- {
- /* failed yet again, give up on using file */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to remove bogus bloomfilter file `%s'\n"),
- pfn);
- GNUNET_free (pfn);
- pfn = NULL;
- filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx. 3% false positives at max use */
- }
- }
+ /* file exists but not valid, remove and try again, but refresh */
+ if (0 != unlink (pfn))
+ {
+ /* failed to remove, run without file */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to remove bogus bloomfilter file `%s'\n"),
+ pfn);
+ GNUNET_free (pfn);
+ pfn = NULL;
+ filter = GNUNET_CONTAINER_bloomfilter_load (
+ NULL,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
+ refresh_bf = GNUNET_YES;
+ }
+ else
+ {
+ /* try again after remove */
+ filter = GNUNET_CONTAINER_bloomfilter_load (
+ pfn,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
+ refresh_bf = GNUNET_YES;
+ if (NULL == filter)
+ {
+ /* failed yet again, give up on using file */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to remove bogus bloomfilter file `%s'\n"),
+ pfn);
+ GNUNET_free (pfn);
+ pfn = NULL;
+ filter = GNUNET_CONTAINER_bloomfilter_init (
+ NULL,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
+ }
+ }
}
else
{
- /* normal case: have an existing valid bf file, no need to refresh */
- refresh_bf = GNUNET_NO;
+ /* normal case: have an existing valid bf file, no need to refresh */
+ refresh_bf = GNUNET_NO;
}
}
else
{
- filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */
+ filter =
+ GNUNET_CONTAINER_bloomfilter_load (pfn,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
refresh_bf = GNUNET_YES;
}
GNUNET_free (pfn);
}
else
{
- filter = GNUNET_CONTAINER_bloomfilter_init (NULL,
- bf_size,
- 5); /* approx. 3% false positives at max use */
+ filter =
+ GNUNET_CONTAINER_bloomfilter_init (NULL,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
refresh_bf = GNUNET_YES;
}
GNUNET_free_non_null (fn);
if (NULL == filter)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to initialize bloomfilter.\n"));
+ _ ("Failed to initialize bloomfilter.\n"));
if (NULL != stats)
{
- GNUNET_STATISTICS_destroy (stats,
- GNUNET_YES);
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
stats = NULL;
}
return;
}
GNUNET_SERVICE_suspend (service);
- stat_get =
- GNUNET_STATISTICS_get (stats,
- "datastore",
- quota_stat_name,
- &process_stat_done,
- &process_stat_in,
- NULL);
+ stat_get = GNUNET_STATISTICS_get (stats,
+ "datastore",
+ quota_stat_name,
+ &process_stat_done,
+ &process_stat_in,
+ NULL);
if (NULL == stat_get)
- process_stat_done (NULL,
- GNUNET_SYSERR);
+ process_stat_done (NULL, GNUNET_SYSERR);
else
- stat_timeout_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &stat_timeout,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
- NULL);
+ stat_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &stat_timeout,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL);
}
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("datastore",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_fixed_size (reserve,
- GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
- struct ReserveMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (release_reserve,
- GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
- struct ReleaseReserveMessage,
- NULL),
- GNUNET_MQ_hd_var_size (put,
- GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
- struct DataMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (get,
- GNUNET_MESSAGE_TYPE_DATASTORE_GET,
- struct GetMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (get_key,
- GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY,
- struct GetKeyMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (get_replication,
- GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_hd_fixed_size (get_zero_anonymity,
- GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
- struct GetZeroAnonymityMessage,
- NULL),
- GNUNET_MQ_hd_var_size (remove,
- GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE,
- struct DataMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (drop,
- GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN (
+ "datastore",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_fixed_size (reserve,
+ GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
+ struct ReserveMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (release_reserve,
+ GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
+ struct ReleaseReserveMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (put,
+ GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
+ struct DataMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET,
+ struct GetMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get_key,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY,
+ struct GetKeyMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get_replication,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get_zero_anonymity,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
+ struct GetZeroAnonymityMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (remove,
+ GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE,
+ struct DataMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (drop,
+ GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ());
/* end of gnunet-service-datastore.c */
struct CpsRunContext *crc = cls;
#if REPORT_ID
- FPRINTF (stderr, "%s", (GNUNET_OK == success) ? "I" : "i");
+ fprintf (stderr, "%s", (GNUNET_OK == success) ? "I" : "i");
#endif
if (GNUNET_OK != success)
{
return;
}
#if REPORT_ID
- FPRINTF (stderr, "%s", "D");
+ fprintf (stderr, "%s", "D");
#endif
GNUNET_assert (GNUNET_OK == success);
GNUNET_SCHEDULER_add_now (&run_continuation,
if (success != GNUNET_YES)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
msg);
GNUNET_DATASTORE_disconnect (datastore,
0, 1,
&run_tests, crc))
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Test 'put' operation failed.\n");
ok = 1;
&run,
NULL))
return 1;
- FPRINTF (stderr, "%s", "\n");
+ fprintf (stderr, "%s", "\n");
return ok;
}
if (GNUNET_OK != status)
{
- FPRINTF (stderr, "ERROR: `%s'\n", msg);
+ fprintf (stderr, "ERROR: `%s'\n", msg);
}
else
{
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
{
- FPRINTF (stderr, "Failed to load plugin `%s'!\n", name);
+ fprintf (stderr, "Failed to load plugin `%s'!\n", name);
GNUNET_free (name);
GNUNET_free (libname);
return NULL;
api = load_plugin (c);
if (api == NULL)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s", "Could not initialize plugin, assuming database not configured. Test not run!\n");
return;
}
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
"perf-plugin-datastore", "nohelp", options, &run, NULL);
if (ok != 0)
- FPRINTF (stderr, "Missed some testcases: %u\n", ok);
+ fprintf (stderr, "Missed some testcases: %u\n", ok);
GNUNET_DISK_directory_remove (dir_name);
return ok;
- /*
+/*
* This file is part of GNUnet
* Copyright (C) 2009, 2011, 2017 GNUnet e.V.
*
* a failure of the command 'cmd' on file 'filename'
* with the message given by strerror(errno).
*/
-#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0)
+#define LOG_SQLITE(db, level, cmd) \
+ do \
+ { \
+ GNUNET_log_from (level, \
+ "sqlite", \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ sqlite3_errmsg (db->dbh)); \
+ } while (0)
/**
* a failure of the command 'cmd' on file 'filename'
* with the message given by strerror(errno).
*/
-#define LOG_SQLITE_MSG(db, msg, level, cmd) do { GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0)
-
+#define LOG_SQLITE_MSG(db, msg, level, cmd) \
+ do \
+ { \
+ GNUNET_log_from (level, \
+ "sqlite", \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ sqlite3_errmsg (db->dbh)); \
+ GNUNET_asprintf (msg, \
+ _ ("`%s' failed at %s:%u with error: %s"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ sqlite3_errmsg (db->dbh)); \
+ } while (0)
/**
* Should the database be dropped on shutdown?
*/
int drop_on_shutdown;
-
};
* @return 0 on success
*/
static int
-sq_prepare (sqlite3 *dbh,
- const char *zSql,
- sqlite3_stmt **ppStmt)
+sq_prepare (sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt)
{
char *dummy;
int result;
* @param dbh handle to the database
*/
static void
-create_indices (sqlite3 * dbh)
+create_indices (sqlite3 *dbh)
{
/* create indices */
- if (0 !=
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)",
- NULL, NULL, NULL)) +
+ if (
+ 0 !=
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)",
+ NULL,
+ NULL,
+ NULL)) +
(SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)",
- NULL, NULL, NULL)) +
+ sqlite3_exec (
+ dbh,
+ "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)",
+ NULL,
+ NULL,
+ NULL)) +
(SQLITE_OK !=
sqlite3_exec (dbh,
"CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)",
- NULL, NULL, NULL)) +
+ NULL,
+ NULL,
+ NULL)) +
(SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)",
- NULL, NULL, NULL)) )
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
- "Failed to create indices: %s\n", sqlite3_errmsg (dbh));
+ sqlite3_exec (
+ dbh,
+ "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)",
+ NULL,
+ NULL,
+ NULL)))
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "sqlite",
+ "Failed to create indices: %s\n",
+ sqlite3_errmsg (dbh));
}
#if 0
-#define CHECK(a) GNUNET_break(a)
+#define CHECK(a) GNUNET_break (a)
#define ENULL NULL
#else
#define ENULL &e
#define ENULL_DEFINED 1
-#define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
+#define CHECK(a) \
+ if (! (a)) \
+ { \
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", e); \
+ sqlite3_free (e); \
+ }
#endif
char *e;
#endif
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "datastore-sqlite",
- "FILENAME",
- &afsdir))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "datastore-sqlite",
+ "FILENAME",
+ &afsdir))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "datastore-sqlite",
+ "datastore-sqlite",
"FILENAME");
return GNUNET_SYSERR;
}
if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
{
- if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (afsdir))
+ if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
{
GNUNET_break (0);
GNUNET_free (afsdir);
}
/* database is new or got deleted, reset payload to zero! */
if (NULL != plugin->env->duc)
- plugin->env->duc (plugin->env->cls,
- 0);
+ plugin->env->duc (plugin->env->cls, 0);
}
/* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
plugin->fn = afsdir;
/* Open database and precompile statements */
- if (SQLITE_OK !=
- sqlite3_open (plugin->fn, &plugin->dbh))
+ if (SQLITE_OK != sqlite3_open (plugin->fn, &plugin->dbh))
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
- _("Unable to initialize SQLite: %s.\n"),
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "sqlite",
+ _ ("Unable to initialize SQLite: %s.\n"),
sqlite3_errmsg (plugin->dbh));
return GNUNET_SYSERR;
}
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA temp_store=MEMORY", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA synchronous=OFF", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA legacy_file_format=OFF", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA auto_vacuum=INCREMENTAL", NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA page_size=4096", NULL, NULL,
- ENULL));
-
- CHECK (SQLITE_OK ==
- sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
+ CHECK (
+ SQLITE_OK ==
+ sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL));
+ CHECK (
+ SQLITE_OK ==
+ sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL, ENULL));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
+ "PRAGMA legacy_file_format=OFF",
+ NULL,
+ NULL,
+ ENULL));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
+ "PRAGMA auto_vacuum=INCREMENTAL",
+ NULL,
+ NULL,
+ ENULL));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
+ "PRAGMA locking_mode=EXCLUSIVE",
+ NULL,
+ NULL,
+ ENULL));
+ CHECK (
+ SQLITE_OK ==
+ sqlite3_exec (plugin->dbh, "PRAGMA page_size=4096", NULL, NULL, ENULL));
+
+ CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
/* We have to do it here, because otherwise precompiling SQL might fail */
* we do math or inequality tests, so we can't handle the entire range of uint32_t.
* This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC.
*/
- if ( (SQLITE_DONE ==
- sqlite3_step (stmt)) &&
- (SQLITE_OK !=
- sqlite3_exec (plugin->dbh,
- "CREATE TABLE gn091 ("
- " repl INT4 NOT NULL DEFAULT 0,"
- " type INT4 NOT NULL DEFAULT 0,"
- " prio INT4 NOT NULL DEFAULT 0,"
- " anonLevel INT4 NOT NULL DEFAULT 0,"
- " expire INT8 NOT NULL DEFAULT 0,"
- " rvalue INT8 NOT NULL,"
- " hash TEXT NOT NULL DEFAULT '',"
- " vhash TEXT NOT NULL DEFAULT '',"
- " value BLOB NOT NULL DEFAULT '')",
- NULL,
- NULL,
- NULL)) )
+ if ((SQLITE_DONE == sqlite3_step (stmt)) &&
+ (SQLITE_OK != sqlite3_exec (plugin->dbh,
+ "CREATE TABLE gn091 ("
+ " repl INT4 NOT NULL DEFAULT 0,"
+ " type INT4 NOT NULL DEFAULT 0,"
+ " prio INT4 NOT NULL DEFAULT 0,"
+ " anonLevel INT4 NOT NULL DEFAULT 0,"
+ " expire INT8 NOT NULL DEFAULT 0,"
+ " rvalue INT8 NOT NULL,"
+ " hash TEXT NOT NULL DEFAULT '',"
+ " vhash TEXT NOT NULL DEFAULT '',"
+ " value BLOB NOT NULL DEFAULT '')",
+ NULL,
+ NULL,
+ NULL)))
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_exec");
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
sqlite3_finalize (stmt);
return GNUNET_SYSERR;
}
sqlite3_finalize (stmt);
create_indices (plugin->dbh);
-#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, _ROWID_"
- if ( (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "UPDATE gn091 "
- "SET prio = prio + ?, "
- "repl = repl + ?, "
- "expire = MAX(expire, ?) "
- "WHERE hash = ? AND vhash = ?",
- &plugin->update)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "UPDATE gn091 " "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
- &plugin->updRepl)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE repl=?2 AND " " (rvalue>=?1 OR "
- " NOT EXISTS (SELECT 1 FROM gn091 "
- "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
- "ORDER BY rvalue ASC LIMIT 1",
- &plugin->selRepl)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT MAX(repl) FROM gn091",
- &plugin->maxRepl)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
- "ORDER BY expire ASC LIMIT 1",
- &plugin->selExpi)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ? AND "
- "anonLevel = 0 AND "
- "type = ? "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->selZeroAnon)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
- &plugin->insertContent)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[0])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "type = ?4 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[1])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "hash = ?3 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[2])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "hash = ?3 AND "
- "type = ?4 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[3])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "rvalue >= ?2 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[4])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "rvalue >= ?2 AND "
- "type = ?4 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[5])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "rvalue >= ?2 AND "
- "hash = ?3 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[6])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "rvalue >= ?2 AND "
- "hash = ?3 AND "
- "type = ?4 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[7])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "DELETE FROM gn091 WHERE _ROWID_ = ?",
- &plugin->delRow)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "DELETE FROM gn091 "
- "WHERE hash = ? AND "
- "value = ? ",
- &plugin->remove)) ||
- false)
+#define RESULT_COLUMNS \
+ "repl, type, prio, anonLevel, expire, hash, value, _ROWID_"
+ if (
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "UPDATE gn091 "
+ "SET prio = prio + ?, "
+ "repl = repl + ?, "
+ "expire = MAX(expire, ?) "
+ "WHERE hash = ? AND vhash = ?",
+ &plugin->update)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "UPDATE gn091 "
+ "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
+ &plugin->updRepl)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE repl=?2 AND "
+ " (rvalue>=?1 OR "
+ " NOT EXISTS (SELECT 1 FROM gn091 "
+ "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
+ "ORDER BY rvalue ASC LIMIT 1",
+ &plugin->selRepl)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT MAX(repl) FROM gn091",
+ &plugin->maxRepl)) ||
+ (SQLITE_OK !=
+ sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
+ "ORDER BY expire ASC LIMIT 1",
+ &plugin->selExpi)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ? AND "
+ "anonLevel = 0 AND "
+ "type = ? "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->selZeroAnon)) ||
+ (SQLITE_OK !=
+ sq_prepare (plugin->dbh,
+ "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ &plugin->insertContent)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[0])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "type = ?4 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[1])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "hash = ?3 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[2])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "hash = ?3 AND "
+ "type = ?4 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[3])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "rvalue >= ?2 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[4])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "rvalue >= ?2 AND "
+ "type = ?4 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[5])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "rvalue >= ?2 AND "
+ "hash = ?3 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[6])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "rvalue >= ?2 AND "
+ "hash = ?3 AND "
+ "type = ?4 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[7])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "DELETE FROM gn091 WHERE _ROWID_ = ?",
+ &plugin->delRow)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "DELETE FROM gn091 "
+ "WHERE hash = ? AND "
+ "value = ? ",
+ &plugin->remove)) ||
+ false)
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "precompiling");
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "precompiling");
return GNUNET_SYSERR;
}
return GNUNET_OK;
#if SQLITE_VERSION_NUMBER >= 3007000
if (result == SQLITE_BUSY)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "sqlite",
- _("Tried to close sqlite without finalizing all prepared statements.\n"));
- stmt = sqlite3_next_stmt (plugin->dbh,
- NULL);
+ GNUNET_log_from (
+ GNUNET_ERROR_TYPE_WARNING,
+ "sqlite",
+ _ (
+ "Tried to close sqlite without finalizing all prepared statements.\n"));
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
while (NULL != stmt)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"Failed to close statement %p: %d\n",
stmt,
result);
- stmt = sqlite3_next_stmt (plugin->dbh,
- NULL);
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
}
result = sqlite3_close (plugin->dbh);
}
#endif
if (SQLITE_OK != result)
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_close");
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
GNUNET_free_non_null (plugin->fn);
}
* @param rid the ID of the row to delete
*/
static int
-delete_by_rowid (struct Plugin *plugin,
- uint64_t rid)
+delete_by_rowid (struct Plugin *plugin, uint64_t rid)
{
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint64 (&rid),
- GNUNET_SQ_query_param_end
- };
-
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->delRow,
- params))
+ struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (&rid),
+ GNUNET_SQ_query_param_end};
+
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->delRow, params))
return GNUNET_SYSERR;
if (SQLITE_DONE != sqlite3_step (plugin->delRow))
{
- LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ LOG_SQLITE (plugin,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->delRow);
+ GNUNET_SQ_reset (plugin->dbh, plugin->delRow);
return GNUNET_SYSERR;
}
- GNUNET_SQ_reset (plugin->dbh,
- plugin->delRow);
+ GNUNET_SQ_reset (plugin->dbh, plugin->delRow);
return GNUNET_OK;
}
struct GNUNET_HashCode vhash;
char *msg = NULL;
- GNUNET_CRYPTO_hash (data,
- size,
- &vhash);
+ GNUNET_CRYPTO_hash (data, size, &vhash);
- if (!absent)
+ if (! absent)
{
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint32 (&priority),
- GNUNET_SQ_query_param_uint32 (&replication),
- GNUNET_SQ_query_param_absolute_time (&expiration),
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_auto_from_type (&vhash),
- GNUNET_SQ_query_param_end
- };
-
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->update,
- params))
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_uint32 (&priority),
+ GNUNET_SQ_query_param_uint32 (&replication),
+ GNUNET_SQ_query_param_absolute_time (&expiration),
+ GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_auto_from_type (&vhash),
+ GNUNET_SQ_query_param_end};
+
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->update, params))
{
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- _("sqlite bind failure"));
+ cont (cont_cls, key, size, GNUNET_SYSERR, _ ("sqlite bind failure"));
return;
}
if (SQLITE_DONE != sqlite3_step (plugin->update))
{
- LOG_SQLITE_MSG (plugin, &msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ LOG_SQLITE_MSG (plugin,
+ &msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- msg);
+ cont (cont_cls, key, size, GNUNET_SYSERR, msg);
GNUNET_free_non_null (msg);
return;
}
int changes = sqlite3_changes (plugin->dbh);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->update);
+ GNUNET_SQ_reset (plugin->dbh, plugin->update);
if (0 != changes)
{
- cont (cont_cls,
- key,
- size,
- GNUNET_NO,
- NULL);
+ cont (cont_cls, key, size, GNUNET_NO, NULL);
return;
}
}
uint64_t rvalue;
uint32_t type32 = (uint32_t) type;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint32 (&replication),
- GNUNET_SQ_query_param_uint32 (&type32),
- GNUNET_SQ_query_param_uint32 (&priority),
- GNUNET_SQ_query_param_uint32 (&anonymity),
- GNUNET_SQ_query_param_absolute_time (&expiration),
- GNUNET_SQ_query_param_uint64 (&rvalue),
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_auto_from_type (&vhash),
- GNUNET_SQ_query_param_fixed_size (data, size),
- GNUNET_SQ_query_param_end
- };
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_uint32 (&replication),
+ GNUNET_SQ_query_param_uint32 (&type32),
+ GNUNET_SQ_query_param_uint32 (&priority),
+ GNUNET_SQ_query_param_uint32 (&anonymity),
+ GNUNET_SQ_query_param_absolute_time (&expiration),
+ GNUNET_SQ_query_param_uint64 (&rvalue),
+ GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_auto_from_type (&vhash),
+ GNUNET_SQ_query_param_fixed_size (data, size),
+ GNUNET_SQ_query_param_end};
int n;
int ret;
sqlite3_stmt *stmt;
if (size > MAX_ITEM_SIZE)
{
- cont (cont_cls, key, size, GNUNET_SYSERR, _("Data too large"));
+ cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large"));
return;
}
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
- "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n",
- type,
- GNUNET_h2s (key),
- priority,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration),
- GNUNET_YES),
- GNUNET_STRINGS_absolute_time_to_string (expiration));
+ GNUNET_log_from (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n",
+ type,
+ GNUNET_h2s (key),
+ priority,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
+ expiration),
+ GNUNET_YES),
+ GNUNET_STRINGS_absolute_time_to_string (expiration));
stmt = plugin->insertContent;
rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
- if (GNUNET_OK !=
- GNUNET_SQ_bind (stmt,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
{
cont (cont_cls, key, size, GNUNET_SYSERR, NULL);
return;
if (NULL != plugin->env->duc)
plugin->env->duc (plugin->env->cls,
size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
"Stored new entry (%u bytes)\n",
size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
ret = GNUNET_OK;
case SQLITE_BUSY:
GNUNET_break (0);
LOG_SQLITE_MSG (plugin,
- &msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ &msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
ret = GNUNET_SYSERR;
break;
default:
LOG_SQLITE_MSG (plugin,
- &msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ &msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- stmt);
+ GNUNET_SQ_reset (plugin->dbh, stmt);
database_shutdown (plugin);
database_setup (plugin->env->cfg, plugin);
cont (cont_cls, key, size, GNUNET_SYSERR, msg);
- GNUNET_free_non_null(msg);
+ GNUNET_free_non_null (msg);
return;
}
- GNUNET_SQ_reset (plugin->dbh,
- stmt);
+ GNUNET_SQ_reset (plugin->dbh, stmt);
cont (cont_cls, key, size, ret, msg);
- GNUNET_free_non_null(msg);
+ GNUNET_free_non_null (msg);
}
size_t value_size;
struct GNUNET_HashCode key;
int ret;
- struct GNUNET_SQ_ResultSpec rs[] = {
- GNUNET_SQ_result_spec_uint32 (&replication),
- GNUNET_SQ_result_spec_uint32 (&type),
- GNUNET_SQ_result_spec_uint32 (&priority),
- GNUNET_SQ_result_spec_uint32 (&anonymity),
- GNUNET_SQ_result_spec_absolute_time (&expiration),
- GNUNET_SQ_result_spec_auto_from_type (&key),
- GNUNET_SQ_result_spec_variable_size (&value,
- &value_size),
- GNUNET_SQ_result_spec_uint64 (&rowid),
- GNUNET_SQ_result_spec_end
- };
+ struct GNUNET_SQ_ResultSpec rs[] =
+ {GNUNET_SQ_result_spec_uint32 (&replication),
+ GNUNET_SQ_result_spec_uint32 (&type),
+ GNUNET_SQ_result_spec_uint32 (&priority),
+ GNUNET_SQ_result_spec_uint32 (&anonymity),
+ GNUNET_SQ_result_spec_absolute_time (&expiration),
+ GNUNET_SQ_result_spec_auto_from_type (&key),
+ GNUNET_SQ_result_spec_variable_size (&value, &value_size),
+ GNUNET_SQ_result_spec_uint64 (&rowid),
+ GNUNET_SQ_result_spec_end};
n = sqlite3_step (stmt);
switch (n)
{
case SQLITE_ROW:
- if (GNUNET_OK !=
- GNUNET_SQ_extract_result (stmt,
- rs))
+ if (GNUNET_OK != GNUNET_SQ_extract_result (stmt, rs))
{
GNUNET_break (0);
break;
expiration,
rowid);
GNUNET_SQ_cleanup_result (rs);
- GNUNET_SQ_reset (plugin->dbh,
- stmt);
- if ( (GNUNET_NO == ret) &&
- (GNUNET_OK == delete_by_rowid (plugin,
- rowid)) &&
- (NULL != plugin->env->duc) )
+ GNUNET_SQ_reset (plugin->dbh, stmt);
+ if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)) &&
+ (NULL != plugin->env->duc))
plugin->env->duc (plugin->env->cls,
-(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
return;
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- if (SQLITE_OK !=
- sqlite3_reset (stmt))
+ if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
GNUNET_break (0);
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
database_shutdown (plugin);
- database_setup (plugin->env->cfg,
- plugin);
+ database_setup (plugin->env->cfg, plugin);
return;
}
- GNUNET_SQ_reset (plugin->dbh,
- stmt);
+ GNUNET_SQ_reset (plugin->dbh, stmt);
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
}
{
struct Plugin *plugin = cls;
uint32_t type32 = type;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint64 (&next_uid),
- GNUNET_SQ_query_param_uint32 (&type32),
- GNUNET_SQ_query_param_end
- };
+ struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (
+ &next_uid),
+ GNUNET_SQ_query_param_uint32 (
+ &type32),
+ GNUNET_SQ_query_param_end};
GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->selZeroAnon,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->selZeroAnon, params))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
int use_type = GNUNET_BLOCK_TYPE_ANY != type;
int use_key = NULL != key;
sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type];
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint64 (&next_uid),
- GNUNET_SQ_query_param_uint64 (&rvalue),
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_uint32 (&type32),
- GNUNET_SQ_query_param_end
- };
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_uint64 (&next_uid),
+ GNUNET_SQ_query_param_uint64 (&rvalue),
+ GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_uint32 (&type32),
+ GNUNET_SQ_query_param_end};
/* SQLite doesn't like it when you try to bind a parameter greater than the
* last numbered parameter, but unused parameters in the middle are OK.
}
if (random)
{
- rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
+ rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
next_uid = 0;
}
else
rvalue = 0;
- if (GNUNET_OK !=
- GNUNET_SQ_bind (stmt,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
- execute_get (plugin,
- stmt,
- proc,
- proc_cls);
+ execute_get (plugin, stmt, proc, proc_cls);
}
struct ReplCtx rc;
uint64_t rvalue;
uint32_t repl;
- struct GNUNET_SQ_QueryParam params_sel_repl[] = {
- GNUNET_SQ_query_param_uint64 (&rvalue),
- GNUNET_SQ_query_param_uint32 (&repl),
- GNUNET_SQ_query_param_end
- };
- struct GNUNET_SQ_QueryParam params_upd_repl[] = {
- GNUNET_SQ_query_param_uint64 (&rc.uid),
- GNUNET_SQ_query_param_end
- };
+ struct GNUNET_SQ_QueryParam params_sel_repl[] =
+ {GNUNET_SQ_query_param_uint64 (&rvalue),
+ GNUNET_SQ_query_param_uint32 (&repl),
+ GNUNET_SQ_query_param_end};
+ struct GNUNET_SQ_QueryParam params_upd_repl[] =
+ {GNUNET_SQ_query_param_uint64 (&rc.uid), GNUNET_SQ_query_param_end};
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"datastore-sqlite",
"Getting random block based on replication order.\n");
- if (SQLITE_ROW !=
- sqlite3_step (plugin->maxRepl))
+ if (SQLITE_ROW != sqlite3_step (plugin->maxRepl))
{
- GNUNET_SQ_reset (plugin->dbh,
- plugin->maxRepl);
+ GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl);
/* DB empty */
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
- repl = sqlite3_column_int (plugin->maxRepl,
- 0);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->maxRepl);
- rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->selRepl,
- params_sel_repl))
+ repl = sqlite3_column_int (plugin->maxRepl, 0);
+ GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl);
+ rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->selRepl, params_sel_repl))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
rc.have_uid = GNUNET_SYSERR;
rc.proc = proc;
rc.proc_cls = proc_cls;
- execute_get (plugin,
- plugin->selRepl,
- &repl_proc,
- &rc);
+ execute_get (plugin, plugin->selRepl, &repl_proc, &rc);
if (GNUNET_YES == rc.have_uid)
{
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->updRepl,
- params_upd_repl))
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->updRepl, params_upd_repl))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
- if (SQLITE_DONE !=
- sqlite3_step (plugin->updRepl))
+ if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->updRepl);
+ GNUNET_SQ_reset (plugin->dbh, plugin->updRepl);
}
if (GNUNET_SYSERR == rc.have_uid)
{
* @param proc_cls closure for @a proc
*/
static void
-sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
+sqlite_plugin_get_expiration (void *cls,
+ PluginDatumProcessor proc,
void *proc_cls)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
struct GNUNET_TIME_Absolute now;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_absolute_time (&now),
- GNUNET_SQ_query_param_end
- };
-
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Getting random block based on expiration and priority order.\n");
+ struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_absolute_time (
+ &now),
+ GNUNET_SQ_query_param_end};
+
+ GNUNET_log_from (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Getting random block based on expiration and priority order.\n");
now = GNUNET_TIME_absolute_get ();
stmt = plugin->selExpi;
- if (GNUNET_OK !=
- GNUNET_SQ_bind (stmt,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
* @param proc_cls closure for @a proc
*/
static void
-sqlite_plugin_get_keys (void *cls,
- PluginKeyProcessor proc,
- void *proc_cls)
+sqlite_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
struct GNUNET_HashCode key;
- struct GNUNET_SQ_ResultSpec results[] = {
- GNUNET_SQ_result_spec_auto_from_type (&key),
- GNUNET_SQ_result_spec_end
- };
+ struct GNUNET_SQ_ResultSpec results[] =
+ {GNUNET_SQ_result_spec_auto_from_type (&key), GNUNET_SQ_result_spec_end};
sqlite3_stmt *stmt;
int ret;
GNUNET_assert (NULL != proc);
- if (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT hash FROM gn091",
- &stmt))
+ if (SQLITE_OK != sq_prepare (plugin->dbh, "SELECT hash FROM gn091", &stmt))
{
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite_prepare");
- proc (proc_cls,
- NULL,
- 0);
+ "sqlite_prepare");
+ proc (proc_cls, NULL, 0);
return;
}
while (SQLITE_ROW == (ret = sqlite3_step (stmt)))
{
- if (GNUNET_OK ==
- GNUNET_SQ_extract_result (stmt,
- results))
- proc (proc_cls,
- &key,
- 1);
+ if (GNUNET_OK == GNUNET_SQ_extract_result (stmt, results))
+ proc (proc_cls, &key, 1);
else
GNUNET_break (0);
}
if (SQLITE_DONE != ret)
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite_step");
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
sqlite3_finalize (stmt);
- proc (proc_cls,
- NULL,
- 0);
+ proc (proc_cls, NULL, 0);
}
void *cont_cls)
{
struct Plugin *plugin = cls;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_fixed_size (data, size),
- GNUNET_SQ_query_param_end
- };
-
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->remove,
- params))
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_fixed_size (data, size),
+ GNUNET_SQ_query_param_end};
+
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->remove, params))
{
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- "bind failed");
+ cont (cont_cls, key, size, GNUNET_SYSERR, "bind failed");
return;
}
if (SQLITE_DONE != sqlite3_step (plugin->remove))
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->remove);
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- "sqlite3_step failed");
+ GNUNET_SQ_reset (plugin->dbh, plugin->remove);
+ cont (cont_cls, key, size, GNUNET_SYSERR, "sqlite3_step failed");
return;
}
int changes = sqlite3_changes (plugin->dbh);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->remove);
+ GNUNET_SQ_reset (plugin->dbh, plugin->remove);
if (0 == changes)
{
- cont (cont_cls,
- key,
- size,
- GNUNET_NO,
- NULL);
+ cont (cont_cls, key, size, GNUNET_NO, NULL);
return;
}
if (NULL != plugin->env->duc)
plugin->env->duc (plugin->env->cls,
-(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
- cont (cont_cls,
- key,
- size,
- GNUNET_OK,
- NULL);
+ cont (cont_cls, key, size, GNUNET_OK, NULL);
}
* @return the size of the database on disk (estimate)
*/
static void
-sqlite_plugin_estimate_size (void *cls,
- unsigned long long *estimate)
+sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
return;
if (SQLITE_VERSION_NUMBER < 3006000)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "datastore-sqlite",
- _("sqlite version to old to determine size, assuming zero\n"));
+ GNUNET_log_from (
+ GNUNET_ERROR_TYPE_WARNING,
+ "datastore-sqlite",
+ _ ("sqlite version to old to determine size, assuming zero\n"));
*estimate = 0;
return;
}
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "VACUUM",
- NULL,
- NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA auto_vacuum=INCREMENTAL",
- NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "PRAGMA page_count",
- &stmt));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
+ "PRAGMA auto_vacuum=INCREMENTAL",
+ NULL,
+ NULL,
+ ENULL));
+ CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt));
if (SQLITE_ROW == sqlite3_step (stmt))
- pages = sqlite3_column_int64 (stmt,
- 0);
+ pages = sqlite3_column_int64 (stmt, 0);
else
pages = 0;
sqlite3_finalize (stmt);
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "PRAGMA page_size",
- &stmt));
- CHECK (SQLITE_ROW ==
- sqlite3_step (stmt));
+ CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_size", &stmt));
+ CHECK (SQLITE_ROW == sqlite3_step (stmt));
page_size = sqlite3_column_int64 (stmt, 0);
sqlite3_finalize (stmt);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"),
- (unsigned long long) pages,
- (unsigned long long) page_size);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ (
+ "Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"),
+ (unsigned long long) pages,
+ (unsigned long long) page_size);
*estimate = pages * page_size;
}
struct GNUNET_DATASTORE_PluginFunctions *api;
if (NULL != plugin.env)
- return NULL; /* can only initialize once! */
- memset (&plugin,
- 0,
- sizeof (struct Plugin));
+ return NULL; /* can only initialize once! */
+ memset (&plugin, 0, sizeof (struct Plugin));
plugin.env = env;
if (GNUNET_OK != database_setup (env->cfg, &plugin))
{
api->remove_key = &sqlite_plugin_remove_key;
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
"sqlite",
- _("Sqlite database running\n"));
+ _ ("Sqlite database running\n"));
return api;
}
GNUNET_free (api);
if (NULL != fn)
{
- if (0 != UNLINK (fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fn);
+ if (0 != unlink (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
GNUNET_free (fn);
}
return NULL;
return;
}
#if 0
- FPRINTF (stderr,
+ fprintf (stderr,
"Check value got `%s' of size %u, type %d, expire %s\n",
GNUNET_h2s (key), (unsigned int) size, type,
GNUNET_STRINGS_absolute_time_to_string (expiration));
- FPRINTF (stderr,
+ fprintf (stderr,
"Check value iteration %d wants size %u, type %d, expire %s\n", i,
(unsigned int) get_size (i), get_type (i),
GNUNET_STRINGS_absolute_time_to_string (get_expiration(i)));
crc);
return;
case GNUNET_NO:
- FPRINTF (stderr,
+ fprintf (stderr,
"%s", "Test 'put' operation failed, key already exists (!?)\n");
GNUNET_DATASTORE_disconnect (datastore,
GNUNET_YES);
GNUNET_free (crc);
return;
case GNUNET_SYSERR:
- FPRINTF (stderr,
+ fprintf (stderr,
"Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
msg);
GNUNET_DATASTORE_disconnect (datastore,
0, 1,
&run_tests, crc))
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Test 'put' operation failed.\n");
ok = 1;
if (success != GNUNET_YES)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
msg);
GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
&run_tests,
crc))
{
- FPRINTF (stderr, "%s", "Test 'put' operation failed.\n");
+ fprintf (stderr, "%s", "Test 'put' operation failed.\n");
GNUNET_free (crc);
ok = 1;
}
if (GNUNET_OK != status)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"ERROR: `%s'\n",
msg);
}
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
{
- FPRINTF (stderr, "Failed to load plugin `%s'!\n", name);
+ fprintf (stderr, "Failed to load plugin `%s'!\n", name);
GNUNET_free (libname);
GNUNET_free (name);
ok = 77; /* mark test as skipped */
api = load_plugin (c);
if (api == NULL)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s", "Could not initialize plugin, assuming database not configured. Test not run!\n");
return;
}
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
"test-plugin-datastore", "nohelp", options, &run, NULL);
if ( (0 != ok) && (77 != ok) )
- FPRINTF (stderr, "Missed some testcases: %u\n", ok);
+ fprintf (stderr, "Missed some testcases: %u\n", ok);
GNUNET_DISK_directory_remove (dir_name);
return ok;
}
#include "platform.h"
#include "gnunet_dht_service.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "dht-clients", __VA_ARGS__)
/**
* The type of the query
*/
/**
* User supplied timeout value
*/
-static struct GNUNET_TIME_Relative timeout_request = { 60000 };
+static struct GNUNET_TIME_Relative timeout_request = {60000};
/**
* Be verbose
* @param data pointer to the result data
*/
static void
-get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
- const struct GNUNET_HashCode * key,
+get_result_iterator (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const struct GNUNET_HashCode *key,
const struct GNUNET_PeerIdentity *get_path,
unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
size_t size,
const void *data)
{
- FPRINTF (stdout,
- (GNUNET_BLOCK_TYPE_TEST == type)
- ? _("Result %d, type %d:\n%.*s\n")
- : _("Result %d, type %d:\n"),
- result_count,
+ fprintf (stdout,
+ (GNUNET_BLOCK_TYPE_TEST == type) ? _ ("Result %d, type %d:\n%.*s\n")
+ : _ ("Result %d, type %d:\n"),
+ result_count,
type,
(unsigned int) size,
(char *) data);
if (verbose)
{
- FPRINTF (stdout,
- " GET path: ");
- for (unsigned int i=0;i<get_path_length;i++)
- FPRINTF (stdout,
- "%s%s",
- (0 == i) ? "" : "-",
- GNUNET_i2s (&get_path[i]));
- FPRINTF (stdout,
- "\n PUT path: ");
- for (unsigned int i=0;i<put_path_length;i++)
- FPRINTF (stdout,
- "%s%s",
- (0 == i) ? "" : "-",
- GNUNET_i2s (&put_path[i]));
- FPRINTF (stdout,
- "\n");
+ fprintf (stdout, " GET path: ");
+ for (unsigned int i = 0; i < get_path_length; i++)
+ fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&get_path[i]));
+ fprintf (stdout, "\n PUT path: ");
+ for (unsigned int i = 0; i < put_path_length; i++)
+ fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&put_path[i]));
+ fprintf (stdout, "\n");
}
result_count++;
}
* @param c configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_HashCode key;
cfg = c;
if (NULL == query_key)
{
- FPRINTF (stderr, "%s", _("Must provide key for DHT GET!\n"));
+ fprintf (stderr, "%s", _ ("Must provide key for DHT GET!\n"));
ret = 1;
return;
}
if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
{
- FPRINTF (stderr, "%s", _("Failed to connect to DHT service!\n"));
+ fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n"));
ret = 1;
return;
}
- if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
+ if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
query_type = GNUNET_BLOCK_TYPE_TEST;
GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
if (verbose)
- FPRINTF (stderr, "%s `%s' \n",
- _("Issuing DHT GET with key"),
+ fprintf (stderr,
+ "%s `%s' \n",
+ _ ("Issuing DHT GET with key"),
GNUNET_h2s_full (&key));
GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
- tt = GNUNET_SCHEDULER_add_delayed (timeout_request,
- &timeout_task,
+ tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL);
+ get_handle = GNUNET_DHT_get_start (dht_handle,
+ query_type,
+ &key,
+ replication,
+ (demultixplex_everywhere)
+ ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
+ : GNUNET_DHT_RO_NONE,
+ NULL,
+ 0,
+ &get_result_iterator,
NULL);
- get_handle =
- GNUNET_DHT_get_start (dht_handle, query_type, &key, replication,
- (demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE,
- NULL, 0,
- &get_result_iterator,
- NULL);
}
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_string ('k',
- "key",
- "KEY",
- gettext_noop ("the query key"),
- &query_key),
- GNUNET_GETOPT_option_uint ('r',
- "replication",
- "LEVEL",
- gettext_noop ("how many parallel requests (replicas) to create"),
- &replication),
- GNUNET_GETOPT_option_uint ('t',
- "type",
- "TYPE",
- gettext_noop ("the type of data to look for"),
- &query_type),
- GNUNET_GETOPT_option_relative_time ('T',
- "timeout",
- "TIMEOUT",
- gettext_noop ("how long to execute this query before giving up?"),
- &timeout_request),
- GNUNET_GETOPT_option_flag ('x',
- "demultiplex",
- gettext_noop ("use DHT's demultiplex everywhere option"),
- &demultixplex_everywhere),
- GNUNET_GETOPT_option_verbose (&verbose),
- GNUNET_GETOPT_OPTION_END
- };
-
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_string ('k',
+ "key",
+ "KEY",
+ gettext_noop ("the query key"),
+ &query_key),
+ GNUNET_GETOPT_option_uint (
+ 'r',
+ "replication",
+ "LEVEL",
+ gettext_noop ("how many parallel requests (replicas) to create"),
+ &replication),
+ GNUNET_GETOPT_option_uint ('t',
+ "type",
+ "TYPE",
+ gettext_noop ("the type of data to look for"),
+ &query_type),
+ GNUNET_GETOPT_option_relative_time (
+ 'T',
+ "timeout",
+ "TIMEOUT",
+ gettext_noop ("how long to execute this query before giving up?"),
+ &timeout_request),
+ GNUNET_GETOPT_option_flag ('x',
+ "demultiplex",
+ gettext_noop (
+ "use DHT's demultiplex everywhere option"),
+ &demultixplex_everywhere),
+ GNUNET_GETOPT_option_verbose (&verbose),
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-get",
- gettext_noop
- ("Issue a GET request to the GNUnet DHT, prints results."),
- options, &run, NULL)) ? ret : 1;
+ GNUNET_PROGRAM_run (
+ argc,
+ argv,
+ "gnunet-dht-get",
+ gettext_noop (
+ "Issue a GET request to the GNUnet DHT, prints results."),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
}
/* end of gnunet-dht-get.c */
/**
* User supplied timeout value (in seconds)
*/
-static struct GNUNET_TIME_Relative timeout_request = { 60000 };
+static struct GNUNET_TIME_Relative timeout_request = {60000};
/**
* Be verbose
cleanup_task (void *cls)
{
if (verbose)
- FPRINTF (stderr, "%s", "Cleaning up!\n");
+ fprintf (stderr, "%s", "Cleaning up!\n");
if (NULL != monitor_handle)
{
GNUNET_DHT_monitor_stop (monitor_handle);
}
-
/**
* Callback called on each GET request going through the DHT.
*
uint32_t desired_replication_level,
unsigned int path_length,
const struct GNUNET_PeerIdentity *path,
- const struct GNUNET_HashCode * key)
+ const struct GNUNET_HashCode *key)
{
- FPRINTF (stdout,
+ fprintf (stdout,
"GET #%u: type %d, key `%s'\n",
result_count,
(int) type,
- GNUNET_h2s_full(key));
+ GNUNET_h2s_full (key));
result_count++;
}
const struct GNUNET_PeerIdentity *put_path,
unsigned int put_path_length,
struct GNUNET_TIME_Absolute exp,
- const struct GNUNET_HashCode * key,
+ const struct GNUNET_HashCode *key,
const void *data,
size_t size)
{
- FPRINTF (stdout,
+ fprintf (stdout,
(GNUNET_BLOCK_TYPE_TEST == type)
- ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n"
- : "RESPONSE #%u (%s): type %d, key `%s'\n",
+ ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n"
+ : "RESPONSE #%u (%s): type %d, key `%s'\n",
result_count,
GNUNET_STRINGS_absolute_time_to_string (exp),
(int) type,
unsigned int path_length,
const struct GNUNET_PeerIdentity *path,
struct GNUNET_TIME_Absolute exp,
- const struct GNUNET_HashCode * key,
+ const struct GNUNET_HashCode *key,
const void *data,
size_t size)
{
- FPRINTF (stdout,
+ fprintf (stdout,
(GNUNET_BLOCK_TYPE_TEST == type)
- ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n"
- : "PUT %u (%s): type %d, key `%s'\n",
+ ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n"
+ : "PUT %u (%s): type %d, key `%s'\n",
result_count,
GNUNET_STRINGS_absolute_time_to_string (exp),
(int) type,
- GNUNET_h2s_full(key),
+ GNUNET_h2s_full (key),
(unsigned int) size,
(char *) data);
result_count++;
if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
{
- FPRINTF (stderr, "%s",
- _("Failed to connect to DHT service!\n"));
+ fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n"));
ret = 1;
return;
}
- if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */
+ if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */
block_type = GNUNET_BLOCK_TYPE_TEST;
if (NULL != query_key)
- {
- key = &hc;
- if (GNUNET_OK !=
- GNUNET_CRYPTO_hash_from_string (query_key, key))
- GNUNET_CRYPTO_hash (query_key, strlen (query_key), key);
- }
+ {
+ key = &hc;
+ if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (query_key, key))
+ GNUNET_CRYPTO_hash (query_key, strlen (query_key), key);
+ }
else
- {
- key = NULL;
- }
+ {
+ key = NULL;
+ }
if (verbose)
- FPRINTF (stderr,
- "Monitoring for %s\n",
- GNUNET_STRINGS_relative_time_to_string (timeout_request, GNUNET_NO));
- tt = GNUNET_SCHEDULER_add_delayed (timeout_request,
- &timeout_task,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
- NULL);
+ fprintf (stderr,
+ "Monitoring for %s\n",
+ GNUNET_STRINGS_relative_time_to_string (timeout_request,
+ GNUNET_NO));
+ tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
block_type,
key,
&query_key),
GNUNET_GETOPT_option_uint ('t',
- "type",
- "TYPE",
- gettext_noop ("the type of data to look for"),
- &block_type),
-
- GNUNET_GETOPT_option_relative_time ('T',
- "timeout",
- "TIMEOUT",
- gettext_noop ("how long should the monitor command run"),
- &timeout_request),
+ "type",
+ "TYPE",
+ gettext_noop ("the type of data to look for"),
+ &block_type),
+
+ GNUNET_GETOPT_option_relative_time (
+ 'T',
+ "timeout",
+ "TIMEOUT",
+ gettext_noop ("how long should the monitor command run"),
+ &timeout_request),
GNUNET_GETOPT_option_flag ('V',
- "verbose",
- gettext_noop ("be verbose (print progress information)"),
- &verbose),
+ "verbose",
+ gettext_noop (
+ "be verbose (print progress information)"),
+ &verbose),
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-monitor",
- gettext_noop
- ("Prints all packets that go through the DHT."),
- options, &run, NULL)) ? ret : 1;
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-dht-monitor",
+ gettext_noop (
+ "Prints all packets that go through the DHT."),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
}
/* end of gnunet-dht-monitor.c */
static void
message_sent_cont (void *cls)
{
- GNUNET_SCHEDULER_add_now (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
cfg = c;
if ((NULL == query_key) || (NULL == data))
{
- FPRINTF (stderr, "%s", _("Must provide KEY and DATA for DHT put!\n"));
+ fprintf (stderr, "%s", _ ("Must provide KEY and DATA for DHT put!\n"));
ret = 1;
return;
}
if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
{
- FPRINTF (stderr,
- _("Could not connect to DHT service!\n"));
+ fprintf (stderr, _ ("Could not connect to DHT service!\n"));
ret = 1;
return;
}
- if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */
+ if (GNUNET_BLOCK_TYPE_ANY == query_type) /* Type of data not set */
query_type = GNUNET_BLOCK_TYPE_TEST;
GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
if (verbose)
- FPRINTF (stderr,
- _("Issuing put request for `%s' with data `%s'!\n"),
+ fprintf (stderr,
+ _ ("Issuing put request for `%s' with data `%s'!\n"),
query_key,
data);
ro = GNUNET_DHT_RO_NONE;
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_string ('d',
- "data",
- "DATA",
- gettext_noop ("the data to insert under the key"),
- &data),
- GNUNET_GETOPT_option_relative_time ('e',
- "expiration",
- "EXPIRATION",
- gettext_noop ("how long to store this entry in the dht (in seconds)"),
- &expiration),
- GNUNET_GETOPT_option_string ('k',
- "key",
- "KEY",
- gettext_noop ("the query key"),
- &query_key),
- GNUNET_GETOPT_option_flag ('x',
- "demultiplex",
- gettext_noop ("use DHT's demultiplex everywhere option"),
- &demultixplex_everywhere),
- GNUNET_GETOPT_option_uint ('r',
- "replication",
- "LEVEL",
- gettext_noop ("how many replicas to create"),
- &replication),
- GNUNET_GETOPT_option_flag ('R',
- "record",
- gettext_noop ("use DHT's record route option"),
- &record_route),
- GNUNET_GETOPT_option_uint ('t',
- "type",
- "TYPE",
- gettext_noop ("the type to insert data as"),
- &query_type),
- GNUNET_GETOPT_option_verbose (&verbose),
- GNUNET_GETOPT_OPTION_END
- };
-
-
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_string ('d',
+ "data",
+ "DATA",
+ gettext_noop (
+ "the data to insert under the key"),
+ &data),
+ GNUNET_GETOPT_option_relative_time (
+ 'e',
+ "expiration",
+ "EXPIRATION",
+ gettext_noop ("how long to store this entry in the dht (in seconds)"),
+ &expiration),
+ GNUNET_GETOPT_option_string ('k',
+ "key",
+ "KEY",
+ gettext_noop ("the query key"),
+ &query_key),
+ GNUNET_GETOPT_option_flag ('x',
+ "demultiplex",
+ gettext_noop (
+ "use DHT's demultiplex everywhere option"),
+ &demultixplex_everywhere),
+ GNUNET_GETOPT_option_uint ('r',
+ "replication",
+ "LEVEL",
+ gettext_noop ("how many replicas to create"),
+ &replication),
+ GNUNET_GETOPT_option_flag ('R',
+ "record",
+ gettext_noop ("use DHT's record route option"),
+ &record_route),
+ GNUNET_GETOPT_option_uint ('t',
+ "type",
+ "TYPE",
+ gettext_noop ("the type to insert data as"),
+ &query_type),
+ GNUNET_GETOPT_option_verbose (&verbose),
+ GNUNET_GETOPT_OPTION_END};
+
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
expiration = GNUNET_TIME_UNIT_HOURS;
return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-dht-put",
- gettext_noop
- ("Issue a PUT request to the GNUnet DHT insert DATA under KEY."),
- options,
- &run,
- NULL))
- ? ret : 1;
+ GNUNET_PROGRAM_run (
+ argc,
+ argv,
+ "gnunet-dht-put",
+ gettext_noop (
+ "Issue a PUT request to the GNUnet DHT insert DATA under KEY."),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
}
/* end of gnunet-dht-put.c */
end_badly (void *cls)
{
die_task = NULL;
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Ending on an unhappy note.\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
for (i = 0; NULL != stats[i].name; i++)
- FPRINTF (stderr,
+ fprintf (stderr,
"%6s/%60s = %12llu\n",
stats[i].subsystem,
stats[i].name,
const char *buf;
#if DETAILS
- FPRINTF (stderr, "%s", "M! "); /* message complete, good! */
+ fprintf (stderr, "%s", "M! "); /* message complete, good! */
#endif
buf = (const char *) hdr;
for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++)
total++;
#if ! DETAILS
if (0 == (total % (NUM_MSGS / 100)))
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
#endif
/* tolerate 10% loss, i.e. due to duplicate fragment IDs */
if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
{
frag_drops++;
#if DETAILS
- FPRINTF (stderr, "%s", "DF "); /* dropped Frag */
+ fprintf (stderr, "%s", "DF "); /* dropped Frag */
#endif
return; /* random drop */
}
if (NULL == defrag)
{
- FPRINTF (stderr, "%s", "?E "); /* Error: frag after shutdown!? */
+ fprintf (stderr, "%s", "?E "); /* Error: frag after shutdown!? */
return;
}
ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
if (ret == GNUNET_NO)
{
#if DETAILS
- FPRINTF (stderr, "%s", "FF "); /* duplicate fragment */
+ fprintf (stderr, "%s", "FF "); /* duplicate fragment */
#endif
dups++;
}
else if (ret == GNUNET_OK)
{
#if DETAILS
- FPRINTF (stderr, "%s", "F! "); /* good fragment */
+ fprintf (stderr, "%s", "F! "); /* good fragment */
#endif
fragc++;
}
if (i == NUM_MSGS)
return;
#if DETAILS
- FPRINTF (stderr, "%s", "T! "); /* sending message */
+ fprintf (stderr, "%s", "T! "); /* sending message */
#endif
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons ((uint16_t) i);
{
ack_drops++;
#if DETAILS
- FPRINTF (stderr, "%s", "DA "); /* dropped ACK */
+ fprintf (stderr, "%s", "DA "); /* dropped ACK */
#endif
return; /* random drop */
}
if (ret == GNUNET_OK)
{
#if DETAILS
- FPRINTF (stderr, "%s", "GA "); /* good ACK */
+ fprintf (stderr, "%s", "GA "); /* good ACK */
#endif
next_transmission ();
acks++;
if (ret == GNUNET_NO)
{
#if DETAILS
- FPRINTF (stderr, "%s", "AA "); /* duplciate ACK */
+ fprintf (stderr, "%s", "AA "); /* duplciate ACK */
#endif
acks++;
return;
}
}
#if DETAILS
- FPRINTF (stderr, "%s", "?A "); /* BAD: ack that nobody feels responsible for... */
+ fprintf (stderr, "%s", "?A "); /* BAD: ack that nobody feels responsible for... */
#endif
}
"test-fragmentation", "nohelp",
options,
&run, NULL);
- FPRINTF (stderr,
+ fprintf (stderr,
"\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n",
fragc,
dups,
const char *buf;
#if DETAILS
- FPRINTF (stderr, "%s", "!"); /* message complete, good! */
+ fprintf (stderr, "%s", "!"); /* message complete, good! */
#endif
buf = (const char *) hdr;
for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++)
total++;
#if ! DETAILS
if (0 == (total % (NUM_MSGS / 100)))
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
#endif
/* tolerate 10% loss, i.e. due to duplicate fragment IDs */
if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
if (ret == GNUNET_OK)
{
#if DETAILS
- FPRINTF (stderr, "%s", "@"); /* good ACK */
+ fprintf (stderr, "%s", "@"); /* good ACK */
#endif
GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
frags[i] = NULL;
if (ret == GNUNET_NO)
{
#if DETAILS
- FPRINTF (stderr, "%s", "@"); /* good ACK */
+ fprintf (stderr, "%s", "@"); /* good ACK */
#endif
acks++;
return;
}
}
#if DETAILS
- FPRINTF (stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */
+ fprintf (stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */
#endif
}
}
if (NULL == defrag)
{
- FPRINTF (stderr, "%s", "E"); /* Error: frag after shutdown!? */
+ fprintf (stderr, "%s", "E"); /* Error: frag after shutdown!? */
return;
}
ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
if (ret == GNUNET_NO)
{
#if DETAILS
- FPRINTF (stderr, "%s", "?"); /* duplicate fragment */
+ fprintf (stderr, "%s", "?"); /* duplicate fragment */
#endif
dups++;
}
else if (ret == GNUNET_OK)
{
#if DETAILS
- FPRINTF (stderr, "%s", "."); /* good fragment */
+ fprintf (stderr, "%s", "."); /* good fragment */
#endif
fragc++;
}
100);
GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options,
&run, NULL);
- FPRINTF (stderr,
+ fprintf (stderr,
"\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n",
fragc, dups, acks, ack_drops);
return ret;
qe->h->active_downloads++;
qe->start_time = GNUNET_TIME_absolute_get ();
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting job %p (%u active)\n",
- qe,
- qe->h->active_downloads);
- GNUNET_CONTAINER_DLL_remove (qe->h->pending_head,
- qe->h->pending_tail,
- qe);
+ "Starting job %p (%u active)\n",
+ qe,
+ qe->h->active_downloads);
+ GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe);
GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head,
qe->h->running_tail,
qe->h->running_tail,
GNUNET_assert (0 < qe->h->active_downloads);
qe->h->active_downloads--;
qe->h->active_blocks -= qe->blocks;
- qe->run_time =
- GNUNET_TIME_relative_add (qe->run_time,
- GNUNET_TIME_absolute_get_duration
- (qe->start_time));
+ qe->run_time = GNUNET_TIME_relative_add (qe->run_time,
+ GNUNET_TIME_absolute_get_duration (
+ qe->start_time));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping job %p (%u active)\n",
- qe,
- qe->h->active_downloads);
- GNUNET_CONTAINER_DLL_remove (qe->h->running_head,
- qe->h->running_tail,
- qe);
+ "Stopping job %p (%u active)\n",
+ qe,
+ qe->h->active_downloads);
+ GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe);
GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head,
qe->h->pending_tail,
qe->h->pending_tail,
rst = GNUNET_TIME_absolute_get_remaining (end_time);
if (0 == rst.rel_value_us)
{
- num_probes_expired++;
- stop_job (qe);
+ num_probes_expired++;
+ stop_job (qe);
}
else
{
- num_probes_active++;
- restart_at = GNUNET_TIME_relative_min (rst, restart_at);
+ num_probes_active++;
+ restart_at = GNUNET_TIME_relative_min (rst, restart_at);
}
break;
case GNUNET_FS_QUEUE_PRIORITY_NORMAL:
rst = GNUNET_TIME_absolute_get_remaining (end_time);
if (0 == rst.rel_value_us)
{
- num_downloads_expired++;
- stop_job (qe);
+ num_downloads_expired++;
+ stop_job (qe);
}
else
{
- num_downloads_active++;
- restart_at = GNUNET_TIME_relative_min (rst, restart_at);
+ num_downloads_active++;
+ restart_at = GNUNET_TIME_relative_min (rst, restart_at);
}
break;
default:
GNUNET_break (h->active_downloads ==
num_downloads_active + num_probes_active);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n",
- num_probes_active,
- num_probes_expired,
- num_probes_waiting,
- num_downloads_active,
- num_downloads_expired,
- num_downloads_waiting);
+ "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n",
+ num_probes_active,
+ num_probes_expired,
+ num_probes_waiting,
+ num_downloads_active,
+ num_downloads_expired,
+ num_downloads_waiting);
GNUNET_break (h->active_downloads + num_probes_active <=
h->max_parallel_downloads);
/* calculate start/stop decisions */
if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads)
{
/* stop as many probes as there are downloads and probes */
- num_probes_change = - GNUNET_MIN (num_probes_active,
- num_downloads_waiting);
+ num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting);
/* start as many downloads as there are free slots, including those
we just opened up */
- num_downloads_change = h->max_parallel_downloads - h->active_downloads - num_probes_change;
+ num_downloads_change =
+ h->max_parallel_downloads - h->active_downloads - num_probes_change;
}
else
{
/* start all downloads (we can) */
num_downloads_change = num_downloads_waiting;
/* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */
- if (1 + h->max_parallel_downloads / 4 >= (h->active_downloads + num_downloads_change))
- num_probes_change = GNUNET_MIN (num_probes_waiting,
- (1 + h->max_parallel_downloads / 4) - (h->active_downloads + num_downloads_change));
+ if (1 + h->max_parallel_downloads / 4 >=
+ (h->active_downloads + num_downloads_change))
+ num_probes_change =
+ GNUNET_MIN (num_probes_waiting,
+ (1 + h->max_parallel_downloads / 4) -
+ (h->active_downloads + num_downloads_change));
else
num_probes_change = 0;
}
GNUNET_break (num_downloads_change <= num_downloads_waiting);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Changing %d probes and %d/%u/%u downloads\n",
- num_probes_change,
- num_downloads_change,
+ "Changing %d probes and %d/%u/%u downloads\n",
+ num_probes_change,
+ num_downloads_change,
(unsigned int) h->active_downloads,
(unsigned int) h->max_parallel_downloads);
/* actually stop probes */
stop_job (qe);
num_probes_change++;
if (0 == num_probes_change)
- break;
+ break;
}
}
GNUNET_break (0 <= num_probes_change);
/* start some more tasks if we now have empty slots */
block_limit_hit = GNUNET_NO;
next = h->pending_head;
- while ( (NULL != (qe = next)) &&
- ( (num_probes_change > 0) ||
- (num_downloads_change > 0) ) )
+ while ((NULL != (qe = next)) &&
+ ((num_probes_change > 0) || (num_downloads_change > 0)))
{
next = qe->next;
switch (qe->priority)
case GNUNET_FS_QUEUE_PRIORITY_PROBE:
if (num_probes_change > 0)
{
- start_job (qe);
- num_probes_change--;
- run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2);
- restart_at = GNUNET_TIME_relative_min (run_time, restart_at);
+ start_job (qe);
+ num_probes_change--;
+ run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2);
+ restart_at = GNUNET_TIME_relative_min (run_time, restart_at);
}
break;
case GNUNET_FS_QUEUE_PRIORITY_NORMAL:
- if ( (num_downloads_change > 0) &&
- ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) ||
- ( (qe->blocks > h->max_parallel_requests) &&
- (0 == h->active_downloads) ) ) )
+ if ((num_downloads_change > 0) &&
+ ((qe->blocks + h->active_blocks <= h->max_parallel_requests) ||
+ ((qe->blocks > h->max_parallel_requests) &&
+ (0 == h->active_downloads))))
{
- start_job (qe);
- num_downloads_change--;
+ start_job (qe);
+ num_downloads_change--;
}
else if (num_downloads_change > 0)
- block_limit_hit = GNUNET_YES;
+ block_limit_hit = GNUNET_YES;
break;
default:
GNUNET_break (0);
break;
}
}
- GNUNET_break ( (0 == num_downloads_change) ||
- (GNUNET_YES == block_limit_hit) );
+ GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit));
GNUNET_break (0 == num_probes_change);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n",
- h->active_downloads,
- h->max_parallel_requests,
- num_probes_change,
- num_downloads_change,
- GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n",
+ h->active_downloads,
+ h->max_parallel_requests,
+ num_probes_change,
+ num_downloads_change,
+ GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES));
/* make sure we run again, callbacks might have
already re-scheduled the job, so cancel such
if (NULL != h->queue_job)
GNUNET_SCHEDULER_cancel (h->queue_job);
h->queue_job =
- GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h);
+ GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h);
}
GNUNET_SCHEDULER_TaskCallback stop,
void *cls,
unsigned int blocks,
- enum GNUNET_FS_QueuePriority priority)
+ enum GNUNET_FS_QueuePriority priority)
{
struct GNUNET_FS_QueueEntry *qe;
qe->queue_time = GNUNET_TIME_absolute_get ();
qe->blocks = blocks;
qe->priority = priority;
- GNUNET_CONTAINER_DLL_insert_after (h->pending_head, h->pending_tail,
- h->pending_tail, qe);
+ GNUNET_CONTAINER_DLL_insert_after (h->pending_head,
+ h->pending_tail,
+ h->pending_tail,
+ qe);
if (NULL != h->queue_job)
GNUNET_SCHEDULER_cancel (h->queue_job);
h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing job %p\n",
- qe);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe);
return qe;
}
struct GNUNET_FS_Handle *h;
h = qe->h;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dequeueing job %p\n",
- qe);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe);
if (GNUNET_YES == qe->active)
stop_job (qe);
- GNUNET_CONTAINER_DLL_remove (h->pending_head,
- h->pending_tail,
- qe);
+ GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe);
GNUNET_free (qe);
if (NULL != h->queue_job)
GNUNET_SCHEDULER_cancel (h->queue_job);
- h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue,
- h);
+ h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h);
}
ret = GNUNET_new (struct TopLevelActivity);
ret->ssf = ssf;
ret->ssf_cls = ssf_cls;
- GNUNET_CONTAINER_DLL_insert (h->top_head,
- h->top_tail,
- ret);
+ GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret);
return ret;
}
* @param top top level activity entry
*/
void
-GNUNET_FS_end_top (struct GNUNET_FS_Handle *h,
- struct TopLevelActivity *top)
+GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top)
{
- GNUNET_CONTAINER_DLL_remove (h->top_head,
- h->top_tail,
- top);
+ GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top);
GNUNET_free (top);
}
}
if (NULL == fi->fd)
{
- fi->fd =
- GNUNET_DISK_file_open (fi->filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ fi->fd = GNUNET_DISK_file_open (fi->filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
if (NULL == fi->fd)
{
GNUNET_asprintf (emsg,
- _("Could not open file `%s': %s"),
+ _ ("Could not open file `%s': %s"),
fi->filename,
- STRERROR (errno));
+ strerror (errno));
return 0;
}
}
- if ( (GNUNET_SYSERR ==
- GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) ||
- (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))) )
+ if ((GNUNET_SYSERR ==
+ GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) ||
+ (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))))
{
GNUNET_asprintf (emsg,
- _("Could not read file `%s': %s"),
+ _ ("Could not read file `%s': %s"),
fi->filename,
- STRERROR (errno));
+ strerror (errno));
return 0;
}
if (ret != max)
{
GNUNET_asprintf (emsg,
- _("Short read reading from file `%s'!"),
+ _ ("Short read reading from file `%s'!"),
fi->filename);
return 0;
}
char *ret;
if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
- return NULL; /* persistence not requested */
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR",
- &basename))
+ return NULL; /* persistence not requested */
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg,
+ "fs",
+ "STATE_DIR",
+ &basename))
return NULL;
- GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s", basename, DIR_SEPARATOR_STR,
- h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR,
+ GNUNET_asprintf (&ret,
+ "%s%s%s%s%s%s%s",
+ basename,
+ DIR_SEPARATOR_STR,
+ h->client_name,
+ DIR_SEPARATOR_STR,
+ ext,
+ DIR_SEPARATOR_STR,
ent);
GNUNET_free (basename);
return ret;
char *ret;
if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
- return NULL; /* persistence not requested */
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR",
- &basename))
+ return NULL; /* persistence not requested */
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg,
+ "fs",
+ "STATE_DIR",
+ &basename))
return NULL;
- GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s.dir%s%s", basename, DIR_SEPARATOR_STR,
- h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR,
- uni, DIR_SEPARATOR_STR, ent);
+ GNUNET_asprintf (&ret,
+ "%s%s%s%s%s%s%s.dir%s%s",
+ basename,
+ DIR_SEPARATOR_STR,
+ h->client_name,
+ DIR_SEPARATOR_STR,
+ ext,
+ DIR_SEPARATOR_STR,
+ uni,
+ DIR_SEPARATOR_STR,
+ ent);
GNUNET_free (basename);
return ret;
}
* @return NULL on error
*/
static struct GNUNET_BIO_ReadHandle *
-get_read_handle (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *ent)
+get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
{
char *fn;
struct GNUNET_BIO_ReadHandle *ret;
* @return NULL on error
*/
static struct GNUNET_BIO_WriteHandle *
-get_write_handle (struct GNUNET_FS_Handle *h,
- const char *ext,
- const char *ent)
+get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent)
{
char *fn;
struct GNUNET_BIO_WriteHandle *ret;
* @return NULL on error
*/
static struct GNUNET_BIO_WriteHandle *
-get_write_handle_in_dir (struct GNUNET_FS_Handle *h, const char *ext,
- const char *uni, const char *ent)
+get_write_handle_in_dir (struct GNUNET_FS_Handle *h,
+ const char *ext,
+ const char *uni,
+ const char *ent)
{
char *fn;
struct GNUNET_BIO_WriteHandle *ret;
filename = get_serialization_file_name (h, ext, ent);
if (NULL != filename)
{
- if ( (0 != UNLINK (filename)) &&
- (ENOENT != errno) )
+ if ((0 != unlink (filename)) && (ENOENT != errno))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
GNUNET_free (filename);
}
static void
remove_sync_file_in_dir (struct GNUNET_FS_Handle *h,
const char *ext,
- const char *uni, const char *ent)
+ const char *uni,
+ const char *ent)
{
char *filename;
filename = get_serialization_file_name_in_dir (h, ext, uni, ent);
if (NULL == filename)
return;
- if (0 != UNLINK (filename))
+ if (0 != unlink (filename))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
GNUNET_free (filename);
}
* @return NULL on error
*/
static struct GNUNET_FS_FileInformation *
-deserialize_file_information (struct GNUNET_FS_Handle *h,
- const char *filename);
+deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename);
/**
filename = NULL;
if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) ||
(GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) ||
- ( (NULL != ksks) &&
- ( (NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ||
- (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)) ) ) ||
+ ((NULL != ksks) &&
+ ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) ||
+ (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) ||
(GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) ||
- ( (NULL != chks) &&
- ( (NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
- (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri))) ) ||
+ ((NULL != chks) &&
+ ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) ||
+ (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) ||
(GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) ||
- ( (NULL != skss) &&
- ( (NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) ||
- (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri))) ) ||
+ ((NULL != skss) &&
+ ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) ||
+ (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) ||
(GNUNET_OK != read_start_time (rh, &ret->start_time)) ||
- (GNUNET_OK != GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024))
- || (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) ||
(GNUNET_OK !=
GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) ||
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) ||
}
switch (b)
{
- case 0: /* file-insert */
+ case 0: /* file-insert */
if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size))
{
GNUNET_break (0);
{
ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
ret->data.file.reader_cls =
- GNUNET_malloc_large (ret->data.file.file_size);
+ GNUNET_malloc_large (ret->data.file.file_size);
if (ret->data.file.reader_cls == NULL)
goto cleanup;
- if (GNUNET_OK !=
- GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls,
- ret->data.file.file_size))
+ if (GNUNET_OK != GNUNET_BIO_read (rh,
+ "file-data",
+ ret->data.file.reader_cls,
+ ret->data.file.file_size))
{
GNUNET_break (0);
goto cleanup;
{
ret->data.file.reader = &GNUNET_FS_data_reader_file_;
ret->data.file.reader_cls =
- GNUNET_FS_make_file_reader_context_ (ret->filename);
+ GNUNET_FS_make_file_reader_context_ (ret->filename);
}
}
break;
- case 1: /* file-index, no hash */
+ case 1: /* file-index, no hash */
if (NULL == ret->filename)
{
GNUNET_break (0);
ret->data.file.index_start_confirmed = GNUNET_NO;
ret->data.file.reader = &GNUNET_FS_data_reader_file_;
ret->data.file.reader_cls =
- GNUNET_FS_make_file_reader_context_ (ret->filename);
+ GNUNET_FS_make_file_reader_context_ (ret->filename);
break;
- case 2: /* file-index-with-hash */
+ case 2: /* file-index-with-hash */
if (NULL == ret->filename)
{
GNUNET_break (0);
goto cleanup;
}
if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
- sizeof (struct GNUNET_HashCode))))
+ (GNUNET_OK != GNUNET_BIO_read (rh,
+ "fileid",
+ &ret->data.file.file_id,
+ sizeof (struct GNUNET_HashCode))))
{
GNUNET_break (0);
goto cleanup;
ret->data.file.index_start_confirmed = GNUNET_NO;
ret->data.file.reader = &GNUNET_FS_data_reader_file_;
ret->data.file.reader_cls =
- GNUNET_FS_make_file_reader_context_ (ret->filename);
+ GNUNET_FS_make_file_reader_context_ (ret->filename);
break;
- case 3: /* file-index-with-hash-confirmed */
+ case 3: /* file-index-with-hash-confirmed */
if (NULL == ret->filename)
{
GNUNET_break (0);
goto cleanup;
}
if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id,
- sizeof (struct GNUNET_HashCode))))
+ (GNUNET_OK != GNUNET_BIO_read (rh,
+ "fileid",
+ &ret->data.file.file_id,
+ sizeof (struct GNUNET_HashCode))))
{
GNUNET_break (0);
goto cleanup;
ret->data.file.index_start_confirmed = GNUNET_YES;
ret->data.file.reader = &GNUNET_FS_data_reader_file_;
ret->data.file.reader_cls =
- GNUNET_FS_make_file_reader_context_ (ret->filename);
+ GNUNET_FS_make_file_reader_context_ (ret->filename);
break;
- case 4: /* directory */
+ case 4: /* directory */
ret->is_directory = GNUNET_YES;
if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) ||
- (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) ||
- (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) ||
(NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) ||
(GNUNET_OK !=
GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) ||
* @return NULL on error
*/
static struct GNUNET_FS_FileInformation *
-deserialize_file_information (struct GNUNET_FS_Handle *h,
- const char *filename)
+deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename)
{
struct GNUNET_FS_FileInformation *ret;
struct GNUNET_BIO_ReadHandle *rh;
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume publishing information `%s': %s\n"),
- filename, emsg);
+ _ ("Failed to resume publishing information `%s': %s\n"),
+ filename,
+ emsg);
GNUNET_free (emsg);
}
if (NULL == ret)
{
- fn = get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename);
+ fn =
+ get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename);
if (NULL != fn)
{
- if (0 != UNLINK (fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
+ if (0 != unlink (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
GNUNET_free (fn);
}
}
* @return NULL on errror
*/
static char *
-make_serialization_file_name (struct GNUNET_FS_Handle *h,
- const char *ext)
+make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext)
{
char *fn;
char *dn;
char *ret;
if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
- return NULL; /* persistence not requested */
+ return NULL; /* persistence not requested */
dn = get_serialization_file_name (h, ext, "");
if (NULL == dn)
return NULL;
fn = GNUNET_DISK_mktemp (dn);
GNUNET_free (dn);
if (NULL == fn)
- return NULL; /* epic fail */
+ return NULL; /* epic fail */
ret = get_serialization_short_name (fn);
GNUNET_free (fn);
return ret;
char *ret;
if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE))
- return NULL; /* persistence not requested */
+ return NULL; /* persistence not requested */
dn = get_serialization_file_name_in_dir (h, ext, uni, "");
if (NULL == dn)
return NULL;
fn = GNUNET_DISK_mktemp (dn);
GNUNET_free (dn);
if (NULL == fn)
- return NULL; /* epic fail */
+ return NULL; /* epic fail */
ret = get_serialization_short_name (fn);
GNUNET_free (fn);
return ret;
{
left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off);
ret =
- fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg);
+ fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg);
if (0 == ret)
{
GNUNET_free (emsg);
if (NULL == fi->serialization)
fi->serialization =
- make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
+ make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO);
if (NULL == fi->serialization)
return;
- wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
- fi->serialization);
+ wh =
+ get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization);
if (NULL == wh)
{
GNUNET_free (fi->serialization);
switch (b)
{
- case 0: /* file-insert */
+ case 0: /* file-insert */
if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size))
{
GNUNET_break (0);
goto cleanup;
}
break;
- case 1: /* file-index, no hash */
+ case 1: /* file-index, no hash */
if (NULL == fi->filename)
{
GNUNET_break (0);
goto cleanup;
}
break;
- case 2: /* file-index-with-hash */
- case 3: /* file-index-with-hash-confirmed */
+ case 2: /* file-index-with-hash */
+ case 3: /* file-index-with-hash-confirmed */
if (NULL == fi->filename)
{
GNUNET_break (0);
goto cleanup;
}
if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &fi->data.file.file_id,
- sizeof (struct GNUNET_HashCode))))
+ (GNUNET_OK != GNUNET_BIO_write (wh,
+ &fi->data.file.file_id,
+ sizeof (struct GNUNET_HashCode))))
{
GNUNET_break (0);
goto cleanup;
}
break;
- case 4: /* directory */
- if ( (NULL != fi->data.dir.entries) &&
- (NULL == fi->data.dir.entries->serialization) )
+ case 4: /* directory */
+ if ((NULL != fi->data.dir.entries) &&
+ (NULL == fi->data.dir.entries->serialization))
GNUNET_FS_file_information_sync_ (fi->data.dir.entries);
if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) ||
- (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) ||
- (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) ||
(GNUNET_OK !=
- GNUNET_BIO_write (wh, fi->data.dir.dir_data,
- (uint32_t) fi->data.dir.dir_size)) ||
+ GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) ||
+ (GNUNET_OK != GNUNET_BIO_write (wh,
+ fi->data.dir.dir_data,
+ (uint32_t) fi->data.dir.dir_size)) ||
(GNUNET_OK !=
GNUNET_BIO_write_string (wh,
- (fi->data.dir.entries ==
- NULL) ? NULL : fi->data.dir.
- entries->serialization)))
+ (fi->data.dir.entries == NULL)
+ ? NULL
+ : fi->data.dir.entries->serialization)))
{
GNUNET_break (0);
goto cleanup;
GNUNET_assert (0);
goto cleanup;
}
- if ( (NULL != fi->next) &&
- (NULL == fi->next->serialization) )
+ if ((NULL != fi->next) && (NULL == fi->next->serialization))
GNUNET_FS_file_information_sync_ (fi->next);
- if (GNUNET_OK !=
- GNUNET_BIO_write_string (wh,
- (fi->next !=
- NULL) ? fi->next->serialization : NULL))
+ if (GNUNET_OK != GNUNET_BIO_write_string (wh,
+ (fi->next != NULL)
+ ? fi->next->serialization
+ : NULL))
{
GNUNET_break (0);
goto cleanup;
GNUNET_break (0);
goto cleanup;
}
- return; /* done! */
+ return; /* done! */
cleanup:
if (NULL != wh)
(void) GNUNET_BIO_write_close (wh);
GNUNET_free_non_null (chks);
GNUNET_free_non_null (ksks);
GNUNET_free_non_null (skss);
- fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
+ fn = get_serialization_file_name (fi->h,
+ GNUNET_FS_SYNC_PATH_FILE_INFO,
fi->serialization);
if (NULL != fn)
{
- if (0 != UNLINK (fn))
+ if (0 != unlink (fn))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
GNUNET_free (fn);
}
}
-
/**
* Find the entry in the file information struct where the
* serialization filename matches the given name.
* @return NULL if srch was not found in this subtree
*/
static struct GNUNET_FS_FileInformation *
-find_file_position (struct GNUNET_FS_FileInformation *pos,
- const char *srch)
+find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch)
{
struct GNUNET_FS_FileInformation *r;
{
if (0 == strcmp (srch, pos->serialization))
return pos;
- if ( (GNUNET_YES == pos->is_directory) &&
- (NULL != (r = find_file_position (pos->data.dir.entries, srch))) )
+ if ((GNUNET_YES == pos->is_directory) &&
+ (NULL != (r = find_file_position (pos->data.dir.entries, srch))))
return r;
pos = pos->next;
}
* @return #GNUNET_OK (continue to iterate)
*/
static int
-deserialize_publish_file (void *cls,
- const char *filename)
+deserialize_publish_file (void *cls, const char *filename)
{
struct GNUNET_FS_Handle *h = cls;
struct GNUNET_BIO_ReadHandle *rh;
GNUNET_break (0);
goto cleanup;
}
- if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024))
- || (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) ||
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) ||
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) ||
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) ||
(GNUNET_OK !=
GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) ||
- (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128))
- || ( (GNUNET_YES == have_ns) &&
- (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns)))) )
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) ||
+ ((GNUNET_YES == have_ns) &&
+ (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns)))))
{
GNUNET_break (0);
goto cleanup;
{
GNUNET_assert (NULL == pc->upload_task);
pc->upload_task =
- GNUNET_SCHEDULER_add_with_priority
- (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
- &GNUNET_FS_publish_main_, pc);
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
+ &GNUNET_FS_publish_main_,
+ pc);
}
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming publishing operation `%s': %s\n"),
- filename, emsg);
+ _ ("Failure while resuming publishing operation `%s': %s\n"),
+ filename,
+ emsg);
GNUNET_free (emsg);
}
- pc->top = GNUNET_FS_make_top (h,
- &GNUNET_FS_publish_signal_suspend_,
- pc);
+ pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc);
return GNUNET_OK;
cleanup:
GNUNET_free_non_null (pc->nid);
if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume publishing operation `%s': %s\n"), filename,
+ _ ("Failed to resume publishing operation `%s': %s\n"),
+ filename,
emsg);
GNUNET_free (emsg);
}
if (NULL != pc->fi)
GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
- if (0 != UNLINK (filename))
+ if (0 != unlink (filename))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
GNUNET_free (pc->serialization);
GNUNET_free (pc);
if (NULL == pc->serialization)
pc->serialization =
- make_serialization_file_name (pc->h,
- GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
+ make_serialization_file_name (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH);
if (NULL == pc->serialization)
return;
if (NULL == pc->fi)
GNUNET_break (0);
return;
}
- wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
+ wh = get_write_handle (pc->h,
+ GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
pc->serialization);
if (NULL == wh)
{
(GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
(GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) ||
(GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh,
- (NULL == pc->fi_pos) ? NULL : pc->fi_pos->serialization)) ||
- ( (NULL != pc->ns) &&
- (GNUNET_OK != GNUNET_BIO_write (wh,
- pc->ns,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) ) ))
+ (GNUNET_OK != GNUNET_BIO_write_string (wh,
+ (NULL == pc->fi_pos)
+ ? NULL
+ : pc->fi_pos->serialization)) ||
+ ((NULL != pc->ns) &&
+ (GNUNET_OK !=
+ GNUNET_BIO_write (wh,
+ pc->ns,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))))
{
GNUNET_break (0);
goto cleanup;
cleanup:
if (NULL != wh)
(void) GNUNET_BIO_write_close (wh);
- GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
+ GNUNET_FS_remove_sync_file_ (pc->h,
+ GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
pc->serialization);
GNUNET_free (pc->serialization);
pc->serialization = NULL;
if (NULL == uc->serialization)
uc->serialization =
- make_serialization_file_name (uc->h,
- GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
+ make_serialization_file_name (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX);
if (NULL == uc->serialization)
return;
- wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
+ wh = get_write_handle (uc->h,
+ GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
uc->serialization);
if (NULL == wh)
{
(GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
(GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) ||
((uc->state == UNINDEX_STATE_FS_NOTIFY) &&
- (GNUNET_OK !=
- GNUNET_BIO_write (wh, &uc->file_id, sizeof (struct GNUNET_HashCode)))) ||
+ (GNUNET_OK != GNUNET_BIO_write (wh,
+ &uc->file_id,
+ sizeof (struct GNUNET_HashCode)))) ||
((uc->state == UNINDEX_STATE_ERROR) &&
(GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg))))
{
cleanup:
if (NULL != wh)
(void) GNUNET_BIO_write_close (wh);
- GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
+ GNUNET_FS_remove_sync_file_ (uc->h,
+ GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
uc->serialization);
GNUNET_free (uc->serialization);
uc->serialization = NULL;
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) ||
(dr->num_children > CHK_PER_INODE) ||
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) ||
- ( (0 == dr->depth) &&
- (dr->num_children > 0) ) ||
+ ((0 == dr->depth) && (dr->num_children > 0)) ||
((dr->depth > 0) && (0 == dr->num_children)))
{
GNUNET_break (0);
}
if (dr->num_children > 0)
dr->children =
- GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *));
+ GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *));
switch (dr->state)
{
case BRS_INIT:
if (dc->parent == NULL)
return get_serialization_file_name (dc->h,
- (dc->search != NULL) ?
- GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
- GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
+ (dc->search != NULL)
+ ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
+ : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
uni);
if (NULL == dc->parent->serialization)
return NULL;
if (NULL != wh)
(void) GNUNET_BIO_write_close (wh);
GNUNET_free_non_null (uris);
- if (0 != UNLINK (fn))
+ if (0 != unlink (fn))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
GNUNET_free (fn);
GNUNET_free (dc->serialization);
uris = NULL;
if (NULL == sr->serialization)
sr->serialization =
- make_serialization_file_name_in_dir (sr->h,
- (sr->sc->psearch_result ==
- NULL) ?
- GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
- GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sr->sc->serialization);
+ make_serialization_file_name_in_dir (sr->h,
+ (sr->sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sr->sc->serialization);
if (NULL == sr->serialization)
return;
wh = get_write_handle_in_dir (sr->h,
- (sr->sc->psearch_result ==
- NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
- GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sr->sc->serialization, sr->serialization);
+ (sr->sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sr->sc->serialization,
+ sr->serialization);
if (NULL == wh)
{
GNUNET_break (0);
}
uris = GNUNET_FS_uri_to_string (sr->uri);
if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) ||
+ (GNUNET_OK != GNUNET_BIO_write_string (wh,
+ sr->download != NULL
+ ? sr->download->serialization
+ : NULL)) ||
(GNUNET_OK !=
GNUNET_BIO_write_string (wh,
- sr->download !=
- NULL ? sr->download->serialization : NULL)) ||
+ sr->update_search != NULL
+ ? sr->update_search->serialization
+ : NULL)) ||
+ (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
(GNUNET_OK !=
- GNUNET_BIO_write_string (wh,
- sr->update_search !=
- NULL ? sr->update_search->serialization : NULL))
- || (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
- (GNUNET_OK != GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode)))
- || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
+ GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) ||
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
(GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
(GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
- (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)) )
+ (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)))
{
GNUNET_break (0);
goto cleanup;
}
- if ( (NULL != sr->uri) &&
- (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
- (GNUNET_OK != GNUNET_BIO_write (wh, sr->keyword_bitmap,
- (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) )
+ if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) &&
+ (GNUNET_OK !=
+ GNUNET_BIO_write (wh,
+ sr->keyword_bitmap,
+ (sr->sc->uri->data.ksk.keywordCount + 7) / 8)))
{
GNUNET_break (0);
goto cleanup;
(void) GNUNET_BIO_write_close (wh);
remove_sync_file_in_dir (sr->h,
(NULL == sr->sc->psearch_result)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sr->sc->serialization, sr->serialization);
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sr->sc->serialization,
+ sr->serialization);
GNUNET_free (sr->serialization);
sr->serialization = NULL;
}
char in_pause;
const char *category;
- category =
- (NULL == sc->psearch_result)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
+ category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH;
if (NULL == sc->serialization)
sc->serialization = make_serialization_file_name (sc->h, category);
if (NULL == sc->serialization)
* @return #GNUNET_OK (continue to iterate)
*/
static int
-deserialize_unindex_file (void *cls,
- const char *filename)
+deserialize_unindex_file (void *cls, const char *filename)
{
struct GNUNET_FS_Handle *h = cls;
struct GNUNET_BIO_ReadHandle *rh;
(GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) ||
(GNUNET_OK != read_start_time (rh, &uc->start_time)) ||
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) ||
- (GNUNET_OK != GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) ||
- (GNUNET_OK != GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
- (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)) )
+ (GNUNET_OK !=
+ GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)))
{
GNUNET_free_non_null (uris);
GNUNET_break (0);
goto cleanup;
}
}
- if ( (uc->ksk_offset > 0) &&
- ( (NULL == uc->ksk_uri) ||
- (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount) ) )
+ if ((uc->ksk_offset > 0) &&
+ ((NULL == uc->ksk_uri) ||
+ (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount)))
{
GNUNET_break (0);
goto cleanup;
case UNINDEX_STATE_HASHING:
break;
case UNINDEX_STATE_FS_NOTIFY:
- if (GNUNET_OK !=
- GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id,
- sizeof (struct GNUNET_HashCode)))
+ if (GNUNET_OK != GNUNET_BIO_read (rh,
+ "unindex-hash",
+ &uc->file_id,
+ sizeof (struct GNUNET_HashCode)))
{
GNUNET_break (0);
goto cleanup;
GNUNET_break (0);
goto cleanup;
}
- uc->top = GNUNET_FS_make_top (h,
- &GNUNET_FS_unindex_signal_suspend_,
- uc);
+ uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc);
pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME;
pi.value.unindex.specifics.resume.message = uc->emsg;
- GNUNET_FS_unindex_make_status_ (&pi, uc,
- (uc->state ==
- UNINDEX_STATE_COMPLETE) ? uc->file_size : 0);
+ GNUNET_FS_unindex_make_status_ (&pi,
+ uc,
+ (uc->state == UNINDEX_STATE_COMPLETE)
+ ? uc->file_size
+ : 0);
switch (uc->state)
{
case UNINDEX_STATE_HASHING:
- uc->fhc =
- GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, uc->filename,
- HASHING_BLOCKSIZE,
- &GNUNET_FS_unindex_process_hash_, uc);
+ uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ uc->filename,
+ HASHING_BLOCKSIZE,
+ &GNUNET_FS_unindex_process_hash_,
+ uc);
break;
case UNINDEX_STATE_FS_NOTIFY:
uc->state = UNINDEX_STATE_HASHING;
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming unindexing operation `%s': %s\n"),
- filename, emsg);
+ _ ("Failure while resuming unindexing operation `%s': %s\n"),
+ filename,
+ emsg);
GNUNET_free (emsg);
}
return GNUNET_OK;
if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume unindexing operation `%s': %s\n"),
+ _ ("Failed to resume unindexing operation `%s': %s\n"),
filename,
emsg);
GNUNET_free (emsg);
}
if (NULL != uc->serialization)
- GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
+ GNUNET_FS_remove_sync_file_ (h,
+ GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
uc->serialization);
GNUNET_free_non_null (uc->serialization);
GNUNET_free (uc);
* @return #GNUNET_OK (continue to iterate)
*/
static int
-deserialize_search_result (void *cls,
- const char *filename)
+deserialize_search_result (void *cls, const char *filename)
{
struct GNUNET_FS_SearchContext *sc = cls;
char *ser;
{
remove_sync_file_in_dir (sc->h,
(NULL == sc->psearch_result)
- ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
- : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sc->serialization, ser);
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sc->serialization,
+ ser);
GNUNET_free (ser);
}
return GNUNET_OK;
sr->h = sc->h;
sr->sc = sc;
sr->serialization = ser;
- if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024))
- || (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
- (GNUNET_OK != GNUNET_BIO_read_string (rh, "download-lnk", &download, 16))
- || (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
- (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) ||
+ (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
(GNUNET_OK !=
- GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (struct GNUNET_HashCode)))
- || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
+ GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) ||
+ (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) ||
+ (GNUNET_OK != GNUNET_BIO_read (rh,
+ "result-key",
+ &sr->key,
+ sizeof (struct GNUNET_HashCode))) ||
+ (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) ||
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) ||
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) ||
(GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials)))
}
if (GNUNET_FS_URI_KSK == sr->sc->uri->type)
{
- sr->keyword_bitmap = GNUNET_malloc ((sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */
- if (GNUNET_OK != GNUNET_BIO_read (rh, "keyword-bitmap",
- sr->keyword_bitmap,
- (sr->sc->uri->data.ksk.keywordCount + 7) / 8))
+ sr->keyword_bitmap = GNUNET_malloc (
+ (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */
+ if (GNUNET_OK !=
+ GNUNET_BIO_read (rh,
+ "keyword-bitmap",
+ sr->keyword_bitmap,
+ (sr->sc->uri->data.ksk.keywordCount + 7) / 8))
{
GNUNET_break (0);
goto cleanup;
if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume sub-download `%s': %s\n"),
+ _ ("Failed to resume sub-download `%s': %s\n"),
download,
emsg);
GNUNET_free (emsg);
if (NULL != update_srch)
{
drh =
- get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch);
+ get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch);
if (NULL != drh)
{
deserialize_search (sc->h, drh, sr, update_srch);
if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume sub-search `%s': %s\n"),
+ _ ("Failed to resume sub-search `%s': %s\n"),
update_srch,
emsg);
GNUNET_free (emsg);
}
GNUNET_free (update_srch);
}
- GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_put (sc->master_result_map,
- &sr->key, sr,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put (
+ sc->master_result_map,
+ &sr->key,
+ sr,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming search operation `%s': %s\n"),
- filename, emsg);
+ _ ("Failure while resuming search operation `%s': %s\n"),
+ filename,
+ emsg);
GNUNET_free (emsg);
}
return GNUNET_OK;
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming search operation `%s': %s\n"),
- filename, emsg);
+ _ ("Failure while resuming search operation `%s': %s\n"),
+ filename,
+ emsg);
GNUNET_free (emsg);
}
return GNUNET_OK;
* @return #GNUNET_YES (we should continue to iterate)
*/
static int
-signal_result_resume (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct GNUNET_FS_SearchContext *sc = cls;
struct GNUNET_FS_ProgressInfo pi;
pi.value.search.specifics.resume_result.uri = sr->uri;
pi.value.search.specifics.resume_result.result = sr;
pi.value.search.specifics.resume_result.availability_rank =
- 2 * sr->availability_success - sr->availability_trials;
+ 2 * sr->availability_success - sr->availability_trials;
pi.value.search.specifics.resume_result.availability_certainty =
- sr->availability_trials;
+ sr->availability_trials;
pi.value.search.specifics.resume_result.applicability_rank =
- sr->optional_support;
+ sr->optional_support;
sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
}
if (NULL != sr->download)
* @return #GNUNET_YES (we should continue to iterate)
*/
static int
-free_result (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+free_result (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct GNUNET_FS_SearchResult *sr = value;
if (NULL != sc->serialization)
{
GNUNET_FS_remove_sync_file_ (sc->h,
- (sc->psearch_result ==
- NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
- GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ (sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
sc->serialization);
GNUNET_FS_remove_sync_dir_ (sc->h,
- (sc->psearch_result ==
- NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
- GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ (sc->psearch_result == NULL)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
sc->serialization);
}
GNUNET_free_non_null (sc->serialization);
GNUNET_FS_uri_destroy (sc->uri);
if (NULL != sc->master_result_map)
{
- GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, &free_result,
+ GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
+ &free_result,
sc);
GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
}
* @return #GNUNET_OK (continue to iterate)
*/
static int
-deserialize_subdownload (void *cls,
- const char *filename)
+deserialize_subdownload (void *cls, const char *filename)
{
struct GNUNET_FS_DownloadContext *parent = cls;
char *ser;
if (NULL == rh)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume sub-download `%s': could not open file `%s'\n"),
+ _ (
+ "Failed to resume sub-download `%s': could not open file `%s'\n"),
ser,
filename);
GNUNET_free (ser);
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to resume sub-download `%s': %s\n"),
+ _ ("Failed to resume sub-download `%s': %s\n"),
ser,
emsg);
GNUNET_free (emsg);
GNUNET_free_non_null (dc->serialization);
while (NULL != (dcc = dc->child_head))
{
- GNUNET_CONTAINER_DLL_remove (dc->child_head,
- dc->child_tail,
- dcc);
+ GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc);
free_download_context (dcc);
}
GNUNET_FS_free_download_request_ (dc->top_request);
(NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) ||
((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) &&
(GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) ||
- (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta))
- || (GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
(GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
+ GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) ||
+ (GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) ||
(GNUNET_OK !=
- GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename,
- 10 * 1024)) ||
+ GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) ||
+ (GNUNET_OK != GNUNET_BIO_read_string (rh,
+ "download-tfn",
+ &dc->temp_filename,
+ 10 * 1024)) ||
(GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) ||
(GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) ||
(GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) ||
}
dc->options = (enum GNUNET_FS_DownloadOptions) options;
dc->active =
- GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), GNUNET_NO);
+ GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE),
+ GNUNET_NO);
dc->has_finished = (int) status;
dc->treedepth =
- GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
+ GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
if (GNUNET_FS_uri_test_loc (dc->uri))
GNUNET_assert (GNUNET_OK ==
- GNUNET_FS_uri_loc_get_peer_identity (dc->uri,
- &dc->target));
+ GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target));
if (NULL == dc->emsg)
{
dc->top_request = read_download_request (rh);
goto cleanup;
}
}
- dn = get_download_sync_filename (dc,
- dc->serialization,
- ".dir");
+ dn = get_download_sync_filename (dc, dc->serialization, ".dir");
if (NULL != dn)
{
- if (GNUNET_YES ==
- GNUNET_DISK_directory_test (dn,
- GNUNET_YES))
- GNUNET_DISK_directory_scan (dn,
- &deserialize_subdownload,
- dc);
+ if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES))
+ GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc);
GNUNET_free (dn);
}
if (NULL != parent)
{
- GNUNET_CONTAINER_DLL_insert (parent->child_head,
- parent->child_tail,
- dc);
+ GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
}
if (NULL != search)
{
dc->search = search;
search->download = dc;
}
- if ( (NULL == parent) &&
- (NULL == search) )
+ if ((NULL == parent) && (NULL == search))
{
- dc->top
- = GNUNET_FS_make_top (dc->h,
- &GNUNET_FS_download_signal_suspend_,
- dc);
+ dc->top =
+ GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc);
signal_download_resume (dc);
}
GNUNET_free (uris);
GNUNET_assert (NULL == dc->job_queue);
- dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_,
- dc);
+ dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
return;
cleanup:
GNUNET_free_non_null (uris);
pi.status = GNUNET_FS_STATUS_SEARCH_RESUME;
pi.value.search.specifics.resume.message = sc->emsg;
pi.value.search.specifics.resume.is_paused =
- (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO;
+ (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO;
sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc);
GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
- &signal_result_resume, sc);
-
+ &signal_result_resume,
+ sc);
}
sc->options = (enum GNUNET_FS_SearchOptions) options;
sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO);
dn = get_serialization_file_name_in_dir (h,
- (NULL == sc->psearch_result) ?
- GNUNET_FS_SYNC_PATH_MASTER_SEARCH :
- GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
- sc->serialization, "");
+ (NULL == sc->psearch_result)
+ ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH
+ : GNUNET_FS_SYNC_PATH_CHILD_SEARCH,
+ sc->serialization,
+ "");
if (NULL != dn)
{
if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES))
if (('\0' == in_pause) &&
(GNUNET_OK != GNUNET_FS_search_start_searching_ (sc)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not resume running search, will resume as paused search\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ ("Could not resume running search, will resume as paused search\n"));
}
signal_search_resume (sc);
GNUNET_free (uris);
* @return #GNUNET_OK (continue to iterate)
*/
static int
-deserialize_search_file (void *cls,
- const char *filename)
+deserialize_search_file (void *cls, const char *filename)
{
struct GNUNET_FS_Handle *h = cls;
char *ser;
struct GNUNET_FS_SearchContext *sc;
struct stat buf;
- if (0 != STAT (filename, &buf))
+ if (0 != stat (filename, &buf))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
return GNUNET_OK;
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming search operation `%s': %s\n"),
- filename, emsg);
+ _ ("Failure while resuming search operation `%s': %s\n"),
+ filename,
+ emsg);
GNUNET_free (emsg);
}
return GNUNET_OK;
rh = GNUNET_BIO_read_open (filename);
if (NULL == rh)
{
- if (0 != UNLINK (filename))
+ if (0 != unlink (filename))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
GNUNET_free (ser);
return GNUNET_OK;
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure while resuming download operation `%s': %s\n"),
- filename, emsg);
+ _ ("Failure while resuming download operation `%s': %s\n"),
+ filename,
+ emsg);
GNUNET_free (emsg);
}
return GNUNET_OK;
*/
static void
deserialization_master (const char *master_path,
- GNUNET_FileNameCallback proc,
+ GNUNET_FileNameCallback proc,
struct GNUNET_FS_Handle *h)
{
char *dn;
const char *client_name,
GNUNET_FS_ProgressCallback upcb,
void *upcb_cls,
- enum GNUNET_FS_Flags flags, ...)
+ enum GNUNET_FS_Flags flags,
+ ...)
{
struct GNUNET_FS_Handle *ret;
enum GNUNET_FS_OPTIONS opt;
ret->flags = flags;
ret->max_parallel_downloads = DEFAULT_MAX_PARALLEL_DOWNLOADS;
ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS;
- ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
+ ret->avg_block_latency =
+ GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */
va_start (ap, flags);
- while (GNUNET_FS_OPTIONS_END != (opt = GNUNET_VA_ARG_ENUM (ap,GNUNET_FS_OPTIONS)))
+ while (GNUNET_FS_OPTIONS_END !=
+ (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS)))
{
switch (opt)
{
if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags))
{
deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
- &deserialize_publish_file, ret);
+ &deserialize_publish_file,
+ ret);
deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH,
- &deserialize_search_file, ret);
+ &deserialize_search_file,
+ ret);
deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
- &deserialize_download_file, ret);
+ &deserialize_download_file,
+ ret);
deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX,
- &deserialize_unindex_file, ret);
+ &deserialize_unindex_file,
+ ret);
}
return ret;
}
/**
* Task scheduled when we are done.
*/
- struct GNUNET_SCHEDULER_Task * stop_task;
+ struct GNUNET_SCHEDULER_Task *stop_task;
/**
* Arguments for helper.
*/
char *args[4];
-
};
GNUNET_assert (NULL != pos);
moved = 0; /* must not terminate, even on file, otherwise "normal" */
- while ( (pos->is_directory == GNUNET_YES) ||
- (0 == moved) )
+ while ((pos->is_directory == GNUNET_YES) || (0 == moved))
{
- if ( (moved != -1) &&
- (NULL != pos->children_head) )
+ if ((moved != -1) && (NULL != pos->children_head))
{
pos = pos->children_head;
moved = 1; /* can terminate if file */
*/
static struct GNUNET_FS_ShareTreeItem *
expand_tree (struct GNUNET_FS_ShareTreeItem *parent,
- const char *filename,
- int is_directory)
+ const char *filename,
+ int is_directory)
{
struct GNUNET_FS_ShareTreeItem *chld;
size_t slen;
chld->parent = parent;
chld->filename = GNUNET_strdup (filename);
GNUNET_asprintf (&chld->short_filename,
- "%s%s",
- GNUNET_STRINGS_get_short_name (filename),
- is_directory == GNUNET_YES ? "/" : "");
+ "%s%s",
+ GNUNET_STRINGS_get_short_name (filename),
+ is_directory == GNUNET_YES ? "/" : "");
/* make sure we do not end with '//' */
slen = strlen (chld->short_filename);
- if ( (slen >= 2) &&
- (chld->short_filename[slen-1] == '/') &&
- (chld->short_filename[slen-2] == '/') )
- chld->short_filename[slen-1] = '\0';
+ if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') &&
+ (chld->short_filename[slen - 2] == '/'))
+ chld->short_filename[slen - 1] = '\0';
chld->is_directory = is_directory;
if (NULL != parent)
GNUNET_CONTAINER_DLL_insert (parent->children_head,
- parent->children_tail,
- chld);
+ parent->children_tail,
+ chld);
return chld;
}
ds->helper = NULL;
}
ds->progress_callback (ds->progress_callback_cls,
- NULL, GNUNET_SYSERR,
- GNUNET_FS_DIRSCANNER_FINISHED);
+ NULL,
+ GNUNET_SYSERR,
+ GNUNET_FS_DIRSCANNER_FINISHED);
}
* #GNUNET_SYSERR to stop further processing with error
*/
static int
-process_helper_msgs (void *cls,
- const struct GNUNET_MessageHeader *msg)
+process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_FS_DirScanner *ds = cls;
const char *filename;
(unsigned int) ntohs (msg->type));
#endif
left = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader);
- filename = (const char*) &msg[1];
+ filename = (const char *) &msg[1];
switch (ntohs (msg->type))
{
case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE:
- if (filename[left-1] != '\0')
+ if (filename[left - 1] != '\0')
{
GNUNET_break (0);
break;
}
ds->progress_callback (ds->progress_callback_cls,
- filename, GNUNET_NO,
- GNUNET_FS_DIRSCANNER_FILE_START);
+ filename,
+ GNUNET_NO,
+ GNUNET_FS_DIRSCANNER_FILE_START);
if (NULL == ds->toplevel)
{
- ds->toplevel = expand_tree (ds->pos,
- filename,
- GNUNET_NO);
+ ds->toplevel = expand_tree (ds->pos, filename, GNUNET_NO);
}
else
{
GNUNET_assert (NULL != ds->pos);
- (void) expand_tree (ds->pos,
- filename,
- GNUNET_NO);
+ (void) expand_tree (ds->pos, filename, GNUNET_NO);
}
return GNUNET_OK;
case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY:
- if (filename[left-1] != '\0')
+ if (filename[left - 1] != '\0')
{
GNUNET_break (0);
break;
{
if (NULL == ds->pos)
{
- GNUNET_break (0);
- break;
+ GNUNET_break (0);
+ break;
}
ds->pos = ds->pos->parent;
return GNUNET_OK;
}
ds->progress_callback (ds->progress_callback_cls,
- filename, GNUNET_YES,
- GNUNET_FS_DIRSCANNER_FILE_START);
- ds->pos = expand_tree (ds->pos,
- filename,
- GNUNET_YES);
+ filename,
+ GNUNET_YES,
+ GNUNET_FS_DIRSCANNER_FILE_START);
+ ds->pos = expand_tree (ds->pos, filename, GNUNET_YES);
if (NULL == ds->toplevel)
ds->toplevel = ds->pos;
return GNUNET_OK;
case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR:
break;
case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE:
- if ('\0' != filename[left-1])
+ if ('\0' != filename[left - 1])
break;
ds->progress_callback (ds->progress_callback_cls,
- filename, GNUNET_SYSERR,
- GNUNET_FS_DIRSCANNER_FILE_IGNORED);
+ filename,
+ GNUNET_SYSERR,
+ GNUNET_FS_DIRSCANNER_FILE_IGNORED);
return GNUNET_OK;
case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE:
if (0 != left)
if (NULL == ds->toplevel)
break;
ds->progress_callback (ds->progress_callback_cls,
- NULL, GNUNET_SYSERR,
- GNUNET_FS_DIRSCANNER_ALL_COUNTED);
+ NULL,
+ GNUNET_SYSERR,
+ GNUNET_FS_DIRSCANNER_ALL_COUNTED);
ds->pos = ds->toplevel;
if (GNUNET_YES == ds->pos->is_directory)
ds->pos = advance (ds->pos);
return GNUNET_OK;
- case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA:
- {
- size_t nlen;
- const char *end;
+ case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: {
+ size_t nlen;
+ const char *end;
- if (NULL == ds->pos)
- {
- GNUNET_break (0);
- break;
- }
- end = memchr (filename, 0, left);
- if (NULL == end)
- {
- GNUNET_break (0);
- break;
- }
- end++;
- nlen = end - filename;
- left -= nlen;
- if (0 != strcmp (filename,
- ds->pos->filename))
- {
- GNUNET_break (0);
- break;
- }
- ds->progress_callback (ds->progress_callback_cls,
- filename,
- GNUNET_YES,
- GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED);
- if (0 < left)
+ if (NULL == ds->pos)
+ {
+ GNUNET_break (0);
+ break;
+ }
+ end = memchr (filename, 0, left);
+ if (NULL == end)
+ {
+ GNUNET_break (0);
+ break;
+ }
+ end++;
+ nlen = end - filename;
+ left -= nlen;
+ if (0 != strcmp (filename, ds->pos->filename))
+ {
+ GNUNET_break (0);
+ break;
+ }
+ ds->progress_callback (ds->progress_callback_cls,
+ filename,
+ GNUNET_YES,
+ GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED);
+ if (0 < left)
+ {
+ ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left);
+ if (NULL == ds->pos->meta)
{
- ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end,
- left);
- if (NULL == ds->pos->meta)
- {
- GNUNET_break (0);
- break;
- }
- /* having full filenames is too dangerous; always make sure we clean them up */
- GNUNET_CONTAINER_meta_data_delete (ds->pos->meta,
- EXTRACTOR_METATYPE_FILENAME,
- NULL, 0);
- /* instead, put in our 'safer' original filename */
- GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, "<libgnunetfs>",
- EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
- EXTRACTOR_METAFORMAT_UTF8, "text/plain",
- ds->pos->short_filename,
- strlen (ds->pos->short_filename) + 1);
+ GNUNET_break (0);
+ break;
}
- ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta);
- ds->pos = advance (ds->pos);
- return GNUNET_OK;
+ /* having full filenames is too dangerous; always make sure we clean them up */
+ GNUNET_CONTAINER_meta_data_delete (ds->pos->meta,
+ EXTRACTOR_METATYPE_FILENAME,
+ NULL,
+ 0);
+ /* instead, put in our 'safer' original filename */
+ GNUNET_CONTAINER_meta_data_insert (ds->pos->meta,
+ "<libgnunetfs>",
+ EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
+ EXTRACTOR_METAFORMAT_UTF8,
+ "text/plain",
+ ds->pos->short_filename,
+ strlen (ds->pos->short_filename) + 1);
}
+ ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta);
+ ds->pos = advance (ds->pos);
+ return GNUNET_OK;
+ }
case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED:
if (NULL != ds->pos)
{
}
if (NULL == ds->toplevel)
break;
- ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan,
- ds);
+ ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, ds);
return GNUNET_OK;
default:
GNUNET_break (0);
break;
}
ds->progress_callback (ds->progress_callback_cls,
- NULL, GNUNET_SYSERR,
- GNUNET_FS_DIRSCANNER_INTERNAL_ERROR);
+ NULL,
+ GNUNET_SYSERR,
+ GNUNET_FS_DIRSCANNER_INTERNAL_ERROR);
return GNUNET_OK;
}
if (NULL != ds->stop_task)
return; /* normal death, was finished */
ds->progress_callback (ds->progress_callback_cls,
- NULL, GNUNET_SYSERR,
- GNUNET_FS_DIRSCANNER_INTERNAL_ERROR);
+ NULL,
+ GNUNET_SYSERR,
+ GNUNET_FS_DIRSCANNER_INTERNAL_ERROR);
}
*/
struct GNUNET_FS_DirScanner *
GNUNET_FS_directory_scan_start (const char *filename,
- int disable_extractor, const char *ex,
- GNUNET_FS_DirScannerProgressCallback cb,
- void *cb_cls)
+ int disable_extractor,
+ const char *ex,
+ GNUNET_FS_DirScannerProgressCallback cb,
+ void *cb_cls)
{
struct stat sbuf;
char *filename_expanded;
struct GNUNET_FS_DirScanner *ds;
- if (0 != STAT (filename, &sbuf))
+ if (0 != stat (filename, &sbuf))
return NULL;
filename_expanded = GNUNET_STRINGS_filename_expand (filename);
if (NULL == filename_expanded)
return NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting to scan directory `%s'\n",
- filename_expanded);
+ "Starting to scan directory `%s'\n",
+ filename_expanded);
ds = GNUNET_new (struct GNUNET_FS_DirScanner);
ds->progress_callback = cb;
ds->progress_callback_cls = cb_cls;
ds->args[2] = ds->ex_arg;
ds->args[3] = NULL;
ds->helper = GNUNET_HELPER_start (GNUNET_NO,
- "gnunet-helper-fs-publish",
- ds->args,
- &process_helper_msgs,
- &helper_died_cb, ds);
+ "gnunet-helper-fs-publish",
+ ds->args,
+ &process_helper_msgs,
+ &helper_died_cb,
+ ds);
if (NULL == ds->helper)
- {
+ {
GNUNET_free (filename_expanded);
GNUNET_free (ds);
return NULL;
is_recursive_download (struct GNUNET_FS_DownloadContext *dc)
{
return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) &&
- ( (GNUNET_YES ==
- GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
- ( (NULL == dc->meta) &&
- ( (NULL == dc->filename) ||
- ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
- (NULL !=
- strstr (dc->filename + strlen (dc->filename) -
- strlen (GNUNET_FS_DIRECTORY_EXT),
- GNUNET_FS_DIRECTORY_EXT)) ) ) ) );
+ ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
+ ((NULL == dc->meta) &&
+ ((NULL == dc->filename) ||
+ ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
+ (NULL != strstr (dc->filename + strlen (dc->filename) -
+ strlen (GNUNET_FS_DIRECTORY_EXT),
+ GNUNET_FS_DIRECTORY_EXT))))));
}
compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth)
{
unsigned int i;
- uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */
- uint64_t loff; /* where do IBlocks for depth "i" start? */
- unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */
+ uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */
+ uint64_t loff; /* where do IBlocks for depth "i" start? */
+ unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */
if (0 == depth)
return off;
* to full DBLOCK_SIZE */
loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE;
lsize =
- ((fsize + DBLOCK_SIZE -
- 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey);
+ ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey);
GNUNET_assert (0 == (off % DBLOCK_SIZE));
ioff = (off / DBLOCK_SIZE);
for (i = 1; i < depth; i++)
pi->value.download.dc = dc;
pi->value.download.cctx = dc->client_info;
pi->value.download.pctx =
- (NULL == dc->parent) ? NULL : dc->parent->client_info;
+ (NULL == dc->parent) ? NULL : dc->parent->client_info;
pi->value.download.sctx =
- (NULL == dc->search) ? NULL : dc->search->client_info;
+ (NULL == dc->search) ? NULL : dc->search->client_info;
pi->value.download.uri = dc->uri;
pi->value.download.filename = dc->filename;
pi->value.download.size = dc->length;
/* FIXME: Fix duration calculation to account for pauses */
pi->value.download.duration =
- GNUNET_TIME_absolute_get_duration (dc->start_time);
+ GNUNET_TIME_absolute_get_duration (dc->start_time);
pi->value.download.completed = dc->completed;
pi->value.download.anonymity = dc->anonymity;
pi->value.download.eta =
- GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length);
+ GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length);
pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES;
pi->fsh = dc->h;
if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
* how often did we transmit the query?
*/
uint32_t num_transmissions;
-
};
*/
static int
process_result_with_request (void *cls,
- const struct GNUNET_HashCode * key,
+ const struct GNUNET_HashCode *key,
void *value);
static int
encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc,
const struct ContentHashKey *chk,
- struct DownloadRequest *dr, const char *block,
- size_t len, int do_store)
+ struct DownloadRequest *dr,
+ const char *block,
+ size_t len,
+ int do_store)
{
struct ProcessResultClosure prc;
char enc[len];
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n",
- (unsigned int) len,
- dc->filename, (unsigned long long) dr->offset);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n",
+ (unsigned int) len,
+ dc->filename,
+ (unsigned long long) dr->offset);
/* already got it! */
prc.dc = dc;
prc.data = enc;
prc.size = len;
- prc.type =
- (0 ==
- dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : GNUNET_BLOCK_TYPE_FS_IBLOCK;
+ prc.type = (0 == dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK
+ : GNUNET_BLOCK_TYPE_FS_IBLOCK;
prc.query = chk->query;
prc.do_store = do_store;
prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS;
size = (size_t) size64;
if (size64 != (uint64_t) size)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n"));
return;
}
if (NULL != dc->filename)
GNUNET_DISK_PERM_NONE);
}
if (NULL == h)
- return; /* oops */
- data = GNUNET_DISK_file_map (h,
- &m,
- GNUNET_DISK_MAP_TYPE_READ,
- size);
+ return; /* oops */
+ data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size);
if (NULL == data)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Directory too large for system address space\n"));
+ _ ("Directory too large for system address space\n"));
}
else
{
&trigger_recursive_download,
dc))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to access full directroy contents of `%s' for recursive download\n"),
- dc->filename);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Failed to access full directroy contents of `%s' for recursive download\n"),
+ dc->filename);
}
GNUNET_DISK_file_unmap (m);
}
GNUNET_DISK_file_close (h);
if (NULL == dc->filename)
{
- if (0 != UNLINK (dc->temp_filename))
+ if (0 != unlink (dc->temp_filename))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
"unlink",
dc->temp_filename);
/* then, check if children are done already */
for (pos = dc->child_head; NULL != pos; pos = pos->next)
{
- if ( (NULL == pos->emsg) &&
- (pos->completed < pos->length) )
- return; /* not done yet */
- if ( (NULL != pos->child_head) &&
- (pos->has_finished != GNUNET_YES) )
- return; /* not transitively done yet */
+ if ((NULL == pos->emsg) && (pos->completed < pos->length))
+ return; /* not done yet */
+ if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES))
+ return; /* not transitively done yet */
}
/* All of our children are done, so mark this download done */
dc->has_finished = GNUNET_YES;
*/
static void
try_match_block (struct GNUNET_FS_DownloadContext *dc,
- struct DownloadRequest *dr, const char *data, size_t data_len)
+ struct DownloadRequest *dr,
+ const char *data,
+ size_t data_len)
{
struct GNUNET_FS_ProgressInfo pi;
unsigned int i;
return;
if (dr->depth > 0)
{
- if ( (dc->offset > 0) ||
- (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length)) )
+ if ((dc->offset > 0) ||
+ (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length)))
{
/* NOTE: this test is not tight, but should suffice; the issue
here is that 'dr->num_children' may inherently only specify a
else
{
if (dr->offset > data_len)
- return; /* oops */
+ return; /* oops */
dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE);
}
GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key);
GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv);
- if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset],
- dlen,
- &sk,
- &iv,
- enc))
+ if (-1 ==
+ GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc))
{
GNUNET_break (0);
return;
dr->state = BRS_RECONSTRUCT_META_UP;
break;
case BRS_CHK_SET:
- if (0 != memcmp (&in_chk,
- &dr->chk,
- sizeof (struct ContentHashKey)))
+ if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey)))
{
/* other peer provided bogus meta data */
GNUNET_break_op (0);
{
fh = GNUNET_DISK_file_open (fn,
GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE |
- GNUNET_DISK_OPEN_TRUNCATE,
+ GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_TRUNCATE,
GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ);
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ);
if (NULL == fh)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn);
GNUNET_asprintf (&dc->emsg,
- _("Failed to open file `%s' for writing"),
+ _ ("Failed to open file `%s' for writing"),
fn);
GNUNET_DISK_file_close (fh);
dr->state = BRS_ERROR;
if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
- GNUNET_asprintf (&dc->emsg, _("Failed to open file `%s' for writing"),
+ GNUNET_asprintf (&dc->emsg,
+ _ ("Failed to open file `%s' for writing"),
fn);
GNUNET_DISK_file_close (fh);
dr->state = BRS_ERROR;
pi.value.download.specifics.progress.data_len = dlen;
pi.value.download.specifics.progress.depth = 0;
pi.value.download.specifics.progress.respect_offered = 0;
- pi.value.download.specifics.progress.block_download_duration = GNUNET_TIME_UNIT_ZERO;
+ pi.value.download.specifics.progress.block_download_duration =
+ GNUNET_TIME_UNIT_ZERO;
GNUNET_FS_download_make_status_ (&pi, dc);
if ((NULL != dc->filename) &&
- (0 !=
- TRUNCATE (dc->filename,
- GNUNET_ntohll (dc->uri->data.chk.file_length))))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate",
+ (0 != truncate (dc->filename,
+ GNUNET_ntohll (dc->uri->data.chk.file_length))))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "truncate",
dc->filename);
check_completed (dc);
break;
* @return 0 to continue extracting, 1 to abort
*/
static int
-match_full_data (void *cls, const char *plugin_name,
- enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
- const char *data_mime_type, const char *data, size_t data_len)
+match_full_data (void *cls,
+ const char *plugin_name,
+ enum EXTRACTOR_MetaType type,
+ enum EXTRACTOR_MetaFormat format,
+ const char *data_mime_type,
+ const char *data,
+ size_t data_len)
{
struct GNUNET_FS_DownloadContext *dc = cls;
if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type)
return 0;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u bytes of FD!\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found %u bytes of FD!\n",
(unsigned int) data_len);
if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len)
{
GNUNET_break_op (0);
- return 1; /* bogus meta data */
+ return 1; /* bogus meta data */
}
- try_match_block (dc,
- dc->top_request,
- data,
- data_len);
+ try_match_block (dc, dc->top_request, data, data_len);
return 1;
}
for (i = 0; i < dr->num_children; i++)
if (dr->children[i]->state != BRS_DOWNLOAD_UP)
break;
- }
- while (i == dr->num_children);
+ } while (i == dr->num_children);
}
GNUNET_assert (len <= DBLOCK_SIZE);
off = compute_disk_offset (total, dr->offset, dr->depth);
if (dc->old_file_size < off + len)
- return; /* failure */
+ return; /* failure */
if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename);
- return; /* failure */
+ return; /* failure */
}
if (len != GNUNET_DISK_file_read (dc->rfh, block, len))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename);
- return; /* failure */
+ return; /* failure */
}
GNUNET_CRYPTO_hash (block, len, &key);
if (0 != memcmp (&key, &dr->chk.key, sizeof (struct GNUNET_HashCode)))
- return; /* mismatch */
+ return; /* mismatch */
if (GNUNET_OK !=
encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO))
{
try_top_down_reconstruction (dc, drc);
}
if (BRS_DOWNLOAD_UP != drc->state)
- up_done = GNUNET_NO; /* children not all done */
+ up_done = GNUNET_NO; /* children not all done */
}
if (GNUNET_YES == up_done)
- propagate_up (dr); /* children all done (or no children...) */
+ propagate_up (dr); /* children all done (or no children...) */
}
* @return #GNUNET_OK
*/
static int
-retry_entry (void *cls,
- const struct GNUNET_HashCode *key,
- void *entry)
+retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry)
{
struct GNUNET_FS_DownloadContext *dc = cls;
struct DownloadRequest *dr = entry;
struct SearchMessage *sm;
struct GNUNET_MQ_Envelope *env;
- env = GNUNET_MQ_msg (sm,
- GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
+ env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY))
sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY);
else
sm->anonymity_level = htonl (dc->anonymity);
sm->target = dc->target;
sm->query = dr->chk.query;
- GNUNET_MQ_send (dc->mq,
- env);
+ GNUNET_MQ_send (dc->mq, env);
return GNUNET_OK;
}
(unsigned long long) dr->offset,
dr->depth,
GNUNET_h2s (&dr->chk.query));
- if (GNUNET_NO !=
- GNUNET_CONTAINER_multihashmap_contains_value (dc->active,
- &dr->chk.query,
- dr))
- return; /* already active */
+ if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value (dc->active,
+ &dr->chk.query,
+ dr))
+ return; /* already active */
GNUNET_CONTAINER_multihashmap_put (dc->active,
&dr->chk.query,
dr,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
if (NULL == dc->mq)
- return; /* download not active */
- retry_entry (dc,
- &dr->chk.query,
- dr);
+ return; /* download not active */
+ retry_entry (dc, &dr->chk.query, dr);
}
char *sfn;
if (NULL == uri)
- return; /* entry for the directory itself */
+ return; /* entry for the directory itself */
cpos = dc->child_head;
while (NULL != cpos)
{
cpos = cpos->next;
}
if (NULL != cpos)
- return; /* already exists */
+ return; /* already exists */
fn = NULL;
if (NULL == filename)
{
{
ext = fn;
us = GNUNET_FS_uri_to_string (uri);
- GNUNET_asprintf (&fn, "%s%s", &us[strlen (GNUNET_FS_URI_CHK_PREFIX)],
+ GNUNET_asprintf (&fn,
+ "%s%s",
+ &us[strlen (GNUNET_FS_URI_CHK_PREFIX)],
ext);
GNUNET_free (ext);
GNUNET_free (us);
else
{
dn = GNUNET_strdup (dc->filename);
- GNUNET_break ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
- (NULL !=
- strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
- GNUNET_FS_DIRECTORY_EXT)));
+ GNUNET_break (
+ (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
+ (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
+ GNUNET_FS_DIRECTORY_EXT)));
sfn = GNUNET_strdup (filename);
while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1]))
sfn[strlen (sfn) - 1] = '\0';
if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
- (NULL !=
- strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
- GNUNET_FS_DIRECTORY_EXT)))
+ (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT),
+ GNUNET_FS_DIRECTORY_EXT)))
dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0';
if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) &&
((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) ||
- (NULL ==
- strstr (filename + strlen (filename) -
- strlen (GNUNET_FS_DIRECTORY_EXT), GNUNET_FS_DIRECTORY_EXT))))
+ (NULL == strstr (filename + strlen (filename) -
+ strlen (GNUNET_FS_DIRECTORY_EXT),
+ GNUNET_FS_DIRECTORY_EXT))))
{
- GNUNET_asprintf (&full_name, "%s%s%s%s", dn, DIR_SEPARATOR_STR, sfn,
+ GNUNET_asprintf (&full_name,
+ "%s%s%s%s",
+ dn,
+ DIR_SEPARATOR_STR,
+ sfn,
GNUNET_FS_DIRECTORY_EXT);
}
else
(GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Failed to create directory for recursive download of `%s'\n"),
+ _ (
+ "Failed to create directory for recursive download of `%s'\n"),
full_name);
GNUNET_free (full_name);
GNUNET_free_non_null (fn);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Triggering recursive download of size %llu with %u bytes MD\n",
(unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri),
- (unsigned int)
- GNUNET_CONTAINER_meta_data_get_serialized_size (meta));
+ (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (
+ meta));
GNUNET_FS_download_start (dc->h,
uri,
meta,
int i;
struct ContentHashKey *chkarr;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n",
- (unsigned int) prc->size,
- GNUNET_h2s (key),
- dr->depth,
- (unsigned long long) dr->offset,
- (unsigned long long) GNUNET_ntohll (dc->uri->data.
- chk.file_length));
- bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll
- (dc->uri->data.chk.file_length),
- dr->offset, dr->depth);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n",
+ (unsigned int) prc->size,
+ GNUNET_h2s (key),
+ dr->depth,
+ (unsigned long long) dr->offset,
+ (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length));
+ bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll (
+ dc->uri->data.chk.file_length),
+ dr->offset,
+ dr->depth);
if (prc->size != bs)
{
- GNUNET_asprintf (&dc->emsg,
- _
- ("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"),
- bs, dr->depth, (unsigned long long) dr->offset,
- (unsigned long long) GNUNET_ntohll (dc->uri->data.
- chk.file_length),
- prc->size);
+ GNUNET_asprintf (
+ &dc->emsg,
+ _ (
+ "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"),
+ bs,
+ dr->depth,
+ (unsigned long long) dr->offset,
+ (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length),
+ prc->size);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg);
while (NULL != dr->parent)
{
goto signal_error;
}
- (void) GNUNET_CONTAINER_multihashmap_remove (dc->active,
- &prc->query,
- dr);
- GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key,
- &skey,
- &iv);
- if (-1 == GNUNET_CRYPTO_symmetric_decrypt (prc->data,
- prc->size,
- &skey,
- &iv,
- pt))
+ (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, &prc->query, dr);
+ GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv);
+ if (-1 ==
+ GNUNET_CRYPTO_symmetric_decrypt (prc->data, prc->size, &skey, &iv, pt))
{
GNUNET_break (0);
- dc->emsg = GNUNET_strdup (_("internal error decrypting content"));
+ dc->emsg = GNUNET_strdup (_ ("internal error decrypting content"));
goto signal_error;
}
- off =
- compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length),
- dr->offset,
- dr->depth);
+ off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length),
+ dr->offset,
+ dr->depth);
/* save to disk */
if ((GNUNET_YES == prc->do_store) &&
((NULL != dc->filename) || (is_recursive_download (dc))) &&
((dr->depth == dc->treedepth) ||
(0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES))))
{
- fh = GNUNET_DISK_file_open (NULL != dc->filename
- ? dc->filename : dc->temp_filename,
+ fh = GNUNET_DISK_file_open (NULL != dc->filename ? dc->filename
+ : dc->temp_filename,
GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_OPEN_CREATE,
GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ);
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ);
if (NULL == fh)
{
GNUNET_asprintf (&dc->emsg,
- _("Download failed: could not open file `%s': %s"),
- dc->filename, STRERROR (errno));
+ _ ("Download failed: could not open file `%s': %s"),
+ dc->filename,
+ strerror (errno));
goto signal_error;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Saving decrypted block to disk at offset %llu\n",
(unsigned long long) off);
- if ((off != GNUNET_DISK_file_seek (fh,
- off,
- GNUNET_DISK_SEEK_SET)))
+ if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)))
{
GNUNET_asprintf (&dc->emsg,
- _("Failed to seek to offset %llu in file `%s': %s"),
+ _ ("Failed to seek to offset %llu in file `%s': %s"),
(unsigned long long) off,
dc->filename,
- STRERROR (errno));
+ strerror (errno));
goto signal_error;
}
if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size))
{
- GNUNET_asprintf (&dc->emsg,
- _("Failed to write block of %u bytes at offset %llu in file `%s': %s"),
- (unsigned int) prc->size,
- (unsigned long long) off,
- dc->filename,
- STRERROR (errno));
+ GNUNET_asprintf (
+ &dc->emsg,
+ _ ("Failed to write block of %u bytes at offset %llu in file `%s': %s"),
+ (unsigned int) prc->size,
+ (unsigned long long) off,
+ dc->filename,
+ strerror (errno));
goto signal_error;
}
GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
* says it is a directory or if no meta data is given AND filename
* ends in '.gnd' (top-level case) */
if (is_recursive_download (dc))
- GNUNET_FS_directory_list_contents (prc->size, pt, off,
- &trigger_recursive_download, dc);
+ GNUNET_FS_directory_list_contents (prc->size,
+ pt,
+ off,
+ &trigger_recursive_download,
+ dc);
}
GNUNET_assert (dc->completed <= dc->length);
dr->state = BRS_DOWNLOAD_DOWN;
pi.value.download.specifics.progress.data_len = prc->size;
pi.value.download.specifics.progress.depth = dr->depth;
pi.value.download.specifics.progress.respect_offered = prc->respect_offered;
- pi.value.download.specifics.progress.num_transmissions = prc->num_transmissions;
- if (prc->last_transmission.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
- pi.value.download.specifics.progress.block_download_duration
- = GNUNET_TIME_absolute_get_duration (prc->last_transmission);
+ pi.value.download.specifics.progress.num_transmissions =
+ prc->num_transmissions;
+ if (prc->last_transmission.abs_value_us !=
+ GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
+ pi.value.download.specifics.progress.block_download_duration =
+ GNUNET_TIME_absolute_get_duration (prc->last_transmission);
else
- pi.value.download.specifics.progress.block_download_duration
- = GNUNET_TIME_UNIT_ZERO; /* found locally */
+ pi.value.download.specifics.progress.block_download_duration =
+ GNUNET_TIME_UNIT_ZERO; /* found locally */
GNUNET_FS_download_make_status_ (&pi, dc);
if (0 == dr->depth)
propagate_up (dr);
/* download completed, signal */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Download completed, truncating file to desired length %llu\n",
- (unsigned long long) GNUNET_ntohll (dc->uri->data.
- chk.file_length));
+ (unsigned long long) GNUNET_ntohll (
+ dc->uri->data.chk.file_length));
/* truncate file to size (since we store IBlocks at the end) */
if (NULL != dc->filename)
{
- if (0 !=
- TRUNCATE (dc->filename,
- GNUNET_ntohll (dc->uri->data.chk.file_length)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate",
+ if (0 != truncate (dc->filename,
+ GNUNET_ntohll (dc->uri->data.chk.file_length)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "truncate",
dc->filename);
}
GNUNET_assert (0 == dr->depth);
return GNUNET_YES;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Triggering downloads of children (this block was at depth %u and offset %llu)\n",
- dr->depth, (unsigned long long) dr->offset);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Triggering downloads of children (this block was at depth %u and offset %llu)\n",
+ dr->depth,
+ (unsigned long long) dr->offset);
GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey)));
chkarr = (struct ContentHashKey *) pt;
for (i = dr->num_children - 1; i >= 0; i--)
case BRS_INIT:
if ((drc->chk_idx + 1) * sizeof (struct ContentHashKey) > prc->size)
{
- /* 'chkarr' does not have enough space for this chk_idx;
+ /* 'chkarr' does not have enough space for this chk_idx;
internal error! */
- GNUNET_break (0); GNUNET_assert (0);
- dc->emsg = GNUNET_strdup (_("internal error decoding tree"));
- goto signal_error;
+ GNUNET_break (0);
+ GNUNET_assert (0);
+ dc->emsg = GNUNET_strdup (_ ("internal error decoding tree"));
+ goto signal_error;
}
drc->chk = chkarr[drc->chk_idx];
drc->state = BRS_CHK_SET;
if (GNUNET_YES == dc->issue_requests)
- schedule_block_download (dc, drc);
+ schedule_block_download (dc, drc);
break;
case BRS_RECONSTRUCT_DOWN:
GNUNET_assert (0);
* @param msg message received
*/
static int
-check_put (void *cls,
- const struct ClientPutMessage *cm)
+check_put (void *cls, const struct ClientPutMessage *cm)
{
/* any varsize length is OK */
return GNUNET_OK;
* @param msg message received
*/
static void
-handle_put (void *cls,
- const struct ClientPutMessage *cm)
+handle_put (void *cls, const struct ClientPutMessage *cm)
{
struct GNUNET_FS_DownloadContext *dc = cls;
uint16_t msize = ntohs (cm->header.size) - sizeof (*cm);
prc.do_store = GNUNET_YES;
prc.respect_offered = ntohl (cm->respect_offered);
prc.num_transmissions = ntohl (cm->num_transmissions);
- GNUNET_CRYPTO_hash (prc.data,
- msize,
- &prc.query);
+ GNUNET_CRYPTO_hash (prc.data, msize, &prc.query);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received result for query `%s' from FS service\n",
GNUNET_h2s (&prc.query));
* @param error error code
*/
static void
-download_mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_FS_DownloadContext *dc = cls;
do_reconnect (void *cls)
{
struct GNUNET_FS_DownloadContext *dc = cls;
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_var_size (put,
- GNUNET_MESSAGE_TYPE_FS_PUT,
- struct ClientPutMessage,
- dc),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_var_size (put,
+ GNUNET_MESSAGE_TYPE_FS_PUT,
+ struct ClientPutMessage,
+ dc),
+ GNUNET_MQ_handler_end ()};
dc->task = NULL;
dc->mq = GNUNET_CLIENT_connect (dc->h->cfg,
if (NULL == dc->mq)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Connecting to `%s'-service failed, will try again.\n", "FS");
+ "Connecting to `%s'-service failed, will try again.\n",
+ "FS");
try_reconnect (dc);
return;
}
- GNUNET_CONTAINER_multihashmap_iterate (dc->active,
- &retry_entry,
- dc);
+ GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Will try to reconnect in %s\n",
- GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff,
+ GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff,
GNUNET_YES));
GNUNET_break (NULL != dc->job_queue);
dc->task =
- GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff,
- &do_reconnect,
- dc);
+ GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, &do_reconnect, dc);
}
GNUNET_assert (NULL != dc->active);
do_reconnect (dc);
if (NULL != dc->mq)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download activated\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n");
pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE;
- GNUNET_FS_download_make_status_ (&pi,
- dc);
+ GNUNET_FS_download_make_status_ (&pi, dc);
}
struct GNUNET_FS_DownloadContext *dc = cls;
struct GNUNET_FS_ProgressInfo pi;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download deactivated\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n");
if (NULL != dc->mq)
{
GNUNET_MQ_destroy (dc->mq);
dc->mq = NULL;
}
pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE;
- GNUNET_FS_download_make_status_ (&pi,
- dc);
+ GNUNET_FS_download_make_status_ (&pi, dc);
}
*/
static struct DownloadRequest *
create_download_request (struct DownloadRequest *parent,
- unsigned int chk_idx,
- unsigned int depth,
+ unsigned int chk_idx,
+ unsigned int depth,
uint64_t dr_offset,
uint64_t file_start_offset,
uint64_t desired_length)
}
/* calculate index of last block at this level that is interesting (rounded up) */
- dr->num_children = (file_start_offset + desired_length - dr_offset) / child_block_size;
+ dr->num_children =
+ (file_start_offset + desired_length - dr_offset) / child_block_size;
if (dr->num_children * child_block_size <
file_start_offset + desired_length - dr_offset)
- dr->num_children++; /* round up */
+ dr->num_children++; /* round up */
GNUNET_assert (dr->num_children > head_skip);
dr->num_children -= head_skip;
if (dr->num_children > CHK_PER_INODE)
dr->num_children = CHK_PER_INODE; /* cap at max */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Block at offset %llu and depth %u has %u children\n",
- (unsigned long long) dr_offset,
- depth,
- dr->num_children);
+ "Block at offset %llu and depth %u has %u children\n",
+ (unsigned long long) dr_offset,
+ depth,
+ dr->num_children);
/* now we can get the total number of *interesting* children for this block */
/* why else would we have gotten here to begin with? (that'd be a bad logic error) */
GNUNET_assert (dr->num_children > 0);
- dr->children =
- GNUNET_new_array (dr->num_children,
- struct DownloadRequest *);
+ dr->children = GNUNET_new_array (dr->num_children, struct DownloadRequest *);
for (i = 0; i < dr->num_children; i++)
{
dr->children[i] =
create_download_request (dr,
i + head_skip,
depth - 1,
- dr_offset + (i + head_skip) * child_block_size,
- file_start_offset,
+ dr_offset + (i + head_skip) * child_block_size,
+ file_start_offset,
desired_length);
}
return dr;
}
/* start "normal" download */
dc->issue_requests = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting normal download\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n");
schedule_block_download (dc, dc->top_request);
}
if (chld < dr->children[0]->chk_idx)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Block %u < %u irrelevant for our range\n",
- chld,
- dr->children[0]->chk_idx);
- dc->task = GNUNET_SCHEDULER_add_now (&get_next_block,
- dc);
+ "Block %u < %u irrelevant for our range\n",
+ chld,
+ dr->children[0]->chk_idx);
+ dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
return; /* irrelevant block */
}
- if (chld > dr->children[dr->num_children-1]->chk_idx)
+ if (chld > dr->children[dr->num_children - 1]->chk_idx)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Block %u > %u irrelevant for our range\n",
- chld,
- dr->children[dr->num_children-1]->chk_idx);
+ "Block %u > %u irrelevant for our range\n",
+ chld,
+ dr->children[dr->num_children - 1]->chk_idx);
dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
return; /* irrelevant block */
}
dr = dr->children[chld - dr->children[0]->chk_idx];
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Matched TE block with request at offset %llu and depth %u in state %d\n",
- (unsigned long long) dr->offset,
- dr->depth,
- dr->state);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Matched TE block with request at offset %llu and depth %u in state %d\n",
+ (unsigned long long) dr->offset,
+ dr->depth,
+ dr->state);
/* FIXME: this code needs more testing and might
need to handle more states... */
switch (dr->state)
case BRS_CHK_SET:
if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reconstruction succeeded, can use block at offset %llu, depth %u\n",
- (unsigned long long) offset,
- depth);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Reconstruction succeeded, can use block at offset %llu, depth %u\n",
+ (unsigned long long) offset,
+ depth);
/* block matches, hence tree below matches;
* this request is done! */
dr->state = BRS_DOWNLOAD_UP;
pi.value.download.specifics.progress.data_len = 0;
pi.value.download.specifics.progress.depth = 0;
pi.value.download.specifics.progress.respect_offered = 0;
- pi.value.download.specifics.progress.block_download_duration = GNUNET_TIME_UNIT_ZERO;
+ pi.value.download.specifics.progress.block_download_duration =
+ GNUNET_TIME_UNIT_ZERO;
GNUNET_FS_download_make_status_ (&pi, dc);
/* FIXME: duplicated code from 'process_result_with_request - refactor */
if (dc->completed == dc->length)
{
- /* download completed, signal */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download completed, truncating file to desired length %llu\n",
- (unsigned long long) GNUNET_ntohll (dc->uri->data.
- chk.file_length));
- /* truncate file to size (since we store IBlocks at the end) */
- if (NULL != dc->filename)
- {
- if (0 !=
- TRUNCATE (dc->filename,
- GNUNET_ntohll (dc->uri->data.chk.file_length)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate",
- dc->filename);
- }
+ /* download completed, signal */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Download completed, truncating file to desired length %llu\n",
+ (unsigned long long) GNUNET_ntohll (
+ dc->uri->data.chk.file_length));
+ /* truncate file to size (since we store IBlocks at the end) */
+ if (NULL != dc->filename)
+ {
+ if (0 != truncate (dc->filename,
+ GNUNET_ntohll (dc->uri->data.chk.file_length)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "truncate",
+ dc->filename);
+ }
}
}
else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reconstruction failed, need to download block at offset %llu, depth %u\n",
- (unsigned long long) offset,
- depth);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Reconstruction failed, need to download block at offset %llu, depth %u\n",
+ (unsigned long long) offset,
+ depth);
break;
case BRS_DOWNLOAD_DOWN:
break;
GNUNET_assert (0);
break;
}
- dc->task = GNUNET_SCHEDULER_add_now (&get_next_block,
- dc);
- if ( (dr == dc->top_request) &&
- (dr->state == BRS_DOWNLOAD_UP) )
+ dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
+ if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP))
check_completed (dc);
}
struct GNUNET_FS_ProgressInfo pi;
struct GNUNET_DISK_FileHandle *fh;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Start task running...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n");
dc->task = NULL;
if (0 == dc->length)
{
{
fh = GNUNET_DISK_file_open (dc->filename,
GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE |
- ((0 ==
- GNUNET_FS_uri_chk_get_file_size (dc->uri)) ?
- GNUNET_DISK_OPEN_TRUNCATE : 0),
+ GNUNET_DISK_OPEN_CREATE |
+ ((0 ==
+ GNUNET_FS_uri_chk_get_file_size (dc->uri))
+ ? GNUNET_DISK_OPEN_TRUNCATE
+ : 0),
GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ);
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ);
GNUNET_DISK_file_close (fh);
}
GNUNET_FS_download_sync_ (dc);
return;
if (NULL == dc->top_request)
{
- dc->top_request =
- create_download_request (NULL, 0, dc->treedepth - 1, 0, dc->offset,
- dc->length);
+ dc->top_request = create_download_request (NULL,
+ 0,
+ dc->treedepth - 1,
+ 0,
+ dc->offset,
+ dc->length);
dc->top_request->state = BRS_CHK_SET;
- dc->top_request->chk =
- (dc->uri->type ==
- GNUNET_FS_URI_CHK) ? dc->uri->data.chk.chk : dc->uri->data.loc.fi.chk;
+ dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK)
+ ? dc->uri->data.chk.chk
+ : dc->uri->data.loc.fi.chk;
/* signal start */
GNUNET_FS_download_sync_ (dc);
if (NULL != dc->search)
GNUNET_FS_download_start_downloading_ (dc);
/* attempt reconstruction from disk */
if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename))
- dc->rfh =
- GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ dc->rfh = GNUNET_DISK_file_open (dc->filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
if (dc->top_request->state == BRS_CHK_SET)
{
if (NULL != dc->rfh)
{
/* first, try top-down */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying top-down reconstruction for `%s'\n", dc->filename);
+ "Trying top-down reconstruction for `%s'\n",
+ dc->filename);
try_top_down_reconstruction (dc, dc->top_request);
switch (dc->top_request->state)
{
case BRS_CHK_SET:
- break; /* normal */
+ break; /* normal */
case BRS_DOWNLOAD_DOWN:
- break; /* normal, some blocks already down */
+ break; /* normal, some blocks already down */
case BRS_DOWNLOAD_UP:
/* already done entirely, party! */
if (NULL != dc->rfh)
}
return;
case BRS_ERROR:
- GNUNET_asprintf (&dc->emsg, _("Invalid URI"));
+ GNUNET_asprintf (&dc->emsg, _ ("Invalid URI"));
GNUNET_FS_download_sync_ (dc);
pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
pi.value.download.specifics.error.message = dc->emsg;
if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) &&
(NULL != dc->meta))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying to find embedded meta data for download of size %llu with %u bytes MD\n",
- (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri),
- (unsigned int)
- GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to find embedded meta data for download of size %llu with %u bytes MD\n",
+ (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri),
+ (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta));
GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc);
if (BRS_DOWNLOAD_UP == dc->top_request->state)
{
GNUNET_DISK_file_close (dc->rfh);
dc->rfh = NULL;
}
- return; /* finished, status update was already done for us */
+ return; /* finished, status update was already done for us */
}
}
if (NULL != dc->rfh)
{
/* finally, actually run bottom-up */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Trying bottom-up reconstruction of file `%s'\n", dc->filename);
+ "Trying bottom-up reconstruction of file `%s'\n",
+ dc->filename);
dc->te =
GNUNET_FS_tree_encoder_create (dc->h,
- GNUNET_FS_uri_chk_get_file_size (dc->uri),
- dc,
+ GNUNET_FS_uri_chk_get_file_size (dc->uri),
+ dc,
&fh_reader,
- &reconstruct_cb,
+ &reconstruct_cb,
NULL,
- &reconstruct_cont);
- dc->task = GNUNET_SCHEDULER_add_now (&get_next_block,
- dc);
+ &reconstruct_cont);
+ dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc);
}
else
{
dc->job_queue = NULL;
}
if (NULL != dc->parent)
- GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail,
+ GNUNET_CONTAINER_DLL_remove (dc->parent->child_head,
+ dc->parent->child_tail,
dc);
if (NULL != dc->task)
{
*/
struct GNUNET_FS_DownloadContext *
create_download_context (struct GNUNET_FS_Handle *h,
- const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta,
- const char *filename,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ const char *filename,
const char *tempname,
- uint64_t offset,
+ uint64_t offset,
uint64_t length,
uint32_t anonymity,
- enum GNUNET_FS_DownloadOptions options,
+ enum GNUNET_FS_DownloadOptions options,
void *cctx)
{
struct GNUNET_FS_DownloadContext *dc;
}
dc = GNUNET_new (struct GNUNET_FS_DownloadContext);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting download %p, %u bytes at offset %llu\n",
- dc,
- (unsigned int) length,
- (unsigned long long) offset);
+ "Starting download %p, %u bytes at offset %llu\n",
+ dc,
+ (unsigned int) length,
+ (unsigned long long) offset);
dc->h = h;
dc->uri = GNUNET_FS_uri_dup (uri);
dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
{
dc->filename = GNUNET_strdup (filename);
if (GNUNET_YES == GNUNET_DISK_file_test (filename))
- GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename, &dc->old_file_size, GNUNET_YES, GNUNET_YES));
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename,
+ &dc->old_file_size,
+ GNUNET_YES,
+ GNUNET_YES));
}
if (GNUNET_FS_uri_test_loc (dc->uri))
GNUNET_assert (GNUNET_OK ==
dc->anonymity = anonymity;
dc->options = options;
dc->active =
- GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE), GNUNET_NO);
+ GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE),
+ GNUNET_NO);
dc->treedepth =
- GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
+ GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri));
if ((NULL == filename) && (is_recursive_download (dc)))
{
if (NULL != tempname)
dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp");
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting download `%s' of %llu bytes with tree depth %u\n",
- filename,
- (unsigned long long) length,
+ "Starting download `%s' of %llu bytes with tree depth %u\n",
+ filename,
+ (unsigned long long) length,
dc->treedepth);
GNUNET_assert (NULL == dc->job_queue);
- dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_,
- dc);
+ dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc);
return dc;
}
meta,
filename,
tempname,
- offset,
+ offset,
length,
anonymity,
options,
dc->parent = parent;
if (NULL != parent)
GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc);
- else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options) )
+ else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options))
dc->top =
- GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc);
+ GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc);
return dc;
}
sr->meta,
filename,
tempname,
- offset,
+ offset,
length,
anonymity,
options,
GNUNET_assert (NULL == dc->job_queue);
GNUNET_assert (NULL == dc->task);
GNUNET_assert (NULL != dc->active);
- dc->job_queue
- = GNUNET_FS_queue_ (dc->h,
- &activate_fs_download,
- &deactivate_fs_download,
- dc,
- (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
- (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
- ? GNUNET_FS_QUEUE_PRIORITY_NORMAL
- : GNUNET_FS_QUEUE_PRIORITY_PROBE);
+ dc->job_queue =
+ GNUNET_FS_queue_ (dc->h,
+ &activate_fs_download,
+ &deactivate_fs_download,
+ dc,
+ (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
+ (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
+ ? GNUNET_FS_QUEUE_PRIORITY_NORMAL
+ : GNUNET_FS_QUEUE_PRIORITY_PROBE);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Download %p put into queue as job %p\n",
- dc,
- dc->job_queue);
+ "Download %p put into queue as job %p\n",
+ dc,
+ dc->job_queue);
}
/**
void
GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc)
{
- deactivate_fs_download(dc);
+ deactivate_fs_download (dc);
}
GNUNET_FS_download_make_status_ (&pi, dc);
GNUNET_assert (NULL == dc->task);
- dc->job_queue
- = GNUNET_FS_queue_ (dc->h,
- &activate_fs_download,
- &deactivate_fs_download,
- dc, (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
- (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
+ dc->job_queue =
+ GNUNET_FS_queue_ (dc->h,
+ &activate_fs_download,
+ &deactivate_fs_download,
+ dc,
+ (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE,
+ (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE))
? GNUNET_FS_QUEUE_PRIORITY_NORMAL
: GNUNET_FS_QUEUE_PRIORITY_PROBE);
-
}
* @param do_delete delete files of incomplete downloads
*/
void
-GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
- int do_delete)
+GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete)
{
struct GNUNET_FS_ProgressInfo pi;
int have_children;
dc);
if (NULL != dc->serialization)
GNUNET_FS_remove_sync_file_ (dc->h,
- ((NULL != dc->parent) ||
- (! search_was_null)) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
- GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
+ ((NULL != dc->parent) || (! search_was_null))
+ ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
+ : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
dc->serialization);
if ((GNUNET_YES == have_children) && (NULL == dc->parent))
GNUNET_FS_remove_sync_dir_ (dc->h,
- (! search_was_null) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD :
- GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
+ (! search_was_null)
+ ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD
+ : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD,
dc->serialization);
pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED;
GNUNET_FS_download_make_status_ (&pi, dc);
{
if ((dc->completed != dc->length) && (GNUNET_YES == do_delete))
{
- if ( (0 != UNLINK (dc->filename)) &&
- (ENOENT != errno) )
+ if ((0 != unlink (dc->filename)) && (ENOENT != errno))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
"unlink",
dc->filename);
GNUNET_FS_uri_destroy (dc->uri);
if (NULL != dc->temp_filename)
{
- if (0 != UNLINK (dc->temp_filename))
+ if (0 != unlink (dc->temp_filename))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
"unlink",
dc->temp_filename);
* @return publish structure entry for the file
*/
struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
- void *client_info,
- const char *filename,
- const struct GNUNET_FS_Uri
- *keywords,
- const struct
- GNUNET_CONTAINER_MetaData *meta,
- int do_index,
- const struct GNUNET_FS_BlockOptions
- *bo)
+GNUNET_FS_file_information_create_from_file (
+ struct GNUNET_FS_Handle *h,
+ void *client_info,
+ const char *filename,
+ const struct GNUNET_FS_Uri *keywords,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ int do_index,
+ const struct GNUNET_FS_BlockOptions *bo)
{
struct FileInfo *fi;
uint64_t fsize;
#endif
/* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */
- if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES))
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
return NULL;
return NULL;
}
ret =
- GNUNET_FS_file_information_create_from_reader (h, client_info,
- fsize,
- &GNUNET_FS_data_reader_file_,
- fi, keywords, meta,
- do_index, bo);
+ GNUNET_FS_file_information_create_from_reader (h,
+ client_info,
+ fsize,
+ &GNUNET_FS_data_reader_file_,
+ fi,
+ keywords,
+ meta,
+ do_index,
+ bo);
if (ret == NULL)
return NULL;
ret->h = h;
ret->filename = GNUNET_strdup (filename);
-#if !WINDOWS
+#if ! WINDOWS
fn = filename;
#else
plibc_conv_to_win_path (filename, fn_conv);
/* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then
* this should be changed to EXTRACTOR_METAFORMAT_UTF8
*/
-#if !WINDOWS
- GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
+#if ! WINDOWS
+ GNUNET_CONTAINER_meta_data_insert (ret->meta,
+ "<gnunet>",
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
EXTRACTOR_METAFORMAT_C_STRING,
- "text/plain", fn, strlen (fn) + 1);
+ "text/plain",
+ fn,
+ strlen (fn) + 1);
#else
- GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
+ GNUNET_CONTAINER_meta_data_insert (ret->meta,
+ "<gnunet>",
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
EXTRACTOR_METAFORMAT_UTF8,
- "text/plain", fn, strlen (fn) + 1);
+ "text/plain",
+ fn,
+ strlen (fn) + 1);
#endif
return ret;
}
* @return publish structure entry for the file
*/
struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
- void *client_info, uint64_t length,
- void *data,
- const struct GNUNET_FS_Uri
- *keywords,
- const struct
- GNUNET_CONTAINER_MetaData *meta,
- int do_index,
- const struct GNUNET_FS_BlockOptions
- *bo)
+GNUNET_FS_file_information_create_from_data (
+ struct GNUNET_FS_Handle *h,
+ void *client_info,
+ uint64_t length,
+ void *data,
+ const struct GNUNET_FS_Uri *keywords,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ int do_index,
+ const struct GNUNET_FS_BlockOptions *bo)
{
if (GNUNET_YES == do_index)
{
GNUNET_break (0);
return NULL;
}
- return GNUNET_FS_file_information_create_from_reader (h, client_info, length,
+ return GNUNET_FS_file_information_create_from_reader (h,
+ client_info,
+ length,
&GNUNET_FS_data_reader_copy_,
- data, keywords, meta,
- do_index, bo);
+ data,
+ keywords,
+ meta,
+ do_index,
+ bo);
}
* @return publish structure entry for the file
*/
struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
- void *client_info,
- uint64_t length,
- GNUNET_FS_DataReader reader,
- void *reader_cls,
- const struct GNUNET_FS_Uri
- *keywords,
- const struct
- GNUNET_CONTAINER_MetaData *meta,
- int do_index,
- const struct
- GNUNET_FS_BlockOptions *bo)
+GNUNET_FS_file_information_create_from_reader (
+ struct GNUNET_FS_Handle *h,
+ void *client_info,
+ uint64_t length,
+ GNUNET_FS_DataReader reader,
+ void *reader_cls,
+ const struct GNUNET_FS_Uri *keywords,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ int do_index,
+ const struct GNUNET_FS_BlockOptions *bo)
{
struct GNUNET_FS_FileInformation *ret;
* @return #GNUNET_YES if so, #GNUNET_NO if not
*/
int
-GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
- *ent)
+GNUNET_FS_file_information_is_directory (
+ const struct GNUNET_FS_FileInformation *ent)
{
return ent->is_directory;
}
* @return publish structure entry for the directory , NULL on error
*/
struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
- void *client_info,
- const struct GNUNET_FS_Uri
- *keywords,
- const struct
- GNUNET_CONTAINER_MetaData
- *meta,
- const struct
- GNUNET_FS_BlockOptions *bo,
- const char *filename)
+GNUNET_FS_file_information_create_empty_directory (
+ struct GNUNET_FS_Handle *h,
+ void *client_info,
+ const struct GNUNET_FS_Uri *keywords,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ const struct GNUNET_FS_BlockOptions *bo,
+ const char *filename)
{
struct GNUNET_FS_FileInformation *ret;
GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
struct GNUNET_FS_FileInformation *ent)
{
- if ((ent->dir != NULL) || (ent->next != NULL) || (dir->is_directory != GNUNET_YES))
+ if ((ent->dir != NULL) || (ent->next != NULL) ||
+ (dir->is_directory != GNUNET_YES))
{
GNUNET_break (0);
return GNUNET_SYSERR;
no = GNUNET_NO;
if (GNUNET_OK !=
- proc (proc_cls, dir,
- (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size : dir->data.
- file.file_size,
- dir->meta, &dir->keywords, &dir->bo,
+ proc (proc_cls,
+ dir,
+ (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size
+ : dir->data.file.file_size,
+ dir->meta,
+ &dir->keywords,
+ &dir->bo,
(dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index,
&dir->client_info))
return;
{
no = GNUNET_NO;
if (GNUNET_OK !=
- proc (proc_cls, pos,
- (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size : pos->data.
- file.file_size, pos->meta, &pos->keywords, &pos->bo,
- (pos->is_directory == GNUNET_YES) ? &no : &pos->data.file.do_index,
+ proc (proc_cls,
+ pos,
+ (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size
+ : pos->data.file.file_size,
+ pos->meta,
+ &pos->keywords,
+ &pos->bo,
+ (pos->is_directory == GNUNET_YES) ? &no
+ : &pos->data.file.do_index,
&pos->client_info))
break;
pos = pos->next;
}
/* clean up client-info */
if (NULL != cleaner)
- cleaner (cleaner_cls, fi, fi->data.dir.dir_size, fi->meta, &fi->keywords,
- &fi->bo, &no, &fi->client_info);
+ cleaner (cleaner_cls,
+ fi,
+ fi->data.dir.dir_size,
+ fi->meta,
+ &fi->keywords,
+ &fi->bo,
+ &no,
+ &fi->client_info);
GNUNET_free_non_null (fi->data.dir.dir_data);
}
else
}
/* clean up client-info */
if (NULL != cleaner)
- cleaner (cleaner_cls, fi, fi->data.file.file_size, fi->meta,
- &fi->keywords, &fi->bo, &fi->data.file.do_index,
+ cleaner (cleaner_cls,
+ fi,
+ fi->data.file.file_size,
+ fi->meta,
+ &fi->keywords,
+ &fi->bo,
+ &fi->data.file.do_index,
&fi->client_info);
}
GNUNET_free_non_null (fi->filename);
GNUNET_free_non_null (fi->emsg);
if (NULL != fi->sks_uri)
- GNUNET_FS_uri_destroy (fi->sks_uri);
+ GNUNET_FS_uri_destroy (fi->sks_uri);
if (NULL != fi->chk_uri)
- GNUNET_FS_uri_destroy (fi->chk_uri);
+ GNUNET_FS_uri_destroy (fi->chk_uri);
/* clean up serialization */
- if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
+ if ((NULL != fi->serialization) && (0 != unlink (fi->serialization)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink",
fi->serialization);
if (NULL != fi->keywords)
GNUNET_FS_uri_destroy (fi->keywords);
* TREE this entry belongs to (if nug is current).
*/
unsigned int tree_id;
-
};
* @return NULL on error, otherwise the name of the directory
*/
static char *
-get_update_information_directory (struct GNUNET_FS_Handle *h,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns)
+get_update_information_directory (
+ struct GNUNET_FS_Handle *h,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns)
{
char *dn;
char *ret;
struct GNUNET_CRYPTO_HashAsciiEncoded enc;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR",
- &dn))
+ GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", &dn))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "fs", "UPDATE_DIR");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR");
return NULL;
}
GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub);
GNUNET_CRYPTO_hash (&pub, sizeof (pub), &hc);
- GNUNET_CRYPTO_hash_to_enc (&hc,
- &enc);
- GNUNET_asprintf (&ret, "%s%s%s",
- dn,
- DIR_SEPARATOR_STR,
- (const char *) enc.encoding);
+ GNUNET_CRYPTO_hash_to_enc (&hc, &enc);
+ GNUNET_asprintf (&ret,
+ "%s%s%s",
+ dn,
+ DIR_SEPARATOR_STR,
+ (const char *) enc.encoding);
GNUNET_free (dn);
return ret;
}
GNUNET_free (nsn->update);
GNUNET_free (nsn);
}
- GNUNET_array_grow (uig->update_nodes, uig->update_node_count,
- 0);
+ GNUNET_array_grow (uig->update_nodes, uig->update_node_count, 0);
if (NULL != uig->update_map)
GNUNET_CONTAINER_multihashmap_destroy (uig->update_map);
GNUNET_free (uig);
struct NamespaceUpdateNode *n;
char *uris;
- fn = get_update_information_directory (uig->h,
- &uig->ns);
+ fn = get_update_information_directory (uig->h, &uig->ns);
wh = GNUNET_BIO_write_open (fn);
if (NULL == wh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to open `%s' for writing: %s\n"),
+ _ ("Failed to open `%s' for writing: %s\n"),
fn,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (fn);
return;
}
END:
if (GNUNET_OK != GNUNET_BIO_write_close (wh))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to write `%s': %s\n"),
+ _ ("Failed to write `%s': %s\n"),
fn,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (fn);
}
*/
static struct GNUNET_FS_UpdateInformationGraph *
read_update_information_graph (struct GNUNET_FS_Handle *h,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns)
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns)
{
struct GNUNET_FS_UpdateInformationGraph *uig;
char *fn;
for (i = 0; i < count; i++)
{
n = GNUNET_new (struct NamespaceUpdateNode);
- if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024))
- || (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
+ if ((GNUNET_OK !=
+ GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) ||
+ (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) ||
(GNUNET_OK !=
GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) ||
(GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2)))
uig->update_nodes[i] = n;
}
uig->update_node_count = i;
- END:
+END:
if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read `%s': %s\n"),
- fn, emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to read `%s': %s\n"),
+ fn,
+ emsg);
GNUNET_free (emsg);
}
GNUNET_free (fn);
* @param msg error message (or NULL)
*/
static void
-sks_publish_cont (void *cls,
- const char *msg)
+sks_publish_cont (void *cls, const char *msg)
{
struct GNUNET_FS_PublishSksContext *psc = cls;
struct GNUNET_FS_UpdateInformationGraph *uig;
/* FIXME: this can be done much more
* efficiently by simply appending to the
* file and overwriting the 4-byte header */
- uig = read_update_information_graph (psc->h,
- &psc->ns);
- GNUNET_array_append (uig->update_nodes,
- uig->update_node_count,
- psc->nsn);
+ uig = read_update_information_graph (psc->h, &psc->ns);
+ GNUNET_array_append (uig->update_nodes, uig->update_node_count, psc->nsn);
psc->nsn = NULL;
write_update_information_graph (uig);
free_update_information_graph (uig);
struct GNUNET_FS_PublishSksContext *
GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
- const char *identifier, const char *update,
+ const char *identifier,
+ const char *update,
const struct GNUNET_CONTAINER_MetaData *meta,
const struct GNUNET_FS_Uri *uri,
const struct GNUNET_FS_BlockOptions *bo,
enum GNUNET_FS_PublishOptions options,
- GNUNET_FS_PublishContinuation cont, void *cont_cls)
+ GNUNET_FS_PublishContinuation cont,
+ void *cont_cls)
{
struct GNUNET_FS_PublishSksContext *psc;
struct GNUNET_FS_Uri *sks_uri;
sks_uri = GNUNET_new (struct GNUNET_FS_Uri);
sks_uri->type = GNUNET_FS_URI_SKS;
sks_uri->data.sks.identifier = GNUNET_strdup (identifier);
- GNUNET_CRYPTO_ecdsa_key_get_public (ns,
- &sks_uri->data.sks.ns);
+ GNUNET_CRYPTO_ecdsa_key_get_public (ns, &sks_uri->data.sks.ns);
psc = GNUNET_new (struct GNUNET_FS_PublishSksContext);
psc->h = h;
psc->dsh = GNUNET_DATASTORE_connect (h->cfg);
if (NULL == psc->dsh)
{
- sks_publish_cont (psc,
- _("Failed to connect to datastore."));
+ sks_publish_cont (psc, _ ("Failed to connect to datastore."));
return NULL;
}
}
psc->nsn->uri = GNUNET_FS_uri_dup (uri);
}
psc->uc = GNUNET_FS_publish_ublock_ (h,
- psc->dsh,
- identifier,
- update,
- ns,
- meta,
- uri,
- bo,
- options,
- &sks_publish_cont,
- psc);
+ psc->dsh,
+ identifier,
+ update,
+ ns,
+ meta,
+ uri,
+ bo,
+ options,
+ &sks_publish_cont,
+ psc);
return psc;
}
* GNUNET_NO if not.
*/
static int
-process_update_node (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct ProcessUpdateClosure *pc = cls;
struct NamespaceUpdateNode *nsn = value;
- pc->ip (pc->ip_cls,
- nsn->id,
- nsn->uri,
- nsn->md,
- nsn->update);
+ pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
return GNUNET_YES;
}
* GNUNET_NO if not.
*/
static int
-find_trees (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+find_trees (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct FindTreeClosure *fc = cls;
struct NamespaceUpdateNode *nsn = value;
if (nsn->nug == fc->nug)
{
if (UINT_MAX == nsn->tree_id)
- return GNUNET_YES; /* circular */
+ return GNUNET_YES; /* circular */
GNUNET_assert (nsn->tree_id < fc->tree_array_size);
if (fc->tree_array[nsn->tree_id] != nsn)
- return GNUNET_YES; /* part of "another" (directed) TREE,
+ return GNUNET_YES; /* part of "another" (directed) TREE,
* and not root of it, end trace */
if (nsn->tree_id == fc->id)
- return GNUNET_YES; /* that's our own root (can this be?) */
+ return GNUNET_YES; /* that's our own root (can this be?) */
/* merge existing TREE, we have a root for both */
fc->tree_array[nsn->tree_id] = NULL;
if (UINT_MAX == fc->id)
- fc->id = nsn->tree_id; /* take over ID */
+ fc->id = nsn->tree_id; /* take over ID */
}
else
{
nsn->nug = fc->nug;
- nsn->tree_id = UINT_MAX; /* mark as undef */
+ nsn->tree_id = UINT_MAX; /* mark as undef */
/* trace */
GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
- GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, &hc,
- &find_trees, fc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map,
+ &hc,
+ &find_trees,
+ fc);
}
return GNUNET_YES;
}
* @param ip_cls closure for ip
*/
void
-GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
- const char *next_id,
- GNUNET_FS_IdentifierProcessor ip,
- void *ip_cls)
+GNUNET_FS_namespace_list_updateable (
+ struct GNUNET_FS_Handle *h,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
+ const char *next_id,
+ GNUNET_FS_IdentifierProcessor ip,
+ void *ip_cls)
{
unsigned int i;
unsigned int nug;
if (NULL == uig->update_nodes)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No updateable nodes found for ID `%s'\n", next_id);
+ "No updateable nodes found for ID `%s'\n",
+ next_id);
free_update_information_graph (uig);
- return; /* no nodes */
+ return; /* no nodes */
}
uig->update_map =
- GNUNET_CONTAINER_multihashmap_create (2 +
- 3 * uig->update_node_count /
- 4,
- GNUNET_NO);
+ GNUNET_CONTAINER_multihashmap_create (2 + 3 * uig->update_node_count / 4,
+ GNUNET_NO);
for (i = 0; i < uig->update_node_count; i++)
{
nsn = uig->update_nodes[i];
GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
- GNUNET_CONTAINER_multihashmap_put (uig->update_map, &hc, nsn,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_CONTAINER_multihashmap_put (
+ uig->update_map,
+ &hc,
+ nsn,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
}
if (NULL != next_id)
{
GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc);
pc.ip = ip;
pc.ip_cls = ip_cls;
- GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc,
- &process_update_node, &pc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map,
+ &hc,
+ &process_update_node,
+ &pc);
free_update_information_graph (uig);
return;
}
nsn = uig->update_nodes[i];
if (nsn->nug == nug)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TREE of node `%s' is %u\n", nsn->id,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TREE of node `%s' is %u\n",
+ nsn->id,
nsn->nug);
- continue; /* already placed in TREE */
+ continue; /* already placed in TREE */
}
GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc);
nsn->nug = nug;
fc.id = UINT_MAX;
fc.nug = nug;
fc.uig = uig;
- GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc,
- &find_trees, &fc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map,
+ &hc,
+ &find_trees,
+ &fc);
if (UINT_MAX == fc.id)
{
/* start new TREE */
nsn->tree_id = fc.id;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting new TREE %u with node `%s'\n", nsn->tree_id,
+ "Starting new TREE %u with node `%s'\n",
+ nsn->tree_id,
nsn->id);
/* put all nodes with same identifier into this TREE */
GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc);
fc.id = nsn->tree_id;
fc.nug = nug;
fc.uig = uig;
- GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc,
- &find_trees, &fc);
+ GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map,
+ &hc,
+ &find_trees,
+ &fc);
}
else
{
nsn->tree_id = fc.id;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TREE of node `%s' is %u\n", nsn->id,
+ "TREE of node `%s' is %u\n",
+ nsn->id,
fc.id);
}
for (i = 0; i < fc.tree_array_size; i++)
nsn = fc.tree_array[i];
if (NULL != nsn)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Root of TREE %u is node `%s'\n", i,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Root of TREE %u is node `%s'\n",
+ i,
nsn->id);
ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update);
}
#include <unistdio.h>
-
/**
* Get a unique key from a URI. This is for putting URIs
* into HashMaps. The key may change between FS implementations.
*/
int
GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
- struct GNUNET_HashCode *key)
+ struct GNUNET_HashCode *key)
{
switch (uri->type)
{
case GNUNET_FS_URI_SKS:
GNUNET_CRYPTO_hash (uri->data.sks.identifier,
strlen (uri->data.sks.identifier),
- key);
+ key);
return GNUNET_OK;
case GNUNET_FS_URI_KSK:
if (uri->data.ksk.keywordCount > 0)
{
GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
strlen (uri->data.ksk.keywords[0]),
- key);
+ key);
return GNUNET_OK;
}
else
case GNUNET_FS_URI_LOC:
GNUNET_CRYPTO_hash (&uri->data.loc.fi,
sizeof (struct FileIdentifier) +
- sizeof (struct GNUNET_PeerIdentity),
+ sizeof (struct GNUNET_PeerIdentity),
key);
return GNUNET_OK;
default:
* @return decodded string with leading space (or preserved plus)
*/
static char *
-percent_decode_keyword (const char *in,
- char **emsg)
+percent_decode_keyword (const char *in, char **emsg)
{
char *out;
char *ret;
{
if (out[rpos] == '%')
{
- if (1 != SSCANF (&out[rpos + 1], "%2X", &hx))
+ if (1 != sscanf (&out[rpos + 1], "%2X", &hx))
{
GNUNET_free (out);
- *emsg = GNUNET_strdup (_(/* xgettext:no-c-format */
- "Malformed KSK URI (`%' must be followed by HEX number)"));
+ *emsg = GNUNET_strdup (
+ _ (/* xgettext:no-c-format */
+ "Malformed KSK URI (`%' must be followed by HEX number)"));
return NULL;
}
rpos += 3;
if (hx == '"')
- continue; /* skip double quote */
+ continue; /* skip double quote */
out[wpos++] = (char) hx;
}
else
* @return NULL on error, otherwise the KSK URI
*/
static struct GNUNET_FS_Uri *
-uri_ksk_parse (const char *s,
- char **emsg)
+uri_ksk_parse (const char *s, char **emsg)
{
struct GNUNET_FS_Uri *ret;
char **keywords;
slen = strlen (s);
pos = strlen (GNUNET_FS_URI_KSK_PREFIX);
if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos)))
- return NULL; /* not KSK URI */
+ return NULL; /* not KSK URI */
if ((s[slen - 1] == '+') || (s[pos] == '+'))
{
*emsg =
- GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')"));
+ GNUNET_strdup (_ ("Malformed KSK URI (must not begin or end with `+')"));
return NULL;
}
max = 1;
max++;
if (s[i - 1] == '+')
{
- *emsg = GNUNET_strdup (_("Malformed KSK URI (`++' not allowed)"));
+ *emsg = GNUNET_strdup (_ ("Malformed KSK URI (`++' not allowed)"));
return NULL;
}
}
}
if (saw_quote == 1)
{
- *emsg = GNUNET_strdup (_("Malformed KSK URI (quotes not balanced)"));
+ *emsg = GNUNET_strdup (_ ("Malformed KSK URI (quotes not balanced)"));
return NULL;
}
iret = max;
dup = GNUNET_strdup (s);
- keywords = GNUNET_new_array (max,
- char *);
+ keywords = GNUNET_new_array (max, char *);
for (i = slen - 1; i >= (int) pos; i--)
{
if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
* @return NULL on error, SKS URI otherwise
*/
static struct GNUNET_FS_Uri *
-uri_sks_parse (const char *s,
- char **emsg)
+uri_sks_parse (const char *s, char **emsg)
{
struct GNUNET_FS_Uri *ret;
struct GNUNET_CRYPTO_EcdsaPublicKey ns;
pos = strlen (GNUNET_FS_URI_SKS_PREFIX);
if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos)))
- return NULL; /* not an SKS URI */
+ return NULL; /* not an SKS URI */
end = strchr (&s[pos], '/');
- if ( (NULL == end) ||
- (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (&s[pos],
- end - &s[pos],
- &ns,
- sizeof (ns))) )
+ if ((NULL == end) ||
+ (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[pos],
+ end - &s[pos],
+ &ns,
+ sizeof (ns))))
{
- *emsg = GNUNET_strdup (_("Malformed SKS URI (wrong syntax)"));
+ *emsg = GNUNET_strdup (_ ("Malformed SKS URI (wrong syntax)"));
return NULL; /* malformed */
}
end++; /* skip over '/' */
* @return NULL on error, CHK URI otherwise
*/
static struct GNUNET_FS_Uri *
-uri_chk_parse (const char *s,
- char **emsg)
+uri_chk_parse (const char *s, char **emsg)
{
struct GNUNET_FS_Uri *ret;
struct FileIdentifier fi;
pos = strlen (GNUNET_FS_URI_CHK_PREFIX);
if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
(0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos)))
- return NULL; /* not a CHK URI */
+ return NULL; /* not a CHK URI */
if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
(s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
{
- *emsg = GNUNET_strdup (_("Malformed CHK URI (wrong syntax)"));
+ *emsg = GNUNET_strdup (_ ("Malformed CHK URI (wrong syntax)"));
return NULL;
}
GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
- GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
- sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ GNUNET_memcpy (h2,
+ &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
+ sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) ||
(GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) ||
(1 !=
- SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
- "%llu", &flen)))
+ sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
+ "%llu",
+ &flen)))
{
- *emsg = GNUNET_strdup (_("Malformed CHK URI (failed to decode CHK)"));
+ *emsg = GNUNET_strdup (_ ("Malformed CHK URI (failed to decode CHK)"));
return NULL;
}
fi.file_length = GNUNET_htonll (flen);
* Peer offering the file.
*/
struct GNUNET_PeerIdentity peer;
-
};
GNUNET_NETWORK_STRUCT_END
* @return NULL on error, valid LOC URI otherwise
*/
static struct GNUNET_FS_Uri *
-uri_loc_parse (const char *s,
- char **emsg)
+uri_loc_parse (const char *s, char **emsg)
{
struct GNUNET_FS_Uri *uri;
char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
pos = strlen (GNUNET_FS_URI_LOC_PREFIX);
if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
(0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos)))
- return NULL; /* not a LOC URI */
+ return NULL; /* not a LOC URI */
if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
(s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
{
- *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax)"));
+ *emsg = GNUNET_strdup (_ ("LOC URI malformed (wrong syntax)"));
return NULL;
}
GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
- GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
- sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
+ GNUNET_memcpy (h2,
+ &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
+ sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) ||
(GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) ||
(1 !=
- SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
- "%llu", &flen)))
+ sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
+ "%llu",
+ &flen)))
{
- *emsg = GNUNET_strdup (_("LOC URI malformed (no CHK)"));
+ *emsg = GNUNET_strdup (_ ("LOC URI malformed (no CHK)"));
return NULL;
}
ass.fi.file_length = GNUNET_htonll (flen);
npos++;
if (s[npos] == '\0')
{
- *emsg = GNUNET_strdup (_("LOC URI malformed (missing LOC)"));
+ *emsg = GNUNET_strdup (_ ("LOC URI malformed (missing LOC)"));
goto ERR;
}
npos++;
- if ( (strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) ||
- ('.' != s[npos+GNUNET_CRYPTO_PKEY_ASCII_LENGTH]) )
+ if ((strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) ||
+ ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH]))
{
*emsg =
- GNUNET_strdup (_("LOC URI malformed (wrong syntax for public key)"));
+ GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for public key)"));
}
- if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos],
- GNUNET_CRYPTO_PKEY_ASCII_LENGTH,
- &ass.peer.public_key))
+ if (
+ GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos],
+ GNUNET_CRYPTO_PKEY_ASCII_LENGTH,
+ &ass.peer.public_key))
{
*emsg =
- GNUNET_strdup (_("LOC URI malformed (could not decode public key)"));
+ GNUNET_strdup (_ ("LOC URI malformed (could not decode public key)"));
goto ERR;
}
npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH;
if (s[npos++] != '.')
{
- *emsg = GNUNET_strdup (_("LOC URI malformed (could not find signature)"));
+ *emsg = GNUNET_strdup (_ ("LOC URI malformed (could not find signature)"));
goto ERR;
}
- if ( (strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) ||
- ('.' != s[npos + SIGNATURE_ASCII_LENGTH]) )
+ if ((strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) ||
+ ('.' != s[npos + SIGNATURE_ASCII_LENGTH]))
{
- *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for signature)"));
+ *emsg =
+ GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for signature)"));
goto ERR;
}
if (GNUNET_OK !=
GNUNET_STRINGS_string_to_data (&s[npos],
SIGNATURE_ASCII_LENGTH,
&sig,
- sizeof (struct GNUNET_CRYPTO_EddsaSignature)))
+ sizeof (
+ struct GNUNET_CRYPTO_EddsaSignature)))
{
- *emsg = GNUNET_strdup (_("LOC URI malformed (could not decode signature)"));
+ *emsg =
+ GNUNET_strdup (_ ("LOC URI malformed (could not decode signature)"));
goto ERR;
}
npos += SIGNATURE_ASCII_LENGTH;
if (s[npos++] != '.')
{
- *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for expiration time)"));
+ *emsg = GNUNET_strdup (
+ _ ("LOC URI malformed (wrong syntax for expiration time)"));
goto ERR;
}
- if (1 != SSCANF (&s[npos], "%llu", &exptime))
+ if (1 != sscanf (&s[npos], "%llu", &exptime))
{
*emsg =
- GNUNET_strdup (_("LOC URI malformed (could not parse expiration time)"));
+ GNUNET_strdup (_ ("LOC URI malformed (could not parse expiration time)"));
goto ERR;
}
ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
ass.exptime = GNUNET_TIME_absolute_hton (et);
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT,
- &ass.purpose, &sig, &ass.peer.public_key))
+ &ass.purpose,
+ &sig,
+ &ass.peer.public_key))
{
*emsg =
- GNUNET_strdup (_("LOC URI malformed (signature failed validation)"));
+ GNUNET_strdup (_ ("LOC URI malformed (signature failed validation)"));
goto ERR;
}
uri = GNUNET_new (struct GNUNET_FS_Uri);
* @return NULL on error
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_parse (const char *uri,
- char **emsg)
+GNUNET_FS_uri_parse (const char *uri, char **emsg)
{
struct GNUNET_FS_Uri *ret;
char *msg;
{
GNUNET_break (0);
if (NULL != emsg)
- *emsg = GNUNET_strdup (_("invalid argument"));
+ *emsg = GNUNET_strdup (_ ("invalid argument"));
return NULL;
}
if (NULL == emsg)
(NULL != (ret = uri_loc_parse (uri, emsg))))
return ret;
if (NULL == *emsg)
- *emsg = GNUNET_strdup (_("Unrecognized URI type"));
+ *emsg = GNUNET_strdup (_ ("Unrecognized URI type"));
if (emsg == &msg)
GNUNET_free (msg);
return NULL;
if (0 == strcmp (&old[1], keyword))
{
uri->data.ksk.keywords[i] =
- uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1];
- GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount,
+ uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1];
+ GNUNET_array_grow (uri->data.ksk.keywords,
+ uri->data.ksk.keywordCount,
uri->data.ksk.keywordCount - 1);
GNUNET_free (old);
return;
return NULL;
/* we round expiration time to full seconds for SKS URIs */
et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL;
- GNUNET_CRYPTO_eddsa_key_get_public (sign_key,
- &my_public_key);
+ GNUNET_CRYPTO_eddsa_key_get_public (sign_key, &my_public_key);
ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
ass.exptime = GNUNET_TIME_absolute_hton (et);
*/
struct GNUNET_FS_Uri *
GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns,
- const char *id)
+ const char *id)
{
struct GNUNET_FS_Uri *ns_uri;
return NULL;
}
kc = u1->data.ksk.keywordCount;
- kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount,
- char *);
+ kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, char *);
for (i = 0; i < u1->data.ksk.keywordCount; i++)
kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]);
for (i = 0; i < u2->data.ksk.keywordCount; i++)
}
if (ret->data.ksk.keywordCount > 0)
{
- ret->data.ksk.keywords
- = GNUNET_new_array (ret->data.ksk.keywordCount,
- char *);
+ ret->data.ksk.keywords =
+ GNUNET_new_array (ret->data.ksk.keywordCount, char *);
for (i = 0; i < ret->data.ksk.keywordCount; i++)
ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]);
}
else
- ret->data.ksk.keywords = NULL; /* just to be sure */
+ ret->data.ksk.keywords = NULL; /* just to be sure */
break;
case GNUNET_FS_URI_SKS:
ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier);
* if keywords is not legal (i.e. empty).
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create (const char *keywords,
- char **emsg)
+GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg)
{
char **keywordarr;
unsigned int num_Words;
if (keywords == NULL)
{
- *emsg = GNUNET_strdup (_("No keywords specified!\n"));
+ *emsg = GNUNET_strdup (_ ("No keywords specified!\n"));
GNUNET_break (0);
return NULL;
}
if (num_Words == 0)
{
GNUNET_free (searchString);
- *emsg = GNUNET_strdup (_("No keywords specified!\n"));
+ *emsg = GNUNET_strdup (_ ("No keywords specified!\n"));
return NULL;
}
if (saw_quote != 0)
{
GNUNET_free (searchString);
- *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n"));
+ *emsg = GNUNET_strdup (_ ("Number of double-quotes not balanced!\n"));
return NULL;
}
- keywordarr = GNUNET_new_array (num_Words,
- char *);
+ keywordarr = GNUNET_new_array (num_Words, char *);
num_Words = 0;
inWord = 0;
pos = searchString;
pos++;
}
uri =
- GNUNET_FS_uri_ksk_create_from_args (num_Words,
- (const char **) keywordarr);
+ GNUNET_FS_uri_ksk_create_from_args (num_Words, (const char **) keywordarr);
GNUNET_free (keywordarr);
GNUNET_free (searchString);
return uri;
* if keywords is not legal (i.e. empty).
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
- const char **argv)
+GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv)
{
unsigned int i;
struct GNUNET_FS_Uri *uri;
* handle accordingly */
emsg = NULL;
if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) &&
- (0 ==
- strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX)))
- && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg))))
+ (0 == strncmp (argv[0],
+ GNUNET_FS_URI_PREFIX,
+ strlen (GNUNET_FS_URI_PREFIX))) &&
+ (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg))))
return uri;
GNUNET_free_non_null (emsg);
uri = GNUNET_new (struct GNUNET_FS_Uri);
uri->type = GNUNET_FS_URI_KSK;
uri->data.ksk.keywordCount = argc;
- uri->data.ksk.keywords = GNUNET_new_array (argc,
- char *);
+ uri->data.ksk.keywords = GNUNET_new_array (argc, char *);
for (i = 0; i < argc; i++)
{
keyword = argv[i];
return GNUNET_YES;
return GNUNET_NO;
case GNUNET_FS_URI_SKS:
- if ((0 ==
- memcmp (&u1->data.sks.ns, &u2->data.sks.ns,
- sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) &&
+ if ((0 == memcmp (&u1->data.sks.ns,
+ &u2->data.sks.ns,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) &&
(0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier)))
return GNUNET_YES;
}
return GNUNET_YES;
case GNUNET_FS_URI_LOC:
- if (memcmp
- (&u1->data.loc, &u2->data.loc,
- sizeof (struct FileIdentifier) +
- sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) +
- sizeof (struct GNUNET_TIME_Absolute) + sizeof (unsigned short) +
- sizeof (unsigned short)) != 0)
+ if (memcmp (&u1->data.loc,
+ &u2->data.loc,
+ sizeof (struct FileIdentifier) +
+ sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) +
+ sizeof (struct GNUNET_TIME_Absolute) +
+ sizeof (unsigned short) + sizeof (unsigned short)) != 0)
return GNUNET_NO;
return GNUNET_YES;
default:
GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym)
{
- if (!GNUNET_FS_uri_test_sks (uri))
+ if (! GNUNET_FS_uri_test_sks (uri))
{
GNUNET_break (0);
return GNUNET_SYSERR;
char *
GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri)
{
- if (!GNUNET_FS_uri_test_sks (uri))
+ if (! GNUNET_FS_uri_test_sks (uri))
{
GNUNET_break (0);
return NULL;
if (uri->type == GNUNET_FS_URI_KSK)
{
- for (i=0;i < uri->data.ksk.keywordCount; i++)
+ for (i = 0; i < uri->data.ksk.keywordCount; i++)
GNUNET_assert (uri->data.ksk.keywords[i] != NULL);
}
#endif
* @return size of the file as specified in the CHK URI
*/
uint64_t
-GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri)
+GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri)
{
switch (uri->type)
{
default:
GNUNET_assert (0);
}
- return 0; /* unreachable */
+ return 0; /* unreachable */
}
* @param index offset where to add the keyword
*/
static void
-insert_non_mandatory_keyword (const char *s,
- char **array,
- int index)
+insert_non_mandatory_keyword (const char *s, char **array, int index)
{
char *nkword;
* @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not
*/
static int
-find_duplicate (const char *s,
- const char **array,
- int array_length)
+find_duplicate (const char *s, const char **array, int array_length)
{
int j;
}
if (format == EXTRACTOR_METAFORMAT_C_STRING)
{
- free_str = u8_strconv_from_encoding (data, locale_charset (), iconveh_escape_sequence);
+ free_str = u8_strconv_from_encoding (data,
+ locale_charset (),
+ iconveh_escape_sequence);
if (free_str == NULL)
return NULL;
}
- normalized = u8_tolower (str_to_normalize, strlen ((char *) str_to_normalize), NULL, UNINORM_NFD, NULL, &r_len);
+ normalized = u8_tolower (str_to_normalize,
+ strlen ((char *) str_to_normalize),
+ NULL,
+ UNINORM_NFD,
+ NULL,
+ &r_len);
/* free_str is allocated by libunistring internally, use free() */
if (free_str != NULL)
free (free_str);
* were duplicates (when extracting).
*/
static int
-get_keywords_from_parens (const char *s,
- char **array,
- int index)
+get_keywords_from_parens (const char *s, char **array, int index)
{
int count = 0;
char *open_paren;
{
char *normalized;
if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1],
- (const char **) array, index + count))
+ (const char **) array,
+ index + count))
{
- insert_non_mandatory_keyword ((const char *) &open_paren[1], array,
- index + count);
+ insert_non_mandatory_keyword ((const char *) &open_paren[1],
+ array,
+ index + count);
count++;
}
normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8,
- &open_paren[1], close_paren - &open_paren[1]);
+ &open_paren[1],
+ close_paren - &open_paren[1]);
if (normalized != NULL)
{
if (GNUNET_NO == find_duplicate ((const char *) normalized,
- (const char **) array, index + count))
+ (const char **) array,
+ index + count))
{
- insert_non_mandatory_keyword ((const char *) normalized, array,
- index + count);
+ insert_non_mandatory_keyword ((const char *) normalized,
+ array,
+ index + count);
count++;
}
GNUNET_free (normalized);
}
}
else
- count++;
+ count++;
close_paren[0] = tmp;
}
}
* duplicates (when extracting).
*/
static int
-get_keywords_from_tokens (const char *s,
- char **array,
- int index)
+get_keywords_from_tokens (const char *s, char **array, int index)
{
char *p;
char *ss;
char *normalized;
if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps))
{
- insert_non_mandatory_keyword (p, array,
- index + seps);
- seps++;
+ insert_non_mandatory_keyword (p, array, index + seps);
+ seps++;
}
- normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8,
- p, strlen (p));
+ normalized =
+ normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, p, strlen (p));
if (normalized != NULL)
{
if (GNUNET_NO == find_duplicate ((const char *) normalized,
- (const char **) array, index + seps))
+ (const char **) array,
+ index + seps))
{
- insert_non_mandatory_keyword ((const char *) normalized, array,
- index + seps);
+ insert_non_mandatory_keyword ((const char *) normalized,
+ array,
+ index + seps);
seps++;
}
GNUNET_free (normalized);
* @return 0 (always)
*/
static int
-gather_uri_data (void *cls, const char *plugin_name,
+gather_uri_data (void *cls,
+ const char *plugin_name,
enum EXTRACTOR_MetaType type,
enum EXTRACTOR_MetaFormat format,
const char *data_mime_type,
*/
if (u8_strcount ((const uint8_t *) data) <= 2)
return 0;
- if ( (EXTRACTOR_METATYPE_MIMETYPE == type) &&
- (NULL != (sep = memchr (data, '/', data_len))) &&
- (sep != data) )
+ if ((EXTRACTOR_METATYPE_MIMETYPE == type) &&
+ (NULL != (sep = memchr (data, '/', data_len))) && (sep != data))
{
char *xtra;
- GNUNET_asprintf (&xtra,
- "mimetype:%.*s",
- (int) (sep - data),
- data);
+ GNUNET_asprintf (&xtra, "mimetype:%.*s", (int) (sep - data), data);
if (! find_duplicate (xtra,
(const char **) uri->data.ksk.keywords,
uri->data.ksk.keywordCount))
uri->data.ksk.keywordCount))
{
insert_non_mandatory_keyword (data,
- uri->data.ksk.keywords, uri->data.ksk.keywordCount);
+ uri->data.ksk.keywords,
+ uri->data.ksk.keywordCount);
uri->data.ksk.keywordCount++;
}
if (NULL != normalized_data)
- {
+ {
if (! find_duplicate (normalized_data,
(const char **) uri->data.ksk.keywords,
uri->data.ksk.keywordCount))
{
insert_non_mandatory_keyword (normalized_data,
- uri->data.ksk.keywords, uri->data.ksk.keywordCount);
+ uri->data.ksk.keywords,
+ uri->data.ksk.keywordCount);
uri->data.ksk.keywordCount++;
}
GNUNET_free (normalized_data);
* @return NULL on error, otherwise a KSK URI
*/
struct GNUNET_FS_Uri *
-GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md)
+GNUNET_FS_uri_ksk_create_from_meta_data (
+ const struct GNUNET_CONTAINER_MetaData *md)
{
struct GNUNET_FS_Uri *ret;
char *filename;
ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
if (ent > 0)
{
- full_name = GNUNET_CONTAINER_meta_data_get_first_by_types (md,
- EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, -1);
+ full_name = GNUNET_CONTAINER_meta_data_get_first_by_types (
+ md,
+ EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
+ -1);
if (NULL != full_name)
{
filename = full_name;
}
/* x3 because there might be a normalized variant of every keyword,
plus theoretically one more for mime... */
- ret->data.ksk.keywords
- = GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3,
- char *);
+ ret->data.ksk.keywords =
+ GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, char *);
GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
}
if (tok_keywords > 0)
- ret->data.ksk.keywordCount += get_keywords_from_tokens (filename,
- ret->data.ksk.keywords,
- ret->data.ksk.keywordCount);
+ ret->data.ksk.keywordCount +=
+ get_keywords_from_tokens (filename,
+ ret->data.ksk.keywords,
+ ret->data.ksk.keywordCount);
if (paren_keywords > 0)
- ret->data.ksk.keywordCount += get_keywords_from_parens (filename,
- ret->data.ksk.keywords,
- ret->data.ksk.keywordCount);
+ ret->data.ksk.keywordCount +=
+ get_keywords_from_parens (filename,
+ ret->data.ksk.keywords,
+ ret->data.ksk.keywordCount);
if (ent > 0)
GNUNET_free_non_null (full_name);
return ret;
static int
needs_percent (char c)
{
- return (!
- ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') ||
- (c == '.') || (c == '~')));
+ return (! ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') ||
+ (c == '.') || (c == '~')));
}
if ((j == 0) && (keyword[j] == ' '))
{
n--;
- continue; /* skip leading space */
+ continue; /* skip leading space */
}
if (needs_percent (keyword[j]))
- n += 2; /* will use %-encoding */
+ n += 2; /* will use %-encoding */
}
}
ret = GNUNET_malloc (n);
for (j = 0; j < slen; j++)
{
if ((j == 0) && (keyword[j] == ' '))
- continue; /* skip leading space */
+ continue; /* skip leading space */
if (needs_percent (keyword[j]))
{
sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]);
if (GNUNET_FS_URI_SKS != uri->type)
return NULL;
- ret = GNUNET_STRINGS_data_to_string (&uri->data.sks.ns,
- sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
- buf,
- sizeof (buf));
+ ret =
+ GNUNET_STRINGS_data_to_string (&uri->data.sks.ns,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
+ buf,
+ sizeof (buf));
GNUNET_assert (NULL != ret);
ret[0] = '\0';
- GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX,
- GNUNET_FS_URI_SKS_INFIX, buf,
- uri->data.sks.identifier);
+ GNUNET_asprintf (&ret,
+ "%s%s%s/%s",
+ GNUNET_FS_URI_PREFIX,
+ GNUNET_FS_URI_SKS_INFIX,
+ buf,
+ uri->data.sks.identifier);
return ret;
}
GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash);
GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash);
- GNUNET_asprintf (&ret, "%s%s%s.%s.%llu", GNUNET_FS_URI_PREFIX,
- GNUNET_FS_URI_CHK_INFIX, (const char *) &keyhash,
- (const char *) &queryhash, GNUNET_ntohll (fi->file_length));
+ GNUNET_asprintf (&ret,
+ "%s%s%s.%s.%llu",
+ GNUNET_FS_URI_PREFIX,
+ GNUNET_FS_URI_CHK_INFIX,
+ (const char *) &keyhash,
+ (const char *) &queryhash,
+ GNUNET_ntohll (fi->file_length));
return ret;
}
GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash);
peer_id =
GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key);
- GNUNET_assert (NULL !=
- GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature,
- sizeof (struct GNUNET_CRYPTO_EddsaSignature),
- peer_sig,
- sizeof (peer_sig)));
+ GNUNET_assert (
+ NULL !=
+ GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature,
+ sizeof (struct GNUNET_CRYPTO_EddsaSignature),
+ peer_sig,
+ sizeof (peer_sig)));
GNUNET_asprintf (&ret,
- "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX,
- GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash,
+ "%s%s%s.%s.%llu.%s.%s.%llu",
+ GNUNET_FS_URI_PREFIX,
+ GNUNET_FS_URI_LOC_INFIX,
+ (const char *) &keyhash,
(const char *) &queryhash,
- (unsigned long long) GNUNET_ntohll (uri->data.loc.
- fi.file_length),
+ (unsigned long long) GNUNET_ntohll (
+ uri->data.loc.fi.file_length),
peer_id,
peer_sig,
- (unsigned long long) uri->data.loc.expirationTime.abs_value_us / 1000000LL);
+ (unsigned long long)
+ uri->data.loc.expirationTime.abs_value_us /
+ 1000000LL);
GNUNET_free (peer_id);
return ret;
}
struct GNUNET_HashCode fx[2];
struct GNUNET_HashCode ft;
- if (0 != STAT (filename, &sbuf))
+ if (0 != stat (filename, &sbuf))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
return GNUNET_OK;
{
if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
{
- printf (_("\t<original file embedded in %u bytes of meta data>\n"),
+ printf (_ ("\t<original file embedded in %u bytes of meta data>\n"),
(unsigned int) data_size);
return 0;
}
printf ("\t%20s: %s\n",
dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
EXTRACTOR_metatype_to_string (type)),
- data);
-#else
- printf ("\t%20d: %s\n",
- type,
data);
+#else
+ printf ("\t%20d: %s\n", type, data);
#endif
return 0;
}
-
/**
* Print an entry in a directory.
*
* @param data data available for the file (length bytes)
*/
static void
-print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta, size_t length,
+print_entry (void *cls,
+ const char *filename,
+ const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *meta,
+ size_t length,
const void *data)
{
char *string;
char *name;
- name =
- GNUNET_CONTAINER_meta_data_get_by_type (meta,
- EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+ name = GNUNET_CONTAINER_meta_data_get_by_type (
+ meta,
+ EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
if (uri == NULL)
{
- printf (_("Directory `%s' meta data:\n"), name ? name : "");
+ printf (_ ("Directory `%s' meta data:\n"), name ? name : "");
GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL);
printf ("\n");
- printf (_("Directory `%s' contents:\n"), name ? name : "");
+ printf (_ ("Directory `%s' contents:\n"), name ? name : "");
GNUNET_free_non_null (name);
return;
}
* @param cfg configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_DISK_MapHandle *map;
if (NULL == args[0])
{
- FPRINTF (stderr, "%s", _("You must specify a filename to inspect.\n"));
+ fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n"));
ret = 1;
return;
}
i = 0;
while (NULL != (filename = args[i++]))
{
- if ((GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) ||
- (NULL ==
- (h =
- GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE))))
+ if ((GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) ||
+ (NULL == (h = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE))))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read directory `%s'\n"),
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to read directory `%s'\n"),
filename);
ret = 1;
continue;
len = (size_t) size;
data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
GNUNET_assert (NULL != data);
- if (GNUNET_OK != GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL))
- fprintf (stdout, _("`%s' is not a GNUnet directory\n"),
- filename);
+ if (GNUNET_OK !=
+ GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL))
+ fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename);
else
printf ("\n");
GNUNET_DISK_file_unmap (map);
main (int argc, char *const *argv)
{
static struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-directory [OPTIONS] FILENAME",
- gettext_noop
- ("Display contents of a GNUnet directory"),
- options, &run, NULL)) ? ret : 1;
- GNUNET_free ((void*) argv);
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-directory [OPTIONS] FILENAME",
+ gettext_noop (
+ "Display contents of a GNUnet directory"),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
* @param w desired number of steps in the progress bar
*/
static void
-display_bar (unsigned long long x,
- unsigned long long n,
- unsigned int w)
+display_bar (unsigned long long x, unsigned long long n, unsigned int w)
{
char buf[w + 20];
unsigned int p;
unsigned int endeq;
float ratio_complete;
-#if !WINDOWS
+#if ! WINDOWS
if (0 == isatty (1))
return;
#else
if (FILE_TYPE_CHAR != GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
return;
#endif
- ratio_complete = x/(float)n;
+ ratio_complete = x / (float) n;
endeq = ratio_complete * w;
- GNUNET_snprintf (buf, sizeof (buf),
- "%3d%% [", (int)(ratio_complete*100) );
- for (p=0; p<endeq; p++)
+ GNUNET_snprintf (buf, sizeof (buf), "%3d%% [", (int) (ratio_complete * 100));
+ for (p = 0; p < endeq; p++)
strcat (buf, "=");
- for (p=endeq; p<w; p++)
+ for (p = endeq; p < w; p++)
strcat (buf, " ");
strcat (buf, "]\r");
printf ("%s", buf);
- fflush(stdout);
+ fflush (stdout);
}
* field in the `struct GNUNET_FS_ProgressInfo`
*/
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *info)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
char *s;
const char *s2;
{
case GNUNET_FS_STATUS_DOWNLOAD_START:
if (verbose > 1)
- FPRINTF (stderr,
- _("Starting download `%s'.\n"),
+ fprintf (stderr,
+ _ ("Starting download `%s'.\n"),
info->value.download.filename);
break;
case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
if (verbose)
{
- s = GNUNET_strdup (GNUNET_STRINGS_relative_time_to_string (info->value.download.eta,
- GNUNET_YES));
- if (info->value.download.specifics.progress.block_download_duration.rel_value_us
- == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
- s2 = _("<unknown time>");
+ s = GNUNET_strdup (
+ GNUNET_STRINGS_relative_time_to_string (info->value.download.eta,
+ GNUNET_YES));
+ if (info->value.download.specifics.progress.block_download_duration
+ .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
+ s2 = _ ("<unknown time>");
else
- s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download.specifics.progress.block_download_duration,
- GNUNET_YES);
- t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed *
- 1000LL /
- (info->value.download.
- duration.rel_value_us + 1));
- FPRINTF (stdout,
- _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"),
- info->value.download.filename,
- (unsigned long long) info->value.download.completed,
- (unsigned long long) info->value.download.size,
- s,
- t,
- s2);
+ s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download
+ .specifics.progress
+ .block_download_duration,
+ GNUNET_YES);
+ t = GNUNET_STRINGS_byte_size_fancy (
+ info->value.download.completed * 1000LL /
+ (info->value.download.duration.rel_value_us + 1));
+ fprintf (
+ stdout,
+ _ (
+ "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"),
+ info->value.download.filename,
+ (unsigned long long) info->value.download.completed,
+ (unsigned long long) info->value.download.size,
+ s,
+ t,
+ s2);
GNUNET_free (s);
GNUNET_free (t);
}
else
{
display_bar (info->value.download.completed,
- info->value.download.size,
- 60);
+ info->value.download.size,
+ 60);
}
break;
case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
-#if !WINDOWS
+#if ! WINDOWS
if (0 != isatty (1))
fprintf (stdout, "\n");
#else
- if (FILE_TYPE_CHAR ==
- GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
+ if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
fprintf (stdout, "\n");
#endif
- FPRINTF (stderr, _("Error downloading: %s.\n"),
+ fprintf (stderr,
+ _ ("Error downloading: %s.\n"),
info->value.download.specifics.error.message);
GNUNET_SCHEDULER_shutdown ();
break;
case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
- s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 /
- (info->value.download.
- duration.rel_value_us + 1));
-#if !WINDOWS
+ s = GNUNET_STRINGS_byte_size_fancy (
+ info->value.download.completed * 1000 /
+ (info->value.download.duration.rel_value_us + 1));
+#if ! WINDOWS
if (0 != isatty (1))
fprintf (stdout, "\n");
#else
- if (FILE_TYPE_CHAR ==
- GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
+ if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
fprintf (stdout, "\n");
#endif
- FPRINTF (stdout,
- _("Downloading `%s' done (%s/s).\n"),
- info->value.download.filename, s);
+ fprintf (stdout,
+ _ ("Downloading `%s' done (%s/s).\n"),
+ info->value.download.filename,
+ s);
GNUNET_free (s);
if (info->value.download.dc == dc)
GNUNET_SCHEDULER_shutdown ();
case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
break;
default:
- FPRINTF (stderr,
- _("Unexpected status: %d\n"),
- info->status);
+ fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
break;
}
return NULL;
if (NULL == args[0])
{
- FPRINTF (stderr,
- "%s",
- _("You need to specify a URI argument.\n"));
+ fprintf (stderr, "%s", _ ("You need to specify a URI argument.\n"));
return;
}
uri = GNUNET_FS_uri_parse (args[0], &emsg);
if (NULL == uri)
{
- FPRINTF (stderr,
- _("Failed to parse URI: %s\n"),
- emsg);
+ fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg);
GNUNET_free (emsg);
ret = 1;
return;
}
- if ( (! GNUNET_FS_uri_test_chk (uri)) &&
- (! GNUNET_FS_uri_test_loc (uri)))
+ if ((! GNUNET_FS_uri_test_chk (uri)) && (! GNUNET_FS_uri_test_loc (uri)))
{
- FPRINTF (stderr,
- "%s",
- _("Only CHK or LOC URIs supported.\n"));
+ fprintf (stderr, "%s", _ ("Only CHK or LOC URIs supported.\n"));
ret = 1;
GNUNET_FS_uri_destroy (uri);
return;
}
if (NULL == filename)
{
- FPRINTF (stderr,
- "%s",
- _("Target filename must be specified.\n"));
+ fprintf (stderr, "%s", _ ("Target filename must be specified.\n"));
ret = 1;
GNUNET_FS_uri_destroy (uri);
return;
}
cfg = c;
ctx = GNUNET_FS_start (cfg,
- "gnunet-download",
- &progress_cb, NULL,
- GNUNET_FS_FLAGS_NONE,
- GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
- parallelism,
- GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
- request_parallelism,
- GNUNET_FS_OPTIONS_END);
+ "gnunet-download",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
+ parallelism,
+ GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
+ request_parallelism,
+ GNUNET_FS_OPTIONS_END);
if (NULL == ctx)
{
- FPRINTF (stderr,
- _("Could not initialize `%s' subsystem.\n"),
- "FS");
+ fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
GNUNET_FS_uri_destroy (uri);
ret = 1;
return;
if (local_only)
options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY;
dc = GNUNET_FS_download_start (ctx,
- uri,
- NULL,
- filename,
- NULL,
- 0,
+ uri,
+ NULL,
+ filename,
+ NULL,
+ 0,
GNUNET_FS_uri_chk_get_file_size (uri),
anonymity,
- options,
- NULL,
- NULL);
+ options,
+ NULL,
+ NULL);
GNUNET_FS_uri_destroy (uri);
if (dc == NULL)
{
ctx = NULL;
return;
}
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_uint ('a',
- "anonymity",
- "LEVEL",
- gettext_noop ("set the desired LEVEL of receiver-anonymity"),
- &anonymity),
-
- GNUNET_GETOPT_option_flag ('D',
- "delete-incomplete",
- gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"),
- &delete_incomplete),
-
- GNUNET_GETOPT_option_flag ('n',
- "no-network",
- gettext_noop ("only search the local peer (no P2P network search)"),
- &local_only),
- GNUNET_GETOPT_option_string ('o',
- "output",
- "FILENAME",
- gettext_noop ("write the file to FILENAME"),
- &filename),
- GNUNET_GETOPT_option_uint ('p',
- "parallelism",
- "DOWNLOADS",
- gettext_noop ("set the maximum number of parallel downloads that is allowed"),
- ¶llelism),
- GNUNET_GETOPT_option_uint ('r',
- "request-parallelism",
- "REQUESTS",
- gettext_noop ("set the maximum number of parallel requests for blocks that is allowed"),
- &request_parallelism),
- GNUNET_GETOPT_option_flag ('R',
- "recursive",
- gettext_noop ("download a GNUnet directory recursively"),
- &do_recursive),
- GNUNET_GETOPT_option_increment_uint ('V',
- "verbose",
- gettext_noop ("be verbose (print progress information)"),
- &verbose),
- GNUNET_GETOPT_OPTION_END
- };
-
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_uint ('a',
+ "anonymity",
+ "LEVEL",
+ gettext_noop (
+ "set the desired LEVEL of receiver-anonymity"),
+ &anonymity),
+
+ GNUNET_GETOPT_option_flag (
+ 'D',
+ "delete-incomplete",
+ gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"),
+ &delete_incomplete),
+
+ GNUNET_GETOPT_option_flag (
+ 'n',
+ "no-network",
+ gettext_noop ("only search the local peer (no P2P network search)"),
+ &local_only),
+ GNUNET_GETOPT_option_string ('o',
+ "output",
+ "FILENAME",
+ gettext_noop ("write the file to FILENAME"),
+ &filename),
+ GNUNET_GETOPT_option_uint (
+ 'p',
+ "parallelism",
+ "DOWNLOADS",
+ gettext_noop (
+ "set the maximum number of parallel downloads that is allowed"),
+ ¶llelism),
+ GNUNET_GETOPT_option_uint (
+ 'r',
+ "request-parallelism",
+ "REQUESTS",
+ gettext_noop (
+ "set the maximum number of parallel requests for blocks that is allowed"),
+ &request_parallelism),
+ GNUNET_GETOPT_option_flag ('R',
+ "recursive",
+ gettext_noop (
+ "download a GNUnet directory recursively"),
+ &do_recursive),
+ GNUNET_GETOPT_option_increment_uint (
+ 'V',
+ "verbose",
+ gettext_noop ("be verbose (print progress information)"),
+ &verbose),
+ GNUNET_GETOPT_OPTION_END};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv,
- "gnunet-download [OPTIONS] URI",
- gettext_noop
- ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"),
- options,
- &run, NULL)) ? ret : 1;
- GNUNET_free ((void*) argv);
+ ret =
+ (GNUNET_OK ==
+ GNUNET_PROGRAM_run (
+ argc,
+ argv,
+ "gnunet-download [OPTIONS] URI",
+ gettext_noop (
+ "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
* @return GNUNET_OK to continue iteration
*/
static int
-print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * file_id)
+print_indexed (void *cls,
+ const char *filename,
+ const struct GNUNET_HashCode *file_id)
{
if (NULL == filename)
{
return GNUNET_OK;
}
if (verbose)
- FPRINTF (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
+ fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
else
- FPRINTF (stdout, "%s\n", filename);
+ fprintf (stdout, "%s\n", filename);
return GNUNET_OK;
}
* @param cfg configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
if (list_indexed_files)
{
- fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE,
+ fs = GNUNET_FS_start (cfg,
+ "gnunet-fs",
+ NULL,
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
GNUNET_FS_OPTIONS_END);
if (NULL == fs)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_option_flag ('i',
- "list-indexed",
- gettext_noop ("print a list of all indexed files"),
- &list_indexed_files),
+ "list-indexed",
+ gettext_noop (
+ "print a list of all indexed files"),
+ &list_indexed_files),
GNUNET_GETOPT_option_verbose (&verbose),
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]",
- gettext_noop ("Special file-sharing operations"),
- options, &run, NULL)) ? ret : 1;
- GNUNET_free ((void*) argv);
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-fs [OPTIONS]",
+ gettext_noop ("Special file-sharing operations"),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
* #GNUNET_YES if this is a directory
*/
int is_directory;
-
};
{
struct GNUNET_CONTAINER_MetaData *md = cls;
- if ( ((EXTRACTOR_METAFORMAT_UTF8 == format) ||
- (EXTRACTOR_METAFORMAT_C_STRING == format)) &&
- ('\0' != data[data_len - 1]) )
+ if (((EXTRACTOR_METAFORMAT_UTF8 == format) ||
+ (EXTRACTOR_METAFORMAT_C_STRING == format)) &&
+ ('\0' != data[data_len - 1]))
{
char zdata[data_len + 1];
GNUNET_memcpy (zdata, data, data_len);
zdata[data_len] = '\0';
- (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
- data_mime_type, zdata, data_len + 1);
+ (void) GNUNET_CONTAINER_meta_data_insert (md,
+ plugin_name,
+ type,
+ format,
+ data_mime_type,
+ zdata,
+ data_len + 1);
}
else
{
- (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
- data_mime_type, data, data_len);
+ (void) GNUNET_CONTAINER_meta_data_insert (md,
+ plugin_name,
+ type,
+ format,
+ data_mime_type,
+ data,
+ data_len);
}
return 0;
}
free_tree (pos);
if (NULL != tree->parent)
GNUNET_CONTAINER_DLL_remove (tree->parent->children_head,
- tree->parent->children_tail,
- tree);
+ tree->parent->children_tail,
+ tree);
GNUNET_free (tree->filename);
GNUNET_free (tree);
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
static int
-write_all (const void *buf,
- size_t size)
+write_all (const void *buf, size_t size)
{
const char *cbuf = buf;
size_t total;
total = 0;
do
{
- wr = write (output_stream,
- &cbuf[total],
- size - total);
+ wr = write (output_stream, &cbuf[total], size - total);
if (wr > 0)
total += wr;
- } while ( (wr > 0) && (total < size) );
+ } while ((wr > 0) && (total < size));
if (wr <= 0)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to write to stdout: %s\n",
- strerror (errno));
+ "Failed to write to stdout: %s\n",
+ strerror (errno));
return (total == size) ? GNUNET_OK : GNUNET_SYSERR;
}
* @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow)
*/
static int
-write_message (uint16_t message_type,
- const char *data,
- size_t data_length)
+write_message (uint16_t message_type, const char *data, size_t data_length)
{
struct GNUNET_MessageHeader hdr;
#endif
hdr.type = htons (message_type);
hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length);
- if ( (GNUNET_OK !=
- write_all (&hdr,
- sizeof (hdr))) ||
- (GNUNET_OK !=
- write_all (data,
- data_length)) )
+ if ((GNUNET_OK != write_all (&hdr, sizeof (hdr))) ||
+ (GNUNET_OK != write_all (data, data_length)))
return GNUNET_SYSERR;
return GNUNET_OK;
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
static int
-preprocess_file (const char *filename,
- struct ScanTreeNode **dst);
+preprocess_file (const char *filename, struct ScanTreeNode **dst);
/**
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
static int
-scan_callback (void *cls,
- const char *filename)
+scan_callback (void *cls, const char *filename)
{
struct RecursionContext *rc = cls;
struct ScanTreeNode *chld;
- if (GNUNET_OK !=
- preprocess_file (filename,
- &chld))
+ if (GNUNET_OK != preprocess_file (filename, &chld))
{
rc->stop = GNUNET_YES;
return GNUNET_SYSERR;
return GNUNET_OK;
chld->parent = rc->parent;
GNUNET_CONTAINER_DLL_insert (rc->parent->children_head,
- rc->parent->children_tail,
- chld);
+ rc->parent->children_tail,
+ chld);
return GNUNET_OK;
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
static int
-preprocess_file (const char *filename,
- struct ScanTreeNode **dst)
+preprocess_file (const char *filename, struct ScanTreeNode **dst)
{
struct ScanTreeNode *item;
struct stat sbuf;
uint64_t fsize = 0;
- if ((0 != STAT (filename, &sbuf)) ||
- ((!S_ISDIR (sbuf.st_mode)) && (GNUNET_OK != GNUNET_DISK_file_size (
- filename, &fsize, GNUNET_NO, GNUNET_YES))))
+ if ((0 != stat (filename, &sbuf)) ||
+ ((! S_ISDIR (sbuf.st_mode)) &&
+ (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES))))
{
/* If the file doesn't exist (or is not stat-able for any other reason)
skip it (but report it), but do continue. */
if (GNUNET_OK !=
- write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE,
- filename, strlen (filename) + 1))
+ write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE,
+ filename,
+ strlen (filename) + 1))
return GNUNET_SYSERR;
/* recoverable error, store 'NULL' in *dst */
*dst = NULL;
}
/* Report the progress */
- if (GNUNET_OK !=
- write_message (S_ISDIR (sbuf.st_mode)
- ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY
- : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE,
- filename, strlen (filename) + 1))
+ if (
+ GNUNET_OK !=
+ write_message (S_ISDIR (sbuf.st_mode)
+ ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY
+ : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE,
+ filename,
+ strlen (filename) + 1))
return GNUNET_SYSERR;
item = GNUNET_new (struct ScanTreeNode);
item->filename = GNUNET_strdup (filename);
rc.parent = item;
rc.stop = GNUNET_NO;
- GNUNET_DISK_directory_scan (filename,
- &scan_callback,
- &rc);
- if ( (GNUNET_YES == rc.stop) ||
- (GNUNET_OK !=
- write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY,
- "..", 3)) )
+ GNUNET_DISK_directory_scan (filename, &scan_callback, &rc);
+ if (
+ (GNUNET_YES == rc.stop) ||
+ (GNUNET_OK !=
+ write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY,
+ "..",
+ 3)))
{
free_tree (item);
return GNUNET_SYSERR;
struct ScanTreeNode *pos;
for (pos = item->children_head; NULL != pos; pos = pos->next)
- if (GNUNET_OK !=
- extract_files (pos))
- return GNUNET_SYSERR;
+ if (GNUNET_OK != extract_files (pos))
+ return GNUNET_SYSERR;
return GNUNET_OK;
}
/* this is the expensive operation, *afterwards* we'll check for aborts */
meta = GNUNET_CONTAINER_meta_data_create ();
#if HAVE_LIBEXTRACTOR
- EXTRACTOR_extract (plugins,
- item->filename,
- NULL, 0,
- &add_to_md,
- meta);
+ EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta);
#endif
slen = strlen (item->filename) + 1;
size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
/* no meta data */
GNUNET_CONTAINER_meta_data_destroy (meta);
if (GNUNET_OK !=
- write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA,
- item->filename, slen))
+ write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA,
+ item->filename,
+ slen))
return GNUNET_SYSERR;
return GNUNET_OK;
}
char *dst = &buf[slen];
GNUNET_memcpy (buf, item->filename, slen);
- size = GNUNET_CONTAINER_meta_data_serialize (meta,
- &dst, size,
- GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+ size = GNUNET_CONTAINER_meta_data_serialize (
+ meta,
+ &dst,
+ size,
+ GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
if (size < 0)
{
GNUNET_break (0);
}
GNUNET_CONTAINER_meta_data_destroy (meta);
if (GNUNET_OK !=
- write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA,
- buf,
- slen + size))
+ write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA,
+ buf,
+ slen + size))
return GNUNET_SYSERR;
}
return GNUNET_OK;
sig.sa_handler = SIG_IGN;
sigemptyset (&sig.sa_mask);
#ifdef SA_INTERRUPT
- sig.sa_flags = SA_INTERRUPT; /* SunOS */
+ sig.sa_flags = SA_INTERRUPT; /* SunOS */
#else
sig.sa_flags = SA_RESTART;
#endif
if (0 != sigaction (SIGPIPE, &sig, &oldsig))
fprintf (stderr,
- "Failed to install SIGPIPE handler: %s\n", strerror (errno));
+ "Failed to install SIGPIPE handler: %s\n",
+ strerror (errno));
}
* @param flags flags to use (O_RDONLY or O_WRONLY)
*/
static void
-make_dev_zero (int fd,
- int flags)
+make_dev_zero (int fd, int flags)
{
int z;
* @return 0 on success
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
const char *filename_expanded;
const char *ex;
#endif
/* parse command line */
- if ( (3 != argc) && (2 != argc) )
+ if ((3 != argc) && (2 != argc))
{
- FPRINTF (stderr,
- "%s",
- "gnunet-helper-fs-publish needs exactly one or two arguments\n");
+ fprintf (stderr,
+ "%s",
+ "gnunet-helper-fs-publish needs exactly one or two arguments\n");
#if WINDOWS
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
#endif
return 1;
}
filename_expanded = argv[1];
ex = argv[2];
- if ( (NULL == ex) ||
- (0 != strcmp (ex, "-")) )
+ if ((NULL == ex) || (0 != strcmp (ex, "-")))
{
#if HAVE_LIBEXTRACTOR
plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY);
if (NULL != ex)
- plugins = EXTRACTOR_plugin_add_config (plugins, ex,
- EXTRACTOR_OPTION_DEFAULT_POLICY);
+ plugins = EXTRACTOR_plugin_add_config (plugins,
+ ex,
+ EXTRACTOR_OPTION_DEFAULT_POLICY);
#endif
}
/* scan tree to find out how much work there is to be done */
- if (GNUNET_OK != preprocess_file (filename_expanded,
- &root))
+ if (GNUNET_OK != preprocess_file (filename_expanded, &root))
{
(void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0);
#if HAVE_LIBEXTRACTOR
EXTRACTOR_plugin_remove_all (plugins);
#endif
#if WINDOWS
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
#endif
return 2;
}
/* signal that we're done counting files, so that a percentage of
progress can now be calculated */
if (GNUNET_OK !=
- write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, NULL, 0))
+ write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE,
+ NULL,
+ 0))
{
#if HAVE_LIBEXTRACTOR
EXTRACTOR_plugin_remove_all (plugins);
#endif
#if WINDOWS
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
#endif
return 3;
}
if (NULL != root)
{
- if (GNUNET_OK !=
- extract_files (root))
+ if (GNUNET_OK != extract_files (root))
{
- (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0);
+ (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR,
+ NULL,
+ 0);
free_tree (root);
#if HAVE_LIBEXTRACTOR
EXTRACTOR_plugin_remove_all (plugins);
#endif
#if WINDOWS
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
#endif
return 4;
}
free_tree (root);
}
/* enable "clean" shutdown by telling parent that we are done */
- (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, NULL, 0);
+ (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED,
+ NULL,
+ 0);
#if HAVE_LIBEXTRACTOR
EXTRACTOR_plugin_remove_all (plugins);
#endif
#if WINDOWS
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
#endif
return 0;
}
/**
* Options we set for published blocks.
*/
-static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 };
+static struct GNUNET_FS_BlockOptions bo = {{0LL}, 1, 365, 1};
/**
* Value of URI provided on command-line (when not publishing
* field in the GNUNET_FS_ProgressInfo struct.
*/
static void *
-progress_cb (void *cls,
- const struct GNUNET_FS_ProgressInfo *info)
+progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
{
const char *s;
char *suri;
if (verbose)
{
s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta,
- GNUNET_YES);
- FPRINTF (stdout,
- _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
+ GNUNET_YES);
+ fprintf (stdout,
+ _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"),
info->value.publish.filename,
(unsigned long long) info->value.publish.completed,
- (unsigned long long) info->value.publish.size, s);
+ (unsigned long long) info->value.publish.size,
+ s);
}
break;
case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
if (verbose)
{
- s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics.progress_directory.eta,
- GNUNET_YES);
- FPRINTF (stdout,
- _("Publishing `%s' at %llu/%llu (%s remaining)\n"),
+ s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics
+ .progress_directory.eta,
+ GNUNET_YES);
+ fprintf (stdout,
+ _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"),
info->value.publish.filename,
- (unsigned long long) info->value.publish.specifics.progress_directory.completed,
- (unsigned long long) info->value.publish.specifics.progress_directory.total, s);
+ (unsigned long long)
+ info->value.publish.specifics.progress_directory.completed,
+ (unsigned long long)
+ info->value.publish.specifics.progress_directory.total,
+ s);
}
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- FPRINTF (stderr,
- _("Error publishing: %s.\n"),
+ fprintf (stderr,
+ _ ("Error publishing: %s.\n"),
info->value.publish.specifics.error.message);
ret = 1;
GNUNET_SCHEDULER_shutdown ();
break;
case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
- FPRINTF (stdout,
- _("Publishing `%s' done.\n"),
+ fprintf (stdout,
+ _ ("Publishing `%s' done.\n"),
info->value.publish.filename);
- suri = GNUNET_FS_uri_to_string (info->value.publish.specifics.
- completed.chk_uri);
- FPRINTF (stdout,
- _("URI is `%s'.\n"),
- suri);
+ suri =
+ GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.chk_uri);
+ fprintf (stdout, _ ("URI is `%s'.\n"), suri);
GNUNET_free (suri);
if (NULL != info->value.publish.specifics.completed.sks_uri)
{
- suri = GNUNET_FS_uri_to_string (info->value.publish.specifics.
- completed.sks_uri);
- FPRINTF (stdout,
- _("Namespace URI is `%s'.\n"),
- suri);
+ suri = GNUNET_FS_uri_to_string (
+ info->value.publish.specifics.completed.sks_uri);
+ fprintf (stdout, _ ("Namespace URI is `%s'.\n"), suri);
GNUNET_free (suri);
}
if (NULL == info->value.publish.pctx)
GNUNET_break (NULL == pc);
return NULL;
case GNUNET_FS_STATUS_UNINDEX_START:
- FPRINTF (stderr,
- "%s",
- _("Starting cleanup after abort\n"));
+ fprintf (stderr, "%s", _ ("Starting cleanup after abort\n"));
return NULL;
case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
return NULL;
case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
- FPRINTF (stderr,
- "%s",
- _("Cleanup after abort completed.\n"));
+ fprintf (stderr, "%s", _ ("Cleanup after abort completed.\n"));
GNUNET_FS_unindex_stop (info->value.unindex.uc);
return NULL;
case GNUNET_FS_STATUS_UNINDEX_ERROR:
- FPRINTF (stderr,
- "%s",
- _("Cleanup after abort failed.\n"));
+ fprintf (stderr, "%s", _ ("Cleanup after abort failed.\n"));
GNUNET_FS_unindex_stop (info->value.unindex.uc);
return NULL;
case GNUNET_FS_STATUS_UNINDEX_STOPPED:
return NULL;
default:
- FPRINTF (stderr,
- _("Unexpected status: %d\n"),
- info->status);
+ fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
return NULL;
}
- return ""; /* non-null */
+ return ""; /* non-null */
}
enum EXTRACTOR_MetaType type,
enum EXTRACTOR_MetaFormat format,
const char *data_mime_type,
- const char *data, size_t data_size)
+ const char *data,
+ size_t data_size)
{
if ((EXTRACTOR_METAFORMAT_UTF8 != format) &&
(EXTRACTOR_METAFORMAT_C_STRING != format))
if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type)
return 0;
#if HAVE_LIBEXTRACTOR
- FPRINTF (stdout,
- "\t%s - %s\n",
- EXTRACTOR_metatype_to_string (type),
- data);
+ fprintf (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data);
#else
- FPRINTF (stdout,
- "\t%d - %s\n",
- type,
- data);
+ fprintf (stdout, "\t%d - %s\n", type, data);
#endif
return 0;
}
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort
*/
static int
-keyword_printer (void *cls,
- const char *keyword,
- int is_mandatory)
+keyword_printer (void *cls, const char *keyword, int is_mandatory)
{
- FPRINTF (stdout, "\t%s\n", keyword);
+ fprintf (stdout, "\t%s\n", keyword);
return GNUNET_OK;
}
if (cls == fi)
return GNUNET_OK;
- if ( (disable_extractor) &&
- (NULL != *uri) )
+ if ((disable_extractor) && (NULL != *uri))
{
GNUNET_FS_uri_destroy (*uri);
*uri = NULL;
GNUNET_CONTAINER_meta_data_add_publication_date (m);
if (extract_only)
{
- fn = GNUNET_CONTAINER_meta_data_get_by_type (m,
- EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+ fn = GNUNET_CONTAINER_meta_data_get_by_type (
+ m,
+ EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
fs = GNUNET_STRINGS_byte_size_fancy (length);
- FPRINTF (stdout,
- _("Meta data for file `%s' (%s)\n"),
- fn,
- fs);
+ fprintf (stdout, _ ("Meta data for file `%s' (%s)\n"), fn, fs);
GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL);
- FPRINTF (stdout,
- _("Keywords for file `%s' (%s)\n"),
- fn,
- fs);
+ fprintf (stdout, _ ("Keywords for file `%s' (%s)\n"), fn, fs);
GNUNET_free (fn);
GNUNET_free (fs);
if (NULL != *uri)
GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL);
- FPRINTF (stdout,
- "%s",
- "\n");
+ fprintf (stdout, "%s", "\n");
}
if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m))
- GNUNET_FS_file_information_inspect (fi,
- &publish_inspector, fi);
+ GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi);
return GNUNET_OK;
}
{
if (NULL != emsg)
{
- FPRINTF (stderr,
- "%s\n",
- emsg);
+ fprintf (stderr, "%s\n", emsg);
ret = 1;
}
GNUNET_SCHEDULER_shutdown ();
if (NULL != emsg)
{
- FPRINTF (stderr,
- "%s\n",
- emsg);
+ fprintf (stderr, "%s\n", emsg);
ret = 1;
}
if (NULL == namespace)
}
priv = GNUNET_IDENTITY_ego_get_private_key (namespace);
GNUNET_FS_publish_sks (ctx,
- priv,
- this_id,
- next_id,
- meta,
- uri,
- &bo,
- GNUNET_FS_PUBLISH_OPTION_NONE,
- &uri_sks_continuation,
- NULL);
+ priv,
+ this_id,
+ next_id,
+ meta,
+ uri,
+ &bo,
+ GNUNET_FS_PUBLISH_OPTION_NONE,
+ &uri_sks_continuation,
+ NULL);
}
if (NULL == item->meta)
item->meta = GNUNET_CONTAINER_meta_data_create ();
GNUNET_CONTAINER_meta_data_delete (item->meta,
- EXTRACTOR_METATYPE_MIMETYPE,
- NULL, 0);
+ EXTRACTOR_METATYPE_MIMETYPE,
+ NULL,
+ 0);
GNUNET_FS_meta_data_make_directory (item->meta);
if (NULL == item->ksk_uri)
{
item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime);
}
else
- GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, GNUNET_FS_DIRECTORY_MIME,
- GNUNET_NO);
- fi = GNUNET_FS_file_information_create_empty_directory (ctx, NULL,
- item->ksk_uri,
- item->meta,
- &bo, item->filename);
+ GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri,
+ GNUNET_FS_DIRECTORY_MIME,
+ GNUNET_NO);
+ fi = GNUNET_FS_file_information_create_empty_directory (ctx,
+ NULL,
+ item->ksk_uri,
+ item->meta,
+ &bo,
+ item->filename);
for (child = item->children_head; child; child = child->next)
{
fic = get_file_information (child);
}
else
{
- fi = GNUNET_FS_file_information_create_from_file (ctx, NULL,
- item->filename,
- item->ksk_uri, item->meta,
- !do_insert,
- &bo);
+ fi = GNUNET_FS_file_information_create_from_file (ctx,
+ NULL,
+ item->filename,
+ item->ksk_uri,
+ item->meta,
+ ! do_insert,
+ &bo);
}
return fi;
}
GNUNET_FS_share_tree_free (directory_scan_result);
if (NULL == fi)
{
- FPRINTF (stderr,
- "%s",
- _("Could not publish\n"));
+ fprintf (stderr, "%s", _ ("Could not publish\n"));
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
priv = NULL;
else
priv = GNUNET_IDENTITY_ego_get_private_key (namespace);
- pc = GNUNET_FS_publish_start (ctx, fi,
- priv, this_id, next_id,
- (do_simulate) ?
- GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY :
- GNUNET_FS_PUBLISH_OPTION_NONE);
+ pc = GNUNET_FS_publish_start (ctx,
+ fi,
+ priv,
+ this_id,
+ next_id,
+ (do_simulate)
+ ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY
+ : GNUNET_FS_PUBLISH_OPTION_NONE);
if (NULL == pc)
{
- FPRINTF (stderr,
- "%s",
- _("Could not start publishing.\n"));
+ fprintf (stderr, "%s", _ ("Could not start publishing.\n"));
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
*/
static void
directory_scan_cb (void *cls,
- const char *filename,
- int is_directory,
- enum GNUNET_FS_DirScannerProgressUpdateReason reason)
+ const char *filename,
+ int is_directory,
+ enum GNUNET_FS_DirScannerProgressUpdateReason reason)
{
struct GNUNET_FS_ShareTreeItem *directory_scan_result;
if (verbose > 1)
{
if (is_directory == GNUNET_YES)
- FPRINTF (stdout,
- _("Scanning directory `%s'.\n"),
- filename);
+ fprintf (stdout, _ ("Scanning directory `%s'.\n"), filename);
else
- FPRINTF (stdout,
- _("Scanning file `%s'.\n"),
- filename);
+ fprintf (stdout, _ ("Scanning file `%s'.\n"), filename);
}
break;
case GNUNET_FS_DIRSCANNER_FILE_IGNORED:
- FPRINTF (stderr,
- _("There was trouble processing file `%s', skipping it.\n"),
- filename);
+ fprintf (stderr,
+ _ ("There was trouble processing file `%s', skipping it.\n"),
+ filename);
break;
case GNUNET_FS_DIRSCANNER_ALL_COUNTED:
if (verbose)
- FPRINTF (stdout,
- "%s",
- _("Preprocessing complete.\n"));
+ fprintf (stdout, "%s", _ ("Preprocessing complete.\n"));
break;
case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED:
if (verbose > 2)
- FPRINTF (stdout,
- _("Extracting meta data from file `%s' complete.\n"),
+ fprintf (stdout,
+ _ ("Extracting meta data from file `%s' complete.\n"),
filename);
break;
case GNUNET_FS_DIRSCANNER_FINISHED:
if (verbose > 1)
- FPRINTF (stdout,
- "%s",
- _("Meta data extraction has finished.\n"));
+ fprintf (stdout, "%s", _ ("Meta data extraction has finished.\n"));
directory_scan_result = GNUNET_FS_directory_scan_get_result (ds);
ds = NULL;
GNUNET_FS_share_tree_trim (directory_scan_result);
directory_trim_complete (directory_scan_result);
break;
case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR:
- FPRINTF (stdout,
- "%s",
- _("Error scanning directory.\n"));
+ fprintf (stdout, "%s", _ ("Error scanning directory.\n"));
ret = 1;
GNUNET_SCHEDULER_shutdown ();
break;
char *ex;
char *emsg;
- if ( (NULL != pseudonym) &&
- (NULL == namespace) )
+ if ((NULL != pseudonym) && (NULL == namespace))
{
- FPRINTF (stderr,
- _("Selected pseudonym `%s' unknown\n"),
- pseudonym);
+ fprintf (stderr, _ ("Selected pseudonym `%s' unknown\n"), pseudonym);
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
emsg = NULL;
if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg)))
{
- FPRINTF (stderr,
- _("Failed to parse URI: %s\n"),
- emsg);
+ fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg);
GNUNET_free (emsg);
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_FS_publish_ksk (ctx,
- topKeywords,
- meta, uri,
+ topKeywords,
+ meta,
+ uri,
&bo,
GNUNET_FS_PUBLISH_OPTION_NONE,
&uri_ksk_continuation,
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex))
ex = NULL;
- if (0 != ACCESS (args0, R_OK))
+ if (0 != access (args0, R_OK))
{
- FPRINTF (stderr,
- _("Failed to access `%s': %s\n"),
- args0,
- STRERROR (errno));
+ fprintf (stderr,
+ _ ("Failed to access `%s': %s\n"),
+ args0,
+ strerror (errno));
GNUNET_free_non_null (ex);
return;
}
ds = GNUNET_FS_directory_scan_start (args0,
- disable_extractor,
- ex,
- &directory_scan_cb, NULL);
+ disable_extractor,
+ ex,
+ &directory_scan_cb,
+ NULL);
if (NULL == ds)
{
- FPRINTF (stderr,
- "%s",
- _("Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n"));
+ fprintf (
+ stderr,
+ "%s",
+ _ (
+ "Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n"));
GNUNET_free_non_null (ex);
return;
}
*/
static void
identity_cb (void *cls,
- struct GNUNET_IDENTITY_Ego *ego,
- void **ctx,
- const char *name)
+ struct GNUNET_IDENTITY_Ego *ego,
+ void **ctx,
+ const char *name)
{
const char *args0 = cls;
if (NULL == name)
return;
if (0 == strcmp (name, pseudonym))
- namespace = ego;
+ namespace = ego;
}
/* check arguments */
if ((NULL != uri_string) && (extract_only))
{
- printf (_("Cannot extract metadata from a URI!\n"));
+ printf (_ ("Cannot extract metadata from a URI!\n"));
ret = -1;
return;
}
if (((NULL == uri_string) || (extract_only)) &&
((NULL == args[0]) || (NULL != args[1])))
{
- printf (_("You must specify one and only one filename for insertion.\n"));
+ printf (_ ("You must specify one and only one filename for insertion.\n"));
ret = -1;
return;
}
if ((NULL != uri_string) && (NULL != args[0]))
{
- printf (_("You must NOT specify an URI and a filename.\n"));
+ printf (_ ("You must NOT specify an URI and a filename.\n"));
ret = -1;
return;
}
{
if (NULL == this_id)
{
- FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"),
- "-t", "-P");
+ fprintf (stderr,
+ _ ("Option `%s' is required when using option `%s'.\n"),
+ "-t",
+ "-P");
ret = -1;
return;
}
}
else
- { /* ordinary insertion checks */
+ { /* ordinary insertion checks */
if (NULL != next_id)
{
- FPRINTF (stderr,
- _("Option `%s' makes no sense without option `%s'.\n"),
- "-N", "-P");
+ fprintf (stderr,
+ _ ("Option `%s' makes no sense without option `%s'.\n"),
+ "-N",
+ "-P");
ret = -1;
return;
}
if (NULL != this_id)
{
- FPRINTF (stderr,
- _("Option `%s' makes no sense without option `%s'.\n"),
- "-t", "-P");
+ fprintf (stderr,
+ _ ("Option `%s' makes no sense without option `%s'.\n"),
+ "-t",
+ "-P");
ret = -1;
return;
}
}
cfg = c;
- ctx =
- GNUNET_FS_start (cfg, "gnunet-publish", &progress_cb, NULL,
- GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ ctx = GNUNET_FS_start (cfg,
+ "gnunet-publish",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
if (NULL == ctx)
{
- FPRINTF (stderr,
- _("Could not initialize `%s' subsystem.\n"),
- "FS");
+ fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
ret = 1;
return;
}
- GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL);
if (NULL != pseudonym)
- identity = GNUNET_IDENTITY_connect (cfg,
- &identity_cb,
- args[0]);
+ identity = GNUNET_IDENTITY_connect (cfg, &identity_cb, args[0]);
else
identity_continuation (args[0]);
}
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_uint ('a',
- "anonymity",
- "LEVEL",
- gettext_noop ("set the desired LEVEL of sender-anonymity"),
- &bo.anonymity_level),
- GNUNET_GETOPT_option_flag ('D',
- "disable-extractor",
- gettext_noop ("do not use libextractor to add keywords or metadata"),
- &disable_extractor),
- GNUNET_GETOPT_option_flag ('E',
- "enable-creation-time",
- gettext_noop ("enable adding the creation time to the "
- "metadata of the uploaded file"),
- &enable_creation_time),
- GNUNET_GETOPT_option_flag ('e',
- "extract",
- gettext_noop ("print list of extracted keywords that would "
- "be used, but do not perform upload"),
- &extract_only),
- GNUNET_FS_GETOPT_KEYWORDS ('k',
- "key",
- "KEYWORD",
- gettext_noop ("add an additional keyword for the top-level "
- "file or directory (this option can be specified multiple times)"),
- &topKeywords),
- GNUNET_FS_GETOPT_METADATA ('m',
- "meta",
- "TYPE:VALUE",
- gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
- &meta),
- GNUNET_GETOPT_option_flag ('n',
- "noindex",
- gettext_noop ("do not index, perform full insertion (stores "
- "entire file in encrypted form in GNUnet database)"),
- &do_insert),
- GNUNET_GETOPT_option_string ('N',
- "next",
- "ID",
- gettext_noop ("specify ID of an updated version to be "
- "published in the future (for namespace insertions only)"),
- &next_id),
- GNUNET_GETOPT_option_uint ('p',
- "priority",
- "PRIORITY",
- gettext_noop ("specify the priority of the content"),
- &bo.content_priority),
- GNUNET_GETOPT_option_string ('P',
- "pseudonym",
- "NAME",
- gettext_noop ("publish the files under the pseudonym "
- "NAME (place file into namespace)"),
- &pseudonym),
- GNUNET_GETOPT_option_uint ('r',
- "replication",
- "LEVEL",
- gettext_noop ("set the desired replication LEVEL"),
- &bo.replication_level),
- GNUNET_GETOPT_option_flag ('s',
- "simulate-only",
- gettext_noop ("only simulate the process but do not do "
- "any actual publishing (useful to compute URIs)"),
- &do_simulate),
- GNUNET_GETOPT_option_string ('t',
- "this",
- "ID",
- gettext_noop ("set the ID of this version of the publication "
- "(for namespace insertions only)"),
- &this_id),
- GNUNET_GETOPT_option_string ('u',
- "uri",
- "URI",
- gettext_noop ("URI to be published (can be used instead of passing a "
- "file to add keywords to the file with the respective URI)"),
- &uri_string),
-
- GNUNET_GETOPT_option_verbose (&verbose),
-
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_uint ('a',
+ "anonymity",
+ "LEVEL",
+ gettext_noop (
+ "set the desired LEVEL of sender-anonymity"),
+ &bo.anonymity_level),
+ GNUNET_GETOPT_option_flag (
+ 'D',
+ "disable-extractor",
+ gettext_noop ("do not use libextractor to add keywords or metadata"),
+ &disable_extractor),
+ GNUNET_GETOPT_option_flag ('E',
+ "enable-creation-time",
+ gettext_noop (
+ "enable adding the creation time to the "
+ "metadata of the uploaded file"),
+ &enable_creation_time),
+ GNUNET_GETOPT_option_flag ('e',
+ "extract",
+ gettext_noop (
+ "print list of extracted keywords that would "
+ "be used, but do not perform upload"),
+ &extract_only),
+ GNUNET_FS_GETOPT_KEYWORDS (
+ 'k',
+ "key",
+ "KEYWORD",
+ gettext_noop (
+ "add an additional keyword for the top-level "
+ "file or directory (this option can be specified multiple times)"),
+ &topKeywords),
+ GNUNET_FS_GETOPT_METADATA (
+ 'm',
+ "meta",
+ "TYPE:VALUE",
+ gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
+ &meta),
+ GNUNET_GETOPT_option_flag (
+ 'n',
+ "noindex",
+ gettext_noop ("do not index, perform full insertion (stores "
+ "entire file in encrypted form in GNUnet database)"),
+ &do_insert),
+ GNUNET_GETOPT_option_string (
+ 'N',
+ "next",
+ "ID",
+ gettext_noop ("specify ID of an updated version to be "
+ "published in the future (for namespace insertions only)"),
+ &next_id),
+ GNUNET_GETOPT_option_uint ('p',
+ "priority",
+ "PRIORITY",
+ gettext_noop (
+ "specify the priority of the content"),
+ &bo.content_priority),
+ GNUNET_GETOPT_option_string ('P',
+ "pseudonym",
+ "NAME",
+ gettext_noop (
+ "publish the files under the pseudonym "
+ "NAME (place file into namespace)"),
+ &pseudonym),
+ GNUNET_GETOPT_option_uint ('r',
+ "replication",
+ "LEVEL",
+ gettext_noop (
+ "set the desired replication LEVEL"),
+ &bo.replication_level),
+ GNUNET_GETOPT_option_flag ('s',
+ "simulate-only",
+ gettext_noop (
+ "only simulate the process but do not do "
+ "any actual publishing (useful to compute URIs)"),
+ &do_simulate),
+ GNUNET_GETOPT_option_string ('t',
+ "this",
+ "ID",
+ gettext_noop (
+ "set the ID of this version of the publication "
+ "(for namespace insertions only)"),
+ &this_id),
+ GNUNET_GETOPT_option_string (
+ 'u',
+ "uri",
+ "URI",
+ gettext_noop (
+ "URI to be published (can be used instead of passing a "
+ "file to add keywords to the file with the respective URI)"),
+ &uri_string),
+
+ GNUNET_GETOPT_option_verbose (&verbose),
+
+ GNUNET_GETOPT_OPTION_END};
bo.expiration_time =
- GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2);
+ GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2);
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-publish [OPTIONS] FILENAME",
- gettext_noop
- ("Publish a file or directory on GNUnet"),
- options,
- &run,
- NULL)) ? ret : 1;
- GNUNET_free ((void*) argv);
+ ret =
+ (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-publish [OPTIONS] FILENAME",
+ gettext_noop ("Publish a file or directory on GNUnet"),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
#if HAVE_LIBEXTRACTOR
printf ("\t%20s: %s\n",
dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
- EXTRACTOR_metatype_to_string (type)), data);
-#else
- printf ("\t%20d: %s\n",
- type,
+ EXTRACTOR_metatype_to_string (type)),
data);
+#else
+ printf ("\t%20d: %s\n", type, data);
#endif
return 0;
}
GNUNET_free (output_filename);
return;
}
- if (dsize !=
- GNUNET_DISK_fn_write (output_filename, ddata, dsize,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE))
+ if (dsize != GNUNET_DISK_fn_write (output_filename,
+ ddata,
+ dsize,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))
{
- FPRINTF (stderr,
- _("Failed to write directory with search results to `%s'\n"),
+ fprintf (stderr,
+ _ ("Failed to write directory with search results to `%s'\n"),
output_filename);
}
GNUNET_free_non_null (ddata);
NULL);
uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri);
printf ("#%u:\n", ++cnt);
- filename =
- GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.
- specifics.result.meta,
- EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
- is_directory =
- GNUNET_FS_meta_data_test_for_directory (info->value.search.
- specifics.result.meta);
+ filename = GNUNET_CONTAINER_meta_data_get_by_type (
+ info->value.search.specifics.result.meta,
+ EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+ is_directory = GNUNET_FS_meta_data_test_for_directory (
+ info->value.search.specifics.result.meta);
if (NULL != filename)
{
- while ( (filename[0] != '\0') &&
- ('/' == filename[strlen(filename)-1]) )
- filename[strlen(filename)-1] = '\0';
+ while ((filename[0] != '\0') && ('/' == filename[strlen (filename) - 1]))
+ filename[strlen (filename) - 1] = '\0';
GNUNET_DISK_filename_canonicalize (filename);
if (GNUNET_YES == is_directory)
- printf ("gnunet-download -o \"%s%s\" -R %s\n", filename, GNUNET_FS_DIRECTORY_EXT, uri);
+ printf ("gnunet-download -o \"%s%s\" -R %s\n",
+ filename,
+ GNUNET_FS_DIRECTORY_EXT,
+ uri);
else
printf ("gnunet-download -o \"%s\" %s\n", filename, uri);
}
else if (GNUNET_YES == is_directory)
- printf ("gnunet-download -o \"collection%s\" -R %s\n", GNUNET_FS_DIRECTORY_EXT, uri);
+ printf ("gnunet-download -o \"collection%s\" -R %s\n",
+ GNUNET_FS_DIRECTORY_EXT,
+ uri);
else
printf ("gnunet-download %s\n", uri);
if (verbose)
- GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.
- result.meta, &item_printer, NULL);
+ GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result
+ .meta,
+ &item_printer,
+ NULL);
printf ("\n");
fflush (stdout);
GNUNET_free_non_null (filename);
/* ignore */
break;
case GNUNET_FS_STATUS_SEARCH_ERROR:
- FPRINTF (stderr, _("Error searching: %s.\n"),
+ fprintf (stderr,
+ _ ("Error searching: %s.\n"),
info->value.search.specifics.error.message);
GNUNET_SCHEDULER_shutdown ();
break;
GNUNET_SCHEDULER_add_now (&clean_task, NULL);
break;
default:
- FPRINTF (stderr, _("Unexpected status: %d\n"), info->status);
+ fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
break;
}
return NULL;
* @param c configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_FS_Uri *uri;
uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args);
if (NULL == uri)
{
- FPRINTF (stderr, "%s", _("Could not create keyword URI from arguments.\n"));
+ fprintf (stderr,
+ "%s",
+ _ ("Could not create keyword URI from arguments.\n"));
ret = 1;
return;
}
cfg = c;
- ctx =
- GNUNET_FS_start (cfg, "gnunet-search", &progress_cb, NULL,
- GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ ctx = GNUNET_FS_start (cfg,
+ "gnunet-search",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
if (NULL == ctx)
{
- FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
+ fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
GNUNET_FS_uri_destroy (uri);
ret = 1;
return;
GNUNET_FS_uri_destroy (uri);
if (NULL == sc)
{
- FPRINTF (stderr, "%s", _("Could not start searching.\n"));
+ fprintf (stderr, "%s", _ ("Could not start searching.\n"));
GNUNET_FS_stop (ctx);
ret = 1;
return;
}
if (0 != timeout.rel_value_us)
- tt = GNUNET_SCHEDULER_add_delayed (timeout,
- &timeout_task,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_uint ('a',
- "anonymity",
- "LEVEL",
- gettext_noop ("set the desired LEVEL of receiver-anonymity"),
- &anonymity),
- GNUNET_GETOPT_option_flag ('n',
- "no-network",
- gettext_noop ("only search the local peer (no P2P network search)"),
- &local_only),
- GNUNET_GETOPT_option_string ('o',
- "output",
- "PREFIX",
- gettext_noop ("write search results to file starting with PREFIX"),
- &output_filename),
- GNUNET_GETOPT_option_relative_time ('t',
- "timeout",
- "DELAY",
- gettext_noop ("automatically terminate search after DELAY"),
- &timeout),
- GNUNET_GETOPT_option_verbose (&verbose),
- GNUNET_GETOPT_option_uint ('N',
- "results",
- "VALUE",
- gettext_noop ("automatically terminate search "
- "after VALUE results are found"),
- &results_limit),
- GNUNET_GETOPT_OPTION_END
- };
-
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_uint ('a',
+ "anonymity",
+ "LEVEL",
+ gettext_noop (
+ "set the desired LEVEL of receiver-anonymity"),
+ &anonymity),
+ GNUNET_GETOPT_option_flag (
+ 'n',
+ "no-network",
+ gettext_noop ("only search the local peer (no P2P network search)"),
+ &local_only),
+ GNUNET_GETOPT_option_string (
+ 'o',
+ "output",
+ "PREFIX",
+ gettext_noop ("write search results to file starting with PREFIX"),
+ &output_filename),
+ GNUNET_GETOPT_option_relative_time (
+ 't',
+ "timeout",
+ "DELAY",
+ gettext_noop ("automatically terminate search after DELAY"),
+ &timeout),
+ GNUNET_GETOPT_option_verbose (&verbose),
+ GNUNET_GETOPT_option_uint ('N',
+ "results",
+ "VALUE",
+ gettext_noop ("automatically terminate search "
+ "after VALUE results are found"),
+ &results_limit),
+ GNUNET_GETOPT_OPTION_END};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-search [OPTIONS] KEYWORD",
- gettext_noop
- ("Search GNUnet for files that were published on GNUnet"),
- options, &run, NULL)) ? ret : 1;
- GNUNET_free ((void*) argv);
+ ret =
+ (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-search [OPTIONS] KEYWORD",
+ gettext_noop (
+ "Search GNUnet for files that were published on GNUnet"),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
* Hash of the contents of the file.
*/
struct GNUNET_HashCode file_id;
-
};
struct IndexInfo *pos;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "FS",
- "INDEXDB",
- &fn))
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "fs",
+ "fs",
"INDEXDB");
return;
}
if (NULL == wh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Could not open `%s'.\n"),
+ _ ("Could not open `%s'.\n"),
fn);
GNUNET_free (fn);
return;
}
for (pos = indexed_files_head; NULL != pos; pos = pos->next)
- if ((GNUNET_OK !=
- GNUNET_BIO_write (wh,
- &pos->file_id,
- sizeof (struct GNUNET_HashCode))) ||
- (GNUNET_OK !=
- GNUNET_BIO_write_string (wh,
- pos->filename)))
+ if ((GNUNET_OK != GNUNET_BIO_write (wh,
+ &pos->file_id,
+ sizeof (struct GNUNET_HashCode))) ||
+ (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename)))
break;
if (GNUNET_OK != GNUNET_BIO_write_close (wh))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Error writing `%s'.\n"),
+ _ ("Error writing `%s'.\n"),
fn);
GNUNET_free (fn);
return;
char *emsg;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "FS",
- "INDEXDB",
- &fn))
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "fs",
+ "fs",
"INDEXDB");
return;
}
if (NULL == rh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- _("Could not open `%s'.\n"),
+ _ ("Could not open `%s'.\n"),
fn);
GNUNET_free (fn);
return;
}
- while ( (GNUNET_OK ==
- GNUNET_BIO_read (rh,
- "Hash of indexed file",
- &hc,
- sizeof (struct GNUNET_HashCode))) &&
- (GNUNET_OK ==
- GNUNET_BIO_read_string (rh,
- "Name of indexed file",
- &fname,
- 1024 * 16)) &&
- (fname != NULL) )
+ while (
+ (GNUNET_OK == GNUNET_BIO_read (rh,
+ "Hash of indexed file",
+ &hc,
+ sizeof (struct GNUNET_HashCode))) &&
+ (GNUNET_OK ==
+ GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) &&
+ (fname != NULL))
{
slen = strlen (fname) + 1;
pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
pos->file_id = hc;
pos->filename = (const char *) &pos[1];
GNUNET_memcpy (&pos[1], fname, slen);
- if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_put (ifm, &pos->file_id, pos,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
+ ifm,
+ &pos->file_id,
+ pos,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_free (pos);
}
else
{
- GNUNET_CONTAINER_DLL_insert (indexed_files_head,
- indexed_files_tail,
- pos);
+ GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos);
}
GNUNET_free (fname);
}
* @param msg error message
*/
static void
-remove_cont (void *cls, int success,
- struct GNUNET_TIME_Absolute min_expiration,
- const char *msg)
+remove_cont (void *cls,
+ int success,
+ struct GNUNET_TIME_Absolute min_expiration,
+ const char *msg)
{
if (GNUNET_OK != success)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to delete bogus block: %s\n"), msg);
+ _ ("Failed to delete bogus block: %s\n"),
+ msg);
}
* @return GNUNET_OK on success
*/
int
-GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key,
+GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key,
uint32_t size,
const void *data,
enum GNUNET_BLOCK_Type type,
if (size != sizeof (struct OnDemandBlock))
{
GNUNET_break (0);
- GNUNET_DATASTORE_remove (dsh,
- key,
- size,
- data,
- -1,
- -1,
- &remove_cont, NULL);
+ GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
return GNUNET_SYSERR;
}
odb = (const struct OnDemandBlock *) data;
off = GNUNET_ntohll (odb->offset);
- ii = GNUNET_CONTAINER_multihashmap_get (ifm,
- &odb->file_id);
+ ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id);
if (NULL == ii)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
fn = ii->filename;
- if ((NULL == fn) || (0 != ACCESS (fn, R_OK)))
+ if ((NULL == fn) || (0 != access (fn, R_OK)))
{
- GNUNET_STATISTICS_update (GSF_stats,
- gettext_noop ("# index blocks removed: original file inaccessible"),
- 1,
- GNUNET_YES);
- GNUNET_DATASTORE_remove (dsh,
- key,
- size,
- data,
- -1,
- -1,
- &remove_cont,
- NULL);
+ GNUNET_STATISTICS_update (
+ GSF_stats,
+ gettext_noop ("# index blocks removed: original file inaccessible"),
+ 1,
+ GNUNET_YES);
+ GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
return GNUNET_SYSERR;
}
- if ( (NULL ==
- (fh =
- GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE))) ||
- (off != GNUNET_DISK_file_seek (fh,
- off,
- GNUNET_DISK_SEEK_SET)) ||
- (-1 == (nsize = GNUNET_DISK_file_read (fh,
- ndata,
- sizeof (ndata)))) )
+ if ((NULL == (fh = GNUNET_DISK_file_open (fn,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE))) ||
+ (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) ||
+ (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata)))))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not access indexed file `%s' (%s) at offset %llu: %s\n"),
+ _ (
+ "Could not access indexed file `%s' (%s) at offset %llu: %s\n"),
GNUNET_h2s (&odb->file_id),
fn,
(unsigned long long) off,
- (fn == NULL) ? _("not indexed") : STRERROR (errno));
+ (fn == NULL) ? _ ("not indexed") : strerror (errno));
if (fh != NULL)
GNUNET_DISK_file_close (fh);
- GNUNET_DATASTORE_remove (dsh,
- key,
- size,
- data,
- -1,
- -1,
- &remove_cont,
- NULL);
+ GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
return GNUNET_SYSERR;
}
GNUNET_DISK_file_close (fh);
- GNUNET_CRYPTO_hash (ndata,
- nsize,
- &nkey);
- GNUNET_CRYPTO_hash_to_aes_key (&nkey,
- &skey,
- &iv);
- GNUNET_CRYPTO_symmetric_encrypt (ndata,
- nsize,
- &skey,
- &iv,
- edata);
- GNUNET_CRYPTO_hash (edata,
- nsize,
- &query);
- if (0 != memcmp (&query,
- key,
- sizeof (struct GNUNET_HashCode)))
+ GNUNET_CRYPTO_hash (ndata, nsize, &nkey);
+ GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv);
+ GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata);
+ GNUNET_CRYPTO_hash (edata, nsize, &query);
+ if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Indexed file `%s' changed at offset %llu\n"),
+ _ ("Indexed file `%s' changed at offset %llu\n"),
fn,
(unsigned long long) off);
- GNUNET_DATASTORE_remove (dsh,
- key,
- size,
- data,
- -1,
- -1,
- &remove_cont,
- NULL);
+ GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL);
return GNUNET_SYSERR;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
{
fn = pos->filename;
slen = strlen (fn) + 1;
- if (slen + sizeof (struct IndexInfoMessage) >=
- GNUNET_MAX_MESSAGE_SIZE)
+ if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
break;
}
- env = GNUNET_MQ_msg_extra (iim,
- slen,
- GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
+ env =
+ GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
iim->reserved = 0;
iim->file_id = pos->file_id;
- GNUNET_memcpy (&iim[1],
- fn,
- slen);
- GNUNET_MQ_send (mq,
- env);
+ GNUNET_memcpy (&iim[1], fn, slen);
+ GNUNET_MQ_send (mq, env);
}
- env = GNUNET_MQ_msg (iem,
- GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
- GNUNET_MQ_send (mq,
- env);
+ env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
+ GNUNET_MQ_send (mq, env);
}
for (pos = indexed_files_head; NULL != pos; pos = pos->next)
{
- if (0 == memcmp (&pos->file_id,
- fid,
- sizeof (struct GNUNET_HashCode)))
+ if (0 == memcmp (&pos->file_id, fid, sizeof (struct GNUNET_HashCode)))
{
- GNUNET_CONTAINER_DLL_remove (indexed_files_head,
- indexed_files_tail,
- pos);
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (ifm,
- &pos->file_id,
- pos));
+ GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos);
+ GNUNET_break (
+ GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos));
GNUNET_free (pos);
write_index_list ();
return GNUNET_YES;
struct IndexInfo *ii;
size_t slen;
- ii = GNUNET_CONTAINER_multihashmap_get (ifm,
- file_id);
+ ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id);
if (NULL != ii)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
- filename,
- ii->filename);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ (
+ "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"),
+ filename,
+ ii->filename);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
ii->file_id = *file_id;
ii->filename = (const char *) &ii[1];
- GNUNET_memcpy (&ii[1],
- filename,
- slen);
- GNUNET_CONTAINER_DLL_insert (indexed_files_head,
- indexed_files_tail,
- ii);
+ GNUNET_memcpy (&ii[1], filename, slen);
+ GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, ii);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (ifm,
- &ii->file_id,
- ii,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap_put (
+ ifm,
+ &ii->file_id,
+ ii,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
write_index_list ();
}
while (NULL != (pos = indexed_files_head))
{
- GNUNET_CONTAINER_DLL_remove (indexed_files_head,
- indexed_files_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos);
if (pos->fhc != NULL)
GNUNET_CRYPTO_hash_file_cancel (pos->fhc);
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (ifm,
- &pos->file_id,
- pos));
+ GNUNET_break (
+ GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos));
GNUNET_free (pos);
}
GNUNET_CONTAINER_multihashmap_destroy (ifm);
{
cfg = c;
dsh = d;
- ifm = GNUNET_CONTAINER_multihashmap_create (128,
- GNUNET_YES);
+ ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
read_index_list ();
return GNUNET_OK;
}
case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
if (verbose)
{
- s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, GNUNET_YES);
- FPRINTF (stdout, _("Unindexing at %llu/%llu (%s remaining)\n"),
+ s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta,
+ GNUNET_YES);
+ fprintf (stdout,
+ _ ("Unindexing at %llu/%llu (%s remaining)\n"),
(unsigned long long) info->value.unindex.completed,
- (unsigned long long) info->value.unindex.size, s);
+ (unsigned long long) info->value.unindex.size,
+ s);
}
break;
case GNUNET_FS_STATUS_UNINDEX_ERROR:
- FPRINTF (stderr, _("Error unindexing: %s.\n"),
+ fprintf (stderr,
+ _ ("Error unindexing: %s.\n"),
info->value.unindex.specifics.error.message);
GNUNET_SCHEDULER_shutdown ();
break;
case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
- FPRINTF (stdout, "%s", _("Unindexing done.\n"));
+ fprintf (stdout, "%s", _ ("Unindexing done.\n"));
GNUNET_SCHEDULER_shutdown ();
break;
case GNUNET_FS_STATUS_UNINDEX_STOPPED:
GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
break;
default:
- FPRINTF (stderr, _("Unexpected status: %d\n"), info->status);
+ fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
break;
}
return NULL;
* @param c configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
/* check arguments */
if ((args[0] == NULL) || (args[1] != NULL))
{
- printf (_("You must specify one and only one filename for unindexing.\n"));
+ printf (_ ("You must specify one and only one filename for unindexing.\n"));
ret = -1;
return;
}
cfg = c;
- ctx =
- GNUNET_FS_start (cfg, "gnunet-unindex", &progress_cb, NULL,
- GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ ctx = GNUNET_FS_start (cfg,
+ "gnunet-unindex",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
if (NULL == ctx)
{
- FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
+ fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
ret = 1;
return;
}
uc = GNUNET_FS_unindex_start (ctx, args[0], NULL);
if (NULL == uc)
{
- FPRINTF (stderr, "%s", _("Could not start unindex operation.\n"));
+ fprintf (stderr, "%s", _ ("Could not start unindex operation.\n"));
GNUNET_FS_stop (ctx);
return;
}
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
GNUNET_GETOPT_option_verbose (&verbose),
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-unindex [OPTIONS] FILENAME",
- gettext_noop
- ("Unindex a file that was previously indexed with gnunet-publish."),
- options, &run, NULL)) ? ret : 1;
- GNUNET_free ((void*) argv);
+ GNUNET_PROGRAM_run (
+ argc,
+ argv,
+ "gnunet-unindex [OPTIONS] FILENAME",
+ gettext_noop (
+ "Unindex a file that was previously indexed with gnunet-publish."),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
{
struct StatMaster *sm = cls;
- FPRINTF (stderr,
+ fprintf (stderr,
"Peer %2u: %12s/%50s = %12llu\n",
sm->daemon,
subsystem,
fancy =
GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
1000000LL / del.rel_value_us);
- FPRINTF (stdout,
+ fprintf (stdout,
"Download speed was %s/s\n",
fancy);
GNUNET_free (fancy);
{
struct StatMaster *sm = cls;
- FPRINTF (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
+ fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
name, (unsigned long long) value);
return GNUNET_OK;
}
fancy =
GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
1000000LL / del.rel_value_us);
- FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
+ fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
GNUNET_free (fancy);
if (NUM_DAEMONS != ++download_counter)
return; /* more downloads to come */
GNUNET_FSUI_stop (ctx);
if (filename != NULL)
{
- UNLINK (filename);
+ unlink (filename);
GNUNET_free (filename);
}
if (download != NULL)
}
filename = makeName (43);
/* TODO: verify file 'filename(42)' == file 'filename(43)' */
- UNLINK (filename);
+ unlink (filename);
GNUNET_free (filename);
#if START_DAEMON
return;
}
}
- FPRINTF (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
+ fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__);
}
static int
s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
(start),
GNUNET_YES);
- FPRINTF (stdout,
+ fprintf (stdout,
"Creating directory with %u entires and total size %llu took %s\n",
i, (unsigned long long) dlen, s);
if (i < 100)
progress.offset);
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
GNUNET_SCHEDULER_shutdown ();
break;
case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
- FPRINTF (stderr, "Error downloading file: %s\n",
+ fprintf (stderr, "Error downloading file: %s\n",
event->value.download.specifics.error.message);
GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
GNUNET_SCHEDULER_shutdown ();
return 1;
if (NULL != fn1)
{
- UNLINK (fn1);
+ unlink (fn1);
GNUNET_free (fn1);
}
return err;
progress.offset);
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
break;
case GNUNET_FS_STATUS_DOWNLOAD_ERROR:
- FPRINTF (stderr, "Error downloading file: %s\n",
+ fprintf (stderr, "Error downloading file: %s\n",
event->value.download.specifics.error.message);
GNUNET_SCHEDULER_add_now (&abort_download_task, NULL);
break;
GNUNET_log_setup ("test_fs_getopt",
"WARNING",
NULL);
- FPRINTF (stderr, "%s", "WARNING: testcase not yet written.\n");
+ fprintf (stderr, "%s", "WARNING: testcase not yet written.\n");
return 0; /* testcase passed */
}
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
ret = event->value.publish.cctx;
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
err = 1;
if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx))
do_timeout (void *cls)
{
err = 1;
- FPRINTF (stderr, "%s", "Operation timed out\n");
+ fprintf (stderr, "%s", "Operation timed out\n");
kill_task = NULL;
abort_sks_search_task (NULL);
abort_ksk_search_task (NULL);
if (!GNUNET_FS_uri_test_equal
(sks_expect_uri, event->value.search.specifics.result.uri))
{
- FPRINTF (stderr, "%s", "Wrong result for sks search!\n");
+ fprintf (stderr, "%s", "Wrong result for sks search!\n");
err = 1;
}
/* give system 1ms to initiate update search! */
if (!GNUNET_FS_uri_test_equal
(ksk_expect_uri, event->value.search.specifics.result.uri))
{
- FPRINTF (stderr, "%s", "Wrong result for ksk search!\n");
+ fprintf (stderr, "%s", "Wrong result for ksk search!\n");
err = 1;
}
GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL);
}
else
{
- FPRINTF (stderr, "%s", "Unexpected search result received!\n");
+ fprintf (stderr, "%s", "Unexpected search result received!\n");
GNUNET_break (0);
}
break;
case GNUNET_FS_STATUS_SEARCH_ERROR:
- FPRINTF (stderr, "Error searching file: %s\n",
+ fprintf (stderr, "Error searching file: %s\n",
event->value.search.specifics.error.message);
if (sks_search == event->value.search.sc)
GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL);
case GNUNET_FS_STATUS_SEARCH_STOPPED:
return NULL;
default:
- FPRINTF (stderr, "Unexpected event: %d\n", event->status);
+ fprintf (stderr, "Unexpected event: %d\n", event->status);
break;
}
return event->value.search.cctx;
if (NULL != emsg)
{
- FPRINTF (stderr, "Error publishing: %s\n", emsg);
+ fprintf (stderr, "Error publishing: %s\n", emsg);
err = 1;
GNUNET_FS_stop (fs);
return;
sks_uri = GNUNET_FS_uri_parse (sbuf, &msg);
if (NULL == sks_uri)
{
- FPRINTF (stderr, "failed to parse URI `%s': %s\n", sbuf, msg);
+ fprintf (stderr, "failed to parse URI `%s': %s\n", sbuf, msg);
err = 1;
GNUNET_FS_stop (fs);
GNUNET_free_non_null (msg);
if (NULL != emsg)
{
- FPRINTF (stderr, "Error publishing: %s\n", emsg);
+ fprintf (stderr, "Error publishing: %s\n", emsg);
err = 1;
GNUNET_FS_stop (fs);
return;
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
ret = event->value.publish.cctx;
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
err = 1;
if (0 == strcmp ("publish-context-dir", event->value.publish.cctx))
{
- FPRINTF (stderr, "Scheduling abort task for error on `%s'\n",
+ fprintf (stderr, "Scheduling abort task for error on `%s'\n",
(const char *) event->value.publish.cctx);
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
}
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
ret = event->value.publish.cctx;
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
err = 1;
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
break;
case GNUNET_FS_STATUS_SEARCH_ERROR:
- FPRINTF (stderr, "Error searching file: %s\n",
+ fprintf (stderr, "Error searching file: %s\n",
event->value.search.specifics.error.message);
GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
break;
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
break;
default:
- FPRINTF (stderr, "Unexpected event: %d\n", event->status);
+ fprintf (stderr, "Unexpected event: %d\n", event->status);
break;
}
return NULL;
GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
break;
case GNUNET_FS_STATUS_SEARCH_ERROR:
- FPRINTF (stderr, "Error searching file: %s\n",
+ fprintf (stderr, "Error searching file: %s\n",
event->value.search.specifics.error.message);
GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
break;
search = NULL;
break;
default:
- FPRINTF (stderr, "Unexpected event: %d\n", event->status);
+ fprintf (stderr, "Unexpected event: %d\n", event->status);
break;
}
return NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n");
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
break;
case GNUNET_FS_STATUS_SEARCH_ERROR:
- FPRINTF (stderr, "Error searching file: %s\n",
+ fprintf (stderr, "Error searching file: %s\n",
event->value.search.specifics.error.message);
GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
break;
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
break;
default:
- FPRINTF (stderr,
+ fprintf (stderr,
"Unexpected event: %d\n",
event->status);
break;
GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
break;
case GNUNET_FS_STATUS_SEARCH_ERROR:
- FPRINTF (stderr, "Error searching file: %s\n",
+ fprintf (stderr, "Error searching file: %s\n",
event->value.search.specifics.error.message);
GNUNET_SCHEDULER_add_now (&abort_search_task, NULL);
break;
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
break;
default:
- FPRINTF (stderr, "Unexpected event: %d\n", event->status);
+ fprintf (stderr, "Unexpected event: %d\n", event->status);
break;
}
return NULL;
progress.offset);
break;
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
break;
case GNUNET_FS_STATUS_UNINDEX_ERROR:
- FPRINTF (stderr, "Error unindexing file: %s\n",
+ fprintf (stderr, "Error unindexing file: %s\n",
event->value.unindex.specifics.error.message);
GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL);
break;
unindex = event->value.unindex.uc;
return "unindex";
case GNUNET_FS_STATUS_PUBLISH_ERROR:
- FPRINTF (stderr, "Error publishing file: %s\n",
+ fprintf (stderr, "Error publishing file: %s\n",
event->value.publish.specifics.error.message);
GNUNET_break (0);
GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
failureCount += testLocation ();
for (i = 0; i < 255; i++)
{
- /* FPRINTF (stderr, "%s", "."); */
+ /* fprintf (stderr, "%s", "."); */
failureCount += testNamespace (i);
failureCount += testFile (i);
}
- /* FPRINTF (stderr, "%s", "\n"); */
+ /* fprintf (stderr, "%s", "\n"); */
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri");
if (failureCount != 0)
return 1;
fancy =
GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
1000000LL / del.rel_value_us);
- FPRINTF (stdout,
+ fprintf (stdout,
"Download speed was %s/s\n",
fancy);
GNUNET_free (fancy);
fancy =
GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
1000000LL / del.rel_value_us);
- FPRINTF (stdout,
+ fprintf (stdout,
"Download speed was %s/s\n",
fancy);
GNUNET_free (fancy);
GNUNET_BLOCK_context_destroy (ctx);
GNUNET_CONFIGURATION_destroy (cfg);
if (ret != 0)
- FPRINTF (stderr, "Tests failed: %d\n", ret);
+ fprintf (stderr, "Tests failed: %d\n", ret);
return ret;
}
return MHD_NO;
}
GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex");
- f = FOPEN (deffile, "w");
+ f = fopen (deffile, "w");
if (NULL == f)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", deffile);
MHD_GET_ARGUMENT_KIND,
map[i].formname);
if (NULL != val)
- FPRINTF (f, "\\def\\%s{%s}\n", map[i].texname, val);
+ fprintf (f, "\\def\\%s{%s}\n", map[i].texname, val);
else
- FPRINTF (f, "\\def\\%s{}\n", map[i].texname);
+ fprintf (f, "\\def\\%s{}\n", map[i].texname);
}
if (NULL != gpg_fp)
{
slen = strlen (gpg_fp);
gpg1 = GNUNET_strndup (gpg_fp, slen / 2);
gpg2 = GNUNET_strdup (&gpg_fp[slen / 2]);
- FPRINTF (f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2);
+ fprintf (f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2);
GNUNET_free (gpg2);
GNUNET_free (gpg1);
}
- FPRINTF (f,
+ fprintf (f,
"\\def\\gns{%s/%s}\n",
gnskey,
(NULL == gns_nick) ? "" : gns_nick);
- FCLOSE (f);
+ fclose (f);
GNUNET_asprintf (
&p,
"cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null",
--- /dev/null
+# This template file specifies that the certificate is a certificate
+# authority that will be used to sign other certificates, and
+# certificate revocations. Set additional properties (e.g. a CRL URI)
+# as appropriate.
+
+# Certificate authority template
+organization = "Example"
+cn = "Your CA name here"
+expiration_days = 3650
+
+# This CA can not issue subsidiary CAs
+path_len = 0
+
+# Is a CA
+ca
+
+# Signs certificates and certificate revocation lists
+cert_signing_key
+crl_signing_key
+
+# Name constraints (recommended); new in GnuTLS 3.3.x
+# Setting this will allow this CA to only issue
+# certificates for this domain
+nc_permit_dns = "example.com"
+#nc_exclude_dns = "test.example.com"
return GNUNET_strndup (data, data_size);
case GNUNET_GNSRECORD_TYPE_LEHO:
return GNUNET_strndup (data, data_size);
- case GNUNET_GNSRECORD_TYPE_GNS2DNS:
+ case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
+ char *ns;
+ char *ip;
+ size_t off;
+ char *nstr;
+
+ off = 0;
+ ns = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
+ ip = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
+ if ((NULL == ns) || (NULL == ip) || (off != data_size))
{
- char *ns;
- char *ip;
- size_t off;
- char *nstr;
-
- off = 0;
- ns = GNUNET_DNSPARSER_parse_name (data,
- data_size,
- &off);
- ip = GNUNET_DNSPARSER_parse_name (data,
- data_size,
- &off);
- if ( (NULL == ns) ||
- (NULL == ip) ||
- (off != data_size) )
- {
- GNUNET_break_op (0);
- GNUNET_free_non_null (ns);
- GNUNET_free_non_null (ip);
- return NULL;
- }
- GNUNET_asprintf (&nstr,
- "%s@%s",
- ns,
- ip);
+ GNUNET_break_op (0);
GNUNET_free_non_null (ns);
GNUNET_free_non_null (ip);
- return nstr;
- }
- case GNUNET_GNSRECORD_TYPE_VPN:
- {
- struct GNUNET_TUN_GnsVpnRecord vpn;
- char* vpn_str;
-
- cdata = data;
- if ( (data_size <= sizeof (vpn)) ||
- ('\0' != cdata[data_size - 1]) )
- return NULL; /* malformed */
- /* need to memcpy for alignment */
- GNUNET_memcpy (&vpn,
- data,
- sizeof (vpn));
- GNUNET_asprintf (&vpn_str,
- "%u %s %s",
- (unsigned int) ntohs (vpn.proto),
- (const char*) GNUNET_i2s_full (&vpn.peer),
- (const char*) &cdata[sizeof (vpn)]);
- return vpn_str;
- }
- case GNUNET_GNSRECORD_TYPE_BOX:
- {
- struct GNUNET_GNSRECORD_BoxRecord box;
- uint32_t rt;
- char *box_str;
- char *ival;
-
- cdata = data;
- if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord))
- return NULL; /* malformed */
- GNUNET_memcpy (&box,
- data,
- sizeof (box));
- rt = ntohl (box.record_type);
- ival = GNUNET_GNSRECORD_value_to_string (rt,
- &cdata[sizeof (box)],
- data_size - sizeof (box));
- if (NULL == ival)
- return NULL; /* malformed */
- GNUNET_asprintf (&box_str,
- "%u %u %u %s",
- (unsigned int) ntohs (box.protocol),
- (unsigned int) ntohs (box.service),
- (unsigned int) rt,
- ival);
- GNUNET_free (ival);
- return box_str;
+ return NULL;
}
+ GNUNET_asprintf (&nstr, "%s@%s", ns, ip);
+ GNUNET_free_non_null (ns);
+ GNUNET_free_non_null (ip);
+ return nstr;
+ }
+ case GNUNET_GNSRECORD_TYPE_VPN: {
+ struct GNUNET_TUN_GnsVpnRecord vpn;
+ char *vpn_str;
+
+ cdata = data;
+ if ((data_size <= sizeof (vpn)) || ('\0' != cdata[data_size - 1]))
+ return NULL; /* malformed */
+ /* need to memcpy for alignment */
+ GNUNET_memcpy (&vpn, data, sizeof (vpn));
+ GNUNET_asprintf (&vpn_str,
+ "%u %s %s",
+ (unsigned int) ntohs (vpn.proto),
+ (const char *) GNUNET_i2s_full (&vpn.peer),
+ (const char *) &cdata[sizeof (vpn)]);
+ return vpn_str;
+ }
+ case GNUNET_GNSRECORD_TYPE_BOX: {
+ struct GNUNET_GNSRECORD_BoxRecord box;
+ uint32_t rt;
+ char *box_str;
+ char *ival;
+
+ cdata = data;
+ if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord))
+ return NULL; /* malformed */
+ GNUNET_memcpy (&box, data, sizeof (box));
+ rt = ntohl (box.record_type);
+ ival = GNUNET_GNSRECORD_value_to_string (rt,
+ &cdata[sizeof (box)],
+ data_size - sizeof (box));
+ if (NULL == ival)
+ return NULL; /* malformed */
+ GNUNET_asprintf (&box_str,
+ "%u %u %u %s",
+ (unsigned int) ntohs (box.protocol),
+ (unsigned int) ntohs (box.service),
+ (unsigned int) rt,
+ ival);
+ GNUNET_free (ival);
+ return box_str;
+ }
default:
return NULL;
}
switch (type)
{
- case GNUNET_GNSRECORD_TYPE_PKEY:
- if (GNUNET_OK !=
- GNUNET_CRYPTO_ecdsa_public_key_from_string (s,
- strlen (s),
- &pkey))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse PKEY record `%s'\n"),
- s);
- return GNUNET_SYSERR;
- }
- *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
- GNUNET_memcpy (*data,
- &pkey,
- sizeof (pkey));
- *data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
- return GNUNET_OK;
-
- case GNUNET_GNSRECORD_TYPE_NICK:
- *data = GNUNET_strdup (s);
- *data_size = strlen (s);
- return GNUNET_OK;
- case GNUNET_GNSRECORD_TYPE_LEHO:
- *data = GNUNET_strdup (s);
- *data_size = strlen (s);
- return GNUNET_OK;
- case GNUNET_GNSRECORD_TYPE_GNS2DNS:
- {
- char nsbuf[514];
- char *cpy;
- char *at;
- size_t off;
-
- cpy = GNUNET_strdup (s);
- at = strchr (cpy, '@');
- if (NULL == at)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse GNS2DNS record `%s'\n"),
- s);
- GNUNET_free (cpy);
- return GNUNET_SYSERR;
- }
- *at = '\0';
- at++;
-
- off = 0;
- if ( (GNUNET_OK !=
- GNUNET_DNSPARSER_builder_add_name (nsbuf,
- sizeof (nsbuf),
- &off,
- cpy)) ||
- (GNUNET_OK !=
- GNUNET_DNSPARSER_builder_add_name (nsbuf,
- sizeof (nsbuf),
- &off,
- at)) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to serialize GNS2DNS record with value `%s'\n"),
- s);
- GNUNET_free (cpy);
- return GNUNET_SYSERR;
- }
- GNUNET_free (cpy);
- *data_size = off;
- *data = GNUNET_malloc (off);
- GNUNET_memcpy (*data,
- nsbuf,
- off);
- return GNUNET_OK;
- }
- case GNUNET_GNSRECORD_TYPE_VPN:
- {
- struct GNUNET_TUN_GnsVpnRecord *vpn;
- char s_peer[103 + 1];
- char s_serv[253 + 1];
- unsigned int proto;
-
- if (3 != SSCANF (s,
- "%u %103s %253s",
- &proto, s_peer, s_serv))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse VPN record string `%s'\n"),
- s);
- return GNUNET_SYSERR;
- }
- *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
- *data = vpn = GNUNET_malloc (*data_size);
- if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_public_key_from_string ((char*) s_peer,
- strlen (s_peer),
- &vpn->peer.public_key))
- {
- GNUNET_free (vpn);
- *data_size = 0;
- return GNUNET_SYSERR;
- }
- vpn->proto = htons ((uint16_t) proto);
- strcpy ((char*)&vpn[1], s_serv);
- return GNUNET_OK;
- }
- case GNUNET_GNSRECORD_TYPE_BOX:
- {
- struct GNUNET_GNSRECORD_BoxRecord *box;
- size_t rest;
- unsigned int protocol;
- unsigned int service;
- unsigned int record_type;
- void *bval;
- size_t bval_size;
-
- if (3 != SSCANF (s,
- "%u %u %u ",
- &protocol,
- &service,
- &record_type))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse BOX record string `%s'\n"),
- s);
- return GNUNET_SYSERR;
- }
- rest = snprintf (NULL, 0,
- "%u %u %u ",
- protocol,
- service,
- record_type);
- if (GNUNET_OK !=
- GNUNET_GNSRECORD_string_to_value (record_type,
- &s[rest],
- &bval,
- &bval_size))
- return GNUNET_SYSERR;
- *data_size = sizeof (struct GNUNET_GNSRECORD_BoxRecord) + bval_size;
- *data = box = GNUNET_malloc (*data_size);
- box->protocol = htons (protocol);
- box->service = htons (service);
- box->record_type = htonl (record_type);
- GNUNET_memcpy (&box[1],
- bval,
- bval_size);
- GNUNET_free (bval);
- return GNUNET_OK;
- }
- default:
+ case GNUNET_GNSRECORD_TYPE_PKEY:
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_ecdsa_public_key_from_string (s, strlen (s), &pkey))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Unable to parse PKEY record `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+ *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
+ GNUNET_memcpy (*data, &pkey, sizeof (pkey));
+ *data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
+ return GNUNET_OK;
+
+ case GNUNET_GNSRECORD_TYPE_NICK:
+ *data = GNUNET_strdup (s);
+ *data_size = strlen (s);
+ return GNUNET_OK;
+ case GNUNET_GNSRECORD_TYPE_LEHO:
+ *data = GNUNET_strdup (s);
+ *data_size = strlen (s);
+ return GNUNET_OK;
+ case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
+ char nsbuf[514];
+ char *cpy;
+ char *at;
+ size_t off;
+
+ cpy = GNUNET_strdup (s);
+ at = strchr (cpy, '@');
+ if (NULL == at)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Unable to parse GNS2DNS record `%s'\n"),
+ s);
+ GNUNET_free (cpy);
+ return GNUNET_SYSERR;
+ }
+ *at = '\0';
+ at++;
+
+ off = 0;
+ if ((GNUNET_OK != GNUNET_DNSPARSER_builder_add_name (nsbuf,
+ sizeof (nsbuf),
+ &off,
+ cpy)) ||
+ (GNUNET_OK !=
+ GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof (nsbuf), &off, at)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to serialize GNS2DNS record with value `%s'\n"),
+ s);
+ GNUNET_free (cpy);
return GNUNET_SYSERR;
+ }
+ GNUNET_free (cpy);
+ *data_size = off;
+ *data = GNUNET_malloc (off);
+ GNUNET_memcpy (*data, nsbuf, off);
+ return GNUNET_OK;
+ }
+ case GNUNET_GNSRECORD_TYPE_VPN: {
+ struct GNUNET_TUN_GnsVpnRecord *vpn;
+ char s_peer[103 + 1];
+ char s_serv[253 + 1];
+ unsigned int proto;
+
+ if (3 != sscanf (s, "%u %103s %253s", &proto, s_peer, s_serv))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Unable to parse VPN record string `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+ *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
+ *data = vpn = GNUNET_malloc (*data_size);
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string ((char *) s_peer,
+ strlen (s_peer),
+ &vpn->peer.public_key))
+ {
+ GNUNET_free (vpn);
+ *data_size = 0;
+ return GNUNET_SYSERR;
+ }
+ vpn->proto = htons ((uint16_t) proto);
+ strcpy ((char *) &vpn[1], s_serv);
+ return GNUNET_OK;
+ }
+ case GNUNET_GNSRECORD_TYPE_BOX: {
+ struct GNUNET_GNSRECORD_BoxRecord *box;
+ size_t rest;
+ unsigned int protocol;
+ unsigned int service;
+ unsigned int record_type;
+ void *bval;
+ size_t bval_size;
+
+ if (3 != sscanf (s, "%u %u %u ", &protocol, &service, &record_type))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Unable to parse BOX record string `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+ rest = snprintf (NULL, 0, "%u %u %u ", protocol, service, record_type);
+ if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (record_type,
+ &s[rest],
+ &bval,
+ &bval_size))
+ return GNUNET_SYSERR;
+ *data_size = sizeof (struct GNUNET_GNSRECORD_BoxRecord) + bval_size;
+ *data = box = GNUNET_malloc (*data_size);
+ box->protocol = htons (protocol);
+ box->service = htons (service);
+ box->record_type = htonl (record_type);
+ GNUNET_memcpy (&box[1], bval, bval_size);
+ GNUNET_free (bval);
+ return GNUNET_OK;
+ }
+ default:
+ return GNUNET_SYSERR;
}
}
* Mapping of record type numbers to human-readable
* record type names.
*/
-static struct {
+static struct
+{
const char *name;
uint32_t number;
-} gns_name_map[] = {
- { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY },
- { "NICK", GNUNET_GNSRECORD_TYPE_NICK },
- { "LEHO", GNUNET_GNSRECORD_TYPE_LEHO },
- { "VPN", GNUNET_GNSRECORD_TYPE_VPN },
- { "GNS2DNS", GNUNET_GNSRECORD_TYPE_GNS2DNS },
- { "BOX", GNUNET_GNSRECORD_TYPE_BOX },
- { NULL, UINT32_MAX }
-};
+} gns_name_map[] = {{"PKEY", GNUNET_GNSRECORD_TYPE_PKEY},
+ {"NICK", GNUNET_GNSRECORD_TYPE_NICK},
+ {"LEHO", GNUNET_GNSRECORD_TYPE_LEHO},
+ {"VPN", GNUNET_GNSRECORD_TYPE_VPN},
+ {"GNS2DNS", GNUNET_GNSRECORD_TYPE_GNS2DNS},
+ {"BOX", GNUNET_GNSRECORD_TYPE_BOX},
+ {NULL, UINT32_MAX}};
/**
* @return corresponding number, UINT32_MAX on error
*/
static uint32_t
-gns_typename_to_number (void *cls,
- const char *gns_typename)
+gns_typename_to_number (void *cls, const char *gns_typename)
{
unsigned int i;
- i=0;
- while ( (NULL != gns_name_map[i].name) &&
- (0 != strcasecmp (gns_typename,
- gns_name_map[i].name)) )
+ i = 0;
+ while ((NULL != gns_name_map[i].name) &&
+ (0 != strcasecmp (gns_typename, gns_name_map[i].name)))
i++;
return gns_name_map[i].number;
}
* @return corresponding typestring, NULL on error
*/
static const char *
-gns_number_to_typename (void *cls,
- uint32_t type)
+gns_number_to_typename (void *cls, uint32_t type)
{
unsigned int i;
- i=0;
- while ( (NULL != gns_name_map[i].name) &&
- (type != gns_name_map[i].number) )
+ i = 0;
+ while ((NULL != gns_name_map[i].name) && (type != gns_name_map[i].number))
i++;
return gns_name_map[i].name;
}
typep = strtok (sdup, " ");
if ((NULL == typep) ||
((0 == (type = rfc4398_mnemonic_to_value (typep))) &&
- ((1 != SSCANF (typep, "%u", &type)) || (type > UINT16_MAX))))
+ ((1 != sscanf (typep, "%u", &type)) || (type > UINT16_MAX))))
{
GNUNET_free (sdup);
return GNUNET_SYSERR;
}
keyp = strtok (NULL, " ");
- if ((NULL == keyp) || (1 != SSCANF (keyp, "%u", &key)) ||
+ if ((NULL == keyp) || (1 != sscanf (keyp, "%u", &key)) ||
(key > UINT16_MAX))
{
GNUNET_free (sdup);
unsigned int soa_min;
size_t off;
- if (7 != SSCANF (s,
+ if (7 != sscanf (s,
"rname=%253s mname=%253s %u,%u,%u,%u,%u",
soa_rname,
soa_mname,
unsigned int mx_pref;
size_t off;
- if (2 != SSCANF (s, "%u,%253s", &mx_pref, mxhost))
+ if (2 != sscanf (s, "%u,%253s", &mx_pref, mxhost))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Unable to parse MX record `%s'\n"),
unsigned int port;
size_t off;
- if (4 != SSCANF (s, "%u %u %u %253s", &priority, &weight, &port, srvtarget))
+ if (4 != sscanf (s, "%u %u %u %253s", &priority, &weight, &port, srvtarget))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Unable to parse SRV record `%s'\n"),
size_t slen = strlen (s) + 1;
char hex[slen];
- if (4 != SSCANF (s, "%u %u %u %s", &usage, &selector, &matching_type, hex))
+ if (4 != sscanf (s, "%u %u %u %s", &usage, &selector, &matching_type, hex))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Unable to parse TLSA record string `%s'\n"),
char tag[15]; //Max tag length 15
char value[strlen (s) + 1]; //Should be more than enough
- if (3 != SSCANF (s, "%u %s %[^\n]", &flags, tag, value))
+ if (3 != sscanf (s, "%u %s %[^\n]", &flags, tag, value))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Unable to parse CAA record string `%s'\n"),
size_t ret;
ret = GNUNET_HELLO_add_address (address,
- GNUNET_TIME_UNIT_FOREVER_ABS,
- ac->buf,
- ac->max);
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ ac->buf,
+ ac->max);
ac->buf += ret;
ac->max -= ret;
ac->ret += ret;
- address_count ++;
+ address_count++;
return GNUNET_OK;
}
* @return number of bytes added, 0 to terminate
*/
static ssize_t
-add_from_hello (void *cls,
- size_t max,
- void *buf)
+add_from_hello (void *cls, size_t max, void *buf)
{
struct GNUNET_HELLO_Message **orig = cls;
struct AddContext ac;
ac.buf = buf;
ac.max = max;
ac.ret = 0;
- GNUNET_assert (NULL ==
- GNUNET_HELLO_iterate_addresses (*orig,
- GNUNET_NO, &add_to_buf,
- &ac));
+ GNUNET_assert (
+ NULL ==
+ GNUNET_HELLO_iterate_addresses (*orig, GNUNET_NO, &add_to_buf, &ac));
*orig = NULL;
return ac.ret;
}
GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
if (argc != 2)
{
- FPRINTF (stderr,
- "%s",
- _("Call with name of HELLO file to modify.\n"));
+ fprintf (stderr, "%s", _ ("Call with name of HELLO file to modify.\n"));
return 1;
}
- if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES))
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES))
{
- FPRINTF (stderr,
- _("Error accessing file `%s': %s\n"),
- argv[1],
- STRERROR (errno));
+ fprintf (stderr,
+ _ ("Error accessing file `%s': %s\n"),
+ argv[1],
+ strerror (errno));
return 1;
}
if (fsize > 65536)
{
- FPRINTF (stderr,
- _("File `%s' is too big to be a HELLO\n"),
- argv[1]);
+ fprintf (stderr, _ ("File `%s' is too big to be a HELLO\n"), argv[1]);
return 1;
}
if (fsize < sizeof (struct GNUNET_MessageHeader))
{
- FPRINTF (stderr,
- _("File `%s' is too small to be a HELLO\n"),
- argv[1]);
+ fprintf (stderr, _ ("File `%s' is too small to be a HELLO\n"), argv[1]);
return 1;
}
fh = GNUNET_DISK_file_open (argv[1],
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_USER_READ);
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_USER_READ);
if (NULL == fh)
{
- FPRINTF (stderr,
- _("Error opening file `%s': %s\n"),
- argv[1],
- STRERROR (errno));
+ fprintf (stderr,
+ _ ("Error opening file `%s': %s\n"),
+ argv[1],
+ strerror (errno));
return 1;
}
{
char buf[fsize] GNUNET_ALIGN;
- GNUNET_assert (fsize ==
- GNUNET_DISK_file_read (fh, buf, fsize));
+ GNUNET_assert (fsize == GNUNET_DISK_file_read (fh, buf, fsize));
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
orig = (struct GNUNET_HELLO_Message *) buf;
- if ( (fsize < GNUNET_HELLO_size (orig)) ||
- (GNUNET_OK != GNUNET_HELLO_get_id (orig,
- &pid)) )
+ if ((fsize < GNUNET_HELLO_size (orig)) ||
+ (GNUNET_OK != GNUNET_HELLO_get_id (orig, &pid)))
{
- FPRINTF (stderr,
- _("Did not find well-formed HELLO in file `%s'\n"),
- argv[1]);
+ fprintf (stderr,
+ _ ("Did not find well-formed HELLO in file `%s'\n"),
+ argv[1]);
return 1;
}
{
char *pids;
pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid.public_key);
- fprintf (stdout,
- "Processing HELLO for peer `%s'\n",
- pids);
+ fprintf (stdout, "Processing HELLO for peer `%s'\n", pids);
GNUNET_free (pids);
}
result = GNUNET_HELLO_create (&pid.public_key,
&orig,
GNUNET_HELLO_is_friend_only (orig));
GNUNET_assert (NULL != result);
- fh = GNUNET_DISK_file_open (argv[1],
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE,
- GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
- if (NULL == fh)
- {
- FPRINTF (stderr,
- _("Error opening file `%s': %s\n"),
- argv[1],
- STRERROR (errno));
- GNUNET_free (result);
- return 1;
- }
- fsize = GNUNET_HELLO_size (result);
- if (fsize != GNUNET_DISK_file_write (fh,
- result,
- fsize))
- {
- FPRINTF (stderr,
- _("Error writing HELLO to file `%s': %s\n"),
- argv[1],
- STRERROR (errno));
- (void) GNUNET_DISK_file_close (fh);
- return 1;
- }
+ fh =
+ GNUNET_DISK_file_open (argv[1],
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
+ if (NULL == fh)
+ {
+ fprintf (stderr,
+ _ ("Error opening file `%s': %s\n"),
+ argv[1],
+ strerror (errno));
+ GNUNET_free (result);
+ return 1;
+ }
+ fsize = GNUNET_HELLO_size (result);
+ if (fsize != GNUNET_DISK_file_write (fh, result, fsize))
+ {
+ fprintf (stderr,
+ _ ("Error writing HELLO to file `%s': %s\n"),
+ argv[1],
+ strerror (errno));
+ (void) GNUNET_DISK_file_close (fh);
+ return 1;
+ }
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
}
- FPRINTF (stderr,
- _("Modified %u addresses, wrote %u bytes\n"),
+ fprintf (stderr,
+ _ ("Modified %u addresses, wrote %u bytes\n"),
address_count,
(unsigned int) fsize);
return 0;
{
if (GNUNET_YES == GNUNET_DISK_file_test (filename))
{
- result = UNLINK (filename);
+ result = unlink (filename);
if (result == 0)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Hostlist file `%s' was removed\n"),
if (GNUNET_YES ==
GNUNET_DISK_file_test ("hostlists_learn_peer.file"))
{
- if (0 == UNLINK ("hostlists_learn_peer.file"))
+ if (0 == unlink ("hostlists_learn_peer.file"))
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Hostlist file hostlists_learn_peer.file was removed\n");
}
&ok);
if (0 == ok)
{
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
/* now do it again */
ok = 1;
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
options,
&run,
&ok);
- FPRINTF (stderr, "%s", ".\n");
+ fprintf (stderr, "%s", ".\n");
}
GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
"GNUNET_TEST_HOME");
* String identifier for the ego.
*/
char *identifier;
-
};
char *filename;
GNUNET_asprintf (&filename,
- "%s%s%s",
- ego_directory,
- DIR_SEPARATOR_STR,
- ego->identifier);
+ "%s%s%s",
+ ego_directory,
+ DIR_SEPARATOR_STR,
+ ego->identifier);
return filename;
}
struct GNUNET_SERVICE_Client *client,
void *app_ctx)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p disconnected\n",
- client);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
}
*/
static void
send_result_code (struct GNUNET_SERVICE_Client *client,
- uint32_t result_code,
- const char *emsg)
+ uint32_t result_code,
+ const char *emsg)
{
struct ResultCodeMessage *rcm;
struct GNUNET_MQ_Envelope *env;
elen = 0;
else
elen = strlen (emsg) + 1;
- env = GNUNET_MQ_msg_extra (rcm,
- elen,
- GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
+ env =
+ GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
rcm->result_code = htonl (result_code);
if (0 < elen)
GNUNET_memcpy (&rcm[1], emsg, elen);
size_t name_len;
name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
- env = GNUNET_MQ_msg_extra (um,
- name_len,
- GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
+ env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
um->name_len = htons (name_len);
um->end_of_list = htons (GNUNET_NO);
um->private_key = *ego->pk;
* @return corresponding set default message
*/
static struct GNUNET_MQ_Envelope *
-create_set_default_message (struct Ego *ego,
- const char *servicename)
+create_set_default_message (struct Ego *ego, const char *servicename)
{
struct SetDefaultMessage *sdm;
struct GNUNET_MQ_Envelope *env;
* @param message the message received
*/
static void
-handle_start_message (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_start_message (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
struct UpdateMessage *ume;
struct GNUNET_MQ_Envelope *env;
struct Ego *ego;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received START message from client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
GNUNET_SERVICE_client_mark_monitor (client);
GNUNET_SERVICE_client_disable_continue_warning (client);
- GNUNET_notification_context_add (nc,
- GNUNET_SERVICE_client_get_mq(client));
+ GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client));
for (ego = ego_head; NULL != ego; ego = ego->next)
{
env = create_update_message (ego);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(client), env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
}
- env = GNUNET_MQ_msg_extra (ume,
- 0,
- GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
+ env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
ume->end_of_list = htons (GNUNET_YES);
ume->name_len = htons (0);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(client), env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
GNUNET_SERVICE_client_continue (client);
}
* @return #GNUNET_SYSERR if message was ill-formed
*/
static int
-check_lookup_message (void *cls,
- const struct LookupMessage *message)
+check_lookup_message (void *cls, const struct LookupMessage *message)
{
GNUNET_MQ_check_zero_termination (message);
return GNUNET_OK;
* @param message the message received
*/
static void
-handle_lookup_message (void *cls,
- const struct LookupMessage *message)
+handle_lookup_message (void *cls, const struct LookupMessage *message)
{
struct GNUNET_SERVICE_Client *client = cls;
const char *name;
struct GNUNET_MQ_Envelope *env;
struct Ego *ego;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received LOOKUP message from client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n");
name = (const char *) &message[1];
for (ego = ego_head; NULL != ego; ego = ego->next)
{
- if (0 != strcasecmp (name,
- ego->identifier))
+ if (0 != strcasecmp (name, ego->identifier))
continue;
env = create_update_message (ego);
GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
GNUNET_SERVICE_client_continue (client);
return;
}
- send_result_code (client,
- 0,
- "ego not found");
+ send_result_code (client, 0, "ego not found");
GNUNET_SERVICE_client_continue (client);
}
* @return #GNUNET_SYSERR if message was ill-formed
*/
static int
-check_lookup_by_suffix_message (void *cls,
- const struct LookupMessage *message)
+check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
{
GNUNET_MQ_check_zero_termination (message);
return GNUNET_OK;
* @param message the message received
*/
static void
-handle_lookup_by_suffix_message (void *cls,
- const struct LookupMessage *message)
+handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
{
struct GNUNET_SERVICE_Client *client = cls;
const char *name;
if ((strlen (ego->identifier) <= strlen (name)) &&
(0 == strcmp (ego->identifier,
- &name[strlen (name) - strlen (ego->identifier)])) &&
+ &name[strlen (name) - strlen (ego->identifier)])) &&
((strlen (name) == strlen (ego->identifier)) ||
- ('.' == name[strlen (name) -
- strlen (ego->identifier) - 1])) &&
+ ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
((NULL == lprefix) ||
(strlen (ego->identifier) > strlen (lprefix->identifier))))
{
GNUNET_SERVICE_client_continue (client);
return;
}
- send_result_code (client,
- 0,
- "ego not found");
+ send_result_code (client, 0, "ego not found");
GNUNET_SERVICE_client_continue (client);
}
* @return #GNUNET_OK if @a msg is well-formed
*/
static int
-check_get_default_message (void *cls,
- const struct GetDefaultMessage *msg)
+check_get_default_message (void *cls, const struct GetDefaultMessage *msg)
{
uint16_t size;
uint16_t name_len;
}
name = (const char *) &msg[1];
name_len = ntohs (msg->name_len);
- if ( (name_len + sizeof (struct GetDefaultMessage) != size) ||
- (0 != ntohs (msg->reserved)) ||
- ('\0' != name[name_len - 1]) )
+ if ((name_len + sizeof (struct GetDefaultMessage) != size) ||
+ (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
{
GNUNET_break (0);
return GNUNET_SYSERR;
* @param message the message received
*/
static void
-handle_get_default_message (void *cls,
- const struct GetDefaultMessage *gdm)
+handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_SERVICE_Client *client = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received GET_DEFAULT for service `%s' from client\n",
name);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
- name,
- "DEFAULT_IDENTIFIER",
- &identifier))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
+ name,
+ "DEFAULT_IDENTIFIER",
+ &identifier))
{
send_result_code (client, 1, gettext_noop ("no default known"));
GNUNET_SERVICE_client_continue (client);
}
for (ego = ego_head; NULL != ego; ego = ego->next)
{
- if (0 == strcmp (ego->identifier,
- identifier))
+ if (0 == strcmp (ego->identifier, identifier))
{
- env = create_set_default_message (ego,
- name);
+ env = create_set_default_message (ego, name);
GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
GNUNET_SERVICE_client_continue (client);
GNUNET_free (identifier);
}
}
GNUNET_free (identifier);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to find ego `%s'\n",
- name);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name);
GNUNET_free (name);
- send_result_code (client, 1,
- gettext_noop ("default configured, but ego unknown (internal error)"));
+ send_result_code (client,
+ 1,
+ gettext_noop (
+ "default configured, but ego unknown (internal error)"));
GNUNET_SERVICE_client_continue (client);
}
* @return #GNUNET_OK if @a msg is well-formed
*/
static int
-check_set_default_message (void *cls,
- const struct SetDefaultMessage *msg)
+check_set_default_message (void *cls, const struct SetDefaultMessage *msg)
{
uint16_t size;
uint16_t name_len;
* @param message the message received
*/
static void
-handle_set_default_message (void *cls,
- const struct SetDefaultMessage *sdm)
+handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm)
{
struct Ego *ego;
struct GNUNET_SERVICE_Client *client = cls;
str);
for (ego = ego_head; NULL != ego; ego = ego->next)
{
- if (0 == key_cmp (ego->pk,
- &sdm->private_key))
+ if (0 == key_cmp (ego->pk, &sdm->private_key))
{
GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
str,
"DEFAULT_IDENTIFIER",
ego->identifier);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_write (subsystem_cfg,
- subsystem_cfg_file))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to write subsystem default identifier map to `%s'.\n"),
- subsystem_cfg_file);
+ GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to write subsystem default identifier map to `%s'.\n"),
+ subsystem_cfg_file);
send_result_code (client, 0, NULL);
GNUNET_SERVICE_client_continue (client);
GNUNET_free (str);
return;
}
}
- send_result_code (client, 1, _("Unknown ego specified for service (internal error)"));
+ send_result_code (client,
+ 1,
+ _ ("Unknown ego specified for service (internal error)"));
GNUNET_free (str);
GNUNET_SERVICE_client_continue (client);
}
um->end_of_list = htons (GNUNET_NO);
um->private_key = *ego->pk;
GNUNET_memcpy (&um[1], ego->identifier, name_len);
- GNUNET_notification_context_broadcast (nc,
- &um->header,
- GNUNET_NO);
+ GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO);
GNUNET_free (um);
}
* @return #GNUNET_OK if @a msg is well-formed
*/
static int
-check_create_message (void *cls,
- const struct CreateRequestMessage *msg)
+check_create_message (void *cls, const struct CreateRequestMessage *msg)
{
-
+
uint16_t size;
uint16_t name_len;
const char *str;
return GNUNET_SYSERR;
}
return GNUNET_OK;
-}
+}
/**
* Handler for CREATE message from client, creates
* @param message the message received
*/
static void
-handle_create_message (void *cls,
- const struct CreateRequestMessage *crm)
+handle_create_message (void *cls, const struct CreateRequestMessage *crm)
{
struct GNUNET_SERVICE_Client *client = cls;
struct Ego *ego;
char *str;
char *fn;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received CREATE message from client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
str = GNUNET_strdup ((const char *) &crm[1]);
GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str);
for (ego = ego_head; NULL != ego; ego = ego->next)
{
- if (0 == strcmp (ego->identifier,
- str))
+ if (0 == strcmp (ego->identifier, str))
{
- send_result_code (client, 1, gettext_noop ("identifier already in use for another ego"));
+ send_result_code (client,
+ 1,
+ gettext_noop (
+ "identifier already in use for another ego"));
GNUNET_SERVICE_client_continue (client);
GNUNET_free (str);
return;
ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
*ego->pk = crm->private_key;
ego->identifier = GNUNET_strdup (str);
- GNUNET_CONTAINER_DLL_insert (ego_head,
- ego_tail,
- ego);
+ GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
send_result_code (client, 0, NULL);
fn = get_ego_filename (ego);
(void) GNUNET_DISK_directory_create_for_file (fn);
&crm->private_key,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "write", fn);
+ GNUNET_DISK_PERM_USER_WRITE))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
GNUNET_free (fn);
GNUNET_free (str);
notify_listeners (ego);
* @param section a section in the configuration to process
*/
static void
-handle_ego_rename (void *cls,
- const char *section)
+handle_ego_rename (void *cls, const char *section)
{
struct RenameContext *rc = cls;
char *id;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
- section,
- "DEFAULT_IDENTIFIER",
- &id))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
+ section,
+ "DEFAULT_IDENTIFIER",
+ &id))
return;
if (0 != strcmp (id, rc->old_name))
{
* @return #GNUNET_OK if @a msg is well-formed
*/
static int
-check_rename_message (void *cls,
- const struct RenameMessage *msg)
+check_rename_message (void *cls, const struct RenameMessage *msg)
{
uint16_t size;
uint16_t old_name_len;
new_name_len = ntohs (msg->new_name_len);
old_name = (const char *) &msg[1];
new_name = &old_name[old_name_len];
- if ( (old_name_len + new_name_len + sizeof (struct RenameMessage) != size) ||
- ('\0' != old_name[old_name_len - 1]) ||
- ('\0' != new_name[new_name_len - 1]) )
+ if ((old_name_len + new_name_len + sizeof (struct RenameMessage) != size) ||
+ ('\0' != old_name[old_name_len - 1]) ||
+ ('\0' != new_name[new_name_len - 1]))
{
GNUNET_break (0);
return GNUNET_SYSERR;
return GNUNET_OK;
}
-
+
/**
* Handler for RENAME message from client, creates
* @param message the message received
*/
static void
-handle_rename_message (void *cls,
- const struct RenameMessage *rm)
+handle_rename_message (void *cls, const struct RenameMessage *rm)
{
uint16_t old_name_len;
struct Ego *ego;
char *fn_new;
const char *old_name_tmp;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received RENAME message from client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
old_name_len = ntohs (rm->old_name_len);
old_name_tmp = (const char *) &rm[1];
old_name = GNUNET_strdup (old_name_tmp);
/* check if new name is already in use */
for (ego = ego_head; NULL != ego; ego = ego->next)
{
- if (0 == strcmp (ego->identifier,
- new_name))
+ if (0 == strcmp (ego->identifier, new_name))
{
send_result_code (client, 1, gettext_noop ("target name already exists"));
GNUNET_SERVICE_client_continue (client);
/* locate old name and, if found, perform rename */
for (ego = ego_head; NULL != ego; ego = ego->next)
{
- if (0 == strcmp (ego->identifier,
- old_name))
+ if (0 == strcmp (ego->identifier, old_name))
{
fn_old = get_ego_filename (ego);
GNUNET_free (ego->identifier);
&handle_ego_rename,
&rename_ctx);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_write (subsystem_cfg,
- subsystem_cfg_file))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to write subsystem default identifier map to `%s'.\n"),
- subsystem_cfg_file);
+ GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to write subsystem default identifier map to `%s'.\n"),
+ subsystem_cfg_file);
ego->identifier = GNUNET_strdup (new_name);
fn_new = get_ego_filename (ego);
- if (0 != RENAME (fn_old, fn_new))
+ if (0 != rename (fn_old, fn_new))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
GNUNET_free (fn_old);
GNUNET_free (fn_new);
* @param section a section in the configuration to process
*/
static void
-handle_ego_delete (void *cls,
- const char *section)
+handle_ego_delete (void *cls, const char *section)
{
const char *identifier = cls;
char *id;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
- section,
- "DEFAULT_IDENTIFIER",
- &id))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
+ section,
+ "DEFAULT_IDENTIFIER",
+ &id))
return;
if (0 != strcmp (id, identifier))
{
* @return #GNUNET_OK if @a msg is well-formed
*/
static int
-check_delete_message (void *cls,
- const struct DeleteMessage *msg)
+check_delete_message (void *cls, const struct DeleteMessage *msg)
{
uint16_t size;
uint16_t name_len;
}
name = (const char *) &msg[1];
name_len = ntohs (msg->name_len);
- if ( (name_len + sizeof (struct DeleteMessage) != size) ||
- (0 != ntohs (msg->reserved)) ||
- ('\0' != name[name_len - 1]) )
+ if ((name_len + sizeof (struct DeleteMessage) != size) ||
+ (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
{
GNUNET_break (0);
return GNUNET_SYSERR;
* @param message the message received
*/
static void
-handle_delete_message (void *cls,
- const struct DeleteMessage *dm)
+handle_delete_message (void *cls, const struct DeleteMessage *dm)
{
struct Ego *ego;
char *name;
char *fn;
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received DELETE message from client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
name = GNUNET_strdup ((const char *) &dm[1]);
GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
for (ego = ego_head; NULL != ego; ego = ego->next)
{
- if (0 == strcmp (ego->identifier,
- name))
+ if (0 == strcmp (ego->identifier, name))
{
- GNUNET_CONTAINER_DLL_remove (ego_head,
- ego_tail,
- ego);
+ GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego);
GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
&handle_ego_delete,
ego->identifier);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_write (subsystem_cfg,
- subsystem_cfg_file))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to write subsystem default identifier map to `%s'.\n"),
- subsystem_cfg_file);
+ GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to write subsystem default identifier map to `%s'.\n"),
+ subsystem_cfg_file);
fn = get_ego_filename (ego);
- if (0 != UNLINK (fn))
+ if (0 != unlink (fn))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
GNUNET_free (fn);
GNUNET_free (ego->identifier);
* #GNUNET_SYSERR to abort iteration with error!
*/
static int
-process_ego_file (void *cls,
- const char *filename)
+process_ego_file (void *cls, const char *filename)
{
struct Ego *ego;
const char *fn;
{
GNUNET_free (ego);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to parse ego information in `%s'\n"),
+ _ ("Failed to parse ego information in `%s'\n"),
filename);
return GNUNET_OK;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Loaded ego `%s'\n",
- fn + 1);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1);
ego->identifier = GNUNET_strdup (fn + 1);
- GNUNET_CONTAINER_DLL_insert (ego_head,
- ego_tail,
- ego);
+ GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
return GNUNET_OK;
}
{
cfg = c;
nc = GNUNET_notification_context_create (1);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "identity",
- "EGODIR",
- &ego_directory))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "identity",
+ "EGODIR",
+ &ego_directory))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "identity",
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "identity",
"SUBSYSTEM_CFG",
&subsystem_cfg_file))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "SUBSYSTEM_CFG");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "identity",
+ "SUBSYSTEM_CFG");
GNUNET_SCHEDULER_shutdown ();
return;
}
"Loading subsystem configuration `%s'\n",
subsystem_cfg_file);
subsystem_cfg = GNUNET_CONFIGURATION_create ();
- if ( (GNUNET_YES ==
- GNUNET_DISK_file_test (subsystem_cfg_file)) &&
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_parse (subsystem_cfg,
- subsystem_cfg_file)) )
+ if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) &&
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse subsystem identity configuration file `%s'\n"),
+ _ (
+ "Failed to parse subsystem identity configuration file `%s'\n"),
subsystem_cfg_file);
GNUNET_SCHEDULER_shutdown ();
return;
}
stats = GNUNET_STATISTICS_create ("identity", cfg);
- if (GNUNET_OK !=
- GNUNET_DISK_directory_create (ego_directory))
+ if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create directory `%s' for storing egos\n"),
+ _ ("Failed to create directory `%s' for storing egos\n"),
ego_directory);
}
- GNUNET_DISK_directory_scan (ego_directory,
- &process_ego_file,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("identity",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_fixed_size (start_message,
- GNUNET_MESSAGE_TYPE_IDENTITY_START,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_hd_var_size (lookup_message,
- GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
- struct LookupMessage,
- NULL),
- GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
- GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX,
- struct LookupMessage,
- NULL),
- GNUNET_MQ_hd_var_size (get_default_message,
- GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
- struct GetDefaultMessage,
- NULL),
- GNUNET_MQ_hd_var_size (set_default_message,
- GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
- struct SetDefaultMessage,
- NULL),
- GNUNET_MQ_hd_var_size (create_message,
- GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
- struct CreateRequestMessage,
- NULL),
- GNUNET_MQ_hd_var_size (rename_message,
- GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
- struct RenameMessage,
- NULL),
- GNUNET_MQ_hd_var_size (delete_message,
- GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
- struct DeleteMessage,
- NULL),
- GNUNET_MQ_handler_end());
-
+GNUNET_SERVICE_MAIN (
+ "identity",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_fixed_size (start_message,
+ GNUNET_MESSAGE_TYPE_IDENTITY_START,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_var_size (lookup_message,
+ GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
+ struct LookupMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
+ GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX,
+ struct LookupMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (get_default_message,
+ GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
+ struct GetDefaultMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (set_default_message,
+ GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
+ struct SetDefaultMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (create_message,
+ GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
+ struct CreateRequestMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (rename_message,
+ GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
+ struct RenameMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (delete_message,
+ GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
+ struct DeleteMessage,
+ NULL),
+ GNUNET_MQ_handler_end ());
/* end of gnunet-service-identity.c */
else
gnunetinclude_HEADERS = \
- platform.h plibc.h $(WINPROC) gettext.h \
+ platform.h $(WINPROC) gettext.h \
compat.h \
gnunet_applications.h \
gnunet_arm_service.h \
cmd, \
__FILE__, \
__LINE__, \
- STRERROR (errno)); \
+ strerror (errno)); \
} while (0)
cmd, \
__FILE__, \
__LINE__, \
- STRERROR (errno)); \
+ strerror (errno)); \
} while (0)
filename, \
__FILE__, \
__LINE__, \
- STRERROR (errno)); \
+ strerror (errno)); \
} while (0)
filename, \
__FILE__, \
__LINE__, \
- STRERROR (errno)); \
+ strerror (errno)); \
} while (0)
/* ************************* endianess conversion ****************** */
#include <sys/endian.h>
#endif
-#include "plibc.h"
+/* From plibc. */
+#ifdef Q_OS_WIN32
+#define WINDOWS 1
+#endif
+
+#ifndef WINDOWS
+#define DIR_SEPARATOR '/'
+#define DIR_SEPARATOR_STR "/"
+#define PATH_SEPARATOR ':'
+#define PATH_SEPARATOR_STR ":"
+#define NEWLINE "\n"
+#else
+#define DIR_SEPARATOR '\\'
+#define DIR_SEPARATOR_STR "\\"
+#define PATH_SEPARATOR ';'
+#define PATH_SEPARATOR_STR ";"
+#define NEWLINE "\r\n"
+#endif
+
#include "compat.h"
#include <locale.h>
+++ /dev/null
-/*
- This file is part of PlibC.
- Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors)
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-/**
- * @file
- * PlibC header
- *
- * @attention This file is usually not installed under Unix,
- * so ship it with your application
- *
- * @version $Revision: 158 $
- */
-
-#ifndef _PLIBC_H_
-#define _PLIBC_H_
-
-#ifndef SIGALRM
- #define SIGALRM 14
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stddef.h>
-
-#ifdef Q_OS_WIN32
- #define WINDOWS 1
-#endif
-
-#define HAVE_PLIBC_FD 0
-
-#ifdef WINDOWS
-
-#if ENABLE_NLS
- #include "langinfo.h"
-#endif
-
-#include <ws2tcpip.h>
-#include <windows.h>
-#include <sys/types.h>
-#include <time.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <errno.h>
-#include <stdarg.h>
-
-#define __BYTE_ORDER BYTE_ORDER
-#define __BIG_ENDIAN BIG_ENDIAN
-
-/* Conflicts with our definitions */
-#define __G_WIN32_H__
-
-/* Convert LARGE_INTEGER to double */
-#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \
- (double)((x).LowPart))
-#ifndef HAVE_DECL__STATI64
-struct _stati64
-{
- _dev_t st_dev;
- _ino_t st_ino;
- _mode_t st_mode;
- short st_nlink;
- short st_uid;
- short st_gid;
- _dev_t st_rdev;
- __int64 st_size;
- time_t st_atime;
- time_t st_mtime;
- time_t st_ctime;
-};
-#endif
-typedef unsigned int sa_family_t;
-
-struct sockaddr_un {
- short sun_family; /*AF_UNIX*/
- char sun_path[108]; /*path name */
-};
-
-#ifndef pid_t
- #define pid_t DWORD
-#endif
-
-#ifndef error_t
- #define error_t int
-#endif
-
-#ifndef WEXITSTATUS
- #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
-#endif
-
-#ifndef MSG_DONTWAIT
- #define MSG_DONTWAIT 0
-#endif
-
-enum
-{
- _SC_PAGESIZE = 30,
- _SC_PAGE_SIZE = 30
-};
-
-#if !defined(EACCESS)
-# define EACCESS EACCES
-#endif
-
-/* Thanks to the Cygwin project */
-#if !defined(ENOCSI)
-# define ENOCSI 43 /* No CSI structure available */
-#endif
-#if !defined(EL2HLT)
-# define EL2HLT 44 /* Level 2 halted */
-#endif
-#if !defined(EDEADLK)
-# define EDEADLK 45 /* Deadlock condition */
-#endif
-#if !defined(ENOLCK)
-# define ENOLCK 46 /* No record locks available */
-#endif
-#if !defined(EBADE)
-# define EBADE 50 /* Invalid exchange */
-#endif
-#if !defined(EBADR)
-# define EBADR 51 /* Invalid request descriptor */
-#endif
-#if !defined(EXFULL)
-# define EXFULL 52 /* Exchange full */
-#endif
-#if !defined(ENOANO)
-# define ENOANO 53 /* No anode */
-#endif
-#if !defined(EBADRQC)
-# define EBADRQC 54 /* Invalid request code */
-#endif
-#if !defined(EBADSLT)
-# define EBADSLT 55 /* Invalid slot */
-#endif
-#if !defined(EDEADLOCK)
-# define EDEADLOCK EDEADLK /* File locking deadlock error */
-#endif
-#if !defined(EBFONT)
-# define EBFONT 57 /* Bad font file fmt */
-#endif
-#if !defined(ENOSTR)
-# define ENOSTR 60 /* Device not a stream */
-#endif
-#if !defined(ENODATA)
-# define ENODATA 61 /* No data (for no delay io) */
-#endif
-#if !defined(ETIME)
-# define ETIME 62 /* Timer expired */
-#endif
-#if !defined(ENOSR)
-# define ENOSR 63 /* Out of streams resources */
-#endif
-#if !defined(ENONET)
-# define ENONET 64 /* Machine is not on the network */
-#endif
-#if !defined(ENOPKG)
-# define ENOPKG 65 /* Package not installed */
-#endif
-#if !defined(EREMOTE)
-# define EREMOTE 66 /* The object is remote */
-#endif
-#if !defined(ENOLINK)
-# define ENOLINK 67 /* The link has been severed */
-#endif
-#if !defined(EADV)
-# define EADV 68 /* Advertise error */
-#endif
-#if !defined(ESRMNT)
-# define ESRMNT 69 /* Srmount error */
-#endif
-#if !defined(ECOMM)
-# define ECOMM 70 /* Communication error on send */
-#endif
-#if !defined(EMULTIHOP)
-# define EMULTIHOP 74 /* Multihop attempted */
-#endif
-#if !defined(ELBIN)
-# define ELBIN 75 /* Inode is remote (not really error) */
-#endif
-#if !defined(EDOTDOT)
-# define EDOTDOT 76 /* Cross mount point (not really error) */
-#endif
-#if !defined(EBADMSG)
-# define EBADMSG 77 /* Trying to read unreadable message */
-#endif
-#if !defined(ENOTUNIQ)
-# define ENOTUNIQ 80 /* Given log. name not unique */
-#endif
-#if !defined(EBADFD)
-# define EBADFD 81 /* f.d. invalid for this operation */
-#endif
-#if !defined(EREMCHG)
-# define EREMCHG 82 /* Remote address changed */
-#endif
-#if !defined(ELIBACC)
-# define ELIBACC 83 /* Can't access a needed shared lib */
-#endif
-#if !defined(ELIBBAD)
-# define ELIBBAD 84 /* Accessing a corrupted shared lib */
-#endif
-#if !defined(ELIBSCN)
-# define ELIBSCN 85 /* .lib section in a.out corrupted */
-#endif
-#if !defined(ELIBMAX)
-# define ELIBMAX 86 /* Attempting to link in too many libs */
-#endif
-#if !defined(ELIBEXEC)
-# define ELIBEXEC 87 /* Attempting to exec a shared library */
-#endif
-#if !defined(ENOSYS)
-# define ENOSYS 88 /* Function not implemented */
-#endif
-#if !defined(ENMFILE)
-# define ENMFILE 89 /* No more files */
-#endif
-#if !defined(ENOTEMPTY)
-# define ENOTEMPTY 90 /* Directory not empty */
-#endif
-#if !defined(ENAMETOOLONG)
-# define ENAMETOOLONG 91 /* File or path name too long */
-#endif
-#if !defined(EPFNOSUPPORT)
-# define EPFNOSUPPORT 96 /* Protocol family not supported */
-#endif
-#if !defined(ENOSHARE)
-# define ENOSHARE 97 /* No such host or network path */
-#endif
-#if !defined(ENOMEDIUM)
-# define ENOMEDIUM 98 /* No medium (in tape drive) */
-#endif
-#if !defined(ESHUTDOWN)
-# define ESHUTDOWN 99 /* Can't send after socket shutdown */
-#endif
-#if !defined(EADDRINUSE)
-# define EADDRINUSE 100 /* Address already in use */
-#endif
-#if !defined(EADDRNOTAVAIL)
-# define EADDRNOTAVAIL 101 /* Address not available */
-#endif
-#if !defined(EAFNOSUPPORT)
-# define EAFNOSUPPORT 102 /* Address family not supported by protocol family */
-#endif
-#if !defined(EALREADY)
-# define EALREADY 103 /* Socket already connected */
-#endif
-#if !defined(ECANCELED)
-# define ECANCELED 105 /* Connection cancelled */
-#endif
-#if !defined(ECONNABORTED)
-# define ECONNABORTED 106 /* Connection aborted */
-#endif
-#if !defined(ECONNREFUSED)
-# define ECONNREFUSED 107 /* Connection refused */
-#endif
-#if !defined(ECONNRESET)
-# define ECONNRESET 108 /* Connection reset by peer */
-#endif
-#if !defined(EDESTADDRREQ)
-# define EDESTADDRREQ 109 /* Destination address required */
-#endif
-#if !defined(EHOSTUNREACH)
-# define EHOSTUNREACH 110 /* Host is unreachable */
-#endif
-#if !defined(ECONNABORTED)
-# define ECONNABORTED 111 /* Connection aborted */
-#endif
-#if !defined(EINPROGRESS)
-# define EINPROGRESS 112 /* Connection already in progress */
-#endif
-#if !defined(EISCONN)
-# define EISCONN 113 /* Socket is already connected */
-#endif
-#if !defined(ELOOP)
-# define ELOOP 114 /* Too many symbolic links */
-#endif
-#if !defined(EMSGSIZE)
-# define EMSGSIZE 115 /* Message too long */
-#endif
-#if !defined(ENETDOWN)
-# define ENETDOWN 116 /* Network interface is not configured */
-#endif
-#if !defined(ENETRESET)
-# define ENETRESET 117 /* Connection aborted by network */
-#endif
-#if !defined(ENETUNREACH)
-# define ENETUNREACH 118 /* Network is unreachable */
-#endif
-#if !defined(ENOBUFS)
-# define ENOBUFS 119 /* No buffer space available */
-#endif
-#if !defined(EHOSTDOWN)
-# define EHOSTDOWN 120 /* Host is down */
-#endif
-#if !defined(EPROCLIM)
-# define EPROCLIM 121 /* Too many processes */
-#endif
-#if !defined(EDQUOT)
-# define EDQUOT 122 /* Disk quota exceeded */
-#endif
-#if !defined(ENOPROTOOPT)
-# define ENOPROTOOPT 123 /* Protocol not available */
-#endif
-#if !defined(ESOCKTNOSUPPORT)
-# define ESOCKTNOSUPPORT 124 /* Socket type not supported */
-#endif
-#if !defined(ESTALE)
-# define ESTALE 125 /* Unknown error */
-#endif
-#if !defined(ENOTCONN)
-# define ENOTCONN 126 /* Socket is not connected */
-#endif
-#if !defined(ETOOMANYREFS)
-# define ETOOMANYREFS 127 /* Too many references: cannot splice */
-#endif
-#if !defined(ENOTSOCK)
-# define ENOTSOCK 128 /* Socket operation on non-socket */
-#endif
-#if !defined(ENOTSUP)
-# define ENOTSUP 129 /* Not supported */
-#endif
-#if !defined(EOPNOTSUPP)
-# define EOPNOTSUPP 130 /* Operation not supported on transport endpoint */
-#endif
-#if !defined(EUSERS)
-# define EUSERS 131 /* Too many users */
-#endif
-#if !defined(EOVERFLOW)
-# define EOVERFLOW 132 /* Value too large for defined data type */
-#endif
-#if !defined(EOWNERDEAD)
-# define EOWNERDEAD 133 /* Unknown error */
-#endif
-#if !defined(EPROTO)
-# define EPROTO 134 /* Protocol error */
-#endif
-#if !defined(EPROTONOSUPPORT)
-# define EPROTONOSUPPORT 135 /* Unknown protocol */
-#endif
-#if !defined(EPROTOTYPE)
-# define EPROTOTYPE 136 /* Protocol wrong type for socket */
-#endif
-#if !defined(ECASECLASH)
-# define ECASECLASH 137 /* Filename exists with different case */
-#endif
-#if !defined(ETIMEDOUT)
-/* Make sure it's the same as WSATIMEDOUT */
-# define ETIMEDOUT 138 /* Connection timed out */
-#endif
-#if !defined(EWOULDBLOCK) || EWOULDBLOCK == 140
-# undef EWOULDBLOCK /* MinGW-w64 defines it as 140, but we want it as EAGAIN */
-# define EWOULDBLOCK EAGAIN /* Operation would block */
-#endif
-
-#undef HOST_NOT_FOUND
-#define HOST_NOT_FOUND 1
-#undef TRY_AGAIN
-#define TRY_AGAIN 2
-#undef NO_RECOVERY
-#define NO_RECOVERY 3
-#undef NO_ADDRESS
-#define NO_ADDRESS 4
-
-#define PROT_READ 0x1
-#define PROT_WRITE 0x2
-#define MAP_SHARED 0x1
-#define MAP_PRIVATE 0x2 /* unsupported */
-#define MAP_FIXED 0x10
-#define MAP_ANONYMOUS 0x20 /* unsupported */
-#define MAP_FAILED ((void *)-1)
-
-#define MS_ASYNC 1 /* sync memory asynchronously */
-#define MS_INVALIDATE 2 /* invalidate the caches */
-#define MS_SYNC 4 /* synchronous memory sync */
-
-struct statfs
-{
- long f_type; /* type of filesystem (see below) */
- long f_bsize; /* optimal transfer block size */
- long f_blocks; /* total data blocks in file system */
- long f_bfree; /* free blocks in fs */
- long f_bavail; /* free blocks avail to non-superuser */
- long f_files; /* total file nodes in file system */
- long f_ffree; /* free file nodes in fs */
- long f_fsid; /* file system id */
- long f_namelen; /* maximum length of filenames */
- long f_spare[6]; /* spare for later */
-};
-#define sleep(secs) (Sleep(secs * 1000))
-
-/*********************** statfs *****************************/
-/* fake block size */
-#define FAKED_BLOCK_SIZE 512
-
-/* linux-compatible values for fs type */
-#define MSDOS_SUPER_MAGIC 0x4d44
-#define NTFS_SUPER_MAGIC 0x5346544E
-
-/*********************** End of statfs ***********************/
-
-#define SHUT_RDWR SD_BOTH
-
-/* Operations for flock() */
-#define LOCK_SH 1 /* shared lock */
-#define LOCK_EX 2 /* exclusive lock */
-#define LOCK_NB 4 /* or'd with one of the above to prevent
- blocking */
-#define LOCK_UN 8 /* remove lock */
-
-/* Not supported under MinGW */
-#ifndef S_IRGRP
-#define S_IRGRP 0
-#endif
-#ifndef S_IWGRP
-#define S_IWGRP 0
-#endif
-#ifndef S_IROTH
-#define S_IROTH 0
-#endif
-#ifndef S_IXGRP
-#define S_IXGRP 0
-#endif
-#ifndef S_IWOTH
-#define S_IWOTH 0
-#endif
-#ifndef S_IXOTH
-#define S_IXOTH 0
-#endif
-#ifndef S_ISUID
-#define S_ISUID 0
-#endif
-#ifndef S_ISGID
-#define S_ISGID 0
-#endif
-#ifndef S_ISVTX
-#define S_ISVTX 0
-#endif
-#ifndef S_IRWXG
-#define S_IRWXG 0
-#endif
-#ifndef S_IRWXO
-#define S_IRWXO 0
-#endif
-
-#define SHUT_WR SD_SEND
-#define SHUT_RD SD_RECEIVE
-#define SHUT_RDWR SD_BOTH
-
-#define SIGKILL 9
-#define SIGTERM 15
-
-#define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__)
-
-BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest);
-BOOL _plibc_CreateShortcutW(const wchar_t *pwszSrc, const wchar_t *pwszDest);
-BOOL _plibc_DereferenceShortcut(char *pszShortcut);
-BOOL _plibc_DereferenceShortcutW(wchar_t *pwszShortcut);
-char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
-wchar_t *plibc_ChooseDirW(wchar_t *pwszTitle, unsigned long ulFlags);
-char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
-wchar_t *plibc_ChooseFileW(wchar_t *pwszTitle, unsigned long ulFlags);
-
-long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey,
- char *pszBuffer, long *pdLength);
-long QueryRegistryW(HKEY hMainKey, const wchar_t *pszKey, const wchar_t *pszSubKey,
- wchar_t *pszBuffer, long *pdLength);
-
-BOOL __win_IsHandleMarkedAsBlocking(int hHandle);
-void __win_SetHandleBlockingMode(int s, BOOL bBlocking);
-void __win_DiscardHandleBlockingMode(int s);
-int _win_isSocketValid(int s);
-int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
-int plibc_conv_to_win_pathw(const wchar_t *pszUnix, wchar_t *pwszWindows);
-
-int plibc_conv_to_win_pathwconv(const char *pszUnix, wchar_t *pwszWindows);
-int plibc_conv_to_win_pathwconv_ex(const char *pszUnix, wchar_t *pszWindows, int derefLinks);
-
-unsigned plibc_get_handle_count();
-
-typedef void (*TPanicProc) (int, char *);
-void plibc_set_panic_proc(TPanicProc proc);
-void plibc_set_stat_size_size(int iLength);
-void plibc_set_stat_time_size(int iLength);
-
-int flock(int fd, int operation);
-int fsync(int fildes);
-int inet_pton(int af, const char *src, void *dst);
-int inet_pton4(const char *src, u_char *dst, int pton);
-#if USE_IPV6
-int inet_pton6(const char *src, u_char *dst);
-#endif
-int statfs(const char *path, struct statfs *buf);
-const char *hstrerror(int err);
-int mkstemp(char *tmplate);
-char *strptime (const char *buf, const char *format, struct tm *tm);
-const char *inet_ntop(int af, const void *src, char *dst, size_t size);
-#ifndef gmtime_r
-struct tm *gmtime_r(const time_t *clock, struct tm *result);
-#endif
-
-int plibc_init(char *pszOrg, char *pszApp);
-int plibc_init_utf8(char *pszOrg, char *pszApp, int utf8_mode);
-void plibc_shutdown();
-int plibc_initialized();
-
-void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine);
-void SetErrnoFromWinsockError(long lWinError);
-void SetHErrnoFromWinError(long lWinError);
-void SetErrnoFromHRESULT(HRESULT hRes);
-int GetErrnoFromWinsockError(long lWinError);
-FILE *_win_fopen(const char *filename, const char *mode);
-int _win_fclose(FILE *);
-DIR *_win_opendir(const char *dirname);
-struct dirent *_win_readdir(DIR *dirp);
-int _win_closedir(DIR *dirp);
-int _win_open(const char *filename, int oflag, ...);
-#ifdef ENABLE_NLS
-char *_win_bindtextdomain(const char *domainname, const char *dirname);
-#endif
-int _win_chdir(const char *path);
-int _win_close(int fd);
-int _win_creat(const char *path, mode_t mode);
-char *_win_ctime(const time_t *clock);
-char *_win_ctime_r(const time_t *clock, char *buf);
-int _win_fstat(int handle, struct stat *buffer);
-int _win_ftruncate(int fildes, off_t length);
-int _win_truncate(const char *fname, int distance);
-int _win_kill(pid_t pid, int sig);
-int _win_pipe(int *phandles);
-int _win_mkfifo(const char *path, mode_t mode);
-int _win_rmdir(const char *path);
-int _win_access( const char *path, int mode );
-int _win_chmod(const char *filename, int pmode);
-char *realpath(const char *file_name, char *resolved_name);
-long _win_random(void);
-void _win_srandom(unsigned int seed);
-int _win_remove(const char *path);
-int _win_rename(const char *oldname, const char *newname);
-int _win_stat(const char *path, struct stat *buffer);
-int _win_stati64(const char *path, struct _stati64 *buffer);
-long _win_sysconf(int name);
-int _win_unlink(const char *filename);
-int _win_write(int fildes, const void *buf, size_t nbyte);
-int _win_read(int fildes, void *buf, size_t nbyte);
-size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream);
-size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream );
-int _win_symlink(const char *path1, const char *path2);
-void *_win_mmap(void *start, size_t len, int access, int flags, int fd,
- unsigned long long offset);
-int _win_msync(void *start, size_t length, int flags);
-int _win_munmap(void *start, size_t length);
-int _win_lstat(const char *path, struct stat *buf);
-int _win_lstati64(const char *path, struct _stati64 *buf);
-int _win_readlink(const char *path, char *buf, size_t bufsize);
-int _win_accept(int s, struct sockaddr *addr, int *addrlen);
-
-pid_t _win_waitpid(pid_t pid, int *stat_loc, int options);
-int _win_bind(int s, const struct sockaddr *name, int namelen);
-int _win_connect(int s,const struct sockaddr *name, int namelen);
-int _win_getpeername(int s, struct sockaddr *name,
- int *namelen);
-int _win_getsockname(int s, struct sockaddr *name,
- int *namelen);
-int _win_getsockopt(int s, int level, int optname, char *optval,
- int *optlen);
-int _win_listen(int s, int backlog);
-int _win_recv(int s, char *buf, int len, int flags);
-int _win_recvfrom(int s, void *buf, int len, int flags,
- struct sockaddr *from, int *fromlen);
-int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds,
- const struct timeval *tv);
-int _win_send(int s, const char *buf, int len, int flags);
-int _win_sendto(int s, const char *buf, int len, int flags,
- const struct sockaddr *to, int tolen);
-int _win_setsockopt(int s, int level, int optname, const void *optval,
- int optlen);
-int _win_shutdown(int s, int how);
-int _win_socket(int af, int type, int protocol);
-int _win_socketpair(int af, int type, int protocol, int socket_vector[2]);
-struct hostent *_win_gethostbyaddr(const char *addr, int len, int type);
-struct hostent *_win_gethostbyname(const char *name);
-struct hostent *gethostbyname2(const char *name, int af);
-char *_win_strerror(int errnum);
-int IsWinNT();
-char *index(const char *s, int c);
-char *_win_strtok_r (char *ptr, const char *sep, char **end);
-
-#if !HAVE_STRNDUP
-char *strndup (const char *s, size_t n);
-#endif
-#if !HAVE_STRNLEN && (!defined(__MINGW64_VERSION_MAJOR) || !defined(_INC_STRING))
-size_t strnlen (const char *str, size_t maxlen);
-#endif
-char *stpcpy(char *dest, const char *src);
-char *strcasestr(const char *haystack_start, const char *needle_start);
-#ifndef __MINGW64_VERSION_MAJOR
-#define strcasecmp(a, b) stricmp(a, b)
-#define strncasecmp(a, b, c) strnicmp(a, b, c)
-#endif
-#ifndef wcscasecmp
-#define wcscasecmp(a, b) wcsicmp(a, b)
-#endif
-#ifndef wcsncasecmp
-#define wcsncasecmp(a, b, c) wcsnicmp(a, b, c)
-#endif
-#ifndef strtok_r /* winpthreads defines it in pthread.h */
-#define strtok_r _win_strtok_r
-#endif
-#endif /* WINDOWS */
-
-#ifndef WINDOWS
- #define DIR_SEPARATOR '/'
- #define DIR_SEPARATOR_STR "/"
- #define PATH_SEPARATOR ':'
- #define PATH_SEPARATOR_STR ":"
- #define NEWLINE "\n"
-
-#ifdef ENABLE_NLS
- #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n)
-#endif
- #define CREAT(p, m) creat(p, m)
- #define PLIBC_CTIME(c) ctime(c)
- #define CTIME_R(c, b) ctime_r(c, b)
- #undef FOPEN
- #define FOPEN(f, m) fopen(f, m)
- #define FCLOSE(f) fclose(f)
- #define FTRUNCATE(f, l) ftruncate(f, l)
- #define TRUNCATE(f, l) truncate(f, l)
- #define OPENDIR(d) opendir(d)
- #define CLOSEDIR(d) closedir(d)
- #define READDIR(d) readdir(d)
- #define OPEN open
- #define CHDIR(d) chdir(d)
- #define CLOSE(f) close(f)
- #define LSEEK(f, o, w) lseek(f, o, w)
- #define RMDIR(f) rmdir(f)
- #define ACCESS(p, m) access(p, m)
- #define CHMOD(f, p) chmod(f, p)
- #define FSTAT(h, b) fstat(h, b)
- #define PLIBC_KILL(p, s) kill(p, s)
- #define PIPE(h) pipe(h)
- #define REMOVE(p) remove(p)
- #define RENAME(o, n) rename(o, n)
- #define STAT(p, b) stat(p, b)
- #define STAT64(p, b) stat64(p, b)
- #define SYSCONF(n) sysconf(n)
- #define UNLINK(f) unlink(f)
- #define WRITE(f, b, n) write(f, b, n)
- #define READ(f, b, n) read(f, b, n)
- #define GN_FREAD(b, s, c, f) fread(b, s, c, f)
- #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f)
- #define SYMLINK(a, b) symlink(a, b)
- #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o)
- #define MKFIFO(p, m) mkfifo(p, m)
- #define MSYNC(s, l, f) msync(s, l, f)
- #define MUNMAP(s, l) munmap(s, l)
- #define STRERROR(i) strerror(i)
- #define RANDOM() random()
- #define SRANDOM(s) srandom(s)
- #define READLINK(p, b, s) readlink(p, b, s)
- #define LSTAT(p, b) lstat(p, b)
- #define LSTAT64(p, b) lstat64(p, b)
- #define PRINTF printf
- #define FPRINTF fprintf
- #define VPRINTF(f, a) vprintf(f, a)
- #define VFPRINTF(s, f, a) vfprintf(s, f, a)
- #define VSPRINTF(d, f, a) vsprintf(d, f, a)
- #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
- #define _REAL_SNPRINTF snprintf
- #define SPRINTF sprintf
- #define VSSCANF(s, f, a) vsscanf(s, f, a)
- #define SSCANF sscanf
- #define VFSCANF(s, f, a) vfscanf(s, f, a)
- #define VSCANF(f, a) vscanf(f, a)
- #define SCANF scanf
- #define FSCANF fscanf
- #define WAITPID(p, s, o) waitpid(p, s, o)
- #define ACCEPT(s, a, l) accept(s, a, l)
- #define BIND(s, n, l) bind(s, n, l)
- #define CONNECT(s, n, l) connect(s, n, l)
- #define GETPEERNAME(s, n, l) getpeername(s, n, l)
- #define GETSOCKNAME(s, n, l) getsockname(s, n, l)
- #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p)
- #define LISTEN(s, b) listen(s, b)
- #define RECV(s, b, l, f) recv(s, b, l, f)
- #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o)
- #define SELECT(n, r, w, e, t) select(n, r, w, e, t)
- #define SEND(s, b, l, f) send(s, b, l, f)
- #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n)
- #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n)
- #define SHUTDOWN(s, h) shutdown(s, h)
- #define SOCKET(a, t, p) socket(a, t, p)
- #define SOCKETPAIR(a, t, p, v) socketpair(a, t, p, v)
- #define GETHOSTBYADDR(a, l, t) gethostbyaddr(a, l, t)
- #define GETHOSTBYNAME(n) gethostbyname(n)
- #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
- #define INSQUE(e, p) insque(e, p)
- #define REMQUE(e) remque(e)
- #define HSEARCH(i, a) hsearch(i, a)
- #define HCREATE(n) hcreate(n)
- #define HDESTROY() hdestroy()
- #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h)
- #define HCREATE_R(n, h) hcreate_r(n, h)
- #define HDESTROY_R(h) hdestroy_r(h)
- #define TSEARCH(k, r, c) tsearch(k, r, c)
- #define TFIND(k, r, c) tfind(k, r, c)
- #define TDELETE(k, r, c) tdelete(k, r, c)
- #define TWALK(r, a) twalk(r, a)
- #define TDESTROY(r, f) tdestroy(r, f)
- #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c)
- #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c)
- #define STRUCT_STAT64 struct stat64
-#else
- #define DIR_SEPARATOR '\\'
- #define DIR_SEPARATOR_STR "\\"
- #define PATH_SEPARATOR ';'
- #define PATH_SEPARATOR_STR ";"
- #define NEWLINE "\r\n"
-
-#ifdef ENABLE_NLS
- #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n)
-#endif
- #define CREAT(p, m) _win_creat(p, m)
- #define PLIBC_CTIME(c) _win_ctime(c)
- #define CTIME_R(c, b) _win_ctime_r(c, b)
- #define FOPEN(f, m) _win_fopen(f, m)
- #define FCLOSE(f) _win_fclose(f)
- #define FTRUNCATE(f, l) _win_ftruncate(f, l)
- #define TRUNCATE(f, l) _win_truncate(f, l)
- #define OPENDIR(d) _win_opendir(d)
- #define CLOSEDIR(d) _win_closedir(d)
- #define READDIR(d) _win_readdir(d)
- #define OPEN _win_open
- #define CHDIR(d) _win_chdir(d)
- #define CLOSE(f) _win_close(f)
- #define PLIBC_KILL(p, s) _win_kill(p, s)
- #define LSEEK(f, o, w) lseek(f, o, w)
- #define FSTAT(h, b) _win_fstat(h, b)
- #define RMDIR(f) _win_rmdir(f)
- #define ACCESS(p, m) _win_access(p, m)
- #define CHMOD(f, p) _win_chmod(f, p)
- #define PIPE(h) _win_pipe(h)
- #define RANDOM() _win_random()
- #define SRANDOM(s) _win_srandom(s)
- #define REMOVE(p) _win_remove(p)
- #define RENAME(o, n) _win_rename(o, n)
- #define STAT(p, b) _win_stat(p, b)
- #define STAT64(p, b) _win_stati64(p, b)
- #define SYSCONF(n) _win_sysconf(n)
- #define UNLINK(f) _win_unlink(f)
- #define WRITE(f, b, n) _win_write(f, b, n)
- #define READ(f, b, n) _win_read(f, b, n)
- #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f)
- #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f)
- #define SYMLINK(a, b) _win_symlink(a, b)
- #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o)
- #define MKFIFO(p, m) _win_mkfifo(p, m)
- #define MSYNC(s, l, f) _win_msync(s, l, f)
- #define MUNMAP(s, l) _win_munmap(s, l)
- #define STRERROR(i) _win_strerror(i)
- #define READLINK(p, b, s) _win_readlink(p, b, s)
- #define LSTAT(p, b) _win_lstat(p, b)
- #define LSTAT64(p, b) _win_lstati64(p, b)
- #define PRINTF printf
- #define FPRINTF fprintf
- #define VPRINTF(f, a) vprintf(f, a)
- #define VFPRINTF(s, f, a) vfprintf(s, f, a)
- #define VSPRINTF(d, f, a) vsprintf(d, f, a)
- #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a)
- #define _REAL_SNPRINTF snprintf
- #define SPRINTF sprintf
- #define VSSCANF(s, f, a) vsscanf(s, f, a)
- #define SSCANF sscanf
- #define VFSCANF(s, f, a) vfscanf(s, f, a)
- #define VSCANF(f, a) vscanf(f, a)
- #define SCANF scanf
- #define FSCANF fscanf
- #define WAITPID(p, s, o) _win_waitpid(p, s, o)
- #define ACCEPT(s, a, l) _win_accept(s, a, l)
- #define BIND(s, n, l) _win_bind(s, n, l)
- #define CONNECT(s, n, l) _win_connect(s, n, l)
- #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l)
- #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l)
- #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p)
- #define LISTEN(s, b) _win_listen(s, b)
- #define RECV(s, b, l, f) _win_recv(s, b, l, f)
- #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o)
- #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t)
- #define SEND(s, b, l, f) _win_send(s, b, l, f)
- #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n)
- #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n)
- #define SHUTDOWN(s, h) _win_shutdown(s, h)
- #define SOCKET(a, t, p) _win_socket(a, t, p)
- #define SOCKETPAIR(a, t, p, v) _win_socketpair(a, t, p, v)
- #define GETHOSTBYADDR(a, l, t) _win_gethostbyaddr(a, l, t)
- #define GETHOSTBYNAME(n) _win_gethostbyname(n)
- #define GETTIMEOFDAY(t, n) gettimeofday(t, n)
- #define INSQUE(e, p) _win_insque(e, p)
- #define REMQUE(e) _win_remque(e)
- #define HSEARCH(i, a) _win_hsearch(i, a)
- #define HCREATE(n) _win_hcreate(n)
- #define HDESTROY() _win_hdestroy()
- #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h)
- #define HCREATE_R(n, h) _win_hcreate_r(n, h)
- #define HDESTROY_R(h) _win_hdestroy_r(h)
- #define TSEARCH(k, r, c) _win_tsearch(k, r, c)
- #define TFIND(k, r, c) _win_tfind(k, r, c)
- #define TDELETE(k, r, c) _win_tdelete(k, r, c)
- #define TWALK(r, a) _win_twalk(r, a)
- #define TDESTROY(r, f) _win_tdestroy(r, f)
- #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c)
- #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c)
- #define STRUCT_STAT64 struct _stati64
-#endif
-
-/* search.h */
-
-/* Prototype structure for a linked-list data structure.
- This is the type used by the `insque' and `remque' functions. */
-
-struct PLIBC_SEARCH_QELEM
- {
- struct qelem *q_forw;
- struct qelem *q_back;
- char q_data[1];
- };
-
-
-/* Insert ELEM into a doubly-linked list, after PREV. */
-void _win_insque (void *__elem, void *__prev);
-
-/* Unlink ELEM from the doubly-linked list that it is in. */
-void _win_remque (void *__elem);
-
-
-/* For use with hsearch(3). */
-typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *);
-
-typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
-
-/* Action which shall be performed in the call the hsearch. */
-typedef enum
- {
- PLIBC_SEARCH_FIND,
- PLIBC_SEARCH_ENTER
- }
-PLIBC_SEARCH_ACTION;
-
-typedef struct PLIBC_SEARCH_entry
- {
- char *key;
- void *data;
- }
-PLIBC_SEARCH_ENTRY;
-
-/* The reentrant version has no static variables to maintain the state.
- Instead the interface of all functions is extended to take an argument
- which describes the current status. */
-typedef struct _PLIBC_SEARCH_ENTRY
-{
- unsigned int used;
- PLIBC_SEARCH_ENTRY entry;
-}
-_PLIBC_SEARCH_ENTRY;
-
-
-/* Family of hash table handling functions. The functions also
- have reentrant counterparts ending with _r. The non-reentrant
- functions all work on a signle internal hashing table. */
-
-/* Search for entry matching ITEM.key in internal hash table. If
- ACTION is `FIND' return found entry or signal error by returning
- NULL. If ACTION is `ENTER' replace existing data (if any) with
- ITEM.data. */
-PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action);
-
-/* Create a new hashing table which will at most contain NEL elements. */
-int _win_hcreate (size_t __nel);
-
-/* Destroy current internal hashing table. */
-void _win_hdestroy (void);
-
-/* Data type for reentrant functions. */
-struct PLIBC_SEARCH_hsearch_data
- {
- struct _PLIBC_SEARCH_ENTRY *table;
- unsigned int size;
- unsigned int filled;
- };
-
-/* Reentrant versions which can handle multiple hashing tables at the
- same time. */
-int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval,
- struct PLIBC_SEARCH_hsearch_data *__htab);
-int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
-void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
-
-
-/* The tsearch routines are very interesting. They make many
- assumptions about the compiler. It assumes that the first field
- in node must be the "key" field, which points to the datum.
- Everything depends on that. */
-/* For tsearch */
-typedef enum
-{
- PLIBC_SEARCH_preorder,
- PLIBC_SEARCH_postorder,
- PLIBC_SEARCH_endorder,
- PLIBC_SEARCH_leaf
-}
-PLIBC_SEARCH_VISIT;
-
-/* Search for an entry matching the given KEY in the tree pointed to
- by *ROOTP and insert a new element if not found. */
-void *_win_tsearch (__const void *__key, void **__rootp,
- PLIBC_SEARCH__compar_fn_t __compar);
-
-/* Search for an entry matching the given KEY in the tree pointed to
- by *ROOTP. If no matching entry is available return NULL. */
-void *_win_tfind (__const void *__key, void *__const *__rootp,
- PLIBC_SEARCH__compar_fn_t __compar);
-
-/* Remove the element matching KEY from the tree pointed to by *ROOTP. */
-void *_win_tdelete (__const void *__restrict __key,
- void **__restrict __rootp,
- PLIBC_SEARCH__compar_fn_t __compar);
-
-typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value,
- int __level);
-
-/* Walk through the whole tree and call the ACTION callback for every node
- or leaf. */
-void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action);
-
-/* Callback type for function to free a tree node. If the keys are atomic
- data this function should do nothing. */
-typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep);
-
-/* Destroy the whole tree, call FREEFCT for each node or leaf. */
-void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
-
-
-/* Perform linear search for KEY by comparing by COMPAR in an array
- [BASE,BASE+NMEMB*SIZE). */
-void *_win_lfind (__const void *__key, __const void *__base,
- size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
-
-/* Perform linear search for KEY by comparing by COMPAR function in
- array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
-void *_win_lsearch (__const void *__key, void *__base,
- size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //_PLIBC_H_
-
-/* end of plibc.h */
*json = json_loads (value, JSON_REJECT_DUPLICATES, &error);
if (NULL == *json)
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Failed to parse JSON in option `%s': %s (%s)\n"),
option,
error.text,
*/
static void
display_records_from_block (void *cls,
- unsigned int rd_len,
- const struct GNUNET_GNSRECORD_Data *rd)
+ unsigned int rd_len,
+ const struct GNUNET_GNSRECORD_Data *rd)
{
const char *typestring;
char *s;
if (0 == rd_len)
{
- FPRINTF (stdout,
- _("No records found for `%s'"),
- name);
+ fprintf (stdout, _ ("No records found for `%s'"), name);
return;
}
- FPRINTF (stdout,
- "%s:\n",
- name);
- for (i=0;i<rd_len;i++)
+ fprintf (stdout, "%s:\n", name);
+ for (i = 0; i < rd_len; i++)
{
typestring = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
- rd[i].data,
- rd[i].data_size);
+ rd[i].data,
+ rd[i].data_size);
if (NULL == s)
{
- FPRINTF (stdout, _("\tCorrupt or unsupported record of type %u\n"),
- (unsigned int) rd[i].record_type);
+ fprintf (stdout,
+ _ ("\tCorrupt or unsupported record of type %u\n"),
+ (unsigned int) rd[i].record_type);
continue;
}
- FPRINTF (stdout,
- "\t%s: %s\n",
- typestring,
- s);
+ fprintf (stdout, "\t%s: %s\n", typestring, s);
GNUNET_free (s);
}
- FPRINTF (stdout, "%s", "\n");
+ fprintf (stdout, "%s", "\n");
}
* @param block NULL if not found
*/
static void
-handle_block (void *cls,
- const struct GNUNET_GNSRECORD_Block *block)
+handle_block (void *cls, const struct GNUNET_GNSRECORD_Block *block)
{
qe = NULL;
if (NULL == block)
{
- fprintf (stderr,
- "No matching block found\n");
+ fprintf (stderr, "No matching block found\n");
}
else if (GNUNET_OK !=
- GNUNET_GNSRECORD_block_decrypt (block,
- &pubkey,
- name,
- &display_records_from_block,
- NULL))
+ GNUNET_GNSRECORD_block_decrypt (block,
+ &pubkey,
+ name,
+ &display_records_from_block,
+ NULL))
{
- fprintf (stderr,
- "Failed to decrypt block!\n");
+ fprintf (stderr, "Failed to decrypt block!\n");
}
GNUNET_SCHEDULER_shutdown ();
}
* @param cfg configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_HashCode dhash;
if (NULL == pkey)
{
- fprintf (stderr,
- _("You must specify which zone should be accessed\n"));
+ fprintf (stderr, _ ("You must specify which zone should be accessed\n"));
return;
}
if (GNUNET_OK !=
- GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey,
- strlen (pkey),
- &pubkey))
+ GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey, strlen (pkey), &pubkey))
{
- fprintf (stderr,
- _("Invalid public key for zone `%s'\n"),
- pkey);
+ fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey);
GNUNET_SCHEDULER_shutdown ();
return;
}
if (NULL == name)
{
- fprintf (stderr,
- _("You must specify a name\n"));
+ fprintf (stderr, _ ("You must specify a name\n"));
return;
}
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
ns = GNUNET_NAMECACHE_connect (cfg);
- GNUNET_GNSRECORD_query_from_public_key (&pubkey,
- name,
- &dhash);
- qe = GNUNET_NAMECACHE_lookup_block (ns,
- &dhash,
- &handle_block,
- NULL);
+ GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &dhash);
+ qe = GNUNET_NAMECACHE_lookup_block (ns, &dhash, &handle_block, NULL);
}
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_string ('n',
- "name",
- "NAME",
- gettext_noop ("name of the record to add/delete/display"),
- &name),
-
- GNUNET_GETOPT_option_string ('z',
- "zone",
- "PKEY",
- gettext_noop ("specifies the public key of the zone to look in"),
- &pkey),
-
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_string ('n',
+ "name",
+ "NAME",
+ gettext_noop (
+ "name of the record to add/delete/display"),
+ &name),
+
+ GNUNET_GETOPT_option_string (
+ 'z',
+ "zone",
+ "PKEY",
+ gettext_noop ("specifies the public key of the zone to look in"),
+ &pkey),
+
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
GNUNET_log_setup ("gnunet-namecache", "WARNING", NULL);
- if (GNUNET_OK !=
- GNUNET_PROGRAM_run (argc, argv, "gnunet-namecache",
- _("GNUnet zone manipulation tool"),
- options,
- &run, NULL))
+ if (GNUNET_OK != GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-namecache",
+ _ ("GNUnet zone manipulation tool"),
+ options,
+ &run,
+ NULL))
{
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
return 1;
}
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
return ret;
}
GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
{
- FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name);
+ fprintf (stderr, "Failed to load plugin `%s'!\n", plugin_name);
GNUNET_free (libname);
return NULL;
}
nsp = load_plugin (cfg);
if (NULL == nsp)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Failed to initialize namecache. Database likely not setup, skipping test.\n");
return;
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
"test-plugin-namecache", "nohelp", options, &run, NULL);
if (ok != 0)
- FPRINTF (stderr, "Missed some testcases: %d\n", ok);
+ fprintf (stderr, "Missed some testcases: %d\n", ok);
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite");
return ok;
}
}
if (GNUNET_NO == have_record)
return;
- FPRINTF (stdout, "%s:\n", rname);
+ fprintf (stdout, "%s:\n", rname);
if (NULL != typestring)
type = GNUNET_GNSRECORD_typename_to_number (typestring);
else
rd[i].data_size);
if (NULL == s)
{
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("\tCorrupt or unsupported record of type %u\n"),
(unsigned int) rd[i].record_type);
continue;
at.abs_value_us = rd[i].expiration_time;
ets = GNUNET_STRINGS_absolute_time_to_string (at);
}
- FPRINTF (stdout,
+ fprintf (stdout,
"\t%s: %s (%s)\t%s\t%s\n",
typestr,
s,
: "");
GNUNET_free (s);
}
- FPRINTF (stdout, "%s", "\n");
+ fprintf (stdout, "%s", "\n");
}
sync_cb (void *cls)
{
(void) cls;
- FPRINTF (stdout, "%s", "Monitor is now in sync.\n");
+ fprintf (stdout, "%s", "Monitor is now in sync.\n");
}
monitor_error_cb (void *cls)
{
(void) cls;
- FPRINTF (stderr, "%s", "Monitor disconnected and out of sync.\n");
+ fprintf (stderr, "%s", "Monitor disconnected and out of sync.\n");
}
{
(void) cls;
get_qe = NULL;
- FPRINTF (stderr, "%s", "Failed to lookup record.\n");
+ fprintf (stderr, "%s", "Failed to lookup record.\n");
test_finished ();
}
{
(void) cls;
reverse_qe = NULL;
- FPRINTF (stdout, "%s.zkey\n", reverse_pkey);
+ fprintf (stdout, "%s.zkey\n", reverse_pkey);
}
(void) rd;
reverse_qe = NULL;
if (NULL == label)
- FPRINTF (stdout, "%s\n", reverse_pkey);
+ fprintf (stdout, "%s\n", reverse_pkey);
else
- FPRINTF (stdout, "%s.%s\n", label, ego_name);
+ fprintf (stdout, "%s.%s\n", label, ego_name);
test_finished ();
}
del_qe = NULL;
if (0 == rd_count)
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ (
"There are no records under label `%s' that could be deleted.\n"),
label);
if (rd_count == rd_left)
{
/* nothing got deleted */
- FPRINTF (
+ fprintf (
stderr,
_ (
"There are no records under label `%s' that match the request for deletion.\n"),
GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void *) cfg)))
{
- FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name);
+ fprintf (stderr, "Failed to load plugin `%s'!\n", plugin_name);
GNUNET_free (libname);
return NULL;
}
nsp = load_plugin (cfg);
if (NULL == nsp)
{
- FPRINTF (
+ fprintf (
stderr,
"%s",
"Failed to initialize namestore. Database likely not setup, skipping test.\n");
NULL);
GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP");
if (ok != 0)
- FPRINTF (stderr, "Missed some testcases: %d\n", ok);
+ fprintf (stderr, "Missed some testcases: %d\n", ok);
return ok;
}
{
struct GNUNET_CONFIGURATION_Handle *new_cfg = cls;
- PRINTF ("%s: %s\n",
- option,
- value);
+ printf ("%s: %s\n", option, value);
if (NULL != new_cfg)
- GNUNET_CONFIGURATION_set_value_string (new_cfg,
- section,
- option,
- value);
+ GNUNET_CONFIGURATION_set_value_string (new_cfg, section, option, value);
}
*/
static void
auto_config_cb (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *diff,
- enum GNUNET_NAT_StatusCode result,
- enum GNUNET_NAT_Type type)
+ const struct GNUNET_CONFIGURATION_Handle *diff,
+ enum GNUNET_NAT_StatusCode result,
+ enum GNUNET_NAT_Type type)
{
const char *nat_type;
char unknown_type[64];
nat_type = "NAT but UPNP opened the ports";
break;
default:
- SPRINTF (unknown_type,
- "NAT unknown, type %u",
- type);
+ sprintf (unknown_type, "NAT unknown, type %u", type);
nat_type = unknown_type;
break;
}
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "NAT status: %s/%s\n",
- GNUNET_NAT_AUTO_status2string (result),
- nat_type);
+ "NAT status: %s/%s\n",
+ GNUNET_NAT_AUTO_status2string (result),
+ nat_type);
if (NULL == diff)
return;
/* Shortcut: if there are no changes suggested, bail out early. */
- if (GNUNET_NO ==
- GNUNET_CONFIGURATION_is_dirty (diff))
+ if (GNUNET_NO == GNUNET_CONFIGURATION_is_dirty (diff))
{
test_finished ();
return;
new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL;
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- _("Suggested configuration changes:\n"));
+ _ ("Suggested configuration changes:\n"));
GNUNET_CONFIGURATION_iterate_section_values (diff,
"nat",
&auto_conf_iter,
{
struct GNUNET_CONFIGURATION_Handle *def_cfg;
- GNUNET_CONFIGURATION_set_value_string (new_cfg,
- "ARM",
- "CONFIG",
- NULL);
+ GNUNET_CONFIGURATION_set_value_string (new_cfg, "ARM", "CONFIG", NULL);
def_cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_load (def_cfg,
- NULL));
+ GNUNET_break (GNUNET_OK == GNUNET_CONFIGURATION_load (def_cfg, NULL));
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_write_diffs (def_cfg,
- new_cfg,
- cfg_file))
+ GNUNET_CONFIGURATION_write_diffs (def_cfg, new_cfg, cfg_file))
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- _("Failed to write configuration to `%s'\n"),
- cfg_file);
+ _ ("Failed to write configuration to `%s'\n"),
+ cfg_file);
global_ret = 1;
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- _("Wrote updated configuration to `%s'\n"),
- cfg_file);
+ _ ("Wrote updated configuration to `%s'\n"),
+ cfg_file);
}
GNUNET_CONFIGURATION_destroy (def_cfg);
}
* @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
*/
static void
-test_report_cb (void *cls,
- enum GNUNET_NAT_StatusCode result)
+test_report_cb (void *cls, enum GNUNET_NAT_StatusCode result)
{
nt = NULL;
- PRINTF ("NAT test result: %s\n",
- GNUNET_NAT_AUTO_status2string (result));
+ printf ("NAT test result: %s\n", GNUNET_NAT_AUTO_status2string (result));
test_finished ();
}
cfg_file = cfgfile;
cfg = c;
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (do_auto)
{
- ah = GNUNET_NAT_AUTO_autoconfig_start (c,
- &auto_config_cb,
- NULL);
+ ah = GNUNET_NAT_AUTO_autoconfig_start (c, &auto_config_cb, NULL);
}
if (use_tcp && use_udp)
{
if (do_auto)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Cannot use TCP and UDP\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Cannot use TCP and UDP\n");
global_ret = 1;
return;
}
if (NULL != section_name)
{
nt = GNUNET_NAT_AUTO_test_start (c,
- proto,
- section_name,
- &test_report_cb,
- NULL);
+ proto,
+ section_name,
+ &test_report_cb,
+ NULL);
}
test_finished ();
}
* @return 0 on success, -1 on error
*/
int
-main (int argc,
- char *const argv[])
+main (int argc, char *const argv[])
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('a',
- "auto",
- gettext_noop ("run autoconfiguration"),
- &do_auto),
-
- GNUNET_GETOPT_option_string ('S',
- "section",
- "NAME",
- gettext_noop ("section name providing the configuration for the adapter"),
- §ion_name),
-
- GNUNET_GETOPT_option_flag ('t',
- "tcp",
- gettext_noop ("use TCP"),
- &use_tcp),
-
- GNUNET_GETOPT_option_flag ('u',
- "udp",
- gettext_noop ("use UDP"),
- &use_udp),
-
- GNUNET_GETOPT_option_flag ('w',
- "write",
- gettext_noop ("write configuration file (for autoconfiguration)"),
- &write_cfg),
- GNUNET_GETOPT_OPTION_END
- };
-
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag ('a',
+ "auto",
+ gettext_noop ("run autoconfiguration"),
+ &do_auto),
+
+ GNUNET_GETOPT_option_string (
+ 'S',
+ "section",
+ "NAME",
+ gettext_noop (
+ "section name providing the configuration for the adapter"),
+ §ion_name),
+
+ GNUNET_GETOPT_option_flag ('t', "tcp", gettext_noop ("use TCP"), &use_tcp),
+
+ GNUNET_GETOPT_option_flag ('u', "udp", gettext_noop ("use UDP"), &use_udp),
+
+ GNUNET_GETOPT_option_flag (
+ 'w',
+ "write",
+ gettext_noop ("write configuration file (for autoconfiguration)"),
+ &write_cfg),
+ GNUNET_GETOPT_OPTION_END};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
if (GNUNET_OK !=
- GNUNET_PROGRAM_run (argc, argv,
- "gnunet-nat-auto [options]",
- _("GNUnet NAT traversal autoconfiguration"),
- options,
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-nat-auto [options]",
+ _ ("GNUnet NAT traversal autoconfiguration"),
+ options,
&run,
- NULL))
+ NULL))
{
global_ret = 1;
}
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
return global_ret;
}
#include "gnunet_nat_auto_service.h"
#include "nat-auto.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "nat-auto", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "nat-auto", __VA_ARGS__)
-#define NAT_SERVER_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
+#define NAT_SERVER_TIMEOUT \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
/**
* Entry we keep for each incoming connection.
* Handle to overall NAT test.
*/
struct GNUNET_NAT_AUTO_Test *h;
-
};
* @param addrlen actual lenght of the @a addr
*/
static void
-reversal_cb (void *cls,
- const struct sockaddr *addr,
- socklen_t addrlen)
+reversal_cb (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
struct GNUNET_NAT_AUTO_Test *h = cls;
const struct sockaddr_in *sa;
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received connection reversal request for wrong port\n");
- return; /* wrong port */
+ return; /* wrong port */
}
/* report success */
- h->report (h->report_cls,
- GNUNET_NAT_ERROR_SUCCESS);
+ h->report (h->report_cls, GNUNET_NAT_ERROR_SUCCESS);
}
const struct GNUNET_SCHEDULER_TaskContext *tc;
tc = GNUNET_SCHEDULER_get_task_context ();
- tst->ltask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- tst->lsock,
- &do_udp_read,
- tst);
+ tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ tst->lsock,
+ &do_udp_read,
+ tst);
if ((NULL != tc->write_ready) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- tst->lsock)) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) &&
(sizeof (data) ==
- GNUNET_NETWORK_socket_recv (tst->lsock,
- &data,
- sizeof (data))))
+ GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data))))
{
if (data == tst->data)
- tst->report (tst->report_cls,
- GNUNET_NAT_ERROR_SUCCESS);
+ tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS);
else
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received data mismatches expected value\n");
tc = GNUNET_SCHEDULER_get_task_context ();
na->rtask = NULL;
tst = na->h;
- GNUNET_CONTAINER_DLL_remove (tst->na_head,
- tst->na_tail,
- na);
+ GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na);
if ((NULL != tc->write_ready) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- na->sock)) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) &&
(sizeof (data) ==
- GNUNET_NETWORK_socket_recv (na->sock,
- &data,
- sizeof (data))))
+ GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data))))
{
if (data == tst->data)
- tst->report (tst->report_cls,
- GNUNET_NAT_ERROR_SUCCESS);
+ tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS);
else
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received data does not match expected value\n");
tst->lsock,
&do_accept,
tst);
- s = GNUNET_NETWORK_socket_accept (tst->lsock,
- NULL,
- NULL);
+ s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL);
if (NULL == s)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO,
- "accept");
- return; /* odd error */
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept");
+ return; /* odd error */
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Got an inbound connection, waiting for data\n");
wl = GNUNET_new (struct NatActivity);
wl->sock = s;
wl->h = tst;
- wl->rtask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- wl->sock,
- &do_read,
- wl);
- GNUNET_CONTAINER_DLL_insert (tst->na_head,
- tst->na_tail,
- wl);
+ wl->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ wl->sock,
+ &do_read,
+ wl);
+ GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl);
}
* @param error error code
*/
static void
-mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct ClientActivity *ca = cls;
struct GNUNET_NAT_AUTO_Test *tst = ca->h;
- GNUNET_CONTAINER_DLL_remove (tst->ca_head,
- tst->ca_tail,
- ca);
+ GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, ca);
GNUNET_MQ_destroy (ca->mq);
GNUNET_free (ca);
}
*/
static void
addr_cb (void *cls,
- void **app_ctx,
+ void **app_ctx,
int add_remove,
enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
if (addrlen != sizeof (struct sockaddr_in))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "NAT test ignores IPv6 address `%s' returned from NAT library\n",
- GNUNET_a2s (addr,
- addrlen));
- return; /* ignore IPv6 here */
+ "NAT test ignores IPv6 address `%s' returned from NAT library\n",
+ GNUNET_a2s (addr, addrlen));
+ return; /* ignore IPv6 here */
}
LOG (GNUNET_ERROR_TYPE_INFO,
"Asking gnunet-nat-server to connect to `%s'\n",
- GNUNET_a2s (addr,
- addrlen));
+ GNUNET_a2s (addr, addrlen));
ca = GNUNET_new (struct ClientActivity);
ca->h = h;
{
GNUNET_free (ca);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to `gnunet-nat-server'\n"));
+ _ ("Failed to connect to `gnunet-nat-server'\n"));
return;
}
- GNUNET_CONTAINER_DLL_insert (h->ca_head,
- h->ca_tail,
- ca);
+ GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca);
sa = (const struct sockaddr_in *) addr;
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_NAT_TEST);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAT_TEST);
msg->dst_ipv4 = sa->sin_addr.s_addr;
msg->dport = sa->sin_port;
msg->data = h->data;
msg->is_tcp = htonl ((uint32_t) (h->proto == IPPROTO_TCP));
- GNUNET_MQ_send (ca->mq,
- env);
+ GNUNET_MQ_send (ca->mq, env);
}
struct GNUNET_NAT_AUTO_Test *nh = cls;
nh->ttask = NULL;
- nh->report (nh->report_cls,
- nh->status);
+ nh->report (nh->report_cls, nh->status);
}
*/
struct GNUNET_NAT_AUTO_Test *
GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- uint8_t proto,
- const char *section_name,
- GNUNET_NAT_TestCallback report,
- void *report_cls)
+ uint8_t proto,
+ const char *section_name,
+ GNUNET_NAT_TestCallback report,
+ void *report_cls)
{
struct GNUNET_NAT_AUTO_Test *nh;
unsigned long long bnd_port;
struct sockaddr_in sa;
- const struct sockaddr *addrs[] = {
- (const struct sockaddr *) &sa
- };
- const socklen_t addrlens[] = {
- sizeof (sa)
- };
-
- if ( (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- section_name,
- "PORT",
- &bnd_port)) ||
- (bnd_port > 65535) )
+ const struct sockaddr *addrs[] = {(const struct sockaddr *) &sa};
+ const socklen_t addrlens[] = {sizeof (sa)};
+
+ if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ section_name,
+ "PORT",
+ &bnd_port)) ||
+ (bnd_port > 65535))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to find valid PORT in section `%s'\n"),
+ _ ("Failed to find valid PORT in section `%s'\n"),
section_name);
return NULL;
}
nh->status = GNUNET_NAT_ERROR_SUCCESS;
if (0 == bnd_port)
{
- nh->nat
- = GNUNET_NAT_register (cfg,
- section_name,
- proto,
- 0, NULL, NULL,
- &addr_cb,
- &reversal_cb,
- nh);
+ nh->nat = GNUNET_NAT_register (cfg,
+ section_name,
+ proto,
+ 0,
+ NULL,
+ NULL,
+ &addr_cb,
+ &reversal_cb,
+ nh);
}
else
{
- nh->lsock
- = GNUNET_NETWORK_socket_create (AF_INET,
- (IPPROTO_UDP == proto)
- ? SOCK_DGRAM
- : SOCK_STREAM,
- proto);
- if ( (NULL == nh->lsock) ||
- (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (nh->lsock,
- (const struct sockaddr *) &sa,
- sizeof (sa))))
+ nh->lsock =
+ GNUNET_NETWORK_socket_create (AF_INET,
+ (IPPROTO_UDP == proto) ? SOCK_DGRAM
+ : SOCK_STREAM,
+ proto);
+ if ((NULL == nh->lsock) ||
+ (GNUNET_OK != GNUNET_NETWORK_socket_bind (nh->lsock,
+ (const struct sockaddr *) &sa,
+ sizeof (sa))))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create socket bound to `%s' for NAT test: %s\n"),
- GNUNET_a2s ((const struct sockaddr *) &sa,
- sizeof (sa)),
- STRERROR (errno));
+ _ ("Failed to create socket bound to `%s' for NAT test: %s\n"),
+ GNUNET_a2s ((const struct sockaddr *) &sa, sizeof (sa)),
+ strerror (errno));
if (NULL != nh->lsock)
{
GNUNET_NETWORK_socket_close (nh->lsock);
nh->lsock = NULL;
}
nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR;
- nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail,
- nh);
+ nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, nh);
return nh;
}
if (IPPROTO_TCP == proto)
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_listen (nh->lsock,
- 5));
- nh->ltask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- nh->lsock,
- &do_accept,
- nh);
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (nh->lsock, 5));
+ nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ nh->lsock,
+ &do_accept,
+ nh);
}
else
{
- nh->ltask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- nh->lsock,
- &do_udp_read,
- nh);
+ nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ nh->lsock,
+ &do_udp_read,
+ nh);
}
LOG (GNUNET_ERROR_TYPE_INFO,
- "NAT test listens on port %llu (%s)\n",
- bnd_port,
- (IPPROTO_TCP == proto) ? "tcp" : "udp");
+ "NAT test listens on port %llu (%s)\n",
+ bnd_port,
+ (IPPROTO_TCP == proto) ? "tcp" : "udp");
nh->nat = GNUNET_NAT_register (cfg,
section_name,
proto,
if (NULL == nh->nat)
{
LOG (GNUNET_ERROR_TYPE_INFO,
- _("NAT test failed to start NAT library\n"));
+ _ ("NAT test failed to start NAT library\n"));
if (NULL != nh->ltask)
{
GNUNET_SCHEDULER_cancel (nh->ltask);
nh->lsock = NULL;
}
nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED;
- nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail,
- nh);
+ nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, nh);
return nh;
}
}
struct NatActivity *pos;
struct ClientActivity *cpos;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping NAT test\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping NAT test\n");
while (NULL != (cpos = tst->ca_head))
{
- GNUNET_CONTAINER_DLL_remove (tst->ca_head,
- tst->ca_tail,
- cpos);
+ GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, cpos);
GNUNET_MQ_destroy (cpos->mq);
GNUNET_free (cpos);
}
while (NULL != (pos = tst->na_head))
{
- GNUNET_CONTAINER_DLL_remove (tst->na_head,
- tst->na_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, pos);
GNUNET_SCHEDULER_cancel (pos->rtask);
GNUNET_NETWORK_socket_close (pos->sock);
GNUNET_free (pos);
*/
static void
address_cb (void *cls,
- void **app_ctx,
- int add_remove,
- enum GNUNET_NAT_AddressClass ac,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ void **app_ctx,
+ int add_remove,
+ enum GNUNET_NAT_AddressClass ac,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
{
(void) cls;
(void) app_ctx;
-
+
fprintf (stdout,
"%s %s (%d)\n",
add_remove ? "+" : "-",
- GNUNET_a2s (addr,
- addrlen),
+ GNUNET_a2s (addr, addrlen),
(int) ac);
}
*/
static void
reversal_cb (void *cls,
- const struct sockaddr *remote_addr,
- socklen_t remote_addrlen)
+ const struct sockaddr *remote_addr,
+ socklen_t remote_addrlen)
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Connection reversal requested by %s\n",
- GNUNET_a2s (remote_addr,
- remote_addrlen));
+ "Connection reversal requested by %s\n",
+ GNUNET_a2s (remote_addr, remote_addrlen));
}
ssize_t size;
rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- ls,
- &stun_read_task,
- NULL);
+ ls,
+ &stun_read_task,
+ NULL);
size = GNUNET_NETWORK_socket_recvfrom_amount (ls);
if (size > 0)
{
ssize_t ret;
ret = GNUNET_NETWORK_socket_recvfrom (ls,
- buf,
- size + 1,
- (struct sockaddr *) &sa,
- &salen);
+ buf,
+ size + 1,
+ (struct sockaddr *) &sa,
+ &salen);
if (ret != size)
{
GNUNET_break (0);
return;
}
(void) GNUNET_NAT_stun_handle_packet (nh,
- (const struct sockaddr *) &sa,
- salen,
- buf,
- ret);
+ (const struct sockaddr *) &sa,
+ salen,
+ buf,
+ ret);
}
}
if (use_tcp && use_udp)
{
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Cannot use TCP and UDP\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Cannot use TCP and UDP\n");
global_ret = 1;
return;
}
if (use_udp)
proto = IPPROTO_UDP;
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (0 == proto)
{
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Must specify either TCP or UDP\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Must specify either TCP or UDP\n");
global_ret = 1;
return;
}
remote_sa = NULL;
if (NULL != local_addr)
{
- local_len = (socklen_t) GNUNET_STRINGS_parse_socket_addr (local_addr,
- &af,
- &local_sa);
+ local_len =
+ (socklen_t) GNUNET_STRINGS_parse_socket_addr (local_addr, &af, &local_sa);
if (0 == local_len)
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Invalid socket address `%s'\n",
- local_addr);
+ "Invalid socket address `%s'\n",
+ local_addr);
goto fail_and_shutdown;
}
}
if (NULL != remote_addr)
{
- remote_len = GNUNET_STRINGS_parse_socket_addr (remote_addr,
- &af,
- &remote_sa);
+ remote_len =
+ GNUNET_STRINGS_parse_socket_addr (remote_addr, &af, &remote_sa);
if (0 == remote_len)
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Invalid socket address `%s'\n",
- remote_addr);
+ "Invalid socket address `%s'\n",
+ remote_addr);
goto fail_and_shutdown;
}
}
if (NULL == section_name)
section_name = GNUNET_strdup ("undefined");
nh = GNUNET_NAT_register (c,
- section_name,
- proto,
- 1,
- (const struct sockaddr **) &local_sa,
- &local_len,
- &address_cb,
- (listen_reversal) ? &reversal_cb : NULL,
- NULL);
+ section_name,
+ proto,
+ 1,
+ (const struct sockaddr **) &local_sa,
+ &local_len,
+ &address_cb,
+ (listen_reversal) ? &reversal_cb : NULL,
+ NULL);
}
else if (listen_reversal)
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Use of `-W` only effective in combination with `-i`\n");
+ "Use of `-W` only effective in combination with `-i`\n");
goto fail_and_shutdown;
}
{
int ret;
- if ( (NULL == nh) ||
- (sizeof (struct sockaddr_in) != local_len) )
+ if ((NULL == nh) || (sizeof (struct sockaddr_in) != local_len))
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Require IPv4 local address to initiate connection reversal\n");
+ "Require IPv4 local address to initiate connection reversal\n");
goto fail_and_shutdown;
}
if (sizeof (struct sockaddr_in) != remote_len)
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Require IPv4 reversal target address\n");
+ "Require IPv4 reversal target address\n");
goto fail_and_shutdown;
}
GNUNET_assert (AF_INET == local_sa->sa_family);
GNUNET_assert (AF_INET == remote_sa->sa_family);
ret = GNUNET_NAT_request_reversal (nh,
- (const struct sockaddr_in *) local_sa,
- (const struct sockaddr_in *) remote_sa);
+ (const struct sockaddr_in *) local_sa,
+ (const struct sockaddr_in *) remote_sa);
switch (ret)
{
case GNUNET_SYSERR:
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Connection reversal internal error\n");
+ "Connection reversal internal error\n");
break;
case GNUNET_NO:
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Connection reversal unavailable\n");
+ "Connection reversal unavailable\n");
break;
case GNUNET_OK:
/* operation in progress */
if (NULL == local_addr)
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Require local address to support STUN requests\n");
+ "Require local address to support STUN requests\n");
goto fail_and_shutdown;
}
if (IPPROTO_UDP != proto)
{
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "STUN only supported over UDP\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "STUN only supported over UDP\n");
goto fail_and_shutdown;
}
- ls = GNUNET_NETWORK_socket_create (af,
- SOCK_DGRAM,
- IPPROTO_UDP);
+ ls = GNUNET_NETWORK_socket_create (af, SOCK_DGRAM, IPPROTO_UDP);
if (NULL == ls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Failed to create socket\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Failed to create socket\n");
goto fail_and_shutdown;
}
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (ls,
- local_sa,
- local_len))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ls, local_sa, local_len))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to bind to %s: %s\n",
- GNUNET_a2s (local_sa,
- local_len),
- STRERROR (errno));
+ "Failed to bind to %s: %s\n",
+ GNUNET_a2s (local_sa, local_len),
+ strerror (errno));
goto fail_and_shutdown;
}
rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- ls,
- &stun_read_task,
- NULL);
+ ls,
+ &stun_read_task,
+ NULL);
}
GNUNET_free_non_null (remote_sa);
GNUNET_free_non_null (local_sa);
test_finished ();
return;
- fail_and_shutdown:
+fail_and_shutdown:
global_ret = 1;
GNUNET_SCHEDULER_shutdown ();
GNUNET_free_non_null (remote_sa);
* @return 0 on success, -1 on error
*/
int
-main (int argc,
- char *const argv[])
+main (int argc, char *const argv[])
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_string ('i',
- "in",
- "ADDRESS",
- gettext_noop ("which IP and port are we locally using to bind/listen to"),
- &local_addr),
-
- GNUNET_GETOPT_option_string ('r',
- "remote",
- "ADDRESS",
- gettext_noop ("which remote IP and port should be asked for connection reversal"),
- &remote_addr),
-
- GNUNET_GETOPT_option_string ('S',
- "section",
- NULL,
- gettext_noop ("name of configuration section to find additional options, such as manual host punching data"),
- §ion_name),
+ GNUNET_GETOPT_option_string (
+ 'i',
+ "in",
+ "ADDRESS",
+ gettext_noop ("which IP and port are we locally using to bind/listen to"),
+ &local_addr),
+
+ GNUNET_GETOPT_option_string (
+ 'r',
+ "remote",
+ "ADDRESS",
+ gettext_noop (
+ "which remote IP and port should be asked for connection reversal"),
+ &remote_addr),
+
+ GNUNET_GETOPT_option_string (
+ 'S',
+ "section",
+ NULL,
+ gettext_noop (
+ "name of configuration section to find additional options, such as manual host punching data"),
+ §ion_name),
GNUNET_GETOPT_option_flag ('s',
- "stun",
- gettext_noop ("enable STUN processing"),
- &do_stun),
+ "stun",
+ gettext_noop ("enable STUN processing"),
+ &do_stun),
- GNUNET_GETOPT_option_flag ('t',
- "tcp",
- gettext_noop ("use TCP"),
- &use_tcp),
+ GNUNET_GETOPT_option_flag ('t', "tcp", gettext_noop ("use TCP"), &use_tcp),
- GNUNET_GETOPT_option_flag ('u',
- "udp",
- gettext_noop ("use UDP"),
- &use_udp),
+ GNUNET_GETOPT_option_flag ('u', "udp", gettext_noop ("use UDP"), &use_udp),
GNUNET_GETOPT_option_flag ('W',
- "watch",
- gettext_noop ("watch for connection reversal requests"),
- &listen_reversal),
- GNUNET_GETOPT_OPTION_END
- };
+ "watch",
+ gettext_noop (
+ "watch for connection reversal requests"),
+ &listen_reversal),
+ GNUNET_GETOPT_OPTION_END};
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
if (GNUNET_OK !=
- GNUNET_PROGRAM_run (argc, argv,
- "gnunet-nat [options]",
- _("GNUnet NAT traversal autoconfigure daemon"),
- options,
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-nat [options]",
+ _ ("GNUnet NAT traversal autoconfigure daemon"),
+ options,
&run,
- NULL))
+ NULL))
{
global_ret = 1;
}
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
return global_ret;
}
try_again (struct HelperContext *h)
{
GNUNET_assert (NULL == h->server_read_task);
- h->server_retry_delay
- = GNUNET_TIME_STD_BACKOFF (h->server_retry_delay);
- h->server_read_task
- = GNUNET_SCHEDULER_add_delayed (h->server_retry_delay,
- &restart_nat_server,
- h);
+ h->server_retry_delay = GNUNET_TIME_STD_BACKOFF (h->server_retry_delay);
+ h->server_read_task = GNUNET_SCHEDULER_add_delayed (h->server_retry_delay,
+ &restart_nat_server,
+ h);
}
struct sockaddr_in sin_addr;
h->server_read_task = NULL;
- memset (mybuf,
- 0,
- sizeof (mybuf));
- bytes
- = GNUNET_DISK_file_read (h->server_stdout_handle,
- mybuf,
- sizeof (mybuf));
+ memset (mybuf, 0, sizeof (mybuf));
+ bytes =
+ GNUNET_DISK_file_read (h->server_stdout_handle, mybuf, sizeof (mybuf));
if (bytes < 1)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished reading from server stdout with code: %d\n",
- (int) bytes);
- if (0 != GNUNET_OS_process_kill (h->server_proc,
- GNUNET_TERM_SIG))
- GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING,
- "nat",
- "kill");
+ "Finished reading from server stdout with code: %d\n",
+ (int) bytes);
+ if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG))
+ GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "kill");
GNUNET_OS_process_wait (h->server_proc);
GNUNET_OS_process_destroy (h->server_proc);
h->server_proc = NULL;
}
/* construct socket address of sender */
- memset (&sin_addr,
- 0,
- sizeof (sin_addr));
+ memset (&sin_addr, 0, sizeof (sin_addr));
sin_addr.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
sin_addr.sin_len = sizeof (sin_addr);
#endif
- if ( (NULL == port_start) ||
- (1 != SSCANF (port_start,
- "%d",
- &port)) ||
- (-1 == inet_pton (AF_INET,
- mybuf,
- &sin_addr.sin_addr)))
+ if ((NULL == port_start) || (1 != sscanf (port_start, "%d", &port)) ||
+ (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr)))
{
/* should we restart gnunet-helper-nat-server? */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("gnunet-helper-nat-server generated malformed address `%s'\n"),
- mybuf);
- h->server_read_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle,
- &nat_server_read,
- h);
+ _ (
+ "gnunet-helper-nat-server generated malformed address `%s'\n"),
+ mybuf);
+ h->server_read_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->server_stdout_handle,
+ &nat_server_read,
+ h);
return;
}
sin_addr.sin_port = htons ((uint16_t) port);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "gnunet-helper-nat-server read: %s:%d\n",
- mybuf,
- port);
- h->cb (h->cb_cls,
- &sin_addr);
- h->server_read_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle,
- &nat_server_read,
- h);
+ "gnunet-helper-nat-server read: %s:%d\n",
+ mybuf,
+ port);
+ h->cb (h->cb_cls, &sin_addr);
+ h->server_read_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->server_stdout_handle,
+ &nat_server_read,
+ h);
}
h->server_read_task = NULL;
GNUNET_assert (NULL !=
- inet_ntop (AF_INET,
- &h->internal_address,
- ia,
- sizeof (ia)));
+ inet_ntop (AF_INET, &h->internal_address, ia, sizeof (ia)));
/* Start the server process */
binary = GNUNET_OS_get_suid_binary_path (h->cfg, "gnunet-helper-nat-server");
- if (GNUNET_YES !=
- GNUNET_OS_check_helper_binary (binary,
- GNUNET_YES,
- ia))
+ if (GNUNET_YES != GNUNET_OS_check_helper_binary (binary, GNUNET_YES, ia))
{
/* move instantly to max delay, as this is unlikely to be fixed */
- h->server_retry_delay
- = GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD;
+ h->server_retry_delay = GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD;
GNUNET_free (binary);
try_again (h);
return;
}
- h->server_stdout
- = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES,
- GNUNET_NO, GNUNET_YES);
+ h->server_stdout =
+ GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == h->server_stdout)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
GNUNET_free (binary);
try_again (h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting `%s' at `%s'\n",
- "gnunet-helper-nat-server",
- ia);
- h->server_proc
- = GNUNET_OS_start_process (GNUNET_NO,
- 0,
- NULL,
- h->server_stdout,
- NULL,
- binary,
- "gnunet-helper-nat-server",
- ia,
- NULL);
+ "Starting `%s' at `%s'\n",
+ "gnunet-helper-nat-server",
+ ia);
+ h->server_proc = GNUNET_OS_start_process (GNUNET_NO,
+ 0,
+ NULL,
+ h->server_stdout,
+ NULL,
+ binary,
+ "gnunet-helper-nat-server",
+ ia,
+ NULL);
GNUNET_free (binary);
if (NULL == h->server_proc)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to start %s\n"),
- "gnunet-helper-nat-server");
+ _ ("Failed to start %s\n"),
+ "gnunet-helper-nat-server");
GNUNET_DISK_pipe_close (h->server_stdout);
h->server_stdout = NULL;
try_again (h);
return;
}
/* Close the write end of the read pipe */
- GNUNET_DISK_pipe_close_end (h->server_stdout,
- GNUNET_DISK_PIPE_END_WRITE);
- h->server_stdout_handle
- = GNUNET_DISK_pipe_handle (h->server_stdout,
- GNUNET_DISK_PIPE_END_READ);
- h->server_read_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle,
- &nat_server_read,
- h);
+ GNUNET_DISK_pipe_close_end (h->server_stdout, GNUNET_DISK_PIPE_END_WRITE);
+ h->server_stdout_handle =
+ GNUNET_DISK_pipe_handle (h->server_stdout, GNUNET_DISK_PIPE_END_READ);
+ h->server_read_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->server_stdout_handle,
+ &nat_server_read,
+ h);
}
*/
struct HelperContext *
GN_start_gnunet_nat_server_ (const struct in_addr *internal_address,
- GN_ReversalCallback cb,
- void *cb_cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ GN_ReversalCallback cb,
+ void *cb_cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct HelperContext *h;
}
if (NULL != h->server_proc)
{
- if (0 != GNUNET_OS_process_kill (h->server_proc,
- GNUNET_TERM_SIG))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "kill");
+ if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
GNUNET_OS_process_wait (h->server_proc);
GNUNET_OS_process_destroy (h->server_proc);
h->server_proc = NULL;
*/
int
GN_request_connection_reversal (const struct in_addr *internal_address,
- uint16_t internal_port,
- const struct in_addr *remote_v4,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ uint16_t internal_port,
+ const struct in_addr *remote_v4,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char intv4[INET_ADDRSTRLEN];
char remv4[INET_ADDRSTRLEN];
struct GNUNET_OS_Process *proc;
char *binary;
- if (NULL == inet_ntop (AF_INET,
- internal_address,
- intv4,
- INET_ADDRSTRLEN))
+ if (NULL == inet_ntop (AF_INET, internal_address, intv4, INET_ADDRSTRLEN))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "inet_ntop");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
return GNUNET_SYSERR;
}
- if (NULL == inet_ntop (AF_INET,
- remote_v4,
- remv4,
- INET_ADDRSTRLEN))
+ if (NULL == inet_ntop (AF_INET, remote_v4, remv4, INET_ADDRSTRLEN))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "inet_ntop");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
return GNUNET_SYSERR;
}
GNUNET_snprintf (port_as_string,
"%d",
internal_port);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Running gnunet-helper-nat-client %s %s %u\n",
- intv4,
- remv4,
- internal_port);
+ "Running gnunet-helper-nat-client %s %s %u\n",
+ intv4,
+ remv4,
+ internal_port);
binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-nat-client");
- proc
- = GNUNET_OS_start_process (GNUNET_NO,
- 0,
- NULL,
- NULL,
- NULL,
- binary,
- "gnunet-helper-nat-client",
- intv4,
- remv4,
- port_as_string,
- NULL);
+ proc = GNUNET_OS_start_process (GNUNET_NO,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ binary,
+ "gnunet-helper-nat-client",
+ intv4,
+ remv4,
+ port_as_string,
+ NULL);
GNUNET_free (binary);
if (NULL == proc)
return GNUNET_SYSERR;
#include "gnunet-service-nat_mini.h"
#include "nat.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
/**
* How long do we give upnpc to create a mapping?
/**
* How long do we give upnpc to remove a mapping?
*/
-#define UNMAP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+#define UNMAP_TIMEOUT \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
/**
* How often do we check for changes in the mapping?
*/
-#define MAP_REFRESH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
+#define MAP_REFRESH_FREQ \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
/* ************************* external-ip calling ************************ */
eh->task = NULL;
ret = GNUNET_DISK_file_read (eh->r,
- &eh->buf[eh->off],
+ &eh->buf[eh->off],
sizeof (eh->buf) - eh->off);
if (ret > 0)
{
/* try to read more */
eh->off += ret;
- eh->task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- eh->r,
- &read_external_ipv4,
- eh);
+ eh->task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ eh->r,
+ &read_external_ipv4,
+ eh);
return;
}
eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID;
- if ( (eh->off > 7) &&
- (eh->buf[eh->off - 1] == '\n') )
+ if ((eh->off > 7) && (eh->buf[eh->off - 1] == '\n'))
{
eh->buf[eh->off - 1] = '\0';
- if (1 == inet_pton (AF_INET,
- eh->buf,
- &addr))
+ if (1 == inet_pton (AF_INET, eh->buf, &addr))
{
if (0 == addr.s_addr)
- eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID; /* got 0.0.0.0 */
+ eh->ret =
+ GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID; /* got 0.0.0.0 */
else
eh->ret = GNUNET_NAT_ERROR_SUCCESS;
}
struct GNUNET_NAT_ExternalHandle *eh = cls;
eh->task = NULL;
- eh->cb (eh->cb_cls,
- NULL,
- eh->ret);
+ eh->cb (eh->cb_cls, NULL, eh->ret);
GNUNET_free (eh);
}
* @return handle for cancellation (can only be used until @a cb is called), never NULL
*/
struct GNUNET_NAT_ExternalHandle *
-GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
- void *cb_cls)
+GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb, void *cb_cls)
{
struct GNUNET_NAT_ExternalHandle *eh;
eh->cb_cls = cb_cls;
eh->ret = GNUNET_NAT_ERROR_SUCCESS;
if (GNUNET_SYSERR ==
- GNUNET_OS_check_helper_binary ("external-ip",
- GNUNET_NO,
- NULL))
+ GNUNET_OS_check_helper_binary ("external-ip", GNUNET_NO, NULL))
{
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("`external-ip' command not found\n"));
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("`external-ip' command not found\n"));
eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND;
- eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
- eh);
+ eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, eh);
return eh;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Running `external-ip' to determine our external IP\n");
- eh->opipe = GNUNET_DISK_pipe (GNUNET_YES,
- GNUNET_YES,
- GNUNET_NO,
- GNUNET_YES);
+ eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == eh->opipe)
{
eh->ret = GNUNET_NAT_ERROR_IPC_FAILURE;
- eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
- eh);
+ eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, eh);
return eh;
}
- eh->eip =
- GNUNET_OS_start_process (GNUNET_NO,
- 0,
- NULL,
- eh->opipe,
- NULL,
- "external-ip",
- "external-ip",
- NULL);
+ eh->eip = GNUNET_OS_start_process (GNUNET_NO,
+ 0,
+ NULL,
+ eh->opipe,
+ NULL,
+ "external-ip",
+ "external-ip",
+ NULL);
if (NULL == eh->eip)
{
GNUNET_DISK_pipe_close (eh->opipe);
eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED;
- eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
- eh);
+ eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error, eh);
return eh;
}
- GNUNET_DISK_pipe_close_end (eh->opipe,
- GNUNET_DISK_PIPE_END_WRITE);
- eh->r = GNUNET_DISK_pipe_handle (eh->opipe,
- GNUNET_DISK_PIPE_END_READ);
- eh->task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- eh->r,
- &read_external_ipv4,
- eh);
+ GNUNET_DISK_pipe_close_end (eh->opipe, GNUNET_DISK_PIPE_END_WRITE);
+ eh->r = GNUNET_DISK_pipe_handle (eh->opipe, GNUNET_DISK_PIPE_END_READ);
+ eh->task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ eh->r,
+ &read_external_ipv4,
+ eh);
return eh;
}
{
if (NULL != eh->eip)
{
- (void) GNUNET_OS_process_kill (eh->eip,
- SIGKILL);
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (eh->eip));
+ (void) GNUNET_OS_process_kill (eh->eip, SIGKILL);
+ GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (eh->eip));
GNUNET_OS_process_destroy (eh->eip);
}
if (NULL != eh->opipe)
* Which port are we mapping?
*/
uint16_t port;
-
};
* @param line line of output, NULL at the end
*/
static void
-process_map_output (void *cls,
- const char *line);
+process_map_output (void *cls, const char *line);
/**
{
char pstr[6];
- GNUNET_snprintf (pstr,
- sizeof (pstr),
- "%u",
- (unsigned int) mini->port);
- mini->map_cmd
- = GNUNET_OS_command_run (&process_map_output,
- mini,
- MAP_TIMEOUT,
- "upnpc",
- "upnpc",
- "-r",
- pstr,
- mini->is_tcp ? "tcp" : "udp",
- NULL);
+ GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) mini->port);
+ mini->map_cmd = GNUNET_OS_command_run (&process_map_output,
+ mini,
+ MAP_TIMEOUT,
+ "upnpc",
+ "upnpc",
+ "-r",
+ pstr,
+ mini->is_tcp ? "tcp" : "udp",
+ NULL);
if (NULL == mini->map_cmd)
{
mini->ac (mini->ac_cls,
GNUNET_SYSERR,
NULL,
- 0,
+ 0,
GNUNET_NAT_ERROR_UPNPC_FAILED);
return;
}
* @param line line of output, NULL at the end
*/
static void
-process_refresh_output (void *cls,
- const char *line)
+process_refresh_output (void *cls, const char *line)
{
struct GNUNET_NAT_MiniHandle *mini = cls;
char pstr[9];
return;
}
if (! mini->did_map)
- return; /* never mapped, won't find our mapping anyway */
+ return; /* never mapped, won't find our mapping anyway */
/* we're looking for output of the form:
* "ExternalIPAddress = 12.134.41.124" */
- s = strstr (line,
- "ExternalIPAddress = ");
+ s = strstr (line, "ExternalIPAddress = ");
if (NULL != s)
{
s += strlen ("ExternalIPAddress = ");
- if (1 != inet_pton (AF_INET,
- s,
- &exip))
- return; /* skip */
+ if (1 != inet_pton (AF_INET, s, &exip))
+ return; /* skip */
if (exip.s_addr == mini->current_addr.sin_addr.s_addr)
- return; /* no change */
+ return; /* no change */
/* update mapping */
mini->ac (mini->ac_cls,
- GNUNET_NO,
+ GNUNET_NO,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
GNUNET_NAT_ERROR_SUCCESS);
mini->current_addr.sin_addr = exip;
mini->ac (mini->ac_cls,
- GNUNET_YES,
+ GNUNET_YES,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
GNUNET_NAT_ERROR_SUCCESS);
* "%s TCP PORT->STRING:OURPORT *" or
* "%s UDP PORT->STRING:OURPORT *"
*/
- GNUNET_snprintf (pstr,
- sizeof (pstr),
- ":%u ",
- mini->port);
+ GNUNET_snprintf (pstr, sizeof (pstr), ":%u ", mini->port);
if (NULL == (s = strstr (line, "->")))
- return; /* skip */
+ return; /* skip */
if (NULL == strstr (s, pstr))
- return; /* skip */
- if (1 !=
- SSCANF (line,
- (mini->is_tcp) ? "%*u TCP %u->%*s:%*u %*s" :
- "%*u UDP %u->%*s:%*u %*s", &nport))
- return; /* skip */
+ return; /* skip */
+ if (1 != sscanf (line,
+ (mini->is_tcp) ? "%*u TCP %u->%*s:%*u %*s"
+ : "%*u UDP %u->%*s:%*u %*s",
+ &nport))
+ return; /* skip */
mini->found = GNUNET_YES;
if (nport == ntohs (mini->current_addr.sin_port))
- return; /* no change */
+ return; /* no change */
/* external port changed, update mapping */
mini->ac (mini->ac_cls,
- GNUNET_NO,
+ GNUNET_NO,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
GNUNET_NAT_ERROR_SUCCESS);
mini->current_addr.sin_port = htons ((uint16_t) nport);
mini->ac (mini->ac_cls,
- GNUNET_YES,
+ GNUNET_YES,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
GNUNET_NAT_ERROR_SUCCESS);
struct GNUNET_NAT_MiniHandle *mini = cls;
int ac;
- mini->refresh_task
- = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
- &do_refresh,
- mini);
+ mini->refresh_task =
+ GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Running `upnpc' to check if our mapping still exists\n");
mini->found = GNUNET_NO;
mini->refresh_cmd = NULL;
ac = GNUNET_YES;
}
- mini->refresh_cmd
- = GNUNET_OS_command_run (&process_refresh_output,
- mini,
- MAP_TIMEOUT,
- "upnpc",
- "upnpc",
- "-l",
- NULL);
+ mini->refresh_cmd = GNUNET_OS_command_run (&process_refresh_output,
+ mini,
+ MAP_TIMEOUT,
+ "upnpc",
+ "upnpc",
+ "-l",
+ NULL);
if (GNUNET_YES == ac)
mini->ac (mini->ac_cls,
GNUNET_SYSERR,
NULL,
- 0,
+ 0,
GNUNET_NAT_ERROR_UPNPC_TIMEOUT);
}
* @param line line of output, NULL at the end
*/
static void
-process_map_output (void *cls,
- const char *line)
+process_map_output (void *cls, const char *line)
{
struct GNUNET_NAT_MiniHandle *mini = cls;
const char *ipaddr;
mini->ac (mini->ac_cls,
GNUNET_SYSERR,
NULL,
- 0,
+ 0,
GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED);
if (NULL == mini->refresh_task)
- mini->refresh_task
- = GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
- &do_refresh,
- mini);
+ mini->refresh_task =
+ GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
return;
}
/*
*/
if ((NULL == (ipaddr = strstr (line, " "))) ||
(NULL == (pstr = strstr (ipaddr, ":"))) ||
- (1 != SSCANF (pstr + 1, "%u", &port)))
+ (1 != sscanf (pstr + 1, "%u", &port)))
{
- return; /* skip line */
+ return; /* skip line */
}
ipa = GNUNET_strdup (ipaddr + 1);
strstr (ipa, ":")[0] = '\0';
- if (1 != inet_pton (AF_INET,
- ipa,
- &mini->current_addr.sin_addr))
+ if (1 != inet_pton (AF_INET, ipa, &mini->current_addr.sin_addr))
{
GNUNET_free (ipa);
- return; /* skip line */
+ return; /* skip line */
}
GNUNET_free (ipa);
#endif
mini->did_map = GNUNET_YES;
mini->ac (mini->ac_cls,
- GNUNET_YES,
+ GNUNET_YES,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
GNUNET_NAT_ERROR_SUCCESS);
{
struct GNUNET_NAT_MiniHandle *ret;
- if (GNUNET_SYSERR ==
- GNUNET_OS_check_helper_binary ("upnpc",
- GNUNET_NO,
- NULL))
+ if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("upnpc", GNUNET_NO, NULL))
{
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("`upnpc' command not found\n"));
- ac (ac_cls,
- GNUNET_SYSERR,
- NULL, 0,
- GNUNET_NAT_ERROR_UPNPC_NOT_FOUND);
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("`upnpc' command not found\n"));
+ ac (ac_cls, GNUNET_SYSERR, NULL, 0, GNUNET_NAT_ERROR_UPNPC_NOT_FOUND);
return NULL;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Running `upnpc' to install mapping\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Running `upnpc' to install mapping\n");
ret = GNUNET_new (struct GNUNET_NAT_MiniHandle);
ret->ac = ac;
ret->ac_cls = ac_cls;
ret->is_tcp = is_tcp;
ret->port = port;
ret->refresh_task =
- GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
- &do_refresh,
- ret);
+ GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, ret);
run_upnpc_r (ret);
return ret;
}
* @param line line of output, NULL at the end
*/
static void
-process_unmap_output (void *cls,
- const char *line)
+process_unmap_output (void *cls, const char *line)
{
struct GNUNET_NAT_MiniHandle *mini = cls;
if (NULL == line)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UPnP unmap done\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "UPnP unmap done\n");
GNUNET_OS_command_stop (mini->unmap_cmd);
mini->unmap_cmd = NULL;
GNUNET_free (mini);
return;
}
mini->ac (mini->ac_cls,
- GNUNET_NO,
+ GNUNET_NO,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
GNUNET_NAT_ERROR_SUCCESS);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Unmapping port %u with UPnP\n",
ntohs (mini->current_addr.sin_port));
- mini->unmap_cmd
- = GNUNET_OS_command_run (&process_unmap_output,
- mini,
- UNMAP_TIMEOUT,
- "upnpc",
- "upnpc",
- "-d",
- pstr,
- mini->is_tcp ? "tcp" : "udp",
- NULL);
+ mini->unmap_cmd = GNUNET_OS_command_run (&process_unmap_output,
+ mini,
+ UNMAP_TIMEOUT,
+ "upnpc",
+ "upnpc",
+ "-d",
+ pstr,
+ mini->is_tcp ? "tcp" : "udp",
+ NULL);
}
/**
* Generic loggins shorthand
*/
-#define LOG(kind,...) \
- GNUNET_log (kind, __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
/**
* Debug logging shorthand
*/
-#define LOG_DEBUG(...) \
- LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
/**
* How long to wait before triggering next round?
* Default: 60 s.
*/
-static struct GNUNET_TIME_Relative wait_time = { 60 * 1000 };
+static struct GNUNET_TIME_Relative wait_time = {60 * 1000};
/**
* DLL head for operation list
*/
static void
handle_estimate (void *cls,
- struct GNUNET_TIME_Absolute timestamp,
- double estimate, double std_dev)
+ struct GNUNET_TIME_Absolute timestamp,
+ double estimate,
+ double std_dev)
{
struct NSEPeer *peer = cls;
char output_buffer[512];
size_t size;
if (NULL == output_file)
- {
- FPRINTF (stderr,
- "Received network size estimate from peer %p. Size: %f std.dev. %f\n",
- peer, estimate, std_dev);
- return;
- }
+ {
+ fprintf (stderr,
+ "Received network size estimate from peer %p. Size: %f std.dev. %f\n",
+ peer,
+ estimate,
+ std_dev);
+ return;
+ }
size = GNUNET_snprintf (output_buffer,
- sizeof (output_buffer),
- "%p %llu %llu %f %f %f\n",
- peer, peers_running,
- (unsigned long long) timestamp.abs_value_us,
- GNUNET_NSE_log_estimate_to_n (estimate), estimate,
- std_dev);
+ sizeof (output_buffer),
+ "%p %llu %llu %f %f %f\n",
+ peer,
+ peers_running,
+ (unsigned long long) timestamp.abs_value_us,
+ GNUNET_NSE_log_estimate_to_n (estimate),
+ estimate,
+ std_dev);
if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unable to write to file!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
}
* @return service handle to return in 'op_result', NULL on error
*/
static void *
-nse_connect_adapter (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+nse_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct NSEPeer *current_peer = cls;
* @param op_result service handle returned from the connect adapter
*/
static void
-nse_disconnect_adapter (void *cls,
- void *op_result)
+nse_disconnect_adapter (void *cls, void *op_result)
{
GNUNET_NSE_disconnect (op_result);
}
flag = strcasecmp (subsystem, "core");
if (0 != flag)
flag = 1;
- size = GNUNET_asprintf (&output_buffer, "%llu %llu %u\n",
+ size = GNUNET_asprintf (&output_buffer,
+ "%llu %llu %u\n",
now.abs_value_us / 1000LL / 1000LL,
- value, flag);
+ value,
+ flag);
if (0 > size)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n");
* @return service handle to return in 'op_result', NULL on error
*/
static void *
-stat_connect_adapter (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+stat_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct NSEPeer *peer = cls;
{
struct NSEPeer *peer = cls;
- GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
- (peer->sh, "core", "# peers connected",
- stat_iterator, peer));
- GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
- (peer->sh, "nse", "# peers connected",
- stat_iterator, peer));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_STATISTICS_watch_cancel (peer->sh,
+ "core",
+ "# peers connected",
+ stat_iterator,
+ peer));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_STATISTICS_watch_cancel (peer->sh,
+ "nse",
+ "# peers connected",
+ stat_iterator,
+ peer));
GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
peer->sh = NULL;
}
* operation has executed successfully.
*/
static void
-stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
- void *ca_result, const char *emsg )
+stat_comp_cb (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
+ void *ca_result,
+ const char *emsg)
{
struct GNUNET_STATISTICS_Handle *sh = ca_result;
struct NSEPeer *peer = cls;
GNUNET_break (0);
return;
}
- GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
- (sh, "core", "# peers connected",
- stat_iterator, peer));
- GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
- (sh, "nse", "# peers connected",
- stat_iterator, peer));
+ GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh,
+ "core",
+ "# peers connected",
+ stat_iterator,
+ peer));
+ GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch (sh,
+ "nse",
+ "# peers connected",
+ stat_iterator,
+ peer));
}
for (i = 0; i < num_peers_in_round[current_round]; i++)
{
if ((num_peers_in_round[current_round] > connection_limit) &&
- (0 != (i % (num_peers_in_round[current_round] / connection_limit))))
+ (0 != (i % (num_peers_in_round[current_round] / connection_limit))))
continue;
LOG_DEBUG ("Connecting to nse service of peer %d\n", i);
current_peer = GNUNET_new (struct NSEPeer);
current_peer->daemon = daemons[i];
- current_peer->nse_op
- = GNUNET_TESTBED_service_connect (NULL,
- current_peer->daemon,
- "nse",
- NULL, NULL,
- &nse_connect_adapter,
- &nse_disconnect_adapter,
- current_peer);
+ current_peer->nse_op =
+ GNUNET_TESTBED_service_connect (NULL,
+ current_peer->daemon,
+ "nse",
+ NULL,
+ NULL,
+ &nse_connect_adapter,
+ &nse_disconnect_adapter,
+ current_peer);
if (NULL != data_file)
- current_peer->stat_op
- = GNUNET_TESTBED_service_connect (NULL,
- current_peer->daemon,
- "statistics",
- stat_comp_cb,
- current_peer,
- &stat_connect_adapter,
- &stat_disconnect_adapter,
- current_peer);
+ current_peer->stat_op =
+ GNUNET_TESTBED_service_connect (NULL,
+ current_peer->daemon,
+ "statistics",
+ stat_comp_cb,
+ current_peer,
+ &stat_connect_adapter,
+ &stat_disconnect_adapter,
+ current_peer);
GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
if (++connections == connection_limit)
break;
static void
finish_round (void *cls)
{
- LOG (GNUNET_ERROR_TYPE_INFO,
- "Have %u connections\n",
- total_connections);
+ LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections);
close_monitor_connections ();
round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL);
}
static void
run_round ()
{
- LOG_DEBUG ("Running round %u\n",
- current_round);
+ LOG_DEBUG ("Running round %u\n", current_round);
connect_nse_service ();
- GNUNET_SCHEDULER_add_delayed (wait_time,
- &finish_round,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (wait_time, &finish_round, NULL);
}
struct OpListEntry *entry;
entry = GNUNET_new (struct OpListEntry);
- GNUNET_CONTAINER_DLL_insert_tail (oplist_head,
- oplist_tail,
- entry);
+ GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
return entry;
}
*/
static void
manage_service_cb (void *cls,
- struct GNUNET_TESTBED_Operation *op,
+ struct GNUNET_TESTBED_Operation *op,
const char *emsg)
{
struct OpListEntry *entry = cls;
}
GNUNET_assert (0 != entry->delta);
peers_running += entry->delta;
- GNUNET_CONTAINER_DLL_remove (oplist_head,
- oplist_tail,
- entry);
+ GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
GNUNET_free (entry);
if (num_peers_in_round[current_round] == peers_running)
run_round ();
unsigned int i;
/* start peers if we have too few */
- for (i=peers_running;i<num_peers_in_round[current_round];i++)
+ for (i = peers_running; i < num_peers_in_round[current_round]; i++)
{
entry = make_oplist_entry ();
entry->delta = 1;
1);
}
/* stop peers if we have too many */
- for (i=num_peers_in_round[current_round];i<peers_running;i++)
+ for (i = num_peers_in_round[current_round]; i < peers_running; i++)
{
entry = make_oplist_entry ();
entry->delta = -1;
- entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
- daemons[i],
- "nse",
- &manage_service_cb,
- entry,
- 0);
+ entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
+ daemons[i],
+ "nse",
+ &manage_service_cb,
+ entry,
+ 0);
}
}
*/
static void
master_controller_cb (void *cls,
- const struct GNUNET_TESTBED_EventInformation *event)
+ const struct GNUNET_TESTBED_EventInformation *event)
{
switch (event->type)
- {
- case GNUNET_TESTBED_ET_CONNECT:
- total_connections++;
- break;
- case GNUNET_TESTBED_ET_DISCONNECT:
- total_connections--;
- break;
- default:
- break;
- }
+ {
+ case GNUNET_TESTBED_ET_CONNECT:
+ total_connections++;
+ break;
+ case GNUNET_TESTBED_ET_DISCONNECT:
+ total_connections--;
+ break;
+ default:
+ break;
+ }
}
* @param cfg configuration handle
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char *tok;
return;
}
for (tok = strtok (num_peer_spec, ","); NULL != tok; tok = strtok (NULL, ","))
+ {
+ if (1 != sscanf (tok, "%u", &num))
{
- if (1 != sscanf (tok, "%u", &num))
- {
- fprintf (stderr, "You need to specify numbers, not `%s'\n", tok);
- return;
- }
- if (0 == num)
- {
- fprintf (stderr, "Refusing to run a round with 0 peers\n");
- return;
- }
- GNUNET_array_append (num_peers_in_round, num_rounds, num);
- num_peers = GNUNET_MAX (num_peers, num);
+ fprintf (stderr, "You need to specify numbers, not `%s'\n", tok);
+ return;
}
- if (0 == num_peers)
+ if (0 == num)
{
- fprintf (stderr, "Refusing to run a testbed with no rounds\n");
+ fprintf (stderr, "Refusing to run a round with 0 peers\n");
return;
}
- if ( (NULL != data_filename) &&
- (NULL == (data_file =
- GNUNET_DISK_file_open (data_filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_TRUNCATE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE))) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- data_filename);
-
- if ( (NULL != output_filename) &&
- (NULL == (output_file =
- GNUNET_DISK_file_open (output_filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE))) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open",
- output_filename);
+ GNUNET_array_append (num_peers_in_round, num_rounds, num);
+ num_peers = GNUNET_MAX (num_peers, num);
+ }
+ if (0 == num_peers)
+ {
+ fprintf (stderr, "Refusing to run a testbed with no rounds\n");
+ return;
+ }
+ if ((NULL != data_filename) &&
+ (NULL ==
+ (data_file = GNUNET_DISK_file_open (data_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", data_filename);
+
+ if ((NULL != output_filename) &&
+ (NULL ==
+ (output_file = GNUNET_DISK_file_open (output_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", output_filename);
event_mask = 0LL;
event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
num_peers,
event_mask,
master_controller_cb,
- NULL, /* master_controller_cb cls */
+ NULL, /* master_controller_cb cls */
&test_master,
- NULL); /* test_master cls */
+ NULL); /* test_master cls */
GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_uint ('C',
- "connections",
- "COUNT",
- gettext_noop ("limit to the number of connections to NSE services, 0 for none"),
- &connection_limit),
- GNUNET_GETOPT_option_string ('d',
- "details",
- "FILENAME",
- gettext_noop ("name of the file for writing connection information and statistics"),
- &data_filename),
-
- GNUNET_GETOPT_option_string ('H',
- "hosts",
- "FILENAME",
- gettext_noop ("name of the file with the login information for the testbed"),
- &hosts_file),
-
- GNUNET_GETOPT_option_string ('o',
- "output",
- "FILENAME",
- gettext_noop ("name of the file for writing the main results"),
- &output_filename),
-
-
- GNUNET_GETOPT_option_string ('p',
- "peers",
- "NETWORKSIZESPEC",
- gettext_noop ("Number of peers to run in each round, separated by commas"),
- &num_peer_spec),
-
- GNUNET_GETOPT_option_increment_uint ('V',
- "verbose",
- gettext_noop ("be verbose (print progress information)"),
- &verbose),
-
- GNUNET_GETOPT_option_relative_time ('w',
- "wait",
- "DELAY",
- gettext_noop ("delay between rounds"),
- &wait_time),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_uint (
+ 'C',
+ "connections",
+ "COUNT",
+ gettext_noop (
+ "limit to the number of connections to NSE services, 0 for none"),
+ &connection_limit),
+ GNUNET_GETOPT_option_string (
+ 'd',
+ "details",
+ "FILENAME",
+ gettext_noop (
+ "name of the file for writing connection information and statistics"),
+ &data_filename),
+
+ GNUNET_GETOPT_option_string (
+ 'H',
+ "hosts",
+ "FILENAME",
+ gettext_noop (
+ "name of the file with the login information for the testbed"),
+ &hosts_file),
+
+ GNUNET_GETOPT_option_string (
+ 'o',
+ "output",
+ "FILENAME",
+ gettext_noop ("name of the file for writing the main results"),
+ &output_filename),
+
+
+ GNUNET_GETOPT_option_string (
+ 'p',
+ "peers",
+ "NETWORKSIZESPEC",
+ gettext_noop (
+ "Number of peers to run in each round, separated by commas"),
+ &num_peer_spec),
+
+ GNUNET_GETOPT_option_increment_uint (
+ 'V',
+ "verbose",
+ gettext_noop ("be verbose (print progress information)"),
+ &verbose),
+
+ GNUNET_GETOPT_option_relative_time ('w',
+ "wait",
+ "DELAY",
+ gettext_noop ("delay between rounds"),
+ &wait_time),
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- if (GNUNET_OK !=
- GNUNET_PROGRAM_run (argc, argv, "nse-profiler",
- gettext_noop
- ("Measure quality and performance of the NSE service."),
- options, &run, NULL))
+ if (
+ GNUNET_OK !=
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "nse-profiler",
+ gettext_noop (
+ "Measure quality and performance of the NSE service."),
+ options,
+ &run,
+ NULL))
ok = 1;
return ok;
}
{
(void) cls;
status = 0;
- FPRINTF (stdout,
+ fprintf (stdout,
"%llu %f %f %f\n",
(unsigned long long) timestamp.abs_value_us,
GNUNET_NSE_log_estimate_to_n (estimate),
{
int *ok = cls;
- FPRINTF (stderr,
+ fprintf (stderr,
"Received NSE message, estimate %f, standard deviation %f.\n",
estimate, std_dev);
/* Fantastic check below. Expect NaN, the only thing not equal to itself. */
{
struct NSEPeer *peer = cls;
- FPRINTF (stderr,
+ fprintf (stderr,
"Received network size estimate from peer %u. logSize: %f std.dev. %f (%f/%u)\n",
(unsigned int) (peer - nse_peers),
estimate, std_dev,
* Hello was friend only, #GNUNET_YES or #GNUNET_NO
*/
int friend_only;
-
};
{
unsigned int i;
- printf (_("%sPeer `%s'\n"),
- (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
- GNUNET_i2s_full (&pc->peer));
+ printf (_ ("%sPeer `%s'\n"),
+ (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
+ GNUNET_i2s_full (&pc->peer));
for (i = 0; i < pc->num_addresses; i++)
{
if (NULL != pc->address_list[i].result)
{
- printf (_("\tExpires: %s \t %s\n"),
- GNUNET_STRINGS_absolute_time_to_string (pc->address_list[i].expiration),
+ printf (_ ("\tExpires: %s \t %s\n"),
+ GNUNET_STRINGS_absolute_time_to_string (
+ pc->address_list[i].expiration),
pc->address_list[i].result);
GNUNET_free (pc->address_list[i].result);
}
}
printf ("\n");
GNUNET_free_non_null (pc->address_list);
- GNUNET_CONTAINER_DLL_remove (pc_head,
- pc_tail,
- pc);
+ GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
GNUNET_free (pc);
- if ( (NULL == pc_head) &&
- (NULL == pic) )
- tt = GNUNET_SCHEDULER_add_now (&state_machine,
- NULL);
+ if ((NULL == pc_head) && (NULL == pic))
+ tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
}
* if #GNUNET_SYSERR: address is invalid
*/
static void
-process_resolved_address (void *cls,
- const char *address,
- int res)
+process_resolved_address (void *cls, const char *address, int res)
{
struct AddressRecord *ar = cls;
struct PrintContext *pc = ar->pc;
ar->atsc = NULL;
if (GNUNET_SYSERR == res)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Failure: Cannot convert address to string for peer `%s'\n"),
+ _ ("Failure: Cannot convert address to string for peer `%s'\n"),
GNUNET_i2s (&ar->pc->peer));
pc->num_addresses++;
if (pc->num_addresses == pc->address_list_size)
ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg,
address,
no_resolve,
- TIMEOUT,
- &process_resolved_address, ar);
+ TIMEOUT,
+ &process_resolved_address,
+ ar);
return GNUNET_OK;
}
pic = NULL; /* end of iteration */
if (NULL != err_msg)
{
- FPRINTF (stderr,
- _("Error in communication with PEERINFO service: %s\n"),
- err_msg);
+ fprintf (stderr,
+ _ ("Error in communication with PEERINFO service: %s\n"),
+ err_msg);
}
if (NULL == pc_head)
tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
}
friend_only = GNUNET_NO;
if (NULL != hello)
- friend_only = GNUNET_HELLO_is_friend_only (hello);
- if ( (GNUNET_YES == be_quiet) ||
- (NULL == hello) )
+ friend_only = GNUNET_HELLO_is_friend_only (hello);
+ if ((GNUNET_YES == be_quiet) || (NULL == hello))
{
printf ("%s%s\n",
- (GNUNET_YES == friend_only) ? "F2F: " : "",
- GNUNET_i2s_full (peer));
+ (GNUNET_YES == friend_only) ? "F2F: " : "",
+ GNUNET_i2s_full (peer));
return;
}
pc = GNUNET_new (struct PrintContext);
- GNUNET_CONTAINER_DLL_insert (pc_head,
- pc_tail,
- pc);
+ GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
pc->peer = *peer;
pc->friend_only = friend_only;
- GNUNET_HELLO_iterate_addresses (hello,
- GNUNET_NO,
- &count_address,
- pc);
+ GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_address, pc);
if (0 == pc->off)
{
dump_pc (pc);
}
pc->address_list_size = pc->off;
pc->address_list = GNUNET_malloc (sizeof (struct AddressRecord) * pc->off);
- GNUNET_HELLO_iterate_addresses (hello,
- GNUNET_NO,
- &print_address,
- pc);
+ GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc);
}
/* ************************* DUMP Hello ************************** */
size = GNUNET_HELLO_size (my_hello);
if (0 == size)
{
- FPRINTF (stderr,
- _("Failure: Received invalid %s\n"),
- "HELLO");
+ fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO");
return;
}
- if (GNUNET_SYSERR ==
- GNUNET_DISK_fn_write (dump_hello,
- my_hello,
- size,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ))
+ if (GNUNET_SYSERR == GNUNET_DISK_fn_write (dump_hello,
+ my_hello,
+ size,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ))
{
- FPRINTF (stderr,
- _("Failed to write HELLO with %u bytes to file `%s'\n"),
+ fprintf (stderr,
+ _ ("Failed to write HELLO with %u bytes to file `%s'\n"),
size,
dump_hello);
- if (0 != UNLINK (dump_hello))
+ if (0 != unlink (dump_hello))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK,
+ GNUNET_ERROR_TYPE_BULK,
"unlink",
dump_hello);
-
}
c_addr = 0;
- GNUNET_HELLO_iterate_addresses (my_hello,
- GNUNET_NO,
- count_addr,
- &c_addr);
+ GNUNET_HELLO_iterate_addresses (my_hello, GNUNET_NO, count_addr, &c_addr);
if (! be_quiet)
{
- FPRINTF (stderr,
- _("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"),
- (GNUNET_YES == GNUNET_HELLO_is_friend_only (my_hello)) ? "friend-only": "public",
- c_addr,
- size,
- dump_hello);
+ fprintf (
+ stderr,
+ _ ("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"),
+ (GNUNET_YES == GNUNET_HELLO_is_friend_only (my_hello)) ? "friend-only"
+ : "public",
+ c_addr,
+ size,
+ dump_hello);
}
GNUNET_free (dump_hello);
dump_hello = NULL;
print_my_uri (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Message *hello,
- const char *err_msg)
+ const char *err_msg)
{
char *uri;
{
pic = NULL;
if (NULL != err_msg)
- FPRINTF (stderr,
- _("Error in communication with PEERINFO service: %s\n"),
- err_msg);
+ fprintf (stderr,
+ _ ("Error in communication with PEERINFO service: %s\n"),
+ err_msg);
tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
return;
}
if (NULL == hello)
return;
- uri = GNUNET_HELLO_compose_uri (hello,
- &GPI_plugins_find);
+ uri = GNUNET_HELLO_compose_uri (hello, &GPI_plugins_find);
if (NULL != uri)
{
- printf ("%s\n",
- (const char *) uri);
+ printf ("%s\n", (const char *) uri);
GNUNET_free (uri);
}
}
{
/* WARNING: this adds the address from URI WITHOUT verification! */
if (GNUNET_OK == ret)
- ac = GNUNET_PEERINFO_add_peer (peerinfo,
- hello,
- &add_continuation,
- NULL);
+ ac = GNUNET_PEERINFO_add_peer (peerinfo, hello, &add_continuation, NULL);
else
tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
GNUNET_free (hello);
}
while (NULL != (pc = pc_head))
{
- GNUNET_CONTAINER_DLL_remove (pc_head,
- pc_tail,
- pc);
- for (i=0;i<pc->address_list_size;i++)
+ GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
+ for (i = 0; i < pc->address_list_size; i++)
{
ar = &pc->address_list[i];
GNUNET_free_non_null (ar->result);
if (NULL != ar->atsc)
{
- GNUNET_TRANSPORT_address_to_string_cancel (ar->atsc);
- ar->atsc = NULL;
+ GNUNET_TRANSPORT_address_to_string_cancel (ar->atsc);
+ ar->atsc = NULL;
}
}
GNUNET_free_non_null (pc->address_list);
* @param hello the HELLO message
*/
static void
-hello_callback (void *cls,
- const struct GNUNET_MessageHeader *hello)
+hello_callback (void *cls, const struct GNUNET_MessageHeader *hello)
{
if (NULL == hello)
{
- fprintf (stderr,
- "Failed to get my own HELLO from this peer!\n");
+ fprintf (stderr, "Failed to get my own HELLO from this peer!\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
my_hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (hello);
GNUNET_assert (GNUNET_OK ==
- GNUNET_HELLO_get_id (my_hello,
- &my_peer_identity));
+ GNUNET_HELLO_get_id (my_hello, &my_peer_identity));
GNUNET_TRANSPORT_hello_get_cancel (gh);
gh = NULL;
if (NULL != dump_hello)
const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
- if ( (NULL != args[0]) &&
- (NULL == put_uri) &&
- (args[0] == strcasestr (args[0],
- "gnunet://hello/")) )
+ if ((NULL != args[0]) && (NULL == put_uri) &&
+ (args[0] == strcasestr (args[0], "gnunet://hello/")))
{
put_uri = GNUNET_strdup (args[0]);
args++;
}
if (NULL != args[0])
{
- FPRINTF (stderr,
- _("Invalid command line argument `%s'\n"),
- args[0]);
+ fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
return;
}
if (NULL == (peerinfo = GNUNET_PEERINFO_connect (cfg)))
{
- FPRINTF (stderr,
- "%s",
- "Could not access PEERINFO service. Exiting.\n");
+ fprintf (stderr, "%s", "Could not access PEERINFO service. Exiting.\n");
return;
}
- if ( (GNUNET_YES == get_self) ||
- (GNUNET_YES == get_uri) ||
- (NULL != dump_hello) )
+ if ((GNUNET_YES == get_self) || (GNUNET_YES == get_uri) ||
+ (NULL != dump_hello))
{
gh = GNUNET_TRANSPORT_hello_get (cfg,
- GNUNET_TRANSPORT_AC_ANY,
+ GNUNET_TRANSPORT_AC_ANY,
&hello_callback,
NULL);
}
else
{
- tt = GNUNET_SCHEDULER_add_now (&state_machine,
- NULL);
+ tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
}
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
GPI_plugins_load (cfg);
if (GNUNET_SYSERR == parse_hello_uri (put_uri))
{
- fprintf (stderr,
- _("Invalid URI `%s'\n"),
- put_uri);
+ fprintf (stderr, _ ("Invalid URI `%s'\n"), put_uri);
GNUNET_SCHEDULER_shutdown ();
}
GNUNET_free (put_uri);
pic = GNUNET_PEERINFO_iterate (peerinfo,
include_friend_only,
NULL,
- &print_peer_info,
- NULL);
+ &print_peer_info,
+ NULL);
}
else if (GNUNET_YES == get_self)
{
get_self = GNUNET_NO;
if (be_quiet)
- printf ("%s\n",
- GNUNET_i2s_full (&my_peer_identity));
+ printf ("%s\n", GNUNET_i2s_full (&my_peer_identity));
else
- printf (_("I am peer `%s'.\n"),
- GNUNET_i2s_full (&my_peer_identity));
- tt = GNUNET_SCHEDULER_add_now (&state_machine,
- NULL);
+ printf (_ ("I am peer `%s'.\n"), GNUNET_i2s_full (&my_peer_identity));
+ tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
}
else if (GNUNET_YES == get_uri)
{
include_friend_only,
&my_peer_identity,
&print_my_uri,
- NULL);
+ NULL);
get_uri = GNUNET_NO;
}
else if (GNUNET_YES == default_operation)
/* default operation list all */
default_operation = GNUNET_NO;
get_info = GNUNET_YES;
- tt = GNUNET_SCHEDULER_add_now (&state_machine,
- NULL);
+ tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
}
else
{
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('n',
- "numeric",
- gettext_noop ("don't resolve host names"),
- &no_resolve),
-
- GNUNET_GETOPT_option_flag ('q',
- "quiet",
- gettext_noop ("output only the identity strings"),
- &be_quiet),
- GNUNET_GETOPT_option_flag ('f',
- "friends",
- gettext_noop ("include friend-only information"),
- &include_friend_only),
-
- GNUNET_GETOPT_option_flag ('s',
- "self",
- gettext_noop ("output our own identity only"),
- &get_self),
-
- GNUNET_GETOPT_option_flag ('i',
- "info",
- gettext_noop ("list all known peers"),
- &get_info),
-
- GNUNET_GETOPT_option_string ('d',
- "dump-hello",
- NULL,
- gettext_noop ("dump hello to file"),
- &dump_hello),
-
- GNUNET_GETOPT_option_flag ('g',
- "get-hello",
- gettext_noop ("also output HELLO uri(s)"),
- &get_uri),
-
- GNUNET_GETOPT_option_string ('p',
- "put-hello",
- "HELLO",
- gettext_noop ("add given HELLO uri to the database"),
- &put_uri),
-
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag ('n',
+ "numeric",
+ gettext_noop ("don't resolve host names"),
+ &no_resolve),
+
+ GNUNET_GETOPT_option_flag ('q',
+ "quiet",
+ gettext_noop (
+ "output only the identity strings"),
+ &be_quiet),
+ GNUNET_GETOPT_option_flag ('f',
+ "friends",
+ gettext_noop (
+ "include friend-only information"),
+ &include_friend_only),
+
+ GNUNET_GETOPT_option_flag ('s',
+ "self",
+ gettext_noop ("output our own identity only"),
+ &get_self),
+
+ GNUNET_GETOPT_option_flag ('i',
+ "info",
+ gettext_noop ("list all known peers"),
+ &get_info),
+
+ GNUNET_GETOPT_option_string ('d',
+ "dump-hello",
+ NULL,
+ gettext_noop ("dump hello to file"),
+ &dump_hello),
+
+ GNUNET_GETOPT_option_flag ('g',
+ "get-hello",
+ gettext_noop ("also output HELLO uri(s)"),
+ &get_uri),
+
+ GNUNET_GETOPT_option_string ('p',
+ "put-hello",
+ "HELLO",
+ gettext_noop (
+ "add given HELLO uri to the database"),
+ &put_uri),
+
+ GNUNET_GETOPT_OPTION_END};
int ret;
default_operation = GNUNET_YES;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc,
- argv,
- &argc,
- &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-peerinfo",
- gettext_noop ("Print information about peers."),
- options,
- &run,
- NULL)) ? 0 : 1;
- GNUNET_free ((void*) argv);
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-peerinfo",
+ gettext_noop ("Print information about peers."),
+ options,
+ &run,
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
/**
* How often do we scan the HOST_DIR for new entries?
*/
-#define DATA_HOST_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+#define DATA_HOST_FREQ \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
/**
* How often do we discard old entries in data/hosts/?
*/
-#define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60)
+#define DATA_HOST_CLEAN_FREQ \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60)
/**
* Friend only hello for the peer (can be NULL)
*/
struct GNUNET_HELLO_Message *friend_only_hello;
-
};
* @return generated notification message
*/
static struct InfoMessage *
-make_info_message (const struct HostEntry *he,
- int include_friend_only)
+make_info_message (const struct HostEntry *he, int include_friend_only)
{
struct InfoMessage *im;
struct GNUNET_HELLO_Message *src;
im->header.size = htons (hs + sizeof (struct InfoMessage));
im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
im->peer = he->identity;
- GNUNET_memcpy (&im[1],
- src,
- hs);
+ GNUNET_memcpy (&im[1], src, hs);
return im;
}
if (now->abs_value_us > expiration.abs_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Removing expired address of transport `%s'\n"),
+ _ ("Removing expired address of transport `%s'\n"),
address->transport_name);
return GNUNET_NO;
}
struct InfoMessage *msg_friend;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notifying all clients about peer `%s'\n",
- GNUNET_i2s(&entry->identity));
- msg_pub = make_info_message (entry,
- GNUNET_NO);
+ "Notifying all clients about peer `%s'\n",
+ GNUNET_i2s (&entry->identity));
+ msg_pub = make_info_message (entry, GNUNET_NO);
GNUNET_notification_context_broadcast (notify_list,
&msg_pub->header,
GNUNET_NO);
GNUNET_free (msg_pub);
- msg_friend = make_info_message (entry,
- GNUNET_YES);
+ msg_friend = make_info_message (entry, GNUNET_YES);
GNUNET_notification_context_broadcast (notify_friend_only_list,
&msg_friend->header,
GNUNET_NO);
if (GNUNET_YES != GNUNET_DISK_file_test (fn))
return;
- size_total = GNUNET_DISK_fn_read (fn,
- buffer,
- sizeof (buffer));
+ size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Read %d bytes from `%s'\n",
(int) size_total,
fn);
- if ( (size_total < 0) ||
- (((size_t) size_total) < sizeof (struct GNUNET_MessageHeader)) )
+ if ((size_total < 0) ||
+ (((size_t) size_total) < sizeof (struct GNUNET_MessageHeader)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse HELLO in file `%s': %s\n"),
- fn,
+ _ ("Failed to parse HELLO in file `%s': %s\n"),
+ fn,
"File has invalid size");
- if ( (GNUNET_YES == unlink_garbage) &&
- (0 != UNLINK (fn)) &&
- (ENOENT != errno) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fn);
+ if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) &&
+ (ENOENT != errno))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
return;
}
{
hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos];
size_hello = GNUNET_HELLO_size (hello);
- if ( (0 == size_hello) ||
- (((size_t) size_total) - read_pos < size_hello) )
+ if ((0 == size_hello) || (((size_t) size_total) - read_pos < size_hello))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse HELLO in file `%s'\n"),
+ _ ("Failed to parse HELLO in file `%s'\n"),
fn);
if (0 == read_pos)
{
- if ((GNUNET_YES == unlink_garbage) &&
- (0 != UNLINK (fn)) &&
- (ENOENT != errno) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fn);
+ if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) &&
+ (ENOENT != errno))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
}
else
{
- if ( (GNUNET_YES == unlink_garbage) &&
- (0 != TRUNCATE (fn, read_pos)) &&
- (ENOENT != errno) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "truncate",
- fn);
+ if ((GNUNET_YES == unlink_garbage) && (0 != truncate (fn, read_pos)) &&
+ (ENOENT != errno))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", fn);
}
return;
}
now = GNUNET_TIME_absolute_get ();
hello_clean = GNUNET_HELLO_iterate_addresses (hello,
GNUNET_YES,
- &discard_expired,
+ &discard_expired,
&now);
if (NULL == hello_clean)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse HELLO in file `%s'\n"),
+ _ ("Failed to parse HELLO in file `%s'\n"),
fn);
- if ((GNUNET_YES == unlink_garbage) &&
- (0 != UNLINK (fn)) &&
- (ENOENT != errno) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fn);
+ if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) &&
+ (ENOENT != errno))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
return;
}
left = 0;
(void) GNUNET_HELLO_iterate_addresses (hello_clean,
GNUNET_NO,
- &count_addresses,
+ &count_addresses,
&left);
if (0 == left)
if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean))
{
if (NULL == r->hello)
- r->hello = hello_clean;
+ r->hello = hello_clean;
else
{
- GNUNET_break (0);
- GNUNET_free (r->hello);
- r->hello = hello_clean;
+ GNUNET_break (0);
+ GNUNET_free (r->hello);
+ r->hello = hello_clean;
}
}
else
{
if (NULL == r->friend_only_hello)
- r->friend_only_hello = hello_clean;
+ r->friend_only_hello = hello_clean;
else
{
- GNUNET_break (0);
- GNUNET_free (r->friend_only_hello);
- r->friend_only_hello = hello_clean;
+ GNUNET_break (0);
+ GNUNET_free (r->friend_only_hello);
+ r->friend_only_hello = hello_clean;
}
}
read_pos += size_hello;
if (0 == left)
{
/* no addresses left, remove from disk */
- if ( (GNUNET_YES == unlink_garbage) &&
- (0 != UNLINK (fn)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fn);
+ if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found `%s' and `%s' HELLO message in file\n",
- (NULL != r->hello) ? "public" : "NON-public",
- (NULL != r->friend_only_hello) ? "friend only" : "NO friend only");
+ "Found `%s' and `%s' HELLO message in file\n",
+ (NULL != r->hello) ? "public" : "NON-public",
+ (NULL != r->friend_only_hello) ? "friend only"
+ : "NO friend only");
}
struct ReadHostFileContext r;
char *fn;
- entry = GNUNET_CONTAINER_multipeermap_get (hostmap,
- identity);
+ entry = GNUNET_CONTAINER_multipeermap_get (hostmap, identity);
if (NULL == entry)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_STATISTICS_update (stats,
gettext_noop ("# peers known"),
1,
- GNUNET_NO);
+ GNUNET_NO);
entry = GNUNET_new (struct HostEntry);
entry->identity = *identity;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (hostmap,
- &entry->identity,
- entry,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multipeermap_put (
+ hostmap,
+ &entry->identity,
+ entry,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
notify_all (entry);
fn = get_host_filename (identity);
if (NULL != fn)
{
- read_host_file (fn,
- GNUNET_YES,
- &r);
+ read_host_file (fn, GNUNET_YES, &r);
if (NULL != r.hello)
- update_hello (identity,
- r.hello);
+ update_hello (identity, r.hello);
if (NULL != r.friend_only_hello)
- update_hello (identity,
- r.friend_only_hello);
+ update_hello (identity, r.friend_only_hello);
GNUNET_free_non_null (r.hello);
GNUNET_free_non_null (r.friend_only_hello);
GNUNET_free (fn);
static void
remove_garbage (const char *fullname)
{
- if (0 == UNLINK (fullname))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- _("File `%s' in directory `%s' does not match naming convention. Removed.\n"),
- fullname,
- networkIdDirectory);
+ if (0 == unlink (fullname))
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+ _ (
+ "File `%s' in directory `%s' does not match naming convention. Removed.\n"),
+ fullname,
+ networkIdDirectory);
else
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"unlink",
* @return #GNUNET_OK (continue iteration)
*/
static int
-hosts_directory_scan_callback (void *cls,
- const char *fullname)
+hosts_directory_scan_callback (void *cls, const char *fullname)
{
struct DirScanContext *dsc = cls;
struct GNUNET_PeerIdentity identity;
struct GNUNET_PeerIdentity id;
if (GNUNET_YES != GNUNET_DISK_file_test (fullname))
- return GNUNET_OK; /* ignore non-files */
+ return GNUNET_OK; /* ignore non-files */
- filename = strrchr (fullname,
- DIR_SEPARATOR);
- if ( (NULL == filename) ||
- (1 > strlen (filename)) )
+ filename = strrchr (fullname, DIR_SEPARATOR);
+ if ((NULL == filename) || (1 > strlen (filename)))
filename = fullname;
else
- filename ++;
+ filename++;
- read_host_file (fullname,
- dsc->remove_files,
- &r);
- if ( (NULL == r.hello) &&
- (NULL == r.friend_only_hello))
+ read_host_file (fullname, dsc->remove_files, &r);
+ if ((NULL == r.hello) && (NULL == r.friend_only_hello))
return GNUNET_OK;
if (NULL != r.friend_only_hello)
{
- if (GNUNET_OK !=
- GNUNET_HELLO_get_id (r.friend_only_hello,
- &id_friend))
+ if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend))
{
if (GNUNET_YES == dsc->remove_files)
- remove_garbage (fullname);
+ remove_garbage (fullname);
return GNUNET_OK;
}
id = id_friend;
}
if (NULL != r.hello)
{
- if (GNUNET_OK !=
- GNUNET_HELLO_get_id (r.hello,
- &id_public))
+ if (GNUNET_OK != GNUNET_HELLO_get_id (r.hello, &id_public))
{
if (GNUNET_YES == dsc->remove_files)
- remove_garbage (fullname);
+ remove_garbage (fullname);
return GNUNET_OK;
}
id = id_public;
}
- if ( (NULL != r.hello) &&
- (NULL != r.friend_only_hello) &&
- (0 != GNUNET_memcmp (&id_friend,
- &id_public)) )
+ if ((NULL != r.hello) && (NULL != r.friend_only_hello) &&
+ (0 != GNUNET_memcmp (&id_friend, &id_public)))
{
/* HELLOs are not for the same peer */
GNUNET_break (0);
/* HELLOs are not for the same peer */
GNUNET_break (0);
if (GNUNET_YES == dsc->remove_files)
- remove_garbage (fullname);
+ remove_garbage (fullname);
return GNUNET_OK;
}
}
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Updating peer `%s' public HELLO \n",
- GNUNET_i2s (&id));
+ GNUNET_i2s (&id));
update_hello (&id, r.hello);
GNUNET_free (r.hello);
}
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Updating peer `%s' friend only HELLO \n",
- GNUNET_i2s (&id));
+ GNUNET_i2s (&id));
update_hello (&id, r.friend_only_hello);
GNUNET_free (r.friend_only_hello);
}
(void) cls;
cron_scan = NULL;
- if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_create (networkIdDirectory))
+ if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory))
{
- cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts, NULL);
+ cron_scan =
+ GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts,
+ NULL);
return;
}
dsc.matched = 0;
dsc.remove_files = GNUNET_YES;
GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
- _("Scanning directory `%s'\n"),
+ _ ("Scanning directory `%s'\n"),
networkIdDirectory);
GNUNET_DISK_directory_scan (networkIdDirectory,
&hosts_directory_scan_callback,
&dsc);
- if ( (0 == dsc.matched) &&
- (0 == (++retries & 31)) )
+ if ((0 == dsc.matched) && (0 == (++retries & 31)))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- _("Still no peers found in `%s'!\n"),
+ _ ("Still no peers found in `%s'!\n"),
networkIdDirectory);
- cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts,
- NULL);
+ cron_scan =
+ GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts,
+ NULL);
}
*/
static struct GNUNET_HELLO_Message *
update_friend_hello (const struct GNUNET_HELLO_Message *hello,
- const struct GNUNET_HELLO_Message *friend_hello)
+ const struct GNUNET_HELLO_Message *friend_hello)
{
- struct GNUNET_HELLO_Message * res;
- struct GNUNET_HELLO_Message * tmp;
+ struct GNUNET_HELLO_Message *res;
+ struct GNUNET_HELLO_Message *tmp;
struct GNUNET_PeerIdentity pid;
if (NULL != friend_hello)
{
- res = GNUNET_HELLO_merge (hello,
- friend_hello);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_HELLO_is_friend_only (res));
+ res = GNUNET_HELLO_merge (hello, friend_hello);
+ GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res));
return res;
}
- if (GNUNET_OK !=
- GNUNET_HELLO_get_id (hello, &pid))
+ if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
{
GNUNET_break (0);
return NULL;
}
- tmp = GNUNET_HELLO_create (&pid.public_key,
- NULL,
- NULL,
- GNUNET_YES);
+ tmp = GNUNET_HELLO_create (&pid.public_key, NULL, NULL, GNUNET_YES);
res = GNUNET_HELLO_merge (hello, tmp);
GNUNET_free (tmp);
GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res));
}
else
{
- mrg = GNUNET_HELLO_merge ((*dest),
- hello);
- delta = GNUNET_HELLO_equals (mrg,
- (*dest),
- GNUNET_TIME_absolute_get ());
+ mrg = GNUNET_HELLO_merge ((*dest), hello);
+ delta = GNUNET_HELLO_equals (mrg, (*dest), GNUNET_TIME_absolute_get ());
if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
{
/* no differences, just ignore the update */
(*dest) = mrg;
}
- if ( (NULL != (host->hello)) &&
- (GNUNET_NO == friend_hello_type) )
+ if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type))
{
/* Update friend only hello */
- mrg = update_friend_hello (host->hello,
- host->friend_only_hello);
+ mrg = update_friend_hello (host->hello, host->friend_only_hello);
if (NULL != host->friend_only_hello)
GNUNET_free (host->friend_only_hello);
host->friend_only_hello = mrg;
}
if (NULL != host->hello)
- GNUNET_assert ((GNUNET_NO ==
- GNUNET_HELLO_is_friend_only (host->hello)));
+ GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello)));
if (NULL != host->friend_only_hello)
- GNUNET_assert ((GNUNET_YES ==
- GNUNET_HELLO_is_friend_only (host->friend_only_hello)));
+ GNUNET_assert (
+ (GNUNET_YES == GNUNET_HELLO_is_friend_only (host->friend_only_hello)));
fn = get_host_filename (peer);
- if ( (NULL != fn) &&
- (GNUNET_OK ==
- GNUNET_DISK_directory_create_for_file (fn)) )
+ if ((NULL != fn) && (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)))
{
store_hello = GNUNET_NO;
size = 0;
cnt = 0;
if (NULL != host->hello)
(void) GNUNET_HELLO_iterate_addresses (host->hello,
- GNUNET_NO,
+ GNUNET_NO,
&count_addresses,
&cnt);
if (cnt > 0)
if (NULL != host->friend_only_hello)
(void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello,
GNUNET_NO,
- &count_addresses,
+ &count_addresses,
&cnt);
store_friend_hello = GNUNET_NO;
if (0 < cnt)
size += GNUNET_HELLO_size (host->friend_only_hello);
}
- if ( (GNUNET_NO == store_hello) &&
- (GNUNET_NO == store_friend_hello) )
+ if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello))
{
/* no valid addresses, don't put HELLO on disk; in fact,
if one exists on disk, remove it */
- (void) UNLINK (fn);
+ (void) unlink (fn);
}
else
{
if (GNUNET_YES == store_hello)
{
- GNUNET_memcpy (buffer,
- host->hello,
- GNUNET_HELLO_size (host->hello));
- pos += GNUNET_HELLO_size (host->hello);
+ GNUNET_memcpy (buffer, host->hello, GNUNET_HELLO_size (host->hello));
+ pos += GNUNET_HELLO_size (host->hello);
}
if (GNUNET_YES == store_friend_hello)
{
- GNUNET_memcpy (&buffer[pos],
- host->friend_only_hello,
- GNUNET_HELLO_size (host->friend_only_hello));
- pos += GNUNET_HELLO_size (host->friend_only_hello);
+ GNUNET_memcpy (&buffer[pos],
+ host->friend_only_hello,
+ GNUNET_HELLO_size (host->friend_only_hello));
+ pos += GNUNET_HELLO_size (host->friend_only_hello);
}
GNUNET_assert (pos == size);
- if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, buffer, size,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
+ if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn,
+ buffer,
+ size,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Stored %s %s HELLO in %s with total size %u\n",
- (GNUNET_YES == store_friend_hello) ? "friend-only": "",
- (GNUNET_YES == store_hello) ? "public": "",
- fn,
+ (GNUNET_YES == store_friend_hello) ? "friend-only" : "",
+ (GNUNET_YES == store_hello) ? "public" : "",
+ fn,
size);
GNUNET_free (buffer);
}
* @return #GNUNET_YES (continue to iterate)
*/
static int
-add_to_tc (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
{
struct TransmitContext *tc = cls;
struct HostEntry *pos = value;
hs = 0;
- if ( (NULL != pos->hello) &&
- (GNUNET_NO == tc->friend_only) )
+ if ((NULL != pos->hello) && (GNUNET_NO == tc->friend_only))
{
- /* Copy public HELLO */
+ /* Copy public HELLO */
hs = GNUNET_HELLO_size (pos->hello);
- GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE -
- sizeof (struct InfoMessage));
- env = GNUNET_MQ_msg_extra (im,
- hs,
- GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
- GNUNET_memcpy (&im[1],
- pos->hello,
- hs);
+ GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InfoMessage));
+ env = GNUNET_MQ_msg_extra (im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
+ GNUNET_memcpy (&im[1], pos->hello, hs);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending public HELLO with size %u for peer `%s'\n",
- hs,
+ hs,
GNUNET_i2s (key));
}
- else if ( (NULL != pos->friend_only_hello) &&
- (GNUNET_YES == tc->friend_only) )
+ else if ((NULL != pos->friend_only_hello) && (GNUNET_YES == tc->friend_only))
{
- /* Copy friend only HELLO */
+ /* Copy friend only HELLO */
hs = GNUNET_HELLO_size (pos->friend_only_hello);
- GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE -
- sizeof (struct InfoMessage));
- env = GNUNET_MQ_msg_extra (im,
- hs,
- GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
- GNUNET_memcpy (&im[1],
- pos->friend_only_hello,
- hs);
+ GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InfoMessage));
+ env = GNUNET_MQ_msg_extra (im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
+ GNUNET_memcpy (&im[1], pos->friend_only_hello, hs);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending friend-only HELLO with size %u for peer `%s'\n",
- hs,
+ hs,
GNUNET_i2s (key));
}
else
{
- env = GNUNET_MQ_msg (im,
- GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
+ env = GNUNET_MQ_msg (im, GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding no HELLO for peer `%s'\n",
GNUNET_i2s (key));
}
im->peer = pos->identity;
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (tc->client),
- env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (tc->client), env);
return GNUNET_YES;
}
* @return #GNUNET_OK (continue iteration)
*/
static int
-discard_hosts_helper (void *cls,
- const char *fn)
+discard_hosts_helper (void *cls, const char *fn)
{
struct GNUNET_TIME_Absolute *now = cls;
char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
unsigned int cnt;
char *writebuffer;
uint64_t fsize;
-
- if (GNUNET_OK !=
- GNUNET_DISK_file_size (fn,
- &fsize,
- GNUNET_YES,
- GNUNET_YES))
+
+ if (GNUNET_OK != GNUNET_DISK_file_size (fn, &fsize, GNUNET_YES, GNUNET_YES))
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK,
- "fstat",
- fn);
+ GNUNET_ERROR_TYPE_BULK,
+ "fstat",
+ fn);
return GNUNET_OK;
}
- read_size = GNUNET_DISK_fn_read (fn,
- buffer,
- sizeof (buffer));
+ read_size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
- if ( (read_size < (int) sizeof (struct GNUNET_MessageHeader)) ||
- (fsize > GNUNET_MAX_MESSAGE_SIZE) )
+ if ((read_size < (int) sizeof (struct GNUNET_MessageHeader)) ||
+ (fsize > GNUNET_MAX_MESSAGE_SIZE))
{
- if (0 != UNLINK (fn))
+ if (0 != unlink (fn))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK,
- "unlink",
- fn);
+ GNUNET_ERROR_TYPE_BULK,
+ "unlink",
+ fn);
return GNUNET_OK;
}
if (0 == cur_hello_size)
{
/* Invalid data, discard */
- if (0 != UNLINK (fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK,
+ if (0 != unlink (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
+ GNUNET_ERROR_TYPE_BULK,
"unlink",
fn);
GNUNET_free (writebuffer);
return GNUNET_OK;
}
- new_hello = GNUNET_HELLO_iterate_addresses (hello,
- GNUNET_YES,
- &discard_expired,
- now);
+ new_hello =
+ GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now);
cnt = 0;
if (NULL != new_hello)
(void) GNUNET_HELLO_iterate_addresses (hello,
GNUNET_NO,
&count_addresses,
&cnt);
- if ( (NULL != new_hello) && (0 < cnt) )
+ if ((NULL != new_hello) && (0 < cnt))
{
/* Store new HELLO to write it when done */
new_hello_size = GNUNET_HELLO_size (new_hello);
- GNUNET_memcpy (&writebuffer[write_pos],
- new_hello,
- new_hello_size);
+ GNUNET_memcpy (&writebuffer[write_pos], new_hello, new_hello_size);
write_pos += new_hello_size;
}
read_pos += cur_hello_size;
writebuffer,
write_pos,
GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ);
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_OTHER_READ);
}
- else if (0 != UNLINK (fn))
+ else if (0 != unlink (fn))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
- GNUNET_ERROR_TYPE_BULK,
- "unlink", fn);
+ GNUNET_ERROR_TYPE_BULK,
+ "unlink",
+ fn);
GNUNET_free (writebuffer);
return GNUNET_OK;
cron_clean = NULL;
now = GNUNET_TIME_absolute_get ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
- _("Cleaning up directory `%s'\n"),
+ _ ("Cleaning up directory `%s'\n"),
networkIdDirectory);
- GNUNET_DISK_directory_scan (networkIdDirectory,
- &discard_hosts_helper,
- &now);
+ GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now);
cron_clean = GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
- &cron_clean_data_hosts,
- NULL);
+ &cron_clean_data_hosts,
+ NULL);
}
* @return #GNUNET_OK if @a hello is well-formed
*/
static int
-check_hello (void *cls,
- const struct GNUNET_HELLO_Message *hello)
+check_hello (void *cls, const struct GNUNET_HELLO_Message *hello)
{
struct GNUNET_PeerIdentity pid;
(void) cls;
- if (GNUNET_OK !=
- GNUNET_HELLO_get_id (hello,
- &pid))
+ if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
{
GNUNET_break (0);
return GNUNET_SYSERR;
* @param hello the actual message
*/
static void
-handle_hello (void *cls,
- const struct GNUNET_HELLO_Message *hello)
+handle_hello (void *cls, const struct GNUNET_HELLO_Message *hello)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_PeerIdentity pid;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_HELLO_get_id (hello,
- &pid));
+ GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &pid));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"HELLO message received for peer `%s'\n",
GNUNET_i2s (&pid));
add_host_to_known_hosts (&pid);
- update_hello (&pid,
- hello);
+ update_hello (&pid, hello);
GNUNET_SERVICE_client_continue (client);
}
* @param lpm the actual message
*/
static void
-handle_get (void *cls,
- const struct ListPeerMessage *lpm)
+handle_get (void *cls, const struct ListPeerMessage *lpm)
{
struct GNUNET_SERVICE_Client *client = cls;
struct TransmitContext tcx;
&lpm->peer,
&add_to_tc,
&tcx);
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
GNUNET_SERVICE_client_continue (client);
}
* @param lapm the actual message
*/
static void
-handle_get_all (void *cls,
- const struct ListAllPeersMessage *lapm)
+handle_get_all (void *cls, const struct ListAllPeersMessage *lapm)
{
struct GNUNET_SERVICE_Client *client = cls;
struct TransmitContext tcx;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GET_ALL message received\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET_ALL message received\n");
tcx.friend_only = ntohl (lapm->include_friend_only);
tcx.client = client;
- GNUNET_CONTAINER_multipeermap_iterate (hostmap,
- &add_to_tc,
- &tcx);
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
GNUNET_SERVICE_client_continue (client);
}
* @param nm the actual message
*/
static void
-handle_notify (void *cls,
- const struct NotifyMessage *nm)
+handle_notify (void *cls, const struct NotifyMessage *nm)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_MQ_Handle *mq;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "NOTIFY message received\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "NOTIFY message received\n");
mq = GNUNET_SERVICE_client_get_mq (client);
GNUNET_SERVICE_client_mark_monitor (client);
if (ntohl (nm->include_friend_only))
- GNUNET_notification_context_add (notify_friend_only_list,
- mq);
+ GNUNET_notification_context_add (notify_friend_only_list, mq);
else
- GNUNET_notification_context_add (notify_list,
- mq);
+ GNUNET_notification_context_add (notify_list, mq);
tcx.friend_only = ntohl (nm->include_friend_only);
tcx.client = client;
- GNUNET_CONTAINER_multipeermap_iterate (hostmap,
- &add_to_tc,
- &tcx);
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
GNUNET_SERVICE_client_continue (client);
}
* @return #GNUNET_YES (continue to iterate)
*/
static int
-free_host_entry (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+free_host_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
{
struct HostEntry *he = value;
GNUNET_notification_context_destroy (notify_friend_only_list);
notify_friend_only_list = NULL;
- GNUNET_CONTAINER_multipeermap_iterate (hostmap,
- &free_host_entry,
- NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (hostmap, &free_host_entry, NULL);
GNUNET_CONTAINER_multipeermap_destroy (hostmap);
if (NULL != stats)
{
- GNUNET_STATISTICS_destroy (stats,
- GNUNET_NO);
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
stats = NULL;
}
if (NULL != cron_clean)
(void) cls;
(void) service;
- hostmap
- = GNUNET_CONTAINER_multipeermap_create (1024,
- GNUNET_YES);
- stats
- = GNUNET_STATISTICS_create ("peerinfo",
- cfg);
- notify_list
- = GNUNET_notification_context_create (0);
- notify_friend_only_list
- = GNUNET_notification_context_create (0);
- noio = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "peerinfo",
- "NO_IO");
- use_included
- = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "peerinfo",
- "USE_INCLUDED_HELLOS");
+ hostmap = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
+ stats = GNUNET_STATISTICS_create ("peerinfo", cfg);
+ notify_list = GNUNET_notification_context_create (0);
+ notify_friend_only_list = GNUNET_notification_context_create (0);
+ noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO");
+ use_included = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "peerinfo",
+ "USE_INCLUDED_HELLOS");
if (GNUNET_SYSERR == use_included)
use_included = GNUNET_NO;
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
if (GNUNET_YES != noio)
{
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "peerinfo",
- "HOSTS",
- &networkIdDirectory));
- if (GNUNET_OK !=
- GNUNET_DISK_directory_create (networkIdDirectory))
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "peerinfo",
+ "HOSTS",
+ &networkIdDirectory));
+ if (GNUNET_OK != GNUNET_DISK_directory_create (networkIdDirectory))
{
GNUNET_SCHEDULER_shutdown ();
return;
}
- cron_scan
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts,
- NULL);
+ cron_scan =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts,
+ NULL);
- cron_clean
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_clean_data_hosts,
- NULL);
+ cron_clean =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_clean_data_hosts,
+ NULL);
if (GNUNET_YES == use_included)
{
ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
- GNUNET_asprintf (&peerdir,
- "%shellos",
- ip);
+ GNUNET_asprintf (&peerdir, "%shellos", ip);
GNUNET_free (ip);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Importing HELLOs from `%s'\n"),
+ _ ("Importing HELLOs from `%s'\n"),
peerdir);
dsc.matched = 0;
dsc.remove_files = GNUNET_NO;
else
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Skipping import of included HELLOs\n"));
+ _ ("Skipping import of included HELLOs\n"));
}
}
}
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("peerinfo",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_var_size (hello,
- GNUNET_MESSAGE_TYPE_HELLO,
- struct GNUNET_HELLO_Message,
- NULL),
- GNUNET_MQ_hd_fixed_size (get,
- GNUNET_MESSAGE_TYPE_PEERINFO_GET,
- struct ListPeerMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (get_all,
- GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,
- struct ListAllPeersMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (notify,
- GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY,
- struct NotifyMessage,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN (
+ "peerinfo",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_var_size (hello,
+ GNUNET_MESSAGE_TYPE_HELLO,
+ struct GNUNET_HELLO_Message,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get,
+ GNUNET_MESSAGE_TYPE_PEERINFO_GET,
+ struct ListPeerMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get_all,
+ GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,
+ struct ListAllPeersMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (notify,
+ GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY,
+ struct NotifyMessage,
+ NULL),
+ GNUNET_MQ_handler_end ());
/* end of gnunet-service-peerinfo.c */
"test_peerinfo_api_data.conf",
&run, NULL))
return 1;
- FPRINTF (stderr,
+ fprintf (stderr,
"Received %u/%u calls before timeout\n",
numpeers,
NUM_REQUESTS * NUM_REQUESTS / 2);
if (NULL == (ret = GNUNET_PLUGIN_load (libname,
(void*) cfg)))
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Failed to load plugin `%s'!\n",
plugin_name);
GNUNET_free (libname);
psp = load_plugin (cfg);
if (NULL == psp)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Failed to initialize peerstore. Database likely not setup, skipping test.\n");
return;
&run,
NULL);
if (ok != 0)
- FPRINTF (stderr,
+ fprintf (stderr,
"Missed some testcases: %d\n",
ok);
return ok;
payload_len = sizeof (struct OIDC_Parameters);
if (NULL != nonce_str && strcmp ("", nonce_str) != 0)
{
- if ((1 != SSCANF (nonce_str, "%u", &nonce)) || (nonce > UINT32_MAX))
+ if ((1 != sscanf (nonce_str, "%u", &nonce)) || (nonce > UINT32_MAX))
{
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid nonce %s\n", nonce_str);
&access_token);
return access_token;
}
-
{
if (meter->completed == 0)
{
- FPRINTF (stdout, "%sProgress: [0%%", meter->startup_string);
+ fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
}
else
- FPRINTF (stdout, "%d%%",
+ fprintf (stdout, "%d%%",
(int) (((float) meter->completed / meter->total) * 100));
}
else if (meter->completed % meter->dotnum == 0)
- FPRINTF (stdout, "%s", ".");
+ fprintf (stdout, "%s", ".");
if (meter->completed + 1 == meter->total)
- FPRINTF (stdout, "%d%%]\n", 100);
+ fprintf (stdout, "%d%%]\n", 100);
fflush (stdout);
}
meter->completed++;
end_badly ()
{
die_task = NULL;
- FPRINTF (stderr, "%s", "Testcase failed (timeout).\n");
+ fprintf (stderr, "%s", "Testcase failed (timeout).\n");
GNUNET_REGEX_announce_cancel (a);
a = NULL;
GNUNET_REGEX_search_cancel (s);
static void
end_badly ()
{
- FPRINTF (stderr, "%s", "Testcase failed (timeout).\n");
+ fprintf (stderr, "%s", "Testcase failed (timeout).\n");
end (NULL);
ok = 1;
}
* @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error
*/
static void
-print_query_result (void *cls,
- int is_valid)
+print_query_result (void *cls, int is_valid)
{
q = NULL;
switch (is_valid)
{
case GNUNET_YES:
- FPRINTF (stdout,
- _("Key `%s' is valid\n"),
- test_ego);
+ fprintf (stdout, _ ("Key `%s' is valid\n"), test_ego);
break;
case GNUNET_NO:
- FPRINTF (stdout,
- _("Key `%s' has been revoked\n"),
- test_ego);
+ fprintf (stdout, _ ("Key `%s' has been revoked\n"), test_ego);
break;
case GNUNET_SYSERR:
- FPRINTF (stdout,
- "%s",
- _("Internal error\n"));
+ fprintf (stdout, "%s", _ ("Internal error\n"));
break;
default:
GNUNET_break (0);
* @param is_valid #GNUNET_YES if the key is still valid, #GNUNET_NO if not, #GNUNET_SYSERR on error
*/
static void
-print_revocation_result (void *cls,
- int is_valid)
+print_revocation_result (void *cls, int is_valid)
{
h = NULL;
switch (is_valid)
{
case GNUNET_YES:
if (NULL != revoke_ego)
- FPRINTF (stdout,
- _("Key for ego `%s' is still valid, revocation failed (!)\n"),
+ fprintf (stdout,
+ _ ("Key for ego `%s' is still valid, revocation failed (!)\n"),
revoke_ego);
else
- FPRINTF (stdout,
- "%s",
- _("Revocation failed (!)\n"));
+ fprintf (stdout, "%s", _ ("Revocation failed (!)\n"));
break;
case GNUNET_NO:
if (NULL != revoke_ego)
- FPRINTF (stdout,
- _("Key for ego `%s' has been successfully revoked\n"),
+ fprintf (stdout,
+ _ ("Key for ego `%s' has been successfully revoked\n"),
revoke_ego);
else
- FPRINTF (stdout,
- "%s",
- _("Revocation successful.\n"));
+ fprintf (stdout, "%s", _ ("Revocation successful.\n"));
break;
case GNUNET_SYSERR:
- FPRINTF (stdout,
+ fprintf (stdout,
"%s",
- _("Internal error, key revocation might have failed\n"));
+ _ ("Internal error, key revocation might have failed\n"));
break;
default:
GNUNET_break (0);
static void
sync_rd (const struct RevocationData *rd)
{
- if ( (NULL != filename) &&
- (sizeof (struct RevocationData) ==
- GNUNET_DISK_fn_write (filename,
- &rd,
- sizeof (rd),
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "write",
- filename);
+ if ((NULL != filename) &&
+ (sizeof (struct RevocationData) ==
+ GNUNET_DISK_fn_write (filename,
+ &rd,
+ sizeof (rd),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
}
if (0 == (rd->pow % 128))
sync_rd (rd);
/* display progress estimate */
- if ( (0 == ((1 << matching_bits) / 100 / 50)) ||
- (0 == (rd->pow % ((1 << matching_bits) / 100 / 50))) )
- FPRINTF (stderr, "%s", ".");
- if ( (0 != rd->pow) &&
- ( (0 == ((1 << matching_bits) / 100)) ||
- (0 == (rd->pow % ((1 << matching_bits) / 100))) ) )
- FPRINTF (stderr, " - @ %3u%% (estimate)\n",
+ if ((0 == ((1 << matching_bits) / 100 / 50)) ||
+ (0 == (rd->pow % ((1 << matching_bits) / 100 / 50))))
+ fprintf (stderr, "%s", ".");
+ if ((0 != rd->pow) && ((0 == ((1 << matching_bits) / 100)) ||
+ (0 == (rd->pow % ((1 << matching_bits) / 100)))))
+ fprintf (stderr,
+ " - @ %3u%% (estimate)\n",
(unsigned int) (rd->pow * 100) / (1 << matching_bits));
/* actually do POW calculation */
rd->pow++;
- if (GNUNET_OK ==
- GNUNET_REVOCATION_check_pow (&rd->key,
- rd->pow,
- (unsigned int) matching_bits))
+ if (GNUNET_OK == GNUNET_REVOCATION_check_pow (&rd->key,
+ rd->pow,
+ (unsigned int) matching_bits))
{
- if ( (NULL != filename) &&
- (sizeof (struct RevocationData) !=
- GNUNET_DISK_fn_write (filename,
- rd,
- sizeof (struct RevocationData),
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "write",
- filename);
+ if ((NULL != filename) &&
+ (sizeof (struct RevocationData) !=
+ GNUNET_DISK_fn_write (filename,
+ rd,
+ sizeof (struct RevocationData),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
if (perform)
{
perform_revocation (rd);
}
else
{
- FPRINTF (stderr, "%s", "\n");
- FPRINTF (stderr,
- _("Revocation certificate for `%s' stored in `%s'\n"),
+ fprintf (stderr, "%s", "\n");
+ fprintf (stderr,
+ _ ("Revocation certificate for `%s' stored in `%s'\n"),
revoke_ego,
filename);
GNUNET_SCHEDULER_shutdown ();
}
return;
}
- pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow,
- rd);
+ pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd);
}
* @param ego the ego, NULL if not found
*/
static void
-ego_callback (void *cls,
- const struct GNUNET_IDENTITY_Ego *ego)
+ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
{
struct RevocationData *rd;
struct GNUNET_CRYPTO_EcdsaPublicKey key;
el = NULL;
if (NULL == ego)
{
- FPRINTF (stdout,
- _("Ego `%s' not found.\n"),
- revoke_ego);
+ fprintf (stdout, _ ("Ego `%s' not found.\n"), revoke_ego);
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_IDENTITY_ego_get_public_key (ego,
- &key);
+ GNUNET_IDENTITY_ego_get_public_key (ego, &key);
rd = GNUNET_new (struct RevocationData);
- if ( (NULL != filename) &&
- (GNUNET_YES ==
- GNUNET_DISK_file_test (filename)) &&
- (sizeof (struct RevocationData) ==
- GNUNET_DISK_fn_read (filename,
- rd,
- sizeof (struct RevocationData))) )
+ if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) &&
+ (sizeof (struct RevocationData) ==
+ GNUNET_DISK_fn_read (filename, rd, sizeof (struct RevocationData))))
{
- if (0 != GNUNET_memcmp (&rd->key,
- &key))
+ if (0 != GNUNET_memcmp (&rd->key, &key))
{
fprintf (stderr,
- _("Error: revocation certificate in `%s' is not for `%s'\n"),
+ _ ("Error: revocation certificate in `%s' is not for `%s'\n"),
filename,
revoke_ego);
GNUNET_free (rd);
}
else
{
- GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key (ego),
+ GNUNET_REVOCATION_sign_revocation (GNUNET_IDENTITY_ego_get_private_key (
+ ego),
&rd->sig);
rd->key = key;
}
if (GNUNET_YES ==
- GNUNET_REVOCATION_check_pow (&key,
- rd->pow,
- (unsigned int) matching_bits))
+ GNUNET_REVOCATION_check_pow (&key, rd->pow, (unsigned int) matching_bits))
{
- FPRINTF (stderr,
- "%s",
- _("Revocation certificate ready\n"));
+ fprintf (stderr, "%s", _ ("Revocation certificate ready\n"));
if (perform)
perform_revocation (rd);
else
GNUNET_free (rd);
return;
}
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
- _("Revocation certificate not ready, calculating proof of work\n"));
- pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow,
- rd);
- GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
- rd);
+ _ ("Revocation certificate not ready, calculating proof of work\n"));
+ pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, rd);
+ GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, rd);
}
{
if (GNUNET_OK !=
GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego,
- strlen (test_ego),
- &pk))
+ strlen (test_ego),
+ &pk))
{
- FPRINTF (stderr,
- _("Public key `%s' malformed\n"),
- test_ego);
+ fprintf (stderr, _ ("Public key `%s' malformed\n"), test_ego);
return;
}
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
- q = GNUNET_REVOCATION_query (cfg,
- &pk,
- &print_query_result,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
+ q = GNUNET_REVOCATION_query (cfg, &pk, &print_query_result, NULL);
if (NULL != revoke_ego)
- FPRINTF (stderr,
- "%s",
- _("Testing and revoking at the same time is not allowed, only executing test.\n"));
+ fprintf (
+ stderr,
+ "%s",
+ _ (
+ "Testing and revoking at the same time is not allowed, only executing test.\n"));
return;
}
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "REVOCATION",
- "WORKBITS",
- &matching_bits))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ "REVOCATION",
+ "WORKBITS",
+ &matching_bits))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"REVOCATION",
}
if (NULL != revoke_ego)
{
- if ( !perform && (NULL == filename) )
+ if (! perform && (NULL == filename))
{
- FPRINTF (stderr,
- "%s",
- _("No filename to store revocation certificate given.\n"));
- return;
+ fprintf (stderr,
+ "%s",
+ _ ("No filename to store revocation certificate given.\n"));
+ return;
}
/* main code here */
- el = GNUNET_IDENTITY_ego_lookup (cfg,
- revoke_ego,
- &ego_callback,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
+ el = GNUNET_IDENTITY_ego_lookup (cfg, revoke_ego, &ego_callback, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
return;
}
- if ( (NULL != filename) &&
- (perform) )
+ if ((NULL != filename) && (perform))
{
- if (sizeof (rd) !=
- GNUNET_DISK_fn_read (filename,
- &rd,
- sizeof (rd)))
+ if (sizeof (rd) != GNUNET_DISK_fn_read (filename, &rd, sizeof (rd)))
{
fprintf (stderr,
- _("Failed to read revocation certificate from `%s'\n"),
+ _ ("Failed to read revocation certificate from `%s'\n"),
filename);
return;
}
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (GNUNET_YES !=
GNUNET_REVOCATION_check_pow (&rd.key,
rd.pow,
struct RevocationData *cp = GNUNET_new (struct RevocationData);
*cp = rd;
- pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow,
- cp);
- GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
- cp);
+ pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, cp);
+ GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, cp);
return;
}
perform_revocation (&rd);
return;
}
- FPRINTF (stderr,
- "%s",
- _("No action specified. Nothing to do.\n"));
+ fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n"));
}
GNUNET_GETOPT_option_string ('f',
"filename",
"NAME",
- gettext_noop ("use NAME for the name of the revocation file"),
+ gettext_noop (
+ "use NAME for the name of the revocation file"),
&filename),
- GNUNET_GETOPT_option_string ('R',
- "revoke",
- "NAME",
- gettext_noop ("revoke the private key associated for the the private key associated with the ego NAME "),
- &revoke_ego),
-
- GNUNET_GETOPT_option_flag ('p',
- "perform",
- gettext_noop ("actually perform revocation, otherwise we just do the precomputation"),
- &perform),
+ GNUNET_GETOPT_option_string (
+ 'R',
+ "revoke",
+ "NAME",
+ gettext_noop (
+ "revoke the private key associated for the the private key associated with the ego NAME "),
+ &revoke_ego),
+
+ GNUNET_GETOPT_option_flag (
+ 'p',
+ "perform",
+ gettext_noop (
+ "actually perform revocation, otherwise we just do the precomputation"),
+ &perform),
GNUNET_GETOPT_option_string ('t',
"test",
"KEY",
- gettext_noop ("test if the public key KEY has been revoked"),
- &test_ego),
+ gettext_noop (
+ "test if the public key KEY has been revoked"),
+ &test_ego),
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-revocation",
- gettext_noop ("help text"), options, &run,
- NULL)) ? ret : 1;
- GNUNET_free ((void*) argv);
+ ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-revocation",
+ gettext_noop ("help text"),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
req_handle = NULL;
for (i = 0; i < n; i++)
{
- FPRINTF (stdout, "%s\n",
+ fprintf (stdout, "%s\n",
GNUNET_i2s_full (&recv_peers[i]));
}
ret = 0;
if (0 == n)
{
- FPRINTF (stdout, "Empty view\n");
+ fprintf (stdout, "Empty view\n");
}
req_handle = NULL;
for (i = 0; i < n; i++)
{
- FPRINTF (stdout, "%s\n",
+ fprintf (stdout, "%s\n",
GNUNET_i2s_full (&recv_peers[i]));
}
if (0 == num_peers)
{
- FPRINTF (stdout, "No peer was returned\n");
+ fprintf (stdout, "No peer was returned\n");
}
req_handle = NULL;
for (i = 0; i < num_peers; i++)
{
- FPRINTF (stdout, "%s\n",
+ fprintf (stdout, "%s\n",
GNUNET_i2s_full (&recv_peers[i]));
}
}
rps_handle = GNUNET_RPS_connect (cfg);
if (NULL == rps_handle)
{
- FPRINTF (stderr, "Failed to connect to the rps service\n");
+ fprintf (stderr, "Failed to connect to the rps service\n");
return;
}
else
{ /* Seed PeerID */
GNUNET_RPS_seed_ids (rps_handle, 1, &peer_id);
- FPRINTF (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (&peer_id));
+ fprintf (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (&peer_id));
ret = 0;
GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
* #GNUNET_NO : last_value is n/a, #GNUNET_YES: last_value is valid
*/
int last_value_set;
-
};
* #GNUNET_NO: value is n/a, #GNUNET_YES: value is valid
*/
int set;
-
};
* the end of this struct, do not free().
*/
const char *service;
-
};
* Maximum watch ID used by this client so far.
*/
uint32_t max_wid;
-
};
size_t slen;
struct GNUNET_STATISTICS_SetMessage *msg;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "STATISTICS",
- "DATABASE",
- &fn))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "STATISTICS",
+ "DATABASE",
+ &fn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"STATISTICS",
total = 0;
while (NULL != (se = sub_head))
{
- GNUNET_CONTAINER_DLL_remove (sub_head,
- sub_tail,
- se);
+ GNUNET_CONTAINER_DLL_remove (sub_head, sub_tail, se);
slen = strlen (se->service) + 1;
while (NULL != (pos = se->stat_head))
{
- GNUNET_CONTAINER_DLL_remove (se->stat_head,
- se->stat_tail,
- pos);
- if ( (pos->persistent) &&
- (NULL != wh) )
+ GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos);
+ if ((pos->persistent) && (NULL != wh))
{
nlen = strlen (pos->name) + 1;
size = sizeof (struct GNUNET_STATISTICS_SetMessage) + nlen + slen;
2,
se->service,
pos->name));
- msg->flags = htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
+ msg->flags =
+ htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
msg->value = GNUNET_htonll (pos->value);
- if (GNUNET_OK != GNUNET_BIO_write (wh,
- msg,
- size))
+ if (GNUNET_OK != GNUNET_BIO_write (wh, msg, size))
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "write",
- fn);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
if (GNUNET_OK != GNUNET_BIO_write_close (wh))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "close",
- fn);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
wh = NULL;
}
else
}
if (NULL != wh)
{
- if (GNUNET_OK !=
- GNUNET_BIO_write_close (wh))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "close",
- fn);
+ if (GNUNET_OK != GNUNET_BIO_write_close (wh))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
if (0 == total)
- GNUNET_break (0 ==
- UNLINK (fn));
+ GNUNET_break (0 == unlink (fn));
else
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Wrote %llu bytes of statistics to `%s'\n"),
+ _ ("Wrote %llu bytes of statistics to `%s'\n"),
total,
fn);
}
* @param e value to transmit
*/
static void
-transmit (struct ClientEntry *ce,
- const struct StatsEntry *e)
+transmit (struct ClientEntry *ce, const struct StatsEntry *e)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_STATISTICS_ReplyMessage *m;
size_t size;
- size = strlen (e->subsystem->service) + 1 +
- strlen (e->name) + 1;
+ size = strlen (e->subsystem->service) + 1 + strlen (e->name) + 1;
GNUNET_assert (size < GNUNET_MAX_MESSAGE_SIZE);
- env = GNUNET_MQ_msg_extra (m,
- size,
- GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
+ env = GNUNET_MQ_msg_extra (m, size, GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
m->uid = htonl (e->uid);
if (e->persistent)
m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT);
m->value = GNUNET_htonll (e->value);
- GNUNET_assert (size ==
- GNUNET_STRINGS_buffer_fill ((char *) &m[1],
- size,
- 2,
- e->subsystem->service,
- e->name));
+ GNUNET_assert (size == GNUNET_STRINGS_buffer_fill ((char *) &m[1],
+ size,
+ 2,
+ e->subsystem->service,
+ e->name));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting value for `%s:%s' (%d): %llu\n",
e->subsystem->service,
e->name,
e->persistent,
(unsigned long long) e->value);
- GNUNET_MQ_send (ce->mq,
- env);
+ GNUNET_MQ_send (ce->mq, env);
}
*/
static void *
client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *c,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_SERVICE_Client *c,
+ struct GNUNET_MQ_Handle *mq)
{
struct ClientEntry *ce;
ce->client = c;
ce->mq = mq;
client_count++;
- GNUNET_notification_context_add (nc,
- mq);
+ GNUNET_notification_context_add (nc, mq);
return ce;
}
* @return #GNUNET_OK if @a message is well-formed
*/
static int
-check_get (void *cls,
- const struct GNUNET_MessageHeader *message)
+check_get (void *cls, const struct GNUNET_MessageHeader *message)
{
const char *service;
const char *name;
size_t size;
size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
- if (size !=
- GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
- size,
- 2,
- &service,
- &name))
+ if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
+ size,
+ 2,
+ &service,
+ &name))
{
GNUNET_break (0);
return GNUNET_SYSERR;
* @param message the actual message
*/
static void
-handle_get (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_get (void *cls, const struct GNUNET_MessageHeader *message)
{
struct ClientEntry *ce = cls;
struct GNUNET_MQ_Envelope *env;
size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
GNUNET_assert (size ==
- GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
- size,
- 2,
- &service,
- &name));
+ GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
+ size,
+ 2,
+ &service,
+ &name));
slen = strlen (service);
nlen = strlen (name);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
nlen ? name : "*");
for (se = sub_head; NULL != se; se = se->next)
{
- if (! ( (0 == slen) ||
- (0 == strcmp (service, se->service))) )
+ if (! ((0 == slen) || (0 == strcmp (service, se->service))))
continue;
for (pos = se->stat_head; NULL != pos; pos = pos->next)
{
- if (! ( (0 == nlen) ||
- (0 == strcmp (name,
- pos->name))) )
+ if (! ((0 == nlen) || (0 == strcmp (name, pos->name))))
continue;
- transmit (ce,
- pos);
+ transmit (ce, pos);
}
}
- env = GNUNET_MQ_msg (end,
- GNUNET_MESSAGE_TYPE_STATISTICS_END);
- GNUNET_MQ_send (ce->mq,
- env);
+ env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_STATISTICS_END);
+ GNUNET_MQ_send (ce->mq, env);
GNUNET_SERVICE_client_continue (ce->client);
}
{
pos->last_value_set = GNUNET_YES;
}
- env = GNUNET_MQ_msg (wvm,
- GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE);
- wvm->flags = htonl (se->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
+ env = GNUNET_MQ_msg (wvm, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE);
+ wvm->flags =
+ htonl (se->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
wvm->wid = htonl (pos->wid);
wvm->reserved = htonl (0);
wvm->value = GNUNET_htonll (se->value);
- GNUNET_MQ_send (pos->ce->mq,
- env);
+ GNUNET_MQ_send (pos->ce->mq, env);
pos->last_value = se->value;
}
}
* @return subsystem entry, never NULL (subsystem entry is created if necessary)
*/
static struct SubsystemEntry *
-find_subsystem_entry (struct ClientEntry *ce,
- const char *service)
+find_subsystem_entry (struct ClientEntry *ce, const char *service)
{
size_t slen;
struct SubsystemEntry *se;
se = ce->subsystem;
else
se = NULL;
- if ( (NULL == se) ||
- (0 != strcmp (service,
- se->service)) )
+ if ((NULL == se) || (0 != strcmp (service, se->service)))
{
for (se = sub_head; NULL != se; se = se->next)
- if (0 == strcmp (service,
- se->service))
+ if (0 == strcmp (service, se->service))
break;
if (NULL != ce)
ce->subsystem = se;
"Allocating new subsystem entry `%s'\n",
service);
slen = strlen (service) + 1;
- se = GNUNET_malloc (sizeof (struct SubsystemEntry) +
- slen);
- GNUNET_memcpy (&se[1],
- service,
- slen);
+ se = GNUNET_malloc (sizeof (struct SubsystemEntry) + slen);
+ GNUNET_memcpy (&se[1], service, slen);
se->service = (const char *) &se[1];
- GNUNET_CONTAINER_DLL_insert (sub_head,
- sub_tail,
- se);
+ GNUNET_CONTAINER_DLL_insert (sub_head, sub_tail, se);
if (NULL != ce)
ce->subsystem = se;
return se;
* @return statistis entry, or NULL if not found
*/
static struct StatsEntry *
-find_stat_entry (struct SubsystemEntry *se,
- const char *name)
+find_stat_entry (struct SubsystemEntry *se, const char *name)
{
struct StatsEntry *pos;
for (pos = se->stat_head; NULL != pos; pos = pos->next)
- if (0 == strcmp (name, pos->name))
+ if (0 == strcmp (name, pos->name))
return pos;
return NULL;
}
* @return #GNUNET_OK if message is well-formed
*/
static int
-check_set (void *cls,
- const struct GNUNET_STATISTICS_SetMessage *msg)
+check_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
{
const char *service;
const char *name;
size_t msize;
msize = ntohs (msg->header.size) - sizeof (*msg);
- if (msize !=
- GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1],
- msize,
- 2,
- &service,
- &name))
+ if (msize != GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1],
+ msize,
+ 2,
+ &service,
+ &name))
{
GNUNET_break (0);
return GNUNET_SYSERR;
* @param message the actual message
*/
static void
-handle_set (void *cls,
- const struct GNUNET_STATISTICS_SetMessage *msg)
+handle_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
{
struct ClientEntry *ce = cls;
const char *service;
msize = ntohs (msg->header.size);
size = msize - sizeof (struct GNUNET_STATISTICS_SetMessage);
- GNUNET_assert (size ==
- GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1],
- size,
- 2,
- &service,
- &name));
- se = find_subsystem_entry (ce,
- service);
+ GNUNET_assert (size == GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1],
+ size,
+ 2,
+ &service,
+ &name));
+ se = find_subsystem_entry (ce, service);
flags = ntohl (msg->flags);
value = GNUNET_ntohll (msg->value);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
name,
(unsigned int) flags,
(unsigned long long) value);
- pos = find_stat_entry (se,
- name);
+ pos = find_stat_entry (se, name);
if (NULL != pos)
{
initial_set = 0;
else
{
changed = (0 != delta);
- GNUNET_break ( (delta <= 0) ||
- (pos->value + delta > pos->value) );
+ GNUNET_break ((delta <= 0) || (pos->value + delta > pos->value));
pos->value += delta;
}
}
if (pos != se->stat_head)
{
/* move to front for faster setting next time! */
- GNUNET_CONTAINER_DLL_remove (se->stat_head,
- se->stat_tail,
- pos);
- GNUNET_CONTAINER_DLL_insert (se->stat_head,
- se->stat_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos);
+ GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Statistic `%s:%s' updated to value %llu (%d).\n",
name,
(unsigned long long) pos->value,
pos->persistent);
- if ( (changed) ||
- (1 == initial_set) )
+ if ((changed) || (1 == initial_set))
notify_change (pos);
GNUNET_SERVICE_client_continue (ce->client);
return;
/* not found, create a new entry */
nlen = strlen (name) + 1;
pos = GNUNET_malloc (sizeof (struct StatsEntry) + nlen);
- GNUNET_memcpy (&pos[1],
- name,
- nlen);
+ GNUNET_memcpy (&pos[1], name, nlen);
pos->name = (const char *) &pos[1];
pos->subsystem = se;
- if ( (0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) ||
- (0 < (int64_t) GNUNET_ntohll (msg->value)) )
+ if ((0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) ||
+ (0 < (int64_t) GNUNET_ntohll (msg->value)))
{
pos->value = GNUNET_ntohll (msg->value);
pos->set = GNUNET_YES;
}
pos->uid = uidgen++;
pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT));
- GNUNET_CONTAINER_DLL_insert (se->stat_head,
- se->stat_tail,
- pos);
+ GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New statistic on `%s:%s' with value %llu created.\n",
service,
* @return #GNUNET_OK if message is well-formed
*/
static int
-check_watch (void *cls,
- const struct GNUNET_MessageHeader *message)
+check_watch (void *cls, const struct GNUNET_MessageHeader *message)
{
size_t size;
const char *service;
const char *name;
size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
- if (size !=
- GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
- size,
- 2,
- &service,
- &name))
+ if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
+ size,
+ 2,
+ &service,
+ &name))
{
GNUNET_break (0);
return GNUNET_SYSERR;
* @param message the actual message
*/
static void
-handle_watch (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_watch (void *cls, const struct GNUNET_MessageHeader *message)
{
struct ClientEntry *ce = cls;
const char *service;
msize = ntohs (message->size);
size = msize - sizeof (struct GNUNET_MessageHeader);
GNUNET_assert (size ==
- GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
- size,
- 2,
- &service,
- &name));
+ GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
+ size,
+ 2,
+ &service,
+ &name));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received request to watch statistic on `%s:%s'\n",
service,
name);
- se = find_subsystem_entry (ce,
- service);
- pos = find_stat_entry (se,
- name);
+ se = find_subsystem_entry (ce, service);
+ pos = find_stat_entry (se, name);
if (NULL == pos)
{
nlen = strlen (name) + 1;
- pos = GNUNET_malloc (sizeof (struct StatsEntry) +
- nlen);
- GNUNET_memcpy (&pos[1],
- name,
- nlen);
+ pos = GNUNET_malloc (sizeof (struct StatsEntry) + nlen);
+ GNUNET_memcpy (&pos[1], name, nlen);
pos->name = (const char *) &pos[1];
pos->subsystem = se;
- GNUNET_CONTAINER_DLL_insert (se->stat_head,
- se->stat_tail,
- pos);
+ GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos);
pos->uid = uidgen++;
pos->set = GNUNET_NO;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
we->ce = ce;
we->last_value_set = GNUNET_NO;
we->wid = ce->max_wid++;
- GNUNET_CONTAINER_DLL_insert (pos->we_head,
- pos->we_tail,
- we);
+ GNUNET_CONTAINER_DLL_insert (pos->we_head, pos->we_tail, we);
if (0 != pos->value)
notify_change (pos);
GNUNET_SERVICE_client_continue (ce->client);
* @param message the actual message
*/
static void
-handle_disconnect (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_disconnect (void *cls, const struct GNUNET_MessageHeader *message)
{
struct ClientEntry *ce = cls;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM);
- GNUNET_MQ_send (ce->mq,
- env);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM);
+ GNUNET_MQ_send (ce->mq, env);
GNUNET_SERVICE_client_continue (ce->client);
}
GNUNET_assert (0 == client_count);
while (NULL != (se = sub_head))
{
- GNUNET_CONTAINER_DLL_remove (sub_head,
- sub_tail,
- se);
+ GNUNET_CONTAINER_DLL_remove (sub_head, sub_tail, se);
while (NULL != (pos = se->stat_head))
{
- GNUNET_CONTAINER_DLL_remove (se->stat_head,
- se->stat_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos);
while (NULL != (we = pos->we_head))
{
GNUNET_break (0);
- GNUNET_CONTAINER_DLL_remove (pos->we_head,
- pos->we_tail,
- we);
+ GNUNET_CONTAINER_DLL_remove (pos->we_head, pos->we_tail, we);
GNUNET_free (we);
}
GNUNET_free (pos);
*/
static void
client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *app_cls)
+ struct GNUNET_SERVICE_Client *client,
+ void *app_cls)
{
struct ClientEntry *ce = app_cls;
struct WatchEntry *we;
wen = we->next;
if (we->ce != ce)
continue;
- GNUNET_CONTAINER_DLL_remove (pos->we_head,
- pos->we_tail,
- we);
+ GNUNET_CONTAINER_DLL_remove (pos->we_head, pos->we_tail, we);
GNUNET_free (we);
}
}
}
GNUNET_free (ce);
- if ( (0 == client_count) &&
- (GNUNET_YES == in_shutdown) )
+ if ((0 == client_count) && (GNUNET_YES == in_shutdown))
do_shutdown ();
}
* #GNUNET_SYSERR to stop further processing with error
*/
static int
-inject_message (void *cls,
- const struct GNUNET_MessageHeader *message)
+inject_message (void *cls, const struct GNUNET_MessageHeader *message)
{
uint16_t msize = ntohs (message->size);
const struct GNUNET_STATISTICS_SetMessage *sm;
sm = (const struct GNUNET_STATISTICS_SetMessage *) message;
- if ( (sizeof (struct GNUNET_STATISTICS_SetMessage) > msize) ||
- (GNUNET_OK !=
- check_set (NULL,
- sm)) )
+ if ((sizeof (struct GNUNET_STATISTICS_SetMessage) > msize) ||
+ (GNUNET_OK != check_set (NULL, sm)))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
- handle_set (NULL,
- sm);
+ handle_set (NULL, sm);
return GNUNET_OK;
}
char *buf;
struct GNUNET_MessageStreamTokenizer *mst;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "STATISTICS",
- "DATABASE",
- &fn))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "STATISTICS",
+ "DATABASE",
+ &fn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"STATISTICS",
"DATABASE");
return;
}
- if ( (GNUNET_OK !=
- GNUNET_DISK_file_size (fn,
- &fsize,
- GNUNET_NO,
- GNUNET_YES)) ||
- (0 == fsize) )
+ if ((GNUNET_OK !=
+ GNUNET_DISK_file_size (fn, &fsize, GNUNET_NO, GNUNET_YES)) ||
+ (0 == fsize))
{
GNUNET_free (fn);
return;
GNUNET_free (fn);
return;
}
- if (GNUNET_OK !=
- GNUNET_BIO_read (rh,
- fn,
- buf,
- fsize))
+ if (GNUNET_OK != GNUNET_BIO_read (rh, fn, buf, fsize))
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "read",
- fn);
- GNUNET_break (GNUNET_OK ==
- GNUNET_BIO_read_close (rh,
- NULL));
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", fn);
+ GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
GNUNET_free (buf);
GNUNET_free (fn);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading %llu bytes of statistics from `%s'\n"),
+ _ ("Loading %llu bytes of statistics from `%s'\n"),
(unsigned long long) fsize,
- fn);
- mst = GNUNET_MST_create (&inject_message,
- NULL);
- GNUNET_break (GNUNET_OK ==
- GNUNET_MST_from_buffer (mst,
- buf,
- (size_t) fsize,
- GNUNET_YES,
- GNUNET_NO));
+ fn);
+ mst = GNUNET_MST_create (&inject_message, NULL);
+ GNUNET_break (
+ GNUNET_OK ==
+ GNUNET_MST_from_buffer (mst, buf, (size_t) fsize, GNUNET_YES, GNUNET_NO));
GNUNET_MST_destroy (mst);
GNUNET_free (buf);
- GNUNET_break (GNUNET_OK ==
- GNUNET_BIO_read_close (rh,
- NULL));
+ GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
GNUNET_free (fn);
}
cfg = c;
nc = GNUNET_notification_context_create (16);
load ();
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("statistics",
- GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_var_size (set,
- GNUNET_MESSAGE_TYPE_STATISTICS_SET,
- struct GNUNET_STATISTICS_SetMessage,
- NULL),
- GNUNET_MQ_hd_var_size (get,
- GNUNET_MESSAGE_TYPE_STATISTICS_GET,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_hd_var_size (watch,
- GNUNET_MESSAGE_TYPE_STATISTICS_WATCH,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_hd_fixed_size (disconnect,
- GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN (
+ "statistics",
+ GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_var_size (set,
+ GNUNET_MESSAGE_TYPE_STATISTICS_SET,
+ struct GNUNET_STATISTICS_SetMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (get,
+ GNUNET_MESSAGE_TYPE_STATISTICS_GET,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_var_size (watch,
+ GNUNET_MESSAGE_TYPE_STATISTICS_WATCH,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (disconnect,
+ GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ());
#if defined(LINUX) && defined(__GLIBC__)
/**
* MINIMIZE heap size (way below 128k) since this process doesn't need much.
*/
-void __attribute__ ((constructor))
-GNUNET_STATISTICS_memory_init ()
+void __attribute__ ((constructor)) GNUNET_STATISTICS_memory_init ()
{
mallopt (M_TRIM_THRESHOLD, 4 * 1024);
mallopt (M_TOP_PAD, 1 * 1024);
if (GNUNET_YES == watch)
{
now_str = GNUNET_STRINGS_absolute_time_to_string (now);
- FPRINTF (stdout,
+ fprintf (stdout,
"%24s%s %s%s%12s%s %s%50s%s%s ",
now_str,
csv_separator,
}
else
{
- FPRINTF (stdout,
+ fprintf (stdout,
"%s%s%12s%s %s%50s%s%s ",
value_set->is_persistent ? "!" : " ",
csv_separator,
}
for (unsigned i = 0; i < num_nodes; i++)
{
- FPRINTF (stdout,
+ fprintf (stdout,
"%16llu%s",
(unsigned long long) value_set->values[i],
csv_separator);
}
- FPRINTF (stdout, "\n");
+ fprintf (stdout, "\n");
GNUNET_free (value_set->subsystem);
GNUNET_free (value_set->name);
GNUNET_free (value_set->values);
if (GNUNET_YES == watch)
{
now_str = GNUNET_STRINGS_absolute_time_to_string (now);
- FPRINTF (stdout,
+ fprintf (stdout,
"%24s%s %s%s%12s%s %s%50s%s%s %16llu\n",
now_str,
csv_separator,
}
else
{
- FPRINTF (stdout,
+ fprintf (stdout,
"%s%s%12s%s %s%50s%s%s %16llu\n",
is_persistent ? "!" : " ",
csv_separator,
}
}
else
- FPRINTF (stdout, "%llu\n", (unsigned long long) value);
+ fprintf (stdout, "%llu\n", (unsigned long long) value);
return GNUNET_OK;
}
if (GNUNET_OK != success)
{
if (NULL == remote_host)
- FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n"));
+ fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n"));
else
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Failed to obtain statistics from host `%s:%llu'\n"),
remote_host,
remote_port);
if (GNUNET_OK != success)
{
if (NULL == remote_host)
- FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n"));
+ fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n"));
else
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Failed to obtain statistics from host `%s:%llu'\n"),
remote_host,
remote_port);
len_subsys_name = strlen (subsystem) + 3 + strlen (name) + 1;
subsys_name = GNUNET_malloc (len_subsys_name);
- SPRINTF (subsys_name, "%s---%s", subsystem, name);
+ sprintf (subsys_name, "%s---%s", subsystem, name);
key = &hc;
GNUNET_CRYPTO_hash (subsys_name, len_subsys_name, key);
GNUNET_free (subsys_name);
{
if (NULL == subsystem)
{
- FPRINTF (stderr, "%s", _ ("Missing argument: subsystem \n"));
+ fprintf (stderr, "%s", _ ("Missing argument: subsystem \n"));
ret = 1;
return;
}
if (NULL == name)
{
- FPRINTF (stderr, "%s", _ ("Missing argument: name\n"));
+ fprintf (stderr, "%s", _ ("Missing argument: name\n"));
ret = 1;
return;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_load (nodes[num_nodes - 1].conf, filename))
{
- FPRINTF (stderr, "Failed loading config `%s'\n", filename);
+ fprintf (stderr, "Failed loading config `%s'\n", filename);
return GNUNET_SYSERR;
}
return GNUNET_NO;
unsigned index_node;
GNUNET_assert (NULL != filename);
- if (1 == SSCANF (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node))
+ if (1 == sscanf (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node))
{
if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL))
{
GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL);
if (-1 == num_dir_entries)
{
- FPRINTF (stderr, "Failure during scanning directory `%s'\n", path_testbed);
+ fprintf (stderr, "Failure during scanning directory `%s'\n", path_testbed);
return -1;
}
return 0;
csv_separator = "";
if (NULL != args[0])
{
- if (1 != SSCANF (args[0], "%llu", &set_val))
+ if (1 != sscanf (args[0], "%llu", &set_val))
{
- FPRINTF (stderr, _ ("Invalid argument `%s'\n"), args[0]);
+ fprintf (stderr, _ ("Invalid argument `%s'\n"), args[0]);
ret = 1;
return;
}
"PORT",
&remote_port))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("A port is required to connect to host `%s'\n"),
remote_host);
return;
}
else if (65535 <= remote_port)
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ (
"A port has to be between 1 and 65535 to connect to host `%s'\n"),
remote_host);
#include "testbed_api_topology.h"
#include "sqlite3.h"
-#define LOG(type, ...) \
- GNUNET_log (type, __VA_ARGS__)
+#define LOG(type, ...) GNUNET_log (type, __VA_ARGS__)
-#define LOG_ERROR(...) \
- LOG (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
+#define LOG_ERROR(...) LOG (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
/**
* Log an error message at log-level 'level' that indicates
* a failure of the command 'cmd' on file 'filename'
* with the message given by strerror(errno).
*/
-#define LOG_SQLITE(db, msg, level, cmd) \
- do { \
- GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \
- cmd, __FILE__,__LINE__, sqlite3_errmsg(db)); \
- if (msg != NULL) \
- GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, \
- __FILE__, __LINE__, sqlite3_errmsg(db)); \
- } while(0)
+#define LOG_SQLITE(db, msg, level, cmd) \
+ do \
+ { \
+ GNUNET_log_from (level, \
+ "sqlite", \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ sqlite3_errmsg (db)); \
+ if (msg != NULL) \
+ GNUNET_asprintf (msg, \
+ _ ("`%s' failed at %s:%u with error: %s"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ sqlite3_errmsg (db)); \
+ } while (0)
/**
unsigned int latency,
unsigned int loss)
{
- if ( (SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, A)) ||
- (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, B)) ||
- (SQLITE_OK != sqlite3_bind_int (stmt_insert, 3, bandwidth)) ||
- (SQLITE_OK != sqlite3_bind_int (stmt_insert, 4, latency)) ||
- (SQLITE_OK != sqlite3_bind_int (stmt_insert, 5, loss)) )
+ if ((SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, A)) ||
+ (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, B)) ||
+ (SQLITE_OK != sqlite3_bind_int (stmt_insert, 3, bandwidth)) ||
+ (SQLITE_OK != sqlite3_bind_int (stmt_insert, 4, latency)) ||
+ (SQLITE_OK != sqlite3_bind_int (stmt_insert, 5, loss)))
{
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int");
return GNUNET_SYSERR;
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step");
return GNUNET_SYSERR;
}
- FPRINTF (stdout, "%u -> %u\n", A, B);
+ fprintf (stdout, "%u -> %u\n", A, B);
GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert));
//GNUNET_break (SQLITE_OK == sqlite3_clear_bindings (stmt_insert));
- if ( (SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, B)) ||
- (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, A)) )
+ if ((SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, B)) ||
+ (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, A)))
{
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int");
return GNUNET_SYSERR;
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step");
return GNUNET_SYSERR;
}
- FPRINTF (stdout, "%u -> %u\n", B, A);
+ fprintf (stdout, "%u -> %u\n", B, A);
GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert));
return GNUNET_OK;
}
static int
setup_db (const char *dbfile)
{
- const char *query_create =
- "CREATE TABLE whitelist ("
- "id INTEGER,"
- "oid INTEGER,"
- "bandwidth INTEGER DEFAULT NULL,"
- "latency INTEGER DEFAULT NULL,"
- "loss INTEGER DEFAULT NULL,"
- " UNIQUE ("
- " id,"
- " oid"
- " ) ON CONFLICT IGNORE"
- ");";
- const char *query_insert =
- "INSERT INTO whitelist("
- " id,"
- " oid,"
- " bandwidth,"
- " latency,"
- " loss"
- ") VALUES ("
- " ?1,"
- " ?2,"
- " ?3,"
- " ?4,"
- " ?5);";
+ const char *query_create = "CREATE TABLE whitelist ("
+ "id INTEGER,"
+ "oid INTEGER,"
+ "bandwidth INTEGER DEFAULT NULL,"
+ "latency INTEGER DEFAULT NULL,"
+ "loss INTEGER DEFAULT NULL,"
+ " UNIQUE ("
+ " id,"
+ " oid"
+ " ) ON CONFLICT IGNORE"
+ ");";
+ const char *query_insert = "INSERT INTO whitelist("
+ " id,"
+ " oid,"
+ " bandwidth,"
+ " latency,"
+ " loss"
+ ") VALUES ("
+ " ?1,"
+ " ?2,"
+ " ?3,"
+ " ?4,"
+ " ?5);";
int ret;
ret = GNUNET_SYSERR;
if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL))
{
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
- FPRINTF (stderr, "Error: %d. Perhaps the database `%s' already exits.\n",
+ fprintf (stderr,
+ "Error: %d. Perhaps the database `%s' already exits.\n",
sqlite3_errcode (db),
dbfile);
goto err_ret;
}
- GNUNET_break (0 == sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL));
- if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1,
- &stmt_insert, NULL))
+ GNUNET_break (0 ==
+ sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL));
+ if (SQLITE_OK !=
+ sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert, NULL))
{
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2");
goto err_ret;
}
ret = GNUNET_OK;
- err_ret:
+err_ret:
return ret;
}
* @param cfg the configuration file handle
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
const char *dbfile;
arg_uint2 = 0; /* make compilers happy */
if (NULL == args)
{
- LOG_ERROR (_("Need at least 2 arguments\n"));
+ LOG_ERROR (_ ("Need at least 2 arguments\n"));
return;
}
if (NULL == (dbfile = args[argc++]))
{
- LOG_ERROR (_("Database filename missing\n"));
+ LOG_ERROR (_ ("Database filename missing\n"));
return;
}
if (GNUNET_OK != setup_db (dbfile))
return;
if (NULL == (topology_string = args[argc++]))
{
- LOG_ERROR (_("Topology string missing\n"));
+ LOG_ERROR (_ ("Topology string missing\n"));
return;
}
if (GNUNET_YES != GNUNET_TESTBED_topology_get_ (&topology, topology_string))
{
- LOG_ERROR (_("Invalid topology: %s\n"), topology_string);
+ LOG_ERROR (_ ("Invalid topology: %s\n"), topology_string);
return;
}
arg_str1 = NULL;
case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
if (NULL == (value = args[argc++]))
{
- LOG_ERROR (_("An argument is missing for given topology `%s'\n"),
+ LOG_ERROR (_ ("An argument is missing for given topology `%s'\n"),
topology_string);
return;
}
- if (-1 == SSCANF (value, "%u", &arg_uint1))
+ if (-1 == sscanf (value, "%u", &arg_uint1))
{
- LOG_ERROR (_("Invalid argument `%s' given as topology argument\n"),
+ LOG_ERROR (_ ("Invalid argument `%s' given as topology argument\n"),
value);
return;
}
case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
if (NULL == (arg_str1 = args[argc++]))
{
- LOG_ERROR (_("Filename argument missing for topology `%s'\n"),
+ LOG_ERROR (_ ("Filename argument missing for topology `%s'\n"),
topology_string);
return;
}
case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
if (NULL == (value = args[argc++]))
{
- LOG_ERROR (_("Second argument for topology `%s' is missing\n"),
+ LOG_ERROR (_ ("Second argument for topology `%s' is missing\n"),
topology_string);
return;
}
- if (-1 == SSCANF (value, "%u", &arg_uint2))
+ if (-1 == sscanf (value, "%u", &arg_uint2))
{
- LOG_ERROR (_("Invalid argument `%s'; expecting unsigned int\n"), value);
+ LOG_ERROR (_ ("Invalid argument `%s'; expecting unsigned int\n"), value);
return;
}
break;
case GNUNET_TESTBED_TOPOLOGY_STAR:
case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
- GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL,
+ GNUNET_TESTBED_underlay_construct_ (num_peers,
+ link_processor,
+ NULL,
topology);
break;
case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
- GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL,
+ GNUNET_TESTBED_underlay_construct_ (num_peers,
+ link_processor,
+ NULL,
topology,
arg_uint1);
break;
case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
- GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL,
+ GNUNET_TESTBED_underlay_construct_ (num_peers,
+ link_processor,
+ NULL,
topology,
arg_str1);
break;
case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
- GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL,
+ GNUNET_TESTBED_underlay_construct_ (num_peers,
+ link_processor,
+ NULL,
topology,
arg_uint1,
arg_uint2);
struct GNUNET_GETOPT_CommandLineOption option[] = {
GNUNET_GETOPT_option_uint ('p',
- "num-peers",
- "COUNT",
- gettext_noop ("create COUNT number of peers"),
- &num_peers),
- GNUNET_GETOPT_OPTION_END
- };
+ "num-peers",
+ "COUNT",
+ gettext_noop ("create COUNT number of peers"),
+ &num_peers),
+ GNUNET_GETOPT_OPTION_END};
int ret;
exit_result = GNUNET_SYSERR;
- ret =
- GNUNET_PROGRAM_run (argc, argv, "gnunet-underlay-topology",
- _("Generates SQLite3 database representing a given underlay topology.\n"
- "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n"
- "The following options are available for TOPO followed by TOPOOPTS if applicable:\n"
- "\t LINE\n"
- "\t RING\n"
- "\t RANDOM <num_rnd_links>\n"
- "\t SMALL_WORLD <num_rnd_links>\n"
- "\t SMALL_WORLD_RING <num_rnd_links>\n"
- "\t CLIQUE\n"
- "\t 2D_TORUS\n"
- "\t SCALE_FREE <cap> <m>\n"
- "\t FROM_FILE <filename>\n"
- "TOPOOPTS:\n"
- "\t num_rnd_links: The number of random links\n"
- "\t cap: the maximum number of links a node can have\n"
- "\t m: the number of links a node should have while joining the network\n"
- "\t filename: the path of the file which contains topology information\n"
- "NOTE: the format of the above file is descibed here: https://www.gnunet.org/content/topology-file-format\n"),
- option, &run, NULL);
+ ret = GNUNET_PROGRAM_run (
+ argc,
+ argv,
+ "gnunet-underlay-topology",
+ _ (
+ "Generates SQLite3 database representing a given underlay topology.\n"
+ "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n"
+ "The following options are available for TOPO followed by TOPOOPTS if applicable:\n"
+ "\t LINE\n"
+ "\t RING\n"
+ "\t RANDOM <num_rnd_links>\n"
+ "\t SMALL_WORLD <num_rnd_links>\n"
+ "\t SMALL_WORLD_RING <num_rnd_links>\n"
+ "\t CLIQUE\n"
+ "\t 2D_TORUS\n"
+ "\t SCALE_FREE <cap> <m>\n"
+ "\t FROM_FILE <filename>\n"
+ "TOPOOPTS:\n"
+ "\t num_rnd_links: The number of random links\n"
+ "\t cap: the maximum number of links a node can have\n"
+ "\t m: the number of links a node should have while joining the network\n"
+ "\t filename: the path of the file which contains topology information\n"
+ "NOTE: the format of the above file is descibed here: https://www.gnunet.org/content/topology-file-format\n"),
+ option,
+ &run,
+ NULL);
if (NULL != stmt_insert)
sqlite3_finalize (stmt_insert);
if (NULL != db)
GNUNET_OS_process_destroy (testbed);
testbed = NULL;
/* Send SIGTERM to our process group */
- if (0 != PLIBC_KILL (0, GNUNET_TERM_SIG))
+ if (0 != kill (0, GNUNET_TERM_SIG))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal");
GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */
hc_handle = NULL;
if (GNUNET_NO == status)
{
- (void) PRINTF ("%s",
+ (void) printf ("%s",
"Unable to run the test as this system is not configured "
"to use password less SSH logins to localhost.\n"
"Skipping test\n");
{
GNUNET_TESTBED_host_destroy (host);
host = NULL;
- (void) PRINTF ("%s",
+ (void) printf ("%s",
"Unable to run the test as this system is not configured "
"to use password less SSH logins to localhost.\n"
"Skipping test\n");
/**
* Generic logging shortcut
*/
-#define LOG(kind,...) \
- GNUNET_log (kind, __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
/**
* Debug logging shorthand
*/
-#define LOG_DEBUG(...) \
- LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
/**
* Different stages in testing
/**
* shortcut to exit during failure
*/
-#define FAIL_TEST(cond) do { \
- if (!(cond)) { \
- GNUNET_break(0); \
- if (NULL != abort_task) \
- GNUNET_SCHEDULER_cancel (abort_task); \
- abort_task = NULL; \
- GNUNET_SCHEDULER_shutdown (); \
- return; \
- } \
+#define FAIL_TEST(cond) \
+ do \
+ { \
+ if (! (cond)) \
+ { \
+ GNUNET_break (0); \
+ if (NULL != abort_task) \
+ GNUNET_SCHEDULER_cancel (abort_task); \
+ abort_task = NULL; \
+ GNUNET_SCHEDULER_shutdown (); \
+ return; \
+ } \
} while (0)
static void
do_abort (void *cls)
{
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "Aborting in stage %d\n",
- result);
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting in stage %d\n", result);
abort_task = NULL;
GNUNET_SCHEDULER_shutdown ();
}
* @param emsg NULL if peer is not NULL; else MAY contain the error description
*/
static void
-peer_create_cb (void *cls,
- struct GNUNET_TESTBED_Peer *peer,
- const char *emsg)
+peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
{
FAIL_TEST (NULL != peer);
FAIL_TEST (NULL == emsg);
slave2_peer = peer;
GNUNET_TESTBED_operation_done (op);
op = NULL;
- delay_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 1),
- &delay_task,
- NULL);
+ delay_task_id = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
+ &delay_task,
+ NULL);
return;
case SLAVE3_STARTED:
result = SLAVE3_PEER_CREATE_SUCCESS;
* @param event information about the event
*/
static void
-controller_cb (void *cls,
- const struct GNUNET_TESTBED_EventInformation *event)
+controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
{
switch (result)
{
result = SLAVE3_PEER_START_SUCCESS;
sleep (1);
LOG_DEBUG ("**************************************\n");
- op = GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer,
- slave3_peer);
+ op =
+ GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, slave2_peer, slave3_peer);
FAIL_TEST (NULL != op);
break;
case SLAVE3_PEER_START_SUCCESS:
result = SLAVE2_SLAVE3_PEERS_CONNECTED;
GNUNET_TESTBED_operation_done (op);
op = NULL;
- delay_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task,
- NULL);
+ delay_task_id = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
+ &delay_task,
+ NULL);
break;
case SLAVE1_PEER_STOP_SUCCESS:
FAIL_TEST (GNUNET_TESTBED_ET_PEER_START == event->type);
FAIL_TEST (event->details.peer_start.peer == slave2_peer);
GNUNET_TESTBED_operation_done (op);
result = SLAVE2_PEER_START_SUCCESS;
- op = GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer,
- slave2_peer);
+ op =
+ GNUNET_TESTBED_overlay_connect (mc, NULL, NULL, master_peer, slave2_peer);
break;
case SLAVE2_PEER_START_SUCCESS:
FAIL_TEST (NULL != event);
result = MASTER_SLAVE2_PEERS_CONNECTED;
GNUNET_TESTBED_operation_done (op);
op = NULL;
- delay_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 1), &delay_task,
- NULL);
+ delay_task_id = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
+ &delay_task,
+ NULL);
break;
case SLAVE2_SLAVE3_PEERS_CONNECTED:
FAIL_TEST (GNUNET_TESTBED_ET_PEER_STOP == event->type);
* GNUNET_TESTBED_controller_stop() shouldn't be called in this case
*/
static void
-status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
+status_cb (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *config,
int status)
{
switch (result)
event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
- mc = GNUNET_TESTBED_controller_connect (host, event_mask,
- &controller_cb, NULL);
+ mc = GNUNET_TESTBED_controller_connect (host,
+ event_mask,
+ &controller_cb,
+ NULL);
FAIL_TEST (NULL != mc);
result = MASTER_STARTED;
op = GNUNET_TESTBED_peer_create (mc, host, cfg, peer_create_cb, NULL);
hc_handle = NULL;
if (GNUNET_NO == status)
{
- (void) PRINTF ("%s",
+ (void) printf ("%s",
"Unable to run the test as this system is not configured "
"to use password less SSH logins to localhost.\n"
"Skipping test\n");
result = SKIP;
return;
}
- cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb,
- NULL);
+ cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, status_cb, NULL);
}
* @param cfg the configuration file handle
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
cfg = GNUNET_CONFIGURATION_dup (config);
host = GNUNET_TESTBED_host_create (NULL, NULL, cfg, 0);
FAIL_TEST (NULL != host);
- if (NULL ==
- (hc_handle =
- GNUNET_TESTBED_is_host_habitable (host, config, &host_habitable_cb,
- NULL)))
+ if (NULL == (hc_handle = GNUNET_TESTBED_is_host_habitable (host,
+ config,
+ &host_habitable_cb,
+ NULL)))
{
GNUNET_TESTBED_host_destroy (host);
GNUNET_CONFIGURATION_destroy (cfg);
cfg = NULL;
host = NULL;
- (void) PRINTF ("%s",
+ (void) printf ("%s",
"Unable to run the test as this system is not configured "
"to use password less SSH logins to localhost.\n"
"Marking test as successful\n");
result = SKIP;
return;
}
- abort_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
+ abort_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5),
+ &do_abort,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
int
main (int argc, char **argv)
{
- char *const argv2[] = { "test_testbed_api_controllerlink",
- "-c", "test_testbed_api.conf",
- NULL
- };
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ char *const argv2[] = {"test_testbed_api_controllerlink",
+ "-c",
+ "test_testbed_api.conf",
+ NULL};
+ struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END};
int ret;
result = INIT;
- ret =
- GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
- "test_testbed_api_controllerlink", "nohelp", options,
- &run, NULL);
+ ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
+ argv2,
+ "test_testbed_api_controllerlink",
+ "nohelp",
+ options,
+ &run,
+ NULL);
if (GNUNET_OK != ret)
return 1;
switch (result)
case SUCCESS:
return 0;
case SKIP:
- return 77; /* Mark test as skipped */
+ return 77; /* Mark test as skipped */
default:
return 1;
}
/**
* Generic logging shorthand
*/
-#define LOG(kind, ...) \
- GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__);
+#define LOG(kind, ...) GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__);
/**
* Debug logging shorthand
*/
-#define LOG_DEBUG(...) \
- LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
+#define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
/**
* Prints API violation message
*/
-#define API_VIOLATION(cond,errstr) \
- do { \
- if (cond) \
- break; \
+#define API_VIOLATION(cond, errstr) \
+ do \
+ { \
+ if (cond) \
+ break; \
LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \
- GNUNET_assert (0); \
+ GNUNET_assert (0); \
} while (0)
/**
* Log an error message at log-level 'level' that indicates a failure of the
* command 'cmd' with the message given by gai_strerror(rc).
*/
-#define LOG_GAI(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gai_strerror(rc)); } while(0)
+#define LOG_GAI(level, cmd, rc) \
+ do \
+ { \
+ LOG (level, \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ gai_strerror (rc)); \
+ } while (0)
/**
* Number of extra elements we create space for when we grow host list
* The port which is to be used for SSH
*/
uint16_t port;
-
};
* @return handle to the host, NULL on error
*/
struct GNUNET_TESTBED_Host *
-GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+GNUNET_TESTBED_host_create_by_id_ (
+ uint32_t id,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0);
}
* 'localhost', but then obviously not globally unique)
*/
uint32_t
-GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host * host)
+GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host)
{
return host->id;
}
* @return username to login to the host
*/
uint16_t
-GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host * host)
+GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host)
{
return host->port;
}
* @param new_cfg the new configuration to replace the old one
*/
void
-GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host,
- const struct GNUNET_CONFIGURATION_Handle *new_cfg)
+GNUNET_TESTBED_host_replace_cfg_ (
+ struct GNUNET_TESTBED_Host *host,
+ const struct GNUNET_CONFIGURATION_Handle *new_cfg)
{
GNUNET_CONFIGURATION_destroy (host->cfg);
host->cfg = GNUNET_CONFIGURATION_dup (new_cfg);
* @return handle to the host, NULL on error
*/
struct GNUNET_TESTBED_Host *
-GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname,
- const char *username,
- const struct GNUNET_CONFIGURATION_Handle
- *cfg,
- uint16_t port)
+GNUNET_TESTBED_host_create_with_id (
+ uint32_t id,
+ const char *hostname,
+ const char *username,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ uint16_t port)
{
struct GNUNET_TESTBED_Host *host;
unsigned int new_size;
host->port = (0 == port) ? 22 : port;
host->cfg = GNUNET_CONFIGURATION_dup (cfg);
host->opq_parallel_overlay_connect_operations =
- GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE,
- UINT_MAX);
+ GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_ADAPTIVE,
+ UINT_MAX);
new_size = host_list_size;
while (id >= new_size)
new_size += HOST_LIST_GROW_STEP;
* @return handle to the host, NULL on error
*/
struct GNUNET_TESTBED_Host *
-GNUNET_TESTBED_host_create (const char *hostname, const char *username,
+GNUNET_TESTBED_host_create (const char *hostname,
+ const char *username,
const struct GNUNET_CONFIGURATION_Handle *cfg,
uint16_t port)
{
static uint32_t uid_generator;
if (NULL == hostname)
- return GNUNET_TESTBED_host_create_with_id (0, hostname, username,
- cfg, port);
- return GNUNET_TESTBED_host_create_with_id (++uid_generator, hostname,
- username, cfg, port);
+ return GNUNET_TESTBED_host_create_with_id (0,
+ hostname,
+ username,
+ cfg,
+ port);
+ return GNUNET_TESTBED_host_create_with_id (++uid_generator,
+ hostname,
+ username,
+ cfg,
+ port);
}
* @return number of hosts returned in 'hosts', 0 on error
*/
unsigned int
-GNUNET_TESTBED_hosts_load_from_file (const char *filename,
- const struct GNUNET_CONFIGURATION_Handle
- *cfg,
- struct GNUNET_TESTBED_Host ***hosts)
+GNUNET_TESTBED_hosts_load_from_file (
+ const char *filename,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTBED_Host ***hosts)
{
struct GNUNET_TESTBED_Host *starting_host;
char *data;
GNUNET_assert (NULL != filename);
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s not found\n"), filename);
+ LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Hosts file %s not found\n"), filename);
return 0;
}
if (GNUNET_OK !=
fs = 0;
if (0 == fs)
{
- LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s has no data\n"), filename);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _ ("Hosts file %s has no data\n"),
+ filename);
return 0;
}
data = GNUNET_malloc (fs);
if (fs != GNUNET_DISK_fn_read (filename, data, fs))
{
GNUNET_free (data);
- LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s cannot be read\n"),
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _ ("Hosts file %s cannot be read\n"),
filename);
return 0;
}
username = NULL;
hostname = NULL;
port = 0;
- if ((REG_NOMATCH == regexec (&rex, buf, 6, pmatch, 0))
- || (-1 == pmatch[3].rm_so))
+ if ((REG_NOMATCH == regexec (&rex, buf, 6, pmatch, 0)) ||
+ (-1 == pmatch[3].rm_so))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Error reading line `%s' in hostfile\n", buf);
+ "Error reading line `%s' in hostfile\n",
+ buf);
buf = &data[offset + 1];
continue;
}
{
size = pmatch[2].rm_eo - pmatch[2].rm_so;
username = GNUNET_malloc (size + 1);
- GNUNET_assert(0 != GNUNET_strlcpy (username,
- buf + pmatch[2].rm_so,
- size + 1));
+ GNUNET_assert (
+ 0 != GNUNET_strlcpy (username, buf + pmatch[2].rm_so, size + 1));
}
if (-1 != pmatch[5].rm_so)
{
- (void) SSCANF (buf + pmatch[5].rm_so, "%5hd", &port);
+ (void) sscanf (buf + pmatch[5].rm_so, "%5hd", &port);
}
size = pmatch[3].rm_eo - pmatch[3].rm_so;
hostname = GNUNET_malloc (size + 1);
- GNUNET_assert(0 != GNUNET_strlcpy (hostname,
- buf + pmatch[3].rm_so,
- size + 1));
+ GNUNET_assert (
+ 0 != GNUNET_strlcpy (hostname, buf + pmatch[3].rm_so, size + 1));
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Successfully read host %s, port %d and user %s from file\n",
(NULL == hostname) ? "NULL" : hostname,
/* We store hosts in a static list; hence we only require the starting
* host pointer in that list to access the newly created list of hosts */
if (NULL == starting_host)
- starting_host = GNUNET_TESTBED_host_create (hostname, username, cfg,
- port);
+ starting_host =
+ GNUNET_TESTBED_host_create (hostname, username, cfg, port);
else
(void) GNUNET_TESTBED_host_create (hostname, username, cfg, port);
count++;
struct addrinfo hint;
unsigned int rc;
- hint.ai_family = AF_INET; /* IPv4 */
+ hint.ai_family = AF_INET; /* IPv4 */
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_addrlen = 0;
* @return number of hosts returned in 'hosts', 0 on error
*/
unsigned int
-GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTBED_Host ***hosts)
+GNUNET_TESTBED_hosts_load_from_loadleveler (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTBED_Host ***hosts)
{
-#if !ENABLE_SUPERMUC
+#if ! ENABLE_SUPERMUC
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("The function %s is only available when compiled with (--with-ll)\n"),
+ _ ("The function %s is only available when compiled with (--with-ll)\n"),
__func__);
GNUNET_assert (0);
#else
}
GNUNET_free_non_null ((char *) host->username);
GNUNET_free_non_null ((char *) host->hostname);
- GNUNET_TESTBED_operation_queue_destroy_
- (host->opq_parallel_overlay_connect_operations);
+ GNUNET_TESTBED_operation_queue_destroy_ (
+ host->opq_parallel_overlay_connect_operations);
GNUNET_CONFIGURATION_destroy (host->cfg);
GNUNET_free (host);
while (host_list_size >= HOST_LIST_GROW_STEP)
host_list_size -= HOST_LIST_GROW_STEP;
}
host_list =
- GNUNET_realloc (host_list,
- sizeof (struct GNUNET_TESTBED_Host *) * host_list_size);
+ GNUNET_realloc (host_list,
+ sizeof (struct GNUNET_TESTBED_Host *) * host_list_size);
}
* @param controller the controller at which this host is registered
*/
void
-GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host,
- const struct GNUNET_TESTBED_Controller
- *const controller)
+GNUNET_TESTBED_mark_host_registered_at_ (
+ struct GNUNET_TESTBED_Host *host,
+ const struct GNUNET_TESTBED_Controller *const controller)
{
struct RegisteredController *rc;
for (rc = host->rc_head; NULL != rc; rc = rc->next)
{
- if (controller == rc->controller) /* already registered at controller */
+ if (controller == rc->controller) /* already registered at controller */
{
GNUNET_break (0);
return;
* @param controller the controller at which this host has to be unmarked
*/
void
-GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host,
- const struct GNUNET_TESTBED_Controller
- *const controller)
+GNUNET_TESTBED_deregister_host_at_ (
+ struct GNUNET_TESTBED_Host *host,
+ const struct GNUNET_TESTBED_Controller *const controller)
{
struct RegisteredController *rc;
- for (rc = host->rc_head; NULL != rc; rc=rc->next)
+ for (rc = host->rc_head; NULL != rc; rc = rc->next)
if (controller == rc->controller)
break;
if (NULL == rc)
* @return GNUNET_YES if registered; GNUNET_NO if not
*/
int
-GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host,
- const struct GNUNET_TESTBED_Controller
- *const controller)
+GNUNET_TESTBED_is_host_registered_ (
+ const struct GNUNET_TESTBED_Host *host,
+ const struct GNUNET_TESTBED_Controller *const controller)
{
struct RegisteredController *rc;
for (rc = host->rc_head; NULL != rc; rc = rc->next)
{
- if (controller == rc->controller) /* already registered at controller */
+ if (controller == rc->controller) /* already registered at controller */
{
return GNUNET_YES;
}
* The message corresponding to send handle
*/
struct GNUNET_MessageHeader *msg;
-
};
unsigned int argp;
GNUNET_assert (NULL != argv);
- for (argp = 0; NULL != argv[argp]; argp++) ;
+ for (argp = 0; NULL != argv[argp]; argp++)
+ ;
argv_dup = GNUNET_malloc (sizeof (char *) * (argp + 1));
for (argp = 0; NULL != argv[argp]; argp++)
argv_dup[argp] = GNUNET_strdup (argv[argp]);
static char **
gen_rsh_args (const char *port, const char *hostname, const char *username)
{
- static const char *default_ssh_args[] = {
- "ssh",
- "-o",
- "BatchMode=yes",
- "-o",
- "NoHostAuthenticationForLocalhost=yes",
- "-o",
- "StrictHostKeyChecking=no",
- "-o",
- "PasswordAuthentication=no",
- "%h",
- NULL
- };
+ static const char *default_ssh_args[] =
+ {"ssh",
+ "-o",
+ "BatchMode=yes",
+ "-o",
+ "NoHostAuthenticationForLocalhost=yes",
+ "-o",
+ "StrictHostKeyChecking=no",
+ "-o",
+ "PasswordAuthentication=no",
+ "%h",
+ NULL};
char **ssh_args;
char *ssh_cmd;
char *ssh_cmd_cp;
* @return NULL-terminated args
*/
static char **
-gen_rsh_suffix_args (const char * const *append_args)
+gen_rsh_suffix_args (const char *const *append_args)
{
char **rshell_args;
char *rshell_cmd;
if (NULL != append_args)
{
for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++)
- GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (append_args[append_cnt]));
+ GNUNET_array_append (rshell_args,
+ cnt,
+ GNUNET_strdup (append_args[append_cnt]));
}
GNUNET_array_append (rshell_args, cnt, NULL);
return rshell_args;
* @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
*/
static int
-helper_mst (void *cls,
- const struct GNUNET_MessageHeader *message)
+helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_TESTBED_ControllerProc *cp = cls;
const struct GNUNET_TESTBED_HelperReply *msg;
GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY ==
ntohs (msg->header.type));
config_size = (uLongf) ntohs (msg->config_size);
- xconfig_size =
- (uLongf) (ntohs (msg->header.size) -
- sizeof (struct GNUNET_TESTBED_HelperReply));
+ xconfig_size = (uLongf) (ntohs (msg->header.size) -
+ sizeof (struct GNUNET_TESTBED_HelperReply));
config = GNUNET_malloc (config_size);
- GNUNET_assert (Z_OK ==
- uncompress ((Bytef *) config, &config_size,
- (const Bytef *) &msg[1], xconfig_size));
+ GNUNET_assert (Z_OK == uncompress ((Bytef *) config,
+ &config_size,
+ (const Bytef *) &msg[1],
+ xconfig_size));
/* Replace the configuration template present in the host with the
controller's running configuration */
GNUNET_CONFIGURATION_destroy (cp->host->cfg);
cp->host->cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_assert (GNUNET_CONFIGURATION_deserialize
- (cp->host->cfg,
- config,
- config_size,
- NULL));
+ GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg,
+ config,
+ config_size,
+ NULL));
GNUNET_free (config);
if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))
hostname = "localhost";
/* Change the hostname so that we can connect to it */
- GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, "testbed", "hostname",
+ GNUNET_CONFIGURATION_set_value_string (cp->host->cfg,
+ "testbed",
+ "hostname",
hostname);
cp->host->locked = GNUNET_NO;
cp->host->controller_started = GNUNET_YES;
struct GNUNET_TESTBED_HelperInit *msg;
const struct GNUNET_CONFIGURATION_Handle *cfg;
const char *hostname;
- static char *const binary_argv[] = {
- HELPER_TESTBED_BINARY, NULL
- };
+ static char *const binary_argv[] = {HELPER_TESTBED_BINARY, NULL};
GNUNET_assert (NULL != host);
GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host)));
hostname = NULL;
- API_VIOLATION (GNUNET_NO == host->locked,
- "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()");
+ API_VIOLATION (
+ GNUNET_NO == host->locked,
+ "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()");
host->locked = GNUNET_YES;
- API_VIOLATION (GNUNET_NO == host->controller_started,
- "Attempting to start a controller on a host which is already started a controller");
+ API_VIOLATION (
+ GNUNET_NO == host->controller_started,
+ "Attempting to start a controller on a host which is already started a controller");
cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc);
if (0 == GNUNET_TESTBED_host_get_id_ (host))
{
- cp->helper =
- GNUNET_HELPER_start (GNUNET_YES, HELPER_TESTBED_BINARY, binary_argv,
- &helper_mst, &helper_exp_cb, cp);
+ cp->helper = GNUNET_HELPER_start (GNUNET_YES,
+ HELPER_TESTBED_BINARY,
+ binary_argv,
+ &helper_mst,
+ &helper_exp_cb,
+ cp);
}
else
{
GNUNET_asprintf (&port, "%u", host->port);
LOG_DEBUG ("Starting remote connection to destination %s\n", hostname);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed",
- "HELPER_BINARY_PATH",
- &helper_binary_path_args[0]))
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "testbed",
+ "HELPER_BINARY_PATH",
+ &helper_binary_path_args[0]))
helper_binary_path_args[0] =
- GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
+ GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
helper_binary_path_args[1] = NULL;
rsh_args = gen_rsh_args (port, hostname, username);
- rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args);
+ rsh_suffix_args =
+ gen_rsh_suffix_args ((const char **) helper_binary_path_args);
cp->helper_argv =
- join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
+ join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
free_argv (rsh_args);
free_argv (rsh_suffix_args);
GNUNET_free (port);
for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++)
{
aux = argstr;
- GNUNET_assert (0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt]));
+ GNUNET_assert (
+ 0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt]));
GNUNET_free (aux);
}
LOG_DEBUG ("Helper cmd str: %s\n", argstr);
GNUNET_free (argstr);
- cp->helper =
- GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst,
- &helper_exp_cb, cp);
+ cp->helper = GNUNET_HELPER_start (GNUNET_NO,
+ cp->helper_argv[0],
+ cp->helper_argv,
+ &helper_mst,
+ &helper_exp_cb,
+ cp);
GNUNET_free (helper_binary_path_args[0]);
}
if (NULL == cp->helper)
msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg);
cp->msg = &msg->header;
cp->shandle =
- GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp);
+ GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp);
if (NULL == cp->shandle)
{
GNUNET_free (msg);
/**
* Task id for the habitability check task
*/
- struct GNUNET_SCHEDULER_Task * habitability_check_task;
+ struct GNUNET_SCHEDULER_Task *habitability_check_task;
/**
* How long we wait before checking the process status. Should grow
* exponentially
*/
struct GNUNET_TIME_Relative wait_time;
-
};
{
h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
h->habitability_check_task =
- GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
+ GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
return;
}
GNUNET_OS_process_destroy (h->auxp);
* GNUNET_TESTBED_is_host_habitable_cancel()
*/
struct GNUNET_TESTBED_HostHabitableCheckHandle *
-GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
- const struct GNUNET_CONFIGURATION_Handle
- *config,
- GNUNET_TESTBED_HostHabitableCallback cb,
- void *cb_cls)
+GNUNET_TESTBED_is_host_habitable (
+ const struct GNUNET_TESTBED_Host *host,
+ const struct GNUNET_CONFIGURATION_Handle *config,
+ GNUNET_TESTBED_HostHabitableCallback cb,
+ void *cb_cls)
{
struct GNUNET_TESTBED_HostHabitableCheckHandle *h;
char **rsh_args;
h->host = host;
hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (config, "testbed",
- "HELPER_BINARY_PATH",
- &stat_args[1]))
- stat_args[1] =
- GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
+ GNUNET_CONFIGURATION_get_value_filename (config,
+ "testbed",
+ "HELPER_BINARY_PATH",
+ &stat_args[1]))
+ stat_args[1] = GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
GNUNET_asprintf (&port, "%u", host->port);
rsh_args = gen_rsh_args (port, hostname, host->username);
GNUNET_free (port);
stat_args[2] = NULL;
rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args);
GNUNET_free (stat_args[1]);
- h->helper_argv = join_argv ((const char **) rsh_args,
- (const char **) rsh_suffix_args);
+ h->helper_argv =
+ join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
free_argv (rsh_suffix_args);
free_argv (rsh_args);
- h->auxp =
- GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, NULL,
- NULL, NULL, h->helper_argv[0], h->helper_argv);
+ h->auxp = GNUNET_OS_start_process_vap (GNUNET_NO,
+ GNUNET_OS_INHERIT_STD_ERR,
+ NULL,
+ NULL,
+ NULL,
+ h->helper_argv[0],
+ h->helper_argv);
if (NULL == h->auxp)
{
- GNUNET_break (0); /* Cannot exec SSH? */
+ GNUNET_break (0); /* Cannot exec SSH? */
GNUNET_free (h);
return NULL;
}
h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
h->habitability_check_task =
- GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
+ GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
return h;
}
* @param handle the habitability check handle
*/
void
-GNUNET_TESTBED_is_host_habitable_cancel (struct
- GNUNET_TESTBED_HostHabitableCheckHandle
- *handle)
+GNUNET_TESTBED_is_host_habitable_cancel (
+ struct GNUNET_TESTBED_HostHabitableCheckHandle *handle)
{
GNUNET_SCHEDULER_cancel (handle->habitability_check_task);
(void) GNUNET_OS_process_kill (handle->auxp, GNUNET_TERM_SIG);
hostname = GNUNET_TESTBED_host_get_hostname (host);
if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller))
{
- LOG (GNUNET_ERROR_TYPE_WARNING, "Host hostname: %s already registered\n",
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Host hostname: %s already registered\n",
(NULL == hostname) ? "localhost" : hostname);
return NULL;
}
* @param handle the registration handle to cancel
*/
void
-GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
- *handle)
+GNUNET_TESTBED_cancel_registration (
+ struct GNUNET_TESTBED_HostRegistrationHandle *handle)
{
if (handle != handle->c->rh)
{
GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h,
struct GNUNET_TESTBED_Operation *op)
{
- GNUNET_TESTBED_operation_queue_insert_
- (h->opq_parallel_overlay_connect_operations, op);
+ GNUNET_TESTBED_operation_queue_insert_ (h->opq_parallel_overlay_connect_operations,
+ op);
}
#include "gnunet_testing_lib.h"
-#define LOG(kind,...) \
- GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__)
/**
static struct GNUNET_TESTING_Peer *my_peer;
-
static int
-create_unique_cfgs (const char * template, const unsigned int no)
+create_unique_cfgs (const char *template, const unsigned int no)
{
struct GNUNET_TESTING_System *system;
int fail;
struct GNUNET_CONFIGURATION_Handle *cfg_new;
struct GNUNET_CONFIGURATION_Handle *cfg_tmpl;
- if (GNUNET_NO == GNUNET_DISK_file_test(template))
+ if (GNUNET_NO == GNUNET_DISK_file_test (template))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Configuration template `%s': file not found\n", create_cfg_template);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Configuration template `%s': file not found\n",
+ create_cfg_template);
return 1;
}
- cfg_tmpl = GNUNET_CONFIGURATION_create();
+ cfg_tmpl = GNUNET_CONFIGURATION_create ();
/* load template */
- if ((create_cfg_template != NULL) && (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, create_cfg_template)))
+ if ((create_cfg_template != NULL) &&
+ (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, create_cfg_template)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load template `%s'\n", create_cfg_template);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not load template `%s'\n",
+ create_cfg_template);
GNUNET_CONFIGURATION_destroy (cfg_tmpl);
return 1;
}
/* load defaults */
- if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load template `%s'\n", create_cfg_template);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not load template `%s'\n",
+ create_cfg_template);
GNUNET_CONFIGURATION_destroy (cfg_tmpl);
return 1;
}
fail = GNUNET_NO;
- system = GNUNET_TESTING_system_create ("testing", NULL /* controller */,
- NULL, NULL);
+ system =
+ GNUNET_TESTING_system_create ("testing", NULL /* controller */, NULL, NULL);
for (cur = 0; cur < no; cur++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating configuration no. %u \n", cur);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating configuration no. %u \n",
+ cur);
if (create_cfg_template != NULL)
- GNUNET_asprintf (&cur_file,"%04u-%s",cur, create_cfg_template);
+ GNUNET_asprintf (&cur_file, "%04u-%s", cur, create_cfg_template);
else
- GNUNET_asprintf (&cur_file,"%04u%s",cur, ".conf");
+ GNUNET_asprintf (&cur_file, "%04u%s", cur, ".conf");
cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl);
- if (GNUNET_OK !=
- GNUNET_TESTING_configuration_create (system, cfg_new))
+ if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg_new))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create another configuration\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not create another configuration\n");
GNUNET_CONFIGURATION_destroy (cfg_new);
fail = GNUNET_YES;
break;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Writing configuration no. %u to file `%s' \n", cur, cur_file);
- if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg_new, cur_file))
+ "Writing configuration no. %u to file `%s' \n",
+ cur,
+ cur_file);
+ if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg_new, cur_file))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to write configuration no. %u \n", cur);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to write configuration no. %u \n",
+ cur);
fail = GNUNET_YES;
}
GNUNET_CONFIGURATION_destroy (cfg_new);
if (GNUNET_YES == fail)
break;
}
- GNUNET_CONFIGURATION_destroy(cfg_tmpl);
+ GNUNET_CONFIGURATION_destroy (cfg_tmpl);
GNUNET_TESTING_system_destroy (system, GNUNET_NO);
if (GNUNET_YES == fail)
return 1;
pk = GNUNET_TESTING_hostkey_get (system, create_no, &id);
if (NULL == pk)
{
- fprintf (stderr, _("Could not extract hostkey %u (offset too large?)\n"), create_no);
+ fprintf (stderr,
+ _ ("Could not extract hostkey %u (offset too large?)\n"),
+ create_no);
GNUNET_TESTING_system_destroy (system, GNUNET_YES);
return 1;
}
(void) GNUNET_DISK_directory_create_for_file (create_hostkey);
- fd = GNUNET_DISK_file_open (create_hostkey,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ fd =
+ GNUNET_DISK_file_open (create_hostkey,
+ GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
GNUNET_assert (fd != NULL);
- ret = GNUNET_DISK_file_write (fd, pk,
- sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
+ ret = GNUNET_DISK_file_write (fd,
+ pk,
+ sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
- "Wrote hostkey to file: `%s'\n", create_hostkey);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "transport-testing",
+ "Wrote hostkey to file: `%s'\n",
+ create_hostkey);
GNUNET_free (pk);
GNUNET_TESTING_system_destroy (system, GNUNET_YES);
return 0;
{
if (NULL != tmpfilename)
{
- if (0 != UNLINK (tmpfilename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", tmpfilename);
+ if (0 != unlink (tmpfilename))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "unlink",
+ tmpfilename);
}
if (NULL != tid)
{
/* ignore whitespace */
break;
default:
- fprintf (stderr, _("Unknown command, use 'q' to quit or 'r' to restart peer\n"));
+ fprintf (stderr,
+ _ ("Unknown command, use 'q' to quit or 'r' to restart peer\n"));
break;
}
tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- fh,
- &stdin_cb, NULL);
+ fh,
+ &stdin_cb,
+ NULL);
}
* @param peer handle to the peer
*/
static void
-testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+testing_main (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
my_peer = peer;
GNUNET_break (0);
return;
}
- printf("ok\n%s\n", tmpfilename);
- fflush(stdout);
+ printf ("ok\n%s\n", tmpfilename);
+ fflush (stdout);
GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
fh = GNUNET_DISK_get_handle_from_native (stdin);
tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- fh,
- &stdin_cb, NULL);
+ fh,
+ &stdin_cb,
+ NULL);
}
-
/**
* Main function that will be running without scheduler.
*
* @param cfg configuration
*/
static void
-run_no_scheduler (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+run_no_scheduler (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
if (NULL != run_service_name)
{
- ret = GNUNET_TESTING_service_run ("gnunet_service_test", run_service_name,
- cfgfile, &testing_main, NULL);
+ ret = GNUNET_TESTING_service_run ("gnunet_service_test",
+ run_service_name,
+ cfgfile,
+ &testing_main,
+ NULL);
return;
}
if (create_no > 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating %u configuration files based on template `%s'\n", create_no, create_cfg_template);
+ "Creating %u configuration files based on template `%s'\n",
+ create_no,
+ create_cfg_template);
ret = create_unique_cfgs (create_cfg_template, create_no);
}
else
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('C',
- "cfg",
- gettext_noop ("create unique configuration files"),
- &create_cfg),
- GNUNET_GETOPT_option_string ('k',
- "key",
- "FILENAME",
- gettext_noop ("extract hostkey file from pre-computed hostkey list"),
- &create_hostkey),
-
- GNUNET_GETOPT_option_uint ('n',
- "number",
- "NUMBER",
- gettext_noop ("number of unique configuration files to create, or number of the hostkey to extract"),
- &create_no),
-
-
- GNUNET_GETOPT_option_string ('t',
- "template",
- "FILENAME",
- gettext_noop ("configuration template"),
- &create_cfg_template),
-
- GNUNET_GETOPT_option_string ('r',
- "run",
- "SERVICE",
- gettext_noop ("run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"),
- &run_service_name),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag ('C',
+ "cfg",
+ gettext_noop (
+ "create unique configuration files"),
+ &create_cfg),
+ GNUNET_GETOPT_option_string (
+ 'k',
+ "key",
+ "FILENAME",
+ gettext_noop ("extract hostkey file from pre-computed hostkey list"),
+ &create_hostkey),
+
+ GNUNET_GETOPT_option_uint (
+ 'n',
+ "number",
+ "NUMBER",
+ gettext_noop (
+ "number of unique configuration files to create, or number of the hostkey to extract"),
+ &create_no),
+
+
+ GNUNET_GETOPT_option_string ('t',
+ "template",
+ "FILENAME",
+ gettext_noop ("configuration template"),
+ &create_cfg_template),
+
+ GNUNET_GETOPT_option_string (
+ 'r',
+ "run",
+ "SERVICE",
+ gettext_noop (
+ "run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"),
+ &run_service_name),
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
* GNUNET_TESTING_service_run, which starts the scheduler on its own.
* Furthermore, the other functionality currently does not require the scheduler, too,
* but beware when extending gnunet-testing. */
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run2 (argc, argv, "gnunet-testing",
- gettext_noop ("Command line tool to access the testing library"), options, &run_no_scheduler,
- NULL, GNUNET_YES)) ? ret : 1;
- GNUNET_free ((void*) argv);
+ ret =
+ (GNUNET_OK ==
+ GNUNET_PROGRAM_run2 (argc,
+ argv,
+ "gnunet-testing",
+ gettext_noop (
+ "Command line tool to access the testing library"),
+ options,
+ &run_no_scheduler,
+ NULL,
+ GNUNET_YES))
+ ? ret
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
* @param cfg the configuration file handle
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *config)
{
char *idfile;
if ((NULL == args) || (NULL == args[0]))
{
- FPRINTF (stderr, "Need the hostkey file\n");
+ fprintf (stderr, "Need the hostkey file\n");
return;
}
idfile = args[0];
}
if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
{
- FPRINTF (stderr,
- _("Incorrect hostkey file format: %s\n"), idfile);
+ fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), idfile);
return;
}
- f = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ,
+ f = GNUNET_DISK_file_open (idfile,
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == f)
{
{
if (nskip + cnt >= nmax)
{
- PRINTF ("Max keys %u reached\n", nmax);
+ printf ("Max keys %u reached\n", nmax);
break;
}
GNUNET_memcpy (&pkey,
data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
GNUNET_TESTING_HOSTKEYFILESIZE);
GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key);
- PRINTF ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
+ printf ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
}
result = GNUNET_OK;
GNUNET_DISK_file_unmap (map);
}
-int main (int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
- struct GNUNET_GETOPT_CommandLineOption option[] = {
- GNUNET_GETOPT_option_uint ('n',
- "num-keys",
- "COUNT",
- gettext_noop ("list COUNT number of keys"),
- &nkeys),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption option[] =
+ {GNUNET_GETOPT_option_uint ('n',
+ "num-keys",
+ "COUNT",
+ gettext_noop ("list COUNT number of keys"),
+ &nkeys),
+ GNUNET_GETOPT_OPTION_END};
int ret;
result = GNUNET_SYSERR;
nkeys = 10;
ret =
- GNUNET_PROGRAM_run (argc, argv, "list-keys", "Lists the peer IDs corresponding to the given keys file\n",
- option, &run, NULL);
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "list-keys",
+ "Lists the peer IDs corresponding to the given keys file\n",
+ option,
+ &run,
+ NULL);
if (GNUNET_OK != ret)
return 1;
if (GNUNET_SYSERR == result)
#include "gnunet_arm_service.h"
#include "gnunet_testing_lib.h"
-#define LOG(kind,...) \
- GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
/**
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Hostkeys file not found: %s\n"), filename);
+ _ ("Hostkeys file not found: %s\n"),
+ filename);
GNUNET_free (filename);
return GNUNET_SYSERR;
}
if (0 == fs)
{
GNUNET_free (filename);
- return GNUNET_SYSERR; /* File is empty */
+ return GNUNET_SYSERR; /* File is empty */
}
if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Incorrect hostkey file format: %s\n"), filename);
+ _ ("Incorrect hostkey file format: %s\n"),
+ filename);
GNUNET_free (filename);
return GNUNET_SYSERR;
}
- fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ fd = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
if (NULL == fd)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
return GNUNET_SYSERR;
}
GNUNET_free (filename);
- system->hostkeys_data = GNUNET_DISK_file_map (fd,
- &system->map,
- GNUNET_DISK_MAP_TYPE_READ,
- fs);
+ system->hostkeys_data =
+ GNUNET_DISK_file_map (fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs);
GNUNET_DISK_file_close (fd);
if (NULL == system->hostkeys_data)
return GNUNET_SYSERR;
* @param value value of the option
*/
static void
-cfg_copy_iterator (void *cls, const char *section,
- const char *option, const char *value)
+cfg_copy_iterator (void *cls,
+ const char *section,
+ const char *option,
+ const char *value)
{
struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
* @return handle to this system, NULL on error
*/
struct GNUNET_TESTING_System *
-GNUNET_TESTING_system_create_with_portrange (const char *testdir,
- const char *trusted_ip,
- const char *hostname,
- const struct
- GNUNET_TESTING_SharedService *
- shared_services,
- uint16_t lowport,
- uint16_t highport)
+GNUNET_TESTING_system_create_with_portrange (
+ const char *testdir,
+ const char *trusted_ip,
+ const char *hostname,
+ const struct GNUNET_TESTING_SharedService *shared_services,
+ uint16_t lowport,
+ uint16_t highport)
{
struct GNUNET_TESTING_System *system;
struct GNUNET_TESTING_SharedService tss;
ss = GNUNET_new (struct SharedService);
ss->sname = GNUNET_strdup (tss.service);
ss->cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, ss->sname,
- &cfg_copy_iterator, ss->cfg);
- GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, "TESTING",
- &cfg_copy_iterator, ss->cfg);
- GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, "PATHS",
- &cfg_copy_iterator, ss->cfg);
+ GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
+ ss->sname,
+ &cfg_copy_iterator,
+ ss->cfg);
+ GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
+ "TESTING",
+ &cfg_copy_iterator,
+ ss->cfg);
+ GNUNET_CONFIGURATION_iterate_section_values (tss.cfg,
+ "PATHS",
+ &cfg_copy_iterator,
+ ss->cfg);
ss->share = tss.share;
- GNUNET_array_append (system->shared_services, system->n_shared_services,
+ GNUNET_array_append (system->shared_services,
+ system->n_shared_services,
ss);
}
return system;
* @return handle to this system, NULL on error
*/
struct GNUNET_TESTING_System *
-GNUNET_TESTING_system_create (const char *testdir,
- const char *trusted_ip,
- const char *hostname,
- const struct GNUNET_TESTING_SharedService *
- shared_services)
+GNUNET_TESTING_system_create (
+ const char *testdir,
+ const char *trusted_ip,
+ const char *hostname,
+ const struct GNUNET_TESTING_SharedService *shared_services)
{
return GNUNET_TESTING_system_create_with_portrange (testdir,
- trusted_ip,
- hostname,
+ trusted_ip,
+ hostname,
shared_services,
- LOW_PORT,
- HIGH_PORT);
+ LOW_PORT,
+ HIGH_PORT);
}
GNUNET_free (binary);
i->proc = GNUNET_OS_start_process (PIPE_CONTROL,
GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- NULL, NULL, NULL,
+ NULL,
+ NULL,
+ NULL,
libexec_binary,
libexec_binary,
"-c",
GNUNET_break (0 == i->n_refs);
if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG))
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Killing shared service instance (%s) failed\n", i->ss->sname);
+ "Killing shared service instance (%s) failed\n",
+ i->ss->sname);
(void) GNUNET_OS_process_wait (i->proc);
GNUNET_OS_process_destroy (i->proc);
i->proc = NULL;
*/
void
GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
- int remove_paths)
+ int remove_paths)
{
struct SharedService *ss;
struct SharedServiceInstance *i;
On system with either IPv4 or IPv6. A port is considered open if it's
open in the respective address family
*/
- hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
+ hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
hint.ai_socktype = 0;
hint.ai_protocol = 0;
hint.ai_addrlen = 0;
hint.ai_addr = NULL;
hint.ai_canonname = NULL;
hint.ai_next = NULL;
- hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
+ hint.ai_flags = AI_PASSIVE | AI_NUMERICSERV; /* Wild card address */
port_buckets = system->reserved_ports;
- for (index = (system->lowport / 32) + 1; index < (system->highport / 32); index++)
+ for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
+ index++)
{
xor_image = (UINT32_MAX ^ port_buckets[index]);
- if (0 == xor_image) /* Ports in the bucket are full */
+ if (0 == xor_image) /* Ports in the bucket are full */
continue;
pos = system->lowport % 32;
while (pos < 32)
}
open_port = (index * 32) + pos;
if (open_port >= system->highport)
- return 0;
+ return 0;
GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port);
ret = NULL;
GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret));
socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0);
if (NULL == socket)
continue;
- bind_status = GNUNET_NETWORK_socket_bind (socket,
- ai->ai_addr,
- ai->ai_addrlen);
+ bind_status =
+ GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
GNUNET_NETWORK_socket_close (socket);
if (GNUNET_OK != bind_status)
break;
socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0);
if (NULL == socket)
continue;
- bind_status = GNUNET_NETWORK_socket_bind (socket,
- ai->ai_addr,
- ai->ai_addrlen);
+ bind_status =
+ GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen);
GNUNET_NETWORK_socket_close (socket);
if (GNUNET_OK != bind_status)
break;
if (GNUNET_OK == bind_status)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Found a free port %u\n", (unsigned int) open_port);
- return open_port;
+ "Found a free port %u\n",
+ (unsigned int) open_port);
+ return open_port;
}
pos++;
}
*/
void
GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
- uint16_t port)
+ uint16_t port)
{
uint32_t *port_buckets;
uint16_t bucket;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
if (0 == (port_buckets[bucket] & (1U << pos)))
{
- GNUNET_break(0); /* Port was not reserved by us using reserve_port() */
+ GNUNET_break (0); /* Port was not reserved by us using reserve_port() */
return;
}
port_buckets[bucket] &= ~(1U << pos);
*/
struct GNUNET_CRYPTO_EddsaPrivateKey *
GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
- uint32_t key_number,
- struct GNUNET_PeerIdentity *id)
+ uint32_t key_number,
+ struct GNUNET_PeerIdentity *id)
{
struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
if (key_number >= system->total_hostkeys)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Key number %u does not exist\n"),
+ _ ("Key number %u does not exist\n"),
key_number);
return NULL;
}
private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey);
GNUNET_memcpy (private_key,
- system->hostkeys_data +
- (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
- GNUNET_TESTING_HOSTKEYFILESIZE);
- GNUNET_CRYPTO_eddsa_key_get_public (private_key,
- &id->public_key);
+ system->hostkeys_data +
+ (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
+ GNUNET_TESTING_HOSTKEYFILESIZE);
+ GNUNET_CRYPTO_eddsa_key_get_public (private_key, &id->public_key);
return private_key;
}
if (GNUNET_OK != uc->status)
return;
- if (! ((0 == strcmp (option, "PORT"))
- || (0 == strcmp (option, "UNIXPATH"))
- || (0 == strcmp (option, "HOSTNAME"))))
+ if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) ||
+ (0 == strcmp (option, "HOSTNAME"))))
return;
GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
- if ((0 == strcmp (option, "PORT")) && (1 == SSCANF (value, "%u", &ival)))
+ if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
{
if ((ival != 0) &&
- (GNUNET_YES !=
- GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing",
- single_variable)))
+ (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
+ "testing",
+ single_variable)))
{
new_port = GNUNET_TESTING_reserve_port (uc->system);
if (0 == new_port)
}
else if ((ival != 0) &&
(GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing",
+ GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
+ "testing",
single_variable)) &&
- GNUNET_CONFIGURATION_get_value_number (uc->cfg, "testing",
+ GNUNET_CONFIGURATION_get_value_number (uc->cfg,
+ "testing",
per_host_variable,
&num_per_host))
{
/* GNUNET_snprintf (cval, sizeof (cval), "%u", */
/* ival + ctx->fdnum % num_per_host); */
/* value = cval; */
- GNUNET_break (0); /* FIXME */
+ GNUNET_break (0); /* FIXME */
}
}
if (0 == strcmp (option, "UNIXPATH"))
{
- if (GNUNET_YES !=
- GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, "testing",
- single_variable))
+ if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
+ "testing",
+ single_variable))
{
GNUNET_snprintf (uval,
sizeof (uval),
"%s/%s.sock",
- uc->gnunet_home, section);
+ uc->gnunet_home,
+ section);
value = uval;
}
else if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_number (uc->cfg, "testing",
+ GNUNET_CONFIGURATION_get_value_number (uc->cfg,
+ "testing",
per_host_variable,
&num_per_host)) &&
(num_per_host > 0))
{
- GNUNET_break(0); /* FIXME */
+ GNUNET_break (0); /* FIXME */
}
}
if (0 == strcmp (option, "HOSTNAME"))
* @param section name of the section
*/
static void
-update_config_sections (void *cls,
- const char *section)
+update_config_sections (void *cls, const char *section)
{
struct UpdateContext *uc = cls;
char **ikeys;
val = NULL;
/* Ignore certain options from sections. See
https://gnunet.org/bugs/view.php?id=2476 */
- if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section,
- "TESTING_IGNORE_KEYS"))
+ if (GNUNET_YES ==
+ GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS"))
{
- GNUNET_assert
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string (uc->cfg, section,
- "TESTING_IGNORE_KEYS", &val));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_string (uc->cfg,
+ section,
+ "TESTING_IGNORE_KEYS",
+ &val));
ptr = val;
for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
ptr++;
for (key = 0; key < ikeys_cnt; key++)
{
if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
- break;
+ break;
}
if ((key == ikeys_cnt) &&
- (GNUNET_YES == GNUNET_CONFIGURATION_have_value (uc->cfg, section,
- "ADVERTISED_PORT")))
+ (GNUNET_YES ==
+ GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
{
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, "PORT", &ptr))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (uc->cfg,
+ section,
+ "PORT",
+ &ptr))
{
- GNUNET_CONFIGURATION_set_value_string (uc->cfg, section,
- "ADVERTISED_PORT", ptr);
- GNUNET_free (ptr);
+ GNUNET_CONFIGURATION_set_value_string (uc->cfg,
+ section,
+ "ADVERTISED_PORT",
+ ptr);
+ GNUNET_free (ptr);
}
}
for (key = 0; key < ikeys_cnt; key++)
if ((NULL != uc->system->trusted_ip) &&
(NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */
ACCEPT_FROM_key = "ACCEPT_FROM6";
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (uc->cfg, section, ACCEPT_FROM_key,
- &orig_allowed_hosts))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (uc->cfg,
+ section,
+ ACCEPT_FROM_key,
+ &orig_allowed_hosts))
{
orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;");
}
if (NULL == uc->system->trusted_ip)
allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
else
- GNUNET_asprintf (&allowed_hosts, "%s%s;", orig_allowed_hosts,
+ GNUNET_asprintf (&allowed_hosts,
+ "%s%s;",
+ orig_allowed_hosts,
uc->system->trusted_ip);
GNUNET_free (orig_allowed_hosts);
- GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, ACCEPT_FROM_key,
+ GNUNET_CONFIGURATION_set_value_string (uc->cfg,
+ section,
+ ACCEPT_FROM_key,
allowed_hosts);
GNUNET_free (allowed_hosts);
}
uint32_t port;
ss->n_peers++;
- if ( ((0 == ss->share) && (NULL == ss->instances))
- ||
- ( (0 != ss->share)
- && (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)) ) )
+ if (((0 == ss->share) && (NULL == ss->instances)) ||
+ ((0 != ss->share) &&
+ (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
{
i = GNUNET_new (struct SharedServiceInstance);
i->ss = ss;
- (void) GNUNET_asprintf (&gnunet_home, "%s/shared/%s/%u",
- system->tmppath, ss->sname, ss->n_instances);
+ (void) GNUNET_asprintf (&gnunet_home,
+ "%s/shared/%s/%u",
+ system->tmppath,
+ ss->sname,
+ ss->n_instances);
(void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home);
port = GNUNET_TESTING_reserve_port (system);
if (0 == port)
temp = GNUNET_CONFIGURATION_dup (ss->cfg);
(void) GNUNET_asprintf (&i->port_str, "%u", port);
(void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
- GNUNET_CONFIGURATION_set_value_string (temp, "PATHS", "GNUNET_HOME",
+ GNUNET_CONFIGURATION_set_value_string (temp,
+ "PATHS",
+ "GNUNET_HOME",
gnunet_home);
GNUNET_free (gnunet_home);
- GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "UNIXPATH",
+ GNUNET_CONFIGURATION_set_value_string (temp,
+ ss->sname,
+ "UNIXPATH",
i->unix_sock);
- GNUNET_CONFIGURATION_set_value_string (temp, ss->sname, "PORT",
+ GNUNET_CONFIGURATION_set_value_string (temp,
+ ss->sname,
+ "PORT",
i->port_str);
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn))
{
GNUNET_assert (0 < ss->n_instances);
i = ss->instances[ss->n_instances - 1];
}
- GNUNET_CONFIGURATION_iterate_section_values(ss->cfg, ss->sname,
- &cfg_copy_iterator, cfg);
- GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "UNIXPATH",
+ GNUNET_CONFIGURATION_iterate_section_values (ss->cfg,
+ ss->sname,
+ &cfg_copy_iterator,
+ cfg);
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ ss->sname,
+ "UNIXPATH",
i->unix_sock);
GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
return i;
uc.status = GNUNET_OK;
uc.ports = NULL;
uc.nports = 0;
- GNUNET_asprintf (&uc.gnunet_home, "%s/%u", system->tmppath,
+ GNUNET_asprintf (&uc.gnunet_home,
+ "%s/%u",
+ system->tmppath,
system->path_counter++);
GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home);
- GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
- default_config);
- GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG",
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ "PATHS",
+ "DEFAULTCONFIG",
default_config);
+ GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config);
GNUNET_free (default_config);
- GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "GNUNET_HOME",
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ "PATHS",
+ "GNUNET_HOME",
uc.gnunet_home);
/* make PORTs and UNIXPATHs unique */
GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
/* allow connections to services from system trusted_ip host */
GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc);
/* enable loopback-based connections between peers */
- GNUNET_CONFIGURATION_set_value_string (cfg,
- "nat",
- "USE_LOCALADDR", "YES");
+ GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES");
GNUNET_free (uc.gnunet_home);
if ((NULL != ports) && (NULL != nports))
{
*/
int
GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
- struct GNUNET_CONFIGURATION_Handle *cfg)
+ struct GNUNET_CONFIGURATION_Handle *cfg)
{
return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL);
}
*/
struct GNUNET_TESTING_Peer *
GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
- struct GNUNET_CONFIGURATION_Handle *cfg,
- uint32_t key_number,
- struct GNUNET_PeerIdentity *id,
- char **emsg)
+ struct GNUNET_CONFIGURATION_Handle *cfg,
+ uint32_t key_number,
+ struct GNUNET_PeerIdentity *id,
+ char **emsg)
{
struct GNUNET_TESTING_Peer *peer;
struct GNUNET_DISK_FileHandle *fd;
*emsg = NULL;
if (key_number >= system->total_hostkeys)
{
- GNUNET_asprintf (&emsg_,
- _("You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
- (unsigned int) system->total_hostkeys);
+ GNUNET_asprintf (
+ &emsg_,
+ _ (
+ "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
+ (unsigned int) system->total_hostkeys);
goto err_ret;
}
pk = NULL;
(NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id))))
{
GNUNET_asprintf (&emsg_,
- _("Failed to initialize hostkey for peer %u\n"),
- (unsigned int) key_number);
+ _ ("Failed to initialize hostkey for peer %u\n"),
+ (unsigned int) key_number);
goto err_ret;
}
if (NULL != pk)
GNUNET_free (pk);
- if (GNUNET_NO ==
- GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
+ if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY"))
{
- GNUNET_asprintf (&emsg_,
- _("PRIVATE_KEY option in PEER section missing in configuration\n"));
+ GNUNET_asprintf (
+ &emsg_,
+ _ ("PRIVATE_KEY option in PEER section missing in configuration\n"));
goto err_ret;
}
/* Remove sections for shared services */
ss = system->shared_services[cnt];
GNUNET_CONFIGURATION_remove_section (cfg, ss->sname);
}
- if (GNUNET_OK != GNUNET_TESTING_configuration_create_ (system, cfg,
- &ports, &nports))
+ if (GNUNET_OK !=
+ GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports))
{
GNUNET_asprintf (&emsg_,
- _("Failed to create configuration for peer "
- "(not enough free ports?)\n"));
+ _ ("Failed to create configuration for peer "
+ "(not enough free ports?)\n"));
goto err_ret;
}
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER",
- "PRIVATE_KEY",
- &hostkey_filename));
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PEER",
+ "PRIVATE_KEY",
+ &hostkey_filename));
fd = GNUNET_DISK_file_open (hostkey_filename,
GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
{
- GNUNET_asprintf (&emsg_, _("Cannot open hostkey file `%s': %s\n"),
- hostkey_filename, STRERROR (errno));
+ GNUNET_asprintf (&emsg_,
+ _ ("Cannot open hostkey file `%s': %s\n"),
+ hostkey_filename,
+ strerror (errno));
GNUNET_free (hostkey_filename);
goto err_ret;
}
GNUNET_free (hostkey_filename);
if (GNUNET_TESTING_HOSTKEYFILESIZE !=
- GNUNET_DISK_file_write (fd, system->hostkeys_data
- + (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
- GNUNET_TESTING_HOSTKEYFILESIZE))
+ GNUNET_DISK_file_write (fd,
+ system->hostkeys_data +
+ (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
+ GNUNET_TESTING_HOSTKEYFILESIZE))
{
GNUNET_asprintf (&emsg_,
- _("Failed to write hostkey file for peer %u: %s\n"),
- (unsigned int) key_number,
- STRERROR (errno));
+ _ ("Failed to write hostkey file for peer %u: %s\n"),
+ (unsigned int) key_number,
+ strerror (errno));
GNUNET_DISK_file_close (fd);
goto err_ret;
}
GNUNET_DISK_file_close (fd);
- ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *)
- * system->n_shared_services);
- for (cnt=0; cnt < system->n_shared_services; cnt++)
+ ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *) *
+ system->n_shared_services);
+ for (cnt = 0; cnt < system->n_shared_services; cnt++)
{
ss = system->shared_services[cnt];
ss_instances[cnt] = associate_shared_service (system, ss, cfg);
}
}
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename
- (cfg, "PATHS", "DEFAULTCONFIG", &config_filename));
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PATHS",
+ "DEFAULTCONFIG",
+ &config_filename));
if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
{
GNUNET_asprintf (&emsg_,
- _("Failed to write configuration file `%s' for peer %u: %s\n"),
- config_filename,
- (unsigned int) key_number,
- STRERROR (errno));
+ _ (
+ "Failed to write configuration file `%s' for peer %u: %s\n"),
+ config_filename,
+ (unsigned int) key_number,
+ strerror (errno));
GNUNET_free (config_filename);
goto err_ret;
}
peer->cfgfile = config_filename; /* Free in peer_destroy */
peer->cfg = GNUNET_CONFIGURATION_dup (cfg);
libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "arm", "PREFIX", &peer->main_binary))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "arm",
+ "PREFIX",
+ &peer->main_binary))
{
/* No prefix */
- GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary);
+ GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
peer->args = GNUNET_strdup ("");
}
else
peer->system = system;
peer->key_number = key_number;
GNUNET_free (libexec_binary);
- peer->ports = ports; /* Free in peer_destroy */
+ peer->ports = ports; /* Free in peer_destroy */
peer->nports = nports;
return peer;
- err_ret:
+err_ret:
GNUNET_free_non_null (ss_instances);
GNUNET_free_non_null (ports);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
*/
void
GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
- struct GNUNET_PeerIdentity *id)
+ struct GNUNET_PeerIdentity *id)
{
if (NULL != peer->id)
{
return;
}
peer->id = GNUNET_new (struct GNUNET_PeerIdentity);
- GNUNET_free (GNUNET_TESTING_hostkey_get (peer->system,
- peer->key_number,
- peer->id));
+ GNUNET_free (
+ GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id));
GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity));
}
for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
{
i = peer->ss_instances[cnt];
- if ((0 == i->n_refs)
- && (GNUNET_SYSERR == start_shared_service_instance (i)) )
+ if ((0 == i->n_refs) &&
+ (GNUNET_SYSERR == start_shared_service_instance (i)))
return GNUNET_SYSERR;
i->n_refs++;
}
- peer->main_binary = GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary);
- peer->main_process = GNUNET_OS_start_process_s (PIPE_CONTROL,
- GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- NULL,
- peer->main_binary,
- peer->args,
- "-c",
- peer->cfgfile,
- NULL);
+ peer->main_binary =
+ GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary);
+ peer->main_process =
+ GNUNET_OS_start_process_s (PIPE_CONTROL,
+ GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+ NULL,
+ peer->main_binary,
+ peer->args,
+ "-c",
+ peer->cfgfile,
+ NULL);
if (NULL == peer->main_process)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to start `%s': %s\n"),
- peer->main_binary,
- STRERROR (errno));
+ _ ("Failed to start `%s': %s\n"),
+ peer->main_binary,
+ strerror (errno));
return GNUNET_SYSERR;
}
return GNUNET_OK;
* #GNUNET_SYSERR on error.
*/
static void
-disconn_status (void *cls,
- int connected)
+disconn_status (void *cls, int connected)
{
struct GNUNET_TESTING_Peer *peer = cls;
*/
int
GNUNET_TESTING_peer_run (const char *testdir,
- const char *cfgfilename,
- GNUNET_TESTING_TestMain tm,
- void *tm_cls)
+ const char *cfgfilename,
+ GNUNET_TESTING_TestMain tm,
+ void *tm_cls)
{
- return GNUNET_TESTING_service_run (testdir, "arm",
- cfgfilename, tm, tm_cls);
+ return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls);
}
*/
int
GNUNET_TESTING_service_run (const char *testdir,
- const char *service_name,
- const char *cfgfilename,
- GNUNET_TESTING_TestMain tm,
- void *tm_cls)
+ const char *service_name,
+ const char *cfgfilename,
+ GNUNET_TESTING_TestMain tm,
+ void *tm_cls)
{
struct ServiceContext sc;
struct GNUNET_TESTING_System *system;
char *binary;
char *libexec_binary;
- GNUNET_log_setup (testdir,
- "WARNING",
- NULL);
+ GNUNET_log_setup (testdir, "WARNING", NULL);
system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL);
if (NULL == system)
return 1;
if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load configuration from %s\n"), cfgfilename);
+ _ ("Failed to load configuration from %s\n"),
+ cfgfilename);
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_TESTING_system_destroy (system, GNUNET_YES);
return 1;
GNUNET_free (peer->args);
GNUNET_asprintf (&binary, "gnunet-service-%s", service_name);
libexec_binary = GNUNET_OS_get_libexec_binary_path (binary);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, service_name, "PREFIX", &peer->main_binary))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ service_name,
+ "PREFIX",
+ &peer->main_binary))
{
/* No prefix */
- GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary);
+ GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary);
peer->args = GNUNET_strdup ("");
}
else
GNUNET_TESTBED_operation_done (op);
if (NULL != emsg)
{
- FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg);
+ fprintf (stderr, "Failed to connect two peers: %s\n", emsg);
result = GNUNET_SYSERR;
GNUNET_SCHEDULER_shutdown ();
return;
char *colon;
char *cp;
- if (1 == SSCANF (bindto, "%u%1s", &port, dummy))
+ if (1 == sscanf (bindto, "%u%1s", &port, dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
/* interpet value after colon as port */
*colon = '\0';
colon++;
- if (1 == SSCANF (colon, "%u%1s", &port, dummy))
+ if (1 == sscanf (colon, "%u%1s", &port, dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"socket(%d) failed: %s",
in->sa_family,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (in);
return GNUNET_SYSERR;
}
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"connect to `%s' failed: %s",
address,
- STRERROR (errno));
+ strerror (errno));
GNUNET_NETWORK_socket_close (sock);
GNUNET_free (in);
return GNUNET_SYSERR;
char *colon;
char *cp;
- if (1 == SSCANF (bindto, "%u%1s", &port, dummy))
+ if (1 == sscanf (bindto, "%u%1s", &port, dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
/* interpet value after colon as port */
*colon = '\0';
colon++;
- if (1 == SSCANF (colon, "%u%1s", &port, dummy))
+ if (1 == sscanf (colon, "%u%1s", &port, dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
GNUNET_i2s (&queue->target),
(int) sent,
(unsigned int) msg_size,
- (sent < 0) ? STRERROR (errno) : "ok");
+ (sent < 0) ? strerror (errno) : "ok");
if (-1 != sent)
{
GNUNET_STATISTICS_update (stats,
if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ||
(sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) )
{
- FPRINTF (stderr, "%s", "Received malformed message\n");
+ fprintf (stderr, "%s", "Received malformed message\n");
exit (1);
}
payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2)
{
- FPRINTF (stderr, "%s", "Packet too big for buffer\n");
+ fprintf (stderr, "%s", "Packet too big for buffer\n");
exit (1);
}
memset (&newheader, 0, sizeof (newheader));
sendsize = ntohs (hdr->size);
if ((sendsize + write_std->size) > MAXLINE * 2)
{
- FPRINTF (stderr, "%s", "Packet too big for buffer\n");
+ fprintf (stderr, "%s", "Packet too big for buffer\n");
exit (1);
}
GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize);
if ( (2 != argc) ||
((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) )
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"This program must be started with the operating mode (1 or 2) as the only argument.\n");
return 1;
if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
(GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) )
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Failed to create directory for file `%s'\n",
FIFO_FILE1);
return 1;
{
erg = mkfifo (FIFO_FILE1, 0666);
if ( (0 != erg) && (EEXIST != errno) )
- FPRINTF (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1,
+ fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1,
strerror (errno));
}
}
{
GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666)));
if ( (0 != erg) && (EEXIST != errno) )
- FPRINTF (stderr,
+ fprintf (stderr,
"Error in mkfifo(%s): %s\n",
FIFO_FILE2,
strerror (errno));
fpin = fopen (FIFO_FILE1, "r");
if (NULL == fpin)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"fopen of read FIFO_FILE1 failed: %s\n",
STRERROR (errno));
goto end;
}
if (NULL == fpout)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"fopen of write FIFO_FILE2 failed: %s\n",
STRERROR (errno));
goto end;
}
if (NULL == fpout)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"fopen of write FIFO_FILE1 failed: %s\n",
STRERROR (errno));
goto end;
fpin = fopen (FIFO_FILE2, "r");
if (NULL == fpin)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"fopen of read FIFO_FILE2 failed: %s\n",
STRERROR (errno));
goto end;
GNUNET_assert (fpin >= 0);
if (fdpin >= FD_SETSIZE)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"File fdpin number too large (%d > %u)\n",
fdpin,
(unsigned int) FD_SETSIZE);
if (fdpout >= FD_SETSIZE)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"File fdpout number too large (%d > %u)\n",
fdpout,
(unsigned int) FD_SETSIZE);
continue;
if (0 > retval)
{
- FPRINTF (stderr, "select failed: %s\n", STRERROR (errno));
+ fprintf (stderr, "select failed: %s\n", STRERROR (errno));
closeprog = 1;
break;
}
if (0 > ret)
{
closeprog = 1;
- FPRINTF (stderr, "Write ERROR to STDOUT_FILENO: %s\n",
+ fprintf (stderr, "Write ERROR to STDOUT_FILENO: %s\n",
STRERROR (errno));
break;
}
if (0 > ret)
{
closeprog = 1;
- FPRINTF (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno));
+ fprintf (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno));
}
else
{
if (0 > readsize)
{
closeprog = 1;
- FPRINTF (stderr, "Error reading from STDIN_FILENO: %s\n",
+ fprintf (stderr, "Error reading from STDIN_FILENO: %s\n",
STRERROR (errno));
}
else if (0 < readsize)
if (0 > readsize)
{
closeprog = 1;
- FPRINTF (stderr, "Error reading from fdpin: %s\n", STRERROR (errno));
+ fprintf (stderr, "Error reading from fdpin: %s\n", STRERROR (errno));
break;
}
else if (0 < readsize)
}
if (verbosity > 0)
- FPRINTF (stdout, "\n");
+ fprintf (stdout, "\n");
/* Output format:
* All time values in ms
icur->rate = ((benchmark_count * benchmark_size) / 1024) /
((float) icur->dur.rel_value_us / (1000 * 1000));
if (verbosity > 0)
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("%llu B in %llu ms == %.2f KB/s!\n"),
((long long unsigned int) benchmark_count * benchmark_size),
((long long unsigned int) icur->dur.rel_value_us / 1000),
stddev_duration = sqrtf (stddev_duration);
/* Output */
- FPRINTF (stdout,
+ fprintf (stdout,
"%u;%u;%llu;%llu;%.2f;%.2f",
benchmark_count,
benchmark_size,
inext = icur->next;
GNUNET_CONTAINER_DLL_remove (ihead, itail, icur);
- FPRINTF (stdout,
+ fprintf (stdout,
";%llu;%.2f",
(long long unsigned int) (icur->dur.rel_value_us / 1000),
icur->rate);
if (benchmark_receive)
{
duration = GNUNET_TIME_absolute_get_duration (start_time);
- FPRINTF (stdout,
+ fprintf (stdout,
"Received %llu bytes/s (%llu bytes in %s)\n",
1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
traffic_received,
GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
}
#endif
- FPRINTF (stdout, "\n");
+ fprintf (stdout, "\n");
}
}
GNUNET_MQ_send (mq, env);
if ((verbosity > 0) && (0 == itail->msgs_sent % 10))
- FPRINTF (stdout, ".");
+ fprintf (stdout, ".");
}
GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur);
icur->start = GNUNET_TIME_absolute_get ();
if (verbosity > 0)
- FPRINTF (
+ fprintf (
stdout,
"\nStarting benchmark, starting to send %u messages in %u byte blocks\n",
benchmark_count,
{
if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
{
- FPRINTF (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid));
+ fprintf (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid));
return NULL;
}
if (verbosity > 0)
- FPRINTF (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid));
+ fprintf (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid));
mq = m;
iteration_start ();
return NULL;
mq = NULL;
if (GNUNET_YES == benchmark_running)
{
- FPRINTF (stdout,
+ fprintf (stdout,
"Disconnected from peer `%s' while benchmarking\n",
GNUNET_i2s (&pid));
return;
if (! benchmark_receive)
return;
if (verbosity > 0)
- FPRINTF (stdout,
+ fprintf (stdout,
"Received %u bytes\n",
(unsigned int) ntohs (message->size));
}
if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
{
if (verbosity > 0)
- FPRINTF (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer));
+ fprintf (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer));
return GNUNET_SYSERR;
}
return GNUNET_OK;
ret = 1;
if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size)
{
- FPRINTF (stderr, "Message size too big!\n");
+ fprintf (stderr, "Message size too big!\n");
return;
}
if (NULL == cpid)
{
- FPRINTF (stderr, "No peer identity given\n");
+ fprintf (stderr, "No peer identity given\n");
return;
}
if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid,
strlen (cpid),
&pid.public_key))
{
- FPRINTF (stderr, "Failed to parse peer identity `%s'\n", cpid);
+ fprintf (stderr, "Failed to parse peer identity `%s'\n", cpid);
return;
}
if (1 == benchmark_send)
{
if (verbosity > 0)
- FPRINTF (stderr,
+ fprintf (stderr,
"Trying to send %u messages with size %u to peer `%s'\n",
benchmark_count,
benchmark_size,
}
else if (1 == benchmark_receive)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Trying to receive messages from peer `%s'\n",
GNUNET_i2s (&pid));
}
else
{
- FPRINTF (stderr, "No operation given\n");
+ fprintf (stderr, "No operation given\n");
return;
}
ats = GNUNET_ATS_connectivity_init (cfg);
if (NULL == ats)
{
- FPRINTF (stderr, "Failed to connect to ATS service\n");
+ fprintf (stderr, "Failed to connect to ATS service\n");
ret = 1;
return;
}
NULL);
if (NULL == handle)
{
- FPRINTF (stderr, "Failed to connect to transport service\n");
+ fprintf (stderr, "Failed to connect to transport service\n");
GNUNET_ATS_connectivity_done (ats);
ats = NULL;
ret = 1;
if (benchmark_send)
{
duration = GNUNET_TIME_absolute_get_duration (start_time);
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
traffic_sent,
if (benchmark_receive)
{
duration = GNUNET_TIME_absolute_get_duration (start_time);
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Received %llu bytes/s (%llu bytes in %s)\n"),
1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
traffic_received,
op_timeout = NULL;
if ((benchmark_send) || (benchmark_receive))
{
- FPRINTF (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
+ fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
GNUNET_SCHEDULER_shutdown ();
ret = 1;
return;
while (NULL != (cur = next))
{
next = cur->next;
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Failed to resolve address for peer `%s'\n"),
GNUNET_i2s (&cur->addrcp->peer));
GNUNET_free (cur->addrcp);
GNUNET_free (cur);
}
- FPRINTF (stdout,
+ fprintf (stdout,
"%s",
_ ("Failed to list connections, timeout occurred\n"));
GNUNET_SCHEDULER_shutdown ();
traffic_sent += BLOCKSIZE * 1024;
GNUNET_MQ_notify_sent (env, &do_send, mq);
if (verbosity > 0)
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Transmitting %u bytes\n"),
(unsigned int) BLOCKSIZE * 1024);
GNUNET_MQ_send (mq, env);
op_timeout = NULL;
}
if (verbosity > 0)
- FPRINTF (
+ fprintf (
stdout,
_ (
"Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
return; /* not about target peer */
if (! benchmark_send)
return; /* not transmitting */
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Disconnected from peer `%s' while benchmarking\n"),
GNUNET_i2s (&pid));
}
const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
monitor_connect_counter++;
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("%24s: %-17s %4s (%u connections in total)\n"),
now_str,
_ ("Connected to"),
GNUNET_assert (monitor_connect_counter > 0);
monitor_connect_counter--;
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("%24s: %-17s %4s (%u connections in total)\n"),
now_str,
_ ("Disconnected from"),
if (! benchmark_receive)
return;
if (verbosity > 0)
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Received %u bytes\n"),
(unsigned int) ntohs (message->size));
if (0 == traffic_received)
if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) ||
(GNUNET_YES == monitor_connections))
{
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Peer `%s': %s %s in state `%s' until %s\n"),
GNUNET_i2s (id),
(NULL == transport) ? "<none>" : transport,
(GNUNET_TRANSPORT_is_connected (state)))
{
/* Only connected peers, skip state */
- FPRINTF (stdout,
+ fprintf (stdout,
_ ("Peer `%s': %s %s\n"),
GNUNET_i2s (id),
transport,
{
if (GNUNET_SYSERR == res)
{
- FPRINTF (
+ fprintf (
stderr,
"Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
GNUNET_i2s (&rc->addrcp->peer),
if (NULL == peer)
{
- FPRINTF (stdout,
+ fprintf (stdout,
"%s",
_ (
"Monitor disconnected from transport service. Reconnecting.\n"));
if (1 < counter)
{
- FPRINTF (
+ fprintf (
stderr,
_ (
"Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
}
if (0 == counter)
{
- FPRINTF (
+ fprintf (
stderr,
_ (
"No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
{
if (0 == memcmp (&zero_pid, &pid, sizeof (pid)))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Option `%s' makes no sense without option `%s'.\n"),
"-D",
"-p");
blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
if (NULL == blacklist)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
_ (
"Failed to connect to transport service for disconnection\n"));
ret = 1;
return;
}
- FPRINTF (stdout,
+ fprintf (stdout,
"%s",
_ ("Blacklisting request in place, stop with CTRL-C\n"));
}
{
if (0 == memcmp (&zero_pid, &pid, sizeof (pid)))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Option `%s' makes no sense without option `%s'.\n"),
"-s",
"-p");
NULL);
if (NULL == handle)
{
- FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n"));
+ fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
ret = 1;
return;
}
NULL);
if (NULL == handle)
{
- FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n"));
+ fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
ret = 1;
return;
}
if (verbosity > 0)
- FPRINTF (stdout, "%s", _ ("Starting to receive benchmark data\n"));
+ fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n"));
start_time = GNUNET_TIME_absolute_get ();
}
else if (iterate_connections) /* -i: List information about peers once */
NULL);
if (NULL == handle)
{
- FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n"));
+ fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
ret = 1;
return;
}
stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)"));
}
GNUNET_GC_get_configuration_value_filename (core_api->cfg, "SMTP", "PIPE", &pipename);
- UNLINK (pipename);
+ unlink (pipename);
if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
{
GNUNET_GE_LOG_STRERROR (ectx,
}
GNUNET_mutex_destroy (lock);
lock = NULL;
- UNLINK (pipename);
+ unlink (pipename);
GNUNET_free (pipename);
pipename = NULL;
GNUNET_free (email);
#include "gnunet_transport_plugin.h"
#include "transport.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "transport-tcp",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "transport-tcp", __VA_ARGS__)
#define PLUGIN_NAME "tcp"
LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv);
-
/**
* Function called to notify a client about the connection begin ready
* to queue more data. @a buf will be NULL and @a size zero if the
* @param buf where the callee should write the message
* @return number of bytes written to @a buf
*/
-typedef size_t
-(*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls,
- size_t size,
- void *buf);
+typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls,
+ size_t size,
+ void *buf);
/**
* Credentials for UNIX domain sockets.
* @param client identification of the client; NULL
* for the last call when the server is destroyed
*/
-typedef void
-(*GNUNET_SERVER_DisconnectCallback) (void *cls,
- struct GNUNET_SERVER_Client *client);
+typedef void (*GNUNET_SERVER_DisconnectCallback) (
+ void *cls,
+ struct GNUNET_SERVER_Client *client);
/**
* @param cls closure
* @param client identification of the client
*/
-typedef void
-(*GNUNET_SERVER_ConnectCallback) (void *cls,
- struct GNUNET_SERVER_Client *client);
-
-
+typedef void (*GNUNET_SERVER_ConnectCallback) (
+ void *cls,
+ struct GNUNET_SERVER_Client *client);
/**
* @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR
* for unknown address family (will be denied).
*/
-typedef int
-(*GNUNET_CONNECTION_AccessCheck) (void *cls,
- const struct
- GNUNET_CONNECTION_Credentials *
- ucred,
- const struct sockaddr * addr,
- socklen_t addrlen);
+typedef int (*GNUNET_CONNECTION_AccessCheck) (
+ void *cls,
+ const struct GNUNET_CONNECTION_Credentials *ucred,
+ const struct sockaddr *addr,
+ socklen_t addrlen);
/**
* Callback function for data received from the network. Note that
* @param addrlen size of addr
* @param errCode value of errno (on errors receiving)
*/
-typedef void
-(*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf,
- size_t available,
- const struct sockaddr * addr,
- socklen_t addrlen, int errCode);
-
+typedef void (*GNUNET_CONNECTION_Receiver) (void *cls,
+ const void *buf,
+ size_t available,
+ const struct sockaddr *addr,
+ socklen_t addrlen,
+ int errCode);
/**
* @param client handle to client the tokenzier will be used for
* @return handle to custom tokenizer ('mst')
*/
-typedef void*
-(*GNUNET_SERVER_MstCreateCallback) (void *cls,
- struct GNUNET_SERVER_Client *client);
+typedef void *(*GNUNET_SERVER_MstCreateCallback) (
+ void *cls,
+ struct GNUNET_SERVER_Client *client);
/**
* @param cls closure from #GNUNET_SERVER_set_callbacks
* @param mst custom tokenizer handle
*/
-typedef void
-(*GNUNET_SERVER_MstDestroyCallback) (void *cls,
- void *mst);
+typedef void (*GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst);
/**
* Signature of a function to receive data for a custom tokenizer.
* #GNUNET_NO if one_shot was set and we have another message ready
* #GNUNET_SYSERR if the data stream is corrupt
*/
-typedef int
-(*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst,
- struct GNUNET_SERVER_Client *client,
- const char *buf,
- size_t size,
- int purge,
- int one_shot);
+typedef int (*GNUNET_SERVER_MstReceiveCallback) (
+ void *cls,
+ void *mst,
+ struct GNUNET_SERVER_Client *client,
+ const char *buf,
+ size_t size,
+ int purge,
+ int one_shot);
/**
* Functions with this signature are called whenever a message is
* received.
* @param client identification of the client
* @param message the actual message
*/
-typedef void
-(*GNUNET_SERVER_MessageCallback) (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message);
+typedef void (*GNUNET_SERVER_MessageCallback) (
+ void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message);
/**
* Message handler. Each struct specifies how to handle on particular
* if they do not have the right size.
*/
uint16_t expected_size;
-
};
};
-
/**
* Ask the server to disconnect from the given client. This is the
* same as passing #GNUNET_SYSERR to #GNUNET_SERVER_receive_done,
* @param message the actual message
* @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
*/
-typedef int
-(*GNUNET_SERVER_MessageTokenizerCallback) (void *cls,
- void *client,
- const struct GNUNET_MessageHeader *message);
+typedef int (*GNUNET_SERVER_MessageTokenizerCallback) (
+ void *cls,
+ void *client,
+ const struct GNUNET_MessageHeader *message);
/**
int
GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
void *client_identity,
- const char *buf, size_t size,
- int purge, int one_shot);
-
+ const char *buf,
+ size_t size,
+ int purge,
+ int one_shot);
/**
* @param type expected return type (i.e. 'struct Foo')
* @return pointer to user context of type 'type *'.
*/
-#define GNUNET_SERVER_client_get_user_context(client,type) \
+#define GNUNET_SERVER_client_get_user_context(client, type) \
(type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type))
/**
* @param client client to query
* @param value pointer to user context
*/
-#define GNUNET_SERVER_client_set_user_context(client,value) \
+#define GNUNET_SERVER_client_set_user_context(client, value) \
GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value))
-
/**
* Notify us when the server has enough space to transmit
* a message of the given size to the given client.
* NULL if we are already going to notify someone else (busy)
*/
struct GNUNET_SERVER_TransmitHandle *
-GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
- size_t size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_TransmitReadyNotify callback,
- void *callback_cls);
+GNUNET_SERVER_notify_transmit_ready (
+ struct GNUNET_SERVER_Client *client,
+ size_t size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CONNECTION_TransmitReadyNotify callback,
+ void *callback_cls);
/**
* Abort transmission request.
* @param th request to abort
*/
void
-GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th);
-
-
+GNUNET_SERVER_notify_transmit_ready_cancel (
+ struct GNUNET_SERVER_TransmitHandle *th);
/**
* @param server the initialized server
* @param cfg configuration to use
*/
-typedef void
-(*LEGACY_SERVICE_Main) (void *cls,
- struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *cfg);
-
+typedef void (*LEGACY_SERVICE_Main) (
+ void *cls,
+ struct GNUNET_SERVER_Handle *server,
+ const struct GNUNET_CONFIGURATION_Handle *cfg);
/**
* NULL if we are already going to notify someone else (busy)
*/
struct GNUNET_SERVER_TransmitHandle *
-GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
- size_t size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_TransmitReadyNotify callback,
- void *callback_cls);
+GNUNET_SERVER_notify_transmit_ready (
+ struct GNUNET_SERVER_Client *client,
+ size_t size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CONNECTION_TransmitReadyNotify callback,
+ void *callback_cls);
/**
GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server);
-
-
#include "tcp_connection_legacy.c"
#include "tcp_server_mst_legacy.c"
#include "tcp_server_legacy.c"
* Identity of the node connecting (TCP client)
*/
struct GNUNET_PeerIdentity clientIdentity;
-
};
/**
* Identity of the sender of the message.
*/
struct GNUNET_PeerIdentity clientIdentity;
-
};
GNUNET_NETWORK_STRUCT_END
* Port number, in network byte order.
*/
uint16_t t4_port GNUNET_PACKED;
-
};
/**
* Port number, in network byte order.
*/
uint16_t t6_port GNUNET_PACKED;
-
};
GNUNET_NETWORK_STRUCT_END
* instead of just a `struct GNUNET_MessageHeader`.
*/
size_t message_size;
-
};
/**
* Was this session created using NAT traversal?
*/
int is_nat;
-
};
* rest of the world.
*/
uint16_t adv_port;
-
};
*/
static int
get_server_addresses (const char *service_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct sockaddr ***addrs,
- socklen_t ** addr_lens)
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct sockaddr ***addrs,
+ socklen_t **addr_lens)
{
int disablev6;
struct GNUNET_NETWORK_Handle *desc;
if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
{
if (GNUNET_SYSERR ==
- (disablev6 =
- GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
+ (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ service_name,
+ "DISABLEV6")))
return GNUNET_SYSERR;
}
else
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
- service_name, STRERROR (errno));
+ _ (
+ "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
+ service_name,
+ strerror (errno));
disablev6 = GNUNET_YES;
}
else
port = 0;
if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, service_name,
- "PORT", &port))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ service_name,
+ "PORT",
+ &port))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
}
if (port > 65535)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
return GNUNET_SYSERR;
}
if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
{
GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, service_name,
- "BINDTO", &hostname));
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ service_name,
+ "BINDTO",
+ &hostname));
}
else
hostname = NULL;
#ifdef AF_UNIX
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH",
- &unixpath)) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
+ service_name,
+ "UNIXPATH",
+ &unixpath)) &&
(0 < strlen (unixpath)))
{
/* probe UNIX support */
if (strlen (unixpath) >= sizeof (s_un.sun_path))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
+ _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
+ unixpath,
(unsigned long long) sizeof (s_un.sun_path));
unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Using `%s' instead\n"),
- unixpath);
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
}
#ifdef LINUX
abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
if (GNUNET_SYSERR == abstract)
abstract = GNUNET_NO;
#endif
- if ((GNUNET_YES != abstract)
- && (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (unixpath)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "mkdir",
- unixpath);
+ if ((GNUNET_YES != abstract) &&
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
}
if (NULL != unixpath)
{
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
+ _ (
+ "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
service_name,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (unixpath);
unixpath = NULL;
}
if ((0 == port) && (NULL == unixpath))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
+ _ (
+ "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
service_name);
GNUNET_free_non_null (hostname);
return GNUNET_SYSERR;
(NULL == res))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to resolve `%s': %s\n"),
+ _ ("Failed to resolve `%s': %s\n"),
hostname,
gai_strerror (ret));
GNUNET_free (hostname);
if (0 == i)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to find %saddress for `%s'.\n"),
+ _ ("Failed to find %saddress for `%s'.\n"),
disablev6 ? "IPv4 " : "",
hostname);
freeaddrinfo (res);
if ((disablev6) && (AF_INET6 == pos->ai_family))
continue;
if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
- continue; /* not TCP */
+ continue; /* not TCP */
if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
- continue; /* huh? */
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
- service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
+ continue; /* huh? */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' will bind to `%s'\n",
+ service_name,
+ GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
if (AF_INET == pos->ai_family)
{
GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
return;
memset (&info, 0, sizeof (info));
info.state = state;
- info.is_inbound = GNUNET_HELLO_address_check_option (session->address,
- GNUNET_HELLO_ADDRESS_INFO_INBOUND);
+ info.is_inbound =
+ GNUNET_HELLO_address_check_option (session->address,
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND);
info.num_msg_pending = session->msgs_in_queue;
info.num_bytes_pending = session->bytes_in_queue;
if (NULL != session->receive_delay_task)
info.receive_delay = session->receive_delay;
info.session_timeout = session->timeout;
info.address = session->address;
- plugin->sic (plugin->sic_cls,
- session,
- &info);
+ plugin->sic (plugin->sic_cls, session, &info);
}
*/
static void
tcp_nat_port_map_callback (void *cls,
- void **app_ctx,
+ void **app_ctx,
int add_remove,
- enum GNUNET_NAT_AddressClass ac,
- const struct sockaddr *addr,
+ enum GNUNET_NAT_AddressClass ac,
+ const struct sockaddr *addr,
socklen_t addrlen)
{
struct Plugin *plugin = cls;
switch (addr->sa_family)
{
case AF_INET:
- GNUNET_assert(addrlen == sizeof(struct sockaddr_in));
- memset (&t4, 0, sizeof(t4));
+ GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
+ memset (&t4, 0, sizeof (t4));
t4.options = htonl (plugin->myoptions);
t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
t4.t4_port = ((struct sockaddr_in *) addr)->sin_port;
#tcp_plugin_check_address() */
return;
}
- GNUNET_assert(addrlen == sizeof(struct sockaddr_in6));
- memset (&t6, 0, sizeof(t6));
+ GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
+ memset (&t6, 0, sizeof (t6));
GNUNET_memcpy (&t6.ipv6_addr,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
- sizeof(struct in6_addr));
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
t6.options = htonl (plugin->myoptions);
t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
arg = &t6;
args = sizeof (t6);
break;
default:
- GNUNET_break(0);
+ GNUNET_break (0);
return;
}
/* modify our published address list */
GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) ||
- (args == sizeof (struct IPv6TcpAddress)));
+ (args == sizeof (struct IPv6TcpAddress)));
/* TODO: use 'ac' here in the future... */
address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
- PLUGIN_NAME,
- arg,
- args,
- GNUNET_HELLO_ADDRESS_INFO_NONE);
- plugin->env->notify_address (plugin->env->cls,
- add_remove,
- address);
+ PLUGIN_NAME,
+ arg,
+ args,
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
+ plugin->env->notify_address (plugin->env->cls, add_remove, address);
GNUNET_HELLO_address_free (address);
}
* @return string representing the same address
*/
static const char *
-tcp_plugin_address_to_string (void *cls,
- const void *addr,
- size_t addrlen)
+tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
{
static char rbuf[INET6_ADDRSTRLEN + 12];
char buf[INET6_ADDRSTRLEN];
switch (addrlen)
{
- case sizeof(struct IPv6TcpAddress):
+ case sizeof (struct IPv6TcpAddress):
t6 = addr;
af = AF_INET6;
port = ntohs (t6->t6_port);
options = ntohl (t6->options);
- GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof(a6));
+ GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
sb = &a6;
break;
- case sizeof(struct IPv4TcpAddress):
+ case sizeof (struct IPv4TcpAddress):
t4 = addr;
af = AF_INET;
port = ntohs (t4->t4_port);
options = ntohl (t4->options);
- GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof(a4));
+ GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
sb = &a4;
break;
default:
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Unexpected address length: %u bytes\n"),
+ _ ("Unexpected address length: %u bytes\n"),
(unsigned int) addrlen);
- return NULL ;
+ return NULL;
}
if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "inet_ntop");
- return NULL ;
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+ return NULL;
}
- GNUNET_snprintf (rbuf, sizeof(rbuf),
+ GNUNET_snprintf (rbuf,
+ sizeof (rbuf),
(af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
PLUGIN_NAME,
options,
optionstr = NULL;
if ((NULL == addr) || (0 == addrlen))
{
- GNUNET_break(0);
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
if ('\0' != addr[addrlen - 1])
{
- GNUNET_break(0);
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
if (strlen (addr) != addrlen - 1)
{
- GNUNET_break(0);
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
plugin = GNUNET_strdup (addr);
optionstr = strchr (plugin, '.');
if (NULL == optionstr)
{
- GNUNET_break(0);
- GNUNET_free(plugin);
+ GNUNET_break (0);
+ GNUNET_free (plugin);
return GNUNET_SYSERR;
}
optionstr[0] = '\0';
address = strchr (optionstr, '.');
if (NULL == address)
{
- GNUNET_break(0);
- GNUNET_free(plugin);
+ GNUNET_break (0);
+ GNUNET_free (plugin);
return GNUNET_SYSERR;
}
address[0] = '\0';
address++;
if (GNUNET_OK !=
- GNUNET_STRINGS_to_address_ip (address,
- strlen (address),
- &socket_address))
+ GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address))
{
- GNUNET_break(0);
- GNUNET_free(plugin);
+ GNUNET_break (0);
+ GNUNET_free (plugin);
return GNUNET_SYSERR;
}
- GNUNET_free(plugin);
+ GNUNET_free (plugin);
switch (socket_address.ss_family)
{
- case AF_INET:
- {
+ case AF_INET: {
struct IPv4TcpAddress *t4;
struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address;
t4 = GNUNET_new (struct IPv4TcpAddress);
t4->ipv4_addr = in4->sin_addr.s_addr;
t4->t4_port = in4->sin_port;
*buf = t4;
- *added = sizeof(struct IPv4TcpAddress);
+ *added = sizeof (struct IPv4TcpAddress);
return GNUNET_OK;
}
- case AF_INET6:
- {
+ case AF_INET6: {
struct IPv6TcpAddress *t6;
struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address;
t6 = GNUNET_new (struct IPv6TcpAddress);
t6->ipv6_addr = in6->sin6_addr;
t6->t6_port = in6->sin6_port;
*buf = t6;
- *added = sizeof(struct IPv6TcpAddress);
+ *added = sizeof (struct IPv6TcpAddress);
return GNUNET_OK;
}
default:
* @return #GNUNET_OK on success
*/
static int
-tcp_plugin_disconnect_session (void *cls,
- struct GNUNET_ATS_Session *session)
+tcp_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *session)
{
struct Plugin *plugin = cls;
struct PendingMessage *pm;
session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
}
- if (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap,
- &session->target,
- session))
+ if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap,
+ &session->target,
+ session))
{
GNUNET_STATISTICS_update (session->plugin->env->stats,
- gettext_noop ("# TCP sessions active"),
- -1,
- GNUNET_NO);
+ gettext_noop ("# TCP sessions active"),
+ -1,
+ GNUNET_NO);
}
else
{
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
- &session->target,
- session));
+ GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
+ &session->target,
+ session));
}
if (NULL != session->client)
- GNUNET_SERVER_client_set_user_context (session->client,
- NULL);
+ GNUNET_SERVER_client_set_user_context (session->client, NULL);
/* clean up state */
if (NULL != session->transmit_handle)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
(NULL != pm->transmit_cont)
- ? "Could not deliver message to `%s' at %s.\n"
- : "Could not deliver message to `%s' at %s, notifying.\n",
+ ? "Could not deliver message to `%s' at %s.\n"
+ : "Could not deliver message to `%s' at %s, notifying.\n",
GNUNET_i2s (&session->target),
tcp_plugin_address_to_string (session->plugin,
session->address->address,
session->address->address_length));
GNUNET_STATISTICS_update (session->plugin->env->stats,
gettext_noop ("# bytes currently in TCP buffers"),
- -(int64_t) pm->message_size, GNUNET_NO);
+ -(int64_t) pm->message_size,
+ GNUNET_NO);
GNUNET_STATISTICS_update (session->plugin->env->stats,
- gettext_noop ("# bytes discarded by TCP (disconnect)"),
+ gettext_noop (
+ "# bytes discarded by TCP (disconnect)"),
pm->message_size,
GNUNET_NO);
GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
}
GNUNET_assert (0 == session->msgs_in_queue);
GNUNET_assert (0 == session->bytes_in_queue);
- notify_session_monitor (session->plugin,
- session,
- GNUNET_TRANSPORT_SS_DONE);
+ notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_DONE);
if (NULL != session->receive_delay_task)
{
{
/* not actually our turn yet, but let's at least update
the monitor, it may think we're about to die ... */
- notify_session_monitor (s->plugin,
- s,
- GNUNET_TRANSPORT_SS_UPDATE);
- s->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
- &session_timeout,
- s);
+ notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
+ s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s);
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p was idle for %s, disconnecting\n",
s,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ GNUNET_YES));
/* call session destroy function */
- tcp_plugin_disconnect_session (s->plugin,
- s);
+ tcp_plugin_disconnect_session (s->plugin, s);
}
reschedule_session_timeout (struct GNUNET_ATS_Session *s)
{
GNUNET_assert (NULL != s->timeout_task);
- s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ s->timeout =
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
}
if (NULL != client)
{
session->client = client;
- GNUNET_SERVER_client_set_user_context (client,
- session);
+ GNUNET_SERVER_client_set_user_context (client, session);
}
session->address = GNUNET_HELLO_address_copy (address);
session->target = address->peer;
session->expecting_welcome = GNUNET_YES;
session->scope = scope;
pm = GNUNET_malloc (sizeof (struct PendingMessage) +
- sizeof (struct WelcomeMessage));
+ sizeof (struct WelcomeMessage));
pm->msg = (const char *) &pm[1];
- pm->message_size = sizeof(struct WelcomeMessage);
- GNUNET_memcpy (&pm[1],
- &plugin->my_welcome,
- sizeof(struct WelcomeMessage));
+ pm->message_size = sizeof (struct WelcomeMessage);
+ GNUNET_memcpy (&pm[1], &plugin->my_welcome, sizeof (struct WelcomeMessage));
pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
GNUNET_STATISTICS_update (plugin->env->stats,
gettext_noop ("# bytes currently in TCP buffers"),
- pm->message_size,
+ pm->message_size,
GNUNET_NO);
GNUNET_CONTAINER_DLL_insert (session->pending_messages_head,
session->pending_messages_tail,
pm);
session->msgs_in_queue++;
session->bytes_in_queue += pm->message_size;
- session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- &session_timeout,
- session);
- notify_session_monitor (session->plugin,
- session,
- GNUNET_TRANSPORT_SS_INIT);
+ session->timeout =
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ session->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &session_timeout,
+ session);
+ notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_INIT);
if (GNUNET_YES != is_nat)
{
GNUNET_STATISTICS_update (plugin->env->stats,
gettext_noop ("# TCP sessions active"),
1,
GNUNET_NO);
- notify_session_monitor (session->plugin,
- session,
- GNUNET_TRANSPORT_SS_UP);
+ notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UP);
}
else
{
* @return number of bytes written to @a buf
*/
static size_t
-do_transmit (void *cls,
- size_t size,
- void *buf)
+do_transmit (void *cls, size_t size, void *buf)
{
struct GNUNET_ATS_Session *session = cls;
struct GNUNET_PeerIdentity pid;
tl = NULL;
ret = 0;
now = GNUNET_TIME_absolute_get ();
- while ( (NULL != (pos = session->pending_messages_head)) &&
- (pos->timeout.abs_value_us <= now.abs_value_us) )
+ while ((NULL != (pos = session->pending_messages_head)) &&
+ (pos->timeout.abs_value_us <= now.abs_value_us))
{
GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
session->pending_messages_tail,
pos->message_size,
GNUNET_i2s (&session->target));
ret += pos->message_size;
- GNUNET_CONTAINER_DLL_insert_after (hd,
- tl,
- tl,
- pos);
+ GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
}
/* do this call before callbacks (so that if callbacks destroy
* session, they have a chance to cancel actions done by this
* the callbacks may abort the session */
while (NULL != (pos = hd))
{
- GNUNET_CONTAINER_DLL_remove (hd,
- tl,
- pos);
+ GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
if (NULL != pos->transmit_cont)
pos->transmit_cont (pos->transmit_cont_cls,
&pid,
GNUNET_free (pos);
}
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) ret,
+ gettext_noop ("# bytes currently in TCP buffers"),
+ -(int64_t) ret,
GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes discarded by TCP (timeout)"),
+ gettext_noop (
+ "# bytes discarded by TCP (timeout)"),
ret,
GNUNET_NO);
if (0 < ret)
session->msgs_in_queue--;
GNUNET_assert (pos->message_size <= session->bytes_in_queue);
session->bytes_in_queue -= pos->message_size;
- GNUNET_assert(size >= pos->message_size);
+ GNUNET_assert (size >= pos->message_size);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting message of type %u size %u to peer %s at %s\n",
ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type),
session->address->address,
session->address->address_length));
/* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */
- GNUNET_memcpy (cbuf,
- pos->msg,
- pos->message_size);
+ GNUNET_memcpy (cbuf, pos->msg, pos->message_size);
cbuf += pos->message_size;
ret += pos->message_size;
size -= pos->message_size;
- GNUNET_CONTAINER_DLL_insert_tail (hd,
- tl,
- pos);
+ GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos);
}
- notify_session_monitor (session->plugin,
- session,
- GNUNET_TRANSPORT_SS_UPDATE);
+ notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
/* schedule 'continuation' before callbacks so that callbacks that
* cancel everything don't cause us to use a session that no longer
* exists... */
GNUNET_assert (NULL == tl);
GNUNET_STATISTICS_update (plugin->env->stats,
gettext_noop ("# bytes currently in TCP buffers"),
- - (int64_t) ret,
+ -(int64_t) ret,
GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
gettext_noop ("# bytes transmitted via TCP"),
if (NULL == (pm = session->pending_messages_head))
return;
- session->transmit_handle
- = GNUNET_SERVER_notify_transmit_ready (session->client,
- pm->message_size,
- GNUNET_TIME_absolute_get_remaining (pm->timeout),
- &do_transmit,
- session);
+ session->transmit_handle =
+ GNUNET_SERVER_notify_transmit_ready (session->client,
+ pm->message_size,
+ GNUNET_TIME_absolute_get_remaining (
+ pm->timeout),
+ &do_transmit,
+ session);
}
GNUNET_TRANSPORT_TransmitContinuation cont,
void *cont_cls)
{
- struct Plugin * plugin = cls;
+ struct Plugin *plugin = cls;
struct PendingMessage *pm;
/* create new message entry */
"This NAT WAIT session for peer `%s' is not yet ready!\n",
GNUNET_i2s (&session->target));
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size,
+ gettext_noop ("# bytes currently in TCP buffers"),
+ msgbuf_size,
GNUNET_NO);
/* append pm to pending_messages list */
GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
GNUNET_TRANSPORT_SS_HANDSHAKE);
return msgbuf_size;
}
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Invalid session %p\n",
- session);
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session);
if (NULL != cont)
- cont (cont_cls,
- &session->target,
- GNUNET_SYSERR,
- pm->message_size,
- 0);
+ cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0);
GNUNET_break (0);
GNUNET_free (pm);
return GNUNET_SYSERR; /* session does not exist here */
* Where to store the session (if we found it).
*/
struct GNUNET_ATS_Session *result;
-
};
struct GNUNET_ATS_SessionItCtx *si_ctx = cls;
struct GNUNET_ATS_Session *session = value;
- if (0 !=
- GNUNET_HELLO_address_cmp (si_ctx->address,
- session->address))
+ if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address))
return GNUNET_YES;
si_ctx->result = session;
return GNUNET_NO;
tcp_plugin_address_to_string (session->plugin,
session->address->address,
session->address->address_length));
- tcp_plugin_disconnect_session (session->plugin,
- session);
+ tcp_plugin_disconnect_session (session->plugin, session);
}
session->receive_delay_task = NULL;
reschedule_session_timeout (session);
- GNUNET_SERVER_receive_done (session->client,
- GNUNET_OK);
+ GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
}
return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"New inbound delay %s\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_NO));
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO));
session->receive_delay = GNUNET_TIME_relative_to_absolute (delay);
GNUNET_SCHEDULER_cancel (session->receive_delay_task);
- session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
- &delayed_done,
- session);
+ session->receive_delay_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
}
* @return the session if the address is valid, NULL otherwise
*/
static struct GNUNET_ATS_Session *
-tcp_plugin_get_session (void *cls,
- const struct GNUNET_HELLO_Address *address)
+tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
{
struct Plugin *plugin = cls;
struct GNUNET_ATS_Session *session = NULL;
}
/* look for existing session */
- if (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap,
- &address->peer))
+ if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap,
+ &address->peer))
{
struct GNUNET_ATS_SessionItCtx si_ctx;
GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap,
&address->peer,
&session_lookup_it,
- &si_ctx);
+ &si_ctx);
if (NULL != si_ctx.result)
{
session = si_ctx.result;
peer pair at the same time. */
}
- if (addrlen == sizeof(struct IPv6TcpAddress))
+ if (addrlen == sizeof (struct IPv6TcpAddress))
{
GNUNET_assert (NULL != address->address); /* make static analysis happy */
t6 = address->address;
options = t6->options;
af = AF_INET6;
- memset (&a6, 0, sizeof(a6));
+ memset (&a6, 0, sizeof (a6));
#if HAVE_SOCKADDR_IN_SIN_LEN
a6.sin6_len = sizeof (a6);
#endif
a6.sin6_port = t6->t6_port;
if (t6->t6_port == 0)
is_natd = GNUNET_YES;
- GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
+ GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
sb = &a6;
- sbs = sizeof(a6);
+ sbs = sizeof (a6);
}
- else if (addrlen == sizeof(struct IPv4TcpAddress))
+ else if (addrlen == sizeof (struct IPv4TcpAddress))
{
- GNUNET_assert(NULL != address->address); /* make static analysis happy */
+ GNUNET_assert (NULL != address->address); /* make static analysis happy */
t4 = address->address;
options = t4->options;
af = AF_INET;
- memset (&a4, 0, sizeof(a4));
+ memset (&a4, 0, sizeof (a4));
#if HAVE_SOCKADDR_IN_SIN_LEN
a4.sin_len = sizeof (a4);
#endif
is_natd = GNUNET_YES;
a4.sin_addr.s_addr = t4->ipv4_addr;
sb = &a4;
- sbs = sizeof(a4);
+ sbs = sizeof (a4);
}
else
{
- GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# requests to create session with invalid address"),
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ plugin->env->stats,
+ gettext_noop ("# requests to create session with invalid address"),
+ 1,
+ GNUNET_NO);
return NULL;
}
- net_type = plugin->env->get_address_type (plugin->env->cls,
- sb,
- sbs);
+ net_type = plugin->env->get_address_type (plugin->env->cls, sb, sbs);
GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED);
- if ( (is_natd == GNUNET_YES) &&
- (addrlen == sizeof(struct IPv6TcpAddress)) )
+ if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress)))
{
/* NAT client only works with IPv4 addresses */
return NULL;
return NULL;
}
- if ( (is_natd == GNUNET_YES) &&
- (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
- &address->peer)))
+ if ((is_natd == GNUNET_YES) &&
+ (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
+ &address->peer)))
{
/* Only do one NAT punch attempt per peer identity */
return NULL;
}
- if ( (is_natd == GNUNET_YES) &&
- (NULL != plugin->nat) &&
- (GNUNET_NO ==
- GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
- &address->peer)))
+ if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
+ (GNUNET_NO ==
+ GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns,
+ &address->peer)))
{
struct sockaddr_in local_sa;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Found valid IPv4 NAT address (creating session)!\n");
- session = create_session (plugin,
- address,
- net_type,
- NULL,
- GNUNET_YES);
- session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT,
- &nat_connect_timeout,
- session);
+ session = create_session (plugin, address, net_type, NULL, GNUNET_YES);
+ session->nat_connection_timeout =
+ GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, &nat_connect_timeout, session);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns,
- &session->target,
- session,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multipeermap_put (
+ plugin->nat_wait_conns,
+ &session->target,
+ session,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Created NAT WAIT connection to `%s' at `%s'\n",
GNUNET_i2s (&session->target),
GNUNET_a2s (sb, sbs));
- memset (&local_sa,
- 0,
- sizeof (local_sa));
+ memset (&local_sa, 0, sizeof (local_sa));
local_sa.sin_family = AF_INET;
local_sa.sin_port = htons (plugin->open_port);
/* We leave sin_address at 0, let the kernel figure it out,
even if our bind() is more specific. (May want to reconsider
later.) */
- if (GNUNET_OK ==
- GNUNET_NAT_request_reversal (plugin->nat,
- &local_sa,
- &a4))
+ if (GNUNET_OK == GNUNET_NAT_request_reversal (plugin->nat, &local_sa, &a4))
return session;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Running NAT client for `%s' at `%s' failed\n",
- GNUNET_i2s (&session->target),
- GNUNET_a2s (sb, sbs));
- tcp_plugin_disconnect_session (plugin,
- session);
+ "Running NAT client for `%s' at `%s' failed\n",
+ GNUNET_i2s (&session->target),
+ GNUNET_a2s (sb, sbs));
+ tcp_plugin_disconnect_session (plugin, session);
return NULL;
}
}
else
{
- if ( (GNUNET_OK !=
- GNUNET_NETWORK_socket_setsockopt (s,
- IPPROTO_TCP,
- TCP_STEALTH,
- &session->target,
- sizeof (struct GNUNET_PeerIdentity))) ||
- (GNUNET_OK !=
- GNUNET_NETWORK_socket_setsockopt (s,
- IPPROTO_TCP,
- TCP_STEALTH_INTEGRITY,
- &plugin->my_welcome,
- sizeof (struct WelcomeMessage))) )
+ if ((GNUNET_OK !=
+ GNUNET_NETWORK_socket_setsockopt (s,
+ IPPROTO_TCP,
+ TCP_STEALTH,
+ &session->target,
+ sizeof (
+ struct GNUNET_PeerIdentity))) ||
+ (GNUNET_OK !=
+ GNUNET_NETWORK_socket_setsockopt (s,
+ IPPROTO_TCP,
+ TCP_STEALTH_INTEGRITY,
+ &plugin->my_welcome,
+ sizeof (struct WelcomeMessage))))
{
/* TCP STEALTH not supported by kernel */
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (s));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
sa = NULL;
}
else
session = create_session (plugin,
address,
net_type,
- GNUNET_SERVER_connect_socket (plugin->server,
- sa),
+ GNUNET_SERVER_connect_socket (plugin->server, sa),
GNUNET_NO);
- (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap,
- &session->target,
- session,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ (void) GNUNET_CONTAINER_multipeermap_put (
+ plugin->sessionmap,
+ &session->target,
+ session,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
/* Send TCP Welcome */
process_pending_messages (session);
struct GNUNET_ATS_Session *session = value;
GNUNET_STATISTICS_update (session->plugin->env->stats,
- gettext_noop ("# transport-service disconnect requests for TCP"),
+ gettext_noop (
+ "# transport-service disconnect requests for TCP"),
1,
GNUNET_NO);
- tcp_plugin_disconnect_session (plugin,
- session);
+ tcp_plugin_disconnect_session (plugin, session);
return GNUNET_YES;
}
* to be cancelled
*/
static void
-tcp_plugin_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *target)
+tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
{
struct Plugin *plugin = cls;
* @param hostname hostname part of the address
*/
static void
-append_port (void *cls,
- const char *hostname)
+append_port (void *cls, const char *hostname)
{
struct PrettyPrinterContext *ppc = cls;
struct Plugin *plugin = ppc->plugin;
GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head,
plugin->ppc_dll_tail,
ppc);
- ppc->asc (ppc->asc_cls,
- NULL,
- GNUNET_OK);
+ ppc->asc (ppc->asc_cls, NULL, GNUNET_OK);
GNUNET_free (ppc);
return;
}
ppc->options,
hostname,
ppc->port);
- ppc->asc (ppc->asc_cls,
- ret,
- GNUNET_OK);
+ ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
GNUNET_free (ret);
}
uint16_t port;
uint32_t options;
- if (sizeof(struct IPv6TcpAddress) == addrlen)
+ if (sizeof (struct IPv6TcpAddress) == addrlen)
{
t6 = addr;
- memset (&a6, 0, sizeof(a6));
+ memset (&a6, 0, sizeof (a6));
a6.sin6_family = AF_INET6;
a6.sin6_port = t6->t6_port;
- GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
+ GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
port = ntohs (t6->t6_port);
options = ntohl (t6->options);
sb = &a6;
- sbs = sizeof(a6);
+ sbs = sizeof (a6);
}
- else if (sizeof(struct IPv4TcpAddress) == addrlen)
+ else if (sizeof (struct IPv4TcpAddress) == addrlen)
{
t4 = addr;
- memset (&a4, 0, sizeof(a4));
+ memset (&a4, 0, sizeof (a4));
a4.sin_family = AF_INET;
a4.sin_port = t4->t4_port;
a4.sin_addr.s_addr = t4->ipv4_addr;
port = ntohs (t4->t4_port);
options = ntohl (t4->options);
sb = &a4;
- sbs = sizeof(a4);
+ sbs = sizeof (a4);
}
else
{
/* invalid address */
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Unexpected address length: %u bytes\n"),
+ _ ("Unexpected address length: %u bytes\n"),
(unsigned int) addrlen);
asc (asc_cls, NULL, GNUNET_SYSERR);
asc (asc_cls, NULL, GNUNET_OK);
}
ppc = GNUNET_new (struct PrettyPrinterContext);
ppc->plugin = plugin;
- if (addrlen == sizeof(struct IPv6TcpAddress))
+ if (addrlen == sizeof (struct IPv6TcpAddress))
ppc->ipv6 = GNUNET_YES;
else
ppc->ipv6 = GNUNET_NO;
ppc->asc_cls = asc_cls;
ppc->port = port;
ppc->options = options;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting DNS reverse lookup\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n");
ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
sbs,
! numeric,
timeout,
&append_port,
- ppc);
+ ppc);
if (NULL == ppc->resolver_handle)
{
GNUNET_break (0);
GNUNET_free (ppc);
return;
}
- GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head,
- plugin->ppc_dll_tail,
- ppc);
+ GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
}
* and transport, #GNUNET_SYSERR if not
*/
static int
-tcp_plugin_check_address (void *cls,
- const void *addr,
- size_t addrlen)
+tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
{
struct Plugin *plugin = cls;
const struct IPv4TcpAddress *v4;
const struct IPv6TcpAddress *v6;
- if ( (addrlen != sizeof(struct IPv4TcpAddress)) &&
- (addrlen != sizeof(struct IPv6TcpAddress)) )
+ if ((addrlen != sizeof (struct IPv4TcpAddress)) &&
+ (addrlen != sizeof (struct IPv6TcpAddress)))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (addrlen == sizeof(struct IPv4TcpAddress))
+ if (addrlen == sizeof (struct IPv4TcpAddress))
{
struct sockaddr_in s4;
v4 = (const struct IPv4TcpAddress *) addr;
- if (0 != memcmp (&v4->options,
- &plugin->myoptions,
- sizeof(uint32_t)))
+ if (0 != memcmp (&v4->options, &plugin->myoptions, sizeof (uint32_t)))
{
GNUNET_break (0);
return GNUNET_SYSERR;
s4.sin_addr.s_addr = v4->ipv4_addr;
if (GNUNET_OK !=
- GNUNET_NAT_test_address (plugin->nat,
- &s4,
- sizeof (struct sockaddr_in)))
+ GNUNET_NAT_test_address (plugin->nat, &s4, sizeof (struct sockaddr_in)))
return GNUNET_SYSERR;
}
else
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (0 != memcmp (&v6->options,
- &plugin->myoptions,
- sizeof (uint32_t)))
+ if (0 != memcmp (&v6->options, &plugin->myoptions, sizeof (uint32_t)))
{
GNUNET_break (0);
return GNUNET_SYSERR;
s6.sin6_port = v6->t6_port;
s6.sin6_addr = v6->ipv6_addr;
- if (GNUNET_OK !=
- GNUNET_NAT_test_address (plugin->nat,
- &s6,
- sizeof(struct sockaddr_in6)))
+ if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat,
+ &s6,
+ sizeof (struct sockaddr_in6)))
return GNUNET_SYSERR;
}
return GNUNET_OK;
const struct sockaddr_in *s4;
const struct sockaddr_in6 *s6;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received NAT probe\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n");
/* We have received a TCP NAT probe, meaning we (hopefully) initiated
* a connection to this peer by running gnunet-nat-client. This peer
* received the punch message and now wants us to use the new connection
* as the default for that peer. Do so and then send a WELCOME message
* so we can really be connected!
*/
- if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage))
+ if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage))
{
- GNUNET_break_op(0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message;
- if (0 == memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity,
- sizeof(struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&tcp_nat_probe->clientIdentity,
+ plugin->env->my_identity,
+ sizeof (struct GNUNET_PeerIdentity)))
{
/* refuse connections from ourselves */
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
&tcp_nat_probe->clientIdentity);
if (NULL == session)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Did NOT find session for NAT probe!\n");
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n");
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Found session for NAT probe!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n");
if (NULL != session->nat_connection_timeout)
{
session->nat_connection_timeout = NULL;
}
- if (GNUNET_OK !=
- GNUNET_SERVER_client_get_address (client,
- &vaddr,
- &alen))
+ if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
- GNUNET_break(0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- tcp_plugin_disconnect_session (plugin,
- session);
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ tcp_plugin_disconnect_session (plugin, session);
return;
}
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
- &tcp_nat_probe->clientIdentity,
- session));
- GNUNET_SERVER_client_set_user_context (client,
- session);
- (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap,
- &session->target,
- session,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
+ &tcp_nat_probe->clientIdentity,
+ session));
+ GNUNET_SERVER_client_set_user_context (client, session);
+ (void) GNUNET_CONTAINER_multipeermap_put (
+ plugin->sessionmap,
+ &session->target,
+ session,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
session->last_activity = GNUNET_TIME_absolute_get ();
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Found address `%s' for incoming connection\n",
t4->options = htonl (TCP_OPTIONS_NONE);
t4->t4_port = s4->sin_port;
t4->ipv4_addr = s4->sin_addr.s_addr;
- session->address = GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity,
- PLUGIN_NAME,
- &t4,
- sizeof(struct IPv4TcpAddress),
- GNUNET_HELLO_ADDRESS_INFO_NONE);
+ session->address =
+ GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity,
+ PLUGIN_NAME,
+ &t4,
+ sizeof (struct IPv4TcpAddress),
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
break;
case AF_INET6:
s6 = vaddr;
t6 = GNUNET_new (struct IPv6TcpAddress);
t6->options = htonl (TCP_OPTIONS_NONE);
t6->t6_port = s6->sin6_port;
- GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
- session->address = GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity,
- PLUGIN_NAME,
- &t6,
- sizeof(struct IPv6TcpAddress),
- GNUNET_HELLO_ADDRESS_INFO_NONE);
+ GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
+ session->address =
+ GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity,
+ PLUGIN_NAME,
+ &t6,
+ sizeof (struct IPv6TcpAddress),
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
break;
default:
- GNUNET_break_op(0);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Bad address for incoming connection!\n");
- GNUNET_free(vaddr);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- tcp_plugin_disconnect_session (plugin,
- session);
+ GNUNET_break_op (0);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n");
+ GNUNET_free (vaddr);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ tcp_plugin_disconnect_session (plugin, session);
return;
}
GNUNET_free (vaddr);
GNUNET_break (NULL == session->client);
session->client = client;
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# TCP sessions active"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# TCP sessions active"),
+ 1,
+ GNUNET_NO);
process_pending_messages (session);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
if (0 == memcmp (&wm->clientIdentity,
plugin->env->my_identity,
- sizeof(struct GNUNET_PeerIdentity)))
+ sizeof (struct GNUNET_PeerIdentity)))
{
/* refuse connections from ourselves */
- if (GNUNET_OK ==
- GNUNET_SERVER_client_get_address (client,
- &vaddr,
- &alen))
+ if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
LOG (GNUNET_ERROR_TYPE_INFO,
"Received WELCOME message from my own identity `%s' on address `%s'\n",
GNUNET_a2s (vaddr, alen));
GNUNET_free (vaddr);
}
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- if (GNUNET_OK ==
- GNUNET_SERVER_client_get_address (client,
- &vaddr,
- &alen))
+ if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received WELCOME message from `%s' on address `%s'\n",
- GNUNET_i2s (&wm->clientIdentity),
- GNUNET_a2s (vaddr, alen));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received WELCOME message from `%s' on address `%s'\n",
+ GNUNET_i2s (&wm->clientIdentity),
+ GNUNET_a2s (vaddr, alen));
GNUNET_free (vaddr);
}
GNUNET_STATISTICS_update (plugin->env->stats,
gettext_noop ("# TCP WELCOME messages received"),
1,
GNUNET_NO);
- session = lookup_session_by_client (plugin,
- client);
+ session = lookup_session_by_client (plugin, client);
if (NULL != session)
{
- if (GNUNET_OK ==
- GNUNET_SERVER_client_get_address (client,
- &vaddr,
- &alen))
+ if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Found existing session %p for peer `%s'\n",
}
else
{
- if (GNUNET_OK ==
- GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
+ if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
{
- if (alen == sizeof(struct sockaddr_in))
+ if (alen == sizeof (struct sockaddr_in))
{
s4 = vaddr;
memset (&t4, '\0', sizeof (t4));
t4.options = htonl (TCP_OPTIONS_NONE);
t4.t4_port = s4->sin_port;
t4.ipv4_addr = s4->sin_addr.s_addr;
- address = GNUNET_HELLO_address_allocate (&wm->clientIdentity,
- PLUGIN_NAME,
- &t4,
- sizeof(t4),
- GNUNET_HELLO_ADDRESS_INFO_INBOUND);
+ address =
+ GNUNET_HELLO_address_allocate (&wm->clientIdentity,
+ PLUGIN_NAME,
+ &t4,
+ sizeof (t4),
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND);
}
- else if (alen == sizeof(struct sockaddr_in6))
+ else if (alen == sizeof (struct sockaddr_in6))
{
s6 = vaddr;
memset (&t6, '\0', sizeof (t6));
t6.options = htonl (TCP_OPTIONS_NONE);
t6.t6_port = s6->sin6_port;
- GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
- address = GNUNET_HELLO_address_allocate (&wm->clientIdentity,
- PLUGIN_NAME,
- &t6,
- sizeof (t6),
- GNUNET_HELLO_ADDRESS_INFO_INBOUND);
+ GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
+ address =
+ GNUNET_HELLO_address_allocate (&wm->clientIdentity,
+ PLUGIN_NAME,
+ &t6,
+ sizeof (t6),
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND);
}
else
{
GNUNET_break (0);
GNUNET_free_non_null (vaddr);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
session = create_session (plugin,
"Creating new%s session %p for peer `%s' client %p\n",
GNUNET_HELLO_address_check_option (session->address,
GNUNET_HELLO_ADDRESS_INFO_INBOUND)
- ? " inbound" : "",
+ ? " inbound"
+ : "",
session,
tcp_plugin_address_to_string (plugin,
session->address->address,
session->address->address_length),
client);
GNUNET_free (vaddr);
- (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap,
- &session->target,
- session,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ (void) GNUNET_CONTAINER_multipeermap_put (
+ plugin->sessionmap,
+ &session->target,
+ session,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
/* Notify transport and ATS about new session */
plugin->env->session_start (plugin->env->cls,
session->address,
}
else
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Did not obtain TCP socket address for incoming connection\n");
- GNUNET_break(0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Did not obtain TCP socket address for incoming connection\n");
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
}
if (GNUNET_YES != session->expecting_welcome)
{
GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
session->last_activity = GNUNET_TIME_absolute_get ();
process_pending_messages (session);
GNUNET_SERVER_client_set_timeout (client,
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
uint16_t type;
type = ntohs (message->type);
- if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
- (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type) )
+ if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
+ (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type))
{
/* We don't want to propagate WELCOME and NAT Probe messages up! */
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
session = lookup_session_by_client (plugin, client);
size_t alen;
GNUNET_assert (GNUNET_OK ==
- GNUNET_SERVER_client_get_address (client,
- &vaddr,
- &alen));
+ GNUNET_SERVER_client_get_address (client, &vaddr, &alen));
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received unexpected %u bytes of type %u from `%s'\n",
(unsigned int) ntohs (message->size),
(unsigned int) ntohs (message->type),
- GNUNET_a2s (vaddr,
- alen));
- GNUNET_break_op(0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
+ GNUNET_a2s (vaddr, alen));
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
GNUNET_free_non_null (vaddr);
return;
}
void *vaddr = NULL;
size_t alen;
- GNUNET_SERVER_client_get_address (client,
- &vaddr,
- &alen);
+ GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received unexpected %u bytes of type %u from `%s'\n",
(unsigned int) ntohs (message->size),
(unsigned int) ntohs (message->type),
GNUNET_a2s (vaddr, alen));
- GNUNET_break_op(0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
+ GNUNET_break_op (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
GNUNET_free_non_null (vaddr);
return;
}
void *vaddr = NULL;
size_t alen;
- GNUNET_SERVER_client_get_address (client,
- &vaddr,
- &alen);
+ GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Passing %u bytes of type %u from `%s' at %s to transport service.\n",
(unsigned int) ntohs (message->size),
ntohs (message->size),
GNUNET_NO);
- GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
- &session->target,
- session));
- delay = plugin->env->receive (plugin->env->cls,
- session->address,
- session,
- message);
+ GNUNET_assert (
+ GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
+ &session->target,
+ session));
+ delay =
+ plugin->env->receive (plugin->env->cls, session->address, session, message);
reschedule_session_timeout (session);
if (0 == delay.rel_value_us)
{
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Throttling receiving from `%s' for %s\n",
GNUNET_i2s (&session->target),
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
GNUNET_SERVER_disable_receive_done_warning (client);
GNUNET_assert (NULL == session->receive_delay_task);
- session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
- &delayed_done,
- session);
+ session->receive_delay_task =
+ GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
}
}
* @param client identification of the client
*/
static void
-connect_notify (void *cls,
- struct GNUNET_SERVER_Client *client)
+connect_notify (void *cls, struct GNUNET_SERVER_Client *client)
{
struct Plugin *plugin = cls;
plugin->cur_connections,
GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# TCP server connect events"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# TCP server connect events"),
+ 1,
+ GNUNET_NO);
if (plugin->cur_connections != plugin->max_connections)
return;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("TCP connection limit reached, suspending server\n"));
+ _ ("TCP connection limit reached, suspending server\n"));
GNUNET_STATISTICS_update (plugin->env->stats,
- gettext_noop ("# TCP service suspended"),
- 1,
- GNUNET_NO);
- GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */
+ gettext_noop ("# TCP service suspended"),
+ 1,
+ GNUNET_NO);
+ GNUNET_SERVER_suspend (
+ plugin->server); /* Maximum number of connections rechead */
}
* @param client identification of the client
*/
static void
-disconnect_notify (void *cls,
- struct GNUNET_SERVER_Client *client)
+disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
{
struct Plugin *plugin = cls;
struct GNUNET_ATS_Session *session;
return;
GNUNET_assert (plugin->cur_connections >= 1);
plugin->cur_connections--;
- session = lookup_session_by_client (plugin,
- client);
+ session = lookup_session_by_client (plugin, client);
if (NULL == session)
return; /* unknown, nothing to do */
LOG (GNUNET_ERROR_TYPE_DEBUG,
plugin->cur_connections,
GNUNET_NO);
GNUNET_STATISTICS_update (session->plugin->env->stats,
- gettext_noop ("# network-level TCP disconnect events"),
+ gettext_noop (
+ "# network-level TCP disconnect events"),
1,
GNUNET_NO);
- tcp_plugin_disconnect_session (plugin,
- session);
+ tcp_plugin_disconnect_session (plugin, session);
}
* @return number of bytes copied into @a buf
*/
static size_t
-notify_send_probe (void *cls,
- size_t size,
- void *buf)
+notify_send_probe (void *cls, size_t size, void *buf)
{
struct TCPProbeContext *tcp_probe_ctx = cls;
struct Plugin *plugin = tcp_probe_ctx->plugin;
if (NULL == buf)
{
GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock);
- GNUNET_free(tcp_probe_ctx);
+ GNUNET_free (tcp_probe_ctx);
return 0;
}
- GNUNET_assert(size >= sizeof(tcp_probe_ctx->message));
- GNUNET_memcpy (buf,
- &tcp_probe_ctx->message,
- sizeof(tcp_probe_ctx->message));
+ GNUNET_assert (size >= sizeof (tcp_probe_ctx->message));
+ GNUNET_memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message));
GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server,
tcp_probe_ctx->sock);
- ret = sizeof(tcp_probe_ctx->message);
+ ret = sizeof (tcp_probe_ctx->message);
GNUNET_free (tcp_probe_ctx);
return ret;
}
* We have received an ICMP response, ostensibly from a peer
* that wants to connect to us! Send a message to establish a connection.
*/
- sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET,
- addr,
- addrlen);
+ sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
if (NULL == sock)
{
/* failed for some odd reason (out of sockets?); ignore attempt */
}
tcp_probe_ctx = GNUNET_new (struct TCPProbeContext);
- tcp_probe_ctx->message.header.size
- = htons (sizeof (struct TCP_NAT_ProbeMessage));
- tcp_probe_ctx->message.header.type
- = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
- tcp_probe_ctx->message.clientIdentity
- = *plugin->env->my_identity;
+ tcp_probe_ctx->message.header.size =
+ htons (sizeof (struct TCP_NAT_ProbeMessage));
+ tcp_probe_ctx->message.header.type =
+ htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
+ tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity;
tcp_probe_ctx->plugin = plugin;
tcp_probe_ctx->sock = sock;
GNUNET_CONTAINER_DLL_insert (plugin->probe_head,
plugin->probe_tail,
tcp_probe_ctx);
- tcp_probe_ctx->transmit_handle
- = GNUNET_CONNECTION_notify_transmit_ready (sock,
- ntohs (tcp_probe_ctx->message.header.size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- ¬ify_send_probe,
- tcp_probe_ctx);
+ tcp_probe_ctx->transmit_handle =
+ GNUNET_CONNECTION_notify_transmit_ready (sock,
+ ntohs (tcp_probe_ctx->message
+ .header.size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ ¬ify_send_probe,
+ tcp_probe_ctx);
}
* @return the network type in HBO or #GNUNET_SYSERR
*/
static enum GNUNET_NetworkType
-tcp_plugin_get_network (void *cls,
- struct GNUNET_ATS_Session *session)
+tcp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
{
return session->scope;
}
size_t sbs;
addrlen = address->address_length;
- if (addrlen == sizeof(struct IPv6TcpAddress))
+ if (addrlen == sizeof (struct IPv6TcpAddress))
{
GNUNET_assert (NULL != address->address); /* make static analysis happy */
t6 = address->address;
- memset (&a6, 0, sizeof(a6));
+ memset (&a6, 0, sizeof (a6));
#if HAVE_SOCKADDR_IN_SIN_LEN
a6.sin6_len = sizeof (a6);
#endif
a6.sin6_family = AF_INET6;
a6.sin6_port = t6->t6_port;
- GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
+ GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
sb = &a6;
- sbs = sizeof(a6);
+ sbs = sizeof (a6);
}
- else if (addrlen == sizeof(struct IPv4TcpAddress))
+ else if (addrlen == sizeof (struct IPv4TcpAddress))
{
GNUNET_assert (NULL != address->address); /* make static analysis happy */
t4 = address->address;
- memset (&a4, 0, sizeof(a4));
+ memset (&a4, 0, sizeof (a4));
#if HAVE_SOCKADDR_IN_SIN_LEN
a4.sin_len = sizeof (a4);
#endif
a4.sin_port = t4->t4_port;
a4.sin_addr.s_addr = t4->ipv4_addr;
sb = &a4;
- sbs = sizeof(a4);
+ sbs = sizeof (a4);
}
else
{
GNUNET_break (0);
return GNUNET_NT_UNSPECIFIED;
}
- return plugin->env->get_address_type (plugin->env->cls,
- sb,
- sbs);
+ return plugin->env->get_address_type (plugin->env->cls, sb, sbs);
}
struct Plugin *plugin = cls;
struct GNUNET_ATS_Session *session = value;
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_INIT);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
/* FIXME: cannot tell if this is up or not from current
session state... */
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_UP);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
return GNUNET_OK;
}
void *
libgnunet_plugin_transport_tcp_init (void *cls)
{
- static const struct GNUNET_SERVER_MessageHandler my_handlers[] = {
- { &handle_tcp_welcome, NULL,
+ static const struct GNUNET_SERVER_MessageHandler my_handlers[] =
+ {{&handle_tcp_welcome,
+ NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
- sizeof(struct WelcomeMessage) },
- { &handle_tcp_nat_probe, NULL,
+ sizeof (struct WelcomeMessage)},
+ {&handle_tcp_nat_probe,
+ NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
- sizeof(struct TCP_NAT_ProbeMessage) },
- { &handle_tcp_data, NULL,
- GNUNET_MESSAGE_TYPE_ALL, 0 },
- { NULL, NULL, 0, 0 }
- };
+ sizeof (struct TCP_NAT_ProbeMessage)},
+ {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0},
+ {NULL, NULL, 0, 0}};
struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
struct GNUNET_TRANSPORT_PluginFunctions *api;
struct Plugin *plugin;
unsigned int i;
struct GNUNET_TIME_Relative idle_timeout;
#ifdef TCP_STEALTH
- struct GNUNET_NETWORK_Handle *const*lsocks;
+ struct GNUNET_NETWORK_Handle *const *lsocks;
#endif
int ret;
int ret_s;
}
GNUNET_assert (NULL != env->cfg);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-tcp",
- "MAX_CONNECTIONS",
- &max_connections))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-tcp",
+ "MAX_CONNECTIONS",
+ &max_connections))
max_connections = 128;
aport = 0;
- if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
- "PORT", &bport)) ||
+ if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-tcp",
+ "PORT",
+ &bport)) ||
(bport > 65535) ||
- ((GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp",
- "ADVERTISED-PORT", &aport)) &&
- (aport > 65535) ))
+ ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-tcp",
+ "ADVERTISED-PORT",
+ &aport)) &&
+ (aport > 65535)))
{
- LOG(GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
- "transport-tcp");
- return NULL ;
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Require valid port number for service `%s' in configuration!\n"),
+ "transport-tcp");
+ return NULL;
}
if (0 == aport)
aport = bport;
LEGACY_SERVICE_OPTION_NONE);
if (NULL == service)
{
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to start service.\n"));
+ LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to start service.\n"));
return NULL;
}
}
api = NULL;
plugin = GNUNET_new (struct Plugin);
- plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections,
- GNUNET_YES);
+ plugin->sessionmap =
+ GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES);
plugin->max_connections = max_connections;
plugin->open_port = bport;
plugin->adv_port = aport;
plugin->env = env;
- plugin->my_welcome.header.size = htons (sizeof(struct WelcomeMessage));
- plugin->my_welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME);
+ plugin->my_welcome.header.size = htons (sizeof (struct WelcomeMessage));
+ plugin->my_welcome.header.type =
+ htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME);
plugin->my_welcome.clientIdentity = *plugin->env->my_identity;
- if ( (NULL != service) &&
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- "transport-tcp",
- "TCP_STEALTH")) )
+ if ((NULL != service) &&
+ (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "transport-tcp",
+ "TCP_STEALTH")))
{
#ifdef TCP_STEALTH
plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH;
{
uint32_t len = sizeof (struct WelcomeMessage);
- for (i=0;NULL!=lsocks[i];i++)
+ for (i = 0; NULL != lsocks[i]; i++)
{
- if ( (GNUNET_OK !=
- GNUNET_NETWORK_socket_setsockopt (lsocks[i],
- IPPROTO_TCP,
- TCP_STEALTH,
- env->my_identity,
- sizeof (struct GNUNET_PeerIdentity))) ||
- (GNUNET_OK !=
- GNUNET_NETWORK_socket_setsockopt (lsocks[i],
- IPPROTO_TCP,
- TCP_STEALTH_INTEGRITY_LEN,
- &len,
- sizeof (len))) )
+ if (
+ (GNUNET_OK !=
+ GNUNET_NETWORK_socket_setsockopt (lsocks[i],
+ IPPROTO_TCP,
+ TCP_STEALTH,
+ env->my_identity,
+ sizeof (
+ struct GNUNET_PeerIdentity))) ||
+ (GNUNET_OK !=
+ GNUNET_NETWORK_socket_setsockopt (lsocks[i],
+ IPPROTO_TCP,
+ TCP_STEALTH_INTEGRITY_LEN,
+ &len,
+ sizeof (len))))
{
/* TCP STEALTH not supported by kernel */
GNUNET_assert (0 == i);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("TCP_STEALTH not supported on this platform.\n"));
+ _ ("TCP_STEALTH not supported on this platform.\n"));
goto die;
}
}
}
#else
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("TCP_STEALTH not supported on this platform.\n"));
+ _ ("TCP_STEALTH not supported on this platform.\n"));
goto die;
#endif
}
- if ( (NULL != service) &&
- (GNUNET_SYSERR !=
- (ret_s =
- get_server_addresses ("transport-tcp",
- env->cfg,
- &addrs,
- &addrlens))))
+ if ((NULL != service) &&
+ (GNUNET_SYSERR !=
+ (ret_s =
+ get_server_addresses ("transport-tcp", env->cfg, &addrs, &addrlens))))
{
- for (ret = ret_s-1; ret >= 0; ret--)
+ for (ret = ret_s - 1; ret >= 0; ret--)
LOG (GNUNET_ERROR_TYPE_INFO,
"Binding to address `%s'\n",
GNUNET_a2s (addrs[ret], addrlens[ret]));
- plugin->nat
- = GNUNET_NAT_register (env->cfg,
- "transport-tcp",
- IPPROTO_TCP,
- (unsigned int) ret_s,
- (const struct sockaddr **) addrs,
- addrlens,
- &tcp_nat_port_map_callback,
- &try_connection_reversal,
- plugin);
- for (ret = ret_s -1; ret >= 0; ret--)
+ plugin->nat = GNUNET_NAT_register (env->cfg,
+ "transport-tcp",
+ IPPROTO_TCP,
+ (unsigned int) ret_s,
+ (const struct sockaddr **) addrs,
+ addrlens,
+ &tcp_nat_port_map_callback,
+ &try_connection_reversal,
+ plugin);
+ for (ret = ret_s - 1; ret >= 0; ret--)
GNUNET_free (addrs[ret]);
GNUNET_free_non_null (addrs);
GNUNET_free_non_null (addrlens);
{
plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
"transport-tcp",
- IPPROTO_TCP,
+ IPPROTO_TCP,
0,
NULL,
NULL,
}
else
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (env->cfg,
- "transport-tcp",
- "TIMEOUT",
- &idle_timeout))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (env->cfg,
+ "transport-tcp",
+ "TIMEOUT",
+ &idle_timeout))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"transport-tcp",
"TIMEOUT");
goto die;
}
- plugin->server
- = GNUNET_SERVER_create_with_sockets (NULL,
- plugin,
- NULL,
- idle_timeout,
- GNUNET_YES);
+ plugin->server = GNUNET_SERVER_create_with_sockets (NULL,
+ plugin,
+ NULL,
+ idle_timeout,
+ GNUNET_YES);
}
plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
- GNUNET_memcpy (plugin->handlers,
- my_handlers,
- sizeof(my_handlers));
- for (i = 0;i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);i++)
+ GNUNET_memcpy (plugin->handlers, my_handlers, sizeof (my_handlers));
+ for (i = 0;
+ i < sizeof (my_handlers) / sizeof (struct GNUNET_SERVER_MessageHandler);
+ i++)
plugin->handlers[i].callback_cls = plugin;
- GNUNET_SERVER_add_handlers (plugin->server,
- plugin->handlers);
- GNUNET_SERVER_connect_notify (plugin->server,
- &connect_notify,
- plugin);
- GNUNET_SERVER_disconnect_notify (plugin->server,
- &disconnect_notify,
- plugin);
- plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16,
- GNUNET_YES);
+ GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers);
+ GNUNET_SERVER_connect_notify (plugin->server, &connect_notify, plugin);
+ GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
+ plugin->nat_wait_conns =
+ GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
if (0 != bport)
LOG (GNUNET_ERROR_TYPE_INFO,
- _("TCP transport listening on port %llu\n"),
+ _ ("TCP transport listening on port %llu\n"),
bport);
else
LOG (GNUNET_ERROR_TYPE_INFO,
- _("TCP transport not listening on any port (client only)\n"));
- if ( (aport != bport) &&
- (0 != bport) )
+ _ ("TCP transport not listening on any port (client only)\n"));
+ if ((aport != bport) && (0 != bport))
LOG (GNUNET_ERROR_TYPE_INFO,
- _("TCP transport advertises itself as being on port %llu\n"),
+ _ ("TCP transport advertises itself as being on port %llu\n"),
aport);
/* Initially set connections to 0 */
GNUNET_STATISTICS_set (plugin->env->stats,
GNUNET_NO);
return api;
- die:
+die:
if (NULL != plugin->nat)
GNUNET_NAT_unregister (plugin->nat);
GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap);
if (NULL == plugin)
{
- GNUNET_free(api);
- return NULL ;
+ GNUNET_free (api);
+ return NULL;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Shutting down TCP plugin\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n");
/* Removing leftover sessions */
GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap,
plugin->ppc_dll_tail,
cur);
GNUNET_RESOLVER_request_cancel (cur->resolver_handle);
- cur->asc (cur->asc_cls,
- NULL,
- GNUNET_OK);
+ cur->asc (cur->asc_cls, NULL, GNUNET_OK);
GNUNET_free (cur);
}
#include "gnunet_transport_plugin.h"
#include "transport.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
/**
* After how much inactivity should a UDP session time out?
*/
-#define UDP_SESSION_TIME_OUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+#define UDP_SESSION_TIME_OUT \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
/**
* Number of messages we can defragment in parallel. We only really
* What is the identity of the sender
*/
struct GNUNET_PeerIdentity sender;
-
};
* Port to add after the IP address.
*/
uint16_t port;
-
};
};
-
/**
* Data structure to track defragmentation contexts based
* on the source of the UDP traffic.
* Bytes used to send all fragments on wire including UDP overhead
*/
size_t on_wire_size;
-
};
* #GNUNET_SYSERR if the target disconnected
* or we had a timeout or other trouble sending
*/
-typedef void
-(*QueueContinuation) (void *cls,
- struct UDP_MessageWrapper *udpw,
- int result);
+typedef void (*QueueContinuation) (void *cls,
+ struct UDP_MessageWrapper *udpw,
+ int result);
/**
* Payload size of original message.
*/
size_t payload_size;
-
};
* What is the identity of the sender
*/
struct GNUNET_PeerIdentity sender;
-
};
GNUNET_NETWORK_STRUCT_END
return;
if (GNUNET_YES == session->in_destroy)
return; /* already destroyed, just RC>0 left-over actions */
- memset (&info,
- 0,
- sizeof (info));
+ memset (&info, 0, sizeof (info));
info.state = state;
info.is_inbound = GNUNET_SYSERR; /* hard to say */
info.num_msg_pending = session->msgs_in_queue;
to receive from others) */
info.session_timeout = session->timeout;
info.address = session->address;
- plugin->sic (plugin->sic_cls,
- session,
- &info);
+ plugin->sic (plugin->sic_cls, session, &info);
}
struct Plugin *plugin = cls;
struct GNUNET_ATS_Session *session = value;
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_INIT);
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_UP);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
return GNUNET_OK;
}
&send_session_info_iter,
plugin);
/* signal end of first iteration */
- sic (sic_cls,
- NULL,
- NULL);
+ sic (sic_cls, NULL, NULL);
}
}
}
if (NULL != s->frag_ctx)
{
- GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag,
- NULL,
- NULL);
+ GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL);
GNUNET_free (s->frag_ctx);
s->frag_ctx = NULL;
}
* @return the network type
*/
static enum GNUNET_NetworkType
-udp_plugin_get_network (void *cls,
- struct GNUNET_ATS_Session *session)
+udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
{
return session->scope;
}
size_t sbs;
addrlen = address->address_length;
- if (addrlen == sizeof(struct IPv6UdpAddress))
+ if (addrlen == sizeof (struct IPv6UdpAddress))
{
GNUNET_assert (NULL != address->address); /* make static analysis happy */
u6 = address->address;
- memset (&a6, 0, sizeof(a6));
+ memset (&a6, 0, sizeof (a6));
#if HAVE_SOCKADDR_IN_SIN_LEN
a6.sin6_len = sizeof (a6);
#endif
a6.sin6_family = AF_INET6;
a6.sin6_port = u6->u6_port;
- GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr));
+ GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr));
sb = &a6;
- sbs = sizeof(a6);
+ sbs = sizeof (a6);
}
- else if (addrlen == sizeof(struct IPv4UdpAddress))
+ else if (addrlen == sizeof (struct IPv4UdpAddress))
{
GNUNET_assert (NULL != address->address); /* make static analysis happy */
u4 = address->address;
- memset (&a4, 0, sizeof(a4));
+ memset (&a4, 0, sizeof (a4));
#if HAVE_SOCKADDR_IN_SIN_LEN
a4.sin_len = sizeof (a4);
#endif
a4.sin_port = u4->u4_port;
a4.sin_addr.s_addr = u4->ipv4_addr;
sb = &a4;
- sbs = sizeof(a4);
+ sbs = sizeof (a4);
}
else
{
GNUNET_break (0);
return GNUNET_NT_UNSPECIFIED;
}
- return plugin->env->get_address_type (plugin->env->cls,
- sb,
- sbs);
+ return plugin->env->get_address_type (plugin->env->cls, sb, sbs);
}
struct UDP_MessageWrapper *udpw;
struct UDP_MessageWrapper *min_udpw;
- if ( (GNUNET_YES == plugin->enable_ipv4) &&
- (NULL != plugin->sockv4) )
+ if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
{
/* Find a message ready to send:
* Flow delay from other peer is expired or not set (0) */
GNUNET_i2s (&min_udpw->session->target));
}
}
- plugin->select_task_v4
- = GNUNET_SCHEDULER_add_read_net (min_delay,
- plugin->sockv4,
- &udp_plugin_select_v4,
- plugin);
+ plugin->select_task_v4 =
+ GNUNET_SCHEDULER_add_read_net (min_delay,
+ plugin->sockv4,
+ &udp_plugin_select_v4,
+ plugin);
}
}
struct UDP_MessageWrapper *udpw;
struct UDP_MessageWrapper *min_udpw;
- if ( (GNUNET_YES == plugin->enable_ipv6) &&
- (NULL != plugin->sockv6) )
+ if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6))
{
min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
min_udpw = NULL;
GNUNET_i2s (&min_udpw->session->target));
}
}
- plugin->select_task_v6
- = GNUNET_SCHEDULER_add_read_net (min_delay,
- plugin->sockv6,
- &udp_plugin_select_v6,
- plugin);
+ plugin->select_task_v6 =
+ GNUNET_SCHEDULER_add_read_net (min_delay,
+ plugin->sockv6,
+ &udp_plugin_select_v6,
+ plugin);
}
}
* @return string representing the same address
*/
const char *
-udp_address_to_string (void *cls,
- const void *addr,
- size_t addrlen)
+udp_address_to_string (void *cls, const void *addr, size_t addrlen)
{
static char rbuf[INET6_ADDRSTRLEN + 10];
char buf[INET6_ADDRSTRLEN];
return NULL;
}
- if (addrlen == sizeof(struct IPv6UdpAddress))
+ if (addrlen == sizeof (struct IPv6UdpAddress))
{
t6 = addr;
af = AF_INET6;
a6 = t6->ipv6_addr;
sb = &a6;
}
- else if (addrlen == sizeof(struct IPv4UdpAddress))
+ else if (addrlen == sizeof (struct IPv4UdpAddress))
{
t4 = addr;
af = AF_INET;
GNUNET_break_op (0);
return NULL;
}
- inet_ntop (af,
- sb,
- buf,
- INET6_ADDRSTRLEN);
+ inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
GNUNET_snprintf (rbuf,
- sizeof(rbuf),
- (af == AF_INET6)
- ? "%s.%u.[%s]:%u"
- : "%s.%u.%s:%u",
+ sizeof (rbuf),
+ (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
PLUGIN_NAME,
options,
buf,
address++;
if (GNUNET_OK !=
- GNUNET_STRINGS_to_address_ip (address,
- strlen (address),
- &socket_address))
+ GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address))
{
GNUNET_break (0);
GNUNET_free (plugin);
return GNUNET_SYSERR;
}
- GNUNET_free(plugin);
+ GNUNET_free (plugin);
switch (socket_address.ss_family)
{
- case AF_INET:
- {
- struct IPv4UdpAddress *u4;
- const struct sockaddr_in *in4 = (const struct sockaddr_in *) &socket_address;
-
- u4 = GNUNET_new (struct IPv4UdpAddress);
- u4->options = htonl (options);
- u4->ipv4_addr = in4->sin_addr.s_addr;
- u4->u4_port = in4->sin_port;
- *buf = u4;
- *added = sizeof (struct IPv4UdpAddress);
- return GNUNET_OK;
- }
- case AF_INET6:
- {
- struct IPv6UdpAddress *u6;
- const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *) &socket_address;
-
- u6 = GNUNET_new (struct IPv6UdpAddress);
- u6->options = htonl (options);
- u6->ipv6_addr = in6->sin6_addr;
- u6->u6_port = in6->sin6_port;
- *buf = u6;
- *added = sizeof (struct IPv6UdpAddress);
- return GNUNET_OK;
- }
+ case AF_INET: {
+ struct IPv4UdpAddress *u4;
+ const struct sockaddr_in *in4 =
+ (const struct sockaddr_in *) &socket_address;
+
+ u4 = GNUNET_new (struct IPv4UdpAddress);
+ u4->options = htonl (options);
+ u4->ipv4_addr = in4->sin_addr.s_addr;
+ u4->u4_port = in4->sin_port;
+ *buf = u4;
+ *added = sizeof (struct IPv4UdpAddress);
+ return GNUNET_OK;
+ }
+ case AF_INET6: {
+ struct IPv6UdpAddress *u6;
+ const struct sockaddr_in6 *in6 =
+ (const struct sockaddr_in6 *) &socket_address;
+
+ u6 = GNUNET_new (struct IPv6UdpAddress);
+ u6->options = htonl (options);
+ u6->ipv6_addr = in6->sin6_addr;
+ u6->u6_port = in6->sin6_port;
+ *buf = u6;
+ *added = sizeof (struct IPv6UdpAddress);
+ return GNUNET_OK;
+ }
default:
GNUNET_break (0);
return GNUNET_SYSERR;
* @param hostname result from DNS resolver
*/
static void
-append_port (void *cls,
- const char *hostname)
+append_port (void *cls, const char *hostname)
{
struct PrettyPrinterContext *ppc = cls;
struct Plugin *plugin = ppc->plugin;
plugin->ppc_dll_tail,
ppc);
ppc->resolver_handle = NULL;
- ppc->asc (ppc->asc_cls,
- NULL,
- GNUNET_OK);
+ ppc->asc (ppc->asc_cls, NULL, GNUNET_OK);
GNUNET_free (ppc);
return;
}
ppc->options,
hostname,
ppc->port);
- ppc->asc (ppc->asc_cls,
- ret,
- GNUNET_OK);
+ ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
GNUNET_free (ret);
}
uint16_t port;
uint32_t options;
- if (addrlen == sizeof(struct IPv6UdpAddress))
+ if (addrlen == sizeof (struct IPv6UdpAddress))
{
u6 = addr;
- memset (&a6,
- 0,
- sizeof (a6));
+ memset (&a6, 0, sizeof (a6));
a6.sin6_family = AF_INET6;
#if HAVE_SOCKADDR_IN_SIN_LEN
a6.sin6_len = sizeof (a6);
else if (addrlen == sizeof (struct IPv4UdpAddress))
{
u4 = addr;
- memset (&a4,
- 0,
- sizeof(a4));
+ memset (&a4, 0, sizeof (a4));
a4.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
a4.sin_len = sizeof (a4);
port = ntohs (u4->u4_port);
options = ntohl (u4->options);
sb = (const struct sockaddr *) &a4;
- sbs = sizeof(a4);
+ sbs = sizeof (a4);
}
else
{
/* invalid address */
GNUNET_break_op (0);
- asc (asc_cls,
- NULL,
- GNUNET_SYSERR);
- asc (asc_cls,
- NULL,
- GNUNET_OK);
+ asc (asc_cls, NULL, GNUNET_SYSERR);
+ asc (asc_cls, NULL, GNUNET_OK);
return;
}
ppc = GNUNET_new (struct PrettyPrinterContext);
ppc->ipv6 = GNUNET_YES;
else
ppc->ipv6 = GNUNET_NO;
- GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head,
- plugin->ppc_dll_tail,
- ppc);
- ppc->resolver_handle
- = GNUNET_RESOLVER_hostname_get (sb,
- sbs,
- ! numeric,
- timeout,
- &append_port,
- ppc);
+ GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
+ ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
+ sbs,
+ ! numeric,
+ timeout,
+ &append_port,
+ ppc);
}
* @return #GNUNET_OK if port is either our open or advertised port
*/
static int
-check_port (const struct Plugin *plugin,
- uint16_t in_port)
+check_port (const struct Plugin *plugin, uint16_t in_port)
{
- if ( (plugin->port == in_port) ||
- (plugin->aport == in_port) )
+ if ((plugin->port == in_port) || (plugin->aport == in_port))
return GNUNET_OK;
return GNUNET_SYSERR;
}
* and transport, #GNUNET_SYSERR if not
*/
static int
-udp_plugin_check_address (void *cls,
- const void *addr,
- size_t addrlen)
+udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
{
struct Plugin *plugin = cls;
const struct IPv4UdpAddress *v4;
const struct IPv6UdpAddress *v6;
- if (sizeof(struct IPv4UdpAddress) == addrlen)
+ if (sizeof (struct IPv4UdpAddress) == addrlen)
{
struct sockaddr_in s4;
v4 = (const struct IPv4UdpAddress *) addr;
- if (GNUNET_OK != check_port (plugin,
- ntohs (v4->u4_port)))
+ if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port)))
return GNUNET_SYSERR;
memset (&s4, 0, sizeof (s4));
s4.sin_family = AF_INET;
s4.sin_addr.s_addr = v4->ipv4_addr;
if (GNUNET_OK !=
- GNUNET_NAT_test_address (plugin->nat,
- &s4,
- sizeof (struct sockaddr_in)))
+ GNUNET_NAT_test_address (plugin->nat, &s4, sizeof (struct sockaddr_in)))
return GNUNET_SYSERR;
}
- else if (sizeof(struct IPv6UdpAddress) == addrlen)
+ else if (sizeof (struct IPv6UdpAddress) == addrlen)
{
struct sockaddr_in6 s6;
s6.sin6_port = v6->u6_port;
s6.sin6_addr = v6->ipv6_addr;
- if (GNUNET_OK !=
- GNUNET_NAT_test_address (plugin->nat,
- &s6,
- sizeof(struct sockaddr_in6)))
+ if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat,
+ &s6,
+ sizeof (struct sockaddr_in6)))
return GNUNET_SYSERR;
}
else
*/
static void
udp_nat_port_map_callback (void *cls,
- void **app_ctx,
+ void **app_ctx,
int add_remove,
- enum GNUNET_NAT_AddressClass ac,
+ enum GNUNET_NAT_AddressClass ac,
const struct sockaddr *addr,
socklen_t addrlen)
{
(void) app_ctx;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- (GNUNET_YES == add_remove)
- ? "NAT notification to add address `%s'\n"
- : "NAT notification to remove address `%s'\n",
- GNUNET_a2s (addr,
- addrlen));
+ (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n"
+ : "NAT notification to remove address `%s'\n",
+ GNUNET_a2s (addr, addrlen));
/* convert 'address' to our internal format */
switch (addr->sa_family)
{
- case AF_INET:
- {
- const struct sockaddr_in *i4;
-
- GNUNET_assert (sizeof(struct sockaddr_in) == addrlen);
- i4 = (const struct sockaddr_in *) addr;
- if (0 == ntohs (i4->sin_port))
- return; /* Port = 0 means unmapped, ignore these for UDP. */
- memset (&u4,
- 0,
- sizeof(u4));
- u4.options = htonl (plugin->myoptions);
- u4.ipv4_addr = i4->sin_addr.s_addr;
- u4.u4_port = i4->sin_port;
- arg = &u4;
- args = sizeof (struct IPv4UdpAddress);
- break;
- }
- case AF_INET6:
- {
- const struct sockaddr_in6 *i6;
-
- GNUNET_assert (sizeof(struct sockaddr_in6) == addrlen);
- i6 = (const struct sockaddr_in6 *) addr;
- if (0 == ntohs (i6->sin6_port))
- return; /* Port = 0 means unmapped, ignore these for UDP. */
- memset (&u6,
- 0,
- sizeof(u6));
- u6.options = htonl (plugin->myoptions);
- u6.ipv6_addr = i6->sin6_addr;
- u6.u6_port = i6->sin6_port;
- arg = &u6;
- args = sizeof (struct IPv6UdpAddress);
- break;
- }
+ case AF_INET: {
+ const struct sockaddr_in *i4;
+
+ GNUNET_assert (sizeof (struct sockaddr_in) == addrlen);
+ i4 = (const struct sockaddr_in *) addr;
+ if (0 == ntohs (i4->sin_port))
+ return; /* Port = 0 means unmapped, ignore these for UDP. */
+ memset (&u4, 0, sizeof (u4));
+ u4.options = htonl (plugin->myoptions);
+ u4.ipv4_addr = i4->sin_addr.s_addr;
+ u4.u4_port = i4->sin_port;
+ arg = &u4;
+ args = sizeof (struct IPv4UdpAddress);
+ break;
+ }
+ case AF_INET6: {
+ const struct sockaddr_in6 *i6;
+
+ GNUNET_assert (sizeof (struct sockaddr_in6) == addrlen);
+ i6 = (const struct sockaddr_in6 *) addr;
+ if (0 == ntohs (i6->sin6_port))
+ return; /* Port = 0 means unmapped, ignore these for UDP. */
+ memset (&u6, 0, sizeof (u6));
+ u6.options = htonl (plugin->myoptions);
+ u6.ipv6_addr = i6->sin6_addr;
+ u6.u6_port = i6->sin6_port;
+ arg = &u6;
+ args = sizeof (struct IPv6UdpAddress);
+ break;
+ }
default:
GNUNET_break (0);
return;
arg,
args,
GNUNET_HELLO_ADDRESS_INFO_NONE);
- plugin->env->notify_address (plugin->env->cls,
- add_remove,
- address);
+ plugin->env->notify_address (plugin->env->cls, add_remove, address);
GNUNET_HELLO_address_free (address);
}
* @return #GNUNET_NO if we found the session, #GNUNET_OK if not
*/
static int
-session_cmp_it (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
{
struct GNUNET_ATS_SessionCompareContext *cctx = cls;
struct GNUNET_ATS_Session *s = value;
- if (0 == GNUNET_HELLO_address_cmp (s->address,
- cctx->address))
+ if (0 == GNUNET_HELLO_address_cmp (s->address, cctx->address))
{
GNUNET_assert (GNUNET_NO == s->in_destroy);
cctx->res = s;
GNUNET_break (0);
return NULL;
}
- if (sizeof(struct IPv4UdpAddress) == address->address_length)
+ if (sizeof (struct IPv4UdpAddress) == address->address_length)
{
if (NULL == plugin->sockv4)
return NULL;
return NULL;
}
}
- else if (sizeof(struct IPv6UdpAddress) == address->address_length)
+ else if (sizeof (struct IPv6UdpAddress) == address->address_length)
{
if (NULL == plugin->sockv6)
return NULL;
&cctx);
if (NULL == cctx.res)
return NULL;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Found existing session %p\n",
- cctx.res);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res);
return cctx.res;
}
}
-
/**
* Function that will be called whenever the transport service wants to
* notify the plugin that a session is still active and in use and
* @param udpw message wrapper to dequeue
*/
static void
-dequeue (struct Plugin *plugin,
- struct UDP_MessageWrapper *udpw)
+dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
{
struct GNUNET_ATS_Session *session = udpw->session;
{
GNUNET_STATISTICS_update (plugin->env->stats,
"# UDP, total bytes in send buffers",
- - (long long) udpw->msg_size,
+ -(long long) udpw->msg_size,
GNUNET_NO);
plugin->bytes_in_buffer -= udpw->msg_size;
}
"# UDP, total messages in send buffers",
-1,
GNUNET_NO);
- if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
+ if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length)
{
GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head,
plugin->ipv4_queue_tail,
udpw);
}
- else if (sizeof(struct IPv6UdpAddress) == udpw->session->address->address_length)
+ else if (sizeof (struct IPv6UdpAddress) ==
+ udpw->session->address->address_length)
{
GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head,
plugin->ipv6_queue_tail,
* @param udpw message wrapper to queue
*/
static void
-enqueue (struct Plugin *plugin,
- struct UDP_MessageWrapper *udpw)
+enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
{
struct GNUNET_ATS_Session *session = udpw->session;
GNUNET_NO);
if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length)
{
- GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head,
- plugin->ipv4_queue_tail,
- udpw);
+ GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head,
+ plugin->ipv4_queue_tail,
+ udpw);
}
- else if (sizeof (struct IPv6UdpAddress) == udpw->session->address->address_length)
+ else if (sizeof (struct IPv6UdpAddress) ==
+ udpw->session->address->address_length)
{
GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head,
plugin->ipv6_queue_tail,
* #GNUNET_SYSERR if the transmission failed
*/
static void
-fragmented_message_done (struct UDP_FragmentationContext *frag_ctx,
- int result)
+fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result)
{
struct Plugin *plugin = frag_ctx->plugin;
struct GNUNET_ATS_Session *s = frag_ctx->session;
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"Fragmented message acknowledged after %s (expected at %s)\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES),
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time));
}
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Fragmented message acknowledged after %s (expected at %s)\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES),
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time));
}
"# UDP, fragmented msgs, bytes payload, sent, success",
s->frag_ctx->payload_size,
GNUNET_NO);
- GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, bytes overhead, sent, success",
- overhead,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ plugin->env->stats,
+ "# UDP, fragmented msgs, bytes overhead, sent, success",
+ overhead,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
"# UDP, total, bytes overhead, sent",
overhead,
/* Remove remaining fragments from queue, no need to transmit those
any longer. */
- if (s->address->address_length == sizeof(struct IPv6UdpAddress))
+ if (s->address->address_length == sizeof (struct IPv6UdpAddress))
{
udpw = plugin->ipv6_queue_head;
while (NULL != udpw)
{
tmp = udpw->next;
- if ( (udpw->frag_ctx != NULL) &&
- (udpw->frag_ctx == frag_ctx) )
+ if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx))
{
- dequeue (plugin,
- udpw);
- GNUNET_free (udpw);
+ dequeue (plugin, udpw);
+ GNUNET_free (udpw);
}
udpw = tmp;
}
}
- if (s->address->address_length == sizeof(struct IPv4UdpAddress))
+ if (s->address->address_length == sizeof (struct IPv4UdpAddress))
{
udpw = plugin->ipv4_queue_head;
while (NULL != udpw)
{
tmp = udpw->next;
- if ( (NULL != udpw->frag_ctx) &&
- (udpw->frag_ctx == frag_ctx) )
+ if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx))
{
- dequeue (plugin,
- udpw);
+ dequeue (plugin, udpw);
GNUNET_free (udpw);
}
udpw = tmp;
}
}
- notify_session_monitor (s->plugin,
- s,
- GNUNET_TRANSPORT_SS_UPDATE);
+ notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
GNUNET_FRAGMENT_context_destroy (frag_ctx->frag,
&s->last_expected_msg_delay,
&s->last_expected_ack_delay);
* @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
static void
-qc_fragment_sent (void *cls,
- struct UDP_MessageWrapper *udpw,
- int result)
+qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
{
struct Plugin *plugin = cls;
"# UDP, fragmented msgs, fragments, sent, success",
1,
GNUNET_NO);
- GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, fragments bytes, sent, success",
- udpw->msg_size,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ plugin->env->stats,
+ "# UDP, fragmented msgs, fragments bytes, sent, success",
+ udpw->msg_size,
+ GNUNET_NO);
}
else
{
"Failed to transmit fragment of message with %u bytes to %s\n",
(unsigned int) udpw->payload_size,
GNUNET_i2s (&udpw->session->target));
- fragmented_message_done (udpw->frag_ctx,
- GNUNET_SYSERR);
+ fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR);
GNUNET_STATISTICS_update (plugin->env->stats,
"# UDP, fragmented msgs, fragments, sent, failure",
1,
GNUNET_NO);
- GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, fragments bytes, sent, failure",
- udpw->msg_size,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ plugin->env->stats,
+ "# UDP, fragmented msgs, fragments bytes, sent, failure",
+ udpw->msg_size,
+ GNUNET_NO);
}
}
* @param msg the message that was created
*/
static void
-enqueue_fragment (void *cls,
- const struct GNUNET_MessageHeader *msg)
+enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct UDP_FragmentationContext *frag_ctx = cls;
struct Plugin *plugin = frag_ctx->plugin;
struct GNUNET_ATS_Session *session = frag_ctx->session;
size_t msg_len = ntohs (msg->size);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Enqueuing fragment with %u bytes\n",
- msg_len);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len);
udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len);
udpw->session = session;
udpw->msg_buf = (char *) &udpw[1];
udpw->timeout = frag_ctx->timeout;
udpw->start_time = frag_ctx->start_time;
udpw->transmission_time = frag_ctx->next_frag_time;
- frag_ctx->next_frag_time
- = GNUNET_TIME_absolute_add (frag_ctx->next_frag_time,
- frag_ctx->flow_delay_from_other_peer);
+ frag_ctx->next_frag_time =
+ GNUNET_TIME_absolute_add (frag_ctx->next_frag_time,
+ frag_ctx->flow_delay_from_other_peer);
udpw->frag_ctx = frag_ctx;
udpw->qc = &qc_fragment_sent;
udpw->qc_cls = plugin;
- GNUNET_memcpy (udpw->msg_buf,
- msg,
- msg_len);
- enqueue (plugin,
- udpw);
+ GNUNET_memcpy (udpw->msg_buf, msg, msg_len);
+ enqueue (plugin, udpw);
if (session->address->address_length == sizeof (struct IPv4UdpAddress))
schedule_select_v4 (plugin);
else
* @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
static void
-qc_message_sent (void *cls,
- struct UDP_MessageWrapper *udpw,
- int result)
+qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
{
struct Plugin *plugin = cls;
size_t overhead;
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"Message sent via UDP with delay of %s\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
}
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Message sent via UDP with delay of %s\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
}
udpw->cont (udpw->cont_cls,
&udpw->session->target,
"# UDP, unfragmented msgs, messages, sent, success",
1,
GNUNET_NO);
- GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, bytes payload, sent, success",
- udpw->payload_size,
- GNUNET_NO);
- GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, bytes overhead, sent, success",
- overhead,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ plugin->env->stats,
+ "# UDP, unfragmented msgs, bytes payload, sent, success",
+ udpw->payload_size,
+ GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ plugin->env->stats,
+ "# UDP, unfragmented msgs, bytes overhead, sent, success",
+ overhead,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
"# UDP, total, bytes overhead, sent",
overhead,
"# UDP, unfragmented msgs, messages, sent, failure",
1,
GNUNET_NO);
- GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, bytes payload, sent, failure",
- udpw->payload_size,
- GNUNET_NO);
- GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, bytes overhead, sent, failure",
- overhead,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ plugin->env->stats,
+ "# UDP, unfragmented msgs, bytes payload, sent, failure",
+ udpw->payload_size,
+ GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ plugin->env->stats,
+ "# UDP, unfragmented msgs, bytes overhead, sent, failure",
+ overhead,
+ GNUNET_NO);
}
}
void *cont_cls)
{
struct Plugin *plugin = cls;
- size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage);
+ size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage);
struct UDP_FragmentationContext *frag_ctx;
struct UDP_MessageWrapper *udpw;
struct UDPMessage *udp;
char mbuf[udpmlen] GNUNET_ALIGN;
struct GNUNET_TIME_Relative latency;
- if ( (sizeof(struct IPv6UdpAddress) == s->address->address_length) &&
- (NULL == plugin->sockv6) )
+ if ((sizeof (struct IPv6UdpAddress) == s->address->address_length) &&
+ (NULL == plugin->sockv6))
return GNUNET_SYSERR;
- if ( (sizeof(struct IPv4UdpAddress) == s->address->address_length) &&
- (NULL == plugin->sockv4) )
+ if ((sizeof (struct IPv4UdpAddress) == s->address->address_length) &&
+ (NULL == plugin->sockv4))
return GNUNET_SYSERR;
if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE)
{
udpw->start_time = GNUNET_TIME_absolute_get ();
udpw->timeout = GNUNET_TIME_relative_to_absolute (to);
udpw->transmission_time = s->last_transmit_time;
- s->last_transmit_time
- = GNUNET_TIME_absolute_add (s->last_transmit_time,
- s->flow_delay_from_other_peer);
+ s->last_transmit_time =
+ GNUNET_TIME_absolute_add (s->last_transmit_time,
+ s->flow_delay_from_other_peer);
udpw->cont = cont;
udpw->cont_cls = cont_cls;
udpw->frag_ctx = NULL;
udpw->qc = &qc_message_sent;
udpw->qc_cls = plugin;
- GNUNET_memcpy (udpw->msg_buf,
- udp,
- sizeof (struct UDPMessage));
- GNUNET_memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)],
- msgbuf,
- msgbuf_size);
- enqueue (plugin,
- udpw);
+ GNUNET_memcpy (udpw->msg_buf, udp, sizeof (struct UDPMessage));
+ GNUNET_memcpy (&udpw->msg_buf[sizeof (struct UDPMessage)],
+ msgbuf,
+ msgbuf_size);
+ enqueue (plugin, udpw);
GNUNET_STATISTICS_update (plugin->env->stats,
"# UDP, unfragmented messages queued total",
1,
/* fragmented message */
if (NULL != s->frag_ctx)
return GNUNET_SYSERR;
- GNUNET_memcpy (&udp[1],
- msgbuf,
- msgbuf_size);
+ GNUNET_memcpy (&udp[1], msgbuf, msgbuf_size);
frag_ctx = GNUNET_new (struct UDP_FragmentationContext);
frag_ctx->plugin = plugin;
frag_ctx->session = s;
frag_ctx->cont_cls = cont_cls;
frag_ctx->start_time = GNUNET_TIME_absolute_get ();
frag_ctx->next_frag_time = s->last_transmit_time;
- frag_ctx->flow_delay_from_other_peer
- = GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer,
- 1 + (msgbuf_size /
- UDP_MTU));
+ frag_ctx->flow_delay_from_other_peer =
+ GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer,
+ 1 + (msgbuf_size / UDP_MTU));
frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to);
- frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */
+ frag_ctx->payload_size =
+ msgbuf_size; /* unfragmented message size without UDP overhead */
frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */
frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
UDP_MTU,
if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
LOG (GNUNET_ERROR_TYPE_WARNING,
"Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
- GNUNET_STRINGS_relative_time_to_string (latency,
- GNUNET_YES),
+ GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES),
GNUNET_i2s (&s->target),
(unsigned int) s->msgs_in_queue);
else
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
- GNUNET_STRINGS_relative_time_to_string (latency,
- GNUNET_YES),
+ GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES),
GNUNET_i2s (&s->target),
(unsigned int) s->msgs_in_queue);
frag_ctx->payload_size,
GNUNET_NO);
}
- notify_session_monitor (s->plugin,
- s,
- GNUNET_TRANSPORT_SS_UPDATE);
+ notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
return udpmlen;
}
* Number of bytes in @e udp_addr.
*/
size_t udp_addr_len;
-
};
struct FindReceiveContext *frc = cls;
struct DefragContext *e = element;
- if ( (frc->udp_addr_len == e->udp_addr_len) &&
- (0 == memcmp (frc->udp_addr,
- e->udp_addr,
- frc->udp_addr_len)) )
+ if ((frc->udp_addr_len == e->udp_addr_len) &&
+ (0 == memcmp (frc->udp_addr, e->udp_addr, frc->udp_addr_len)))
{
frc->rc = e;
return GNUNET_NO;
* @return #GNUNET_OK on success
*/
static int
-udp_disconnect_session (void *cls,
- struct GNUNET_ATS_Session *s)
+udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s)
{
struct Plugin *plugin = cls;
struct UDP_MessageWrapper *udpw;
if (NULL != s->frag_ctx)
{
/* Remove fragmented message due to disconnect */
- fragmented_message_done (s->frag_ctx,
- GNUNET_SYSERR);
+ fragmented_message_done (s->frag_ctx, GNUNET_SYSERR);
}
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (plugin->sessions,
- &s->target,
- s));
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s));
frc.rc = NULL;
frc.udp_addr = s->address->address;
frc.udp_addr_len = s->address->address_length;
next = udpw->next;
if (udpw->session == s)
{
- dequeue (plugin,
- udpw);
- udpw->qc (udpw->qc_cls,
- udpw,
- GNUNET_SYSERR);
+ dequeue (plugin, udpw);
+ udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
GNUNET_free (udpw);
}
}
next = udpw->next;
if (udpw->session == s)
{
- dequeue (plugin,
- udpw);
- udpw->qc (udpw->qc_cls,
- udpw,
- GNUNET_SYSERR);
+ dequeue (plugin, udpw);
+ udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
GNUNET_free (udpw);
}
}
- if ( (NULL != s->frag_ctx) &&
- (NULL != s->frag_ctx->cont) )
+ if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont))
{
/* The 'frag_ctx' itself will be freed in #free_session() a bit
later, as it might be in use right now */
s->frag_ctx->payload_size,
s->frag_ctx->on_wire_size);
}
- notify_session_monitor (s->plugin,
- s,
- GNUNET_TRANSPORT_SS_DONE);
- plugin->env->session_end (plugin->env->cls,
- s->address,
- s);
+ notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_DONE);
+ plugin->env->session_end (plugin->env->cls, s->address, s);
GNUNET_STATISTICS_set (plugin->env->stats,
"# UDP sessions active",
GNUNET_CONTAINER_multipeermap_size (plugin->sessions),
struct GNUNET_TIME_Relative flow_delay;
/* check message format */
- if (ntohs (msg->size)
- < sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader))
+ if (ntohs (msg->size) <
+ sizeof (struct UDP_ACK_Message) + sizeof (struct GNUNET_MessageHeader))
{
GNUNET_break_op (0);
return;
}
udp_ack = (const struct UDP_ACK_Message *) msg;
ack = (const struct GNUNET_MessageHeader *) &udp_ack[1];
- if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message))
+ if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDP_ACK_Message))
{
- GNUNET_break_op(0);
+ GNUNET_break_op (0);
return;
}
udp_addr,
udp_addr_len,
GNUNET_HELLO_ADDRESS_INFO_NONE);
- s = udp_plugin_lookup_session (plugin,
- address);
+ s = udp_plugin_lookup_session (plugin, address);
if (NULL == s)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
LOG (GNUNET_ERROR_TYPE_INFO,
"Asked to disconnect UDP session of %s\n",
GNUNET_i2s (&udp_ack->sender));
- udp_disconnect_session (plugin,
- s);
+ udp_disconnect_session (plugin, s);
return;
}
flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay);
if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
LOG (GNUNET_ERROR_TYPE_WARNING,
"We received a sending delay of %s for %s\n",
- GNUNET_STRINGS_relative_time_to_string (flow_delay,
- GNUNET_YES),
+ GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES),
GNUNET_i2s (&udp_ack->sender));
else
LOG (GNUNET_ERROR_TYPE_DEBUG,
"We received a sending delay of %s for %s\n",
- GNUNET_STRINGS_relative_time_to_string (flow_delay,
- GNUNET_YES),
+ GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES),
GNUNET_i2s (&udp_ack->sender));
/* Flow delay is for the reassembled packet, however, our delay
is per packet, so we need to adjust: */
s->flow_delay_from_other_peer = flow_delay;
/* Handle ACK */
- if (GNUNET_OK !=
- GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag,
- ack))
+ if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
(unsigned int) ntohs (msg->size),
GNUNET_i2s (&udp_ack->sender),
- udp_address_to_string (plugin,
- udp_addr,
- udp_addr_len));
+ udp_address_to_string (plugin, udp_addr, udp_addr_len));
/* Expect more ACKs to arrive */
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Message from %s at %s full ACK'ed\n",
GNUNET_i2s (&udp_ack->sender),
- udp_address_to_string (plugin,
- udp_addr,
- udp_addr_len));
- fragmented_message_done (s->frag_ctx,
- GNUNET_OK);
+ udp_address_to_string (plugin, udp_addr, udp_addr_len));
+ fragmented_message_done (s->frag_ctx, GNUNET_OK);
}
if (GNUNET_YES == session->in_destroy)
return GNUNET_OK;
reschedule_session_timeout (session);
- session->flow_delay_for_other_peer
- = plugin->env->receive (plugin->env->cls,
- session->address,
- session,
- hdr);
+ session->flow_delay_for_other_peer =
+ plugin->env->receive (plugin->env->cls, session->address, session, hdr);
return GNUNET_OK;
}
{
struct Plugin *plugin = cls;
- udp_disconnect_session (plugin,
- value);
+ udp_disconnect_session (plugin, value);
return GNUNET_OK;
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
*/
static void
-udp_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *target)
+udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
{
struct Plugin *plugin = cls;
{
/* not actually our turn yet, but let's at least update
the monitor, it may think we're about to die ... */
- notify_session_monitor (s->plugin,
- s,
- GNUNET_TRANSPORT_SS_UPDATE);
- s->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
- &session_timeout,
- s);
+ notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
+ s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s);
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT,
GNUNET_YES));
/* call session destroy function */
- udp_disconnect_session (plugin,
- s);
+ udp_disconnect_session (plugin, s);
}
struct GNUNET_ATS_Session *s;
s = GNUNET_new (struct GNUNET_ATS_Session);
- s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages,
- s);
+ s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, s);
s->plugin = plugin;
s->address = GNUNET_HELLO_address_copy (address);
s->target = address->peer;
s->last_transmit_time = GNUNET_TIME_absolute_get ();
- s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- 250);
+ s->last_expected_ack_delay =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250);
s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO;
s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT);
- s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT,
- &session_timeout,
- s);
+ s->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, &session_timeout, s);
s->scope = network_type;
LOG (GNUNET_ERROR_TYPE_DEBUG,
udp_address_to_string (plugin,
address->address,
address->address_length));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (plugin->sessions,
- &s->target,
- s,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (
+ plugin->sessions,
+ &s->target,
+ s,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
GNUNET_STATISTICS_set (plugin->env->stats,
"# UDP sessions active",
GNUNET_CONTAINER_multipeermap_size (plugin->sessions),
GNUNET_NO);
- notify_session_monitor (plugin,
- s,
- GNUNET_TRANSPORT_SS_INIT);
+ notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_INIT);
return s;
}
* @return the session or NULL of max connections exceeded
*/
static struct GNUNET_ATS_Session *
-udp_plugin_get_session (void *cls,
- const struct GNUNET_HELLO_Address *address)
+udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
{
struct Plugin *plugin = cls;
struct GNUNET_ATS_Session *s;
GNUNET_break (0);
return NULL;
}
- if ( (address->address_length != sizeof(struct IPv4UdpAddress)) &&
- (address->address_length != sizeof(struct IPv6UdpAddress)) )
+ if ((address->address_length != sizeof (struct IPv4UdpAddress)) &&
+ (address->address_length != sizeof (struct IPv6UdpAddress)))
{
GNUNET_break_op (0);
return NULL;
}
- if (NULL != (s = udp_plugin_lookup_session (cls,
- address)))
+ if (NULL != (s = udp_plugin_lookup_session (cls, address)))
return s;
/* need to create new session */
sizeof (v6));
}
GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
- return udp_plugin_create_session (cls,
- address,
- network_type);
+ return udp_plugin_create_session (cls, address, network_type);
}
GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
if (0 != ntohl (msg->reserved))
{
- GNUNET_break_op(0);
+ GNUNET_break_op (0);
return;
}
- if (ntohs (msg->header.size)
- < sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage))
+ if (ntohs (msg->header.size) <
+ sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage))
{
- GNUNET_break_op(0);
+ GNUNET_break_op (0);
return;
}
udp_addr,
udp_addr_len,
GNUNET_HELLO_ADDRESS_INFO_NONE);
- if (NULL ==
- (s = udp_plugin_lookup_session (plugin,
- address)))
+ if (NULL == (s = udp_plugin_lookup_session (plugin, address)))
{
- s = udp_plugin_create_session (plugin,
- address,
- network_type);
- plugin->env->session_start (plugin->env->cls,
- address,
- s,
- s->scope);
- notify_session_monitor (plugin,
- s,
- GNUNET_TRANSPORT_SS_UP);
+ s = udp_plugin_create_session (plugin, address, network_type);
+ plugin->env->session_start (plugin->env->cls, address, s, s->scope);
+ notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UP);
}
GNUNET_free (address);
s->rc++;
GNUNET_MST_from_buffer (s->mst,
(const char *) &msg[1],
- ntohs (msg->header.size) - sizeof(struct UDPMessage),
+ ntohs (msg->header.size) - sizeof (struct UDPMessage),
GNUNET_YES,
GNUNET_NO);
s->rc--;
- if ( (0 == s->rc) &&
- (GNUNET_YES == s->in_destroy) )
+ if ((0 == s->rc) && (GNUNET_YES == s->in_destroy))
free_session (s);
}
* @param msg the message
*/
static void
-fragment_msg_proc (void *cls,
- const struct GNUNET_MessageHeader *msg)
+fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct DefragContext *dc = cls;
const struct UDPMessage *um;
GNUNET_break_op (0);
return;
}
- if (ntohs (msg->size) < sizeof(struct UDPMessage))
+ if (ntohs (msg->size) < sizeof (struct UDPMessage))
{
GNUNET_break_op (0);
return;
* #GNUNET_SYSERR if we failed to send the ACK
*/
static void
-ack_message_sent (void *cls,
- struct UDP_MessageWrapper *udpw,
- int result)
+ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
{
struct Plugin *plugin = cls;
* @param msg ack to transmit
*/
static void
-ack_proc (void *cls,
- uint32_t id,
- const struct GNUNET_MessageHeader *msg)
+ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
{
struct DefragContext *rc = cls;
struct Plugin *plugin = rc->plugin;
- size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size);
+ size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size);
struct UDP_ACK_Message *udp_ack;
uint32_t delay;
struct UDP_MessageWrapper *udpw;
rc->udp_addr,
rc->udp_addr_len,
GNUNET_HELLO_ADDRESS_INFO_NONE);
- s = udp_plugin_lookup_session (plugin,
- address);
+ s = udp_plugin_lookup_session (plugin, address);
GNUNET_HELLO_address_free (address);
if (NULL == s)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Trying to transmit ACK to peer `%s' but no session found!\n",
- udp_address_to_string (plugin,
- rc->udp_addr,
- rc->udp_addr_len));
+ udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len));
GNUNET_CONTAINER_heap_remove_node (rc->hnode);
GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
GNUNET_free (rc);
delay = UINT32_MAX - 1; /* largest value we can communicate */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Sending ACK to `%s' including delay of %s\n",
- udp_address_to_string (plugin,
- rc->udp_addr,
- rc->udp_addr_len),
+ udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len),
GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer,
GNUNET_YES));
udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize);
udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK);
udp_ack->delay = htonl (delay);
udp_ack->sender = *plugin->env->my_identity;
- GNUNET_memcpy (&udp_ack[1],
- msg,
- ntohs (msg->size));
- enqueue (plugin,
- udpw);
- notify_session_monitor (plugin,
- s,
- GNUNET_TRANSPORT_SS_UPDATE);
+ GNUNET_memcpy (&udp_ack[1], msg, ntohs (msg->size));
+ enqueue (plugin, udpw);
+ notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
if (s->address->address_length == sizeof (struct IPv4UdpAddress))
schedule_select_v4 (plugin);
else
{
/* Create a new defragmentation context */
d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + udp_addr_len);
- GNUNET_memcpy (&d_ctx[1],
- udp_addr,
- udp_addr_len);
+ GNUNET_memcpy (&d_ctx[1], udp_addr, udp_addr_len);
d_ctx->udp_addr = (const union UdpAddress *) &d_ctx[1];
d_ctx->udp_addr_len = udp_addr_len;
d_ctx->network_type = network_type;
d_ctx->plugin = plugin;
- d_ctx->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
- UDP_MTU,
- UDP_MAX_MESSAGES_IN_DEFRAG,
- d_ctx,
- &fragment_msg_proc,
- &ack_proc);
+ d_ctx->defrag =
+ GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
+ UDP_MTU,
+ UDP_MAX_MESSAGES_IN_DEFRAG,
+ d_ctx,
+ &fragment_msg_proc,
+ &ack_proc);
d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs,
d_ctx,
- (GNUNET_CONTAINER_HeapCostType) now.abs_value_us);
+ (GNUNET_CONTAINER_HeapCostType)
+ now.abs_value_us);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Created new defragmentation context for %u-byte fragment from `%s'\n",
(unsigned int) ntohs (msg->size),
- udp_address_to_string (plugin,
- udp_addr,
- udp_addr_len));
+ udp_address_to_string (plugin, udp_addr, udp_addr_len));
}
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Found existing defragmentation context for %u-byte fragment from `%s'\n",
(unsigned int) ntohs (msg->size),
- udp_address_to_string (plugin,
- udp_addr,
- udp_addr_len));
+ udp_address_to_string (plugin, udp_addr, udp_addr_len));
}
- if (GNUNET_OK ==
- GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag,
- msg))
+ if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg))
{
/* keep this 'rc' from expiring */
GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode,
- (GNUNET_CONTAINER_HeapCostType) now.abs_value_us);
+ (GNUNET_CONTAINER_HeapCostType)
+ now.abs_value_us);
}
if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) >
UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
* @param rsock socket to read from
*/
static void
-udp_select_read (struct Plugin *plugin,
- struct GNUNET_NETWORK_Handle *rsock)
+udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
{
socklen_t fromlen;
struct sockaddr_storage addr;
enum GNUNET_NetworkType network_type;
fromlen = sizeof (addr);
- memset (&addr,
- 0,
- sizeof(addr));
+ memset (&addr, 0, sizeof (addr));
size = GNUNET_NETWORK_socket_recvfrom (rsock,
buf,
sizeof (buf),
* error indicates a previous send operation resulted in an ICMP Port
* Unreachable message.
*/
- if ( (-1 == size) &&
- (ECONNRESET == errno) )
+ if ((-1 == size) && (ECONNRESET == errno))
return;
#endif
if (-1 == size)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"UDP failed to receive data: %s\n",
- STRERROR (errno));
+ strerror (errno));
/* Connection failure or something. Not a protocol violation. */
return;
}
/* Check if this is a STUN packet */
if (GNUNET_NO !=
GNUNET_NAT_stun_handle_packet (plugin->nat,
- (const struct sockaddr *) &addr,
- fromlen,
- buf,
- size))
+ (const struct sockaddr *) &addr,
+ fromlen,
+ buf,
+ size))
return; /* was STUN, do not process further */
- if (size < sizeof(struct GNUNET_MessageHeader))
+ if (size < sizeof (struct GNUNET_MessageHeader))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"UDP got %u bytes from %s, which is not enough for a GNUnet message header\n",
- (unsigned int ) size,
- GNUNET_a2s (sa,
- fromlen));
+ (unsigned int) size,
+ GNUNET_a2s (sa, fromlen));
/* _MAY_ be a connection failure (got partial message) */
/* But it _MAY_ also be that the other side uses non-GNUnet protocol. */
GNUNET_break_op (0);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"UDP received %u-byte message from `%s' type %u\n",
(unsigned int) size,
- GNUNET_a2s (sa,
- fromlen),
+ GNUNET_a2s (sa, fromlen),
ntohs (msg->type));
if (size != ntohs (msg->size))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"UDP malformed message (size %u) header from %s\n",
(unsigned int) size,
- GNUNET_a2s (sa,
- fromlen));
+ GNUNET_a2s (sa, fromlen));
GNUNET_break_op (0);
return;
}
"# UDP, total bytes received",
size,
GNUNET_NO);
- network_type = plugin->env->get_address_type (plugin->env->cls,
- sa,
- fromlen);
+ network_type = plugin->env->get_address_type (plugin->env->cls, sa, fromlen);
switch (sa->sa_family)
{
case AF_INET:
network_type);
return;
case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
- if (ntohs (msg->size) < sizeof(struct UDPMessage))
+ if (ntohs (msg->size) < sizeof (struct UDPMessage))
{
- GNUNET_break_op(0);
+ GNUNET_break_op (0);
return;
}
process_udp_message (plugin,
network_type);
return;
case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
- read_process_ack (plugin,
- msg,
- int_addr,
- int_addr_len);
+ read_process_ack (plugin, msg, int_addr, int_addr_len);
return;
case GNUNET_MESSAGE_TYPE_FRAGMENT:
- read_process_fragment (plugin,
- msg,
- int_addr,
- int_addr_len,
- network_type);
+ read_process_fragment (plugin, msg, int_addr, int_addr_len, network_type);
return;
default:
- GNUNET_break_op(0);
+ GNUNET_break_op (0);
return;
}
}
int removed;
removed = GNUNET_NO;
- udpw = (sock == plugin->sockv4)
- ? plugin->ipv4_queue_head
- : plugin->ipv6_queue_head;
+ udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head
+ : plugin->ipv6_queue_head;
while (NULL != udpw)
{
session = udpw->session;
{
/* Message timed out */
removed = GNUNET_YES;
- dequeue (plugin,
- udpw);
- udpw->qc (udpw->qc_cls,
- udpw,
- GNUNET_SYSERR);
+ dequeue (plugin, udpw);
+ udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
GNUNET_free (udpw);
if (sock == plugin->sockv4)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Message for peer `%s' (%u bytes) is delayed for %s\n",
GNUNET_i2s (&udpw->session->target),
- udpw->payload_size,
- GNUNET_STRINGS_relative_time_to_string (remaining,
- GNUNET_YES));
+ udpw->payload_size,
+ GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES));
udpw = udpw->next;
}
}
{
enum GNUNET_NetworkType type;
- type = plugin->env->get_address_type (plugin->env->cls,
- sa,
- slen);
- if ( ( (GNUNET_NT_LAN == type) ||
- (GNUNET_NT_WAN == type) ) &&
- ( (ENETUNREACH == errno) ||
- (ENETDOWN == errno) ) )
+ type = plugin->env->get_address_type (plugin->env->cls, sa, slen);
+ if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) &&
+ ((ENETUNREACH == errno) || (ENETDOWN == errno)))
{
if (slen == sizeof (struct sockaddr_in))
{
* This indicates we do not have connectivity
*/
LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- _("UDP could not transmit message to `%s': "
- "Network seems down, please check your network configuration\n"),
- GNUNET_a2s (sa,
- slen));
+ _ ("UDP could not transmit message to `%s': "
+ "Network seems down, please check your network configuration\n"),
+ GNUNET_a2s (sa, slen));
}
if (slen == sizeof (struct sockaddr_in6))
{
* connectivity
*/
LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- _("UDP could not transmit IPv6 message! "
+ _ (
+ "UDP could not transmit IPv6 message! "
"Please check your network configuration and disable IPv6 if your "
"connection does not have a global IPv6 address\n"));
}
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"UDP could not transmit message to `%s': `%s'\n",
- GNUNET_a2s (sa,
- slen),
- STRERROR (error));
+ GNUNET_a2s (sa, slen),
+ strerror (error));
}
}
* @param sock which socket (v4/v6) to send on
*/
static void
-udp_select_send (struct Plugin *plugin,
- struct GNUNET_NETWORK_Handle *sock)
+udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
{
ssize_t sent;
socklen_t slen;
struct UDP_MessageWrapper *udpw;
/* Find message(s) to send */
- while (NULL != (udpw = remove_timeout_messages_and_select (plugin,
- sock)))
+ while (NULL != (udpw = remove_timeout_messages_and_select (plugin, sock)))
{
- if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length)
+ if (sizeof (struct IPv4UdpAddress) ==
+ udpw->session->address->address_length)
{
u4 = udpw->session->address->address;
- memset (&a4,
- 0,
- sizeof(a4));
+ memset (&a4, 0, sizeof (a4));
a4.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
a4.sin_len = sizeof (a4);
a = (const struct sockaddr *) &a4;
slen = sizeof (a4);
}
- else if (sizeof (struct IPv6UdpAddress) == udpw->session->address->address_length)
+ else if (sizeof (struct IPv6UdpAddress) ==
+ udpw->session->address->address_length)
{
u6 = udpw->session->address->address;
- memset (&a6,
- 0,
- sizeof(a6));
+ memset (&a6, 0, sizeof (a6));
a6.sin6_family = AF_INET6;
#if HAVE_SOCKADDR_IN_SIN_LEN
a6.sin6_len = sizeof (a6);
else
{
GNUNET_break (0);
- dequeue (plugin,
- udpw);
- udpw->qc (udpw->qc_cls,
- udpw,
- GNUNET_SYSERR);
+ dequeue (plugin, udpw);
+ udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
notify_session_monitor (plugin,
udpw->session,
GNUNET_TRANSPORT_SS_UPDATE);
udpw->msg_size,
a,
slen);
- udpw->session->last_transmit_time
- = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (),
- udpw->session->last_transmit_time);
- dequeue (plugin,
- udpw);
+ udpw->session->last_transmit_time =
+ GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (),
+ udpw->session->last_transmit_time);
+ dequeue (plugin, udpw);
if (GNUNET_SYSERR == sent)
{
/* Failure */
- analyze_send_error (plugin,
- a,
- slen,
- errno);
- udpw->qc (udpw->qc_cls,
- udpw,
- GNUNET_SYSERR);
+ analyze_send_error (plugin, a, slen, errno);
+ udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
GNUNET_STATISTICS_update (plugin->env->stats,
"# UDP, total, bytes, sent, failure",
sent,
"UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n",
(unsigned int) (udpw->msg_size),
GNUNET_i2s (&udpw->session->target),
- GNUNET_a2s (a,
- slen),
- (int ) sent,
- (sent < 0) ? STRERROR (errno) : "ok");
+ GNUNET_a2s (a, slen),
+ (int) sent,
+ (sent < 0) ? strerror (errno) : "ok");
GNUNET_STATISTICS_update (plugin->env->stats,
"# UDP, total, bytes, sent, success",
sent,
GNUNET_NO);
if (NULL != udpw->frag_ctx)
udpw->frag_ctx->on_wire_size += udpw->msg_size;
- udpw->qc (udpw->qc_cls,
- udpw,
- GNUNET_OK);
+ udpw->qc (udpw->qc_cls, udpw, GNUNET_OK);
}
- notify_session_monitor (plugin,
- udpw->session,
- GNUNET_TRANSPORT_SS_UPDATE);
+ notify_session_monitor (plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE);
GNUNET_free (udpw);
}
}
return;
tc = GNUNET_SCHEDULER_get_task_context ();
if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- plugin->sockv4)))
- udp_select_read (plugin,
- plugin->sockv4);
- udp_select_send (plugin,
- plugin->sockv4);
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)))
+ udp_select_read (plugin, plugin->sockv4);
+ udp_select_send (plugin, plugin->sockv4);
schedule_select_v4 (plugin);
}
if (NULL == plugin->sockv6)
return;
tc = GNUNET_SCHEDULER_get_task_context ();
- if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- plugin->sockv6)) )
- udp_select_read (plugin,
- plugin->sockv6);
-
- udp_select_send (plugin,
- plugin->sockv6);
+ if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
+ udp_select_read (plugin, plugin->sockv6);
+
+ udp_select_send (plugin, plugin->sockv6);
schedule_select_v6 (plugin);
}
eno = EINVAL;
if (GNUNET_YES == plugin->enable_ipv6)
{
- plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6,
- SOCK_DGRAM,
- 0);
+ plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
if (NULL == plugin->sockv6)
{
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling IPv6 since it is not supported on this system!\n"));
+ _ ("Disabling IPv6 since it is not supported on this system!\n"));
plugin->enable_ipv6 = GNUNET_NO;
}
else
{
- memset (&server_addrv6,
- 0,
- sizeof(struct sockaddr_in6));
+ memset (&server_addrv6, 0, sizeof (struct sockaddr_in6));
#if HAVE_SOCKADDR_IN_SIN_LEN
server_addrv6.sin6_len = sizeof (struct sockaddr_in6);
#endif
server_addrv6.sin6_addr = in6addr_any;
if (0 == plugin->port) /* autodetect */
- server_addrv6.sin6_port
- = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
- 33537)
- + 32000);
+ server_addrv6.sin6_port = htons (
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
+ 32000);
else
server_addrv6.sin6_port = htons (plugin->port);
addrlen = sizeof (struct sockaddr_in6);
tries = 0;
while (tries < 10)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Binding to IPv6 `%s'\n",
- GNUNET_a2s (server_addr,
- addrlen));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Binding to IPv6 `%s'\n",
+ GNUNET_a2s (server_addr, addrlen));
/* binding */
if (GNUNET_OK ==
- GNUNET_NETWORK_socket_bind (plugin->sockv6,
- server_addr,
- addrlen))
+ GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, addrlen))
break;
eno = errno;
if (0 != plugin->port)
break; /* bind failed on specific port */
}
/* autodetect */
- server_addrv6.sin6_port
- = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
- 33537)
- + 32000);
+ server_addrv6.sin6_port = htons (
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
+ 32000);
tries++;
}
if (tries >= 10)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"IPv6 UDP socket created listinging at %s\n",
- GNUNET_a2s (server_addr,
- addrlen));
+ GNUNET_a2s (server_addr, addrlen));
addrs[sockets_created] = server_addr;
addrlens[sockets_created] = addrlen;
sockets_created++;
else
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to bind UDP socket to %s: %s\n"),
- GNUNET_a2s (server_addr,
- addrlen),
- STRERROR (eno));
+ _ ("Failed to bind UDP socket to %s: %s\n"),
+ GNUNET_a2s (server_addr, addrlen),
+ strerror (eno));
}
}
}
/* Create IPv4 socket */
eno = EINVAL;
- plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET,
- SOCK_DGRAM,
- 0);
+ plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
if (NULL == plugin->sockv4)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "socket");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling IPv4 since it is not supported on this system!\n"));
+ _ ("Disabling IPv4 since it is not supported on this system!\n"));
plugin->enable_ipv4 = GNUNET_NO;
}
else
{
- memset (&server_addrv4,
- 0,
- sizeof(struct sockaddr_in));
+ memset (&server_addrv4, 0, sizeof (struct sockaddr_in));
#if HAVE_SOCKADDR_IN_SIN_LEN
server_addrv4.sin_len = sizeof (struct sockaddr_in);
#endif
if (0 == plugin->port)
/* autodetect */
- server_addrv4.sin_port
- = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
- 33537)
- + 32000);
+ server_addrv4.sin_port = htons (
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
else
server_addrv4.sin_port = htons (plugin->port);
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Binding to IPv4 `%s'\n",
- GNUNET_a2s (server_addr,
- addrlen));
+ GNUNET_a2s (server_addr, addrlen));
/* binding */
if (GNUNET_OK ==
- GNUNET_NETWORK_socket_bind (plugin->sockv4,
- server_addr,
- addrlen))
+ GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen))
break;
eno = errno;
if (0 != plugin->port)
}
/* autodetect */
- server_addrv4.sin_port
- = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
- 33537)
- + 32000);
+ server_addrv4.sin_port = htons (
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
tries++;
}
if (tries >= 10)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"IPv4 socket created on port %s\n",
- GNUNET_a2s (server_addr,
- addrlen));
+ GNUNET_a2s (server_addr, addrlen));
addrs[sockets_created] = server_addr;
addrlens[sockets_created] = addrlen;
sockets_created++;
else
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to bind UDP socket to %s: %s\n"),
- GNUNET_a2s (server_addr,
- addrlen),
- STRERROR (eno));
+ _ ("Failed to bind UDP socket to %s: %s\n"),
+ GNUNET_a2s (server_addr, addrlen),
+ strerror (eno));
}
}
if (0 == sockets_created)
{
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to open UDP sockets\n"));
+ LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UDP sockets\n"));
return 0; /* No sockets created, return */
}
schedule_select_v4 (plugin);
schedule_select_v6 (plugin);
plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
- "transport-udp",
- IPPROTO_UDP,
+ "transport-udp",
+ IPPROTO_UDP,
sockets_created,
addrs,
addrlens,
/* Get port number: port == 0 : autodetect a port,
* > 0 : use this port, not given : 2086 default */
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-udp",
- "PORT",
- &port))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-udp",
+ "PORT",
+ &port))
port = 2086;
if (port > 65535)
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
"transport-udp",
"PORT",
- _("must be in [0,65535]"));
+ _ ("must be in [0,65535]"));
return NULL;
}
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-udp",
- "ADVERTISED_PORT",
- &aport))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-udp",
+ "ADVERTISED_PORT",
+ &aport))
aport = port;
if (aport > 65535)
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
"transport-udp",
"ADVERTISED_PORT",
- _("must be in [0,65535]"));
+ _ ("must be in [0,65535]"));
return NULL;
}
if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- "nat",
- "DISABLEV6"))
+ GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6"))
enable_v6 = GNUNET_NO;
else
enable_v6 = GNUNET_YES;
have_bind4 = GNUNET_NO;
- memset (&server_addrv4,
- 0,
- sizeof (server_addrv4));
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string (env->cfg,
- "transport-udp",
- "BINDTO",
- &bind4_address))
+ memset (&server_addrv4, 0, sizeof (server_addrv4));
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
+ "transport-udp",
+ "BINDTO",
+ &bind4_address))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Binding UDP plugin to specific address: `%s'\n",
bind4_address);
- if (1 != inet_pton (AF_INET,
- bind4_address,
- &server_addrv4.sin_addr))
+ if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
"transport-udp",
"BINDTO",
- _("must be valid IPv4 address"));
+ _ ("must be valid IPv4 address"));
GNUNET_free (bind4_address);
return NULL;
}
}
GNUNET_free_non_null (bind4_address);
have_bind6 = GNUNET_NO;
- memset (&server_addrv6,
- 0,
- sizeof (server_addrv6));
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_string (env->cfg,
- "transport-udp",
- "BINDTO6",
- &bind6_address))
+ memset (&server_addrv6, 0, sizeof (server_addrv6));
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
+ "transport-udp",
+ "BINDTO6",
+ &bind6_address))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Binding udp plugin to specific address: `%s'\n",
bind6_address);
- if (1 != inet_pton (AF_INET6,
- bind6_address,
- &server_addrv6.sin6_addr))
+ if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
"transport-udp",
"BINDTO6",
- _("must be valid IPv6 address"));
+ _ ("must be valid IPv6 address"));
GNUNET_free (bind6_address);
return NULL;
}
if (enable_broadcasting == GNUNET_SYSERR)
enable_broadcasting = GNUNET_NO;
- enable_broadcasting_recv = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- "transport-udp",
- "BROADCAST_RECEIVE");
+ enable_broadcasting_recv =
+ GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "transport-udp",
+ "BROADCAST_RECEIVE");
if (enable_broadcasting_recv == GNUNET_SYSERR)
enable_broadcasting_recv = GNUNET_YES;
"BROADCAST_INTERVAL",
&interval))
{
- interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- 10);
+ interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
}
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (env->cfg,
- "transport-udp",
- "MAX_BPS",
- &udp_max_bps))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-udp",
+ "MAX_BPS",
+ &udp_max_bps))
{
/* 50 MB/s == infinity for practical purposes */
udp_max_bps = 1024 * 1024 * 50;
p->enable_broadcasting = enable_broadcasting;
p->enable_broadcasting_receiving = enable_broadcasting_recv;
p->env = env;
- p->sessions = GNUNET_CONTAINER_multipeermap_create (16,
- GNUNET_NO);
- p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ p->sessions = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
+ p->defrag_ctxs =
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
GNUNET_BANDWIDTH_tracker_init (&p->tracker,
NULL,
NULL,
- GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps),
+ GNUNET_BANDWIDTH_value_init (
+ (uint32_t) udp_max_bps),
30);
res = setup_sockets (p,
(GNUNET_YES == have_bind6) ? &server_addrv6 : NULL,
(GNUNET_YES == have_bind4) ? &server_addrv4 : NULL);
- if ( (0 == res) ||
- ( (NULL == p->sockv4) &&
- (NULL == p->sockv6) ) )
+ if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6)))
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create UDP network sockets\n"));
+ LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Failed to create UDP network sockets\n"));
GNUNET_CONTAINER_multipeermap_destroy (p->sessions);
GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs);
if (NULL != p->nat)
}
/* Setup broadcasting and receiving beacons */
- setup_broadcast (p,
- &server_addrv6,
- &server_addrv4);
+ setup_broadcast (p, &server_addrv6, &server_addrv4);
api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
api->cls = p;
}
if (NULL != plugin->sockv4)
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (plugin->sockv4));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4));
plugin->sockv4 = NULL;
}
if (NULL != plugin->sockv6)
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (plugin->sockv6));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6));
plugin->sockv6 = NULL;
}
if (NULL != plugin->nat)
}
while (NULL != (udpw = plugin->ipv4_queue_head))
{
- dequeue (plugin,
- udpw);
- udpw->qc (udpw->qc_cls,
- udpw,
- GNUNET_SYSERR);
+ dequeue (plugin, udpw);
+ udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
GNUNET_free (udpw);
}
while (NULL != (udpw = plugin->ipv6_queue_head))
{
- dequeue (plugin,
- udpw);
- udpw->qc (udpw->qc_cls,
- udpw,
- GNUNET_SYSERR);
+ dequeue (plugin, udpw);
+ udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
GNUNET_free (udpw);
}
GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
/**
* How long until we give up on transmitting the welcome message?
*/
-#define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
+#define HOSTNAME_RESOLVE_TIMEOUT \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
-#define LOG(kind,...) GNUNET_log_from (kind, "transport-unix",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "transport-unix", __VA_ARGS__)
GNUNET_NETWORK_STRUCT_BEGIN
* What is the identity of the sender (GNUNET_hash of public key)
*/
struct GNUNET_PeerIdentity sender;
-
};
GNUNET_NETWORK_STRUCT_END
/**
* Session timeout task.
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* Number of messages we currently have in our write queue.
*/
unsigned int msgs_in_queue;
-
};
/**
* ID of task used to update our addresses when one expires.
*/
- struct GNUNET_SCHEDULER_Task * address_update_task;
+ struct GNUNET_SCHEDULER_Task *address_update_task;
/**
* ID of read task
*/
- struct GNUNET_SCHEDULER_Task * read_task;
+ struct GNUNET_SCHEDULER_Task *read_task;
/**
* ID of write task
*/
- struct GNUNET_SCHEDULER_Task * write_task;
+ struct GNUNET_SCHEDULER_Task *write_task;
/**
* Number of bytes we currently have in our write queues.
* Are we using an abstract UNIX domain socket?
*/
int is_abstract;
-
};
to receive from others) */
info.session_timeout = session->timeout;
info.address = session->address;
- plugin->sic (plugin->sic_cls,
- session,
- &info);
+ plugin->sic (plugin->sic_cls, session, &info);
}
* @return string representing the same address
*/
static const char *
-unix_plugin_address_to_string (void *cls,
- const void *addr,
- size_t addrlen)
+unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
{
static char rbuf[1024];
struct UnixAddress *ua = (struct UnixAddress *) addr;
if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
{
- GNUNET_break(0);
+ GNUNET_break (0);
return NULL;
}
addrstr = (char *) &ua[1];
addr_str_len = ntohl (ua->addrlen);
- if (addr_str_len != addrlen - sizeof(struct UnixAddress))
+ if (addr_str_len != addrlen - sizeof (struct UnixAddress))
{
- GNUNET_break(0);
+ GNUNET_break (0);
return NULL;
}
if ('\0' != addrstr[addr_str_len - 1])
{
- GNUNET_break(0);
+ GNUNET_break (0);
return NULL;
}
if (strlen (addrstr) + 1 != addr_str_len)
{
- GNUNET_break(0);
+ GNUNET_break (0);
return NULL;
}
* @return #GNUNET_OK on success
*/
static int
-unix_plugin_session_disconnect (void *cls,
- struct GNUNET_ATS_Session *session)
+unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session)
{
struct Plugin *plugin = cls;
struct UNIXMessageWrapper *msgw;
unix_plugin_address_to_string (NULL,
session->address->address,
session->address->address_length));
- plugin->env->session_end (plugin->env->cls,
- session->address,
- session);
+ plugin->env->session_end (plugin->env->cls, session->address, session);
next = plugin->msg_head;
while (NULL != next)
{
next = msgw->next;
if (msgw->session != session)
continue;
- GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
- plugin->msg_tail,
- msgw);
+ GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
session->msgs_in_queue--;
GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
session->bytes_in_queue -= msgw->msgsize;
msgw->cont (msgw->cont_cls,
&msgw->session->target,
GNUNET_SYSERR,
- msgw->payload, 0);
+ msgw->payload,
+ 0);
GNUNET_free (msgw->msg);
GNUNET_free (msgw);
}
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multipeermap_remove (plugin->session_map,
- &session->target,
- session));
+ &session->target,
+ session));
GNUNET_STATISTICS_set (plugin->env->stats,
- "# UNIX sessions active",
- GNUNET_CONTAINER_multipeermap_size (plugin->session_map),
- GNUNET_NO);
+ "# UNIX sessions active",
+ GNUNET_CONTAINER_multipeermap_size (
+ plugin->session_map),
+ GNUNET_NO);
if (NULL != session->timeout_task)
{
GNUNET_SCHEDULER_cancel (session->timeout_task);
session->timeout_task = NULL;
session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
}
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_DONE);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_DONE);
GNUNET_HELLO_address_free (session->address);
GNUNET_break (0 == session->bytes_in_queue);
GNUNET_break (0 == session->msgs_in_queue);
notify_session_monitor (session->plugin,
session,
GNUNET_TRANSPORT_SS_UPDATE);
- session->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
- &session_timeout,
- session);
+ session->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (left, &session_timeout, session);
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p was idle for %s, disconnecting\n",
session,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ GNUNET_YES));
unix_plugin_session_disconnect (session->plugin, session);
}
reschedule_session_timeout (struct GNUNET_ATS_Session *session)
{
GNUNET_assert (NULL != session->timeout_task);
- session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ session->timeout =
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
}
* @return converted unix path
*/
static struct sockaddr_un *
-unix_address_to_sockaddr (const char *unixpath,
- socklen_t *sock_len)
+unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
{
struct sockaddr_un *un;
size_t slen;
- GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
+ GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
un = GNUNET_new (struct sockaddr_un);
un->sun_family = AF_UNIX;
slen = strlen (unixpath);
*/
static int
lookup_session_it (void *cls,
- const struct GNUNET_PeerIdentity * key,
- void *value)
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
struct LookupCtx *lctx = cls;
struct GNUNET_ATS_Session *session = value;
- if (0 == GNUNET_HELLO_address_cmp (lctx->address,
- session->address))
+ if (0 == GNUNET_HELLO_address_cmp (lctx->address, session->address))
{
lctx->res = session;
return GNUNET_NO;
lctx.address = address;
lctx.res = NULL;
GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
- &address->peer,
- &lookup_session_it, &lctx);
+ &address->peer,
+ &lookup_session_it,
+ &lctx);
return lctx.res;
}
}
/* Prepare address */
- unixpath = (const char *) &addr[1];
- if (NULL == (un = unix_address_to_sockaddr (unixpath,
- &un_len)))
+ unixpath = (const char *) &addr[1];
+ if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len)))
{
GNUNET_break (0);
return -1;
}
if ((GNUNET_YES == plugin->is_abstract) &&
- (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options) )) )
+ (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl (addr->options))))
{
un->sun_path[0] = '\0';
}
un_len);
if (GNUNET_SYSERR == sent)
{
- if ( (EAGAIN == errno) ||
- (ENOBUFS == errno) )
+ if ((EAGAIN == errno) || (ENOBUFS == errno))
{
GNUNET_free (un);
return RETRY; /* We have to retry later */
socklen_t len = sizeof (size);
GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
- send_handle, SOL_SOCKET, SO_SNDBUF, &size,
+ send_handle,
+ SOL_SOCKET,
+ SO_SNDBUF,
+ &size,
&len);
if (size < msgbuf_size)
{
(unsigned int) msgbuf_size);
size = ((msgbuf_size / 1000) + 2) * 1000;
if (GNUNET_OK ==
- GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) send_handle,
- SOL_SOCKET, SO_SNDBUF,
- &size, sizeof (size)))
+ GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *)
+ send_handle,
+ SOL_SOCKET,
+ SO_SNDBUF,
+ &size,
+ sizeof (size)))
goto resend; /* Increased buffer size, retry sending */
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"UNIX transmitted %u-byte message to %s (%d: %s)\n",
(unsigned int) msgbuf_size,
- GNUNET_a2s ((const struct sockaddr *)un, un_len),
+ GNUNET_a2s ((const struct sockaddr *) un, un_len),
(int) sent,
- (sent < 0) ? STRERROR (errno) : "ok");
+ (sent < 0) ? strerror (errno) : "ok");
GNUNET_free (un);
return sent;
}
* @return the network type in HBO or #GNUNET_SYSERR
*/
static enum GNUNET_NetworkType
-unix_plugin_get_network (void *cls,
- struct GNUNET_ATS_Session *session)
+unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
{
GNUNET_assert (NULL != session);
return GNUNET_NT_LOOPBACK;
* @return the session or NULL of max connections exceeded
*/
static struct GNUNET_ATS_Session *
-unix_plugin_get_session (void *cls,
- const struct GNUNET_HELLO_Address *address)
+unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
{
struct Plugin *plugin = cls;
struct GNUNET_ATS_Session *session;
struct UnixAddress *ua;
- char * addrstr;
+ char *addrstr;
uint32_t addr_str_len;
uint32_t addr_option;
ua = (struct UnixAddress *) address->address;
if ((NULL == address->address) || (0 == address->address_length) ||
- (sizeof (struct UnixAddress) > address->address_length))
+ (sizeof (struct UnixAddress) > address->address_length))
{
GNUNET_break (0);
return NULL;
addr_str_len = ntohl (ua->addrlen);
addr_option = ntohl (ua->options);
- if ( (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
- (GNUNET_NO == plugin->is_abstract))
+ if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
+ (GNUNET_NO == plugin->is_abstract))
{
return NULL;
}
}
/* Check if a session for this address already exists */
- if (NULL != (session = lookup_session (plugin,
- address)))
- {
+ if (NULL != (session = lookup_session (plugin, address)))
+ {
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Found existing session %p for address `%s'\n",
- session,
- unix_plugin_address_to_string (NULL,
+ session,
+ unix_plugin_address_to_string (NULL,
address->address,
address->address_length));
return session;
session->target = address->peer;
session->address = GNUNET_HELLO_address_copy (address);
session->plugin = plugin;
- session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- &session_timeout,
- session);
+ session->timeout =
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ session->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &session_timeout,
+ session);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Creating a new session %p for address `%s'\n",
session,
unix_plugin_address_to_string (NULL,
address->address,
address->address_length));
- (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map,
- &address->peer, session,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ (void) GNUNET_CONTAINER_multipeermap_put (
+ plugin->session_map,
+ &address->peer,
+ session,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
GNUNET_STATISTICS_set (plugin->env->stats,
- "# UNIX sessions active",
- GNUNET_CONTAINER_multipeermap_size (plugin->session_map),
- GNUNET_NO);
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_INIT);
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_UP);
+ "# UNIX sessions active",
+ GNUNET_CONTAINER_multipeermap_size (
+ plugin->session_map),
+ GNUNET_NO);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
return session;
}
"Received message from %s\n",
unix_plugin_address_to_string (NULL, ua, ua_len));
GNUNET_STATISTICS_update (plugin->env->stats,
- "# bytes received via UNIX",
- ntohs (currhdr->size),
- GNUNET_NO);
+ "# bytes received via UNIX",
+ ntohs (currhdr->size),
+ GNUNET_NO);
/* Look for existing session */
- address = GNUNET_HELLO_address_allocate (sender,
- PLUGIN_NAME,
- ua, ua_len,
- GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
+ address = GNUNET_HELLO_address_allocate (
+ sender,
+ PLUGIN_NAME,
+ ua,
+ ua_len,
+ GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
session = lookup_session (plugin, address);
if (NULL == session)
{
reschedule_session_timeout (session);
}
GNUNET_HELLO_address_free (address);
- plugin->env->receive (plugin->env->cls,
- session->address,
- session,
- currhdr);
+ plugin->env->receive (plugin->env->cls, session->address, session, currhdr);
}
addrlen = sizeof (un);
memset (&un, 0, sizeof (un));
ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc,
- buf, sizeof (buf),
+ buf,
+ sizeof (buf),
(struct sockaddr *) &un,
&addrlen);
if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS)))
return;
if (GNUNET_SYSERR == ret)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "recvfrom");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
return;
}
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Read %d bytes from socket %s\n",
- (int) ret,
- un.sun_path);
+ "Read %d bytes from socket %s\n",
+ (int) ret,
+ un.sun_path);
}
GNUNET_assert (AF_UNIX == (un.sun_family));
ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1;
ua = GNUNET_malloc (ua_len);
- ua->addrlen = htonl (strlen (&un.sun_path[0]) +1);
+ ua->addrlen = htonl (strlen (&un.sun_path[0]) + 1);
GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1);
if (is_abstract)
- ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
+ ua->options = htonl (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
else
- ua->options = htonl(UNIX_OPTIONS_NONE);
+ ua->options = htonl (UNIX_OPTIONS_NONE);
msg = (struct UNIXMessage *) buf;
csize = ntohs (msg->header.size);
return;
}
msgbuf = (char *) &msg[1];
- GNUNET_memcpy (&sender,
- &msg->sender,
- sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity));
offset = 0;
tsize = csize - sizeof (struct UNIXMessage);
while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
/* Message has a timeout */
did_delete = GNUNET_YES;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout for message with %u bytes \n",
- (unsigned int) msgw->msgsize);
- GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
- plugin->msg_tail,
- msgw);
+ "Timeout for message with %u bytes \n",
+ (unsigned int) msgw->msgsize);
+ GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
session = msgw->session;
session->msgs_in_queue--;
GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
plugin->bytes_in_queue -= msgw->msgsize;
GNUNET_STATISTICS_set (plugin->env->stats,
- "# bytes currently in UNIX buffers",
- plugin->bytes_in_queue,
+ "# bytes currently in UNIX buffers",
+ plugin->bytes_in_queue,
GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UNIX bytes discarded",
- msgw->msgsize,
- GNUNET_NO);
+ "# UNIX bytes discarded",
+ msgw->msgsize,
+ GNUNET_NO);
if (NULL != msgw->cont)
msgw->cont (msgw->cont_cls,
- &msgw->session->target,
- GNUNET_SYSERR,
- msgw->payload,
- 0);
+ &msgw->session->target,
+ GNUNET_SYSERR,
+ msgw->payload,
+ 0);
GNUNET_free (msgw->msg);
GNUNET_free (msgw);
}
if (NULL == msgw)
{
if (GNUNET_YES == did_delete)
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_UPDATE);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
return; /* Nothing to send at the moment */
}
session = msgw->session;
msgw->session->address->address,
msgw->session->address->address_length,
msgw->payload,
- msgw->cont, msgw->cont_cls);
+ msgw->cont,
+ msgw->cont_cls);
if (RETRY == sent)
{
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UNIX retry attempts",
- 1, GNUNET_NO);
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_UPDATE);
+ "# UNIX retry attempts",
+ 1,
+ GNUNET_NO);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
return;
}
- GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
- plugin->msg_tail,
- msgw);
+ GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
session->msgs_in_queue--;
GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
session->bytes_in_queue -= msgw->msgsize;
plugin->bytes_in_queue -= msgw->msgsize;
GNUNET_STATISTICS_set (plugin->env->stats,
"# bytes currently in UNIX buffers",
- plugin->bytes_in_queue, GNUNET_NO);
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_UPDATE);
+ plugin->bytes_in_queue,
+ GNUNET_NO);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
if (GNUNET_SYSERR == sent)
{
/* failed and no retry */
msgw->cont (msgw->cont_cls,
&msgw->session->target,
GNUNET_SYSERR,
- msgw->payload, 0);
+ msgw->payload,
+ 0);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UNIX bytes discarded",
- msgw->msgsize,
- GNUNET_NO);
+ "# UNIX bytes discarded",
+ msgw->msgsize,
+ GNUNET_NO);
GNUNET_free (msgw->msg);
GNUNET_free (msgw);
return;
/* successfully sent bytes */
GNUNET_break (sent > 0);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# bytes transmitted via UNIX",
- msgw->msgsize,
- GNUNET_NO);
+ "# bytes transmitted via UNIX",
+ msgw->msgsize,
+ GNUNET_NO);
if (NULL != msgw->cont)
msgw->cont (msgw->cont_cls,
&msgw->session->target,
- GNUNET_OK,
- msgw->payload,
- msgw->msgsize);
+ GNUNET_OK,
+ msgw->payload,
+ msgw->msgsize);
GNUNET_free (msgw->msg);
GNUNET_free (msgw);
}
plugin->read_task =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
plugin->unix_sock.desc,
- &unix_plugin_select_read, plugin);
+ &unix_plugin_select_read,
+ plugin);
}
plugin->write_task =
GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
plugin->unix_sock.desc,
- &unix_plugin_select_write, plugin);
+ &unix_plugin_select_write,
+ plugin);
}
if (GNUNET_OK !=
GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
- &session->target,
- session))
+ &session->target,
+ session))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- "Invalid session for peer `%s' `%s'\n",
- GNUNET_i2s (&session->target),
- unix_plugin_address_to_string (NULL,
+ "Invalid session for peer `%s' `%s'\n",
+ GNUNET_i2s (&session->target),
+ unix_plugin_address_to_string (NULL,
session->address->address,
session->address->address_length));
GNUNET_break (0);
message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
message->header.size = htons (ssize);
message->header.type = htons (0);
- GNUNET_memcpy (&message->sender, plugin->env->my_identity,
- sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_memcpy (&message->sender,
+ plugin->env->my_identity,
+ sizeof (struct GNUNET_PeerIdentity));
GNUNET_memcpy (&message[1], msgbuf, msgbuf_size);
wrapper = GNUNET_new (struct UNIXMessageWrapper);
wrapper->msg = message;
wrapper->msgsize = ssize;
wrapper->payload = msgbuf_size;
wrapper->priority = priority;
- wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
- to);
+ wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to);
wrapper->cont = cont;
wrapper->cont_cls = cont_cls;
wrapper->session = session;
session->bytes_in_queue += ssize;
session->msgs_in_queue++;
GNUNET_STATISTICS_set (plugin->env->stats,
- "# bytes currently in UNIX buffers",
- plugin->bytes_in_queue,
- GNUNET_NO);
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_UPDATE);
+ "# bytes currently in UNIX buffers",
+ plugin->bytes_in_queue,
+ GNUNET_NO);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
if (NULL == plugin->write_task)
plugin->write_task =
GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
plugin->unix_sock.desc,
- &unix_plugin_select_write, plugin);
+ &unix_plugin_select_write,
+ plugin);
return ssize;
}
struct sockaddr_un *un;
socklen_t un_len;
- un = unix_address_to_sockaddr (plugin->unix_socket_path,
- &un_len);
+ un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len);
if (GNUNET_YES == plugin->is_abstract)
{
plugin->unix_socket_path[0] = '@';
un->sun_path[0] = '\0';
}
plugin->unix_sock.desc =
- GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
+ GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
if (NULL == plugin->unix_sock.desc)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
{
if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot create path to `%s'\n"),
- un->sun_path);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Cannot create path to `%s'\n"),
+ un->sun_path);
GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
plugin->unix_sock.desc = NULL;
GNUNET_free (un);
return GNUNET_SYSERR;
}
}
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc,
- (const struct sockaddr *) un, un_len))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc,
+ (const struct sockaddr *) un,
+ un_len))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"),
- un->sun_path);
+ LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot bind to `%s'\n"), un->sun_path);
GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
plugin->unix_sock.desc = NULL;
GNUNET_free (un);
return GNUNET_SYSERR;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Bound to `%s'\n",
- plugin->unix_socket_path);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path);
plugin->read_task =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
plugin->unix_sock.desc,
- &unix_plugin_select_read, plugin);
+ &unix_plugin_select_read,
+ plugin);
GNUNET_free (un);
return 1;
}
*
*/
static int
-unix_plugin_check_address (void *cls,
- const void *addr,
- size_t addrlen)
+unix_plugin_check_address (void *cls, const void *addr, size_t addrlen)
{
- struct Plugin* plugin = cls;
+ struct Plugin *plugin = cls;
const struct UnixAddress *ua = addr;
char *addrstr;
size_t addr_str_len;
- if ( (NULL == addr) ||
- (0 == addrlen) ||
- (sizeof (struct UnixAddress) > addrlen) )
+ if ((NULL == addr) || (0 == addrlen) ||
+ (sizeof (struct UnixAddress) > addrlen))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
if (0 == strcmp (plugin->unix_socket_path, addrstr))
- return GNUNET_OK;
+ return GNUNET_OK;
return GNUNET_SYSERR;
}
* @param asc_cls closure for @a asc
*/
static void
-unix_plugin_address_pretty_printer (void *cls, const char *type,
+unix_plugin_address_pretty_printer (void *cls,
+ const char *type,
const void *addr,
size_t addrlen,
int numeric,
{
const char *ret;
- if ( (NULL != addr) && (addrlen > 0))
- ret = unix_plugin_address_to_string (NULL,
- addr,
- addrlen);
+ if ((NULL != addr) && (addrlen > 0))
+ ret = unix_plugin_address_to_string (NULL, addr, addrlen);
else
ret = NULL;
- asc (asc_cls,
- ret,
- (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
+ asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
asc (asc_cls, NULL, GNUNET_OK);
}
unix_plugin_string_to_address (void *cls,
const char *addr,
uint16_t addrlen,
- void **buf, size_t *added)
+ void **buf,
+ size_t *added)
{
struct UnixAddress *ua;
char *address;
}
address[0] = '\0';
address++;
- if (0 != strcmp(plugin, PLUGIN_NAME))
+ if (0 != strcmp (plugin, PLUGIN_NAME))
{
GNUNET_break (0);
GNUNET_free (plugin);
len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
ua = GNUNET_malloc (len);
ua->options = htonl (plugin->myoptions);
- ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
+ ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1);
unix_path = (char *) &ua[1];
- GNUNET_memcpy (unix_path, plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1);
+ GNUNET_memcpy (unix_path,
+ plugin->unix_socket_path,
+ strlen (plugin->unix_socket_path) + 1);
plugin->address_update_task = NULL;
address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
ua,
len,
GNUNET_HELLO_ADDRESS_INFO_NONE);
- plugin->env->notify_address (plugin->env->cls,
- GNUNET_YES,
- address);
+ plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address);
GNUNET_free (ua);
GNUNET_free (address);
}
*/
static int
get_session_delete_it (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
struct Plugin *plugin = cls;
struct GNUNET_ATS_Session *session = value;
struct Plugin *plugin = cls;
GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
- target,
- &get_session_delete_it, plugin);
+ target,
+ &get_session_delete_it,
+ plugin);
}
struct Plugin *plugin = cls;
struct GNUNET_ATS_Session *session = value;
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_INIT);
- notify_session_monitor (plugin,
- session,
- GNUNET_TRANSPORT_SS_UP);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
+ notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
return GNUNET_OK;
}
/* Initialize my flags */
#ifdef LINUX
- plugin->is_abstract = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
- "testing",
- "USE_ABSTRACT_SOCKETS");
+ plugin->is_abstract =
+ GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
+ "testing",
+ "USE_ABSTRACT_SOCKETS");
#endif
plugin->myoptions = UNIX_OPTIONS_NONE;
if (GNUNET_YES == plugin->is_abstract)
sockets_created = unix_transport_server_start (plugin);
if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
{
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to open UNIX listen socket\n"));
+ LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UNIX listen socket\n"));
GNUNET_free (api);
GNUNET_free (plugin->unix_socket_path);
GNUNET_free (plugin);
return NULL;
}
plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
- plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification,
- plugin);
+ plugin->address_update_task =
+ GNUNET_SCHEDULER_add_now (&address_notification, plugin);
return api;
}
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
struct GNUNET_HELLO_Address *address;
- struct UNIXMessageWrapper * msgw;
+ struct UNIXMessageWrapper *msgw;
struct UnixAddress *ua;
size_t len;
struct GNUNET_ATS_Session *session;
len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
ua = GNUNET_malloc (len);
ua->options = htonl (plugin->myoptions);
- ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
+ ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1);
GNUNET_memcpy (&ua[1],
- plugin->unix_socket_path,
- strlen (plugin->unix_socket_path) + 1);
+ plugin->unix_socket_path,
+ strlen (plugin->unix_socket_path) + 1);
address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
PLUGIN_NAME,
- ua, len,
+ ua,
+ len,
GNUNET_HELLO_ADDRESS_INFO_NONE);
- plugin->env->notify_address (plugin->env->cls,
- GNUNET_NO,
- address);
+ plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address);
GNUNET_free (address);
GNUNET_free (ua);
while (NULL != (msgw = plugin->msg_head))
{
- GNUNET_CONTAINER_DLL_remove (plugin->msg_head,
- plugin->msg_tail,
- msgw);
+ GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
session = msgw->session;
session->msgs_in_queue--;
GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
msgw->cont (msgw->cont_cls,
&msgw->session->target,
GNUNET_SYSERR,
- msgw->payload, 0);
+ msgw->payload,
+ 0);
GNUNET_free (msgw->msg);
GNUNET_free (msgw);
}
plugin->unix_sock.desc = NULL;
}
GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
- &get_session_delete_it,
+ &get_session_delete_it,
plugin);
GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map);
GNUNET_break (0 == plugin->bytes_in_queue);
* is this value divided by the number of address families.
* Default is 5s.
*/
-#define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
+#define CONNECT_RETRY_TIMEOUT \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
-
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-connection", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-connection", syscall)
/**
/**
* Task called on timeout.
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* At what number of bytes available in the
* write buffer should the notify method be called?
*/
size_t notify_size;
-
};
/**
* Task waiting for the connection to finish connecting.
*/
- struct GNUNET_SCHEDULER_Task * task;
+ struct GNUNET_SCHEDULER_Task *task;
};
* Handle to subsequent connection after proxy handshake completes,
*/
struct GNUNET_CONNECTION_Handle *proxy_handshake;
-
};
addrlen = sizeof (addr);
sock =
- GNUNET_NETWORK_socket_accept (lsock,
- (struct sockaddr *) &addr,
- &addrlen);
+ GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
if (NULL == sock)
{
if (EAGAIN != errno)
sa = (struct sockaddr *) addr;
v6 = (struct sockaddr_in6 *) addr;
- if ( (AF_INET6 == sa->sa_family) &&
- (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)) )
+ if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)))
{
/* convert to V4 address */
v4 = GNUNET_new (struct sockaddr_in);
v4->sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
GNUNET_memcpy (&v4->sin_addr,
- &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) -
- sizeof (struct in_addr)],
- sizeof (struct in_addr));
+ &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) -
+ sizeof (struct in_addr)],
+ sizeof (struct in_addr));
v4->sin_port = v6->sin6_port;
uaddr = v4;
addrlen = sizeof (struct sockaddr_in);
{
#if HAVE_GETPEEREID
/* most BSDs */
- if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock),
- &gc.uid,
- &gc.gid))
+ if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
gcp = &gc;
#else
#ifdef SO_PEERCRED
/* largely traditional GNU/Linux */
olen = sizeof (uc);
- if ( (0 ==
- getsockopt (GNUNET_NETWORK_get_fd (sock),
- SOL_SOCKET,
- SO_PEERCRED,
- &uc,
- &olen)) &&
- (olen == sizeof (uc)) )
+ if ((0 == getsockopt (GNUNET_NETWORK_get_fd (sock),
+ SOL_SOCKET,
+ SO_PEERCRED,
+ &uc,
+ &olen)) &&
+ (olen == sizeof (uc)))
{
gc.uid = uc.uid;
gc.gid = uc.gid;
#endif
}
- if ( (NULL != access_cb) &&
- (GNUNET_YES != (aret = access_cb (access_cb_cls,
- gcp,
- uaddr,
- addrlen))) )
+ if ((NULL != access_cb) &&
+ (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen))))
{
if (GNUNET_NO == aret)
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Access denied to `%s'\n"),
- GNUNET_a2s (uaddr,
- addrlen));
+ _ ("Access denied to `%s'\n"),
+ GNUNET_a2s (uaddr, addrlen));
GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_shutdown (sock,
- SHUT_RDWR));
+ GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
GNUNET_free (uaddr);
return NULL;
connection->addrlen = addrlen;
connection->sock = sock;
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Accepting connection from `%s': %p\n"),
- GNUNET_a2s (uaddr,
- addrlen),
+ _ ("Accepting connection from `%s': %p\n"),
+ GNUNET_a2s (uaddr, addrlen),
connection);
return connection;
}
* @param errcode error code to send
*/
static void
-signal_receive_error (struct GNUNET_CONNECTION_Handle *connection,
- int errcode)
+signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode)
{
GNUNET_CONNECTION_Receiver receiver;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Receive encounters error (%s), connection closed (%p)\n",
- STRERROR (errcode),
+ strerror (errcode),
connection);
GNUNET_assert (NULL != (receiver = connection->receiver));
connection->receiver = NULL;
* @param ecode error code (errno)
*/
static void
-signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection,
- int ecode)
+signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, int ecode)
{
GNUNET_CONNECTION_TransmitReadyNotify notify;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Transmission encounterd error (%s), connection closed (%p)\n",
- STRERROR (ecode),
+ strerror (ecode),
connection);
if (NULL != connection->sock)
{
- (void) GNUNET_NETWORK_socket_shutdown (connection->sock,
- SHUT_RDWR);
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (connection->sock));
+ (void) GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR);
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
connection->sock = NULL;
GNUNET_assert (NULL == connection->write_task);
}
return;
}
if (NULL == connection->nth.notify_ready)
- return; /* nobody to tell about it */
+ return; /* nobody to tell about it */
notify = connection->nth.notify_ready;
connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls,
- 0,
- NULL);
+ notify (connection->nth.notify_ready_cls, 0, NULL);
}
LOG (GNUNET_ERROR_TYPE_INFO,
"Failed to establish TCP connection to `%s:%u', no further addresses to try.\n",
connection->hostname,
- connection->port);
+ connection->port);
GNUNET_break (NULL == connection->ap_head);
GNUNET_break (NULL == connection->ap_tail);
GNUNET_break (GNUNET_NO == connection->dns_active);
/* signal errors for jobs that used to wait on the connection */
connection->destroy_later = 1;
if (NULL != connection->receiver)
- signal_receive_error (connection,
- ECONNREFUSED);
+ signal_receive_error (connection, ECONNREFUSED);
if (NULL != connection->nth.notify_ready)
{
GNUNET_assert (NULL != connection->nth.timeout_task);
GNUNET_SCHEDULER_cancel (connection->nth.timeout_task);
connection->nth.timeout_task = NULL;
- signal_transmit_error (connection,
- ECONNREFUSED);
+ signal_transmit_error (connection, ECONNREFUSED);
}
if (-1 == connection->destroy_later)
{
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connection to `%s' succeeded! (%p)\n",
- GNUNET_a2s (connection->addr,
- connection->addrlen),
+ GNUNET_a2s (connection->addr, connection->addrlen),
connection);
/* trigger jobs that waited for the connection */
if (NULL != connection->receiver)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connection succeeded, starting with receiving data (%p)\n",
- connection);
+ connection);
GNUNET_assert (NULL == connection->read_task);
connection->read_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
- (connection->receive_timeout),
- connection->sock,
- &receive_ready, connection);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (
+ connection->receive_timeout),
+ connection->sock,
+ &receive_ready,
+ connection);
}
if (NULL != connection->nth.notify_ready)
{
connection->nth.timeout_task = NULL;
GNUNET_assert (connection->write_task == NULL);
connection->write_task =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
- (connection->nth.transmit_timeout), connection->sock,
- &transmit_ready, connection);
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining (
+ connection->nth.transmit_timeout),
+ connection->sock,
+ &transmit_ready,
+ connection);
}
}
socklen_t len;
GNUNET_assert (NULL != ap->sock);
- GNUNET_CONTAINER_DLL_remove (connection->ap_head,
- connection->ap_tail,
- ap);
+ GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap);
len = sizeof (error);
errno = 0;
error = 0;
tc = GNUNET_SCHEDULER_get_task_context ();
- if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
- (GNUNET_OK !=
- GNUNET_NETWORK_socket_getsockopt (ap->sock,
- SOL_SOCKET,
- SO_ERROR,
- &error,
- &len)) ||
- (0 != error) )
+ if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
+ (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt (ap->sock,
+ SOL_SOCKET,
+ SO_ERROR,
+ &error,
+ &len)) ||
+ (0 != error))
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (ap->sock));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
GNUNET_free (ap);
- if ( (NULL == connection->ap_head) &&
- (GNUNET_NO == connection->dns_active) &&
- (NULL == connection->proxy_handshake) )
+ if ((NULL == connection->ap_head) &&
+ (GNUNET_NO == connection->dns_active) &&
+ (NULL == connection->proxy_handshake))
connect_fail_continuation (connection);
return;
}
{
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
GNUNET_SCHEDULER_cancel (pos->task);
- GNUNET_CONTAINER_DLL_remove (connection->ap_head,
- connection->ap_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
GNUNET_free (pos);
}
connect_success_continuation (connection);
if (NULL == addr)
{
connection->dns_active = NULL;
- if ((NULL == connection->ap_head) &&
- (NULL == connection->sock) &&
+ if ((NULL == connection->ap_head) && (NULL == connection->sock) &&
(NULL == connection->proxy_handshake))
connect_fail_continuation (connection);
return;
}
if (NULL != connection->sock)
- return; /* already connected */
+ return; /* already connected */
GNUNET_assert (NULL == connection->addr);
/* try to connect */
LOG (GNUNET_ERROR_TYPE_DEBUG,
default:
GNUNET_break (0);
GNUNET_free (ap);
- return; /* not supported by us */
+ return; /* not supported by us */
}
- ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family,
- SOCK_STREAM, 0);
+ ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
if (NULL == ap->sock)
{
GNUNET_free (ap);
- return; /* not supported by OS */
+ return; /* not supported by OS */
}
LOG (GNUNET_ERROR_TYPE_INFO,
"Trying to connect to `%s' (%p)\n",
GNUNET_a2s (ap->addr, ap->addrlen),
connection);
if ((GNUNET_OK !=
- GNUNET_NETWORK_socket_connect (ap->sock,
- ap->addr,
- ap->addrlen)) &&
+ GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
(EINPROGRESS != errno))
{
/* maybe refused / unsupported address, try next */
delay = CONNECT_RETRY_TIMEOUT;
if (NULL != connection->nth.notify_ready)
delay = GNUNET_TIME_relative_min (delay,
- GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout));
+ GNUNET_TIME_absolute_get_remaining (
+ connection->nth.transmit_timeout));
if (NULL != connection->receiver)
delay = GNUNET_TIME_relative_min (delay,
- GNUNET_TIME_absolute_get_remaining (connection->receive_timeout));
+ GNUNET_TIME_absolute_get_remaining (
+ connection->receive_timeout));
ap->task = GNUNET_SCHEDULER_add_write_net (delay,
- ap->sock,
- &connect_probe_continuation,
- ap);
+ ap->sock,
+ &connect_probe_continuation,
+ ap);
}
* @return the connection handle
*/
struct GNUNET_CONNECTION_Handle *
-GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *hostname,
- uint16_t port)
+GNUNET_CONNECTION_create_from_connect (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *hostname,
+ uint16_t port)
{
struct GNUNET_CONNECTION_Handle *connection;
- GNUNET_assert (0 < strlen (hostname)); /* sanity check */
+ GNUNET_assert (0 < strlen (hostname)); /* sanity check */
connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
connection->cfg = cfg;
connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
connection->port = port;
connection->hostname = GNUNET_strdup (hostname);
- connection->dns_active =
- GNUNET_RESOLVER_ip_get (connection->hostname,
- AF_UNSPEC,
- CONNECT_RETRY_TIMEOUT,
- &try_connect_using_address,
- connection);
+ connection->dns_active = GNUNET_RESOLVER_ip_get (connection->hostname,
+ AF_UNSPEC,
+ CONNECT_RETRY_TIMEOUT,
+ &try_connect_using_address,
+ connection);
return connection;
}
* @return the connection handle, NULL on systems without UNIX support
*/
struct GNUNET_CONNECTION_Handle *
-GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *unixpath)
+GNUNET_CONNECTION_create_from_connect_to_unixpath (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *unixpath)
{
#ifdef AF_UNIX
struct GNUNET_CONNECTION_Handle *connection;
struct sockaddr_un *un;
- GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
+ GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
un = GNUNET_new (struct sockaddr_un);
un->sun_family = AF_UNIX;
GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path));
int abstract;
abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "TESTING",
+ "TESTING",
"USE_ABSTRACT_SOCKETS");
if (GNUNET_YES == abstract)
un->sun_path[0] = '\0';
connection->hostname = NULL;
connection->addr = (struct sockaddr *) un;
connection->addrlen = sizeof (struct sockaddr_un);
- connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX,
- SOCK_STREAM,
- 0);
+ connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
if (NULL == connection->sock)
{
GNUNET_free (connection->addr);
GNUNET_free (connection);
return NULL;
}
- if ( (GNUNET_OK !=
- GNUNET_NETWORK_socket_connect (connection->sock,
- connection->addr,
- connection->addrlen)) &&
- (EINPROGRESS != errno) )
+ if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (connection->sock,
+ connection->addr,
+ connection->addrlen)) &&
+ (EINPROGRESS != errno))
{
/* Just return; we expect everything to work eventually so don't fail HARD */
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (connection->sock));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
connection->sock = NULL;
return connection;
}
{
struct GNUNET_CONNECTION_Handle *connection;
- if ( (GNUNET_OK !=
- GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) &&
- (EINPROGRESS != errno) )
+ if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) &&
+ (EINPROGRESS != errno))
{
/* maybe refused / unsupported address, try next */
- LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG,
- "connect");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "connect");
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Attempt to connect to `%s' failed\n",
- GNUNET_a2s (serv_addr,
- addrlen));
+ GNUNET_a2s (serv_addr, addrlen));
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
return NULL;
}
s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
if (NULL == s)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
- "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
return NULL;
}
- return GNUNET_CONNECTION_connect_socket (s,
- serv_addr,
- addrlen);
+ return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen);
}
int
GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection)
{
- if ((NULL != connection->ap_head) ||
- (NULL != connection->dns_active) ||
+ if ((NULL != connection->ap_head) || (NULL != connection->dns_active) ||
(NULL != connection->proxy_handshake))
- return GNUNET_YES; /* still trying to connect */
- if ( (0 != connection->destroy_later) ||
- (NULL == connection->sock) )
+ return GNUNET_YES; /* still trying to connect */
+ if ((0 != connection->destroy_later) || (NULL == connection->sock))
return GNUNET_NO;
return GNUNET_YES;
}
connection->destroy_later = -1;
return;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Shutting down connection (%p)\n",
- connection);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection);
GNUNET_assert (NULL == connection->nth.notify_ready);
GNUNET_assert (NULL == connection->receiver);
if (NULL != connection->write_task)
{
/* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */
connection->proxy_handshake->destroy_later = -1;
- connection->proxy_handshake = NULL; /* Not leaked ??? */
+ connection->proxy_handshake = NULL; /* Not leaked ??? */
}
while (NULL != (pos = connection->ap_head))
{
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
GNUNET_SCHEDULER_cancel (pos->task);
- GNUNET_CONTAINER_DLL_remove (connection->ap_head,
- connection->ap_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
GNUNET_free (pos);
}
- if ( (NULL != connection->sock) &&
- (GNUNET_YES != connection->persist) )
+ if ((NULL != connection->sock) && (GNUNET_YES != connection->persist))
{
if ((GNUNET_OK !=
- GNUNET_NETWORK_socket_shutdown (connection->sock,
- SHUT_RDWR)) &&
- (ENOTCONN != errno) &&
- (ECONNRESET != errno) )
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "shutdown");
+ GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) &&
+ (ENOTCONN != errno) && (ECONNRESET != errno))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown");
}
if (NULL != connection->sock)
{
}
else
{
- GNUNET_NETWORK_socket_free_memory_only_ (connection->sock); /* at least no memory leak (we deliberately
+ GNUNET_NETWORK_socket_free_memory_only_ (
+ connection->sock); /* at least no memory leak (we deliberately
* leak the socket in this special case) ... */
}
}
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Receive from `%s' encounters error: timeout (%s, %p)\n",
- GNUNET_a2s (connection->addr,
- connection->addrlen),
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout),
- GNUNET_YES),
- connection);
+ "Receive from `%s' encounters error: timeout (%s, %p)\n",
+ GNUNET_a2s (connection->addr, connection->addrlen),
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (
+ connection->receive_timeout),
+ GNUNET_YES),
+ connection);
signal_receive_timeout (connection);
return;
}
signal_receive_error (connection, ECONNREFUSED);
return;
}
- GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- connection->sock));
+ GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock));
RETRY:
- ret = GNUNET_NETWORK_socket_recv (connection->sock,
- buffer,
- connection->max);
+ ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max);
if (-1 == ret)
{
if (EINTR == errno)
"receive_ready read %u/%u bytes from `%s' (%p)!\n",
(unsigned int) ret,
connection->max,
- GNUNET_a2s (connection->addr,
- connection->addrlen),
+ GNUNET_a2s (connection->addr, connection->addrlen),
connection);
GNUNET_assert (NULL != (receiver = connection->receiver));
connection->receiver = NULL;
if (NULL != connection->sock)
{
connection->read_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
- (connection->receive_timeout),
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (
+ connection->receive_timeout),
connection->sock,
&receive_ready,
connection);
return GNUNET_OK;
}
- if ((NULL == connection->dns_active) &&
- (NULL == connection->ap_head) &&
+ if ((NULL == connection->dns_active) && (NULL == connection->ap_head) &&
(NULL == connection->proxy_handshake))
{
connection->receiver = NULL;
- receiver (receiver_cls,
- NULL, 0,
- NULL, 0,
- ETIMEDOUT);
+ receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
return GNUNET_SYSERR;
}
return GNUNET_OK;
size_t size;
GNUNET_CONNECTION_TransmitReadyNotify notify;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "process_notify is running\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n");
GNUNET_assert (NULL == connection->write_task);
if (NULL == (notify = connection->nth.notify_ready))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "No one to notify\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n");
return GNUNET_NO;
}
used = connection->write_buffer_off - connection->write_buffer_pos;
size = connection->nth.notify_size;
if (size > avail)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Not enough buffer\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n");
return GNUNET_NO;
}
connection->nth.notify_ready = NULL;
}
avail = connection->write_buffer_size - connection->write_buffer_off;
GNUNET_assert (avail >= size);
- size =
- notify (connection->nth.notify_ready_cls, avail,
- &connection->write_buffer[connection->write_buffer_off]);
+ size = notify (connection->nth.notify_ready_cls,
+ avail,
+ &connection->write_buffer[connection->write_buffer_off]);
GNUNET_assert (size <= avail);
if (0 != size)
connection->write_buffer_off += size;
"Transmit to `%s:%u/%s' fails, time out reached (%p).\n",
connection->hostname,
connection->port,
- GNUNET_a2s (connection->addr,
- connection->addrlen),
+ GNUNET_a2s (connection->addr, connection->addrlen),
connection);
notify = connection->nth.notify_ready;
GNUNET_assert (NULL != notify);
connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls,
- 0,
- NULL);
+ notify (connection->nth.notify_ready_cls, 0, NULL);
}
connection->write_task = NULL;
notify = connection->nth.notify_ready;
connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls,
- 0,
- NULL);
+ notify (connection->nth.notify_ready_cls, 0, NULL);
}
ssize_t ret;
size_t have;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "transmit_ready running (%p).\n",
- connection);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection);
GNUNET_assert (NULL != connection->write_task);
connection->write_task = NULL;
GNUNET_assert (NULL == connection->nth.timeout_task);
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Transmit to `%s' fails, time out reached (%p).\n",
- GNUNET_a2s (connection->addr,
- connection->addrlen),
+ GNUNET_a2s (connection->addr, connection->addrlen),
connection);
notify = connection->nth.notify_ready;
GNUNET_assert (NULL != notify);
* Hence retry. */
goto SCHEDULE_WRITE;
}
- if (! GNUNET_NETWORK_fdset_isset (tc->write_ready,
- connection->sock))
+ if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock))
{
GNUNET_assert (NULL == connection->write_task);
/* special circumstances (in particular, shutdown): not yet ready
(connection->write_buffer_size < connection->nth.notify_size))
{
connection->write_buffer =
- GNUNET_realloc (connection->write_buffer, connection->nth.notify_size);
+ GNUNET_realloc (connection->write_buffer, connection->nth.notify_size);
connection->write_buffer_size = connection->nth.notify_size;
}
process_notify (connection);
return;
}
GNUNET_assert (have <= connection->write_buffer_size);
- GNUNET_assert (have + connection->write_buffer_pos <= connection->write_buffer_size);
+ GNUNET_assert (have + connection->write_buffer_pos <=
+ connection->write_buffer_size);
GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size);
RETRY:
ret =
- GNUNET_NETWORK_socket_send (connection->sock,
- &connection->write_buffer[connection->write_buffer_pos],
- have);
+ GNUNET_NETWORK_socket_send (connection->sock,
+ &connection
+ ->write_buffer[connection->write_buffer_pos],
+ have);
if (-1 == ret)
{
if (EINTR == errno)
"Connection transmitted %u/%u bytes to `%s' (%p)\n",
(unsigned int) ret,
have,
- GNUNET_a2s (connection->addr,
- connection->addrlen),
+ GNUNET_a2s (connection->addr, connection->addrlen),
connection);
connection->write_buffer_pos += ret;
if (connection->write_buffer_pos == connection->write_buffer_off)
connection->write_buffer_pos = 0;
connection->write_buffer_off = 0;
}
- if ( (0 == connection->write_buffer_off) &&
- (NULL == connection->nth.notify_ready) )
- return; /* all data sent! */
+ if ((0 == connection->write_buffer_off) &&
+ (NULL == connection->nth.notify_ready))
+ return; /* all data sent! */
/* not done writing, schedule more */
SCHEDULE_WRITE:
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Re-scheduling transmit_ready (more to do) (%p).\n",
connection);
have = connection->write_buffer_off - connection->write_buffer_pos;
- GNUNET_assert ( (NULL != connection->nth.notify_ready) ||
- (have > 0) );
+ GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0));
if (NULL == connection->write_task)
connection->write_task =
- GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready ==
- NULL) ? GNUNET_TIME_UNIT_FOREVER_REL :
- GNUNET_TIME_absolute_get_remaining
- (connection->nth.transmit_timeout),
- connection->sock,
- &transmit_ready, connection);
+ GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == NULL)
+ ? GNUNET_TIME_UNIT_FOREVER_REL
+ : GNUNET_TIME_absolute_get_remaining (
+ connection->nth.transmit_timeout),
+ connection->sock,
+ &transmit_ready,
+ connection);
}
* NULL if we are already going to notify someone else (busy)
*/
struct GNUNET_CONNECTION_TransmitHandle *
-GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection,
- size_t size,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_TransmitReadyNotify notify,
- void *notify_cls)
+GNUNET_CONNECTION_notify_transmit_ready (
+ struct GNUNET_CONNECTION_Handle *connection,
+ size_t size,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_CONNECTION_TransmitReadyNotify notify,
+ void *notify_cls)
{
if (NULL != connection->nth.notify_ready)
{
connection->nth.notify_size = size;
connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
GNUNET_assert (NULL == connection->nth.timeout_task);
- if ((NULL == connection->sock) &&
- (NULL == connection->ap_head) &&
- (NULL == connection->dns_active) &&
- (NULL == connection->proxy_handshake))
+ if ((NULL == connection->sock) && (NULL == connection->ap_head) &&
+ (NULL == connection->dns_active) && (NULL == connection->proxy_handshake))
{
if (NULL != connection->write_task)
GNUNET_SCHEDULER_cancel (connection->write_task);
- connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error,
- connection);
+ connection->write_task =
+ GNUNET_SCHEDULER_add_now (&connect_error, connection);
return &connection->nth;
}
if (NULL != connection->write_task)
"Scheduling transmission (%p).\n",
connection);
connection->write_task =
- GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
- (connection->nth.transmit_timeout),
- connection->sock,
- &transmit_ready, connection);
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining (
+ connection->nth.transmit_timeout),
+ connection->sock,
+ &transmit_ready,
+ connection);
return &connection->nth;
}
/* not yet connected, wait for connection */
"Need to wait to schedule transmission for connection, adding timeout task (%p).\n",
connection);
connection->nth.timeout_task =
- GNUNET_SCHEDULER_add_delayed (timeout,
- &transmit_timeout,
- connection);
+ GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection);
return &connection->nth;
}
* @param th notification to cancel
*/
void
-GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_TransmitHandle *th)
+GNUNET_CONNECTION_notify_transmit_ready_cancel (
+ struct GNUNET_CONNECTION_TransmitHandle *th)
{
GNUNET_assert (NULL != th->notify_ready);
th->notify_ready = NULL;
* @return connection to be proxied
*/
struct GNUNET_CONNECTION_Handle *
-GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph)
+GNUNET_CONNECTION_create_proxied_from_handshake (
+ struct GNUNET_CONNECTION_Handle *cph)
{
- struct GNUNET_CONNECTION_Handle *proxied = GNUNET_CONNECTION_create_from_existing (NULL);
+ struct GNUNET_CONNECTION_Handle *proxied =
+ GNUNET_CONNECTION_create_from_existing (NULL);
proxied->proxy_handshake = cph;
return proxied;
* Our options.
*/
enum LEGACY_SERVICE_Options options;
-
};
if (size < sizeof (struct GNUNET_MessageHeader))
{
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return 0; /* client disconnected */
+ return 0; /* client disconnected */
}
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
* @param message the actual message
*/
static void
-handle_test (void *cls, struct GNUNET_SERVER_Client *client,
+handle_test (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
/* simply bounce message back to acknowledge */
GNUNET_SERVER_notify_transmit_ready (client,
sizeof (struct GNUNET_MessageHeader),
GNUNET_TIME_UNIT_FOREVER_REL,
- &write_test, client))
+ &write_test,
+ client))
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
}
* "callback_cls" fields will be replaced with the specific service
* struct.
*/
-static const struct GNUNET_SERVER_MessageHandler defhandlers[] = {
- {&handle_test, NULL, GNUNET_MESSAGE_TYPE_TEST,
- sizeof (struct GNUNET_MessageHeader)},
- {NULL, NULL, 0, 0}
-};
+static const struct GNUNET_SERVER_MessageHandler defhandlers[] =
+ {{&handle_test,
+ NULL,
+ GNUNET_MESSAGE_TYPE_TEST,
+ sizeof (struct GNUNET_MessageHeader)},
+ {NULL, NULL, 0, 0}};
/* ****************** service core routines ************** */
* for unknown address family (will be denied).
*/
static int
-check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc,
- const struct sockaddr *addr, socklen_t addrlen)
+check_access (void *cls,
+ const struct GNUNET_CONNECTION_Credentials *uc,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
{
struct LEGACY_SERVICE_Context *sctx = cls;
const struct sockaddr_in *i4;
i4 = (const struct sockaddr_in *) addr;
ret = ((NULL == sctx->v4_allowed) ||
(check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
- ((NULL == sctx->v4_denied) ||
- (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
+ ((NULL == sctx->v4_denied) ||
+ (! check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
break;
case AF_INET6:
GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
i6 = (const struct sockaddr_in6 *) addr;
ret = ((NULL == sctx->v6_allowed) ||
(check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
- ((NULL == sctx->v6_denied) ||
- (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
+ ((NULL == sctx->v6_denied) ||
+ (! check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
break;
#ifndef WINDOWS
case AF_UNIX:
- ret = GNUNET_OK; /* controlled using file-system ACL now */
+ ret = GNUNET_OK; /* controlled using file-system ACL now */
break;
#endif
default:
- LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"),
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _ ("Unknown address family %d\n"),
addr->sa_family);
return GNUNET_SYSERR;
}
if (GNUNET_OK != ret)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Access from `%s' denied to service `%s'\n"),
- GNUNET_a2s (addr, addrlen),
+ _ ("Access from `%s' denied to service `%s'\n"),
+ GNUNET_a2s (addr, addrlen),
sctx->service_name);
}
return ret;
{
char *pif;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name,
- "PIDFILE", &pif))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg,
+ sctx->service_name,
+ "PIDFILE",
+ &pif))
return NULL;
return pif;
}
{
char *opt;
- if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
+ if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
GNUNET_break (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
sctx->service_name,
- option, &opt));
+ option,
+ &opt));
if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt)))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
- opt, sctx->service_name, option);
+ _ ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
+ opt,
+ sctx->service_name,
+ option);
GNUNET_free (opt);
return GNUNET_SYSERR;
}
{
char *opt;
- if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
+ if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
GNUNET_break (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
sctx->service_name,
- option, &opt));
+ option,
+ &opt));
if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt)))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
- opt, sctx->service_name, option);
+ _ ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
+ opt,
+ sctx->service_name,
+ option);
GNUNET_free (opt);
return GNUNET_SYSERR;
}
* set to NULL).
*/
int
-LEGACY_SERVICE_get_server_addresses (const char *service_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct sockaddr ***addrs,
- socklen_t ** addr_lens)
+LEGACY_SERVICE_get_server_addresses (
+ const char *service_name,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct sockaddr ***addrs,
+ socklen_t **addr_lens)
{
int disablev6;
struct GNUNET_NETWORK_Handle *desc;
if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
{
if (GNUNET_SYSERR ==
- (disablev6 =
- GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
+ (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ service_name,
+ "DISABLEV6")))
return GNUNET_SYSERR;
}
else
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
- service_name, STRERROR (errno));
+ _ (
+ "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
+ service_name,
+ strerror (errno));
disablev6 = GNUNET_YES;
}
else
port = 0;
if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, service_name,
- "PORT", &port))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ service_name,
+ "PORT",
+ &port))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
}
if (port > 65535)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
return GNUNET_SYSERR;
}
if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
{
GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, service_name,
- "BINDTO", &hostname));
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ service_name,
+ "BINDTO",
+ &hostname));
}
else
hostname = NULL;
#ifdef AF_UNIX
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH",
- &unixpath)) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
+ service_name,
+ "UNIXPATH",
+ &unixpath)) &&
(0 < strlen (unixpath)))
{
/* probe UNIX support */
if (strlen (unixpath) >= sizeof (s_un.sun_path))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
+ _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
+ unixpath,
(unsigned long long) sizeof (s_un.sun_path));
unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("Using `%s' instead\n"),
- unixpath);
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
}
#ifdef LINUX
abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
if (GNUNET_SYSERR == abstract)
abstract = GNUNET_NO;
#endif
- if ((GNUNET_YES != abstract)
- && (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (unixpath)))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "mkdir",
- unixpath);
+ if ((GNUNET_YES != abstract) &&
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
}
if (NULL != unixpath)
{
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
+ _ (
+ "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
service_name,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (unixpath);
unixpath = NULL;
}
if ((0 == port) && (NULL == unixpath))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
+ _ (
+ "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
service_name);
GNUNET_free_non_null (hostname);
return GNUNET_SYSERR;
(NULL == res))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to resolve `%s': %s\n"),
+ _ ("Failed to resolve `%s': %s\n"),
hostname,
gai_strerror (ret));
GNUNET_free (hostname);
if (0 == i)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to find %saddress for `%s'.\n"),
+ _ ("Failed to find %saddress for `%s'.\n"),
disablev6 ? "IPv4 " : "",
hostname);
freeaddrinfo (res);
if ((disablev6) && (AF_INET6 == pos->ai_family))
continue;
if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
- continue; /* not TCP */
+ continue; /* not TCP */
if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
- continue; /* huh? */
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
- service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
+ continue; /* huh? */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' will bind to `%s'\n",
+ service_name,
+ GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
if (AF_INET == pos->ai_family)
{
GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
* to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
*/
lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10);
- if ( (0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
+ if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
return GNUNET_NO;
fail = 1;
do
if ((0 == ret) || (sizeof (count) != rd) || (0 == count))
break;
sctx->lsocks =
- GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1));
+ GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1));
fail2 = 1;
for (i = 0; i < count; i++)
SOCKET s;
ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL);
- if ( (0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size) )
+ if ((0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size))
break;
ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL);
- if ( (0 == ret) || (sizeof (pi) != rd))
+ if ((0 == ret) || (sizeof (pi) != rd))
break;
- s = WSASocketA (pi.iAddressFamily, pi.iSocketType, pi.iProtocol, &pi, 0, WSA_FLAG_OVERLAPPED);
+ s = WSASocketA (pi.iAddressFamily,
+ pi.iSocketType,
+ pi.iProtocol,
+ &pi,
+ 0,
+ WSA_FLAG_OVERLAPPED);
sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native (s);
if (NULL == sctx->lsocks[i])
break;
break;
sctx->lsocks[count] = NULL;
fail = 0;
- }
- while (fail);
+ } while (fail);
CloseHandle (lsocks_pipe);
if (fail)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access a pre-bound socket, will try to bind myself\n"));
+ _ ("Could not access a pre-bound socket, will try to bind myself\n"));
for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++)
GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[i]));
GNUNET_free_non_null (sctx->lsocks);
int flags;
#endif
- if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, "TIMEOUT"))
+ if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
+ sctx->service_name,
+ "TIMEOUT"))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->service_name,
- "TIMEOUT", &idleout))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg,
+ sctx->service_name,
+ "TIMEOUT",
+ &idleout))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Specified value for `%s' of service `%s' is invalid\n"),
- "TIMEOUT", sctx->service_name);
+ _ ("Specified value for `%s' of service `%s' is invalid\n"),
+ "TIMEOUT",
+ sctx->service_name);
return GNUNET_SYSERR;
}
sctx->timeout = idleout;
else
sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
- if (GNUNET_CONFIGURATION_have_value
- (sctx->cfg, sctx->service_name, "TOLERANT"))
+ if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
+ sctx->service_name,
+ "TOLERANT"))
{
if (GNUNET_SYSERR ==
- (tolerant =
- GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name,
- "TOLERANT")))
+ (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
+ sctx->service_name,
+ "TOLERANT")))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Specified value for `%s' of service `%s' is invalid\n"),
- "TOLERANT", sctx->service_name);
+ _ ("Specified value for `%s' of service `%s' is invalid\n"),
+ "TOLERANT",
+ sctx->service_name);
return GNUNET_SYSERR;
}
}
#ifndef MINGW
errno = 0;
if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
- (1 == SSCANF (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
+ (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
(cnt + 4 < FD_SETSIZE))
{
sctx->lsocks =
- GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
+ GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
while (0 < cnt--)
{
flags = fcntl (3 + cnt, F_GETFD);
(sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Could not access pre-bound socket %u, will try to bind myself\n"),
+ _ (
+ "Could not access pre-bound socket %u, will try to bind myself\n"),
(unsigned int) 3 + cnt);
cnt++;
while (sctx->lsocks[cnt] != NULL)
#endif
if ((NULL == sctx->lsocks) &&
- (GNUNET_SYSERR ==
- LEGACY_SERVICE_get_server_addresses (sctx->service_name, sctx->cfg,
- &sctx->addrs, &sctx->addrlens)))
+ (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses (sctx->service_name,
+ sctx->cfg,
+ &sctx->addrs,
+ &sctx->addrlens)))
return GNUNET_SYSERR;
sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
- sctx->match_uid =
- GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name,
- "UNIX_MATCH_UID");
- sctx->match_gid =
- GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name,
- "UNIX_MATCH_GID");
+ sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
+ sctx->service_name,
+ "UNIX_MATCH_UID");
+ sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
+ sctx->service_name,
+ "UNIX_MATCH_GID");
process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM");
process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM");
process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6");
{
char *un;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name,
- "USERNAME", &un))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg,
+ sctx->service_name,
+ "USERNAME",
+ &un))
return NULL;
return un;
}
int len;
if (NULL == (pif = get_pid_file_name (sctx)))
- return GNUNET_OK; /* no file desired */
+ return GNUNET_OK; /* no file desired */
user = get_user_name (sctx);
rdir = GNUNET_strdup (pif);
len = strlen (rdir);
while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
len--;
rdir[len] = '\0';
- if (0 != ACCESS (rdir, F_OK))
+ if (0 != access (rdir, F_OK))
{
/* we get to create a directory -- and claim it
* as ours! */
if ((NULL != user) && (0 < strlen (user)))
GNUNET_DISK_file_change_owner (rdir, user);
}
- if (0 != ACCESS (rdir, W_OK | X_OK))
+ if (0 != access (rdir, W_OK | X_OK))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
GNUNET_free (rdir);
return GNUNET_SYSERR;
}
GNUNET_free (rdir);
- pidfd = FOPEN (pif, "w");
+ pidfd = fopen (pif, "w");
if (NULL == pidfd)
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
GNUNET_free_non_null (user);
return GNUNET_SYSERR;
}
- if (0 > FPRINTF (pidfd, "%u", pid))
+ if (0 > fprintf (pidfd, "%u", pid))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
- GNUNET_break (0 == FCLOSE (pidfd));
+ GNUNET_break (0 == fclose (pidfd));
if ((NULL != user) && (0 < strlen (user)))
GNUNET_DISK_file_change_owner (pif, user);
GNUNET_free_non_null (user);
GNUNET_RESOLVER_connect (sctx->cfg);
if (NULL != sctx->lsocks)
- sctx->server
- = GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
- sctx->timeout, sctx->require_found);
+ sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
+ sctx,
+ sctx->lsocks,
+ sctx->timeout,
+ sctx->require_found);
else
- sctx->server
- = GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
- sctx->timeout, sctx->require_found);
+ sctx->server = GNUNET_SERVER_create (&check_access,
+ sctx,
+ sctx->addrs,
+ sctx->addrlens,
+ sctx->timeout,
+ sctx->require_found);
if (NULL == sctx->server)
{
if (NULL != sctx->addrs)
for (i = 0; NULL != sctx->addrs[i]; i++)
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Failed to start `%s' at `%s'\n"),
- sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
+ _ ("Failed to start `%s' at `%s'\n"),
+ sctx->service_name,
+ GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
sctx->ret = GNUNET_SYSERR;
return;
}
#ifndef WINDOWS
if (NULL != sctx->addrs)
for (i = 0; NULL != sctx->addrs[i]; i++)
- if ((AF_UNIX == sctx->addrs[i]->sa_family)
- && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
- GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
+ if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
+ ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
+ GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
+ sctx->addrs[i])
+ ->sun_path,
sctx->match_uid,
sctx->match_gid);
#endif
{
/* install a task that will kill the server
* process if the scheduler ever gets a shutdown signal */
- sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- sctx);
+ sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, sctx);
}
sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
if (-1 != sctx->ready_confirm_fd)
{
- GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1));
- GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd));
+ GNUNET_break (1 == write (sctx->ready_confirm_fd, ".", 1));
+ GNUNET_break (0 == close (sctx->ready_confirm_fd));
sctx->ready_confirm_fd = -1;
write_pid_file (sctx, getpid ());
}
i = 0;
while (NULL != sctx->addrs[i])
{
- LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"),
- sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _ ("Service `%s' runs at %s\n"),
+ sctx->service_name,
+ GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
i++;
}
}
int nullfd;
int filedes[2];
- if (0 != PIPE (filedes))
+ if (0 != pipe (filedes))
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
return GNUNET_SYSERR;
/* Parent */
char c;
- GNUNET_break (0 == CLOSE (filedes[1]));
+ GNUNET_break (0 == close (filedes[1]));
c = 'X';
- if (1 != READ (filedes[0], &c, sizeof (char)))
+ if (1 != read (filedes[0], &c, sizeof (char)))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
fflush (stdout);
switch (c)
case '.':
exit (0);
case 'I':
- LOG (GNUNET_ERROR_TYPE_INFO, _("Service process failed to initialize\n"));
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _ ("Service process failed to initialize\n"));
break;
case 'S':
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process could not initialize server function\n"));
+ _ ("Service process could not initialize server function\n"));
break;
case 'X':
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process failed to report status\n"));
+ _ ("Service process failed to report status\n"));
break;
}
- exit (1); /* child reported error */
+ exit (1); /* child reported error */
}
- GNUNET_break (0 == CLOSE (0));
- GNUNET_break (0 == CLOSE (1));
- GNUNET_break (0 == CLOSE (filedes[0]));
- nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND);
+ GNUNET_break (0 == close (0));
+ GNUNET_break (0 == close (1));
+ GNUNET_break (0 == close (filedes[0]));
+ nullfd = open ("/dev/null", O_RDWR | O_APPEND);
if (nullfd < 0)
return GNUNET_SYSERR;
/* set stdin/stdout to /dev/null */
if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
- (void) CLOSE (nullfd);
+ (void) close (nullfd);
return GNUNET_SYSERR;
}
- (void) CLOSE (nullfd);
+ (void) close (nullfd);
/* Detach from controlling terminal */
pid = setsid ();
if (-1 == pid)
char *user;
if (NULL == (user = get_user_name (sctx)))
- return GNUNET_OK; /* keep */
+ return GNUNET_OK; /* keep */
#ifndef MINGW
struct passwd *pws;
if (NULL == pws)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot obtain information about user `%s': %s\n"), user,
- errno == 0 ? _("No such user") : STRERROR (errno));
+ _ ("Cannot obtain information about user `%s': %s\n"),
+ user,
+ errno == 0 ? _ ("No such user") : strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
(0 != setreuid (pws->pw_uid, pws->pw_uid)))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot change user/group to `%s': %s\n"),
- user, STRERROR (errno));
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Cannot change user/group to `%s': %s\n"),
+ user,
+ strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
char *pif = get_pid_file_name (sctx);
if (NULL == pif)
- return; /* no PID file */
- if (0 != UNLINK (pif))
+ return; /* no PID file */
+ if (0 != unlink (pif))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
GNUNET_free (pif);
}
* if we shutdown nicely
*/
int
-LEGACY_SERVICE_run (int argc, char *const *argv,
+LEGACY_SERVICE_run (int argc,
+ char *const *argv,
const char *service_name,
enum LEGACY_SERVICE_Options options,
LEGACY_SERVICE_Main task,
void *task_cls)
{
-#define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0)
+#define HANDLE_ERROR \
+ do \
+ { \
+ GNUNET_break (0); \
+ goto shutdown; \
+ } while (0)
int err;
int ret;
struct GNUNET_CONFIGURATION_Handle *cfg;
const char *xdg;
- struct GNUNET_GETOPT_CommandLineOption service_options[] = {
- GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn),
- GNUNET_GETOPT_option_flag ('d',
- "daemonize",
- gettext_noop ("do daemonize (detach from terminal)"),
- &do_daemonize),
- GNUNET_GETOPT_option_help (NULL),
- GNUNET_GETOPT_option_loglevel (&loglev),
- GNUNET_GETOPT_option_logfile (&logfile),
- GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption service_options[] =
+ {GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn),
+ GNUNET_GETOPT_option_flag ('d',
+ "daemonize",
+ gettext_noop (
+ "do daemonize (detach from terminal)"),
+ &do_daemonize),
+ GNUNET_GETOPT_option_help (NULL),
+ GNUNET_GETOPT_option_loglevel (&loglev),
+ GNUNET_GETOPT_option_logfile (&logfile),
+ GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
+ GNUNET_GETOPT_OPTION_END};
err = 1;
do_daemonize = 0;
logfile = NULL;
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Malformed configuration file `%s', exit ...\n"),
+ _ ("Malformed configuration file `%s', exit ...\n"),
opt_cfg_fn);
goto shutdown;
}
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Malformed configuration, exit ...\n"));
+ _ ("Malformed configuration, exit ...\n"));
goto shutdown;
}
if (0 != strcmp (opt_cfg_fn, cfg_fn))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access configuration file `%s'\n"),
- opt_cfg_fn);
+ _ ("Could not access configuration file `%s'\n"),
+ opt_cfg_fn);
}
if (GNUNET_OK != setup_service (&sctx))
goto shutdown;
"Service `%s' runs with configuration from `%s'\n",
service_name,
opt_cfg_fn);
- if ((GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
- "SKEW_OFFSET", &skew_offset)) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
- "SKEW_VARIANCE", &skew_variance)))
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
+ "TESTING",
+ "SKEW_OFFSET",
+ &skew_offset)) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
+ "TESTING",
+ "SKEW_VARIANCE",
+ &skew_variance)))
{
clock_offset = skew_offset - skew_variance;
GNUNET_TIME_set_offset (clock_offset);
shutdown:
if (-1 != sctx.ready_confirm_fd)
{
- if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1))
+ if (1 != write (sctx.ready_confirm_fd, err ? "I" : "S", 1))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
- GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd));
+ GNUNET_break (0 == close (sctx.ready_confirm_fd));
}
#if HAVE_MALLINFO
{
char *counter;
- if ( (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (sctx.cfg, service_name,
- "GAUGER_HEAP")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sctx.cfg, service_name,
- "GAUGER_HEAP",
- &counter)) )
+ if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg,
+ service_name,
+ "GAUGER_HEAP")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg,
+ service_name,
+ "GAUGER_HEAP",
+ &counter)))
{
struct mallinfo mi;
struct LEGACY_SERVICE_Context *
LEGACY_SERVICE_start (const char *service_name,
const struct GNUNET_CONFIGURATION_Handle *cfg,
- enum LEGACY_SERVICE_Options options)
+ enum LEGACY_SERVICE_Options options)
{
int i;
struct LEGACY_SERVICE_Context *sctx;
sctx = GNUNET_new (struct LEGACY_SERVICE_Context);
- sctx->ready_confirm_fd = -1; /* no daemonizing */
+ sctx->ready_confirm_fd = -1; /* no daemonizing */
sctx->ret = GNUNET_OK;
sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
sctx->service_name = service_name;
return NULL;
}
if (NULL != sctx->lsocks)
- sctx->server =
- GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
- sctx->timeout, sctx->require_found);
+ sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
+ sctx,
+ sctx->lsocks,
+ sctx->timeout,
+ sctx->require_found);
else
- sctx->server =
- GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
- sctx->timeout, sctx->require_found);
+ sctx->server = GNUNET_SERVER_create (&check_access,
+ sctx,
+ sctx->addrs,
+ sctx->addrlens,
+ sctx->timeout,
+ sctx->require_found);
if (NULL == sctx->server)
{
#ifndef WINDOWS
if (NULL != sctx->addrs)
for (i = 0; NULL != sctx->addrs[i]; i++)
- if ((AF_UNIX == sctx->addrs[i]->sa_family)
- && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
- GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
+ if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
+ ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
+ GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
+ sctx->addrs[i])
+ ->sun_path,
sctx->match_uid,
sctx->match_gid);
#endif
* @return NULL if there are no listen sockets, otherwise NULL-terminated
* array of listen sockets.
*/
-struct GNUNET_NETWORK_Handle *const*
+struct GNUNET_NETWORK_Handle *const *
LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx)
{
return ctx->lsocks;
{
char *counter;
- if ( (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name,
- "GAUGER_HEAP")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sctx->cfg, sctx->service_name,
- "GAUGER_HEAP",
- &counter)) )
+ if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg,
+ sctx->service_name,
+ "GAUGER_HEAP")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
+ sctx->service_name,
+ "GAUGER_HEAP",
+ &counter)))
{
struct mallinfo mi;
delta = 1;
datarate = (total_bytes_recv * 1000 * 1000) / delta;
- FPRINTF (stderr,
+ fprintf (stderr,
"Throughput was %llu b/s\n",
datarate);
ccc->global_ret = GNUNET_OK;
counter++;
if ((DURATION.rel_value_us / 1000 / 1000LL) < counter)
{
- FPRINTF (stderr, "%s", ".\n");
+ fprintf (stderr, "%s", ".\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
&measure,
NULL);
}
result = 0;
- FPRINTF (stderr, "\n");
+ fprintf (stderr, "\n");
if (stats[0].switch_attempts > 0)
{
- FPRINTF (
+ fprintf (
stderr,
"Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n",
stats[0].switch_attempts,
}
else if (stats[0].addresses_avail > 1)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Peer 1 had %u addresses available, but did not try to switch\n",
stats[0].addresses_avail);
}
if (stats[1].switch_attempts > 0)
{
- FPRINTF (
+ fprintf (
stderr,
"Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n",
stats[1].switch_attempts,
}
else if (stats[1].addresses_avail > 1)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Peer 2 had %u addresses available, but did not try to switch\n",
stats[1].addresses_avail);
}
if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
(bytes_sent_after_switch == 0))
{
- FPRINTF (stderr, "No data sent after switching!\n");
+ fprintf (stderr, "No data sent after switching!\n");
GNUNET_break (0);
result++;
}
if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
(bytes_recv_after_switch == 0))
{
- FPRINTF (stderr, "No data received after switching!\n");
+ fprintf (stderr, "No data received after switching!\n");
GNUNET_break (0);
result++;
}
counter++;
if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter)
{
- FPRINTF (stderr, "%s", ".\n");
+ fprintf (stderr, "%s", ".\n");
}
else
{
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
&progress_indicator,
NULL);
if (0 == delta)
delta = 1;
rate = (1000LL* 1000ll * total_bytes) / (1024 * delta);
- FPRINTF (stderr,
+ fprintf (stderr,
"\nThroughput was %llu KiBytes/s\n",
rate);
{
}
if (0 == (n % (TOTAL_MSGS / xhdr / 100)))
{
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
}
if (n == TOTAL_MSGS / xhdr)
{
if (time_running.rel_value_us ==
GNUNET_TIME_relative_max (time_running, WAIT).rel_value_us)
{
- FPRINTF (stderr, "%s", "100%%\n");
+ fprintf (stderr, "%s", "100%%\n");
shutdown_flag = GNUNET_YES;
GNUNET_SCHEDULER_shutdown ();
}
else
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%u%%..",
percentage);
timer_task =
static struct GNUNET_SCHEDULER_Task * stage_task;
#if VERBOSE
-#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
+#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
#else
#define OKPP do { ok++; } while (0)
#endif
#include "platform.h"
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-bio",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-bio", __VA_ARGS__)
#ifndef PATH_MAX
/**
* @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
int
-GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h,
- char **emsg)
+GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
{
int err;
int
GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
const char *what,
- void *result, size_t len)
+ void *result,
+ size_t len)
{
char *dst = result;
size_t min;
{
if (min > len - pos)
min = len - pos;
- GNUNET_memcpy (&dst[pos],
- &h->buffer[h->pos],
- min);
+ GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min);
h->pos += min;
pos += min;
}
if (pos == len)
- return GNUNET_OK; /* done! */
+ return GNUNET_OK; /* done! */
GNUNET_assert (((off_t) h->have) == h->pos);
/* fill buffer */
- ret = GNUNET_DISK_file_read (h->fd,
- h->buffer,
- h->size);
+ ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
if (-1 == ret)
{
GNUNET_asprintf (&h->emsg,
- _("Error reading `%s': %s"),
- what,
- STRERROR (errno));
+ _ ("Error reading `%s': %s"),
+ what,
+ strerror (errno));
return GNUNET_SYSERR;
}
if (0 == ret)
{
GNUNET_asprintf (&h->emsg,
- _("Error reading `%s': %s"),
- what,
- _("End of file"));
+ _ ("Error reading `%s': %s"),
+ what,
+ _ ("End of file"));
return GNUNET_SYSERR;
}
h->pos = 0;
h->have = ret;
- }
- while (pos < len); /* should always be true */
+ } while (pos < len); /* should always be true */
return GNUNET_OK;
}
if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
{
GNUNET_free_non_null (h->emsg);
- GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), what);
+ GNUNET_asprintf (&h->emsg, _ ("Error reading length of string `%s'"), what);
return GNUNET_SYSERR;
}
if (0 == big)
}
if (big > max_length)
{
- GNUNET_asprintf (&h->emsg, _("String `%s' longer than allowed (%u > %u)"),
- what, big, max_length);
+ GNUNET_asprintf (&h->emsg,
+ _ ("String `%s' longer than allowed (%u > %u)"),
+ what,
+ big,
+ max_length);
return GNUNET_SYSERR;
}
buf = GNUNET_malloc (big);
char *buf;
struct GNUNET_CONTAINER_MetaData *meta;
- if (GNUNET_OK !=
- GNUNET_BIO_read_int32 (h,
- (int32_t *) & size))
+ if (GNUNET_OK != GNUNET_BIO_read_int32 (h, (int32_t *) &size))
return GNUNET_SYSERR;
if (size == 0)
{
if (size > MAX_META_DATA)
{
GNUNET_asprintf (&h->emsg,
- _("Serialized metadata `%s' larger than allowed (%u>%u)"),
+ _ ("Serialized metadata `%s' larger than allowed (%u>%u)"),
what,
- size,
- MAX_META_DATA);
+ size,
+ MAX_META_DATA);
return GNUNET_SYSERR;
}
buf = GNUNET_malloc (size);
- if (GNUNET_OK !=
- GNUNET_BIO_read (h,
- what,
- buf,
- size))
+ if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
{
GNUNET_free (buf);
return GNUNET_SYSERR;
}
- meta = GNUNET_CONTAINER_meta_data_deserialize (buf,
- size);
+ meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size);
if (NULL == meta)
{
GNUNET_free (buf);
- GNUNET_asprintf (&h->emsg,
- _("Metadata `%s' failed to deserialize"),
- what);
+ GNUNET_asprintf (&h->emsg, _ ("Metadata `%s' failed to deserialize"), what);
return GNUNET_SYSERR;
}
GNUNET_free (buf);
*/
int
GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
- const char *file,
+ const char *file,
int line,
- int32_t * i)
+ int32_t *i)
{
int32_t big;
- if (GNUNET_OK !=
- GNUNET_BIO_read_fn (h,
- file,
- line,
- &big,
- sizeof (int32_t)))
+ if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int32_t)))
return GNUNET_SYSERR;
*i = ntohl (big);
return GNUNET_OK;
{
int64_t big;
- if (GNUNET_OK !=
- GNUNET_BIO_read_fn (h,
- file,
- line,
- &big,
- sizeof (int64_t)))
+ if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int64_t)))
return GNUNET_SYSERR;
*i = GNUNET_ntohll (big);
return GNUNET_OK;
struct GNUNET_DISK_FileHandle *fd;
struct GNUNET_BIO_WriteHandle *h;
- fd = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
- | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ fd =
+ GNUNET_DISK_file_open (fn,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
return NULL;
h = GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
int ret;
ret = GNUNET_SYSERR;
- if ( (NULL != h->fd) &&
- (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) )
+ if ((NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))))
GNUNET_DISK_file_close (h->fd);
GNUNET_free (h);
return ret;
{
ssize_t ret;
- ret = GNUNET_DISK_file_write (h->fd,
- h->buffer,
- h->have);
+ ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
if (ret != (ssize_t) h->have)
{
GNUNET_DISK_file_close (h->fd);
h->fd = NULL;
- return GNUNET_SYSERR; /* error */
+ return GNUNET_SYSERR; /* error */
}
h->have = 0;
return GNUNET_OK;
*/
int
GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
- const void *buffer,
+ const void *buffer,
size_t n)
{
const char *src = buffer;
min = h->size - h->have;
if (min > n - pos)
min = n - pos;
- GNUNET_memcpy (&h->buffer[h->have],
- &src[pos],
- min);
+ GNUNET_memcpy (&h->buffer[h->have], &src[pos], min);
pos += min;
h->have += min;
if (pos == n)
- return GNUNET_OK; /* done */
+ return GNUNET_OK; /* done */
GNUNET_assert (h->have == h->size);
if (GNUNET_OK != GNUNET_BIO_flush (h))
- return GNUNET_SYSERR; /* error */
- }
- while (pos < n); /* should always be true */
+ return GNUNET_SYSERR; /* error */
+ } while (pos < n); /* should always be true */
GNUNET_break (0);
return GNUNET_OK;
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
- const char *s)
+GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s)
{
uint32_t slen;
if (m == NULL)
return GNUNET_BIO_write_int32 (h, 0);
buf = NULL;
- size =
- GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA,
- GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+ size = GNUNET_CONTAINER_meta_data_serialize (
+ m,
+ &buf,
+ MAX_META_DATA,
+ GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
if (size == -1)
{
GNUNET_free (buf);
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
- int32_t i)
+GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i)
{
int32_t big;
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
- int64_t i)
+GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i)
{
int64_t big;
#include <malloc/malloc.h>
#endif
-#define LOG(kind,...) GNUNET_log_from (kind, "util-common-allocation",__VA_ARGS__)
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "util-common-allocation", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-common-allocation", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-common-allocation", syscall)
#ifndef INT_MAX
#define INT_MAX 0x7FFFFFFF
* @return pointer to size bytes of memory
*/
void *
-GNUNET_xmalloc_ (size_t size,
- const char *filename,
- int linenumber)
+GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
{
void *ret;
/* As a security precaution, we generally do not allow very large
* allocations using the default 'GNUNET_malloc()' macro */
- GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED,
- filename,
- linenumber);
- ret = GNUNET_xmalloc_unchecked_ (size,
- filename,
- linenumber);
+ GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
+ ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
if (NULL == ret)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "malloc");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
GNUNET_assert (0);
}
return ret;
*/
void **
GNUNET_xnew_array_2d_ (size_t n,
- size_t m,
- size_t elementSize,
+ size_t m,
+ size_t elementSize,
const char *filename,
- int linenumber)
+ int linenumber)
{
- /* use char pointer internally to avoid void pointer arithmetic warnings */
- char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */
- n * m * elementSize, /* element data */
- filename, linenumber);
-
- for (size_t i = 0; i < n; i++)
- ret[i] = (char *)ret + /* base address */
- n * sizeof (void *) + /* skip 1. dim header */
- i * m * elementSize; /* skip to 2. dim row header */
- return (void **)ret;
+ /* use char pointer internally to avoid void pointer arithmetic warnings */
+ char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */
+ n * m * elementSize, /* element data */
+ filename,
+ linenumber);
+
+ for (size_t i = 0; i < n; i++)
+ ret[i] = (char *) ret + /* base address */
+ n * sizeof (void *) + /* skip 1. dim header */
+ i * m * elementSize; /* skip to 2. dim row header */
+ return (void **) ret;
}
* @return allocated memory, never NULL
*/
void ***
-GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize,
- const char *filename, int linenumber)
+GNUNET_xnew_array_3d_ (size_t n,
+ size_t m,
+ size_t o,
+ size_t elementSize,
+ const char *filename,
+ int linenumber)
{
- /* use char pointer internally to avoid void pointer arithmetic warnings */
- char ***ret = GNUNET_xmalloc_ (n * sizeof (void **) + /* 1. dim header */
- n * m * sizeof (void *) + /* 2. dim header */
- n * m * o * elementSize, /* element data */
- filename, linenumber);
-
- for (size_t i = 0; i < n; i++)
- {
- /* need to cast to (char *) temporarily for byte level acuracy */
- ret[i] = (char **)((char *)ret + /* base address */
- n * sizeof (void **) + /* skip 1. dim header */
- i * m * sizeof (void *)); /* skip to 2. dim header */
- for (size_t j = 0; j < m; j++)
- ret[i][j] = (char *)ret + /* base address */
- n * sizeof (void **) + /* skip 1. dim header */
- n * m * sizeof (void *) + /* skip 2. dim header */
- i * m * o * elementSize + /* skip to 2. dim part */
- j * o * elementSize; /* skip to 3. dim row data */
- }
- return (void ***)ret;
+ /* use char pointer internally to avoid void pointer arithmetic warnings */
+ char ***ret = GNUNET_xmalloc_ (n * sizeof (void **) + /* 1. dim header */
+ n * m * sizeof (void *) + /* 2. dim header */
+ n * m * o * elementSize, /* element data */
+ filename,
+ linenumber);
+
+ for (size_t i = 0; i < n; i++)
+ {
+ /* need to cast to (char *) temporarily for byte level acuracy */
+ ret[i] = (char **) ((char *) ret + /* base address */
+ n * sizeof (void **) + /* skip 1. dim header */
+ i * m * sizeof (void *)); /* skip to 2. dim header */
+ for (size_t j = 0; j < m; j++)
+ ret[i][j] = (char *) ret + /* base address */
+ n * sizeof (void **) + /* skip 1. dim header */
+ n * m * sizeof (void *) + /* skip 2. dim header */
+ i * m * o * elementSize + /* skip to 2. dim part */
+ j * o * elementSize; /* skip to 3. dim row data */
+ }
+ return (void ***) ret;
}
*/
void *
GNUNET_xmemdup_ (const void *buf,
- size_t size,
- const char *filename,
+ size_t size,
+ const char *filename,
int linenumber)
{
void *ret;
* @return pointer to size bytes of memory, NULL if we do not have enough memory
*/
void *
-GNUNET_xmalloc_unchecked_ (size_t size,
- const char *filename,
- int linenumber)
+GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
{
void *result;
* @return pointer to size bytes of memory
*/
void *
-GNUNET_xrealloc_ (void *ptr,
- size_t n,
- const char *filename,
- int linenumber)
+GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
{
(void) filename;
(void) linenumber;
ptr = realloc (ptr, n);
if ((NULL == ptr) && (n > 0))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "realloc");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc");
GNUNET_assert (0);
}
#ifdef W32_MEM_LIMIT
}
-# if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER == __LITTLE_ENDIAN
#define BAADFOOD_STR "\x0D\xF0\xAD\xBA"
#endif
-# if __BYTE_ORDER == __BIG_ENDIAN
+#if __BYTE_ORDER == __BIG_ENDIAN
#define BAADFOOD_STR "\xBA\xAD\xF0\x0D"
#endif
* @param linenumber where in the code was the call to GNUNET_free
*/
void
-GNUNET_xfree_ (void *ptr,
- const char *filename,
- int linenumber)
+GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
{
- GNUNET_assert_at (NULL != ptr,
- filename,
- linenumber);
+ GNUNET_assert_at (NULL != ptr, filename, linenumber);
#ifdef W32_MEM_LIMIT
ptr = &((size_t *) ptr)[-1];
mem_used -= *((size_t *) ptr);
size_t s = M_SIZE (ptr);
size_t i;
- for (i=0;i<s/8;i++)
+ for (i = 0; i < s / 8; i++)
base[i] = baadfood;
- GNUNET_memcpy (&base[s/8], &baadfood, s % 8);
+ GNUNET_memcpy (&base[s / 8], &baadfood, s % 8);
}
#endif
#endif
* @return `strdup(@a str)`
*/
char *
-GNUNET_xstrdup_ (const char *str,
- const char *filename,
- int linenumber)
+GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber)
{
char *res;
size_t slen;
- GNUNET_assert_at (str != NULL,
- filename,
- linenumber);
+ GNUNET_assert_at (str != NULL, filename, linenumber);
slen = strlen (str) + 1;
- res = GNUNET_xmalloc_ (slen,
- filename,
- linenumber);
- GNUNET_memcpy (res,
- str,
- slen);
+ res = GNUNET_xmalloc_ (slen, filename, linenumber);
+ GNUNET_memcpy (res, str, slen);
return res;
}
#if ! HAVE_STRNLEN
static size_t
-strnlen (const char *s,
- size_t n)
+strnlen (const char *s, size_t n)
{
const char *e;
*/
char *
GNUNET_xstrndup_ (const char *str,
- size_t len,
- const char *filename,
+ size_t len,
+ const char *filename,
int linenumber)
{
char *res;
if (0 == len)
return GNUNET_strdup ("");
- GNUNET_assert_at (NULL != str,
- filename,
- linenumber);
- len = strnlen (str,
- len);
- res = GNUNET_xmalloc_ (len + 1,
- filename,
- linenumber);
+ GNUNET_assert_at (NULL != str, filename, linenumber);
+ len = strnlen (str, len);
+ res = GNUNET_xmalloc_ (len + 1, filename, linenumber);
GNUNET_memcpy (res, str, len);
/* res[len] = '\0'; 'malloc' zeros out anyway */
return res;
*/
void
GNUNET_xgrow_ (void **old,
- size_t elementSize,
- unsigned int *oldCount,
- unsigned int newCount,
- const char *filename,
- int linenumber)
+ size_t elementSize,
+ unsigned int *oldCount,
+ unsigned int newCount,
+ const char *filename,
+ int linenumber)
{
void *tmp;
size_t size;
tmp = GNUNET_xmalloc_ (size, filename, linenumber);
if (NULL != *old)
{
- GNUNET_memcpy (tmp, *old, elementSize * GNUNET_MIN(*oldCount, newCount));
+ GNUNET_memcpy (tmp, *old, elementSize * GNUNET_MIN (*oldCount, newCount));
}
}
* @return number of bytes in `*@a buf`, excluding 0-termination
*/
int
-GNUNET_asprintf (char **buf,
- const char *format,
- ...)
+GNUNET_asprintf (char **buf, const char *format, ...)
{
int ret;
va_list args;
va_start (args, format);
- ret = VSNPRINTF (NULL, 0, format, args);
+ ret = vsnprintf (NULL, 0, format, args);
va_end (args);
GNUNET_assert (ret >= 0);
*buf = GNUNET_malloc (ret + 1);
va_start (args, format);
- ret = VSPRINTF (*buf, format, args);
+ ret = vsprintf (*buf, format, args);
va_end (args);
return ret;
}
* @return number of bytes written to buf or negative value on error
*/
int
-GNUNET_snprintf (char *buf,
- size_t size,
- const char *format, ...)
+GNUNET_snprintf (char *buf, size_t size, const char *format, ...)
{
int ret;
va_list args;
va_start (args, format);
- ret = VSNPRINTF (buf,
- size,
- format,
- args);
+ ret = vsnprintf (buf, size, format, args);
va_end (args);
- GNUNET_assert ( (ret >= 0) &&
- (((size_t) ret) < size) );
+ GNUNET_assert ((ret >= 0) && (((size_t) ret) < size));
return ret;
}
msize = ntohs (msg->size);
GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
ret = GNUNET_malloc (msize);
- GNUNET_memcpy (ret,
- msg,
- msize);
+ GNUNET_memcpy (ret, msg, msize);
return ret;
}
* Note that this message maybe truncated to the first BULK_TRACK_SIZE
* characters, in which case it is NOT 0-terminated!
*/
-static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE]
- __nonstring;
+static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE] __nonstring;
/**
* Type of the last bulk message.
{
/* Note: can't log errors during logging (recursion!), so this
operation MUST silently fail... */
- (void) UNLINK (discard);
+ (void) unlink (discard);
GNUNET_free (discard);
}
rotation[rotation_off % ROTATION_KEEP] = GNUNET_strdup (new_name);
fprintf (stderr,
"Failed to create directory for `%s': %s\n",
fn,
- STRERROR (errno));
+ strerror (errno));
return GNUNET_SYSERR;
}
#if WINDOWS
altlog_fd =
- OPEN (fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE);
+ open (fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE);
#else
- altlog_fd = OPEN (fn,
+ altlog_fd = open (fn,
O_APPEND | O_WRONLY | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
#endif
* this way if the output is going to logfiles or robots
* instead.
*/
- FPRINTF (GNUNET_stderr, "* %s", msg);
+ fprintf (GNUNET_stderr, "* %s", msg);
}
else if (GNUNET_YES == current_async_scope.have_scope)
{
GNUNET_assert (NULL != end);
*end = '\0';
skip_log = 0;
- FPRINTF (GNUNET_stderr,
+ fprintf (GNUNET_stderr,
"%s %s(%s) %s %s",
datestr,
comp,
}
else
{
- FPRINTF (GNUNET_stderr,
+ fprintf (GNUNET_stderr,
"%s %s %s %s",
datestr,
comp,
va_list vacp;
va_copy (vacp, va);
- size = VSNPRINTF (NULL, 0, message, vacp) + 1;
+ size = vsnprintf (NULL, 0, message, vacp) + 1;
GNUNET_assert (0 != size);
va_end (vacp);
memset (date, 0, DATE_STR_SIZE);
abort ();
}
#endif
- VSNPRINTF (buf, size, message, va);
+ vsnprintf (buf, size, message, va);
#if ! (defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY)
if (NULL != tmptr)
(void) setup_log_file (tmptr);
#include "gnunet_configuration_lib.h"
#include "gnunet_disk_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
/**
* @brief configuration entry
* #GNUNET_SYSERR on error (i.e. last save failed)
*/
int dirty;
-
};
*/
int
GNUNET_CONFIGURATION_parse_and_run (const char *filename,
- GNUNET_CONFIGURATION_Callback cb,
- void *cb_cls)
+ GNUNET_CONFIGURATION_Callback cb,
+ void *cb_cls)
{
struct GNUNET_CONFIGURATION_Handle *cfg;
int ret;
cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (cfg,
- filename))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename))
{
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
}
- ret = cb (cb_cls,
- cfg);
+ ret = cb (cb_cls, cfg);
GNUNET_CONFIGURATION_destroy (cfg);
return ret;
}
*/
int
GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *mem,
- size_t size,
- const char *basedir)
+ const char *mem,
+ size_t size,
+ const char *basedir)
{
char *line;
char *line_orig;
}
else
{
- line_orig = GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
+ line_orig =
+ GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
r_bytes += line_size + 1;
}
line = line_orig;
continue;
/* remove tailing whitespace */
- for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));i--)
+ for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));
+ i--)
line[i] = '\0';
/* remove leading whitespace */
- for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++);
+ for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
+ ;
/* ignore comments */
- if ( ('#' == line[0]) || ('%' == line[0]) )
+ if (('#' == line[0]) || ('%' == line[0]))
continue;
/* handle special "@INLINE@" directive */
- if (0 == strncasecmp (line,
- "@INLINE@ ",
- strlen ("@INLINE@ ")))
+ if (0 == strncasecmp (line, "@INLINE@ ", strlen ("@INLINE@ ")))
{
/* @INLINE@ value */
value = &line[strlen ("@INLINE@ ")];
if (NULL != basedir)
{
- char *fn;
-
- GNUNET_asprintf (&fn,
- "%s/%s",
- basedir,
- value);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_parse (cfg,
- fn))
- {
- GNUNET_free (fn);
- ret = GNUNET_SYSERR; /* failed to parse included config */
- break;
- }
- GNUNET_free (fn);
+ char *fn;
+
+ GNUNET_asprintf (&fn, "%s/%s", basedir, value);
+ if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, fn))
+ {
+ GNUNET_free (fn);
+ ret = GNUNET_SYSERR; /* failed to parse included config */
+ break;
+ }
+ GNUNET_free (fn);
}
else
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Ignoring parsing @INLINE@ configurations, not allowed!\n");
- ret = GNUNET_SYSERR;
- break;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Ignoring parsing @INLINE@ configurations, not allowed!\n");
+ ret = GNUNET_SYSERR;
+ break;
}
continue;
}
- if ( ('[' == line[0]) && (']' == line[line_size - 1]) )
+ if (('[' == line[0]) && (']' == line[line_size - 1]))
{
/* [value] */
line[line_size - 1] = '\0';
/* tag = value */
tag = GNUNET_strndup (line, eq - line);
/* remove tailing whitespace */
- for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));i--)
- tag[i] = '\0';
+ for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));
+ i--)
+ tag[i] = '\0';
/* Strip whitespace */
value = eq + 1;
while (isspace ((unsigned char) value[0]))
- value++;
- for (i = strlen (value) - 1; (i >= 1) && (isspace ((unsigned char) value[i]));i--)
- value[i] = '\0';
+ value++;
+ for (i = strlen (value) - 1;
+ (i >= 1) && (isspace ((unsigned char) value[i]));
+ i--)
+ value[i] = '\0';
/* remove quotes */
i = 0;
- if ( ('"' == value[0]) &&
- ('"' == value[strlen (value) - 1]) )
+ if (('"' == value[0]) && ('"' == value[strlen (value) - 1]))
{
- value[strlen (value) - 1] = '\0';
- value++;
+ value[strlen (value) - 1] = '\0';
+ value++;
}
GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
GNUNET_free (tag);
}
/* parse error */
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error while deserializing in line %u\n"),
- nr);
+ _ ("Syntax error while deserializing in line %u\n"),
+ nr);
ret = GNUNET_SYSERR;
break;
}
GNUNET_free_non_null (line_orig);
GNUNET_free (section);
- GNUNET_assert ( (GNUNET_OK != ret) || (r_bytes == size) );
+ GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size));
return ret;
}
ssize_t sret;
fn = GNUNET_STRINGS_filename_expand (filename);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to parse config file `%s'\n",
- fn);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
if (NULL == fn)
return GNUNET_SYSERR;
- dirty = cfg->dirty; /* back up value! */
+ dirty = cfg->dirty; /* back up value! */
if (GNUNET_SYSERR ==
- GNUNET_DISK_file_size (fn,
- &fs64,
- GNUNET_YES,
- GNUNET_YES))
+ GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Error while determining the file size of `%s'\n",
+ "Error while determining the file size of `%s'\n",
fn);
GNUNET_free (fn);
return GNUNET_SYSERR;
}
if (fs64 > SIZE_MAX)
{
- GNUNET_break (0); /* File size is more than the heap size */
+ GNUNET_break (0); /* File size is more than the heap size */
GNUNET_free (fn);
return GNUNET_SYSERR;
}
fs = fs64;
mem = GNUNET_malloc (fs);
- sret = GNUNET_DISK_fn_read (fn,
- mem,
- fs);
- if ( (sret < 0) ||
- (fs != (size_t) sret) )
+ sret = GNUNET_DISK_fn_read (fn, mem, fs);
+ if ((sret < 0) || (fs != (size_t) sret))
{
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Error while reading file `%s'\n"),
- fn);
+ LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn);
GNUNET_free (fn);
GNUNET_free (mem);
return GNUNET_SYSERR;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Deserializing contents of file `%s'\n",
- fn);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn);
endsep = strrchr (fn, (int) '/');
if (NULL != endsep)
*endsep = '\0';
- ret = GNUNET_CONFIGURATION_deserialize (cfg,
- mem,
- fs,
- fn);
+ ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, fn);
GNUNET_free (fn);
GNUNET_free (mem);
/* restore dirty flag - anything we set in the meantime
*/
char *
GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
- size_t *size)
+ size_t *size)
{
struct ConfigSection *sec;
struct ConfigEntry *ent;
{
if (NULL != ent->val)
{
- /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
- pos = ent->val;
- while (NULL != (pos = strstr (pos, "\n")))
- {
- m_size++;
- pos++;
- }
- /* For each key = value pair we need to add 4 characters (2
+ /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
+ pos = ent->val;
+ while (NULL != (pos = strstr (pos, "\n")))
+ {
+ m_size++;
+ pos++;
+ }
+ /* For each key = value pair we need to add 4 characters (2
spaces and 1 equal-to character and 1 new line) */
- m_size += strlen (ent->key) + strlen (ent->val) + 4;
+ m_size += strlen (ent->key) + strlen (ent->val) + 4;
}
}
/* A new line after section end */
{
if (NULL != ent->val)
{
- val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
- strcpy (val, ent->val);
+ val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
+ strcpy (val, ent->val);
while (NULL != (pos = strstr (val, "\n")))
{
memmove (&pos[2], &pos[1], strlen (&pos[1]));
pos[0] = '\\';
pos[1] = 'n';
}
- len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
- GNUNET_free (val);
- GNUNET_memcpy (mem + c_size, cbuf, len);
- c_size += len;
- GNUNET_free (cbuf);
+ len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
+ GNUNET_free (val);
+ GNUNET_memcpy (mem + c_size, cbuf, len);
+ c_size += len;
+ GNUNET_free (cbuf);
}
}
GNUNET_memcpy (mem + c_size, "\n", 1);
- c_size ++;
+ c_size++;
sec = sec->next;
}
GNUNET_assert (c_size == m_size);
return GNUNET_SYSERR;
}
cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size);
- sret = GNUNET_DISK_fn_write (fn, cfg_buf, size,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE
- | GNUNET_DISK_PERM_GROUP_READ
- | GNUNET_DISK_PERM_GROUP_WRITE);
- if ( (sret < 0) ||
- (size != (size_t) sret) )
+ sret = GNUNET_DISK_fn_write (fn,
+ cfg_buf,
+ size,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_GROUP_WRITE);
+ if ((sret < 0) || (size != (size_t) sret))
{
GNUNET_free (fn);
GNUNET_free (cfg_buf);
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Writing configuration to file `%s' failed\n",
+ "Writing configuration to file `%s' failed\n",
filename);
cfg->dirty = GNUNET_SYSERR; /* last write failed */
return GNUNET_SYSERR;
}
GNUNET_free (fn);
GNUNET_free (cfg_buf);
- cfg->dirty = GNUNET_NO; /* last write succeeded */
+ cfg->dirty = GNUNET_NO; /* last write succeeded */
return GNUNET_OK;
}
for (spos = cfg->sections; NULL != spos; spos = spos->next)
for (epos = spos->entries; NULL != epos; epos = epos->next)
if (NULL != epos->val)
- iter (iter_cls, spos->name, epos->key, epos->val);
+ iter (iter_cls, spos->name, epos->key, epos->val);
}
* @param iter_cls closure for @a iter
*/
void
-GNUNET_CONFIGURATION_iterate_section_values (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- GNUNET_CONFIGURATION_Iterator iter,
- void *iter_cls)
+GNUNET_CONFIGURATION_iterate_section_values (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ GNUNET_CONFIGURATION_Iterator iter,
+ void *iter_cls)
{
struct ConfigSection *spos;
struct ConfigEntry *epos;
* @param iter_cls closure for @a iter
*/
void
-GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_CONFIGURATION_Section_Iterator iter,
- void *iter_cls)
+GNUNET_CONFIGURATION_iterate_sections (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_CONFIGURATION_Section_Iterator iter,
+ void *iter_cls)
{
struct ConfigSection *spos;
struct ConfigSection *next;
*/
static struct ConfigEntry *
find_entry (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *key)
+ const char *section,
+ const char *key)
{
struct ConfigSection *sec;
struct ConfigEntry *pos;
compare_entries (void *cls,
const char *section,
const char *option,
- const char *value)
+ const char *value)
{
struct DiffHandle *dh = cls;
struct ConfigEntry *entNew;
entNew = find_entry (dh->cfg_default, section, option);
- if ( (NULL != entNew) &&
- (NULL != entNew->val) &&
- (0 == strcmp (entNew->val, value)) )
+ if ((NULL != entNew) && (NULL != entNew->val) &&
+ (0 == strcmp (entNew->val, value)))
return;
GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
}
* @return configuration with only the differences, never NULL
*/
struct GNUNET_CONFIGURATION_Handle *
-GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
- const struct GNUNET_CONFIGURATION_Handle *cfg_new)
+GNUNET_CONFIGURATION_get_diff (
+ const struct GNUNET_CONFIGURATION_Handle *cfg_default,
+ const struct GNUNET_CONFIGURATION_Handle *cfg_new)
{
struct DiffHandle diffHandle;
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
- *cfg_default,
- const struct GNUNET_CONFIGURATION_Handle
- *cfg_new, const char *filename)
+GNUNET_CONFIGURATION_write_diffs (
+ const struct GNUNET_CONFIGURATION_Handle *cfg_default,
+ const struct GNUNET_CONFIGURATION_Handle *cfg_new,
+ const char *filename)
{
int ret;
struct GNUNET_CONFIGURATION_Handle *diff;
*/
void
GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section, const char *option,
+ const char *section,
+ const char *option,
const char *value)
{
struct ConfigSection *sec;
void
GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
const char *section,
- const char *option,
+ const char *option,
unsigned long long number)
{
char s[64];
- GNUNET_snprintf (s,
- 64,
- "%llu",
- number);
- GNUNET_CONFIGURATION_set_value_string (cfg,
- section,
- option,
- s);
+ GNUNET_snprintf (s, 64, "%llu", number);
+ GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- unsigned long long *number)
+GNUNET_CONFIGURATION_get_value_number (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ unsigned long long *number)
{
struct ConfigEntry *e;
char dummy[2];
return GNUNET_SYSERR;
if (NULL == e->val)
return GNUNET_SYSERR;
- if (1 != SSCANF (e->val,
- "%llu%1s",
- number,
- dummy))
+ if (1 != sscanf (e->val, "%llu%1s", number, dummy))
return GNUNET_SYSERR;
return GNUNET_OK;
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- float *number)
+GNUNET_CONFIGURATION_get_value_float (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ float *number)
{
struct ConfigEntry *e;
char dummy[2];
return GNUNET_SYSERR;
if (NULL == e->val)
return GNUNET_SYSERR;
- if (1 != SSCANF (e->val,
- "%f%1s",
- number,
- dummy))
+ if (1 != sscanf (e->val, "%f%1s", number, dummy))
return GNUNET_SYSERR;
return GNUNET_OK;
}
-
/**
* Get a configuration value that should be a relative time.
*
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- struct GNUNET_TIME_Relative *time)
+GNUNET_CONFIGURATION_get_value_time (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ struct GNUNET_TIME_Relative *time)
{
struct ConfigEntry *e;
int ret;
- if (NULL == (e = find_entry (cfg,
- section,
- option)))
+ if (NULL == (e = find_entry (cfg, section, option)))
return GNUNET_SYSERR;
if (NULL == e->val)
return GNUNET_SYSERR;
- ret = GNUNET_STRINGS_fancy_time_to_relative (e->val,
- time);
+ ret = GNUNET_STRINGS_fancy_time_to_relative (e->val, time);
if (GNUNET_OK != ret)
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
section,
option,
- _("Not a valid relative time specification"));
+ _ ("Not a valid relative time specification"));
return ret;
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- unsigned long long *size)
+GNUNET_CONFIGURATION_get_value_size (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ unsigned long long *size)
{
struct ConfigEntry *e;
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- char **value)
+GNUNET_CONFIGURATION_get_value_string (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ char **value)
{
struct ConfigEntry *e;
- if ( (NULL == (e = find_entry (cfg, section, option))) ||
- (NULL == e->val) )
+ if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
{
*value = NULL;
return GNUNET_SYSERR;
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- const char *const *choices,
- const char **value)
+GNUNET_CONFIGURATION_get_value_choice (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ const char *const *choices,
+ const char **value)
{
struct ConfigEntry *e;
unsigned int i;
if (NULL == choices[i])
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Configuration value '%s' for '%s'"
- " in section '%s' is not in set of legal choices\n"),
+ _ ("Configuration value '%s' for '%s'"
+ " in section '%s' is not in set of legal choices\n"),
e->val,
option,
section);
size_t data_size;
if (GNUNET_OK !=
- (res = GNUNET_CONFIGURATION_get_value_string (cfg,
- section,
- option,
- &enc)))
+ (res =
+ GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
return res;
data_size = (strlen (enc) * 5) / 8;
if (data_size != buf_size)
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (enc,
- strlen (enc),
- buf, buf_size))
+ GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
{
GNUNET_free (enc);
return GNUNET_SYSERR;
if (depth > 128)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
+ _ (
+ "Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
orig);
return orig;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to $-expand %s\n",
- orig);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig);
if ('$' != orig[0])
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Doesn't start with $ - not expanding\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n");
return orig;
}
erased_char = 0;
break;
case '\0':
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Missing closing `%s' in option `%s'\n"),
+ _ ("Missing closing `%s' in option `%s'\n"),
"}",
orig);
return orig;
{
*def = '\0';
def++;
- if ( ('-' == *def) ||
- ('=' == *def) )
+ if (('-' == *def) || ('=' == *def))
def++;
def = GNUNET_strdup (def);
}
start = &orig[1];
def = NULL;
i = 0;
- while ( (orig[i] != '/') &&
- (orig[i] != '\\') &&
- (orig[i] != '\0') &&
- (orig[i] != ' ') )
+ while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') &&
+ (orig[i] != ' '))
i++;
if (orig[i] == '\0')
{
post,
def);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- start,
- &prefix))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix))
{
if (NULL == (env = getenv (start)))
{
if (erased_pos)
*erased_pos = erased_char;
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
- start, orig);
+ _ (
+ "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
+ start,
+ orig);
GNUNET_free (start);
return orig;
}
prefix = GNUNET_strdup (env);
}
prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix);
- if ( (erased_pos) && ('}' != erased_char) )
+ if ((erased_pos) && ('}' != erased_char))
{
len = strlen (prefix) + 1;
prefix = GNUNET_realloc (prefix, len + 1);
* @return $-expanded string
*/
char *
-GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
- char *orig)
+GNUNET_CONFIGURATION_expand_dollar (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ char *orig)
{
char *dup;
size_t i;
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- char **value)
+GNUNET_CONFIGURATION_get_value_filename (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ char **value)
{
char *tmp;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to retrieve filename\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
*value = NULL;
return GNUNET_SYSERR;
}
* @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR
*/
int
-GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option)
+GNUNET_CONFIGURATION_get_value_yesno (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option)
{
- static const char *yesno[] = { "YES", "NO", NULL };
+ static const char *yesno[] = {"YES", "NO", NULL};
const char *val;
int ret;
ret =
- GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
+ GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
if (ret == GNUNET_SYSERR)
return ret;
if (val == yesno[0])
* @return number of filenames iterated over, -1 on error
*/
int
-GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- GNUNET_FileNameCallback cb,
- void *cb_cls)
+GNUNET_CONFIGURATION_iterate_value_filenames (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ GNUNET_FileNameCallback cb,
+ void *cb_cls)
{
char *list;
char *pos;
* #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- const char *value)
+GNUNET_CONFIGURATION_append_value_filename (
+ struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ const char *value)
{
char *escaped;
char *old;
char *nw;
if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option,
+ GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
+ section,
+ option,
&test_match,
(void *) value))
- return GNUNET_NO; /* already exists */
+ return GNUNET_NO; /* already exists */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
old = GNUNET_strdup ("");
* #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option,
- const char *value)
+GNUNET_CONFIGURATION_remove_value_filename (
+ struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ const char *value)
{
char *list;
char *pos;
parse_configuration_file (void *cls, const char *filename)
{
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
- char * ext;
+ char *ext;
int ret;
/* Examine file extension */
ext = strrchr (filename, '.');
if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Skipping file `%s'\n",
- filename);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
return GNUNET_OK;
}
*/
int
GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *defaults_d)
+ const char *defaults_d)
{
if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_scan (defaults_d,
- &parse_configuration_file,
- cfg))
- return GNUNET_SYSERR; /* no configuration at all found */
+ GNUNET_DISK_directory_scan (defaults_d, &parse_configuration_file, cfg))
+ return GNUNET_SYSERR; /* no configuration at all found */
return GNUNET_OK;
}
#include "platform.h"
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__)
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall)
+#define LOG_strerror(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-container-bloomfilter", syscall, filename)
+#define LOG_strerror_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, \
+ "util-container-bloomfilter", \
+ syscall, \
+ filename)
struct GNUNET_CONTAINER_BloomFilter
{
* Size of bitArray in bytes
*/
size_t bitArraySize;
-
};
* @return addresses set per element in the bf
*/
size_t
-GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter
- *bf)
+GNUNET_CONTAINER_bloomfilter_get_element_addresses (
+ const struct GNUNET_CONTAINER_BloomFilter *bf)
{
if (bf == NULL)
return 0;
* @return number of bytes used for the data of the bloom filter
*/
size_t
-GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter
- *bf)
+GNUNET_CONTAINER_bloomfilter_get_size (
+ const struct GNUNET_CONTAINER_BloomFilter *bf)
{
if (bf == NULL)
return 0;
* @return copy of the bf
*/
struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter
- *bf)
+GNUNET_CONTAINER_bloomfilter_copy (
+ const struct GNUNET_CONTAINER_BloomFilter *bf)
{
- return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize,
+ return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray,
+ bf->bitArraySize,
bf->addressesPerElement);
}
* @param fh A file to keep the 4 bit address usage counters in
*/
static void
-incrementBit (char *bitArray, unsigned int bitIdx,
+incrementBit (char *bitArray,
+ unsigned int bitIdx,
const struct GNUNET_DISK_FileHandle *fh)
{
off_t fileSlot;
* @param fh A file to keep the 4bit address usage counters in
*/
static void
-decrementBit (char *bitArray, unsigned int bitIdx,
+decrementBit (char *bitArray,
+ unsigned int bitIdx,
const struct GNUNET_DISK_FileHandle *fh)
{
off_t fileslot;
unsigned int targetLoc;
if (GNUNET_DISK_handle_invalid (fh))
- return; /* cannot decrement! */
+ return; /* cannot decrement! */
/* Each char slot in the counter file holds two 4 bit counters */
fileslot = bitIdx / 2;
targetLoc = bitIdx % 2;
- if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
- return;
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
+ return;
+ }
if (1 != GNUNET_DISK_file_read (fh, &value, 1))
value = 0;
low = value & 0xF;
}
}
value = ((high << 4) | low);
- if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
- return;
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
+ return;
+ }
GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
}
{
res = GNUNET_DISK_file_write (fh, buffer, sizeof (buffer));
if (res >= 0)
- bytesleft -= res;
+ bytesleft -= res;
}
else
{
res = GNUNET_DISK_file_write (fh, buffer, bytesleft);
if (res >= 0)
- bytesleft -= res;
+ bytesleft -= res;
}
if (GNUNET_SYSERR == res)
return GNUNET_SYSERR;
* @return GNUNET_YES to continue, GNUNET_NO to stop early
*/
typedef int (*BitIterator) (void *cls,
- const struct GNUNET_CONTAINER_BloomFilter * bf,
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
unsigned int bit);
*/
static void
iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
- BitIterator callback, void *arg, const struct GNUNET_HashCode *key)
+ BitIterator callback,
+ void *arg,
+ const struct GNUNET_HashCode *key)
{
struct GNUNET_HashCode tmp[2];
int bitCount;
while (slot < (sizeof (struct GNUNET_HashCode) / sizeof (uint32_t)))
{
if (GNUNET_YES !=
- callback (arg, bf,
- ntohl ((((uint32_t *) & tmp[round & 1])[slot])) %
- ((bf->bitArraySize * 8LL))))
+ callback (arg,
+ bf,
+ ntohl ((((uint32_t *) &tmp[round & 1])[slot])) %
+ ((bf->bitArraySize * 8LL))))
return;
slot++;
bitCount--;
}
if (bitCount > 0)
{
- GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (struct GNUNET_HashCode),
+ GNUNET_CRYPTO_hash (&tmp[round & 1],
+ sizeof (struct GNUNET_HashCode),
&tmp[(round + 1) & 1]);
round++;
slot = 0;
* @return GNUNET_YES
*/
static int
-incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
+incrementBitCallback (void *cls,
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
unsigned int bit)
{
struct GNUNET_CONTAINER_BloomFilter *b = cls;
* @return GNUNET_YES
*/
static int
-decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
+decrementBitCallback (void *cls,
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
unsigned int bit)
{
struct GNUNET_CONTAINER_BloomFilter *b = cls;
* @return YES if the bit is set, NO if not
*/
static int
-testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
+testBitCallback (void *cls,
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
unsigned int bit)
{
int *arg = cls;
* @return the bloomfilter
*/
struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
+GNUNET_CONTAINER_bloomfilter_load (const char *filename,
+ size_t size,
unsigned int k)
{
struct GNUNET_CONTAINER_BloomFilter *bf;
if (size < BUFFSIZE)
size = BUFFSIZE;
ui = 1;
- while ( (ui < size) &&
- (ui * 2 > ui) )
+ while ((ui < size) && (ui * 2 > ui))
ui *= 2;
- size = ui; /* make sure it's a power of 2 */
+ size = ui; /* make sure it's a power of 2 */
bf = GNUNET_new (struct GNUNET_CONTAINER_BloomFilter);
/* Try to open a bloomfilter file */
if (GNUNET_YES == GNUNET_DISK_file_test (filename))
- bf->fh =
- GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READWRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ bf->fh = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READWRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL != bf->fh)
{
/* file existed, try to read it! */
must_read = GNUNET_YES;
- if (GNUNET_OK !=
- GNUNET_DISK_file_handle_size (bf->fh, &fsize))
+ if (GNUNET_OK != GNUNET_DISK_file_handle_size (bf->fh, &fsize))
{
GNUNET_DISK_file_close (bf->fh);
GNUNET_free (bf);
if (0 == fsize)
{
/* found existing empty file, just overwrite */
- if (GNUNET_OK !=
- make_empty_file (bf->fh, size * 4LL))
+ if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "write");
- GNUNET_DISK_file_close (bf->fh);
- GNUNET_free (bf);
- return NULL;
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
+ GNUNET_DISK_file_close (bf->fh);
+ GNUNET_free (bf);
+ return NULL;
}
}
else if (fsize != ((off_t) size) * 4LL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
- (unsigned long long) (size * 4LL),
- (unsigned long long) fsize);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
+ (unsigned long long) (size * 4LL),
+ (unsigned long long) fsize);
GNUNET_DISK_file_close (bf->fh);
GNUNET_free (bf);
return NULL;
{
/* file did not exist, don't read, just create */
must_read = GNUNET_NO;
- bf->fh =
- GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_CREATE |
- GNUNET_DISK_OPEN_READWRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ bf->fh = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_READWRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == bf->fh)
- {
- GNUNET_free (bf);
- return NULL;
- }
+ {
+ GNUNET_free (bf);
+ return NULL;
+ }
if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "write");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
GNUNET_DISK_file_close (bf->fh);
GNUNET_free (bf);
return NULL;
{
int res;
- res = GNUNET_DISK_file_read (bf->fh,
- rbuff,
- BUFFSIZE);
+ res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
if (res == -1)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "read",
- bf->filename);
+ LOG_strerror_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
GNUNET_free (rbuff);
GNUNET_free (bf->filename);
GNUNET_DISK_file_close (bf->fh);
return NULL;
}
if (res == 0)
- break; /* is ok! we just did not use that many bits yet */
+ break; /* is ok! we just did not use that many bits yet */
for (i = 0; i < res; i++)
{
if ((rbuff[i] & 0x0F) != 0)
}
if (res < BUFFSIZE)
break;
- pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
+ pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
}
GNUNET_free (rbuff);
return bf;
* @return the bloomfilter
*/
struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
+GNUNET_CONTAINER_bloomfilter_init (const char *data,
+ size_t size,
unsigned int k)
{
struct GNUNET_CONTAINER_BloomFilter *bf;
* @return #GNUNET_SYSERR if the data array is not big enough
*/
int
-GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
- GNUNET_CONTAINER_BloomFilter *bf,
- char *data, size_t size)
+GNUNET_CONTAINER_bloomfilter_get_raw_data (
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
+ char *data,
+ size_t size)
{
if (NULL == bf)
return GNUNET_SYSERR;
* @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_HashCode * e)
+GNUNET_CONTAINER_bloomfilter_test (
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
+ const struct GNUNET_HashCode *e)
{
int res;
*/
void
GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_HashCode * e)
+ const struct GNUNET_HashCode *e)
{
if (NULL == bf)
return;
int
GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
const char *data,
- size_t size)
+ size_t size)
{
unsigned int i;
unsigned int n;
* @return #GNUNET_OK on success
*/
int
-GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_CONTAINER_BloomFilter *to_or)
+GNUNET_CONTAINER_bloomfilter_or2 (
+ struct GNUNET_CONTAINER_BloomFilter *bf,
+ const struct GNUNET_CONTAINER_BloomFilter *to_or)
{
unsigned int i;
unsigned int n;
return;
if (NULL == bf->filename)
return;
- iterateBits (bf,
- &decrementBitCallback,
- bf,
- e);
+ iterateBits (bf, &decrementBitCallback, bf, e);
}
/**
GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
GNUNET_CONTAINER_HashCodeIterator iterator,
void *iterator_cls,
- size_t size,
+ size_t size,
unsigned int k)
{
struct GNUNET_HashCode hc;
i = 1;
while (i < size)
i *= 2;
- size = i; /* make sure it's a power of 2 */
+ size = i; /* make sure it's a power of 2 */
bf->addressesPerElement = k;
bf->bitArraySize = size;
bf->bitArray = GNUNET_malloc (size);
if (NULL != bf->filename)
- make_empty_file (bf->fh,
- bf->bitArraySize * 4LL);
- while (GNUNET_YES == iterator (iterator_cls,
- &hc))
- GNUNET_CONTAINER_bloomfilter_add (bf,
- &hc);
+ make_empty_file (bf->fh, bf->bitArraySize * 4LL);
+ while (GNUNET_YES == iterator (iterator_cls, &hc))
+ GNUNET_CONTAINER_bloomfilter_add (bf, &hc);
}
/* end of container_bloomfilter.c */
#include <gcrypt.h>
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename)
/**
* Log an error message at log-level 'level' that indicates
* a failure of the command 'cmd' with the message given
* by gcry_strerror(rc).
*/
-#define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0)
+#define LOG_GCRY(level, cmd, rc) \
+ do \
+ { \
+ LOG (level, \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ gcry_strerror (rc)); \
+ } while (0)
/**
return NULL;
while (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
- | GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ fd =
+ GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_FAILIFEXISTS,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
{
if (EEXIST == errno)
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
/* must exist but not be accessible, fail for good! */
- if (0 != ACCESS (filename, R_OK))
+ if (0 != access (filename, R_OK))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
else
- GNUNET_break (0); /* what is going on!? */
+ GNUNET_break (0); /* what is going on!? */
return NULL;
}
continue;
}
cnt = 0;
while (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd, 0,
+ GNUNET_DISK_file_lock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey),
GNUNET_YES))
{
{
ec = errno;
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not acquire lock on file `%s': %s...\n"),
- filename,
- STRERROR (ec));
+ _ ("Could not acquire lock on file `%s': %s...\n"),
+ filename,
+ strerror (ec));
}
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Creating a new private key. This may take a while.\n"));
+ _ ("Creating a new private key. This may take a while.\n"));
priv = GNUNET_CRYPTO_eddsa_key_create ();
GNUNET_assert (NULL != priv);
GNUNET_assert (sizeof (*priv) ==
GNUNET_DISK_file_write (fd, priv, sizeof (*priv)));
GNUNET_DISK_file_sync (fd);
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
+ GNUNET_DISK_file_unlock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
return priv;
}
/* key file exists already, read it! */
- fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
+ fd = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == fd)
{
while (1)
{
if (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd, 0,
+ GNUNET_DISK_file_lock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey),
GNUNET_NO))
{
{
ec = errno;
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not acquire lock on file `%s': %s...\n"), filename,
- STRERROR (ec));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("This may be ok if someone is currently generating a private key.\n"));
+ _ ("Could not acquire lock on file `%s': %s...\n"),
+ filename,
+ strerror (ec));
+ LOG (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "This may be ok if someone is currently generating a private key.\n"));
}
short_wait ();
continue;
/* eh, what!? File we opened is now gone!? */
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
+ GNUNET_DISK_file_unlock (fd,
+ 0,
+ sizeof (
+ struct GNUNET_CRYPTO_EddsaPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
return NULL;
}
- if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
fs = 0;
if (fs < sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))
{
/* maybe we got the read lock before the key generating
* process had a chance to get the write lock; give it up! */
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
+ GNUNET_DISK_file_unlock (fd,
+ 0,
+ sizeof (
+ struct GNUNET_CRYPTO_EddsaPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
if (0 == ++cnt % 10)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
+ _ (
+ "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
filename,
- (unsigned int) fs,
+ (unsigned int) fs,
(unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("This may be ok if someone is currently generating a key.\n"));
+ _ ("This may be ok if someone is currently generating a key.\n"));
}
- short_wait (); /* wait a bit longer! */
+ short_wait (); /* wait a bit longer! */
continue;
}
break;
}
fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey);
priv = GNUNET_malloc (fs);
- sret = GNUNET_DISK_file_read (fd,
- priv,
- fs);
- GNUNET_assert ( (sret >= 0) &&
- (fs == (size_t) sret) );
+ sret = GNUNET_DISK_file_read (fd, priv, fs);
+ GNUNET_assert ((sret >= 0) && (fs == (size_t) sret));
if (GNUNET_YES !=
GNUNET_DISK_file_unlock (fd,
- 0,
+ 0,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_DISK_file_close (fd));
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
#if CRYPTO_BUG
- if (GNUNET_OK !=
- check_eddsa_key (priv))
+ if (GNUNET_OK != check_eddsa_key (priv))
{
GNUNET_break (0);
GNUNET_free (priv);
uint64_t fs;
ssize_t sret;
- if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_create_for_file (filename))
+ if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
return NULL;
while (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
- | GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ fd =
+ GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_FAILIFEXISTS,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
{
if (EEXIST == errno)
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
/* must exist but not be accessible, fail for good! */
- if (0 != ACCESS (filename, R_OK))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
- "access",
- filename);
+ if (0 != access (filename, R_OK))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
else
- GNUNET_break (0); /* what is going on!? */
+ GNUNET_break (0); /* what is going on!? */
return NULL;
}
continue;
}
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
- "open",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
return NULL;
}
cnt = 0;
while (GNUNET_YES !=
GNUNET_DISK_file_lock (fd,
- 0,
+ 0,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
GNUNET_YES))
{
{
ec = errno;
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not acquire lock on file `%s': %s...\n"),
- filename,
- STRERROR (ec));
+ _ ("Could not acquire lock on file `%s': %s...\n"),
+ filename,
+ strerror (ec));
}
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Creating a new private key. This may take a while.\n"));
+ _ ("Creating a new private key. This may take a while.\n"));
priv = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (NULL != priv);
GNUNET_assert (sizeof (*priv) ==
- GNUNET_DISK_file_write (fd,
- priv,
- sizeof (*priv)));
+ GNUNET_DISK_file_write (fd, priv, sizeof (*priv)));
GNUNET_DISK_file_sync (fd);
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
+ GNUNET_DISK_file_unlock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_DISK_file_close (fd));
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
return priv;
}
/* key file exists already, read it! */
fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == fd)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
- "open",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
return NULL;
}
cnt = 0;
while (1)
{
if (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd, 0,
+ GNUNET_DISK_file_lock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
GNUNET_NO))
{
{
ec = errno;
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not acquire lock on file `%s': %s...\n"),
- filename,
- STRERROR (ec));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("This may be ok if someone is currently generating a private key.\n"));
+ _ ("Could not acquire lock on file `%s': %s...\n"),
+ filename,
+ strerror (ec));
+ LOG (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "This may be ok if someone is currently generating a private key.\n"));
}
short_wait ();
continue;
}
- if (GNUNET_YES !=
- GNUNET_DISK_file_test (filename))
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
/* eh, what!? File we opened is now gone!? */
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "stat",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_file_close (fd));
+ GNUNET_DISK_file_unlock (fd,
+ 0,
+ sizeof (
+ struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
return NULL;
}
if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename,
- &fs,
- GNUNET_YES,
- GNUNET_YES))
+ GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
fs = 0;
if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))
{
/* maybe we got the read lock before the key generating
* process had a chance to get the write lock; give it up! */
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
+ GNUNET_DISK_file_unlock (fd,
+ 0,
+ sizeof (
+ struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
if (0 == ++cnt % 10)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
- filename, (unsigned int) fs,
+ _ (
+ "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
+ filename,
+ (unsigned int) fs,
(unsigned int) sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("This may be ok if someone is currently generating a key.\n"));
+ _ ("This may be ok if someone is currently generating a key.\n"));
}
- short_wait (); /* wait a bit longer! */
+ short_wait (); /* wait a bit longer! */
continue;
}
break;
}
fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
priv = GNUNET_malloc (fs);
- sret = GNUNET_DISK_file_read (fd,
- priv,
- fs);
- GNUNET_assert ( (sret >= 0) &&
- (fs == (size_t) sret) );
+ sret = GNUNET_DISK_file_read (fd, priv, fs);
+ GNUNET_assert ((sret >= 0) && (fs == (size_t) sret));
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
+ GNUNET_DISK_file_unlock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_DISK_file_close (fd));
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
return priv;
}
* permission denied)
*/
struct GNUNET_CRYPTO_EddsaPrivateKey *
-GNUNET_CRYPTO_eddsa_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
+GNUNET_CRYPTO_eddsa_key_create_from_configuration (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
char *fn;
if (NULL == (priv = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not load peer's private key\n"));
+ _ ("Could not load peer's private key\n"));
return GNUNET_SYSERR;
}
GNUNET_CRYPTO_eddsa_key_get_public (priv, &dst->public_key);
static double
get_weak_random ()
{
- return ((double) RANDOM () / RAND_MAX);
+ return ((double) random () / RAND_MAX);
}
void
GNUNET_CRYPTO_seed_weak_random (int32_t seed)
{
- SRANDOM (seed);
+ srandom (seed);
}
if (! gcry_check_version (NEED_LIBGCRYPT_VERSION))
{
- FPRINTF (
+ fprintf (
stderr,
_ ("libgcrypt has not the expected version (version %s is required).\n"),
NEED_LIBGCRYPT_VERSION);
gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free);
/* Disable use of secure memory */
if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
- FPRINTF (stderr,
+ fprintf (stderr,
"Failed to set libgcrypt option %s: %s\n",
"DISABLE_SECMEM",
gcry_strerror (rc));
/* Otherwise gnunet-ecc takes forever to complete, besides
we are fine with "just" using GCRY_STRONG_RANDOM */
if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0)))
- FPRINTF (stderr,
+ fprintf (stderr,
"Failed to set libgcrypt option %s: %s\n",
"ENABLE_QUICK_RANDOM",
gcry_strerror (rc));
#include "gnunet_strings_lib.h"
#include "gnunet_disk_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-disk", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-disk", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-disk", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-disk", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename)
/**
* Block size for IO for copying files.
#endif
#ifndef S_ISLNK
-#define _IFMT 0170000 /* type of file */
-#define _IFLNK 0120000 /* symbolic link */
-#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK)
+#define _IFMT 0170000 /* type of file */
+#define _IFLNK 0120000 /* symbolic link */
+#define S_ISLNK(m) (((m) &_IFMT) == _IFLNK)
#endif
{
struct GetFileSizeData *gfsd = cls;
-#if defined (HAVE_STAT64) && !(defined (_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64)
+#if defined(HAVE_STAT64) && \
+ ! (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64)
STRUCT_STAT64 buf;
if (0 != STAT64 (fn, &buf))
#else
struct stat buf;
- if (0 != STAT (fn, &buf))
+ if (0 != stat (fn, &buf))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "stat", fn);
return GNUNET_SYSERR;
errno = EISDIR;
return GNUNET_SYSERR;
}
- if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
+ if ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
gfsd->total += buf.st_size;
- if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) &&
- ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
+ if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) &&
+ ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
{
if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd))
return GNUNET_SYSERR;
GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
{
#ifdef MINGW
- return ((!h) || (h->h == INVALID_HANDLE_VALUE)) ? GNUNET_YES : GNUNET_NO;
+ return ((! h) || (h->h == INVALID_HANDLE_VALUE)) ? GNUNET_YES : GNUNET_NO;
#else
- return ((!h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
+ return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
#endif
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
- off_t *size)
+GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size)
{
#if WINDOWS
BOOL b;
LARGE_INTEGER li;
b = GetFileSizeEx (fh->h, &li);
- if (!b)
+ if (! b)
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
#else
struct stat sbuf;
- if (0 != FSTAT (fh->fd, &sbuf))
+ if (0 != fstat (fh->fd, &sbuf))
return GNUNET_SYSERR;
*size = sbuf.st_size;
#endif
*/
off_t
GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
- off_t offset,
+ off_t offset,
enum GNUNET_DISK_Seek whence)
{
if (h == NULL)
LARGE_INTEGER new_pos;
BOOL b;
- static DWORD t[] = { FILE_BEGIN, FILE_CURRENT, FILE_END };
+ static DWORD t[] = {FILE_BEGIN, FILE_CURRENT, FILE_END};
li.QuadPart = offset;
b = SetFilePointerEx (h->h, li, &new_pos, t[whence]);
}
return (off_t) new_pos.QuadPart;
#else
- static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END };
+ static int t[] = {SEEK_SET, SEEK_CUR, SEEK_END};
return lseek (h->fd, offset, t[whence]);
#endif
*/
int
GNUNET_DISK_file_size (const char *filename,
- uint64_t * size,
+ uint64_t *size,
int include_symbolic_links,
- int single_file_mode)
+ int single_file_mode)
{
struct GetFileSizeData gfsd;
int ret;
* @return #GNUNET_OK on success
*/
int
-GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
- uint64_t * ino)
+GNUNET_DISK_file_get_identifiers (const char *filename,
+ uint64_t *dev,
+ uint64_t *ino)
{
#if WINDOWS
{
return GNUNET_SYSERR;
succ = GetFileInformationByHandle (fh->h, &info);
GNUNET_DISK_file_close (fh);
- if (!succ)
+ if (! succ)
{
return GNUNET_SYSERR;
}
*dev = info.dwVolumeSerialNumber;
- *ino = ((((uint64_t) info.nFileIndexHigh) << (sizeof (DWORD) * 8)) | info.nFileIndexLow);
+ *ino = ((((uint64_t) info.nFileIndexHigh) << (sizeof (DWORD) * 8)) |
+ info.nFileIndexLow);
}
#else /* !WINDOWS */
#if HAVE_STAT
{
return GNUNET_SYSERR;
}
- *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 ||
- ((uint64_t) fbuf.f_fsid.val[1]);
+ *dev =
+ ((uint64_t) fbuf.f_fsid.val[0]) << 32 || ((uint64_t) fbuf.f_fsid.val[1]);
}
#else
*dev = 0;
if ((t[0] != '/') && (t[0] != '\\')
#if WINDOWS
- && !(isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':'))
+ && ! (isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':'))
#endif
- )
+ )
{
/* FIXME: This uses system codepage on W32, not UTF-8 */
tmpdir = getenv ("TMPDIR");
else if (GNUNET_YES == require_gid_match)
mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
else
- mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
+ mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH |
+ S_IWOTH | S_IXOTH;
if (0 != chmod (fn, mode))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "chmod",
- fn);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "chmod", fn);
}
#endif
num = 0;
do
{
- GNUNET_snprintf (target, slen,
- "%s.%u~",
- fil,
- num++);
+ GNUNET_snprintf (target, slen, "%s.%u~", fil, num++);
} while (0 == access (target, F_OK));
if (0 != rename (fil, target))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "rename",
- fil);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "rename", fil);
GNUNET_free (target);
}
return NULL;
}
umask (omask);
- if (0 != CLOSE (fd))
+ if (0 != close (fd))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn);
return fn;
}
* does not exist or stat'ed
*/
int
-GNUNET_DISK_directory_test (const char *fil,
- int is_readable)
+GNUNET_DISK_directory_test (const char *fil, int is_readable)
{
struct stat filestat;
int ret;
- ret = STAT (fil, &filestat);
+ ret = stat (fil, &filestat);
if (ret != 0)
{
if (errno != ENOENT)
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil);
return GNUNET_SYSERR;
}
- if (!S_ISDIR (filestat.st_mode))
+ if (! S_ISDIR (filestat.st_mode))
{
LOG (GNUNET_ERROR_TYPE_INFO,
- "A file already exits with the same name %s\n", fil);
+ "A file already exits with the same name %s\n",
+ fil);
return GNUNET_NO;
}
if (GNUNET_YES == is_readable)
- ret = ACCESS (fil, R_OK | X_OK);
+ ret = access (fil, R_OK | X_OK);
else
- ret = ACCESS (fil, X_OK);
+ ret = access (fil, X_OK);
if (ret < 0)
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil);
if (rdir == NULL)
return GNUNET_SYSERR;
- ret = STAT (rdir, &filestat);
+ ret = stat (rdir, &filestat);
if (ret != 0)
{
if (errno != ENOENT)
GNUNET_free (rdir);
return GNUNET_NO;
}
- if (!S_ISREG (filestat.st_mode))
+ if (! S_ISREG (filestat.st_mode))
{
GNUNET_free (rdir);
return GNUNET_NO;
}
- if (ACCESS (rdir, F_OK) < 0)
+ if (access (rdir, F_OK) < 0)
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir);
GNUNET_free (rdir);
len = strlen (rdir);
#ifndef MINGW
- pos = 1; /* skip heading '/' */
+ pos = 1; /* skip heading '/' */
#else
/* Local or Network path? */
if (strncmp (rdir, "\\\\", 2) == 0)
}
else
{
- pos = 3; /* strlen("C:\\") */
+ pos = 3; /* strlen("C:\\") */
}
#endif
/* Check which low level directories already exist */
if (GNUNET_SYSERR == ret)
{
#ifndef MINGW
- ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */
+ ret = mkdir (rdir,
+ S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH |
+ S_IXOTH); /* 755 */
#else
wchar_t wrdir[MAX_PATH + 1];
- if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(rdir, wrdir))
- ret = !CreateDirectoryW (wrdir, NULL);
+ if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv (rdir, wrdir))
+ ret = ! CreateDirectoryW (wrdir, NULL);
else
ret = 1;
#endif
errno = EINVAL;
return GNUNET_SYSERR;
}
- if (0 == ACCESS (rdir, W_OK))
+ if (0 == access (rdir, W_OK))
{
GNUNET_free (rdir);
return GNUNET_OK;
rdir = GNUNET_strdup ("/");
}
ret = GNUNET_DISK_directory_create (rdir);
- if ((GNUNET_OK == ret) && (0 != ACCESS (rdir, W_OK)))
+ if ((GNUNET_OK == ret) && (0 != access (rdir, W_OK)))
ret = GNUNET_NO;
eno = errno;
GNUNET_free (rdir);
if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
{
- if (!ReadFile (h->h, result, len, &bytes_read, NULL))
+ if (! ReadFile (h->h, result, len, &bytes_read, NULL))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
}
else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
{
- if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
+ if (! ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
{
if (GetLastError () != ERROR_IO_PENDING)
{
*/
ssize_t
GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
- void *result,
- size_t len)
+ void *result,
+ size_t len)
{
if (NULL == h)
{
if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
{
- if (!ReadFile (h->h, result, len, &bytes_read, NULL))
+ if (! ReadFile (h->h, result, len, &bytes_read, NULL))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
}
else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
{
- if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
+ if (! ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
{
if (GetLastError () != ERROR_IO_PENDING)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n", GetLastError ());
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Error reading from pipe: %u\n",
+ GetLastError ());
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
}
else
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "ReadFile() queued a read, cancelling\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadFile() queued a read, cancelling\n");
CancelIo (h->h);
errno = EAGAIN;
return GNUNET_SYSERR;
}
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Read %u bytes\n",
- bytes_read);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytes_read);
}
else
{
(void) fcntl (h->fd, F_SETFL, flags | O_NONBLOCK);
ret = read (h->fd, result, len);
if (0 == (flags & O_NONBLOCK))
- {
- int eno = errno;
- (void) fcntl (h->fd, F_SETFL, flags);
- errno = eno;
- }
+ {
+ int eno = errno;
+ (void) fcntl (h->fd, F_SETFL, flags);
+ errno = eno;
+ }
return ret;
#endif
}
* @return number of bytes read, #GNUNET_SYSERR on failure
*/
ssize_t
-GNUNET_DISK_fn_read (const char *fn,
- void *result,
- size_t len)
+GNUNET_DISK_fn_read (const char *fn, void *result, size_t len)
{
struct GNUNET_DISK_FileHandle *fh;
ssize_t ret;
int eno;
- fh = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
if (NULL == fh)
return GNUNET_SYSERR;
ret = GNUNET_DISK_file_read (fh, result, len);
* @return number of bytes written on success, #GNUNET_SYSERR on error
*/
ssize_t
-GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
+GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
const void *buffer,
- size_t n)
+ size_t n)
{
if (NULL == h)
{
if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
{
- if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
+ if (! WriteFile (h->h, buffer, n, &bytes_written, NULL))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n);
- if (!WriteFile (h->h, buffer, n, &bytes_written, h->oOverlapWrite))
+ if (! WriteFile (h->h, buffer, n, &bytes_written, h->oOverlapWrite))
{
if (GetLastError () != ERROR_IO_PENDING)
{
SetErrnoFromWinError (GetLastError ());
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
- GetLastError ());
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Error writing to pipe: %u\n",
+ GetLastError ());
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
- if (!GetOverlappedResult (h->h, h->oOverlapWrite, &bytes_written, TRUE))
+ if (! GetOverlappedResult (h->h, h->oOverlapWrite, &bytes_written, TRUE))
{
SetErrnoFromWinError (GetLastError ());
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Error getting overlapped result while writing to pipe: %u\n",
- GetLastError ());
+ "Error getting overlapped result while writing to pipe: %u\n",
+ GetLastError ());
return GNUNET_SYSERR;
}
}
else
{
DWORD ovr;
- if (!GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE))
+ if (! GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Error getting control overlapped result while writing to pipe: %u\n",
- GetLastError ());
+ "Error getting control overlapped result while writing to pipe: %u\n",
+ GetLastError ());
}
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Wrote %u bytes (ovr says %u), picking the greatest\n",
- bytes_written, ovr);
+ "Wrote %u bytes (ovr says %u), picking the greatest\n",
+ bytes_written,
+ ovr);
}
}
if (bytes_written == 0)
{
if (n > 0)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes, returning -1 with EAGAIN\n", bytes_written);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Wrote %u bytes, returning -1 with EAGAIN\n",
+ bytes_written);
errno = EAGAIN;
return GNUNET_SYSERR;
}
* @return number of bytes written on success, #GNUNET_SYSERR on error
*/
ssize_t
-GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
+GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
const void *buffer,
size_t n)
{
DWORD bytes_written;
/* We do a non-overlapped write, which is as blocking as it gets */
LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n);
- if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
+ if (! WriteFile (h->h, buffer, n, &bytes_written, NULL))
{
SetErrnoFromWinError (GetLastError ());
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
- GetLastError ());
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Error writing to pipe: %u\n",
+ GetLastError ());
return GNUNET_SYSERR;
}
if (bytes_written == 0 && n > 0)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n");
WaitForSingleObject (h->h, INFINITE);
- if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
+ if (! WriteFile (h->h, buffer, n, &bytes_written, NULL))
{
SetErrnoFromWinError (GetLastError ());
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
- GetLastError ());
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Error writing to pipe: %u\n",
+ GetLastError ());
return GNUNET_SYSERR;
}
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Wrote %u bytes\n",
- bytes_written);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written);
return bytes_written;
#else
int flags;
struct GNUNET_DISK_FileHandle *fh;
ssize_t ret;
- fh = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
- | GNUNET_DISK_OPEN_CREATE, mode);
+ fh =
+ GNUNET_DISK_file_open (fn,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE,
+ mode);
if (! fh)
return GNUNET_SYSERR;
ret = GNUNET_DISK_file_write (fh, buffer, n);
dname = GNUNET_STRINGS_filename_expand (dir_name);
if (NULL == dname)
return GNUNET_SYSERR;
- while ( (strlen (dname) > 0) &&
- (dname[strlen (dname) - 1] == DIR_SEPARATOR) )
+ while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR))
dname[strlen (dname) - 1] = '\0';
- if (0 != STAT (dname, &istat))
+ if (0 != stat (dname, &istat))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "stat",
- dname);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", dname);
GNUNET_free (dname);
return GNUNET_SYSERR;
}
if (! S_ISDIR (istat.st_mode))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Expected `%s' to be a directory!\n"),
+ _ ("Expected `%s' to be a directory!\n"),
dir_name);
GNUNET_free (dname);
return GNUNET_SYSERR;
}
errno = 0;
- dinfo = OPENDIR (dname);
- if ( (EACCES == errno) ||
- (NULL == dinfo) )
+ dinfo = opendir (dname);
+ if ((EACCES == errno) || (NULL == dinfo))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "opendir",
- dname);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname);
if (NULL != dinfo)
- CLOSEDIR (dinfo);
+ closedir (dinfo);
GNUNET_free (dname);
return GNUNET_SYSERR;
}
name_len = 256;
n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1;
name = GNUNET_malloc (n_size);
- while (NULL != (finfo = READDIR (dinfo)))
+ while (NULL != (finfo = readdir (dinfo)))
{
- if ( (0 == strcmp (finfo->d_name, ".")) ||
- (0 == strcmp (finfo->d_name, "..")) )
+ if ((0 == strcmp (finfo->d_name, ".")) ||
+ (0 == strcmp (finfo->d_name, "..")))
continue;
if (NULL != callback)
{
n_size,
"%s%s%s",
dname,
- (0 == strcmp (dname,
- DIR_SEPARATOR_STR))
- ? ""
- : DIR_SEPARATOR_STR,
+ (0 == strcmp (dname, DIR_SEPARATOR_STR))
+ ? ""
+ : DIR_SEPARATOR_STR,
finfo->d_name);
- ret = callback (callback_cls,
- name);
+ ret = callback (callback_cls, name);
if (GNUNET_OK != ret)
{
- CLOSEDIR (dinfo);
+ closedir (dinfo);
GNUNET_free (name);
GNUNET_free (dname);
if (GNUNET_NO == ret)
}
count++;
}
- CLOSEDIR (dinfo);
+ closedir (dinfo);
GNUNET_free (name);
GNUNET_free (dname);
return count;
* @return #GNUNET_OK
*/
static int
-remove_helper (void *unused,
- const char *fn)
+remove_helper (void *unused, const char *fn)
{
(void) unused;
(void) GNUNET_DISK_directory_remove (fn);
GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (0 != LSTAT (filename, &istat))
- return GNUNET_NO; /* file may not exist... */
- (void) CHMOD (filename,
- S_IWUSR | S_IRUSR | S_IXUSR);
- if (0 == UNLINK (filename))
+ if (0 != lstat (filename, &istat))
+ return GNUNET_NO; /* file may not exist... */
+ (void) chmod (filename, S_IWUSR | S_IRUSR | S_IXUSR);
+ if (0 == unlink (filename))
return GNUNET_OK;
- if ( (errno != EISDIR) &&
- /* EISDIR is not sufficient in all cases, e.g.
+ if ((errno != EISDIR) &&
+ /* EISDIR is not sufficient in all cases, e.g.
* sticky /tmp directory may result in EPERM on BSD.
* So we also explicitly check "isDirectory" */
- (GNUNET_YES !=
- GNUNET_DISK_directory_test (filename,
- GNUNET_YES)) )
+ (GNUNET_YES != GNUNET_DISK_directory_test (filename, GNUNET_YES)))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "rmdir",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename);
return GNUNET_SYSERR;
}
if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_scan (filename,
- &remove_helper,
- NULL))
+ GNUNET_DISK_directory_scan (filename, &remove_helper, NULL))
return GNUNET_SYSERR;
- if (0 != RMDIR (filename))
+ if (0 != rmdir (filename))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "rmdir",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename);
return GNUNET_SYSERR;
}
return GNUNET_OK;
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_DISK_file_copy (const char *src,
- const char *dst)
+GNUNET_DISK_file_copy (const char *src, const char *dst)
{
char *buf;
uint64_t pos;
struct GNUNET_DISK_FileHandle *in;
struct GNUNET_DISK_FileHandle *out;
- if (GNUNET_OK !=
- GNUNET_DISK_file_size (src,
- &size,
- GNUNET_YES,
- GNUNET_YES))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "stat",
- src);
+ if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES, GNUNET_YES))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "stat", src);
return GNUNET_SYSERR;
}
pos = 0;
- in = GNUNET_DISK_file_open (src,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ in =
+ GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
if (! in)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- src);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", src);
return GNUNET_SYSERR;
}
out =
- GNUNET_DISK_file_open (dst,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_file_open (dst,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE |
GNUNET_DISK_PERM_GROUP_READ |
GNUNET_DISK_PERM_GROUP_WRITE);
- if (!out)
+ if (! out)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- dst);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", dst);
GNUNET_DISK_file_close (in);
return GNUNET_SYSERR;
}
len = COPY_BLK_SIZE;
if (len > size - pos)
len = size - pos;
- sret = GNUNET_DISK_file_read (in,
- buf,
- len);
- if ( (sret < 0) ||
- (len != (size_t) sret) )
+ sret = GNUNET_DISK_file_read (in, buf, len);
+ if ((sret < 0) || (len != (size_t) sret))
goto FAIL;
- sret = GNUNET_DISK_file_write (out,
- buf,
- len);
- if ( (sret < 0) ||
- (len != (size_t) sret) )
+ sret = GNUNET_DISK_file_write (out, buf, len);
+ if ((sret < 0) || (len != (size_t) sret))
goto FAIL;
pos += len;
}
{
c = *idx;
- if (c == '/' || c == '\\' || c == ':' ||
- c == '*' || c == '?' || c == '"' ||
+ if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' ||
c == '<' || c == '>' || c == '|')
{
*idx = '_';
}
-
/**
* @brief Change owner of a file
*
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
int
-GNUNET_DISK_file_change_owner (const char *filename,
- const char *user)
+GNUNET_DISK_file_change_owner (const char *filename, const char *user)
{
#ifndef MINGW
struct passwd *pws;
if (NULL == pws)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot obtain information about user `%s': %s\n"),
+ _ ("Cannot obtain information about user `%s': %s\n"),
user,
- STRERROR (errno));
+ strerror (errno));
return GNUNET_SYSERR;
}
- if (0 != chown (filename,
- pws->pw_uid,
- pws->pw_gid))
+ if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "chown",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "chown", filename);
return GNUNET_SYSERR;
}
#endif
diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
memset (&o, 0, sizeof (OVERLAPPED));
- o.Offset = (DWORD) (lock_start & 0xFFFFFFFF);;
- o.OffsetHigh = (DWORD) (((lock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
-
- if (!LockFileEx
- (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY,
- 0, diff_low, diff_high, &o))
+ o.Offset = (DWORD) (lock_start & 0xFFFFFFFF);
+ ;
+ o.OffsetHigh =
+ (DWORD) (((lock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
+
+ if (! LockFileEx (fh->h,
+ (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) |
+ LOCKFILE_FAIL_IMMEDIATELY,
+ 0,
+ diff_low,
+ diff_high,
+ &o))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
memset (&o, 0, sizeof (OVERLAPPED));
- o.Offset = (DWORD) (unlock_start & 0xFFFFFFFF);;
- o.OffsetHigh = (DWORD) (((unlock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
+ o.Offset = (DWORD) (unlock_start & 0xFFFFFFFF);
+ ;
+ o.OffsetHigh = (DWORD) (
+ ((unlock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
- if (!UnlockFileEx (fh->h, 0, diff_low, diff_high, &o))
+ if (! UnlockFileEx (fh->h, 0, diff_low, diff_high, &o))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
#ifndef MINGW
mode = 0;
if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE))
- oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
+ oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
else if (flags & GNUNET_DISK_OPEN_READ)
oflags = O_RDONLY;
else if (flags & GNUNET_DISK_OPEN_WRITE)
return NULL;
}
if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
- oflags |= (O_CREAT | O_EXCL);
+ oflags |= (O_CREAT | O_EXCL);
if (flags & GNUNET_DISK_OPEN_TRUNCATE)
oflags |= O_TRUNC;
if (flags & GNUNET_DISK_OPEN_APPEND)
oflags |= O_APPEND;
- if(GNUNET_NO == GNUNET_DISK_file_test(fn))
- {
- if (flags & GNUNET_DISK_OPEN_CREATE )
- {
- (void) GNUNET_DISK_directory_create_for_file (expfn);
- oflags |= O_CREAT;
- mode = translate_unix_perms (perm);
- }
+ if (GNUNET_NO == GNUNET_DISK_file_test (fn))
+ {
+ if (flags & GNUNET_DISK_OPEN_CREATE)
+ {
+ (void) GNUNET_DISK_directory_create_for_file (expfn);
+ oflags |= O_CREAT;
+ mode = translate_unix_perms (perm);
+ }
}
- fd = open (expfn, oflags
+ fd = open (expfn,
+ oflags
#if O_CLOEXEC
- | O_CLOEXEC
+ | O_CLOEXEC
#endif
- | O_LARGEFILE, mode);
+ | O_LARGEFILE,
+ mode);
if (fd == -1)
{
if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
disp = OPEN_EXISTING;
}
- if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(expfn, wexpfn))
- h = CreateFileW (wexpfn, access,
- FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
- disp, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv (expfn, wexpfn))
+ h = CreateFileW (wexpfn,
+ access,
+ FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ disp,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
else
h = INVALID_HANDLE_VALUE;
if (h == INVALID_HANDLE_VALUE)
}
if (h->oOverlapWrite)
{
- if (!CloseHandle (h->oOverlapWrite->hEvent))
+ if (! CloseHandle (h->oOverlapWrite->hEvent))
{
SetErrnoFromWinError (GetLastError ());
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
ftype = GNUNET_DISK_HANLDE_TYPE_PIPE;
break;
case FILE_TYPE_UNKNOWN:
- if ( (GetLastError () == NO_ERROR) ||
- (GetLastError () == ERROR_INVALID_HANDLE) )
+ if ((GetLastError () == NO_ERROR) ||
+ (GetLastError () == ERROR_INVALID_HANDLE))
{
if (0 != ResetEvent (osfh))
ftype = GNUNET_DISK_HANLDE_TYPE_EVENT;
{
struct GNUNET_DISK_FileHandle *fh;
- if ( (((off_t) -1) == lseek (fno, 0, SEEK_CUR)) &&
- (EBADF == errno) )
+ if ((((off_t) -1) == lseek (fno, 0, SEEK_CUR)) && (EBADF == errno))
return NULL; /* invalid FD */
#ifndef WINDOWS
void *
GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
struct GNUNET_DISK_MapHandle **m,
- enum GNUNET_DISK_MapType access, size_t len)
+ enum GNUNET_DISK_MapType access,
+ size_t len)
{
if (NULL == h)
{
}
(*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len);
- if (!(*m)->addr)
+ if (! (*m)->addr)
{
SetErrnoFromWinError (GetLastError ());
CloseHandle ((*m)->h);
ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR;
if (ret != GNUNET_OK)
SetErrnoFromWinError (GetLastError ());
- if (!CloseHandle (h->h) && (ret == GNUNET_OK))
+ if (! CloseHandle (h->h) && (ret == GNUNET_OK))
{
ret = GNUNET_SYSERR;
SetErrnoFromWinError (GetLastError ());
#if WINDOWS
#ifndef PIPE_BUF
-#define PIPE_BUF 512
+#define PIPE_BUF 512
#endif
/* Copyright Bob Byrnes <byrnes <at> curl.com>
http://permalink.gmane.org/gmane.os.cygwin.patches/2121
Note that the return value is either NO_ERROR or GetLastError,
unlike CreatePipe, which returns a bool for success or failure. */
static int
-create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
- LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize,
- DWORD dwReadMode, DWORD dwWriteMode)
+create_selectable_pipe (PHANDLE read_pipe_ptr,
+ PHANDLE write_pipe_ptr,
+ LPSECURITY_ATTRIBUTES sa_ptr,
+ DWORD psize,
+ DWORD dwReadMode,
+ DWORD dwWriteMode)
{
/* Default to error. */
*read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
{
static volatile LONG pipe_unique_id;
- snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld",
- getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id));
- LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size = %lu\n",
- pipename, psize);
+ snprintf (pipename,
+ sizeof pipename,
+ "\\\\.\\pipe\\gnunet-%d-%ld",
+ getpid (),
+ InterlockedIncrement ((LONG *) &pipe_unique_id));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "CreateNamedPipe: name = %s, size = %lu\n",
+ pipename,
+ psize);
/* Use CreateNamedPipe instead of CreatePipe, because the latter
* returns a write handle that does not permit FILE_READ_ATTRIBUTES
* access, on versions of win32 earlier than WinXP SP2.
* It's important to only allow a single instance, to ensure that
* the pipe was not created earlier by some other process, even if
* the pid has been reused. */
- read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */
- psize, /* output buffer size */
- psize, /* input buffer size */
- NMPWAIT_USE_DEFAULT_WAIT, sa_ptr);
+ read_pipe = CreateNamedPipeA (pipename,
+ PIPE_ACCESS_INBOUND |
+ FILE_FLAG_FIRST_PIPE_INSTANCE | dwReadMode,
+ PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
+ 1, /* max instances */
+ psize, /* output buffer size */
+ psize, /* input buffer size */
+ NMPWAIT_USE_DEFAULT_WAIT,
+ sa_ptr);
if (read_pipe != INVALID_HANDLE_VALUE)
{
* Return an anonymous pipe as the best approximation. */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"CreateNamedPipe not implemented, resorting to "
- "CreatePipe: size = %lu\n", psize);
+ "CreatePipe: size = %lu\n",
+ psize);
if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p, write handle = %p\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "pipe read handle = %p, write handle = %p\n",
*read_pipe_ptr,
*write_pipe_ptr);
return GNUNET_OK;
/* Open the named pipe for writing.
* Be sure to permit FILE_READ_ATTRIBUTES access. */
- write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */
- sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */
+ write_pipe = CreateFileA (pipename,
+ GENERIC_WRITE | FILE_READ_ATTRIBUTES,
+ 0, /* share mode */
+ sa_ptr,
+ OPEN_EXISTING,
+ dwWriteMode, /* flags and attributes */
0); /* handle to template file */
if (write_pipe == INVALID_HANDLE_VALUE)
*/
struct GNUNET_DISK_PipeHandle *
GNUNET_DISK_pipe (int blocking_read,
- int blocking_write,
- int inherit_read,
- int inherit_write)
+ int blocking_write,
+ int inherit_read,
+ int inherit_write)
{
#ifndef MINGW
int fd[2];
if (ret == -1)
{
eno = errno;
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
errno = eno;
return NULL;
}
- return GNUNET_DISK_pipe_from_fd (blocking_read,
- blocking_write,
- fd);
+ return GNUNET_DISK_pipe_from_fd (blocking_read, blocking_write, fd);
#else
struct GNUNET_DISK_PipeHandle *p;
BOOL ret;
* Pipes are not seekable, and need no offsets, which is
* probably why it works for them.
*/
- ret =
- create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0,
- FILE_FLAG_OVERLAPPED,
- FILE_FLAG_OVERLAPPED);
- if (!ret)
+ ret = create_selectable_pipe (&p->fd[0]->h,
+ &p->fd[1]->h,
+ NULL,
+ 0,
+ FILE_FLAG_OVERLAPPED,
+ FILE_FLAG_OVERLAPPED);
+ if (! ret)
{
SetErrnoFromWinError (GetLastError ());
save_errno = errno;
errno = save_errno;
return NULL;
}
- if (!DuplicateHandle
- (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, 0,
- inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
+ if (! DuplicateHandle (GetCurrentProcess (),
+ p->fd[0]->h,
+ GetCurrentProcess (),
+ &tmp_handle,
+ 0,
+ inherit_read == GNUNET_YES ? TRUE : FALSE,
+ DUPLICATE_SAME_ACCESS))
{
SetErrnoFromWinError (GetLastError ());
save_errno = errno;
CloseHandle (p->fd[0]->h);
p->fd[0]->h = tmp_handle;
- if (!DuplicateHandle
- (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, 0,
- inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
+ if (! DuplicateHandle (GetCurrentProcess (),
+ p->fd[1]->h,
+ GetCurrentProcess (),
+ &tmp_handle,
+ 0,
+ inherit_write == GNUNET_YES ? TRUE : FALSE,
+ DUPLICATE_SAME_ACCESS))
{
SetErrnoFromWinError (GetLastError ());
save_errno = errno;
{
p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
p->fd[0]->fd = fd[0];
- if (!blocking_read)
+ if (! blocking_read)
{
flags = fcntl (fd[0], F_GETFL);
flags |= O_NONBLOCK;
if (0 > fcntl (fd[0], F_SETFL, flags))
{
- ret = -1;
- eno = errno;
+ ret = -1;
+ eno = errno;
}
}
flags = fcntl (fd[0], F_GETFD);
{
p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
p->fd[1]->fd = fd[1];
- if (!blocking_write)
+ if (! blocking_write)
{
flags = fcntl (fd[1], F_GETFL);
flags |= O_NONBLOCK;
if (0 > fcntl (fd[1], F_SETFL, flags))
{
- ret = -1;
- eno = errno;
+ ret = -1;
+ eno = errno;
}
}
flags = fcntl (fd[1], F_GETFD);
*/
int
GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
- void *dst, size_t dst_len)
+ void *dst,
+ size_t dst_len)
{
if (NULL == fh)
return GNUNET_SYSERR;
* @return #GNUNET_OK on success
*/
static int
-purge_cfg_dir (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *option = cls;
char *tmpname;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "PATHS",
- option,
- &tmpname))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "PATHS",
- option);
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", option, &tmpname))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "PATHS", option);
return GNUNET_NO;
}
- if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_remove (tmpname))
+ if (GNUNET_SYSERR == GNUNET_DISK_directory_remove (tmpname))
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "remove",
- tmpname);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "remove", tmpname);
GNUNET_free (tmpname);
return GNUNET_OK;
}
* @param option option with the dir name to purge
*/
void
-GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
- const char *option)
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, const char *option)
{
GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_parse_and_run (cfg_filename,
- &purge_cfg_dir,
- (void *) option));
+ GNUNET_CONFIGURATION_parse_and_run (cfg_filename,
+ &purge_cfg_dir,
+ (void *) option));
}
/**
* Timeout for retrying DNS queries.
*/
-#define DNS_RETRANSMIT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
+#define DNS_RETRANSMIT_DELAY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
/**
* Number of bytes in @a request.
*/
size_t request_len;
-
};
* Length of @e sockets array.
*/
unsigned int num_sockets;
-
};
return NULL;
}
sa->sa_family = af;
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret,
- sa,
- alen))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret, sa, alen))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not bind to any port: %s\n"),
- STRERROR (errno));
+ _ ("Could not bind to any port: %s\n"),
+ strerror (errno));
GNUNET_NETWORK_socket_close (ret);
return NULL;
}
{
struct GNUNET_DNSSTUB_RequestSocket *rs;
- for (unsigned int i=0;i<256;i++)
+ for (unsigned int i = 0; i < 256; i++)
{
rs = &ctx->sockets[GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
ctx->num_sockets)];
if (NULL != rs->rc)
{
/* signal "failure" */
- rs->rc (rs->rc_cls,
- NULL,
- 0);
+ rs->rc (rs->rc_cls, NULL, 0);
rs->rc = NULL;
}
if (NULL != rs->read_task)
*/
static int
do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
- struct GNUNET_NETWORK_Handle *dnsout)
+ struct GNUNET_NETWORK_Handle *dnsout)
{
struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
ssize_t r;
int len;
#ifndef MINGW
- if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout),
- FIONREAD,
- &len))
+ if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
{
/* conservative choice: */
len = UINT16_MAX;
/* port the code above? */
len = UINT16_MAX;
#endif
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving %d byte DNS reply\n",
- len);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving %d byte DNS reply\n", len);
{
unsigned char buf[len] GNUNET_ALIGN;
int found;
struct GNUNET_TUN_DnsHeader *dns;
addrlen = sizeof (addr);
- memset (&addr,
- 0,
- sizeof (addr));
+ memset (&addr, 0, sizeof (addr));
r = GNUNET_NETWORK_socket_recvfrom (dnsout,
- buf,
+ buf,
sizeof (buf),
- (struct sockaddr*) &addr,
+ (struct sockaddr *) &addr,
&addrlen);
if (-1 == r)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "recvfrom");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "recvfrom");
GNUNET_NETWORK_socket_close (dnsout);
return GNUNET_SYSERR;
}
{
if (0 == memcmp (&addr,
&ds->ss,
- GNUNET_MIN (sizeof (struct sockaddr_storage),
- addrlen)))
+ GNUNET_MIN (sizeof (struct sockaddr_storage), addrlen)))
{
found = GNUNET_YES;
break;
if (GNUNET_NO == found)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received DNS response from server we never asked (ignored)");
+ "Received DNS response from server we never asked (ignored)");
return GNUNET_NO;
}
if (sizeof (struct GNUNET_TUN_DnsHeader) > (size_t) r)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Received DNS response that is too small (%u bytes)"),
- (unsigned int) r);
+ _ ("Received DNS response that is too small (%u bytes)"),
+ (unsigned int) r);
return GNUNET_NO;
}
dns = (struct GNUNET_TUN_DnsHeader *) buf;
if (NULL == rs->rc)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Request timeout or cancelled; ignoring reply\n");
+ "Request timeout or cancelled; ignoring reply\n");
return GNUNET_NO;
}
- rs->rc (rs->rc_cls,
- dns,
- r);
+ rs->rc (rs->rc_cls, dns, r);
}
return GNUNET_OK;
}
GNUNET_SCHEDULER_cancel (rs->read_task);
rset = GNUNET_NETWORK_fdset_create ();
if (NULL != rs->dnsout4)
- GNUNET_NETWORK_fdset_set (rset,
- rs->dnsout4);
+ GNUNET_NETWORK_fdset_set (rset, rs->dnsout4);
if (NULL != rs->dnsout6)
- GNUNET_NETWORK_fdset_set (rset,
- rs->dnsout6);
- rs->read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_TIME_UNIT_FOREVER_REL,
- rset,
- NULL,
- &read_response,
- rs);
+ GNUNET_NETWORK_fdset_set (rset, rs->dnsout6);
+ rs->read_task =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ rset,
+ NULL,
+ &read_response,
+ rs);
GNUNET_NETWORK_fdset_destroy (rset);
}
rs->read_task = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
/* read and process ready sockets */
- if ( (NULL != rs->dnsout4) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- rs->dnsout4)) &&
- (GNUNET_SYSERR ==
- do_dns_read (rs,
- rs->dnsout4)) )
+ if ((NULL != rs->dnsout4) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, rs->dnsout4)) &&
+ (GNUNET_SYSERR == do_dns_read (rs, rs->dnsout4)))
rs->dnsout4 = NULL;
- if ( (NULL != rs->dnsout6) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- rs->dnsout6)) &&
- (GNUNET_SYSERR ==
- do_dns_read (rs,
- rs->dnsout6)) )
+ if ((NULL != rs->dnsout6) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, rs->dnsout6)) &&
+ (GNUNET_SYSERR == do_dns_read (rs, rs->dnsout6)))
rs->dnsout6 = NULL;
/* re-schedule read task */
schedule_read (rs);
struct DnsServer *ds;
struct GNUNET_NETWORK_Handle *dnsout;
- rs->retry_task = GNUNET_SCHEDULER_add_delayed (ctx->retry_freq,
- &transmit_query,
- rs);
+ rs->retry_task =
+ GNUNET_SCHEDULER_add_delayed (ctx->retry_freq, &transmit_query, rs);
ds = rs->ds_pos;
rs->ds_pos = ds->next;
if (NULL == rs->ds_pos)
"Unable to use configure DNS server, skipping\n");
return;
}
- if (GNUNET_SYSERR ==
- GNUNET_NETWORK_socket_sendto (dnsout,
- rs->request,
- rs->request_len,
- sa,
- salen))
+ if (GNUNET_SYSERR == GNUNET_NETWORK_socket_sendto (dnsout,
+ rs->request,
+ rs->request_len,
+ sa,
+ salen))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to send DNS request to %s: %s\n"),
- GNUNET_a2s (sa,
- salen),
- STRERROR (errno));
+ _ ("Failed to send DNS request to %s: %s\n"),
+ GNUNET_a2s (sa, salen),
+ strerror (errno));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Sent DNS request to %s\n"),
- GNUNET_a2s (sa,
- salen));
+ _ ("Sent DNS request to %s\n"),
+ GNUNET_a2s (sa, salen));
schedule_read (rs);
}
*/
struct GNUNET_DNSSTUB_RequestSocket *
GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
- const void *request,
- size_t request_len,
- GNUNET_DNSSTUB_ResultCallback rc,
- void *rc_cls)
+ const void *request,
+ size_t request_len,
+ GNUNET_DNSSTUB_ResultCallback rc,
+ void *rc_cls)
{
struct GNUNET_DNSSTUB_RequestSocket *rs;
rs->ds_pos = ctx->dns_head;
rs->rc = rc;
rs->rc_cls = rc_cls;
- rs->request = GNUNET_memdup (request,
- request_len);
+ rs->request = GNUNET_memdup (request, request_len);
rs->request_len = request_len;
- rs->retry_task = GNUNET_SCHEDULER_add_now (&transmit_query,
- rs);
+ rs->retry_task = GNUNET_SCHEDULER_add_now (&transmit_query, rs);
return rs;
}
}
ctx = GNUNET_new (struct GNUNET_DNSSTUB_Context);
ctx->num_sockets = num_sockets;
- ctx->sockets = GNUNET_new_array (num_sockets,
- struct GNUNET_DNSSTUB_RequestSocket);
+ ctx->sockets =
+ GNUNET_new_array (num_sockets, struct GNUNET_DNSSTUB_RequestSocket);
ctx->retry_freq = DNS_RETRANSMIT_DELAY;
return ctx;
}
struct in6_addr i6;
ds = GNUNET_new (struct DnsServer);
- if (1 == inet_pton (AF_INET,
- dns_ip,
- &i4))
+ if (1 == inet_pton (AF_INET, dns_ip, &i4))
{
struct sockaddr_in *s4 = (struct sockaddr_in *) &ds->ss;
s4->sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
}
- else if (1 == inet_pton (AF_INET6,
- dns_ip,
- &i6))
+ else if (1 == inet_pton (AF_INET6, dns_ip, &i6))
{
struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &ds->ss;
GNUNET_free (ds);
return GNUNET_SYSERR;
}
- GNUNET_CONTAINER_DLL_insert (ctx->dns_head,
- ctx->dns_tail,
- ds);
+ GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
return GNUNET_OK;
}
switch (sa->sa_family)
{
case AF_INET:
- GNUNET_memcpy (&ds->ss,
- sa,
- sizeof (struct sockaddr_in));
+ GNUNET_memcpy (&ds->ss, sa, sizeof (struct sockaddr_in));
break;
case AF_INET6:
- GNUNET_memcpy (&ds->ss,
- sa,
- sizeof (struct sockaddr_in6));
+ GNUNET_memcpy (&ds->ss, sa, sizeof (struct sockaddr_in6));
break;
default:
GNUNET_break (0);
GNUNET_free (ds);
return GNUNET_SYSERR;
}
- GNUNET_CONTAINER_DLL_insert (ctx->dns_head,
- ctx->dns_tail,
- ds);
+ GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
return GNUNET_OK;
}
while (NULL != (ds = ctx->dns_head))
{
- GNUNET_CONTAINER_DLL_remove (ctx->dns_head,
- ctx->dns_tail,
- ds);
+ GNUNET_CONTAINER_DLL_remove (ctx->dns_head, ctx->dns_tail, ds);
GNUNET_free (ds);
}
- for (unsigned int i=0;i<ctx->num_sockets;i++)
+ for (unsigned int i = 0; i < ctx->num_sockets; i++)
cleanup_rs (&ctx->sockets[i]);
GNUNET_free (ctx->sockets);
GNUNET_free (ctx);
if (ambig && ! exact)
{
if (GNopterr)
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `%s' is ambiguous\n"),
argv[0],
argv[GNoptind]);
{
if (argv[GNoptind - 1][1] == '-')
/* --option */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `--%s' does not allow an argument\n"),
argv[0],
pfound->name);
else
/* +option or -option */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `%c%s' does not allow an argument\n"),
argv[0],
argv[GNoptind - 1][0],
{
if (GNopterr)
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `%s' requires an argument\n"),
argv[0],
argv[GNoptind - 1]);
{
if (argv[GNoptind][1] == '-')
/* --option */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: unrecognized option `--%s'\n"),
argv[0],
nextchar);
else
/* +option or -option */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: unrecognized option `%c%s'\n"),
argv[0],
argv[GNoptind][0],
{
if (posixly_correct)
/* 1003.2 specifies the format of this message. */
- FPRINTF (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c);
+ fprintf (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c);
else
- FPRINTF (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
+ fprintf (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
}
return '?';
}
if (GNopterr)
{
/* 1003.2 specifies the format of this message. */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option requires an argument -- %c\n"),
argv[0],
c);
if (ambig && ! exact)
{
if (GNopterr)
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `-W %s' is ambiguous\n"),
argv[0],
argv[GNoptind]);
else
{
if (GNopterr)
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `-W %s' does not allow an argument\n"),
argv[0],
pfound->name);
else
{
if (GNopterr)
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `%s' requires an argument\n"),
argv[0],
argv[GNoptind - 1]);
if (GNopterr)
{
/* 1003.2 specifies the format of this message. */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option requires an argument -- %c\n"),
argv[0],
c);
}
if (i == count)
{
- FPRINTF (stderr, _ ("Use %s to get a list of options.\n"), "--help");
+ fprintf (stderr, _ ("Use %s to get a list of options.\n"), "--help");
cont = GNUNET_SYSERR;
}
}
is the only option that was provided */
if ((NULL != have_exclusive) && (optmatch > 1))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Option `%s' can't be used with other options.\n"),
have_exclusive);
cont = GNUNET_SYSERR;
{
if ((0 == seen[count]) && (allOptions[count].option_mandatory))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Missing mandatory option `%s'.\n"),
allOptions[count].name);
cont = GNUNET_SYSERR;
if (0 != pd->is_gnu)
printf ("General help using GNU software: http://www.gnu.org/gethelp/\n");
-
+
return GNUNET_NO;
}
char dummy[2];
(void) ctx;
- if (1 != SSCANF (value, "%llu%1s", val, dummy))
+ if (1 != sscanf (value, "%llu%1s", val, dummy))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass a number to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
(void) ctx;
if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (value, val))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass relative time to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
(void) ctx;
if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (value, val))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass absolute time to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
(void) ctx;
if ('-' == *value)
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ (
"Your input for the '%s' option has to be a non negative number \n"),
option);
return GNUNET_SYSERR;
}
- if (1 != SSCANF (value, "%u%1s", val, dummy))
+ if (1 != sscanf (value, "%u%1s", val, dummy))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass a number to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
char dummy[2];
(void) ctx;
- if (1 != SSCANF (value, "%u%1s", &v, dummy))
+ if (1 != sscanf (value, "%u%1s", &v, dummy))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass a number to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
}
if (v > UINT16_MAX)
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass a number below %u to the `%s' option.\n"),
(unsigned int) UINT16_MAX,
option);
/**
* Number of characters a Base32-encoded public key requires.
*/
-#define KEY_STR_LEN sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)*8/5+1
+#define KEY_STR_LEN sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) * 8 / 5 + 1
/**
* Flag for listing public key.
if (NULL == (f = fopen (fn, "w+")))
{
- fprintf (stderr, _("Failed to open `%s': %s\n"), fn, STRERROR (errno));
+ fprintf (stderr, _ ("Failed to open `%s': %s\n"), fn, strerror (errno));
return;
}
if (NULL != prefix)
* rest = 5%8 = 5 (bits)
* mask = ~(2**(8 - 5) - 1) = ~(2**3 - 1) = ~(8 - 1) = ~b111 = b11111000
*/
- mask = ~ ((int)pow (2, 8 - rest) - 1);
+ mask = ~((int) pow (2, 8 - rest) - 1);
target_byte = ((unsigned char *) &target_pub)[n] & mask;
}
else
}
s = GNUNET_CRYPTO_eddsa_public_key_to_string (&target_pub);
fprintf (stderr,
- _("Generating %u keys like %s, please wait"),
+ _ ("Generating %u keys like %s, please wait"),
make_keys,
s);
GNUNET_free (s);
- fprintf (stderr,
- "\nattempt %s [%u, %X]\n",
- vanity,
- (unsigned int) n,
- mask);
+ fprintf (stderr, "\nattempt %s [%u, %X]\n", vanity, (unsigned int) n, mask);
}
else
{
- fprintf (stderr,
- _("Generating %u keys, please wait"),
- make_keys);
+ fprintf (stderr, _ ("Generating %u keys, please wait"), make_keys);
/* Just so old (debian) versions of GCC calm down with the warnings. */
n = rest = target_byte = mask = 0;
}
fprintf (stderr, ".");
if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create ()))
{
- GNUNET_break (0);
- break;
+ GNUNET_break (0);
+ break;
}
if (NULL != prefix)
{
}
}
if (GNUNET_TESTING_HOSTKEYFILESIZE !=
- fwrite (pk, 1,
- GNUNET_TESTING_HOSTKEYFILESIZE, f))
+ fwrite (pk, 1, GNUNET_TESTING_HOSTKEYFILESIZE, f))
{
fprintf (stderr,
- _("\nFailed to write to `%s': %s\n"),
- fn,
- STRERROR (errno));
+ _ ("\nFailed to write to `%s': %s\n"),
+ fn,
+ strerror (errno));
GNUNET_free (pk);
break;
}
GNUNET_free (pk);
}
if (UINT_MAX == make_keys)
- fprintf (stderr,
- _("\nFinished!\n"));
+ fprintf (stderr, _ ("\nFinished!\n"));
else
- fprintf (stderr,
- _("\nError, %u keys not generated\n"),
- make_keys);
+ fprintf (stderr, _ ("\nError, %u keys not generated\n"), make_keys);
fclose (f);
}
static void
-print_hex (const char *msg,
- const void *buf,
- size_t size)
+print_hex (const char *msg, const void *buf, size_t size)
{
printf ("%s: ", msg);
for (size_t i = 0; i < size; i++)
{
- printf ("%02hhx", ((const uint8_t *)buf)[i]);
+ printf ("%02hhx", ((const uint8_t *) buf)[i]);
}
printf ("\n");
}
GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv1, dh_pub1);
GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv2, dh_pub2);
- GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf, 128));
+ GNUNET_assert (NULL !=
+ GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf, 128));
printf ("ECDHE key 1:\n");
printf ("private: %s\n", buf);
print_hex ("private(hex)", dh_priv1, sizeof *dh_priv1);
printf ("public: %s\n", buf);
print_hex ("public(hex)", dh_pub1, sizeof *dh_pub1);
- GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf, 128));
+ GNUNET_assert (NULL !=
+ GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf, 128));
printf ("ECDHE key 2:\n");
printf ("private: %s\n", buf);
print_hex ("private(hex)", dh_priv2, sizeof *dh_priv2);
printf ("public: %s\n", buf);
print_hex ("public(hex)", dh_pub2, sizeof *dh_pub2);
- GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2, &hash));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2, &hash));
GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (&hash, 64, buf, 128));
printf ("ECDH shared secret: %s\n", buf);
unsigned int c;
ssize_t sret;
- if (GNUNET_YES !=
- GNUNET_DISK_file_test (filename))
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- fprintf (stderr,
- _("Hostkeys file `%s' not found\n"),
- filename);
+ fprintf (stderr, _ ("Hostkeys file `%s' not found\n"), filename);
return;
}
/* Check hostkey file size, read entire thing into memory */
if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename,
- &fs,
- GNUNET_YES,
- GNUNET_YES))
+ GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
fs = 0;
if (0 == fs)
{
- fprintf (stderr,
- _("Hostkeys file `%s' is empty\n"),
- filename);
- return; /* File is empty */
+ fprintf (stderr, _ ("Hostkeys file `%s' is empty\n"), filename);
+ return; /* File is empty */
}
if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
{
- fprintf (stderr,
- _("Incorrect hostkey file format: %s\n"),
- filename);
+ fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), filename);
return;
}
fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
if (NULL == fd)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- filename);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
return;
}
hostkeys_data = GNUNET_malloc (fs);
- sret = GNUNET_DISK_file_read (fd,
- hostkeys_data,
- fs);
- if ( (sret < 0) ||
- (fs != (size_t) sret) )
+ sret = GNUNET_DISK_file_read (fd, hostkeys_data, fs);
+ if ((sret < 0) || (fs != (size_t) sret))
{
- fprintf (stderr,
- _("Could not read hostkey file: %s\n"),
- filename);
+ fprintf (stderr, _ ("Could not read hostkey file: %s\n"), filename);
GNUNET_free (hostkeys_data);
GNUNET_DISK_file_close (fd);
return;
for (c = 0; (c < total_hostkeys) && (c < list_keys_count); c++)
{
GNUNET_memcpy (&private_key,
- hostkeys_data + (c * GNUNET_TESTING_HOSTKEYFILESIZE),
- GNUNET_TESTING_HOSTKEYFILESIZE);
+ hostkeys_data + (c * GNUNET_TESTING_HOSTKEYFILESIZE),
+ GNUNET_TESTING_HOSTKEYFILESIZE);
GNUNET_CRYPTO_eddsa_key_get_public (&private_key, &public_key);
hostkey_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&public_key);
if (NULL != hostkey_str)
(void) cls;
(void) cfgfile;
(void) cfg;
-
+
if (print_examples_flag)
{
print_examples ();
}
if (NULL == args[0])
{
- FPRINTF (stderr,
- "%s",
- _("No hostkey file specified on command line\n"));
+ fprintf (stderr, "%s", _ ("No hostkey file specified on command line\n"));
return;
}
if (list_keys)
struct GNUNET_CRYPTO_EddsaPrivateKey pk;
struct GNUNET_CRYPTO_EddsaPublicKey pub;
- keyfile = GNUNET_DISK_file_open (args[0], GNUNET_DISK_OPEN_READ,
+ keyfile = GNUNET_DISK_file_open (args[0],
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == keyfile)
return;
- while (sizeof (pk) ==
- GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
+ while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
{
GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub);
if (print_public_key_hex)
else if (print_public_key)
{
str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
- FPRINTF (stdout, "%s\n", str);
+ fprintf (stdout, "%s\n", str);
GNUNET_free (str);
}
else if (print_private_key)
{
str = GNUNET_CRYPTO_eddsa_private_key_to_string (&pk);
- FPRINTF (stdout, "%s\n", str);
+ fprintf (stdout, "%s\n", str);
GNUNET_free (str);
}
}
GNUNET_DISK_file_close (keyfile);
}
-
}
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('i',
- "iterate",
- gettext_noop ("list keys included in a file (for testing)"),
- &list_keys),
- GNUNET_GETOPT_option_uint ('e',
- "end=",
- "COUNT",
- gettext_noop ("number of keys to list included in a file (for testing)"),
- &list_keys_count),
- GNUNET_GETOPT_option_uint ('g',
- "generate-keys",
- "COUNT",
- gettext_noop ("create COUNT public-private key pairs (for testing)"),
- &make_keys),
- GNUNET_GETOPT_option_flag ('p',
- "print-public-key",
- gettext_noop ("print the public key in ASCII format"),
- &print_public_key),
- GNUNET_GETOPT_option_flag ('P',
- "print-private-key",
- gettext_noop ("print the private key in ASCII format"),
- &print_private_key),
- GNUNET_GETOPT_option_flag ('x',
- "print-hex",
- gettext_noop ("print the public key in HEX format"),
- &print_public_key_hex),
- GNUNET_GETOPT_option_flag ('E',
- "examples",
- gettext_noop ("print examples of ECC operations (used for compatibility testing)"),
- &print_examples_flag),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag ('i',
+ "iterate",
+ gettext_noop (
+ "list keys included in a file (for testing)"),
+ &list_keys),
+ GNUNET_GETOPT_option_uint (
+ 'e',
+ "end=",
+ "COUNT",
+ gettext_noop ("number of keys to list included in a file (for testing)"),
+ &list_keys_count),
+ GNUNET_GETOPT_option_uint (
+ 'g',
+ "generate-keys",
+ "COUNT",
+ gettext_noop ("create COUNT public-private key pairs (for testing)"),
+ &make_keys),
+ GNUNET_GETOPT_option_flag ('p',
+ "print-public-key",
+ gettext_noop (
+ "print the public key in ASCII format"),
+ &print_public_key),
+ GNUNET_GETOPT_option_flag ('P',
+ "print-private-key",
+ gettext_noop (
+ "print the private key in ASCII format"),
+ &print_private_key),
+ GNUNET_GETOPT_option_flag ('x',
+ "print-hex",
+ gettext_noop (
+ "print the public key in HEX format"),
+ &print_public_key_hex),
+ GNUNET_GETOPT_option_flag (
+ 'E',
+ "examples",
+ gettext_noop (
+ "print examples of ECC operations (used for compatibility testing)"),
+ &print_examples_flag),
+ GNUNET_GETOPT_OPTION_END};
int ret;
list_keys_count = UINT32_MAX;
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
+ GNUNET_PROGRAM_run (argc,
argv,
"gnunet-ecc [OPTIONS] keyfile [VANITY_PREFIX]",
- gettext_noop ("Manipulate GNUnet private ECC key files"),
- options,
+ gettext_noop (
+ "Manipulate GNUnet private ECC key files"),
+ options,
&run,
- NULL)) ? 0 : 1;
- GNUNET_free ((void*) argv);
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
(void) cls;
if (NULL == hostname)
return;
- FPRINTF (stdout,
+ fprintf (stdout,
"%s\n",
hostname);
}
(void) cls;
if (NULL == addr)
return;
- FPRINTF (stdout,
+ fprintf (stdout,
"%s\n",
GNUNET_a2s (addr,
addrlen));
if (nse_work_required <= count_leading_zeroes (&result))
{
proof = counter;
- FPRINTF (stdout,
+ fprintf (stdout,
"Proof of work found: %llu!\n",
(unsigned long long) proof);
GNUNET_SCHEDULER_shutdown ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn);
if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn)))
{
- FPRINTF (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn);
+ fprintf (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn);
GNUNET_free (pkfn);
return;
}
* Current write position.
*/
unsigned int wpos;
-
};
* @return #GNUNET_OK on success; #GNUNET_SYSERR on error
*/
int
-GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h,
- int soft_kill)
+GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill)
{
struct GNUNET_HELPER_SendHandle *sh;
int ret;
while (NULL != (sh = h->sh_head))
{
- GNUNET_CONTAINER_DLL_remove (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
if (NULL != sh->cont)
sh->cont (sh->cont_cls, GNUNET_NO);
GNUNET_free (sh);
}
while (NULL != (sh = h->sh_head))
{
- GNUNET_CONTAINER_DLL_remove (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
if (NULL != sh->cont)
sh->cont (sh->cont_cls, GNUNET_NO);
GNUNET_free (sh);
}
/* purge MST buffer */
if (NULL != h->mst)
- (void) GNUNET_MST_from_buffer (h->mst,
- NULL, 0,
- GNUNET_YES,
- GNUNET_NO);
+ (void) GNUNET_MST_from_buffer (h->mst, NULL, 0, GNUNET_YES, GNUNET_NO);
return ret;
}
* stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
*/
static void
-stop_helper (struct GNUNET_HELPER_Handle *h,
- int soft_kill)
+stop_helper (struct GNUNET_HELPER_Handle *h, int soft_kill)
{
if (NULL != h->restart_task)
{
{
/* On read-error, restart the helper */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error reading from `%s': %s\n"),
- h->binary_name,
- STRERROR (errno));
+ _ ("Error reading from `%s': %s\n"),
+ h->binary_name,
+ strerror (errno));
if (NULL != h->exp_cb)
{
h->exp_cb (h->cb_cls);
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
if (0 == t)
/* this happens if the helper is shut down via a
signal, so it is not a "hard" error */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got 0 bytes from helper `%s' (EOF)\n",
- h->binary_name);
+ "Got 0 bytes from helper `%s' (EOF)\n",
+ h->binary_name);
if (NULL != h->exp_cb)
{
h->exp_cb (h->cb_cls);
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got %u bytes from helper `%s'\n",
- (unsigned int) t,
- h->binary_name);
+ "Got %u bytes from helper `%s'\n",
+ (unsigned int) t,
+ h->binary_name);
h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_from_helper,
- &helper_read, h);
+ h->fh_from_helper,
+ &helper_read,
+ h);
if (GNUNET_SYSERR ==
- GNUNET_MST_from_buffer (h->mst,
- buf, t,
- GNUNET_NO,
- GNUNET_NO))
+ GNUNET_MST_from_buffer (h->mst, buf, t, GNUNET_NO, GNUNET_NO))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to parse inbound message from helper `%s'\n"),
- h->binary_name);
+ _ ("Failed to parse inbound message from helper `%s'\n"),
+ h->binary_name);
if (NULL != h->exp_cb)
{
h->exp_cb (h->cb_cls);
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
}
static void
start_helper (struct GNUNET_HELPER_Handle *h)
{
- h->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
- h->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
- if ( (h->helper_in == NULL) || (h->helper_out == NULL))
+ h->helper_in =
+ GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
+ h->helper_out =
+ GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ if ((h->helper_in == NULL) || (h->helper_out == NULL))
{
/* out of file descriptors? try again later... */
stop_helper (h, GNUNET_NO);
- h->restart_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting HELPER process `%s'\n",
- h->binary_name);
+ "Starting HELPER process `%s'\n",
+ h->binary_name);
h->fh_from_helper =
- GNUNET_DISK_pipe_handle (h->helper_out, GNUNET_DISK_PIPE_END_READ);
+ GNUNET_DISK_pipe_handle (h->helper_out, GNUNET_DISK_PIPE_END_READ);
h->fh_to_helper =
- GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE);
- h->helper_proc =
- GNUNET_OS_start_process_vap (h->with_control_pipe, GNUNET_OS_INHERIT_STD_ERR,
- h->helper_in, h->helper_out, NULL,
- h->binary_name,
- h->binary_argv);
+ GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE);
+ h->helper_proc = GNUNET_OS_start_process_vap (h->with_control_pipe,
+ GNUNET_OS_INHERIT_STD_ERR,
+ h->helper_in,
+ h->helper_out,
+ NULL,
+ h->binary_name,
+ h->binary_argv);
if (NULL == h->helper_proc)
{
/* failed to start process? try again later... */
stop_helper (h, GNUNET_NO);
- h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ);
if (NULL != h->mst)
h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_from_helper,
- &helper_read,
- h);
+ h->fh_from_helper,
+ &helper_read,
+ h);
}
static void
restart_task (void *cls)
{
- struct GNUNET_HELPER_Handle*h = cls;
+ struct GNUNET_HELPER_Handle *h = cls;
h->restart_task = NULL;
h->retry_back_off++;
*/
struct GNUNET_HELPER_Handle *
GNUNET_HELPER_start (int with_control_pipe,
- const char *binary_name,
- char *const binary_argv[],
- GNUNET_MessageTokenizerCallback cb,
- GNUNET_HELPER_ExceptionCallback exp_cb,
- void *cb_cls)
+ const char *binary_name,
+ char *const binary_argv[],
+ GNUNET_MessageTokenizerCallback cb,
+ GNUNET_HELPER_ExceptionCallback exp_cb,
+ void *cb_cls)
{
struct GNUNET_HELPER_Handle *h;
unsigned int c;
h->binary_name = GNUNET_OS_get_libexec_binary_path (binary_name);
else
h->binary_name = GNUNET_strdup (binary_name);
- for (c = 0; NULL != binary_argv[c]; c++);
+ for (c = 0; NULL != binary_argv[c]; c++)
+ ;
h->binary_argv = GNUNET_malloc (sizeof (char *) * (c + 1));
for (c = 0; NULL != binary_argv[c]; c++)
h->binary_argv[c] = GNUNET_strdup (binary_argv[c]);
h->binary_argv[c] = NULL;
h->cb_cls = cb_cls;
if (NULL != cb)
- h->mst = GNUNET_MST_create (cb,
- h->cb_cls);
+ h->mst = GNUNET_MST_create (cb, h->cb_cls);
h->exp_cb = exp_cb;
h->retry_back_off = 0;
start_helper (h);
GNUNET_assert (NULL == h->restart_task);
while (NULL != (sh = h->sh_head))
{
- GNUNET_CONTAINER_DLL_remove (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
if (NULL != sh->cont)
sh->cont (sh->cont_cls, GNUNET_SYSERR);
GNUNET_free (sh);
* stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
*/
void
-GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h,
- int soft_kill)
+GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill)
{
h->exp_cb = NULL;
stop_helper (h, soft_kill);
h->write_task = NULL;
if (NULL == (sh = h->sh_head))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Helper write had no work!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Helper write had no work!\n");
return; /* how did this happen? */
}
- buf = (const char*) sh->msg;
+ buf = (const char *) sh->msg;
t = GNUNET_DISK_file_write (h->fh_to_helper,
- &buf[sh->wpos],
- ntohs (sh->msg->size) - sh->wpos);
+ &buf[sh->wpos],
+ ntohs (sh->msg->size) - sh->wpos);
if (-1 == t)
{
/* On write-error, restart the helper */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error writing to `%s': %s\n"),
- h->binary_name,
- STRERROR (errno));
+ _ ("Error writing to `%s': %s\n"),
+ h->binary_name,
+ strerror (errno));
if (NULL != h->exp_cb)
{
h->exp_cb (h->cb_cls);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping and restarting helper task!\n");
+ "Stopping and restarting helper task!\n");
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitted %u bytes to %s\n",
- (unsigned int) t,
- h->binary_name);
+ "Transmitted %u bytes to %s\n",
+ (unsigned int) t,
+ h->binary_name);
sh->wpos += t;
if (sh->wpos == ntohs (sh->msg->size))
{
- GNUNET_CONTAINER_DLL_remove (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
if (NULL != sh->cont)
sh->cont (sh->cont_cls, GNUNET_YES);
GNUNET_free (sh);
}
if (NULL != h->sh_head)
- h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_to_helper,
- &helper_write,
- h);
+ h->write_task =
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->fh_to_helper,
+ &helper_write,
+ h);
}
*/
struct GNUNET_HELPER_SendHandle *
GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h,
- const struct GNUNET_MessageHeader *msg,
- int can_drop,
- GNUNET_HELPER_Continuation cont,
- void *cont_cls)
+ const struct GNUNET_MessageHeader *msg,
+ int can_drop,
+ GNUNET_HELPER_Continuation cont,
+ void *cont_cls)
{
struct GNUNET_HELPER_SendHandle *sh;
uint16_t mlen;
if (NULL == h->fh_to_helper)
return NULL;
- if ( (GNUNET_YES == can_drop) &&
- (NULL != h->sh_head) )
+ if ((GNUNET_YES == can_drop) && (NULL != h->sh_head))
return NULL;
mlen = ntohs (msg->size);
sh = GNUNET_malloc (sizeof (struct GNUNET_HELPER_SendHandle) + mlen);
- sh->msg = (const struct GNUNET_MessageHeader*) &sh[1];
+ sh->msg = (const struct GNUNET_MessageHeader *) &sh[1];
GNUNET_memcpy (&sh[1], msg, mlen);
sh->h = h;
sh->cont = cont;
sh->cont_cls = cont_cls;
- GNUNET_CONTAINER_DLL_insert_tail (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_insert_tail (h->sh_head, h->sh_tail, sh);
if (NULL == h->write_task)
- h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_to_helper,
- &helper_write,
- h);
+ h->write_task =
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->fh_to_helper,
+ &helper_write,
+ h);
return sh;
}
{
char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
if (NULL != path)
- BINDTEXTDOMAIN (PACKAGE, path);
+ bindtextdomain (PACKAGE, path);
GNUNET_free (path);
gettextinit = 1;
}
{
char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
if (NULL != path)
- BINDTEXTDOMAIN (PACKAGE, path);
+ bindtextdomain (PACKAGE, path);
GNUNET_free (path);
gettextinit = 1;
}
char *lgu;
GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/maps", getpid ());
- if (NULL == (f = FOPEN (fn, "r")))
+ if (NULL == (f = fopen (fn, "r")))
return NULL;
while (NULL != fgets (line, sizeof (line), f))
{
(NULL != (lgu = strstr (dir, current_pd->libname))))
{
lgu[0] = '\0';
- FCLOSE (f);
+ fclose (f);
return GNUNET_strdup (dir);
}
}
- FCLOSE (f);
+ fclose (f);
return NULL;
}
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
case GNUNET_OS_IPK_DATADIR:
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
break;
case GNUNET_OS_IPK_LOCALEDIR:
dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
- "locale" DIR_SEPARATOR_STR);
+ "locale" DIR_SEPARATOR_STR);
break;
case GNUNET_OS_IPK_ICONDIR:
dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
- "icons" DIR_SEPARATOR_STR);
+ "icons" DIR_SEPARATOR_STR);
break;
case GNUNET_OS_IPK_DOCDIR:
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
- "doc" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR,
+ "doc" DIR_SEPARATOR_STR
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
break;
case GNUNET_OS_IPK_LIBEXECDIR:
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
- "libexec" DIR_SEPARATOR_STR,
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp,
"%s%s%s%s",
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR
- "libexec" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR
- "libexec" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
}
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
- "libexec" DIR_SEPARATOR_STR,
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
break;
default:
"PATHS",
"SUID_BINARY_PATH",
&path);
- if ((NULL == path)||(0 == strlen (path)))
+ if ((NULL == path) || (0 == strlen (path)))
return GNUNET_OS_get_libexec_binary_path (progname);
path_len = strlen (path);
GNUNET_asprintf (&binary,
"%s%s%s",
path,
(path[path_len - 1] == DIR_SEPARATOR) ? ""
- : DIR_SEPARATOR_STR,
+ : DIR_SEPARATOR_STR,
progname);
cache = path;
return binary;
binary);
return GNUNET_SYSERR;
}
- if (0 != ACCESS (p, X_OK))
+ if (0 != access (p, X_OK))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p);
GNUNET_free (p);
return GNUNET_YES;
}
#endif
- if (0 != STAT (p, &statbuf))
+ if (0 != stat (p, &statbuf))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p);
GNUNET_free (p);
// Start the child process.
if (! (CreateProcess (
- p, // current windows (2k3 and up can handle / instead of \ in paths))
- parameters, // execute dryrun/priviliege checking mode
- NULL, // Process handle not inheritable
- NULL, // Thread handle not inheritable
- FALSE, // Set handle inheritance to FALSE
- CREATE_DEFAULT_ERROR_MODE, // No creation flags
- NULL, // Use parent's environment block
- NULL, // Use parent's starting directory
- &start, // Pointer to STARTUPINFO structure
- &proc) // Pointer to PROCESS_INFORMATION structure
+ p, // current windows (2k3 and up can handle / instead of \ in paths))
+ parameters, // execute dryrun/priviliege checking mode
+ NULL, // Process handle not inheritable
+ NULL, // Thread handle not inheritable
+ FALSE, // Set handle inheritance to FALSE
+ CREATE_DEFAULT_ERROR_MODE, // No creation flags
+ NULL, // Use parent's environment block
+ NULL, // Use parent's starting directory
+ &start, // Pointer to STARTUPINFO structure
+ &proc) // Pointer to PROCESS_INFORMATION structure
))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
#include "disk.h"
#include <unistr.h>
-#define LOG(kind,...) GNUNET_log_from (kind, "util-os-priority", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-os-priority", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-os-priority", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-os-priority", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-os-priority", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util-os-priority", syscall, filename)
#define GNUNET_OS_CONTROL_PIPE "GNUNET_OS_CONTROL_PIPE"
ssize_t ret;
pch = NULL;
- ret = GNUNET_DISK_file_read (control_pipe,
- &sig,
- sizeof (sig));
+ ret = GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig));
if (sizeof (sig) != ret)
{
if (-1 == ret)
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "GNUNET_DISK_file_read");
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Closing control pipe\n");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing control pipe\n");
GNUNET_DISK_file_close (control_pipe);
control_pipe = NULL;
GNUNET_SCHEDULER_cancel (spch);
return;
}
pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE);
- GNUNET_assert ( (NULL == pipe_fd) ||
- (strlen (pipe_fd) <= 0) );
+ GNUNET_assert ((NULL == pipe_fd) || (strlen (pipe_fd) <= 0));
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Got control code %d from parent via pipe %s\n",
sig,
pipe_fd);
pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- control_pipe,
- &parent_control_handler,
- control_pipe);
+ control_pipe,
+ &parent_control_handler,
+ control_pipe);
GNUNET_SIGNAL_raise ((int) sig);
}
return;
}
env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
- if ( (NULL == env_buf) || (strlen (env_buf) <= 0) )
+ if ((NULL == env_buf) || (strlen (env_buf) <= 0))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Not installing a handler because $%s is empty\n",
+ "Not installing a handler because $%s is empty\n",
GNUNET_OS_CONTROL_PIPE);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
pipe_fd = strtoull (env_buf, &env_buf_end, 16);
if ((0 != errno) || (env_buf == env_buf_end))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "strtoull",
- env_buf);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
-#if !defined (WINDOWS)
+#if ! defined(WINDOWS)
if (pipe_fd >= FD_SETSIZE)
#else
- if ((FILE_TYPE_UNKNOWN == GetFileType ((HANDLE) (uintptr_t) pipe_fd))
- && (0 != GetLastError ()))
+ if ((FILE_TYPE_UNKNOWN == GetFileType ((HANDLE) (uintptr_t) pipe_fd)) &&
+ (0 != GetLastError ()))
#endif
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
- env_buf);
+ env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
#if WINDOWS
- control_pipe = GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) (uintptr_t) pipe_fd);
+ control_pipe =
+ GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) (uintptr_t) pipe_fd);
#else
control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
#endif
if (NULL == control_pipe)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "open",
- env_buf);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
"Adding parent control handler pipe `%s' to the scheduler\n",
env_buf);
pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- control_pipe,
- &parent_control_handler,
- control_pipe);
- spch = GNUNET_SCHEDULER_add_shutdown (&shutdown_pch,
+ control_pipe,
+ &parent_control_handler,
control_pipe);
+ spch = GNUNET_SCHEDULER_add_shutdown (&shutdown_pch, control_pipe);
putenv (GNUNET_OS_CONTROL_PIPE "=");
}
* @return 0 on success, -1 on error
*/
int
-GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
- int sig)
+GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
{
int ret;
char csig;
if (NULL != proc->control_pipe)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending signal %d to pid: %u via pipe\n",
- sig,
- proc->pid);
- ret = GNUNET_DISK_file_write (proc->control_pipe,
- &csig,
- sizeof (csig));
+ "Sending signal %d to pid: %u via pipe\n",
+ sig,
+ proc->pid);
+ ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof (csig));
if (sizeof (csig) == ret)
return 0;
}
/* pipe failed or non-existent, try other methods */
switch (sig)
{
-#if !defined (WINDOWS)
+#if ! defined(WINDOWS)
case SIGHUP:
#endif
case SIGINT:
#if (SIGTERM != GNUNET_TERM_SIG)
case GNUNET_TERM_SIG:
#endif
-#if defined(WINDOWS) && !defined(__CYGWIN__)
+#if defined(WINDOWS) && ! defined(__CYGWIN__)
+ {
+ DWORD exitcode;
+ int must_kill = GNUNET_YES;
+ if (0 != GetExitCodeProcess (proc->handle, &exitcode))
+ must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
+ if (GNUNET_YES == must_kill)
{
- DWORD exitcode;
- int must_kill = GNUNET_YES;
- if (0 != GetExitCodeProcess (proc->handle, &exitcode))
- must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
- if (GNUNET_YES == must_kill)
+ if (0 == SafeTerminateProcess (proc->handle, 0, 0))
{
- if (0 == SafeTerminateProcess (proc->handle, 0, 0))
+ DWORD error_code = GetLastError ();
+ if ((error_code != WAIT_TIMEOUT) &&
+ (error_code != ERROR_PROCESS_ABORTED))
{
- DWORD error_code = GetLastError ();
- if ( (error_code != WAIT_TIMEOUT) &&
- (error_code != ERROR_PROCESS_ABORTED) )
- {
- LOG ((error_code == ERROR_ACCESS_DENIED) ?
- GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
- "SafeTermiateProcess failed with code %lu\n",
- error_code);
- /* The problem here is that a process that is already dying
+ LOG ((error_code == ERROR_ACCESS_DENIED) ? GNUNET_ERROR_TYPE_INFO
+ : GNUNET_ERROR_TYPE_WARNING,
+ "SafeTermiateProcess failed with code %lu\n",
+ error_code);
+ /* The problem here is that a process that is already dying
* might cause SafeTerminateProcess to fail with
* ERROR_ACCESS_DENIED, but the process WILL die eventually.
* If we really had a permissions problem, hanging up (which
* is what will happen in process_wait() in that case) is
* a valid option.
*/
- if (ERROR_ACCESS_DENIED == error_code)
- {
- errno = 0;
- }
- else
- {
- SetErrnoFromWinError (error_code);
- return -1;
- }
+ if (ERROR_ACCESS_DENIED == error_code)
+ {
+ errno = 0;
+ }
+ else
+ {
+ SetErrnoFromWinError (error_code);
+ return -1;
}
}
}
}
+ }
return 0;
#else
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Sending signal %d to pid: %u via system call\n",
sig,
proc->pid);
- return PLIBC_KILL (proc->pid, sig);
+ return kill (proc->pid, sig);
#endif
default:
-#if defined (WINDOWS)
+#if defined(WINDOWS)
errno = EINVAL;
return -1;
#else
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending signal %d to pid: %u via system call\n",
- sig,
- proc->pid);
- return PLIBC_KILL (proc->pid, sig);
+ "Sending signal %d to pid: %u via system call\n",
+ sig,
+ proc->pid);
+ return kill (proc->pid, sig);
#endif
}
}
* @return the current process id
*/
pid_t
-GNUNET_OS_process_get_pid (struct GNUNET_OS_Process * proc)
+GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc)
{
return proc->pid;
}
{
if (NULL != proc->control_pipe)
GNUNET_DISK_file_close (proc->control_pipe);
-#if defined (WINDOWS)
+#if defined(WINDOWS)
if (NULL != proc->handle)
CloseHandle (proc->handle);
#endif
win32_env_table = GetEnvironmentStringsA ();
if (NULL == win32_env_table)
return NULL;
- for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) ;
+ for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++)
+ ;
n_var = c;
index = GNUNET_malloc (sizeof (char *) * n_var);
for (c = 0; c < n_var; c++)
break;
}
}
- if (!found)
+ if (! found)
tablesize += len + 1;
ptr += len + 1;
}
break;
}
}
- if (!found)
+ if (! found)
{
strcpy (result_ptr, ptr);
result_ptr += len + 1;
* @param flags open flags (O_RDONLY, O_WRONLY)
*/
static void
-open_dev_null (int target_fd,
- int flags)
+open_dev_null (int target_fd, int flags)
{
int fd;
fd = open ("/dev/null", flags);
if (-1 == fd)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- "/dev/null");
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", "/dev/null");
return;
}
if (fd == target_fd)
static struct GNUNET_OS_Process *
start_process (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- struct GNUNET_DISK_PipeHandle *pipe_stdin,
- struct GNUNET_DISK_PipeHandle *pipe_stdout,
- struct GNUNET_DISK_PipeHandle *pipe_stderr,
- const SOCKTYPE *lsocks,
- const char *filename,
- char *const argv[])
+ struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdout,
+ struct GNUNET_DISK_PipeHandle *pipe_stderr,
+ const SOCKTYPE *lsocks,
+ const char *filename,
+ char *const argv[])
{
#ifndef MINGW
pid_t ret;
struct GNUNET_DISK_PipeHandle *childpipe;
int dup_childpipe_read_fd = -1;
- childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO,
- GNUNET_YES, GNUNET_NO);
+ childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
if (NULL == childpipe)
return NULL;
- childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe,
- GNUNET_DISK_PIPE_END_READ);
- childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe,
- GNUNET_DISK_PIPE_END_WRITE);
+ childpipe_read =
+ GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
+ childpipe_write =
+ GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close (childpipe);
- if ( (NULL == childpipe_read) ||
- (NULL == childpipe_write) ||
- (GNUNET_OK !=
- GNUNET_DISK_internal_file_handle_ (childpipe_read,
- &childpipe_read_fd,
- sizeof (int))) ||
- (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
+ if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
+ (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
+ &childpipe_read_fd,
+ sizeof (int))) ||
+ (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
{
if (NULL != childpipe_read)
GNUNET_DISK_file_close (childpipe_read);
}
if (NULL != pipe_stdin)
{
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
- &fd_stdin_read, sizeof (int)));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
- &fd_stdin_write, sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
+ &fd_stdin_read,
+ sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
+ &fd_stdin_write,
+ sizeof (int)));
}
if (NULL != pipe_stdout)
{
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE),
- &fd_stdout_write, sizeof (int)));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
- &fd_stdout_read, sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE),
+ &fd_stdout_write,
+ sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
+ &fd_stdout_read,
+ sizeof (int)));
}
if (NULL != pipe_stderr)
{
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stderr,
- GNUNET_DISK_PIPE_END_READ),
- &fd_stderr_read, sizeof (int)));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stderr,
- GNUNET_DISK_PIPE_END_WRITE),
- &fd_stderr_write, sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stderr, GNUNET_DISK_PIPE_END_READ),
+ &fd_stderr_read,
+ sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stderr, GNUNET_DISK_PIPE_END_WRITE),
+ &fd_stderr_write,
+ sizeof (int)));
}
lscp = NULL;
ls = 0;
int argcount = 0;
struct GNUNET_OS_Process *gnunet_proc;
char path[MAX_PATH + 1];
- char *our_env[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+ char *our_env[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
char *env_block = NULL;
char *pathbuf;
DWORD pathbuf_len;
DWORD error_code;
DWORD create_no_window;
- if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
+ if (GNUNET_SYSERR ==
+ GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
return NULL; /* not executable */
/* Search in prefix dir (hopefully - the directory from which
pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
- alloc_len =
- pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
- strlen (libdir);
+ alloc_len = pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
+ strlen (libdir);
pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
if (alloc_len != pathbuf_len - 1)
{
GNUNET_free (pathbuf);
- errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
+ errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
return NULL;
}
cmdlen = strlen (filename);
- if ( (cmdlen < 5) || (0 != strcmp (&filename[cmdlen - 4], ".exe")) )
+ if ((cmdlen < 5) || (0 != strcmp (&filename[cmdlen - 4], ".exe")))
GNUNET_asprintf (&non_const_filename, "%s.exe", filename);
else
GNUNET_asprintf (&non_const_filename, "%s", filename);
/* It could be in POSIX form, convert it to a DOS path early on */
- if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename, win_path)))
+ if (ERROR_SUCCESS !=
+ (lRet = plibc_conv_to_win_path (non_const_filename, win_path)))
{
SetErrnoFromWinError (lRet);
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path",
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
+ "plibc_conv_to_win_path",
non_const_filename);
GNUNET_free (non_const_filename);
GNUNET_free (pathbuf);
}
GNUNET_free (non_const_filename);
non_const_filename = GNUNET_strdup (win_path);
- /* Check that this is the full path. If it isn't, search. */
+ /* Check that this is the full path. If it isn't, search. */
/* FIXME: convert it to wchar_t and use SearchPathW?
* Remember: arguments to _start_process() are technically in UTF-8...
*/
{
snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Using path `%s' as-is. PATH is %s\n", path, ptr);
+ "Using path `%s' as-is. PATH is %s\n",
+ path,
+ ptr);
}
- else if (!SearchPathA
- (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
- path, NULL))
+ else if (! SearchPathA (pathbuf,
+ non_const_filename,
+ NULL,
+ sizeof (path) / sizeof (char),
+ path,
+ NULL))
{
SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
+ "SearchPath",
non_const_filename);
GNUNET_free (non_const_filename);
GNUNET_free (pathbuf);
return NULL;
}
else
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Found `%s' in PATH `%s'\n", path, pathbuf);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Found `%s' in PATH `%s'\n", path, pathbuf);
GNUNET_free (pathbuf);
GNUNET_free (non_const_filename);
while (*arg)
{
char arg_last_char = (*arg)[strlen (*arg) - 1];
- idx += sprintf (idx, "\"%s%s\"%s", *arg,
- arg_last_char == '\\' ? "\\" : "", *(arg + 1) ? " " : "");
+ idx += sprintf (idx,
+ "\"%s%s\"%s",
+ *arg,
+ arg_last_char == '\\' ? "\\" : "",
+ *(arg + 1) ? " " : "");
arg++;
}
GetHandleInformation (stdih, &stdif);
if (pipe_stdin != NULL)
{
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
- &stdin_handle, sizeof (HANDLE));
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
+ &stdin_handle,
+ sizeof (HANDLE));
start.hStdInput = stdin_handle;
}
else if (stdih)
GetHandleInformation (stdoh, &stdof);
if (NULL != pipe_stdout)
{
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE),
- &stdout_handle, sizeof (HANDLE));
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE),
+ &stdout_handle,
+ sizeof (HANDLE));
start.hStdOutput = stdout_handle;
}
else if (stdoh)
childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
if (NULL == childpipe)
return NULL;
- childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
- childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
+ childpipe_read =
+ GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
+ childpipe_write =
+ GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close (childpipe);
if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
(GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
- &childpipe_read_handle, sizeof (HANDLE))))
+ &childpipe_read_handle,
+ sizeof (HANDLE))))
{
if (childpipe_read)
GNUNET_DISK_file_close (childpipe_read);
if (lsocks != NULL && lsocks[0] != INVALID_SOCKET)
{
- lsocks_pipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
+ lsocks_pipe =
+ GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
if (lsocks_pipe == NULL)
{
}
return NULL;
}
- lsocks_write_fd = GNUNET_DISK_pipe_handle (lsocks_pipe,
- GNUNET_DISK_PIPE_END_WRITE);
+ lsocks_write_fd =
+ GNUNET_DISK_pipe_handle (lsocks_pipe, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_internal_file_handle_ (lsocks_write_fd,
- &lsocks_write, sizeof (HANDLE));
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (lsocks_pipe, GNUNET_DISK_PIPE_END_READ),
- &lsocks_read, sizeof (HANDLE));
+ &lsocks_write,
+ sizeof (HANDLE));
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (lsocks_pipe, GNUNET_DISK_PIPE_END_READ),
+ &lsocks_read,
+ sizeof (HANDLE));
}
else
{
GNUNET_asprintf (&our_env[env_off++], "%s=", GNUNET_OS_CONTROL_PIPE);
GNUNET_asprintf (&our_env[env_off++], "%p", childpipe_read_handle);
}
- if ( (lsocks != NULL) && (lsocks[0] != INVALID_SOCKET))
+ if ((lsocks != NULL) && (lsocks[0] != INVALID_SOCKET))
{
/*This will tell the child that we're going to send lsocks over the pipe*/
GNUNET_asprintf (&our_env[env_off++], "%s=", "GNUNET_OS_READ_LSOCKS");
GNUNET_free_non_null (our_env[--env_off]);
wpath_len = 0;
- if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len)))
+ if (NULL ==
+ (wpath =
+ u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len)))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno);
+ "Failed to convert `%s' from UTF-8 to UTF-16: %d\n",
+ path,
+ errno);
GNUNET_free (env_block);
GNUNET_free (cmd);
if (lsocks_pipe)
}
wcmd_len = 0;
- if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len)))
+ if (NULL ==
+ (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len)))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Failed to convert `%s' from UTF-8 to UTF-16: %d\n",
create_no_window = 0;
{
- HANDLE console_input = CreateFile ("CONIN$", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ HANDLE console_input = CreateFile ("CONIN$",
+ GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ 0,
+ NULL);
if (INVALID_HANDLE_VALUE == console_input)
create_no_window = CREATE_NO_WINDOW;
else
CloseHandle (console_input);
}
- bresult = CreateProcessW (wpath, wcmd, NULL, NULL, GNUNET_YES,
- create_no_window | CREATE_SUSPENDED, env_block, NULL, &start, &proc);
+ bresult = CreateProcessW (wpath,
+ wcmd,
+ NULL,
+ NULL,
+ GNUNET_YES,
+ create_no_window | CREATE_SUSPENDED,
+ env_block,
+ NULL,
+ &start,
+ &proc);
error_code = GetLastError ();
if ((NULL == pipe_stdin) && (stdih))
if (stdeh)
SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, stdef);
- if (!bresult)
+ if (! bresult)
LOG (GNUNET_ERROR_TYPE_ERROR,
"CreateProcess(%s, %s) failed: %lu\n",
path,
GNUNET_DISK_file_close (childpipe_read);
}
- if (!bresult)
+ if (! bresult)
{
if (GNUNET_YES == pipe_control)
{
ResumeThread (proc.hThread);
CloseHandle (proc.hThread);
- if ( (NULL == lsocks) || (INVALID_SOCKET == lsocks[0]) )
+ if ((NULL == lsocks) || (INVALID_SOCKET == lsocks[0]))
return gnunet_proc;
GNUNET_DISK_pipe_close_end (lsocks_pipe, GNUNET_DISK_PIPE_END_READ);
unsigned int i;
/* Tell the number of sockets */
- for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++);
+ for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++)
+ ;
wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
if (sizeof (count) != wrote)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to write %u count bytes to the child: %lu\n",
- sizeof (count), GetLastError ());
+ "Failed to write %u count bytes to the child: %lu\n",
+ sizeof (count),
+ GetLastError ());
break;
}
for (i = 0; lsocks && lsocks[i] != INVALID_SOCKET; i++)
{
WSAPROTOCOL_INFOA pi;
/* Get a socket duplication info */
- if (SOCKET_ERROR == WSADuplicateSocketA (lsocks[i], gnunet_proc->pid, &pi))
+ if (SOCKET_ERROR ==
+ WSADuplicateSocketA (lsocks[i], gnunet_proc->pid, &pi))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to duplicate an socket[%u]: %lu\n", i,
- GetLastError ());
+ "Failed to duplicate an socket[%u]: %lu\n",
+ i,
+ GetLastError ());
break;
}
/* Synchronous I/O is not nice, but we can't schedule this:
if (sizeof (size) != wrote)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to write %u size[%u] bytes to the child: %lu\n",
- sizeof (size), i, GetLastError ());
+ "Failed to write %u size[%u] bytes to the child: %lu\n",
+ sizeof (size),
+ i,
+ GetLastError ());
break;
}
/* Finally! Send the data */
if (sizeof (pi) != wrote)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to write %u socket[%u] bytes to the child: %lu\n",
- sizeof (pi), i, GetLastError ());
+ "Failed to write %u socket[%u] bytes to the child: %lu\n",
+ sizeof (pi),
+ i,
+ GetLastError ());
break;
}
}
*/
wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
fail = 0;
- }
- while (fail);
+ } while (fail);
GNUNET_DISK_file_sync (lsocks_write_fd);
GNUNET_DISK_pipe_close (lsocks_pipe);
struct GNUNET_OS_Process *
GNUNET_OS_start_process_vap (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- struct GNUNET_DISK_PipeHandle *pipe_stdin,
- struct GNUNET_DISK_PipeHandle *pipe_stdout,
+ struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdout,
struct GNUNET_DISK_PipeHandle *pipe_stderr,
- const char *filename,
- char *const argv[])
+ const char *filename,
+ char *const argv[])
{
return start_process (pipe_control,
std_inheritance,
- pipe_stdin,
- pipe_stdout,
+ pipe_stdin,
+ pipe_stdout,
pipe_stderr,
- NULL,
- filename,
- argv);
+ NULL,
+ filename,
+ argv);
}
struct GNUNET_OS_Process *
GNUNET_OS_start_process_va (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdin,
struct GNUNET_DISK_PipeHandle *pipe_stdout,
struct GNUNET_DISK_PipeHandle *pipe_stderr,
- const char *filename, va_list va)
+ const char *filename,
+ va_list va)
{
struct GNUNET_OS_Process *ret;
va_list ap;
va_end (ap);
ret = GNUNET_OS_start_process_vap (pipe_control,
std_inheritance,
- pipe_stdin,
- pipe_stdout,
+ pipe_stdin,
+ pipe_stdout,
pipe_stderr,
- filename,
- argv);
+ filename,
+ argv);
GNUNET_free (argv);
return ret;
}
struct GNUNET_OS_Process *
GNUNET_OS_start_process (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdin,
struct GNUNET_DISK_PipeHandle *pipe_stdout,
struct GNUNET_DISK_PipeHandle *pipe_stderr,
- const char *filename, ...)
+ const char *filename,
+ ...)
{
struct GNUNET_OS_Process *ret;
va_list ap;
ret = GNUNET_OS_start_process_va (pipe_control,
std_inheritance,
pipe_stdin,
- pipe_stdout,
+ pipe_stdout,
pipe_stderr,
filename,
ap);
struct GNUNET_OS_Process *
GNUNET_OS_start_process_v (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- const SOCKTYPE *lsocks,
+ const SOCKTYPE *lsocks,
const char *filename,
char *const argv[])
{
return start_process (pipe_control,
std_inheritance,
- NULL,
- NULL,
NULL,
- lsocks,
- filename,
- argv);
+ NULL,
+ NULL,
+ lsocks,
+ filename,
+ argv);
}
struct GNUNET_OS_Process *
GNUNET_OS_start_process_s (int pipe_control,
unsigned int std_inheritance,
- const SOCKTYPE * lsocks,
- const char *filename, ...)
+ const SOCKTYPE *lsocks,
+ const char *filename,
+ ...)
{
va_list ap;
char **argv;
{
if ('"' == *rpos)
{
- if (1 == quote_on)
- quote_on = 0;
- else
- quote_on = 1;
+ if (1 == quote_on)
+ quote_on = 0;
+ else
+ quote_on = 1;
}
- if ( (' ' == *rpos) && (0 == quote_on) )
+ if ((' ' == *rpos) && (0 == quote_on))
{
- if (NULL != last)
- argv_size++;
- last = NULL;
- rpos++;
- while (' ' == *rpos)
- rpos++;
+ if (NULL != last)
+ argv_size++;
+ last = NULL;
+ rpos++;
+ while (' ' == *rpos)
+ rpos++;
}
- if ( (NULL == last) && ('\0' != *rpos) ) // FIXME: == or !=?
- last = rpos;
+ if ((NULL == last) && ('\0' != *rpos)) // FIXME: == or !=?
+ last = rpos;
if ('\0' != *rpos)
- rpos++;
+ rpos++;
}
if (NULL != last)
argv_size++;
- }
- while (NULL != (arg = (va_arg (ap, const char*))));
+ } while (NULL != (arg = (va_arg (ap, const char *))));
va_end (ap);
argv = GNUNET_malloc (argv_size * sizeof (char *));
{
if ('"' == *pos)
{
- if (1 == quote_on)
- quote_on = 0;
- else
- quote_on = 1;
+ if (1 == quote_on)
+ quote_on = 0;
+ else
+ quote_on = 1;
}
- if ( (' ' == *pos) && (0 == quote_on) )
+ if ((' ' == *pos) && (0 == quote_on))
{
- *pos = '\0';
- if (NULL != last)
- argv[argv_size++] = GNUNET_strdup (last);
- last = NULL;
- pos++;
- while (' ' == *pos)
- pos++;
+ *pos = '\0';
+ if (NULL != last)
+ argv[argv_size++] = GNUNET_strdup (last);
+ last = NULL;
+ pos++;
+ while (' ' == *pos)
+ pos++;
}
- if ( (NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
- last = pos;
+ if ((NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
+ last = pos;
if ('\0' != *pos)
- pos++;
+ pos++;
}
if (NULL != last)
argv[argv_size++] = GNUNET_strdup (last);
last = NULL;
GNUNET_free (cp);
- }
- while (NULL != (arg = (va_arg (ap, const char*))));
+ } while (NULL != (arg = (va_arg (ap, const char *))));
va_end (ap);
argv[argv_size] = NULL;
- for(i = 0; i < argv_size; i++)
+ for (i = 0; i < argv_size; i++)
{
len = strlen (argv[i]);
- if ( (argv[i][0] == '"') && (argv[i][len-1] == '"'))
+ if ((argv[i][0] == '"') && (argv[i][len - 1] == '"'))
{
memmove (&argv[i][0], &argv[i][1], len - 2);
- argv[i][len-2] = '\0';
+ argv[i][len - 2] = '\0';
}
}
binary_path = argv[0];
- proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks,
- binary_path, argv);
+ proc = GNUNET_OS_start_process_v (pipe_control,
+ std_inheritance,
+ lsocks,
+ binary_path,
+ argv);
while (argv_size > 0)
GNUNET_free (argv[--argv_size]);
GNUNET_free (argv);
ret = waitpid (proc->pid, &status, options);
if (ret < 0)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "waitpid");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
return GNUNET_SYSERR;
}
if (0 == ret)
}
#else
#ifndef WNOHANG
-#define WNOHANG 42 /* just a flag for W32, purely internal at this point */
+#define WNOHANG 42 /* just a flag for W32, purely internal at this point */
#endif
HANDLE h;
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"Invalid process information {%d, %08X}\n",
- ret, h);
+ ret,
+ h);
return GNUNET_SYSERR;
}
if (h == NULL)
enum GNUNET_OS_ProcessStatusType *type,
unsigned long *code)
{
- return process_status (proc,
- type,
- code,
- WNOHANG);
+ return process_status (proc, type, code, WNOHANG);
}
enum GNUNET_OS_ProcessStatusType *type,
unsigned long *code)
{
- return process_status (proc,
- type,
- code,
- 0);
+ return process_status (proc, type, code, 0);
}
pid_t pid = proc->pid;
pid_t ret;
- while ( (pid != (ret = waitpid (pid, NULL, 0))) &&
- (EINTR == errno) ) ;
+ while ((pid != (ret = waitpid (pid, NULL, 0))) && (EINTR == errno))
+ ;
if (pid != ret)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "waitpid");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
return GNUNET_SYSERR;
}
return GNUNET_OK;
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"Invalid process information {%d, %08X}\n",
- proc->pid, h);
+ proc->pid,
+ h);
return GNUNET_SYSERR;
}
if (NULL == h)
cmd->rtask = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (GNUNET_YES !=
- GNUNET_NETWORK_fdset_handle_isset (tc->read_ready,
- cmd->r))
+ if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
{
/* timeout */
proc = cmd->proc;
return;
}
ret = GNUNET_DISK_file_read (cmd->r,
- &cmd->buf[cmd->off],
- sizeof (cmd->buf) - cmd->off);
+ &cmd->buf[cmd->off],
+ sizeof (cmd->buf) - cmd->off);
if (ret <= 0)
{
if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
cmd->off -= (end + 1 - cmd->buf);
end = memchr (cmd->buf, '\n', cmd->off);
}
- cmd->rtask
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
- (cmd->timeout),
- cmd->r,
- &cmd_read, cmd);
+ cmd->rtask =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining (
+ cmd->timeout),
+ cmd->r,
+ &cmd_read,
+ cmd);
}
struct GNUNET_DISK_PipeHandle *opipe;
va_list ap;
- opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES,
- GNUNET_NO, GNUNET_YES);
+ opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == opipe)
return NULL;
va_start (ap, binary);
/* redirect stdout, don't inherit stderr/stdin */
- eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL,
- opipe, NULL, binary,
- ap);
+ eip =
+ GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, NULL, binary, ap);
va_end (ap);
if (NULL == eip)
{
cmd->opipe = opipe;
cmd->proc = proc;
cmd->proc_cls = proc_cls;
- cmd->r = GNUNET_DISK_pipe_handle (opipe,
- GNUNET_DISK_PIPE_END_READ);
- cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout,
- cmd->r,
- &cmd_read,
- cmd);
+ cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
+ cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
return cmd;
}
sprintf (s, "%6s %15s", cryptosystem, description);
t = GNUNET_TIME_absolute_get_duration (start);
t = GNUNET_TIME_relative_divide (t, l);
- FPRINTF (stdout,
+ fprintf (stdout,
"%s: %10s\n",
s,
GNUNET_STRINGS_relative_time_to_string (t,
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_
("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
#include <ltdl.h>
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-plugin", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-plugin", __VA_ARGS__)
/**
* Linked list of active plugins.
err = lt_dlinit ();
if (err > 0)
{
- FPRINTF (stderr,
- _("Initialization of plugin mechanism failed: %s!\n"),
+ fprintf (stderr,
+ _ ("Initialization of plugin mechanism failed: %s!\n"),
lt_dlerror ());
return;
}
* @return NULL if the symbol was not found
*/
static GNUNET_PLUGIN_Callback
-resolve_function (struct PluginList *plug,
- const char *name)
+resolve_function (struct PluginList *plug, const char *name)
{
char *initName;
void *mptr;
- GNUNET_asprintf (&initName,
- "_%s_%s",
- plug->name,
- name);
+ GNUNET_asprintf (&initName, "_%s_%s", plug->name, name);
mptr = lt_dlsym (plug->handle, &initName[1]);
if (NULL == mptr)
mptr = lt_dlsym (plug->handle, initName);
if (NULL == mptr)
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed to resolve method '%s' with error: %s\n"),
+ _ ("`%s' failed to resolve method '%s' with error: %s\n"),
"lt_dlsym",
- &initName[1], lt_dlerror ());
+ &initName[1],
+ lt_dlerror ());
GNUNET_free (initName);
return mptr;
}
GNUNET_PLUGIN_Callback init;
void *ret;
- if (!initialized)
+ if (! initialized)
{
initialized = GNUNET_YES;
plugin_init ();
if (libhandle == NULL)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed for library `%s' with error: %s\n"),
+ _ ("`%s' failed for library `%s' with error: %s\n"),
"lt_dlopenext",
- library_name, lt_dlerror ());
+ library_name,
+ lt_dlerror ());
return NULL;
}
plug = GNUNET_new (struct PluginList);
* @return whatever the shutdown function returned
*/
void *
-GNUNET_PLUGIN_unload (const char *library_name,
- void *arg)
+GNUNET_PLUGIN_unload (const char *library_name, void *arg)
{
struct PluginList *pos;
struct PluginList *prev;
libname = slashpos + 1;
n = strlen (libname);
if (0 != strncmp (lac->basename, libname, strlen (lac->basename)))
- return GNUNET_OK; /* wrong name */
+ return GNUNET_OK; /* wrong name */
if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la")))
- return GNUNET_OK; /* .la file */
+ return GNUNET_OK; /* .la file */
basename = GNUNET_strdup (libname);
if (NULL != (dot = strstr (basename, ".")))
*dot = '\0';
* @param cb_cls closure for @a cb
*/
void
-GNUNET_PLUGIN_load_all (const char *basename, void *arg,
- GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
+GNUNET_PLUGIN_load_all (const char *basename,
+ void *arg,
+ GNUNET_PLUGIN_LoaderCallback cb,
+ void *cb_cls)
{
struct LoadAllContext lac;
char *path;
if (NULL == path)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not determine plugin installation path.\n"));
+ _ ("Could not determine plugin installation path.\n"));
return;
}
lac.basename = basename;
/* prepare */
#if ENABLE_NLS
if (NULL != pd->gettext_domain)
+ {
+ setlocale (LC_ALL, "");
+ path = (NULL == pd->gettext_path)
+ ? GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR)
+ : GNUNET_strdup (pd->gettext_path);
+ if (NULL != path)
{
- setlocale (LC_ALL, "");
- path = (NULL == pd->gettext_path)
- ? GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR)
- : GNUNET_strdup (pd->gettext_path);
- if (NULL != path)
- {
- BINDTEXTDOMAIN (pd->gettext_domain, path);
- GNUNET_free (path);
- }
- textdomain (pd->gettext_domain);
+ bindtextdomain (pd->gettext_domain, path);
+ GNUNET_free (path);
}
+ textdomain (pd->gettext_domain);
+ }
#endif
cnt = 0;
while (NULL != options[cnt].name)
#endif
-#define LOG(kind,...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, \
- "util-service", \
- syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-service", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file ( \
- kind, "util-service", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
/**
* Task scheduled to do the listening.
*/
struct GNUNET_SCHEDULER_Task *listen_task;
-
};
static int
have_non_monitor_clients (struct GNUNET_SERVICE_Handle *sh)
{
- for (struct GNUNET_SERVICE_Client *client = sh->clients_head;
- NULL != client;
+ for (struct GNUNET_SERVICE_Client *client = sh->clients_head; NULL != client;
client = client->next)
{
if (client->is_monitor)
* @param sr reason for suspending accepting connections
*/
static void
-do_suspend (struct GNUNET_SERVICE_Handle *sh,
- enum SuspendReason sr)
+do_suspend (struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
{
struct ServiceListenContext *slc;
break;
case GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN:
if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
- do_suspend (sh,
- SUSPEND_STATE_SHUTDOWN);
+ do_suspend (sh, SUSPEND_STATE_SHUTDOWN);
if (GNUNET_NO == have_non_monitor_clients (sh))
GNUNET_SERVICE_shutdown (sh);
break;
if (NULL == list)
return GNUNET_NO;
i = 0;
- while ( (0 != list[i].network.s_addr) ||
- (0 != list[i].netmask.s_addr) )
+ while ((0 != list[i].network.s_addr) || (0 != list[i].netmask.s_addr))
{
if ((add->s_addr & list[i].netmask.s_addr) ==
(list[i].network.s_addr & list[i].netmask.s_addr))
if (NULL == list)
return GNUNET_NO;
i = 0;
- NEXT:
+NEXT:
while (0 != GNUNET_is_zero (&list[i].network))
{
for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
client->send_task = NULL;
buf = (const char *) client->msg;
left = ntohs (client->msg->size) - client->msg_pos;
- ret = GNUNET_NETWORK_socket_send (client->sock,
- &buf[client->msg_pos],
- left);
+ ret = GNUNET_NETWORK_socket_send (client->sock, &buf[client->msg_pos], left);
GNUNET_assert (ret <= (ssize_t) left);
if (0 == ret)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "no data send");
- GNUNET_MQ_inject_error (client->mq,
- GNUNET_MQ_ERROR_WRITE);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "no data send");
+ GNUNET_MQ_inject_error (client->mq, GNUNET_MQ_ERROR_WRITE);
return;
}
if (-1 == ret)
{
- if ( (EAGAIN == errno) ||
- (EINTR == errno) )
+ if ((EAGAIN == errno) || (EINTR == errno))
{
/* ignore */
ret = 0;
else
{
if (EPIPE != errno)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "send");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
LOG (GNUNET_ERROR_TYPE_DEBUG,
"socket send returned with error code %i",
errno);
- GNUNET_MQ_inject_error (client->mq,
- GNUNET_MQ_ERROR_WRITE);
+ GNUNET_MQ_inject_error (client->mq, GNUNET_MQ_ERROR_WRITE);
return;
}
}
if (left > (size_t) ret)
{
GNUNET_assert (NULL == client->drop_task);
- client->send_task
- = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &do_send,
- client);
+ client->send_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &do_send,
+ client);
return;
}
GNUNET_MQ_impl_send_continue (client->mq);
ntohs (msg->size));
client->msg = msg;
client->msg_pos = 0;
- client->send_task
- = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &do_send,
- client);
+ client->send_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &do_send,
+ client);
}
* @param impl_state state specific to the implementation
*/
static void
-service_mq_cancel (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+service_mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct GNUNET_SERVICE_Client *client = impl_state;
* @param error error code
*/
static void
-service_mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+service_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_SERVICE_Handle *sh = client->sh;
- if ( (GNUNET_MQ_ERROR_NO_MATCH == error) &&
- (GNUNET_NO == sh->require_found) )
+ if ((GNUNET_MQ_ERROR_NO_MATCH == error) && (GNUNET_NO == sh->require_found))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No handler for message of type %u found\n",
{
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */
- client->warn_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_client_continue,
- client);
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _ (
- "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
- (unsigned int) client->warn_type,
- GNUNET_STRINGS_relative_time_to_string (
- GNUNET_TIME_absolute_get_duration (client->warn_start),
- GNUNET_YES));
+ GNUNET_break (
+ 0 !=
+ client->warn_type); /* type should never be 0 here, as we don't use 0 */
+ client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_no_client_continue,
+ client);
+ LOG (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
+ (unsigned int) client->warn_type,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (
+ client->warn_start),
+ GNUNET_YES));
}
* @return #GNUNET_OK on success, #GNUNET_SYSERR if the client was dropped
*/
static int
-service_client_mst_cb (void *cls,
- const struct GNUNET_MessageHeader *message)
+service_client_mst_cb (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
client->warn_type = ntohs (message->type);
client->warn_start = GNUNET_TIME_absolute_get ();
GNUNET_assert (NULL == client->warn_task);
- client->warn_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_client_continue,
- client);
- GNUNET_MQ_inject_message (client->mq,
- message);
+ client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_no_client_continue,
+ client);
+ GNUNET_MQ_inject_message (client->mq, message);
if (NULL != client->drop_task)
return GNUNET_SYSERR;
return GNUNET_OK;
int ret;
client->recv_task = NULL;
- ret = GNUNET_MST_read (client->mst,
- client->sock,
- GNUNET_NO,
- GNUNET_YES);
+ ret = GNUNET_MST_read (client->mst, client->sock, GNUNET_NO, GNUNET_YES);
if (GNUNET_SYSERR == ret)
{
/* client closed connection (or IO error) */
if (NULL != client->recv_task)
return;
/* MST needs more data, re-schedule read job */
- client->recv_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &service_client_recv,
- client);
+ client->recv_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &service_client_recv,
+ client);
}
struct GNUNET_SERVICE_Client *client;
client = GNUNET_new (struct GNUNET_SERVICE_Client);
- GNUNET_CONTAINER_DLL_insert (sh->clients_head,
- sh->clients_tail,
- client);
+ GNUNET_CONTAINER_DLL_insert (sh->clients_head, sh->clients_tail, client);
client->sh = sh;
client->sock = csock;
client->mq = GNUNET_MQ_queue_for_callbacks (&service_mq_send,
sh->handlers,
&service_mq_error_handler,
client);
- client->mst = GNUNET_MST_create (&service_client_mst_cb,
- client);
+ client->mst = GNUNET_MST_create (&service_client_mst_cb, client);
if (NULL != sh->connect_cb)
- client->user_context = sh->connect_cb (sh->cb_cls,
- client,
- client->mq);
- GNUNET_MQ_set_handlers_closure (client->mq,
- client->user_context);
- client->recv_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &service_client_recv,
- client);
+ client->user_context = sh->connect_cb (sh->cb_cls, client, client->mq);
+ GNUNET_MQ_set_handlers_closure (client->mq, client->user_context);
+ client->recv_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &service_client_recv,
+ client);
}
if (NULL == sock)
{
if (EMFILE == errno)
- do_suspend (sh,
- SUSPEND_STATE_EMFILE);
+ do_suspend (sh, SUSPEND_STATE_EMFILE);
else if (EAGAIN != errno)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "accept");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept");
break;
}
switch (sa.ss_family)
case AF_INET:
GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
v4 = (const struct sockaddr_in *) &sa;
- ok = ( ( (NULL == sh->v4_allowed) ||
- (check_ipv4_listed (sh->v4_allowed,
- &v4->sin_addr))) &&
- ( (NULL == sh->v4_denied) ||
- (! check_ipv4_listed (sh->v4_denied,
- &v4->sin_addr)) ) );
+ ok = (((NULL == sh->v4_allowed) ||
+ (check_ipv4_listed (sh->v4_allowed, &v4->sin_addr))) &&
+ ((NULL == sh->v4_denied) ||
+ (! check_ipv4_listed (sh->v4_denied, &v4->sin_addr))));
break;
case AF_INET6:
GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
v6 = (const struct sockaddr_in6 *) &sa;
- ok = ( ( (NULL == sh->v6_allowed) ||
- (check_ipv6_listed (sh->v6_allowed,
- &v6->sin6_addr))) &&
- ( (NULL == sh->v6_denied) ||
- (! check_ipv6_listed (sh->v6_denied,
- &v6->sin6_addr)) ) );
+ ok = (((NULL == sh->v6_allowed) ||
+ (check_ipv6_listed (sh->v6_allowed, &v6->sin6_addr))) &&
+ ((NULL == sh->v6_denied) ||
+ (! check_ipv6_listed (sh->v6_denied, &v6->sin6_addr))));
break;
#ifndef WINDOWS
case AF_UNIX:
- ok = GNUNET_OK; /* controlled using file-system ACL now */
+ ok = GNUNET_OK; /* controlled using file-system ACL now */
break;
#endif
default:
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service rejected incoming connection from %s due to policy.\n",
- GNUNET_a2s ((const struct sockaddr *) &sa,
- addrlen));
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_a2s ((const struct sockaddr *) &sa, addrlen));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
continue;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service accepted incoming connection from %s.\n",
- GNUNET_a2s ((const struct sockaddr *) &sa,
- addrlen));
- start_client (slc->sh,
- sock);
+ GNUNET_a2s ((const struct sockaddr *) &sa, addrlen));
+ start_client (slc->sh, sock);
}
if (0 != sh->suspend_state)
return;
- slc->listen_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- slc->listen_socket,
- &accept_client,
- slc);
+ slc->listen_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ slc->listen_socket,
+ &accept_client,
+ slc);
}
* or #SUSPEND_STATE_NONE on first startup
*/
static void
-do_resume (struct GNUNET_SERVICE_Handle *sh,
- enum SuspendReason sr)
+do_resume (struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
{
struct ServiceListenContext *slc;
- GNUNET_assert ( (SUSPEND_STATE_NONE == sr) ||
- (0 != (sh->suspend_state & sr)) );
+ GNUNET_assert ((SUSPEND_STATE_NONE == sr) || (0 != (sh->suspend_state & sr)));
sh->suspend_state -= sr;
if (SUSPEND_STATE_NONE != sh->suspend_state)
return;
for (slc = sh->slc_head; NULL != slc; slc = slc->next)
{
GNUNET_assert (NULL == slc->listen_task);
- slc->listen_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- slc->listen_socket,
- &accept_client,
- slc);
+ slc->listen_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ slc->listen_socket,
+ &accept_client,
+ slc);
}
}
struct GNUNET_SERVICE_Handle *sh = cls;
if (GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN != sh->options)
- GNUNET_SCHEDULER_add_shutdown (&service_shutdown,
- sh);
- do_resume (sh,
- SUSPEND_STATE_NONE);
+ GNUNET_SCHEDULER_add_shutdown (&service_shutdown, sh);
+ do_resume (sh, SUSPEND_STATE_NONE);
if (-1 != sh->ready_confirm_fd)
{
- GNUNET_break (1 == WRITE (sh->ready_confirm_fd, ".", 1));
- GNUNET_break (0 == CLOSE (sh->ready_confirm_fd));
+ GNUNET_break (1 == write (sh->ready_confirm_fd, ".", 1));
+ GNUNET_break (0 == close (sh->ready_confirm_fd));
sh->ready_confirm_fd = -1;
}
if (NULL != sh->service_init_cb)
- sh->service_init_cb (sh->cb_cls,
- sh->cfg,
- sh);
+ sh->service_init_cb (sh->cb_cls, sh->cfg, sh);
}
{
char *opt;
- if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
- sh->service_name,
- option))
+ if (! GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
{
char *opt;
- if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
- sh->service_name,
- option))
+ if (! GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
un = GNUNET_new (struct sockaddr_un);
un->sun_family = AF_UNIX;
- GNUNET_strlcpy (un->sun_path,
- unixpath,
- sizeof (un->sun_path));
+ GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path));
#ifdef LINUX
if (GNUNET_YES == abstract)
un->sun_path[0] = '\0';
*addr_lens = NULL;
desc = NULL;
disablev6 = GNUNET_NO;
- if ( (GNUNET_NO ==
- GNUNET_NETWORK_test_pf (PF_INET6)) ||
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- service_name,
- "DISABLEV6") ) )
+ if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
+ (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
disablev6 = GNUNET_YES;
port = 0;
- if (GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "PORT"))
+ if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- service_name,
- "PORT",
- &port))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ service_name,
+ "PORT",
+ &port))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Require valid port number for service `%s' in configuration!\n"),
}
}
- if (GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "BINDTO"))
+ if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
{
GNUNET_break (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg,
abstract = GNUNET_NO;
#ifdef AF_UNIX
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "UNIXPATH")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- service_name,
- "UNIXPATH",
- &unixpath)) &&
+ GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
+ service_name,
+ "UNIXPATH",
+ &unixpath)) &&
(0 < strlen (unixpath)))
{
/* probe UNIX support */
unixpath,
(unsigned long long) sizeof (s_un.sun_path));
unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _ ("Using `%s' instead\n"),
- unixpath);
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
}
#ifdef LINUX
abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
if (GNUNET_SYSERR == abstract)
abstract = GNUNET_NO;
#endif
- if ( (GNUNET_YES != abstract) &&
- (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (unixpath)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "mkdir",
- unixpath);
+ if ((GNUNET_YES != abstract) &&
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
}
if (NULL != unixpath)
{
- desc = GNUNET_NETWORK_socket_create (AF_UNIX,
- SOCK_STREAM,
- 0);
+ desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
if (NULL == desc)
{
- if ((ENOBUFS == errno) ||
- (ENOMEM == errno) ||
- (ENFILE == errno) ||
+ if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
(EACCES == errno))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
GNUNET_free_non_null (hostname);
GNUNET_free (unixpath);
return GNUNET_SYSERR;
_ (
"Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
service_name,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (unixpath);
unixpath = NULL;
}
else
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (desc));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
desc = NULL;
}
}
}
if (0 == port)
{
- saddrs = GNUNET_new_array (2,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (2,
- socklen_t);
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ saddrs = GNUNET_new_array (2, struct sockaddr *);
+ saddrlens = GNUNET_new_array (2, socklen_t);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
GNUNET_free_non_null (unixpath);
GNUNET_free_non_null (hostname);
*addrs = saddrs;
"Resolving `%s' since that is where `%s' will bind to.\n",
hostname,
service_name);
- memset (&hints,
- 0,
- sizeof (struct addrinfo));
+ memset (&hints, 0, sizeof (struct addrinfo));
if (disablev6)
hints.ai_family = AF_INET;
hints.ai_protocol = IPPROTO_TCP;
- if ((0 != (ret = getaddrinfo (hostname,
- NULL,
- &hints,
- &res))) ||
+ if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
(NULL == res))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
while (NULL != (pos = next))
{
next = pos->ai_next;
- if ( (disablev6) &&
- (pos->ai_family == AF_INET6) )
+ if ((disablev6) && (pos->ai_family == AF_INET6))
continue;
i++;
}
resi = i;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1, socklen_t);
i = 0;
if (NULL != unixpath)
{
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
next = res;
while (NULL != (pos = next))
{
next = pos->ai_next;
- if ( (disablev6) &&
- (AF_INET6 == pos->ai_family) )
+ if ((disablev6) && (AF_INET6 == pos->ai_family))
continue;
- if ( (IPPROTO_TCP != pos->ai_protocol) &&
- (0 != pos->ai_protocol) )
- continue; /* not TCP */
- if ( (SOCK_STREAM != pos->ai_socktype) &&
- (0 != pos->ai_socktype) )
- continue; /* huh? */
+ if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
+ continue; /* not TCP */
+ if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
+ continue; /* huh? */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service `%s' will bind to `%s'\n",
service_name,
- GNUNET_a2s (pos->ai_addr,
- pos->ai_addrlen));
+ GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
if (AF_INET == pos->ai_family)
{
GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
saddrlens[i] = pos->ai_addrlen;
saddrs[i] = GNUNET_malloc (saddrlens[i]);
- GNUNET_memcpy (saddrs[i],
- pos->ai_addr,
- saddrlens[i]);
+ GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
}
else
GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen);
saddrlens[i] = pos->ai_addrlen;
saddrs[i] = GNUNET_malloc (saddrlens[i]);
- GNUNET_memcpy (saddrs[i],
- pos->ai_addr,
- saddrlens[i]);
+ GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
}
i++;
if (NULL != unixpath)
resi++;
i = 0;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1, socklen_t);
if (NULL != unixpath)
{
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in);
resi = 2;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1, socklen_t);
i = 0;
if (NULL != unixpath)
{
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in6);
HANDLE lsocks_pipe;
env_buf = getenv ("GNUNET_OS_READ_LSOCKS");
- if ( (NULL == env_buf) ||
- (strlen (env_buf) <= 0) )
+ if ((NULL == env_buf) || (strlen (env_buf) <= 0))
return NULL;
/* Using W32 API directly here, because this pipe will
* never be used outside of this function, and it's just too much of a bother
* to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
*/
- lsocks_pipe = (HANDLE) strtoul (env_buf,
- NULL,
- 10);
- if ( (0 == lsocks_pipe) ||
- (INVALID_HANDLE_VALUE == lsocks_pipe))
+ lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10);
+ if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
return NULL;
fail = 1;
do
int fail2;
DWORD rd;
- ret = ReadFile (lsocks_pipe,
- &count,
- sizeof (count),
- &rd,
- NULL);
- if ( (0 == ret) ||
- (sizeof (count) != rd) ||
- (0 == count) )
+ ret = ReadFile (lsocks_pipe, &count, sizeof (count), &rd, NULL);
+ if ((0 == ret) || (sizeof (count) != rd) || (0 == count))
break;
- lsocks = GNUNET_new_array (count + 1,
- struct GNUNET_NETWORK_Handle *);
+ lsocks = GNUNET_new_array (count + 1, struct GNUNET_NETWORK_Handle *);
fail2 = 1;
for (i = 0; i < count; i++)
uint64_t size;
SOCKET s;
- ret = ReadFile (lsocks_pipe,
- &size,
- sizeof (size),
- &rd,
- NULL);
- if ( (0 == ret) ||
- (sizeof (size) != rd) ||
- (sizeof (pi) != size) )
+ ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL);
+ if ((0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size))
break;
- ret = ReadFile (lsocks_pipe,
- &pi,
- sizeof (pi),
- &rd,
- NULL);
- if ( (0 == ret) ||
- (sizeof (pi) != rd))
+ ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL);
+ if ((0 == ret) || (sizeof (pi) != rd))
break;
s = WSASocketA (pi.iAddressFamily,
pi.iSocketType,
break;
lsocks[count] = NULL;
fail = 0;
- }
- while (fail);
+ } while (fail);
CloseHandle (lsocks_pipe);
if (fail)
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Could not access a pre-bound socket, will try to bind myself\n"));
for (i = 0; (i < count) && (NULL != lsocks[i]); i++)
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (lsocks[i]));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsocks[i]));
GNUNET_free (lsocks);
return NULL;
}
* @return NULL on error, otherwise the listen socket
*/
static struct GNUNET_NETWORK_Handle *
-open_listen_socket (const struct sockaddr *server_addr,
- socklen_t socklen)
+open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen)
{
struct GNUNET_NETWORK_Handle *sock;
uint16_t port;
port = 0;
break;
}
- sock = GNUNET_NETWORK_socket_create (server_addr->sa_family,
- SOCK_STREAM,
- 0);
+ sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0);
if (NULL == sock)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
errno = 0;
return NULL;
}
/* bind the socket */
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock,
- server_addr,
- socklen))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen))
{
eno = errno;
if (EADDRINUSE != errno)
port,
(AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
else
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "bind");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
eno = 0;
}
else
if (0 != port)
LOG (GNUNET_ERROR_TYPE_WARNING,
_ ("`%s' failed for port %d (%s): address already in use\n"),
- "bind", port,
+ "bind",
+ port,
(AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
else if (AF_UNIX == server_addr->sa_family)
{
GNUNET_a2s (server_addr, socklen));
}
}
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
errno = eno;
return NULL;
}
- if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock,
- 5))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "listen");
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen");
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
errno = 0;
return NULL;
}
char dummy[2];
#endif
- if (GNUNET_CONFIGURATION_have_value
- (sh->cfg,
- sh->service_name,
- "TOLERANT"))
+ if (GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, "TOLERANT"))
{
if (GNUNET_SYSERR ==
- (tolerant =
- GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "TOLERANT")))
+ (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "TOLERANT")))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Specified value for `%s' of service `%s' is invalid\n"),
lsocks = NULL;
#ifndef MINGW
errno = 0;
- if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) &&
- (1 == SSCANF (nfds,
- "%u%1s",
- &cnt,
- dummy)) &&
- (cnt > 0) &&
- (cnt < FD_SETSIZE) &&
- (cnt + 4 < FD_SETSIZE) )
+ if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
+ (1 == sscanf (nfds, "%u%1s", &cnt, dummy)) && (cnt > 0) &&
+ (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
{
- lsocks = GNUNET_new_array (cnt + 1,
- struct GNUNET_NETWORK_Handle *);
+ lsocks = GNUNET_new_array (cnt + 1, struct GNUNET_NETWORK_Handle *);
while (0 < cnt--)
{
- flags = fcntl (3 + cnt,
- F_GETFD);
- if ( (flags < 0) ||
- (0 != (flags & FD_CLOEXEC)) ||
- (NULL ==
- (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
+ flags = fcntl (3 + cnt, F_GETFD);
+ if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
+ (NULL == (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ (
slc = GNUNET_new (struct ServiceListenContext);
slc->sh = sh;
slc->listen_socket = *ls;
- GNUNET_CONTAINER_DLL_insert (sh->slc_head,
- sh->slc_tail,
- slc);
+ GNUNET_CONTAINER_DLL_insert (sh->slc_head, sh->slc_tail, slc);
}
GNUNET_free (lsocks);
}
socklen_t *addrlens;
int num;
- num = get_server_addresses (sh->service_name,
- sh->cfg,
- &addrs,
- &addrlens);
+ num = get_server_addresses (sh->service_name, sh->cfg, &addrs, &addrlens);
if (GNUNET_SYSERR == num)
return GNUNET_SYSERR;
slc = GNUNET_new (struct ServiceListenContext);
slc->sh = sh;
- slc->listen_socket = open_listen_socket (addrs[i],
- addrlens[i]);
+ slc->listen_socket = open_listen_socket (addrs[i], addrlens[i]);
GNUNET_free (addrs[i]);
if (NULL == slc->listen_socket)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "bind");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
GNUNET_free (slc);
continue;
}
- GNUNET_CONTAINER_DLL_insert (sh->slc_head,
- sh->slc_tail,
- slc);
+ GNUNET_CONTAINER_DLL_insert (sh->slc_head, sh->slc_tail, slc);
}
GNUNET_free_non_null (addrlens);
GNUNET_free_non_null (addrs);
- if ( (0 != num) &&
- (NULL == sh->slc_head) )
+ if ((0 != num) && (NULL == sh->slc_head))
{
/* All attempts to bind failed, hard failure */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ (
- "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
return GNUNET_SYSERR;
}
}
sh->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
- sh->match_uid
- = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "UNIX_MATCH_UID");
- sh->match_gid
- = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "UNIX_MATCH_GID");
- process_acl4 (&sh->v4_denied,
- sh,
- "REJECT_FROM");
- process_acl4 (&sh->v4_allowed,
- sh,
- "ACCEPT_FROM");
- process_acl6 (&sh->v6_denied,
- sh,
- "REJECT_FROM6");
- process_acl6 (&sh->v6_allowed,
- sh,
- "ACCEPT_FROM6");
+ sh->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "UNIX_MATCH_UID");
+ sh->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "UNIX_MATCH_GID");
+ process_acl4 (&sh->v4_denied, sh, "REJECT_FROM");
+ process_acl4 (&sh->v4_allowed, sh, "ACCEPT_FROM");
+ process_acl6 (&sh->v6_denied, sh, "REJECT_FROM6");
+ process_acl6 (&sh->v6_allowed, sh, "ACCEPT_FROM6");
return GNUNET_OK;
}
{
char *un;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
- sh->service_name,
- "USERNAME",
- &un))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
+ sh->service_name,
+ "USERNAME",
+ &un))
return NULL;
return un;
}
char *user;
if (NULL == (user = get_user_name (sh)))
- return GNUNET_OK; /* keep */
+ return GNUNET_OK; /* keep */
#ifndef MINGW
struct passwd *pws;
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Cannot obtain information about user `%s': %s\n"),
user,
- errno == 0 ? _ ("No such user") : STRERROR (errno));
+ errno == 0 ? _ ("No such user") : strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
- if ( (0 != setgid (pws->pw_gid)) ||
- (0 != setegid (pws->pw_gid)) ||
+ if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
#if HAVE_INITGROUPS
- (0 != initgroups (user,
- pws->pw_gid)) ||
+ (0 != initgroups (user, pws->pw_gid)) ||
#endif
- (0 != setuid (pws->pw_uid)) ||
- (0 != seteuid (pws->pw_uid)))
+ (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
{
- if ((0 != setregid (pws->pw_gid,
- pws->pw_gid)) ||
- (0 != setreuid (pws->pw_uid,
- pws->pw_uid)))
+ if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
+ (0 != setreuid (pws->pw_uid, pws->pw_uid)))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Cannot change user/group to `%s': %s\n"),
user,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
{
char *pif;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
- sh->service_name,
- "PIDFILE",
- &pif))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
+ sh->service_name,
+ "PIDFILE",
+ &pif))
return NULL;
return pif;
}
char *pif = get_pid_file_name (sh);
if (NULL == pif)
- return; /* no PID file */
- if (0 != UNLINK (pif))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- pif);
+ return; /* no PID file */
+ if (0 != unlink (pif))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
GNUNET_free (pif);
}
int nullfd;
int filedes[2];
- if (0 != PIPE (filedes))
+ if (0 != pipe (filedes))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
return GNUNET_SYSERR;
}
pid = fork ();
if (pid < 0)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "fork");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
return GNUNET_SYSERR;
}
if (0 != pid)
/* Parent */
char c;
- GNUNET_break (0 == CLOSE (filedes[1]));
+ GNUNET_break (0 == close (filedes[1]));
c = 'X';
- if (1 != READ (filedes[0],
- &c,
- sizeof (char)))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "read");
+ if (1 != read (filedes[0], &c, sizeof (char)))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
fflush (stdout);
switch (c)
{
_ ("Service process failed to report status\n"));
break;
}
- exit (1); /* child reported error */
+ exit (1); /* child reported error */
}
- GNUNET_break (0 == CLOSE (0));
- GNUNET_break (0 == CLOSE (1));
- GNUNET_break (0 == CLOSE (filedes[0]));
- nullfd = OPEN ("/dev/null",
- O_RDWR | O_APPEND);
+ GNUNET_break (0 == close (0));
+ GNUNET_break (0 == close (1));
+ GNUNET_break (0 == close (filedes[0]));
+ nullfd = open ("/dev/null", O_RDWR | O_APPEND);
if (nullfd < 0)
return GNUNET_SYSERR;
/* set stdin/stdout to /dev/null */
- if ( (dup2 (nullfd, 0) < 0) ||
- (dup2 (nullfd, 1) < 0) )
+ if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "dup2");
- (void) CLOSE (nullfd);
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ (void) close (nullfd);
return GNUNET_SYSERR;
}
- (void) CLOSE (nullfd);
+ (void) close (nullfd);
/* Detach from controlling terminal */
pid = setsid ();
if (-1 == pid)
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "setsid");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid");
sh->ready_confirm_fd = filedes[1];
#else
/* FIXME: we probably need to do something else
GNUNET_free_non_null (sh->v6_allowed);
while (NULL != (slc = sh->slc_head))
{
- GNUNET_CONTAINER_DLL_remove (sh->slc_head,
- sh->slc_tail,
- slc);
+ GNUNET_CONTAINER_DLL_remove (sh->slc_head, sh->slc_tail, slc);
if (NULL != slc->listen_task)
GNUNET_SCHEDULER_cancel (slc->listen_task);
GNUNET_break (GNUNET_OK ==
* @param msg AGPL request
*/
static void
-return_agpl (void *cls,
- const struct GNUNET_MessageHeader *msg)
+return_agpl (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_MQ_Handle *mq;
(void) msg;
slen = strlen (GNUNET_AGPL_URL) + 1;
- env = GNUNET_MQ_msg_extra (res,
- GNUNET_MESSAGE_TYPE_RESPONSE_AGPL,
- slen);
- memcpy (&res[1],
- GNUNET_AGPL_URL,
- slen);
+ env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen);
+ memcpy (&res[1], GNUNET_AGPL_URL, slen);
mq = GNUNET_SERVICE_client_get_mq (client);
- GNUNET_MQ_send (mq,
- env);
+ GNUNET_MQ_send (mq, env);
GNUNET_SERVICE_client_continue (client);
}
sh->connect_cb = connect_cb;
sh->disconnect_cb = disconnect_cb;
sh->cb_cls = cls;
- sh->handlers = GNUNET_MQ_copy_handlers2 (handlers,
- &return_agpl,
- NULL);
+ sh->handlers = GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
if (GNUNET_OK != setup_service (sh))
{
GNUNET_free_non_null (sh->handlers);
GNUNET_free (sh);
return NULL;
}
- do_resume (sh,
- SUSPEND_STATE_NONE);
+ do_resume (sh, SUSPEND_STATE_NONE);
return sh;
}
int ret;
int err;
- struct GNUNET_GETOPT_CommandLineOption service_options[] = {
- GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
- GNUNET_GETOPT_option_flag ('d',
- "daemonize",
- gettext_noop (
- "do daemonize (detach from terminal)"),
- &do_daemonize),
- GNUNET_GETOPT_option_help (NULL),
- GNUNET_GETOPT_option_loglevel (&loglev),
- GNUNET_GETOPT_option_logfile (&logfile),
- GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption service_options[] =
+ {GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
+ GNUNET_GETOPT_option_flag ('d',
+ "daemonize",
+ gettext_noop (
+ "do daemonize (detach from terminal)"),
+ &do_daemonize),
+ GNUNET_GETOPT_option_help (NULL),
+ GNUNET_GETOPT_option_loglevel (&loglev),
+ GNUNET_GETOPT_option_logfile (&logfile),
+ GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
+ GNUNET_GETOPT_OPTION_END};
err = 1;
- memset (&sh,
- 0,
- sizeof (sh));
+ memset (&sh, 0, sizeof (sh));
xdg = getenv ("XDG_CONFIG_HOME");
if (NULL != xdg)
GNUNET_asprintf (&cfg_filename,
DIR_SEPARATOR_STR,
GNUNET_OS_project_data_get ()->config_file);
else
- cfg_filename = GNUNET_strdup (
- GNUNET_OS_project_data_get ()->user_config_file);
+ cfg_filename =
+ GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
sh.ready_confirm_fd = -1;
sh.options = options;
sh.cfg = cfg = GNUNET_CONFIGURATION_create ();
logfile = NULL;
opt_cfg_filename = NULL;
do_daemonize = 0;
- ret = GNUNET_GETOPT_run (service_name,
- service_options,
- argc,
- argv);
+ ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv);
if (GNUNET_SYSERR == ret)
goto shutdown;
if (GNUNET_NO == ret)
err = 0;
goto shutdown;
}
- if (GNUNET_OK != GNUNET_log_setup (service_name,
- loglev,
- logfile))
+ if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile))
{
GNUNET_break (0);
goto shutdown;
}
if (NULL != opt_cfg_filename)
{
- if ( (GNUNET_YES !=
- GNUNET_DISK_file_test (opt_cfg_filename)) ||
- (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- opt_cfg_filename)) )
+ if ((GNUNET_YES != GNUNET_DISK_file_test (opt_cfg_filename)) ||
+ (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_filename)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Malformed configuration file `%s', exit ...\n"),
}
else
{
- if (GNUNET_YES ==
- GNUNET_DISK_file_test (cfg_filename))
+ if (GNUNET_YES == GNUNET_DISK_file_test (cfg_filename))
{
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- cfg_filename))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_filename))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Malformed configuration file `%s', exit ...\n"),
}
else
{
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- NULL))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Malformed configuration, exit ...\n"));
}
if (GNUNET_OK != setup_service (&sh))
goto shutdown;
- if ( (1 == do_daemonize) &&
- (GNUNET_OK != detach_terminal (&sh)) )
+ if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sh)))
{
GNUNET_break (0);
goto shutdown;
"Service `%s' runs with configuration from `%s'\n",
service_name,
(NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename);
- if ((GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sh.cfg,
- "TESTING",
- "SKEW_OFFSET",
- &skew_offset)) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sh.cfg,
- "TESTING",
- "SKEW_VARIANCE",
- &skew_variance)))
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sh.cfg,
+ "TESTING",
+ "SKEW_OFFSET",
+ &skew_offset)) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sh.cfg,
+ "TESTING",
+ "SKEW_VARIANCE",
+ &skew_variance)))
{
clock_offset = skew_offset - skew_variance;
GNUNET_TIME_set_offset (clock_offset);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Skewing clock by %dll ms\n",
- clock_offset);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset);
}
GNUNET_RESOLVER_connect (sh.cfg);
/* actually run service */
err = 0;
- GNUNET_SCHEDULER_run (&service_main,
- &sh);
+ GNUNET_SCHEDULER_run (&service_main, &sh);
/* shutdown */
if (1 == do_daemonize)
pid_file_delete (&sh);
- shutdown:
+shutdown:
if (-1 != sh.ready_confirm_fd)
{
- if (1 != WRITE (sh.ready_confirm_fd,
- err ? "I" : "S",
- 1))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "write");
- GNUNET_break (0 == CLOSE (sh.ready_confirm_fd));
+ if (1 != write (sh.ready_confirm_fd, err ? "I" : "S", 1))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
+ GNUNET_break (0 == close (sh.ready_confirm_fd));
}
#if HAVE_MALLINFO
{
char *counter;
- if ( (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (sh.cfg,
- service_name,
- "GAUGER_HEAP")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sh.cfg,
- service_name,
- "GAUGER_HEAP",
- &counter)) )
+ if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sh.cfg,
+ service_name,
+ "GAUGER_HEAP")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sh.cfg,
+ service_name,
+ "GAUGER_HEAP",
+ &counter)))
{
struct mallinfo mi;
mi = mallinfo ();
- GAUGER (service_name,
- counter,
- mi.usmblks,
- "blocks");
+ GAUGER (service_name, counter, mi.usmblks, "blocks");
GNUNET_free (counter);
}
}
void
GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
{
- do_suspend (sh,
- SUSPEND_STATE_APP);
+ do_suspend (sh, SUSPEND_STATE_APP);
}
void
GNUNET_SERVICE_resume (struct GNUNET_SERVICE_Handle *sh)
{
- do_resume (sh,
- SUSPEND_STATE_APP);
+ do_resume (sh, SUSPEND_STATE_APP);
}
c->recv_task = NULL;
/* first, check if there is still something in the buffer */
- ret = GNUNET_MST_next (c->mst,
- GNUNET_YES);
+ ret = GNUNET_MST_next (c->mst, GNUNET_YES);
if (GNUNET_SYSERR == ret)
{
if (NULL == c->drop_task)
/* need to receive more data from the network first */
if (NULL != c->recv_task)
return;
- c->recv_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- c->sock,
- &service_client_recv,
- c);
+ c->recv_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ c->sock,
+ &service_client_recv,
+ c);
}
GNUNET_SCHEDULER_cancel (c->warn_task);
c->warn_task = NULL;
}
- c->recv_task
- = GNUNET_SCHEDULER_add_now (&resume_client_receive,
- c);
+ c->recv_task = GNUNET_SCHEDULER_add_now (&resume_client_receive, c);
}
GNUNET_MQ_destroy (c->mq);
if (GNUNET_NO == c->persist)
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (c->sock));
- if ( (0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) &&
- (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) )
- do_resume (sh,
- SUSPEND_STATE_EMFILE);
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (c->sock));
+ if ((0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) &&
+ (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)))
+ do_resume (sh, SUSPEND_STATE_EMFILE);
}
else
{
GNUNET_NETWORK_socket_free_memory_only_ (c->sock);
}
GNUNET_free (c);
- if ( (0 != (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) &&
- (GNUNET_NO == have_non_monitor_clients (sh)) )
+ if ((0 != (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) &&
+ (GNUNET_NO == have_non_monitor_clients (sh)))
GNUNET_SERVICE_shutdown (sh);
}
void *backtrace_array[MAX_TRACE_DEPTH];
int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
char **backtrace_strings =
- backtrace_symbols (backtrace_array,
- t->num_backtrace_strings);
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
for (unsigned int i = 0; i < num_backtrace_strings; i++)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"client drop trace %u: %s\n",
GNUNET_assert (0);
return;
}
- GNUNET_CONTAINER_DLL_remove (sh->clients_head,
- sh->clients_tail,
- c);
+ GNUNET_CONTAINER_DLL_remove (sh->clients_head, sh->clients_tail, c);
if (NULL != sh->disconnect_cb)
- sh->disconnect_cb (sh->cb_cls,
- c,
- c->user_context);
+ sh->disconnect_cb (sh->cb_cls, c, c->user_context);
if (NULL != c->warn_task)
{
GNUNET_SCHEDULER_cancel (c->warn_task);
GNUNET_SCHEDULER_cancel (c->send_task);
c->send_task = NULL;
}
- c->drop_task = GNUNET_SCHEDULER_add_now (&finish_client_drop,
- c);
+ c->drop_task = GNUNET_SCHEDULER_add_now (&finish_client_drop, c);
}
struct GNUNET_SERVICE_Client *client;
if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
- do_suspend (sh,
- SUSPEND_STATE_SHUTDOWN);
+ do_suspend (sh, SUSPEND_STATE_SHUTDOWN);
while (NULL != (client = sh->clients_head))
GNUNET_SERVICE_client_drop (client);
}
GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c)
{
c->is_monitor = GNUNET_YES;
- if ( ((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state))&&
- (GNUNET_NO == have_non_monitor_clients (c->sh)) ) )
+ if (((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state)) &&
+ (GNUNET_NO == have_non_monitor_clients (c->sh))))
GNUNET_SERVICE_shutdown (c->sh);
}
#include <unistr.h>
#include <uniconv.h>
-#define LOG(kind,...) GNUNET_log_from (kind, "util-strings", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-strings", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-strings", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-strings", syscall)
/**
off = 0;
buf = GNUNET_malloc (plen);
- for (unsigned int i = 0;
- i < num_pids;
- i++)
+ for (unsigned int i = 0; i < num_pids; i++)
{
off += GNUNET_snprintf (&buf[off],
plen - off,
"%s%s",
GNUNET_i2s (&pids[i]),
- (i == num_pids -1) ? "" : "-");
+ (i == num_pids - 1) ? "" : "-");
}
return buf;
}
* in the buffer, or 0 on error.
*/
unsigned int
-GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
- unsigned int count, ...)
+GNUNET_STRINGS_buffer_tokenize (const char *buffer,
+ size_t size,
+ unsigned int count,
+ ...)
{
unsigned int start;
unsigned int needed;
if (needed == size)
{
va_end (ap);
- return 0; /* error */
+ return 0; /* error */
}
*r = &buffer[start];
- needed++; /* skip 0-termination */
+ needed++; /* skip 0-termination */
count--;
}
va_end (ap);
char *
GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
{
- const char *unit = _( /* size unit */ "b");
+ const char *unit = _ (/* size unit */ "b");
char *ret;
if (size > 5 * 1024)
* null byte
*/
size_t
-GNUNET_strlcpy(char *dst, const char *src, size_t n)
+GNUNET_strlcpy (char *dst, const char *src, size_t n)
{
size_t slen;
*/
static int
convert_with_table (const char *input,
- const struct ConversionTable *table,
- unsigned long long *output)
+ const struct ConversionTable *table,
+ unsigned long long *output)
{
unsigned long long ret;
char *in;
if ((0 != errno) || (endptr == tok))
{
GNUNET_free (in);
- return GNUNET_SYSERR; /* expected number */
+ return GNUNET_SYSERR; /* expected number */
}
if ('\0' == endptr[0])
break; /* next tok */
unsigned long long *size)
{
static const struct ConversionTable table[] =
- {
- { "B", 1},
- { "KiB", 1024},
- { "kB", 1000},
- { "MiB", 1024 * 1024},
- { "MB", 1000 * 1000},
- { "GiB", 1024 * 1024 * 1024},
- { "GB", 1000 * 1000 * 1000},
- { "TiB", 1024LL * 1024LL * 1024LL * 1024LL},
- { "TB", 1000LL * 1000LL * 1000LL * 1024LL},
- { "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
- { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL},
- { "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
- { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL},
- { NULL, 0}
- };
-
- return convert_with_table (fancy_size,
- table,
- size);
+ {{"B", 1},
+ {"KiB", 1024},
+ {"kB", 1000},
+ {"MiB", 1024 * 1024},
+ {"MB", 1000 * 1000},
+ {"GiB", 1024 * 1024 * 1024},
+ {"GB", 1000 * 1000 * 1000},
+ {"TiB", 1024LL * 1024LL * 1024LL * 1024LL},
+ {"TB", 1000LL * 1000LL * 1000LL * 1024LL},
+ {"PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
+ {"PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL},
+ {"EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
+ {"EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL},
+ {NULL, 0}};
+
+ return convert_with_table (fancy_size, table, size);
}
struct GNUNET_TIME_Relative *rtime)
{
static const struct ConversionTable table[] =
- {
- { "us", 1},
- { "ms", 1000 },
- { "s", 1000 * 1000LL },
- { "second", 1000 * 1000LL },
- { "seconds", 1000 * 1000LL },
- { "\"", 1000 * 1000LL },
- { "m", 60 * 1000 * 1000LL},
- { "min", 60 * 1000 * 1000LL},
- { "minute", 60 * 1000 * 1000LL},
- { "minutes", 60 * 1000 * 1000LL},
- { "'", 60 * 1000 * 1000LL},
- { "h", 60 * 60 * 1000 * 1000LL},
- { "hour", 60 * 60 * 1000 * 1000LL},
- { "hours", 60 * 60 * 1000 * 1000LL},
- { "d", 24 * 60 * 60 * 1000LL * 1000LL},
- { "day", 24 * 60 * 60 * 1000LL * 1000LL},
- { "days", 24 * 60 * 60 * 1000LL * 1000LL},
- { "week", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
- { "weeks", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
- { "year", 31536000000000LL /* year */ },
- { "years", 31536000000000LL /* year */ },
- { "a", 31536000000000LL /* year */ },
- { NULL, 0}
- };
+ {{"us", 1},
+ {"ms", 1000},
+ {"s", 1000 * 1000LL},
+ {"second", 1000 * 1000LL},
+ {"seconds", 1000 * 1000LL},
+ {"\"", 1000 * 1000LL},
+ {"m", 60 * 1000 * 1000LL},
+ {"min", 60 * 1000 * 1000LL},
+ {"minute", 60 * 1000 * 1000LL},
+ {"minutes", 60 * 1000 * 1000LL},
+ {"'", 60 * 1000 * 1000LL},
+ {"h", 60 * 60 * 1000 * 1000LL},
+ {"hour", 60 * 60 * 1000 * 1000LL},
+ {"hours", 60 * 60 * 1000 * 1000LL},
+ {"d", 24 * 60 * 60 * 1000LL * 1000LL},
+ {"day", 24 * 60 * 60 * 1000LL * 1000LL},
+ {"days", 24 * 60 * 60 * 1000LL * 1000LL},
+ {"week", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
+ {"weeks", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
+ {"year", 31536000000000LL /* year */},
+ {"years", 31536000000000LL /* year */},
+ {"a", 31536000000000LL /* year */},
+ {NULL, 0}};
int ret;
unsigned long long val;
*rtime = GNUNET_TIME_UNIT_FOREVER_REL;
return GNUNET_OK;
}
- ret = convert_with_table (fancy_time,
- table,
- &val);
+ ret = convert_with_table (fancy_time, table, &val);
rtime->rel_value_us = (uint64_t) val;
return ret;
}
time_t t;
const char *eos;
- if (0 == strcasecmp ("end of time",
- fancy_time))
+ if (0 == strcasecmp ("end of time", fancy_time))
{
*atime = GNUNET_TIME_UNIT_FOREVER_ABS;
return GNUNET_OK;
}
eos = &fancy_time[strlen (fancy_time)];
memset (&tv, 0, sizeof (tv));
- if ( (eos != strptime (fancy_time, "%a %b %d %H:%M:%S %Y", &tv)) &&
- (eos != strptime (fancy_time, "%c", &tv)) &&
- (eos != strptime (fancy_time, "%Ec", &tv)) &&
- (eos != strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) &&
- (eos != strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) &&
- (eos != strptime (fancy_time, "%x", &tv)) &&
- (eos != strptime (fancy_time, "%Ex", &tv)) &&
- (eos != strptime (fancy_time, "%Y-%m-%d", &tv)) &&
- (eos != strptime (fancy_time, "%Y-%m", &tv)) &&
- (eos != strptime (fancy_time, "%Y", &tv)) )
+ if ((eos != strptime (fancy_time, "%a %b %d %H:%M:%S %Y", &tv)) &&
+ (eos != strptime (fancy_time, "%c", &tv)) &&
+ (eos != strptime (fancy_time, "%Ec", &tv)) &&
+ (eos != strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) &&
+ (eos != strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) &&
+ (eos != strptime (fancy_time, "%x", &tv)) &&
+ (eos != strptime (fancy_time, "%Ex", &tv)) &&
+ (eos != strptime (fancy_time, "%Y-%m-%d", &tv)) &&
+ (eos != strptime (fancy_time, "%Y-%m", &tv)) &&
+ (eos != strptime (fancy_time, "%Y", &tv)))
return GNUNET_SYSERR;
t = mktime (&tv);
atime->abs_value_us = (uint64_t) ((uint64_t) t * 1000LL * 1000LL);
*/
char *
GNUNET_STRINGS_conv (const char *input,
- size_t len,
- const char *input_charset,
- const char *output_charset)
+ size_t len,
+ const char *input_charset,
+ const char *output_charset)
{
char *ret;
uint8_t *u8_string;
size_t encoded_string_length;
u8_string = u8_conv_from_encoding (input_charset,
- iconveh_error,
- input, len,
- NULL, NULL,
- &u8_string_length);
+ iconveh_error,
+ input,
+ len,
+ NULL,
+ NULL,
+ &u8_string_length);
if (NULL == u8_string)
{
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_from_encoding");
free (u8_string);
return ret;
}
- encoded_string = u8_conv_to_encoding (output_charset, iconveh_error,
- u8_string, u8_string_length,
- NULL, NULL,
- &encoded_string_length);
+ encoded_string = u8_conv_to_encoding (output_charset,
+ iconveh_error,
+ u8_string,
+ u8_string_length,
+ NULL,
+ NULL,
+ &encoded_string_length);
free (u8_string);
if (NULL == encoded_string)
{
ret[encoded_string_length] = '\0';
free (encoded_string);
return ret;
- fail:
+fail:
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Character sets requested were `%s'->`%s'\n"),
- "UTF-8", output_charset);
+ _ ("Character sets requested were `%s'->`%s'\n"),
+ "UTF-8",
+ output_charset);
ret = GNUNET_malloc (len + 1);
GNUNET_memcpy (ret, input, len);
ret[len] = '\0';
* string is returned.
*/
char *
-GNUNET_STRINGS_to_utf8 (const char *input,
- size_t len,
- const char *charset)
+GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
{
return GNUNET_STRINGS_conv (input, len, charset, "UTF-8");
}
* string is returned.
*/
char *
-GNUNET_STRINGS_from_utf8 (const char *input,
- size_t len,
- const char *charset)
+GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
{
return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
}
* @param output output buffer
*/
void
-GNUNET_STRINGS_utf8_tolower (const char *input,
- char *output)
+GNUNET_STRINGS_utf8_tolower (const char *input, char *output)
{
uint8_t *tmp_in;
size_t len;
- tmp_in = u8_tolower ((uint8_t*)input, strlen ((char *) input),
- NULL, UNINORM_NFD, NULL, &len);
- GNUNET_memcpy(output, tmp_in, len);
+ tmp_in = u8_tolower ((uint8_t *) input,
+ strlen ((char *) input),
+ NULL,
+ UNINORM_NFD,
+ NULL,
+ &len);
+ GNUNET_memcpy (output, tmp_in, len);
output[len] = '\0';
- free(tmp_in);
+ free (tmp_in);
}
* @param output output buffer
*/
void
-GNUNET_STRINGS_utf8_toupper(const char *input,
- char *output)
+GNUNET_STRINGS_utf8_toupper (const char *input, char *output)
{
uint8_t *tmp_in;
size_t len;
- tmp_in = u8_toupper ((uint8_t*)input, strlen ((char *) input),
- NULL, UNINORM_NFD, NULL, &len);
+ tmp_in = u8_toupper ((uint8_t *) input,
+ strlen ((char *) input),
+ NULL,
+ UNINORM_NFD,
+ NULL,
+ &len);
GNUNET_memcpy (output, tmp_in, len);
output[len] = '\0';
free (tmp_in);
if (fm == NULL)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to expand `$HOME': environment variable `HOME' not set"));
+ _ ("Failed to expand `$HOME': environment variable `HOME' not set"));
return NULL;
}
fm = GNUNET_strdup (fm);
}
if (fm == NULL)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "getcwd");
- buffer = getenv ("PWD"); /* alternative */
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "getcwd");
+ buffer = getenv ("PWD"); /* alternative */
if (buffer != NULL)
fm = GNUNET_strdup (buffer);
}
if (fm == NULL)
- fm = GNUNET_strdup ("./"); /* give up */
+ fm = GNUNET_strdup ("./"); /* give up */
}
GNUNET_asprintf (&buffer,
"%s%s%s",
fm,
- (fm[strlen (fm) - 1] ==
- DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr);
+ (fm[strlen (fm) - 1] == DIR_SEPARATOR) ? ""
+ : DIR_SEPARATOR_STR,
+ fil_ptr);
GNUNET_free (fm);
return buffer;
#else
if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS)
{
SetErrnoFromWinError (lRet);
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "plibc_conv_to_win_path");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path");
return NULL;
}
/* is the path relative? */
- if ( (0 != strncmp (fn + 1, ":\\", 2)) &&
- (0 != strncmp (fn, "\\\\", 2)) )
+ if ((0 != strncmp (fn + 1, ":\\", 2)) && (0 != strncmp (fn, "\\\\", 2)))
{
char szCurDir[MAX_PATH + 1];
- lRet = GetCurrentDirectory (MAX_PATH + 1,
- szCurDir);
+ lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir);
if (lRet + strlen (fn) + 1 > (MAX_PATH + 1))
{
SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW);
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "GetCurrentDirectory");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory");
return NULL;
}
- GNUNET_asprintf (&buffer,
- "%s\\%s",
- szCurDir,
- fn);
+ GNUNET_asprintf (&buffer, "%s\\%s", szCurDir, fn);
GNUNET_free (fn);
fn = buffer;
}
*/
const char *
GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
- int do_round)
+ int do_round)
{
static char buf[128];
- const char *unit = _( /* time unit */ "µs");
+ const char *unit = _ (/* time unit */ "µs");
uint64_t dval = delta.rel_value_us;
if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == delta.rel_value_us)
- return _("forever");
+ return _ ("forever");
if (0 == delta.rel_value_us)
- return _("0 ms");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 1000) ) ||
- (0 == (dval % 1000) ))
+ return _ ("0 ms");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000)))
{
dval = dval / 1000;
- unit = _( /* time unit */ "ms");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 1000) ) ||
- (0 == (dval % 1000) ))
+ unit = _ (/* time unit */ "ms");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000)))
{
dval = dval / 1000;
- unit = _( /* time unit */ "s");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 60) ) ||
- (0 == (dval % 60) ) )
+ unit = _ (/* time unit */ "s");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
{
- dval = dval / 60;
- unit = _( /* time unit */ "m");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 60) ) ||
- (0 == (dval % 60) ))
- {
- dval = dval / 60;
- unit = _( /* time unit */ "h");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 24) ) ||
- (0 == (dval % 24)) )
- {
- dval = dval / 24;
- if (1 == dval)
- unit = _( /* time unit */ "day");
- else
- unit = _( /* time unit */ "days");
- }
- }
+ dval = dval / 60;
+ unit = _ (/* time unit */ "m");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
+ {
+ dval = dval / 60;
+ unit = _ (/* time unit */ "h");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 24)) ||
+ (0 == (dval % 24)))
+ {
+ dval = dval / 24;
+ if (1 == dval)
+ unit = _ (/* time unit */ "day");
+ else
+ unit = _ (/* time unit */ "days");
+ }
+ }
}
}
}
- GNUNET_snprintf (buf, sizeof (buf),
- "%llu %s", dval, unit);
+ GNUNET_snprintf (buf, sizeof (buf), "%llu %s", dval, unit);
return buf;
}
struct tm *tp;
if (t.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
- return _("end of time");
+ return _ ("end of time");
tt = t.abs_value_us / 1000LL / 1000LL;
tp = localtime (&tt);
/* This is hacky, but i don't know a way to detect libc character encoding.
uint8_t *conved;
size_t ssize;
- wcsftime (wbuf, sizeof (wbuf) / sizeof (wchar_t),
- L"%a %b %d %H:%M:%S %Y", tp);
+ wcsftime (wbuf,
+ sizeof (wbuf) / sizeof (wchar_t),
+ L"%a %b %d %H:%M:%S %Y",
+ tp);
ssize = sizeof (buf);
- conved = u16_to_u8 (wbuf, sizeof (wbuf) / sizeof (wchar_t),
- (uint8_t *) buf, &ssize);
+ conved = u16_to_u8 (wbuf,
+ sizeof (wbuf) / sizeof (wchar_t),
+ (uint8_t *) buf,
+ &ssize);
if (conved != (uint8_t *) buf)
{
GNUNET_strlcpy (buf, (char *) conved, sizeof (buf));
const char *short_fn = filename;
const char *ss;
- while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR))
- && (ss[1] != '\0'))
+ while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)) && (ss[1] != '\0'))
short_fn = 1 + ss;
return short_fn;
}
return a - '0';
if ((a >= 'a') && (a <= 'z'))
a = toupper (a);
- /* return (a - 'a' + 10); */
+ /* return (a - 'a' + 10); */
dec = 0;
if ((a >= 'A') && (a <= 'Z'))
{
{
if ((rpos < size) && (vbit < 5))
{
- bits = (bits << 8) | udata[rpos++]; /* eat 8 more bits */
+ bits = (bits << 8) | udata[rpos++]; /* eat 8 more bits */
vbit += 8;
}
if (vbit < 5)
{
- bits <<= (5 - vbit); /* zero-padding */
+ bits <<= (5 - vbit); /* zero-padding */
GNUNET_assert (vbit == ((size * 8) % 5));
vbit = 5;
}
* @return freshly allocated, null-terminated string
*/
char *
-GNUNET_STRINGS_data_to_string_alloc (const void *buf,
- size_t size)
+GNUNET_STRINGS_data_to_string_alloc (const void *buf, size_t size)
{
char *str_buf;
size_t len = size * 8;
* @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
*/
int
-GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen,
- void *out, size_t out_size)
+GNUNET_STRINGS_string_to_data (const char *enc,
+ size_t enclen,
+ void *out,
+ size_t out_size)
{
unsigned int rpos;
unsigned int wpos;
vbit -= 8;
}
}
- if ( (0 != rpos) ||
- (0 != vbit) )
+ if ((0 != rpos) || (0 != vbit))
return GNUNET_SYSERR;
return GNUNET_OK;
}
*/
int
GNUNET_STRINGS_parse_uri (const char *path,
- char **scheme_part,
- const char **path_part)
+ char **scheme_part,
+ const char **path_part)
{
size_t len;
size_t i;
int pp_state = 0;
const char *post_scheme_part = NULL;
len = strlen (path);
- for (end = 0, i = 0; !end && i < len; i++)
+ for (end = 0, i = 0; ! end && i < len; i++)
{
switch (pp_state)
{
case 0:
- if ( (path[i] == ':') && (i > 0) )
+ if ((path[i] == ':') && (i > 0))
{
pp_state += 1;
continue;
}
- if (!((path[i] >= 'A' && path[i] <= 'Z') || (path[i] >= 'a' && path[i] <= 'z')
- || (path[i] >= '0' && path[i] <= '9') || path[i] == '+' || path[i] == '-'
- || (path[i] == '.')))
+ if (! ((path[i] >= 'A' && path[i] <= 'Z') ||
+ (path[i] >= 'a' && path[i] <= 'z') ||
+ (path[i] >= '0' && path[i] <= '9') || path[i] == '+' ||
+ path[i] == '-' || (path[i] == '.')))
end = 1;
break;
case 1:
#endif
const char *post_scheme_path;
int is_uri;
- char * uri;
+ char *uri;
/* consider POSIX paths to be absolute too, even on W32,
* as plibc expansion will fix them for us.
*/
else
GNUNET_free_non_null (uri);
#if WINDOWS
- len = strlen(post_scheme_path);
+ len = strlen (post_scheme_path);
/* Special check for file:///c:/blah
* We want to parse 'c:/', not '/c:/'
*/
if (post_scheme_path[0] == '/' && len >= 3 && post_scheme_path[2] == ':')
post_scheme_path = &post_scheme_path[1];
#endif
- return GNUNET_STRINGS_path_is_absolute (post_scheme_path, GNUNET_NO, NULL, NULL);
+ return GNUNET_STRINGS_path_is_absolute (post_scheme_path,
+ GNUNET_NO,
+ NULL,
+ NULL);
}
}
else
#if WINDOWS
len = strlen (filename);
if (len >= 3 &&
- ((filename[0] >= 'A' && filename[0] <= 'Z')
- || (filename[0] >= 'a' && filename[0] <= 'z'))
- && filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\'))
+ ((filename[0] >= 'A' && filename[0] <= 'Z') ||
+ (filename[0] >= 'a' && filename[0] <= 'z')) &&
+ filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\'))
return GNUNET_YES;
#endif
return GNUNET_NO;
}
#if MINGW
-#define _IFMT 0170000 /* type of file */
-#define _IFLNK 0120000 /* symbolic link */
-#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK)
+#define _IFMT 0170000 /* type of file */
+#define _IFLNK 0120000 /* symbolic link */
+#define S_ISLNK(m) (((m) &_IFMT) == _IFLNK)
#endif
*/
int
GNUNET_STRINGS_check_filename (const char *filename,
- enum GNUNET_STRINGS_FilenameCheck checks)
+ enum GNUNET_STRINGS_FilenameCheck checks)
{
struct stat st;
- if ( (NULL == filename) || (filename[0] == '\0') )
+ if ((NULL == filename) || (filename[0] == '\0'))
return GNUNET_SYSERR;
if (0 != (checks & GNUNET_STRINGS_CHECK_IS_ABSOLUTE))
- if (!GNUNET_STRINGS_path_is_absolute (filename, GNUNET_NO, NULL, NULL))
+ if (! GNUNET_STRINGS_path_is_absolute (filename, GNUNET_NO, NULL, NULL))
return GNUNET_NO;
- if (0 != (checks & (GNUNET_STRINGS_CHECK_EXISTS
- | GNUNET_STRINGS_CHECK_IS_DIRECTORY
- | GNUNET_STRINGS_CHECK_IS_LINK)))
+ if (0 != (checks &
+ (GNUNET_STRINGS_CHECK_EXISTS | GNUNET_STRINGS_CHECK_IS_DIRECTORY |
+ GNUNET_STRINGS_CHECK_IS_LINK)))
{
- if (0 != STAT (filename, &st))
+ if (0 != stat (filename, &st))
{
if (0 != (checks & GNUNET_STRINGS_CHECK_EXISTS))
return GNUNET_NO;
}
}
if (0 != (checks & GNUNET_STRINGS_CHECK_IS_DIRECTORY))
- if (!S_ISDIR (st.st_mode))
+ if (! S_ISDIR (st.st_mode))
return GNUNET_NO;
if (0 != (checks & GNUNET_STRINGS_CHECK_IS_LINK))
- if (!S_ISLNK (st.st_mode))
+ if (! S_ISLNK (st.st_mode))
return GNUNET_NO;
return GNUNET_YES;
}
*/
int
GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
- uint16_t addrlen,
- struct sockaddr_in6 *r_buf)
+ uint16_t addrlen,
+ struct sockaddr_in6 *r_buf)
{
char zbuf[addrlen + 1];
int ret;
if ('[' != zbuf[0])
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv6 address did not start with `['\n"));
+ _ ("IPv6 address did not start with `['\n"));
return GNUNET_SYSERR;
}
zbuf[addrlen] = '\0';
if (NULL == port_colon)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv6 address did contain ':' to separate port number\n"));
+ _ ("IPv6 address did contain ':' to separate port number\n"));
return GNUNET_SYSERR;
}
if (']' != *(port_colon - 1))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv6 address did contain ']' before ':' to separate port number\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ ("IPv6 address did contain ']' before ':' to separate port number\n"));
return GNUNET_SYSERR;
}
- ret = SSCANF (port_colon,
- ":%u%1s",
- &port,
- dummy);
- if ( (1 != ret) || (port > 65535) )
+ ret = sscanf (port_colon, ":%u%1s", &port, dummy);
+ if ((1 != ret) || (port > 65535))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv6 address did contain a valid port number after the last ':'\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ ("IPv6 address did contain a valid port number after the last ':'\n"));
return GNUNET_SYSERR;
}
- *(port_colon-1) = '\0';
+ *(port_colon - 1) = '\0';
memset (r_buf, 0, sizeof (struct sockaddr_in6));
ret = inet_pton (AF_INET6, &zbuf[1], &r_buf->sin6_addr);
if (ret <= 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid IPv6 address `%s': %s\n"),
- &zbuf[1],
- STRERROR (errno));
+ _ ("Invalid IPv6 address `%s': %s\n"),
+ &zbuf[1],
+ strerror (errno));
return GNUNET_SYSERR;
}
r_buf->sin6_port = htons (port);
*/
int
GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
- uint16_t addrlen,
- struct sockaddr_in *r_buf)
+ uint16_t addrlen,
+ struct sockaddr_in *r_buf)
{
unsigned int temps[4];
unsigned int port;
if (addrlen < 9)
return GNUNET_SYSERR;
- cnt = SSCANF (zt_addr,
- "%u.%u.%u.%u:%u%1s",
- &temps[0],
- &temps[1],
- &temps[2],
- &temps[3],
- &port,
- dummy);
+ cnt = sscanf (zt_addr,
+ "%u.%u.%u.%u:%u%1s",
+ &temps[0],
+ &temps[1],
+ &temps[2],
+ &temps[3],
+ &port,
+ dummy);
if (5 != cnt)
return GNUNET_SYSERR;
for (cnt = 0; cnt < 4; cnt++)
return GNUNET_SYSERR;
r_buf->sin_family = AF_INET;
r_buf->sin_port = htons (port);
- r_buf->sin_addr.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
- (temps[2] << 8) + temps[3]);
+ r_buf->sin_addr.s_addr =
+ htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + temps[3]);
#if HAVE_SOCKADDR_IN_SIN_LEN
r_buf->sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
*/
int
GNUNET_STRINGS_to_address_ip (const char *addr,
- uint16_t addrlen,
- struct sockaddr_storage *r_buf)
+ uint16_t addrlen,
+ struct sockaddr_storage *r_buf)
{
if (addr[0] == '[')
return GNUNET_STRINGS_to_address_ipv6 (addr,
*/
size_t
GNUNET_STRINGS_parse_socket_addr (const char *addr,
- uint8_t *af,
- struct sockaddr **sa)
+ uint8_t *af,
+ struct sockaddr **sa)
{
char *cp = GNUNET_strdup (addr);
/* IPv6 */
*sa = GNUNET_malloc (sizeof (struct sockaddr_in6));
if (GNUNET_OK !=
- GNUNET_STRINGS_to_address_ipv6 (cp,
- strlen (cp),
- (struct sockaddr_in6 *) *sa))
+ GNUNET_STRINGS_to_address_ipv6 (cp,
+ strlen (cp),
+ (struct sockaddr_in6 *) *sa))
{
GNUNET_free (*sa);
*sa = NULL;
/* IPv4 */
*sa = GNUNET_malloc (sizeof (struct sockaddr_in));
if (GNUNET_OK !=
- GNUNET_STRINGS_to_address_ipv4 (cp,
- strlen (cp),
- (struct sockaddr_in *) *sa))
+ GNUNET_STRINGS_to_address_ipv4 (cp,
+ strlen (cp),
+ (struct sockaddr_in *) *sa))
{
GNUNET_free (*sa);
*sa = NULL;
* freed with a single call to GNUNET_free();
*/
static char *const *
-_make_continuous_arg_copy (int argc,
- char *const *argv)
+_make_continuous_arg_copy (int argc, char *const *argv)
{
size_t argvsize = 0;
int i;
*/
int
GNUNET_STRINGS_get_utf8_args (int argc,
- char *const *argv,
- int *u8argc,
- char *const **u8argv)
+ char *const *argv,
+ int *u8argc,
+ char *const **u8argv)
{
#if WINDOWS
wchar_t *wcmd;
{
size_t strl;
/* Hopefully it will allocate us NUL-terminated strings... */
- split_u8argv[i] = (char *) u16_to_u8 (wargv[i], wcslen (wargv[i]) + 1, NULL, &strl);
+ split_u8argv[i] =
+ (char *) u16_to_u8 (wargv[i], wcslen (wargv[i]) + 1, NULL, &strl);
if (NULL == split_u8argv[i])
{
int j;
free (split_u8argv);
return GNUNET_OK;
#else
- char *const *new_argv = (char *const *) _make_continuous_arg_copy (argc, argv);
+ char *const *new_argv =
+ (char *const *) _make_continuous_arg_copy (argc, argv);
*u8argv = new_argv;
*u8argc = argc;
return GNUNET_OK;
pp->negate_portrange = GNUNET_YES;
pos++;
}
- if (2 == sscanf (pos,
- "%u-%u%1s",
- &s,
- &e,
- eol))
+ if (2 == sscanf (pos, "%u-%u%1s", &s, &e, eol))
{
- if ( (0 == s) ||
- (s > 0xFFFF) ||
- (e < s) ||
- (e > 0xFFFF) )
+ if ((0 == s) || (s > 0xFFFF) || (e < s) || (e > 0xFFFF))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Port not in range\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Port not in range\n"));
return GNUNET_SYSERR;
}
pp->start_port = (uint16_t) s;
pp->end_port = (uint16_t) e;
return GNUNET_OK;
}
- if (1 == sscanf (pos,
- "%u%1s",
- &s,
- eol))
+ if (1 == sscanf (pos, "%u%1s", &s, eol))
{
- if ( (0 == s) ||
- (s > 0xFFFF) )
+ if ((0 == s) || (s > 0xFFFF))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Port not in range\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Port not in range\n"));
return GNUNET_SYSERR;
}
return GNUNET_OK;
}
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Malformed port policy `%s'\n"),
+ _ ("Malformed port policy `%s'\n"),
port_policy);
return GNUNET_SYSERR;
}
int end;
char *routeList;
char dummy[2];
-
+
if (NULL == routeListX)
return NULL;
len = strlen (routeListX);
for (i = 0; i < len; i++)
if (routeList[i] == ';')
count++;
- result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv4NetworkPolicy) * (count + 1));
+ result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv4NetworkPolicy) *
+ (count + 1));
i = 0;
pos = 0;
while (i < count)
{
for (colon = pos; ':' != routeList[colon]; colon++)
- if ( (';' == routeList[colon]) ||
- ('\0' == routeList[colon]) )
+ if ((';' == routeList[colon]) || ('\0' == routeList[colon]))
break;
for (end = colon; ';' != routeList[end]; end++)
if ('\0' == routeList[end])
if (':' == routeList[colon])
{
routeList[colon] = '\0';
- if (GNUNET_OK != parse_port_policy (&routeList[colon + 1],
- &result[i].pp))
+ if (GNUNET_OK != parse_port_policy (&routeList[colon + 1], &result[i].pp))
break;
}
- cnt =
- SSCANF (&routeList[pos],
- "%u.%u.%u.%u/%u.%u.%u.%u%1s",
- &temps[0],
- &temps[1],
- &temps[2],
- &temps[3],
- &temps[4],
- &temps[5],
- &temps[6],
- &temps[7],
- dummy);
+ cnt = sscanf (&routeList[pos],
+ "%u.%u.%u.%u/%u.%u.%u.%u%1s",
+ &temps[0],
+ &temps[1],
+ &temps[2],
+ &temps[3],
+ &temps[4],
+ &temps[5],
+ &temps[6],
+ &temps[7],
+ dummy);
if (8 == cnt)
{
for (j = 0; j < 8; j++)
if (temps[j] > 0xFF)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format for IP: `%s'\n"),
+ _ ("Invalid format for IP: `%s'\n"),
&routeList[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
return NULL;
}
- result[i].network.s_addr =
- htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
- temps[3]);
- result[i].netmask.s_addr =
- htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) +
- temps[7]);
+ result[i].network.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
+ (temps[2] << 8) + temps[3]);
+ result[i].netmask.s_addr = htonl ((temps[4] << 24) + (temps[5] << 16) +
+ (temps[6] << 8) + temps[7]);
pos = end + 1;
i++;
continue;
}
/* try second notation */
- cnt =
- SSCANF (&routeList[pos],
- "%u.%u.%u.%u/%u%1s",
- &temps[0],
- &temps[1],
- &temps[2],
- &temps[3],
- &slash,
- dummy);
+ cnt = sscanf (&routeList[pos],
+ "%u.%u.%u.%u/%u%1s",
+ &temps[0],
+ &temps[1],
+ &temps[2],
+ &temps[3],
+ &slash,
+ dummy);
if (5 == cnt)
{
for (j = 0; j < 4; j++)
if (temps[j] > 0xFF)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format for IP: `%s'\n"),
+ _ ("Invalid format for IP: `%s'\n"),
&routeList[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
return NULL;
}
- result[i].network.s_addr =
- htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
- temps[3]);
+ result[i].network.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
+ (temps[2] << 8) + temps[3]);
if ((slash <= 32) && (slash >= 0))
{
result[i].netmask.s_addr = 0;
while (slash > 0)
{
result[i].netmask.s_addr =
- (result[i].netmask.s_addr >> 1) + 0x80000000;
+ (result[i].netmask.s_addr >> 1) + 0x80000000;
slash--;
}
result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
else
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
+ _ ("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
slash);
GNUNET_free (result);
- GNUNET_free (routeList);
- return NULL; /* error */
+ GNUNET_free (routeList);
+ return NULL; /* error */
}
}
/* try third notation */
slash = 32;
- cnt =
- SSCANF (&routeList[pos],
- "%u.%u.%u.%u%1s",
- &temps[0],
- &temps[1],
- &temps[2],
- &temps[3],
- dummy);
+ cnt = sscanf (&routeList[pos],
+ "%u.%u.%u.%u%1s",
+ &temps[0],
+ &temps[1],
+ &temps[2],
+ &temps[3],
+ dummy);
if (4 == cnt)
{
for (j = 0; j < 4; j++)
if (temps[j] > 0xFF)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format for IP: `%s'\n"),
+ _ ("Invalid format for IP: `%s'\n"),
&routeList[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
return NULL;
}
- result[i].network.s_addr =
- htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
- temps[3]);
+ result[i].network.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
+ (temps[2] << 8) + temps[3]);
result[i].netmask.s_addr = 0;
while (slash > 0)
{
continue;
}
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format for IP: `%s'\n"),
+ _ ("Invalid format for IP: `%s'\n"),
&routeList[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
- return NULL; /* error */
+ return NULL; /* error */
}
if (pos < strlen (routeList))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format: `%s'\n"),
+ _ ("Invalid format: `%s'\n"),
&routeListX[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
- return NULL; /* oops */
+ return NULL; /* oops */
}
GNUNET_free (routeList);
- return result; /* ok */
+ return result; /* ok */
}
int save;
int colon;
char dummy[2];
-
+
if (NULL == routeListX)
return NULL;
len = strlen (routeListX);
if (';' != routeList[len - 1])
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid network notation (does not end with ';': `%s')\n"),
+ _ ("Invalid network notation (does not end with ';': `%s')\n"),
routeList);
GNUNET_free (routeList);
return NULL;
}
- result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv6NetworkPolicy) * (count + 1));
+ result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv6NetworkPolicy) *
+ (count + 1));
i = 0;
pos = 0;
while (i < count)
if (slash < start)
{
- memset (&result[i].netmask,
- 0xFF,
- sizeof (struct in6_addr));
+ memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr));
slash = pos;
}
else
if (':' == routeList[colon])
{
routeList[colon] = '\0';
- if (GNUNET_OK != parse_port_policy (&routeList[colon + 1],
- &result[i].pp))
+ if (GNUNET_OK !=
+ parse_port_policy (&routeList[colon + 1], &result[i].pp))
{
GNUNET_free (result);
GNUNET_free (routeList);
if (ret <= 0)
{
save = errno;
- if ( (1 != SSCANF (&routeList[slash + 1],
- "%u%1s",
- &bits,
- dummy)) ||
- (bits > 128) )
+ if ((1 != sscanf (&routeList[slash + 1], "%u%1s", &bits, dummy)) ||
+ (bits > 128))
{
if (0 == ret)
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Wrong format `%s' for netmask\n"),
+ _ ("Wrong format `%s' for netmask\n"),
&routeList[slash + 1]);
else
{
while (bits > 0)
{
result[i].netmask.s6_addr[off] =
- (result[i].netmask.s6_addr[off] >> 1) + 0x80;
+ (result[i].netmask.s6_addr[off] >> 1) + 0x80;
bits--;
}
}
{
if (0 == ret)
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Wrong format `%s' for network\n"),
+ _ ("Wrong format `%s' for network\n"),
&routeList[slash + 1]);
else
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "inet_pton");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
GNUNET_free (result);
GNUNET_free (routeList);
return NULL;
}
-
/** ******************** Base64 encoding ***********/
#define FILLCHAR '='
-static char *cvt =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/";
+static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+/";
/**
* @return the size of the output
*/
size_t
-GNUNET_STRINGS_base64_encode (const void *in,
- size_t len,
- char **output)
+GNUNET_STRINGS_base64_encode (const void *in, size_t len, char **output)
{
const char *data = in;
size_t ret;
return ret;
}
-#define cvtfind(a)( (((a) >= 'A')&&((a) <= 'Z'))? (a)-'A'\
- :(((a)>='a')&&((a)<='z')) ? (a)-'a'+26\
- :(((a)>='0')&&((a)<='9')) ? (a)-'0'+52\
- :((a) == '+') ? 62\
- :((a) == '/') ? 63 : -1)
+#define cvtfind(a) \
+ ((((a) >= 'A') && ((a) <= 'Z')) \
+ ? (a) - 'A' \
+ : (((a) >= 'a') && ((a) <= 'z')) \
+ ? (a) - 'a' + 26 \
+ : (((a) >= '0') && ((a) <= '9')) \
+ ? (a) - '0' + 52 \
+ : ((a) == '+') ? 62 : ((a) == '/') ? 63 : -1)
/**
* @return the size of the output
*/
size_t
-GNUNET_STRINGS_base64_decode (const char *data,
- size_t len,
- void **out)
+GNUNET_STRINGS_base64_decode (const char *data, size_t len, void **out)
{
char *output;
size_t ret = 0;
-#define CHECK_CRLF while (data[i] == '\r' || data[i] == '\n') {\
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "ignoring CR/LF\n"); \
- i++; \
- if (i >= len) goto END; \
- }
+#define CHECK_CRLF \
+ while (data[i] == '\r' || data[i] == '\n') \
+ { \
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, \
+ "ignoring CR/LF\n"); \
+ i++; \
+ if (i >= len) \
+ goto END; \
+ }
output = GNUNET_malloc ((len * 3 / 4) + 8);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
NULL);
ret = check ();
if (ret != 0)
- FPRINTF (stderr,
+ fprintf (stderr,
"ERROR %d.\n",
ret);
return ret;
unsigned int logs = 0;
if (0 != putenv ("GNUNET_FORCE_LOG="))
- FPRINTF (stderr, "Failed to putenv: %s\n", strerror (errno));
+ fprintf (stderr, "Failed to putenv: %s\n", strerror (errno));
GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null");
GNUNET_logger_add (&my_log, &logs);
GNUNET_logger_add (&my_log, &logs);
GNUNET_logger_remove (&my_log, &logs);
if (logs != 4)
{
- FPRINTF (stdout, "Expected 4 log calls, got %u\n", logs);
+ fprintf (stdout, "Expected 4 log calls, got %u\n", logs);
failureCount++;
}
GNUNET_break (0 ==
GNUNET_logger_remove (&my_log, &logs);
if (logs != 1)
{
- FPRINTF (stdout, "Expected 1 log call, got %u\n", logs);
+ fprintf (stdout, "Expected 1 log call, got %u\n", logs);
failureCount++;
}
if (failureCount != 0)
{
- FPRINTF (stdout, "%u TESTS FAILED!\n", failureCount);
+ fprintf (stdout, "%u TESTS FAILED!\n", failureCount);
return -1;
}
return 0;
(void) date;
if (strncmp ("test-common-logging-dummy", component, 25) != 0)
return;
- FPRINTF (stdout, "%s", msg);
+ fprintf (stdout, "%s", msg);
fflush (stdout);
}
buf_ptr += rd;
bytes += rd;
#if VERBOSE
- FPRINTF (stderr, "got %d bytes, reading more\n", rd);
+ fprintf (stderr, "got %d bytes, reading more\n", rd);
#endif
read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
stdout_read_handle,
}
#if VERBOSE
- FPRINTF (stderr, "bytes is %d:%s\n", bytes, buf);
+ fprintf (stderr, "bytes is %d:%s\n", bytes, buf);
#endif
/* +------CHILD OUTPUT--
&bytes, &delays[7], level)))
{
if (bytes == LOG_BUFFER_SIZE)
- FPRINTF (stderr, "%s", "Ran out of buffer space!\n");
+ fprintf (stderr, "%s", "Ran out of buffer space!\n");
GNUNET_break (0);
ok = 2;
GNUNET_SCHEDULER_cancel (die_task);
GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData);
if (1 == (ret = cbData.status))
{
- FPRINTF (stderr, "%s",
+ fprintf (stderr, "%s",
"Incorrect Configuration Diffs: Diffs may contain data not actually edited\n");
goto housekeeping;
}
cbData.cfgDiffs = cfg;
GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData);
if ((ret = cbData.status) == 1)
- FPRINTF (stderr, "%s",
+ fprintf (stderr, "%s",
"Incorrect Configuration Diffs: Data may be missing in diffs\n");
housekeeping:
return 1;
if (0 != strcmp ("b", c))
{
- FPRINTF (stderr, "Got `%s'\n", c);
+ fprintf (stderr, "Got `%s'\n", c);
GNUNET_free (c);
return 2;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
{
- FPRINTF (stderr, "%s", "Failed to parse configuration file\n");
+ fprintf (stderr, "%s", "Failed to parse configuration file\n");
GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
{
- FPRINTF (stderr, "%s", "Failed to write configuration file\n");
+ fprintf (stderr, "%s", "Failed to write configuration file\n");
GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf"));
+ GNUNET_assert (0 == unlink ("/tmp/gnunet-test.conf"));
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK !=
error:
if (failureCount != 0)
{
- FPRINTF (stderr, "Test failed: %u\n", failureCount);
+ fprintf (stderr, "Test failed: %u\n", failureCount);
return 1;
}
return 0;
* Generate a random hashcode.
*/
static void
-nextHC (struct GNUNET_HashCode * hc)
+nextHC (struct GNUNET_HashCode *hc)
{
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, hc);
}
static int
-add_iterator (void *cls, struct GNUNET_HashCode * next)
+add_iterator (void *cls, struct GNUNET_HashCode *next)
{
int *ret = cls;
struct GNUNET_HashCode pos;
GNUNET_log_setup ("test-container-bloomfilter", "WARNING", NULL);
GNUNET_CRYPTO_seed_weak_random (1);
- if (0 == STAT (TESTFILE, &sbuf))
- if (0 != UNLINK (TESTFILE))
+ if (0 == stat (TESTFILE, &sbuf))
+ if (0 != unlink (TESTFILE))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", TESTFILE);
bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K);
}
if (ok1 != 200)
{
- printf ("Got %d elements out of" "200 expected after insertion.\n", ok1);
+ printf ("Got %d elements out of"
+ "200 expected after insertion.\n",
+ ok1);
GNUNET_CONTAINER_bloomfilter_free (bf);
return -1;
}
}
if (ok1 != 200)
{
- printf ("Got %d elements out of 200 " "expected after reloading.\n", ok1);
+ printf ("Got %d elements out of 200 "
+ "expected after reloading.\n",
+ ok1);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
return -1;
if (ok2 != 200)
{
- printf ("Got %d elements out of 200 " "expected after initialization.\n",
+ printf ("Got %d elements out of 200 "
+ "expected after initialization.\n",
ok2);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
if (ok1 != 100)
{
printf ("Expected 100 elements in loaded filter"
- " after adding 200 and deleting 100, got %d\n", ok1);
+ " after adding 200 and deleting 100, got %d\n",
+ ok1);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
return -1;
if (ok1 != 20)
{
printf ("Expected 20 elements in resized file-backed filter"
- " after adding 20, got %d\n", ok1);
+ " after adding 20, got %d\n",
+ ok1);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
return -1;
if (ok2 != 20)
{
printf ("Expected 20 elements in resized filter"
- " after adding 20, got %d\n", ok2);
+ " after adding 20, got %d\n",
+ ok2);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
return -1;
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
- GNUNET_break (0 == UNLINK (TESTFILE));
+ GNUNET_break (0 == unlink (TESTFILE));
return 0;
}
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_
("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
{
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
return 0;
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_
("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
struct GNUNET_TIME_Absolute start;
int ok = GNUNET_OK;
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
start = GNUNET_TIME_absolute_get ();
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
for (i = 0; i < ITER; i++)
{
- FPRINTF (stderr, "%s", "."); fflush (stderr);
+ fprintf (stderr, "%s", "."); fflush (stderr);
if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig))
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (dpriv, &purp, &sig))
{
- FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
+ fprintf (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
GNUNET_free (dpriv);
return GNUNET_SYSERR;
}
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < ITER; i++)
{
- FPRINTF (stderr, "%s", "."); fflush (stderr);
+ fprintf (stderr, "%s", "."); fflush (stderr);
if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig))
{
- FPRINTF (stderr, "%s",
+ fprintf (stderr, "%s",
"GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
continue;
struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
int i;
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
start = GNUNET_TIME_absolute_get ();
for (i=0;i<10;i++)
{
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_
("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
struct GNUNET_TIME_Absolute start;
int ok = GNUNET_OK;
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey);
start = GNUNET_TIME_absolute_get ();
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
for (i = 0; i < ITER; i++)
{
- FPRINTF (stderr, "%s", "."); fflush (stderr);
+ fprintf (stderr, "%s", "."); fflush (stderr);
if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig))
{
- FPRINTF (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
+ fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
continue;
}
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey);
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < ITER; i++)
{
- FPRINTF (stderr, "%s", "."); fflush (stderr);
+ fprintf (stderr, "%s", "."); fflush (stderr);
if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig))
{
- FPRINTF (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
+ fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
continue;
}
GNUNET_CRYPTO_eddsa_key_get_public (key, &p2);
GNUNET_assert (0 == memcmp (&p1, &p2, sizeof (p1)));
GNUNET_free (key);
- GNUNET_assert (0 == UNLINK (KEYFILE));
+ GNUNET_assert (0 == unlink (KEYFILE));
key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE);
GNUNET_assert (NULL != key);
GNUNET_CRYPTO_eddsa_key_get_public (key, &p2);
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
int i;
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
start = GNUNET_TIME_absolute_get ();
for (i=0;i<10;i++)
{
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
return 0;
GNUNET_free (key);
if (GNUNET_OK != testCreateFromFile ())
failure_count++;
- GNUNET_assert (0 == UNLINK (KEYFILE));
+ GNUNET_assert (0 == unlink (KEYFILE));
perf_keygen ();
if (0 != failure_count)
memset (block, 42, sizeof (block) / 2);
memset (&block[sizeof (block) / 2], 43, sizeof (block) / 2);
- GNUNET_assert (NULL != (f = FOPEN (FILENAME, "w+")));
+ GNUNET_assert (NULL != (f = fopen (FILENAME, "w+")));
GNUNET_break (sizeof (block) == fwrite (block, 1, sizeof (block), f));
- GNUNET_break (0 == FCLOSE (f));
+ GNUNET_break (0 == fclose (f));
ret = 1;
GNUNET_SCHEDULER_run (&file_hasher, &ret);
- GNUNET_break (0 == UNLINK (FILENAME));
+ GNUNET_break (0 == unlink (FILENAME));
return ret;
}
b2 = GNUNET_CRYPTO_random_permute (mode, 1024);
if (0 == memcmp (b2, buf, sizeof (buf)))
{
- FPRINTF (stderr, "%s", "!");
+ fprintf (stderr, "%s", "!");
GNUNET_free (b2);
continue;
}
ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1);
if (ret < 0)
{
- FPRINTF (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile");
+ fprintf (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile");
return 1;
}
tmp[ret] = '\0';
if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
{
- FPRINTF (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
+ fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
TESTSTRING, ".testfile");
return 1;
}
ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1);
if (ret < 0)
{
- FPRINTF (stderr, "Error reading file `%s' in testReadWrite\n",
+ fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
".testfile2");
return 1;
}
tmp[ret] = '\0';
if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
{
- FPRINTF (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
+ fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
TESTSTRING, ".testfile2");
return 1;
}
- GNUNET_break (0 == UNLINK (".testfile"));
- GNUNET_break (0 == UNLINK (".testfile2"));
+ GNUNET_break (0 == unlink (".testfile"));
+ GNUNET_break (0 == unlink (".testfile2"));
if (GNUNET_NO != GNUNET_DISK_file_test (".testfile"))
return 1;
GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO, GNUNET_YES));
if (size != 5)
return 1;
- GNUNET_break (0 == UNLINK (".testfile"));
+ GNUNET_break (0 == unlink (".testfile"));
return 0;
}
failureCount += testDirMani ();
if (0 != failureCount)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"\n%u TESTS FAILED!\n",
failureCount);
return -1;
static int
testMinimal ()
{
- char *const emptyargv[] = {
- "test",
- NULL
- };
+ char *const emptyargv[] = {"test", NULL};
const struct GNUNET_GETOPT_CommandLineOption emptyoptionlist[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv))
return 1;
static int
testVerbose ()
{
- char *const myargv[] = {
- "test",
- "-V",
- "-V",
- "more",
- NULL
- };
+ char *const myargv[] = {"test", "-V", "-V", "more", NULL};
unsigned int vflags = 0;
- const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = {
- GNUNET_GETOPT_option_verbose (&vflags),
- GNUNET_GETOPT_OPTION_END
- };
+ const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] =
+ {GNUNET_GETOPT_option_verbose (&vflags), GNUNET_GETOPT_OPTION_END};
if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
{
static int
testVersion ()
{
- char *const myargv[] = {
- "test_getopt",
- "-v",
- NULL
- };
- const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] = {
- GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
- GNUNET_GETOPT_OPTION_END
- };
+ char *const myargv[] = {"test_getopt", "-v", NULL};
+ const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] =
+ {GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
+ GNUNET_GETOPT_OPTION_END};
if (0 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
{
static int
testAbout ()
{
- char *const myargv[] = {
- "test_getopt",
- "-h",
- NULL
- };
- const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] = {
- GNUNET_GETOPT_option_help ("Testing"),
- GNUNET_GETOPT_OPTION_END
- };
+ char *const myargv[] = {"test_getopt", "-h", NULL};
+ const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] =
+ {GNUNET_GETOPT_option_help ("Testing"), GNUNET_GETOPT_OPTION_END};
if (0 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
{
static int
testLogOpts ()
{
- char *const myargv[] = {
- "test_getopt",
- "-l", "filename",
- "-L", "WARNING",
- NULL
- };
+ char *const myargv[] =
+ {"test_getopt", "-l", "filename", "-L", "WARNING", NULL};
char *level = GNUNET_strdup ("stuff");
char *fn = NULL;
- const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
- GNUNET_GETOPT_option_logfile (&fn),
- GNUNET_GETOPT_option_loglevel (&level),
- GNUNET_GETOPT_OPTION_END
- };
+ const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] =
+ {GNUNET_GETOPT_option_logfile (&fn),
+ GNUNET_GETOPT_option_loglevel (&level),
+ GNUNET_GETOPT_OPTION_END};
- if (5 != GNUNET_GETOPT_run ("test_getopt",
- logoptionlist,
- 5, myargv))
+ if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv))
{
GNUNET_break (0);
return 1;
}
GNUNET_assert (NULL != fn);
- if ( (0 != strcmp (level, "WARNING")) ||
- (NULL == strstr (fn, "/filename")) )
+ if ((0 != strcmp (level, "WARNING")) || (NULL == strstr (fn, "/filename")))
{
GNUNET_break (0);
GNUNET_free (level);
static int
testFlagNum ()
{
- char *const myargv[] = {
- "test_getopt",
- "-f",
- "-n", "42",
- "-N", "42",
- NULL
- };
+ char *const myargv[] = {"test_getopt", "-f", "-n", "42", "-N", "42", NULL};
int flag = 0;
unsigned int num = 0;
unsigned long long lnum = 0;
- const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
- GNUNET_GETOPT_option_flag ('f',
- "--flag",
- "helptext",
- &flag),
- GNUNET_GETOPT_option_uint ('n',
- "--num",
- "ARG",
- "helptext",
- &num),
- GNUNET_GETOPT_option_ulong ('N',
- "--lnum",
- "ARG",
- "helptext",
- &lnum),
- GNUNET_GETOPT_OPTION_END
- };
-
- if (6 !=
- GNUNET_GETOPT_run ("test_getopt",
- logoptionlist,
- 6,
- myargv))
+ const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] =
+ {GNUNET_GETOPT_option_flag ('f', "--flag", "helptext", &flag),
+ GNUNET_GETOPT_option_uint ('n', "--num", "ARG", "helptext", &num),
+ GNUNET_GETOPT_option_ulong ('N', "--lnum", "ARG", "helptext", &lnum),
+ GNUNET_GETOPT_OPTION_END};
+
+ if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv))
{
GNUNET_break (0);
return 1;
}
- if ( (1 != flag) ||
- (42 != num) ||
- (42 != lnum))
+ if ((1 != flag) || (42 != num) || (42 != lnum))
{
GNUNET_break (0);
return 1;
{
int errCnt = 0;
- GNUNET_log_setup ("test_getopt",
- "WARNING",
- NULL);
+ GNUNET_log_setup ("test_getopt", "WARNING", NULL);
/* suppress output from -h, -v options */
#ifndef MINGW
- GNUNET_break (0 == CLOSE (1));
+ GNUNET_break (0 == close (1));
#endif
if (0 != testMinimal ())
errCnt++;
pid = GNUNET_PEER_intern (&pidArr[i]);
if (pid != (i + 1))
{
- FPRINTF (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
+ fprintf (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
return 1;
}
}
pid = GNUNET_PEER_intern (&pidArr[i]);
if (pid != (i + 1))
{
- FPRINTF (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
+ fprintf (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
return 1;
}
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("gethostbyname() could not lookup IP address: %s\n"),
hstrerror (h_errno));
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"System seems to be off-line, will not run all DNS tests\n");
*ok = 0; /* mark test as passing anyway */
GNUNET_OS_process_destroy (proc);
proc = NULL;
if (0 != ok)
- FPRINTF (stderr, "Missed some resolutions: %u\n", ok);
+ fprintf (stderr, "Missed some resolutions: %u\n", ok);
return ok;
}
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
&taskNeverRun,
NULL);
- GNUNET_break (0 == PLIBC_KILL (getpid (),
+ GNUNET_break (0 == kill (getpid (),
GNUNET_TERM_SIG));
}
target =
GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MICROSECONDS, i));
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
if (i > MAXV)
{
- FPRINTF (stderr, "%s", "\n");
+ fprintf (stderr, "%s", "\n");
return;
}
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
NULL);
target = GNUNET_TIME_absolute_get ();
GNUNET_SCHEDULER_run (&test_task, NULL);
- FPRINTF (stdout,
+ fprintf (stdout,
"Sleep precision: %llu microseconds (average delta). ",
cumDelta / (MAXV / INCR));
if (cumDelta <= 500 * MAXV / INCR)
- FPRINTF (stdout, "%s", "Timer precision is excellent.\n");
+ fprintf (stdout, "%s", "Timer precision is excellent.\n");
else if (cumDelta <= 5000 * MAXV / INCR) /* 5 ms average deviation */
- FPRINTF (stdout, "%s", "Timer precision is good.\n");
+ fprintf (stdout, "%s", "Timer precision is good.\n");
else if (cumDelta > 25000 * MAXV / INCR)
- FPRINTF (stdout, "%s", "Timer precision is awful.\n");
+ fprintf (stdout, "%s", "Timer precision is awful.\n");
else
- FPRINTF (stdout, "%s", "Timer precision is acceptable.\n");
+ fprintf (stdout, "%s", "Timer precision is acceptable.\n");
return 0;
}
"socket");
return 1;
}
- FPRINTF (stderr,
+ fprintf (stderr,
"IPv6 support seems to not be available (%s), not testing it!\n",
strerror (errno));
}
* however, the "0:05 19" should always be there; hence: */
if (NULL == strstr (bc, "0:05 19"))
{
- FPRINTF (stderr, "Got %s\n", bc);
+ fprintf (stderr, "Got %s\n", bc);
GNUNET_break (0);
return 1;
}
#endif
#endif
-#define LOG(kind,...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
/**
* Variable used to simulate clock skew. Used for testing, never in production.
struct GNUNET_TIME_Absolute ret;
struct timeval tv;
- GETTIMEOFDAY (&tv, NULL);
- ret.abs_value_us =
- (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL) +
- ((uint64_t) tv.tv_usec)) + timestamp_offset;
+ gettimeofday (&tv, NULL);
+ ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL) +
+ ((uint64_t) tv.tv_usec)) +
+ timestamp_offset;
return ret;
}
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_unit_ ()
{
- static struct GNUNET_TIME_Relative one = { 1 };
+ static struct GNUNET_TIME_Relative one = {1};
return one;
}
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_millisecond_ ()
{
- static struct GNUNET_TIME_Relative one = { 1000 };
+ static struct GNUNET_TIME_Relative one = {1000};
return one;
}
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_second_ ()
{
- static struct GNUNET_TIME_Relative one = { 1000 * 1000LL };
+ static struct GNUNET_TIME_Relative one = {1000 * 1000LL};
return one;
}
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_minute_ ()
{
- static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL };
+ static struct GNUNET_TIME_Relative one = {60 * 1000 * 1000LL};
return one;
}
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_hour_ ()
{
- static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL };
+ static struct GNUNET_TIME_Relative one = {60 * 60 * 1000 * 1000LL};
return one;
}
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_forever_ ()
{
- static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
+ static struct GNUNET_TIME_Relative forever = {UINT64_MAX};
return forever;
}
struct GNUNET_TIME_Absolute
GNUNET_TIME_absolute_get_forever_ ()
{
- static struct GNUNET_TIME_Absolute forever = { UINT64_MAX };
+ static struct GNUNET_TIME_Absolute forever = {UINT64_MAX};
return forever;
}
if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
{
- GNUNET_break (0); /* overflow... */
+ GNUNET_break (0); /* overflow... */
return GNUNET_TIME_UNIT_FOREVER_ABS;
}
ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
}
-
/**
* Return the minimum of two relative time values.
*
{
struct GNUNET_TIME_Absolute ret;
- if ((start.abs_value_us == UINT64_MAX) || (duration.rel_value_us == UINT64_MAX))
+ if ((start.abs_value_us == UINT64_MAX) ||
+ (duration.rel_value_us == UINT64_MAX))
return GNUNET_TIME_UNIT_FOREVER_ABS;
if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
{
* @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
*/
struct GNUNET_TIME_Relative
-relative_multiply_double (struct GNUNET_TIME_Relative rel,
- double factor)
+relative_multiply_double (struct GNUNET_TIME_Relative rel, double factor)
{
struct GNUNET_TIME_Relative out;
double m;
* assuming it continues at the same speed
*/
struct GNUNET_TIME_Relative
-GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished,
+GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start,
+ uint64_t finished,
uint64_t total)
{
struct GNUNET_TIME_Relative dur;
ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
return ret;
-
}
struct tm *t;
time_t tp;
- tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
+ tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
t = gmtime (&tp);
if (t == NULL)
return 0;
return t->tm_year + 1900;
-
}
t.tm_wday = 1;
t.tm_yday = 1;
tp = mktime (&t);
- GNUNET_break (tp != (time_t) - 1);
- ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
+ GNUNET_break (tp != (time_t) -1);
+ ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
return ret;
}
* @return the next backoff time
*/
struct GNUNET_TIME_Relative
-GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold)
+GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt,
+ struct GNUNET_TIME_Relative threshold)
{
- double r = (rand() % 500) / 1000.0;
+ double r = (rand () % 500) / 1000.0;
struct GNUNET_TIME_Relative t;
- t = relative_multiply_double (GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS,
- rt),
- 2 + r);
- return GNUNET_TIME_relative_min (threshold,
- t);
+ t = relative_multiply_double (
+ GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, rt),
+ 2 + r);
+ return GNUNET_TIME_relative_min (threshold, t);
}
struct GNUNET_TIME_Relative
GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r)
{
- double d = ((rand() % 1001) - 500) / 1000.0;
+ double d = ((rand () % 1001) - 500) / 1000.0;
- return relative_multiply_double (r,
- d);
+ return relative_multiply_double (r, d);
}
* @return monotonically increasing time
*/
struct GNUNET_TIME_Absolute
-GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cfg)
+GNUNET_TIME_absolute_get_monotonic (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
static struct GNUNET_TIME_Absolute last_time;
map = NULL;
last_cfg = cfg;
- if ( (NULL != cfg) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "util",
- "MONOTONIC_TIME_FILENAME",
- &filename)) )
+ if ((NULL != cfg) &&
+ (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "util",
+ "MONOTONIC_TIME_FILENAME",
+ &filename)))
{
struct GNUNET_DISK_FileHandle *fh;
fh = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_WRITE |
- GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_GROUP_READ);
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_WRITE |
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_GROUP_READ);
if (NULL == fh)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to map `%s', cannot assure monotonic time!\n"),
+ _ ("Failed to map `%s', cannot assure monotonic time!\n"),
filename);
}
else
off_t size;
size = 0;
- GNUNET_break (GNUNET_OK ==
- GNUNET_DISK_file_handle_size (fh,
- &size));
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &size));
if (size < (off_t) sizeof (*map))
{
struct GNUNET_TIME_AbsoluteNBO o;
-
+
o = GNUNET_TIME_absolute_hton (now);
- if (sizeof (o) !=
- GNUNET_DISK_file_write (fh,
- &o,
- sizeof (o)))
+ if (sizeof (o) != GNUNET_DISK_file_write (fh, &o, sizeof (o)))
size = 0;
else
size = sizeof (o);
sizeof (*map));
if (NULL == map)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to map `%s', cannot assure monotonic time!\n"),
+ _ (
+ "Failed to map `%s', cannot assure monotonic time!\n"),
filename);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
- filename);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
+ filename);
}
}
GNUNET_DISK_file_close (fh);
#else
mt.abs_value_us__ = atomic_load (map);
#endif
- last_time = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (mt),
- last_time);
+ last_time =
+ GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (mt), last_time);
}
if (now.abs_value_us <= last_time.abs_value_us)
- now.abs_value_us = last_time.abs_value_us+1;
+ now.abs_value_us = last_time.abs_value_us + 1;
last_time = now;
if (NULL != map)
{
#if __GNUC__
(void) __sync_lock_test_and_set (map, val);
#else
- *map = val; /* godspeed, pray this is atomic */
+ *map = val; /* godspeed, pray this is atomic */
#endif
#else
- atomic_store (map,
- val);
+ atomic_store (map, val);
#endif
}
return now;
/**
* Destructor
*/
-void __attribute__ ((destructor))
-GNUNET_util_time_fini ()
+void __attribute__ ((destructor)) GNUNET_util_time_fini ()
{
(void) GNUNET_TIME_absolute_get_monotonic (NULL);
}
/**
* Option '-d': duration of the mapping
*/
-static struct GNUNET_TIME_Relative duration = { 5 * 60 * 1000} ;
+static struct GNUNET_TIME_Relative duration = {5 * 60 * 1000};
/**
* specified target peer; NULL on error
*/
static void
-allocation_cb (void *cls,
- int af,
- const void *address)
+allocation_cb (void *cls, int af, const void *address)
{
char buf[INET6_ADDRSTRLEN];
{
case AF_INET6:
case AF_INET:
- FPRINTF (stdout,
- "%s\n",
- inet_ntop (af, address, buf, sizeof (buf)));
+ fprintf (stdout, "%s\n", inet_ntop (af, address, buf, sizeof (buf)));
break;
case AF_UNSPEC:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Error creating tunnel\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Error creating tunnel\n"));
ret = 1;
break;
default:
{
if (ipv6)
{
- FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"),
- "-4", "-6");
+ fprintf (stderr,
+ _ ("Option `%s' makes no sense with option `%s'.\n"),
+ "-4",
+ "-6");
goto error;
}
req_af = AF_INET;
{
if (NULL == service_name)
{
- FPRINTF (stderr, _("Option `%s' or `%s' is required.\n"),
- "-i", "-s");
+ fprintf (stderr, _ ("Option `%s' or `%s' is required.\n"), "-i", "-s");
goto error;
}
if (NULL == peer_id)
{
- FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"),
- "-p", "-s");
+ fprintf (stderr,
+ _ ("Option `%s' is required when using option `%s'.\n"),
+ "-p",
+ "-s");
goto error;
}
- if (! (tcp | udp) )
+ if (! (tcp | udp))
{
- FPRINTF (stderr, _("Option `%s' or `%s' is required when using option `%s'.\n"),
- "-t", "-u", "-s");
+ fprintf (stderr,
+ _ ("Option `%s' or `%s' is required when using option `%s'.\n"),
+ "-t",
+ "-u",
+ "-s");
goto error;
}
if (tcp & udp)
{
- FPRINTF (stderr, _("Option `%s' makes no sense with option `%s'.\n"),
- "-t", "-u");
+ fprintf (stderr,
+ _ ("Option `%s' makes no sense with option `%s'.\n"),
+ "-t",
+ "-u");
goto error;
}
if (tcp)
if (udp)
protocol = IPPROTO_UDP;
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
+ GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
strlen (peer_id),
&peer.public_key))
{
- FPRINTF (stderr,
- _("`%s' is not a valid peer identifier.\n"),
- peer_id);
+ fprintf (stderr, _ ("`%s' is not a valid peer identifier.\n"), peer_id);
goto error;
}
- GNUNET_TUN_service_name_to_hash (service_name,
- &sd);
+ GNUNET_TUN_service_name_to_hash (service_name, &sd);
request = GNUNET_VPN_redirect_to_peer (handle,
- req_af,
- protocol,
- &peer,
- &sd,
- etime,
- &allocation_cb, NULL);
+ req_af,
+ protocol,
+ &peer,
+ &sd,
+ etime,
+ &allocation_cb,
+ NULL);
}
else
{
{
if (1 != inet_pton (AF_INET, target_ip, &v4))
{
- FPRINTF (stderr, _("`%s' is not a valid IP address.\n"),
- target_ip);
- goto error;
+ fprintf (stderr, _ ("`%s' is not a valid IP address.\n"), target_ip);
+ goto error;
}
else
{
- dst_af = AF_INET;
- addr = &v4;
+ dst_af = AF_INET;
+ addr = &v4;
}
}
else
addr = &v6;
}
request = GNUNET_VPN_redirect_to_ip (handle,
- req_af,
- dst_af,
- addr,
- etime,
- &allocation_cb, NULL);
+ req_af,
+ dst_af,
+ addr,
+ etime,
+ &allocation_cb,
+ NULL);
}
return;
- error:
+error:
GNUNET_SCHEDULER_shutdown ();
ret = 1;
}
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('4',
- "ipv4",
- gettext_noop ("request that result should be an IPv4 address"),
- &ipv4),
-
- GNUNET_GETOPT_option_flag ('6',
- "ipv6",
- gettext_noop ("request that result should be an IPv6 address"),
- &ipv6),
-
- GNUNET_GETOPT_option_relative_time ('d',
- "duration",
- "TIME",
- gettext_noop ("how long should the mapping be valid for new tunnels?"),
- &duration),
-
- GNUNET_GETOPT_option_string ('i',
- "ip",
- "IP",
- gettext_noop ("destination IP for the tunnel"),
- &target_ip),
-
- GNUNET_GETOPT_option_string ('p',
- "peer",
- "PEERID",
- gettext_noop ("peer offering the service we would like to access"),
- &peer_id),
-
- GNUNET_GETOPT_option_string ('s',
- "service",
- "NAME",
- gettext_noop ("name of the service we would like to access"),
- &service_name),
-
- GNUNET_GETOPT_option_flag ('t',
- "tcp",
- gettext_noop ("service is offered via TCP"),
- &tcp),
-
- GNUNET_GETOPT_option_flag ('u',
- "udp",
- gettext_noop ("service is offered via UDP"),
- &udp),
-
- GNUNET_GETOPT_option_verbose (&verbosity),
-
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag ('4',
+ "ipv4",
+ gettext_noop (
+ "request that result should be an IPv4 address"),
+ &ipv4),
+
+ GNUNET_GETOPT_option_flag ('6',
+ "ipv6",
+ gettext_noop (
+ "request that result should be an IPv6 address"),
+ &ipv6),
+
+ GNUNET_GETOPT_option_relative_time (
+ 'd',
+ "duration",
+ "TIME",
+ gettext_noop ("how long should the mapping be valid for new tunnels?"),
+ &duration),
+
+ GNUNET_GETOPT_option_string ('i',
+ "ip",
+ "IP",
+ gettext_noop (
+ "destination IP for the tunnel"),
+ &target_ip),
+
+ GNUNET_GETOPT_option_string (
+ 'p',
+ "peer",
+ "PEERID",
+ gettext_noop ("peer offering the service we would like to access"),
+ &peer_id),
+
+ GNUNET_GETOPT_option_string ('s',
+ "service",
+ "NAME",
+ gettext_noop (
+ "name of the service we would like to access"),
+ &service_name),
+
+ GNUNET_GETOPT_option_flag ('t',
+ "tcp",
+ gettext_noop ("service is offered via TCP"),
+ &tcp),
+
+ GNUNET_GETOPT_option_flag ('u',
+ "udp",
+ gettext_noop ("service is offered via UDP"),
+ &udp),
+
+ GNUNET_GETOPT_option_verbose (&verbosity),
+
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-vpn",
- gettext_noop
- ("Setup tunnels via VPN."), options,
- &run, NULL)) ? ret : 1;
+ ret =
+ (GNUNET_OK == GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-vpn",
+ gettext_noop ("Setup tunnels via VPN."),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
GNUNET_free ((void *) argv);
return ret;
}