#include "gnunet_curl_lib.h"
-
/**
* Number of connections that we must have to NOT download
* hostlists anymore.
/**
* Time interval hostlists are saved to disk
*/
-#define SAVING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
+#define SAVING_INTERVAL \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
/**
* Time interval between two hostlist tests
*/
-#define TESTING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
+#define TESTING_INTERVAL \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
/**
* Time interval for download dispatcher before a download is re-scheduled
*/
-#define WAITING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+#define WAITING_INTERVAL \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
/**
* Defines concerning the hostlist quality metric
#define HOSTLIST_SUCCESSFUL_HELLO 1
-
/**
* A single hostlist obtained by hostlist advertisements
*/
* Number of times the hostlist was successfully obtained
*/
uint32_t times_used;
-
};
* @return number of bytes that were processed (always size*nmemb)
*/
static size_t
-callback_download (void *ptr,
- size_t size,
- size_t nmemb,
- void *ctx)
+callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
{
static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1];
const char *cbuf = ptr;
stat_bytes_downloaded += total;
if ((total == 0) || (stat_bogus_url))
{
- return total; /* ok, no data or bogus data */
+ return total; /* ok, no data or bogus data */
}
GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("# bytes downloaded from hostlist servers"),
- (int64_t) total, GNUNET_NO);
+ gettext_noop (
+ "# bytes downloaded from hostlist servers"),
+ (int64_t) total,
+ GNUNET_NO);
left = total;
while ((left > 0) || (download_pos > 0))
{
msize = ntohs (msg->size);
if (msize < sizeof (struct GNUNET_MessageHeader))
{
- GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("# invalid HELLOs downloaded from hostlist servers"),
- 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ stats,
+ gettext_noop ("# invalid HELLOs downloaded from hostlist servers"),
+ 1,
+ GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Invalid `%s' message received from hostlist at `%s'\n"),
- "HELLO", current_url);
+ _ ("Invalid `%s' message received from hostlist at `%s'\n"),
+ "HELLO",
+ current_url);
stat_hellos_obtained++;
stat_bogus_url = 1;
return total;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received valid `%s' message from hostlist server.\n",
"HELLO");
- GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("# valid HELLOs downloaded from hostlist servers"),
- 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ stats,
+ gettext_noop ("# valid HELLOs downloaded from hostlist servers"),
+ 1,
+ GNUNET_NO);
stat_hellos_obtained++;
- (void) GNUNET_PEERINFO_add_peer (pi,
- (const struct GNUNET_HELLO_Message *) msg,
- NULL,
- NULL);
+ (void)
+ GNUNET_PEERINFO_add_peer (pi,
+ (const struct GNUNET_HELLO_Message *) msg,
+ NULL,
+ NULL);
}
else
{
- GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("# invalid HELLOs downloaded from hostlist servers"),
- 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (
+ stats,
+ gettext_noop ("# invalid HELLOs downloaded from hostlist servers"),
+ 1,
+ GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Invalid `%s' message received from hostlist at `%s'\n"),
- "HELLO", current_url);
+ _ ("Invalid `%s' message received from hostlist at `%s'\n"),
+ "HELLO",
+ current_url);
stat_bogus_url = GNUNET_YES;
stat_hellos_obtained++;
return total;
}
- memmove (download_buffer,
- &download_buffer[msize],
- download_pos - msize);
+ memmove (download_buffer, &download_buffer[msize], download_pos - msize);
download_pos -= msize;
}
return total;
size_t urls;
size_t pos;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "SERVERS",
- &servers))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ "HOSTLIST",
+ "SERVERS",
+ &servers))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "hostlist", "SERVERS");
+ "hostlist",
+ "SERVERS");
return NULL;
}
if (urls == 0)
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "hostlist", "SERVERS");
+ "hostlist",
+ "SERVERS");
GNUNET_free (servers);
return NULL;
}
return get_bootstrap_server ();
}
index =
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size);
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size);
counter = 0;
pos = linked_list_head;
while (counter < index)
pos = pos->next;
counter++;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using learned hostlist `%s'\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using learned hostlist `%s'\n",
pos->hostlist_uri);
current_hostlist = pos;
return GNUNET_strdup (pos->hostlist_uri);
}
-#define CURL_EASY_SETOPT(c, a, b) do { ret = curl_easy_setopt (c, a, b); if (CURLE_OK != ret) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("%s failed at %s:%d: `%s'\n"), "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror (ret)); } while (0)
+#define CURL_EASY_SETOPT(c, a, b) \
+ do \
+ { \
+ ret = curl_easy_setopt (c, a, b); \
+ if (CURLE_OK != ret) \
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
+ _ ("%s failed at %s:%d: `%s'\n"), \
+ "curl_easy_setopt", \
+ __FILE__, \
+ __LINE__, \
+ curl_easy_strerror (ret)); \
+ } while (0)
/**
* @return result
*/
static uint64_t
-checked_add (uint64_t val1,
- uint64_t val2)
+checked_add (uint64_t val1, uint64_t val2)
{
static uint64_t temp;
static uint64_t maxv;
* @return result
*/
static uint64_t
-checked_sub (uint64_t val1,
- uint64_t val2)
+checked_sub (uint64_t val1, uint64_t val2)
{
if (val1 <= val2)
return 0;
/* No free entries available, replace existing entry */
lowest_quality = linked_list_get_lowest_quality ();
GNUNET_assert (lowest_quality != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n",
- lowest_quality->hostlist_uri,
- (unsigned long long) lowest_quality->quality);
- GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail,
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n",
+ lowest_quality->hostlist_uri,
+ (unsigned long long) lowest_quality->quality);
+ GNUNET_CONTAINER_DLL_remove (linked_list_head,
+ linked_list_tail,
lowest_quality);
linked_list_size--;
GNUNET_free (lowest_quality);
}
- GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail,
+ GNUNET_CONTAINER_DLL_insert (linked_list_head,
+ linked_list_tail,
hostlist_to_test);
linked_list_size++;
- GNUNET_STATISTICS_set (stats, gettext_noop ("# advertised hostlist URIs"),
- linked_list_size, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop ("# advertised hostlist URIs"),
+ linked_list_size,
+ GNUNET_NO);
stat_testing_hostlist = GNUNET_NO;
}
current_hostlist->hello_count = stat_hellos_obtained;
current_hostlist->time_last_usage = GNUNET_TIME_absolute_get ();
current_hostlist->quality =
- checked_add (current_hostlist->quality,
- (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO));
+ checked_add (current_hostlist->quality,
+ (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO));
if (GNUNET_YES == stat_download_successful)
{
current_hostlist->times_used++;
current_hostlist->quality =
- checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD);
- GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"),
+ checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD);
+ GNUNET_asprintf (&stat,
+ gettext_noop ("# advertised URI `%s' downloaded"),
current_hostlist->hostlist_uri);
GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES);
}
else
current_hostlist->quality =
- checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD);
+ checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD);
}
current_hostlist = NULL;
/* Alternating the usage of preconfigured and learned hostlists */
{
CURLMcode mret;
- if ( (stat_testing_hostlist == GNUNET_YES) &&
- (GNUNET_NO == stat_download_successful) &&
- (NULL != hostlist_to_test) )
+ if ((stat_testing_hostlist == GNUNET_YES) &&
+ (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test))
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"),
- hostlist_to_test->hostlist_uri);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ (
+ "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"),
+ hostlist_to_test->hostlist_uri);
}
if (stat_testing_hostlist == GNUNET_YES)
mret = curl_multi_remove_handle (multi, curl);
if (mret != CURLM_OK)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_remove_handle", __FILE__, __LINE__,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_remove_handle",
+ __FILE__,
+ __LINE__,
curl_multi_strerror (mret));
}
mret = curl_multi_cleanup (multi);
if (mret != CURLM_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_cleanup", __FILE__, __LINE__,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_cleanup",
+ __FILE__,
+ __LINE__,
curl_multi_strerror (mret));
multi = NULL;
}
mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
if (mret != CURLM_OK)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_fdset", __FILE__, __LINE__,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_fdset",
+ __FILE__,
+ __LINE__,
curl_multi_strerror (mret));
clean_up ();
return;
mret = curl_multi_timeout (multi, &timeout);
if (mret != CURLM_OK)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_timeout", __FILE__, __LINE__,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_timeout",
+ __FILE__,
+ __LINE__,
curl_multi_strerror (mret));
clean_up ();
return;
}
- rtime =
- GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (end_time),
- GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, timeout));
+ rtime = GNUNET_TIME_relative_min (
+ GNUNET_TIME_absolute_get_remaining (end_time),
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout));
grs = GNUNET_NETWORK_fdset_create ();
gws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Scheduling task for hostlist download using cURL\n");
- ti_download =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- rtime, grs, gws,
- &task_download, multi);
+ ti_download = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ rtime,
+ grs,
+ gws,
+ &task_download,
+ multi);
GNUNET_NETWORK_fdset_destroy (gws);
GNUNET_NETWORK_fdset_destroy (grs);
}
if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Timeout trying to download hostlist from `%s'\n"),
+ _ ("Timeout trying to download hostlist from `%s'\n"),
current_url);
update_hostlist ();
clean_up ();
if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Download limit of %u bytes exceeded, stopping download\n"),
+ _ (
+ "Download limit of %u bytes exceeded, stopping download\n"),
MAX_BYTES_PER_HOSTLISTS);
clean_up ();
return;
if ((msg->data.result != CURLE_OK) &&
(msg->data.result != CURLE_GOT_NOTHING))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Download of hostlist from `%s' failed: `%s'\n"),
+ _ ("Download of hostlist from `%s' failed: `%s'\n"),
current_url,
curl_easy_strerror (msg->data.result));
else
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Download of hostlist `%s' completed.\n"),
+ _ ("Download of hostlist `%s' completed.\n"),
current_url);
stat_download_successful = GNUNET_YES;
update_hostlist ();
if (GNUNET_YES == stat_testing_hostlist)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Adding successfully tested hostlist `%s' datastore.\n"),
- current_url);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ ("Adding successfully tested hostlist `%s' datastore.\n"),
+ current_url);
insert_hostlist ();
hostlist_to_test = NULL;
stat_testing_hostlist = GNUNET_NO;
break;
}
- }
- while ((running > 0));
+ } while ((running > 0));
}
- }
- while (mret == CURLM_CALL_MULTI_PERFORM);
+ } while (mret == CURLM_CALL_MULTI_PERFORM);
if (mret != CURLM_OK)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_perform", __FILE__, __LINE__,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _ ("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_perform",
+ __FILE__,
+ __LINE__,
curl_multi_strerror (mret));
clean_up ();
}
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
- _("Bootstrapping using hostlist at `%s'.\n"), current_url);
+ _ ("Bootstrapping using hostlist at `%s'.\n"),
+ current_url);
stat_download_in_progress = GNUNET_YES;
stat_download_successful = GNUNET_NO;
stat_bytes_downloaded = 0;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# hostlist downloads initiated"), 1,
+ gettext_noop ("# hostlist downloads initiated"),
+ 1,
GNUNET_NO);
if (NULL != proxy)
{
return;
}
CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1);
- CURL_EASY_SETOPT (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
+ CURL_EASY_SETOPT (curl,
+ CURLOPT_REDIR_PROTOCOLS,
+ CURLPROTO_HTTP | CURLPROTO_HTTPS);
CURL_EASY_SETOPT (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4);
/* no need to abort if the above failed */
mret = curl_multi_add_handle (multi, curl);
if (mret != CURLM_OK)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_add_handle", __FILE__, __LINE__,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_add_handle",
+ __FILE__,
+ __LINE__,
curl_multi_strerror (mret));
mret = curl_multi_cleanup (multi);
if (mret != CURLM_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
- "curl_multi_cleanup", __FILE__, __LINE__,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("%s failed at %s:%d: `%s'\n"),
+ "curl_multi_cleanup",
+ __FILE__,
+ __LINE__,
curl_multi_strerror (mret));
multi = NULL;
clean_up ();
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Download in progess, have to wait...\n");
ti_download_dispatcher_task =
- GNUNET_SCHEDULER_add_delayed (WAITING_INTERVAL,
- &task_download_dispatcher, NULL);
+ GNUNET_SCHEDULER_add_delayed (WAITING_INTERVAL,
+ &task_download_dispatcher,
+ NULL);
}
}
if (stats == NULL)
{
curl_global_cleanup ();
- return; /* in shutdown */
+ return; /* in shutdown */
}
- if ( (stat_connection_count < MIN_CONNECTIONS) &&
- (NULL == ti_download_dispatcher_task) )
+ if ((stat_connection_count < MIN_CONNECTIONS) &&
+ (NULL == ti_download_dispatcher_task))
ti_download_dispatcher_task =
- GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL);
+ GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL);
delay = hostlist_delay;
if (0 == hostlist_delay.rel_value_us)
if (hostlist_delay.rel_value_us >
GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count))
hostlist_delay =
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS,
- (1 + stat_connection_count));
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS,
+ (1 + stat_connection_count));
GNUNET_STATISTICS_set (stats,
- gettext_noop
- ("# milliseconds between hostlist downloads"),
+ gettext_noop (
+ "# milliseconds between hostlist downloads"),
hostlist_delay.rel_value_us / 1000LL,
- GNUNET_YES);
+ GNUNET_YES);
if (0 == once)
{
delay = GNUNET_TIME_UNIT_ZERO;
once = 1;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
- stat_connection_count, MIN_CONNECTIONS,
- GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
- ti_check_download = GNUNET_SCHEDULER_add_delayed (delay,
- &task_check, NULL);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ ("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
+ stat_connection_count,
+ MIN_CONNECTIONS,
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
+ ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Hostlists will be saved to file again in %s\n",
- GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL,
+ GNUNET_YES));
ti_saving_task =
- GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
- &task_hostlist_saving,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving, NULL);
}
*/
static void *
handler_connect (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
{
GNUNET_assert (stat_connection_count < UINT_MAX);
stat_connection_count++;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# active connections"),
- 1,
+ gettext_noop ("# active connections"),
+ 1,
GNUNET_NO);
return NULL;
}
*/
static void
handler_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- void *internal_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ void *internal_cls)
{
GNUNET_assert (stat_connection_count > 0);
stat_connection_count--;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# active connections"),
- -1,
+ gettext_noop ("# active connections"),
+ -1,
GNUNET_NO);
}
uri_size = strlen (uri) + 1;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Hostlist client recieved advertisement containing URI `%s'\n",
- uri);
+ uri);
if (GNUNET_NO != linked_list_contains (uri))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "URI `%s' is already known\n",
- uri);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri);
return;
}
if (GNUNET_NO == stat_testing_allowed)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Currently not accepting new advertisements: interval between to advertisements is not reached\n");
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Currently not accepting new advertisements: interval between to advertisements is not reached\n");
return;
}
if (GNUNET_YES == stat_testing_hostlist)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Currently not accepting new advertisements: we are already testing a hostlist\n");
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Currently not accepting new advertisements: we are already testing a hostlist\n");
return;
}
hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size);
hostlist->hostlist_uri = (const char *) &hostlist[1];
- GNUNET_memcpy (&hostlist[1],
- uri,
- uri_size);
+ GNUNET_memcpy (&hostlist[1], uri, uri_size);
hostlist->time_creation = GNUNET_TIME_absolute_get ();
hostlist->quality = HOSTLIST_INITIAL;
hostlist_to_test = hostlist;
stat_testing_hostlist = GNUNET_YES;
stat_testing_allowed = GNUNET_NO;
ti_testing_intervall_task =
- GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL,
- &task_testing_intervall_reset,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL,
+ &task_testing_intervall_reset,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Testing new hostlist advertisements is locked for the next %s\n",
GNUNET_STRINGS_relative_time_to_string (TESTING_INTERVAL,
- GNUNET_YES));
+ GNUNET_YES));
ti_download_dispatcher_task =
- GNUNET_SCHEDULER_add_now (&task_download_dispatcher,
- NULL);
+ GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL);
}
* successfully obtained, #GNUNET_SYSERR if not.
*/
static void
-primary_task (void *cls,
- int success)
+primary_task (void *cls, int success)
{
if (NULL != ti_check_download)
{
{
GNUNET_STATISTICS_get_cancel (sget);
sget = NULL;
- ti_check_download = GNUNET_SCHEDULER_add_now (&task_check,
- NULL);
+ ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL);
}
struct GNUNET_BIO_ReadHandle *rh;
uri = NULL;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE",
- &filename))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "HOSTLIST",
+ "HOSTLISTFILE",
+ &filename))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "hostlist", "HOSTLISTFILE");
+ "hostlist",
+ "HOSTLISTFILE");
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading saved hostlist entries from file `%s' \n"),
- filename);
+ _ ("Loading saved hostlist entries from file `%s' \n"),
+ filename);
if (GNUNET_NO == GNUNET_DISK_file_test (filename))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlist file `%s' does not exist\n"), filename);
+ _ ("Hostlist file `%s' does not exist\n"),
+ filename);
GNUNET_free (filename);
return;
}
if (NULL == rh)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Could not open file `%s' for reading to load hostlists: %s\n"),
- filename, STRERROR (errno));
+ _ (
+ "Could not open file `%s' for reading to load hostlists: %s\n"),
+ filename,
+ strerror (errno));
GNUNET_free (filename);
return;
}
counter = 0;
while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) &&
- (NULL != uri) && (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used))
- && (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
+ (NULL != uri) &&
+ (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) &&
+ (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) &&
(GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) &&
(GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) &&
(GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)))
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("%u hostlist URIs loaded from file\n"),
+ _ ("%u hostlist URIs loaded from file\n"),
counter);
GNUNET_STATISTICS_set (stats,
gettext_noop ("# hostlist URIs read from file"),
- counter, GNUNET_YES);
+ counter,
+ GNUNET_YES);
GNUNET_STATISTICS_set (stats,
gettext_noop ("# advertised hostlist URIs"),
- linked_list_size, GNUNET_NO);
+ linked_list_size,
+ GNUNET_NO);
GNUNET_free_non_null (uri);
emsg = NULL;
int ok;
uint32_t counter;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE",
- &filename))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "HOSTLIST",
+ "HOSTLISTFILE",
+ &filename))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "hostlist", "HOSTLISTFILE");
+ "hostlist",
+ "HOSTLISTFILE");
return;
}
if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
if (NULL == wh)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not open file `%s' for writing to save hostlists: %s\n"),
+ _ (
+ "Could not open file `%s' for writing to save hostlists: %s\n"),
filename,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (filename);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Writing %u hostlist URIs to `%s'\n"),
- linked_list_size, filename);
+ _ ("Writing %u hostlist URIs to `%s'\n"),
+ linked_list_size,
+ filename);
/* add code to write hostlists to file using bio */
ok = GNUNET_YES;
counter = 0;
(GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error writing hostlist URIs to file `%s'\n"), filename);
+ _ ("Error writing hostlist URIs to file `%s'\n"),
+ filename);
ok = GNUNET_NO;
}
}
}
GNUNET_STATISTICS_set (stats,
gettext_noop ("# hostlist URIs written to file"),
- counter, GNUNET_YES);
+ counter,
+ GNUNET_YES);
if (GNUNET_OK != GNUNET_BIO_write_close (wh))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error writing hostlist URIs to file `%s'\n"), filename);
+ _ ("Error writing hostlist URIs to file `%s'\n"),
+ filename);
GNUNET_free (filename);
}
/* Read proxy configuration */
pi = GNUNET_PEERINFO_connect (c);
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "HOSTLIST",
- "PROXY",
- &proxy))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found proxy host: `%s'\n",
- proxy);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy);
/* proxy username */
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "HOSTLIST",
- "PROXY_USERNAME",
- &proxy_username))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
+ "HOSTLIST",
+ "PROXY_USERNAME",
+ &proxy_username))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found proxy username name: `%s'\n",
- proxy_username);
+ "Found proxy username name: `%s'\n",
+ proxy_username);
}
/* proxy password */
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "HOSTLIST",
- "PROXY_PASSWORD",
- &proxy_password))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
+ "HOSTLIST",
+ "PROXY_PASSWORD",
+ &proxy_password))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found proxy password name: `%s'\n",
- proxy_password);
+ "Found proxy password name: `%s'\n",
+ proxy_password);
}
/* proxy type */
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "HOSTLIST",
- "PROXY_TYPE",
- &proxytype_str))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
+ "HOSTLIST",
+ "PROXY_TYPE",
+ &proxytype_str))
{
- GNUNET_STRINGS_utf8_toupper (proxytype_str,
- proxytype_str);
+ GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str);
proxy_type = CURLPROXY_HTTP;
if (0 == strcmp (proxytype_str, "HTTP"))
proxy_type = CURLPROXY_HTTP;
proxy_type = CURLPROXY_SOCKS5_HOSTNAME;
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
- proxytype_str);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
+ proxytype_str);
GNUNET_free (proxytype_str);
GNUNET_free (proxy);
proxy = NULL;
{
*msgh = &handler_advertisement;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Learning is enabled on this peer\n"));
+ _ ("Learning is enabled on this peer\n"));
load_hostlist_file ();
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Hostlists will be saved to file again in %s\n",
- GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL,
- GNUNET_YES));
- ti_saving_task =
- GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
- &task_hostlist_saving,
- NULL);
+ GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL,
+ GNUNET_YES));
+ ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
+ &task_hostlist_saving,
+ NULL);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Learning is not enabled on this peer\n"));
+ _ ("Learning is not enabled on this peer\n"));
*msgh = NULL;
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "HOSTLIST",
- "HOSTLISTFILE",
- &filename))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "HOSTLIST",
+ "HOSTLISTFILE",
+ &filename))
{
if (GNUNET_YES == GNUNET_DISK_file_test (filename))
{
result = remove (filename);
if (0 == result)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
- filename);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ (
+ "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"),
+ filename);
else
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
"remove",
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Loading stats value on hostlist download frequency\n");
- sget = GNUNET_STATISTICS_get (stats, "hostlist",
- gettext_noop
- ("# milliseconds between hostlist downloads"),
+ sget = GNUNET_STATISTICS_get (stats,
+ "hostlist",
+ gettext_noop (
+ "# milliseconds between hostlist downloads"),
&primary_task,
&process_stat,
- NULL);
+ NULL);
if (NULL == sget)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Statistics request failed, scheduling hostlist download\n");
- ti_check_download = GNUNET_SCHEDULER_add_now (&task_check,
- NULL);
+ ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL);
}
else
{
- ti_check_download
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &stat_timeout_task,
- NULL);
+ ti_check_download = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &stat_timeout_task,
+ NULL);
}
return GNUNET_OK;
}
void
GNUNET_HOSTLIST_client_stop ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist client shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
if (NULL != sget)
{
GNUNET_STATISTICS_get_cancel (sget);
ti_saving_task = NULL;
}
if (NULL != ti_download_dispatcher_task)
- {
+ {
GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
ti_download_dispatcher_task = NULL;
}
#include "gnunet_nat_lib.h"
#include "nat.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "nat", __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_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_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_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);
}
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->is_tcp);
- GNUNET_MQ_send (ca->mq,
- env);
+ GNUNET_MQ_send (ca->mq, env);
}
nh->ttask = NULL;
nh->report (nh->report_cls,
(GNUNET_NAT_ERROR_SUCCESS == nh->status)
- ? GNUNET_NAT_ERROR_TIMEOUT
- : nh->status);
+ ? GNUNET_NAT_ERROR_TIMEOUT
+ : nh->status);
}
{
struct GNUNET_NAT_Test *nh;
struct sockaddr_in sa;
- const struct sockaddr *addrs[] = {
- (const struct sockaddr *) &sa
- };
- const socklen_t addrlens[] = {
- sizeof (sa)
- };
+ const struct sockaddr *addrs[] = {(const struct sockaddr *) &sa};
+ const socklen_t addrlens[] = {sizeof (sa)};
memset (&sa, 0, sizeof (sa));
sa.sin_family = AF_INET;
nh->status = GNUNET_NAT_ERROR_SUCCESS;
if (0 == bnd_port)
{
- nh->nat
- = GNUNET_NAT_register (cfg,
- is_tcp,
- 0,
- 0,
- NULL,
- NULL,
- &addr_cb,
- &reversal_cb,
- nh,
- NULL);
+ nh->nat = GNUNET_NAT_register (cfg,
+ is_tcp,
+ 0,
+ 0,
+ NULL,
+ NULL,
+ &addr_cb,
+ &reversal_cb,
+ nh,
+ NULL);
}
else
{
nh->lsock =
- GNUNET_NETWORK_socket_create (AF_INET,
- (is_tcp ==
- GNUNET_YES) ? SOCK_STREAM : SOCK_DGRAM,
- 0);
+ GNUNET_NETWORK_socket_create (AF_INET,
+ (is_tcp == GNUNET_YES) ? SOCK_STREAM
+ : SOCK_DGRAM,
+ 0);
if ((nh->lsock == NULL) ||
- (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (nh->lsock,
- (const struct sockaddr *) &sa,
- sizeof (sa))))
+ (GNUNET_OK != GNUNET_NETWORK_socket_bind (nh->lsock,
+ (const struct sockaddr *) &sa,
+ sizeof (sa))))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create listen socket bound to `%s' for NAT test: %s\n"),
- GNUNET_a2s ((const struct sockaddr *) &sa,
- sizeof (sa)),
- STRERROR (errno));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to create listen 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_timeout,
- nh);
+ nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh);
return nh;
}
if (GNUNET_YES == is_tcp)
{
- 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 %u (%s)\n",
- bnd_port,
- (GNUNET_YES == is_tcp) ? "tcp" : "udp");
+ "NAT test listens on port %u (%s)\n",
+ bnd_port,
+ (GNUNET_YES == is_tcp) ? "tcp" : "udp");
nh->nat = GNUNET_NAT_register (cfg,
is_tcp,
adv_port,
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_timeout,
- nh);
+ nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh);
return nh;
}
}
- nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout,
- &do_timeout,
- nh);
+ nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, 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);
struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
GNUNET_memcpy (&macmsg.mac,
- (char *) mac,
- sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
- macmsg.hdr.size = htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
+ (char *) mac,
+ sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
+ macmsg.hdr.size =
+ htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
GNUNET_memcpy (buffer,
- &macmsg,
- sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
+ &macmsg,
+ sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
}
* #GNUNET_SYSERR to stop further processing with error
*/
static int
-stdin_send (void *cls,
- const struct GNUNET_MessageHeader *hdr)
+stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr)
{
struct SendBuffer *write_pout = cls;
const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in;
sendsize = ntohs (hdr->size);
in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
- if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ||
- (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) )
+ 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");
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)
+ 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));
newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
newheader.frame = in->frame;
GNUNET_memcpy (write_pout->buf + write_pout->size,
- &newheader,
- sizeof (newheader));
+ &newheader,
+ sizeof (newheader));
write_pout->size += sizeof (newheader);
- GNUNET_memcpy (write_pout->buf + write_pout->size,
- &in[1],
- payload_size);
+ GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size);
write_pout->size += payload_size;
return GNUNET_OK;
}
* #GNUNET_SYSERR to stop further processing with error
*/
static int
-file_in_send (void *cls,
- const struct GNUNET_MessageHeader *hdr)
+file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr)
{
struct SendBuffer *write_std = cls;
uint16_t sendsize;
struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr;
int first;
- if ( (2 != argc) ||
- ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) )
+ if ((2 != argc) ||
+ ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))))
{
- fprintf (stderr,
- "%s",
- "This program must be started with the operating mode (1 or 2) as the only argument.\n");
+ fprintf (
+ stderr,
+ "%s",
+ "This program must be started with the operating mode (1 or 2) as the only argument.\n");
return 1;
}
/* make the fifos if needed */
umask (0);
- if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
- (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) )
+ if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)))
{
- fprintf (stderr,
- "Failed to create directory for file `%s'\n",
- FIFO_FILE1);
+ fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
return 1;
}
- if (0 == strcmp (argv[1], "1") )
+ if (0 == strcmp (argv[1], "1"))
{
if (0 != stat (FIFO_FILE1, &st))
{
erg = mkfifo (FIFO_FILE1, 0666);
- if ( (0 != erg) && (EEXIST != errno) )
- fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1,
- strerror (errno));
+ if ((0 != erg) && (EEXIST != errno))
+ fprintf (stderr,
+ "Error in mkfifo(%s): %s\n",
+ FIFO_FILE1,
+ strerror (errno));
}
}
else
{
if (0 != stat (FIFO_FILE2, &st))
{
- GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666)));
- if ( (0 != erg) && (EEXIST != errno) )
- fprintf (stderr,
+ GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666)));
+ if ((0 != erg) && (EEXIST != errno))
+ fprintf (stderr,
"Error in mkfifo(%s): %s\n",
FIFO_FILE2,
- strerror (errno));
+ strerror (errno));
}
}
{
fprintf (stderr,
"fopen of read FIFO_FILE1 failed: %s\n",
- STRERROR (errno));
+ strerror (errno));
goto end;
}
if (NULL == (fpout = fopen (FIFO_FILE2, "w")))
{
fprintf (stderr,
"fopen of write FIFO_FILE2 failed: %s\n",
- STRERROR (errno));
+ strerror (errno));
goto end;
}
}
first = 0;
if (NULL == (fpout = fopen (FIFO_FILE1, "w")))
{
- GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666));
+ GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666));
fpout = fopen (FIFO_FILE1, "w");
}
if (NULL == fpout)
{
fprintf (stderr,
"fopen of write FIFO_FILE1 failed: %s\n",
- STRERROR (errno));
+ strerror (errno));
goto end;
}
fpin = fopen (FIFO_FILE2, "r");
{
fprintf (stderr,
"fopen of read FIFO_FILE2 failed: %s\n",
- STRERROR (errno));
+ strerror (errno));
goto end;
}
}
continue;
if (0 > retval)
{
- fprintf (stderr, "select failed: %s\n", STRERROR (errno));
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
closeprog = 1;
break;
}
if (FD_ISSET (STDOUT_FILENO, &wfds))
{
- ret =
- write (STDOUT_FILENO, write_std.buf + write_std.pos,
- write_std.size - write_std.pos);
+ ret = write (STDOUT_FILENO,
+ write_std.buf + write_std.pos,
+ write_std.size - write_std.pos);
if (0 > ret)
{
closeprog = 1;
- fprintf (stderr, "Write ERROR to STDOUT_FILENO: %s\n",
- STRERROR (errno));
+ fprintf (stderr,
+ "Write ERROR to STDOUT_FILENO: %s\n",
+ strerror (errno));
break;
}
else
if (FD_ISSET (fdpout, &wfds))
{
- ret =
- write (fdpout, write_pout.buf + write_pout.pos,
- write_pout.size - write_pout.pos);
+ ret = write (fdpout,
+ write_pout.buf + write_pout.pos,
+ write_pout.size - write_pout.pos);
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",
- STRERROR (errno));
+ fprintf (stderr,
+ "Error reading from STDIN_FILENO: %s\n",
+ strerror (errno));
}
else if (0 < readsize)
{
GNUNET_MST_from_buffer (stdin_mst,
- readbuf, readsize,
- GNUNET_NO, GNUNET_NO);
-
+ readbuf,
+ readsize,
+ GNUNET_NO,
+ GNUNET_NO);
}
else
{
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)
{
GNUNET_MST_from_buffer (file_in_mst,
- readbuf, readsize,
- GNUNET_NO, GNUNET_NO);
+ readbuf,
+ readsize,
+ GNUNET_NO,
+ GNUNET_NO);
}
else
{
#define WLAN_LLC_DSAP_FIELD 0x1f
#define WLAN_LLC_SSAP_FIELD 0x1f
-#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
+#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
-#define IEEE80211_FC0_VERSION_MASK 0x03
-#define IEEE80211_FC0_VERSION_SHIFT 0
-#define IEEE80211_FC0_VERSION_0 0x00
-#define IEEE80211_FC0_TYPE_MASK 0x0c
-#define IEEE80211_FC0_TYPE_SHIFT 2
-#define IEEE80211_FC0_TYPE_MGT 0x00
-#define IEEE80211_FC0_TYPE_CTL 0x04
-#define IEEE80211_FC0_TYPE_DATA 0x08
+#define IEEE80211_FC0_VERSION_MASK 0x03
+#define IEEE80211_FC0_VERSION_SHIFT 0
+#define IEEE80211_FC0_VERSION_0 0x00
+#define IEEE80211_FC0_TYPE_MASK 0x0c
+#define IEEE80211_FC0_TYPE_SHIFT 2
+#define IEEE80211_FC0_TYPE_MGT 0x00
+#define IEEE80211_FC0_TYPE_CTL 0x04
+#define IEEE80211_FC0_TYPE_DATA 0x08
/**
*/
static int
getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
- uint16_t size)
+ uint16_t size)
{
header->header.size = htons (size);
header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER);
*/
static int
getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header,
- const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
- const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, unsigned int size)
+ const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
+ const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac,
+ unsigned int size)
{
const int rate = 11000000;
int i;
ssize_t ret;
pid_t pid;
- int commpipe[2]; /* This holds the fd for the input & output of the pipe */
- int macpipe[2]; /* This holds the fd for the input & output of the pipe */
+ int commpipe[2]; /* This holds the fd for the input & output of the pipe */
+ int macpipe[2]; /* This holds the fd for the input & output of the pipe */
if (4 != argc)
{
- fprintf (stderr,
- "This program must be started with the interface and the targets and source mac as argument.\n");
+ fprintf (
+ stderr,
+ "This program must be started with the interface and the targets and source mac as argument.\n");
fprintf (stderr,
"Usage: interface-name mac-DST mac-SRC\n"
"e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n");
return 1;
}
- if (6 !=
- SSCANF (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2],
- &temp[3], &temp[4], &temp[5]))
+ if (6 != SSCANF (argv[2],
+ "%x-%x-%x-%x-%x-%x",
+ &temp[0],
+ &temp[1],
+ &temp[2],
+ &temp[3],
+ &temp[4],
+ &temp[5]))
{
fprintf (stderr,
"Usage: interface-name mac-DST mac-SRC\n"
}
for (i = 0; i < 6; i++)
outmac.mac[i] = temp[i];
- if (6 !=
- SSCANF (argv[3], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2],
- &temp[3], &temp[4], &temp[5]))
+ if (6 != SSCANF (argv[3],
+ "%x-%x-%x-%x-%x-%x",
+ &temp[0],
+ &temp[1],
+ &temp[2],
+ &temp[3],
+ &temp[4],
+ &temp[5]))
{
fprintf (stderr,
"Usage: interface-name mac-DST mac-SRC\n"
/* Setup communication pipeline first */
if (pipe (commpipe))
{
- fprintf (stderr,
- "Failed to create pipe: %s\n",
- STRERROR (errno));
+ fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
exit (1);
}
if (pipe (macpipe))
{
- fprintf (stderr,
- "Failed to create pipe: %s\n",
- STRERROR (errno));
+ fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
exit (1);
}
/* Attempt to fork and check for errors */
if ((pid = fork ()) == -1)
{
- fprintf (stderr, "Failed to fork: %s\n",
- STRERROR (errno));
+ fprintf (stderr, "Failed to fork: %s\n", strerror (errno));
exit (1);
}
memset (msg_buf, 0x42, sizeof (msg_buf));
if (pid)
{
/* A positive (non-negative) PID indicates the parent process */
- if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */
- fprintf (stderr,
- "Failed to close fd: %s\n",
- strerror (errno));
- setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */
+ if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */
+ fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
+ setvbuf (stdout,
+ (char *) NULL,
+ _IONBF,
+ 0); /* Set non-buffered output on stdout */
if (0 != close (macpipe[1]))
- fprintf (stderr,
- "Failed to close fd: %s\n",
- strerror (errno));
+ fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
if (sizeof (hcm) != read (macpipe[0], &hcm, sizeof (hcm)))
- fprintf (stderr,
- "Failed to read hcm...\n");
+ fprintf (stderr, "Failed to read hcm...\n");
fprintf (stderr,
- "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
- hcm.mac.mac[0], hcm.mac.mac[1],
- hcm.mac.mac[2], hcm.mac.mac[3], hcm.mac.mac[4], hcm.mac.mac[5]);
+ "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
+ hcm.mac.mac[0],
+ hcm.mac.mac[1],
+ hcm.mac.mac[2],
+ hcm.mac.mac[3],
+ hcm.mac.mac[4],
+ hcm.mac.mac[5]);
radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf;
getRadiotapHeader (radiotap, WLAN_MTU);
- getWlanHeader (&radiotap->frame, &outmac, &inmac,
- WLAN_MTU);
+ getWlanHeader (&radiotap->frame, &outmac, &inmac, WLAN_MTU);
start = time (NULL);
count = 0;
while (1)
ret = write (commpipe[1], msg_buf, WLAN_MTU);
if (0 > ret)
{
- fprintf (stderr, "write failed: %s\n", strerror (errno));
- break;
+ fprintf (stderr, "write failed: %s\n", strerror (errno));
+ break;
}
count += ret;
- akt = time (NULL);
+ akt = time (NULL);
if (akt - start > 30)
{
- bytes_per_s = count / (akt - start);
- bytes_per_s /= 1024;
- printf ("send %f kbytes/s\n", bytes_per_s);
- start = akt;
- count = 0;
+ bytes_per_s = count / (akt - start);
+ bytes_per_s /= 1024;
+ printf ("send %f kbytes/s\n", bytes_per_s);
+ start = akt;
+ count = 0;
}
}
}
/* A zero PID indicates that this is the child process */
(void) close (0);
(void) close (1);
- if (-1 == dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */
+ if (-1 ==
+ dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */
fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
- if (-1 == dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */
+ if (-1 ==
+ dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */
fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
(void) close (commpipe[1]); /* Close unused side of pipe (out side) */
(void) close (macpipe[0]); /* Close unused side of pipe (in side) */
/* Replace the child fork with a new process */
- if (execlp
- ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan",
- argv[1], NULL) == -1)
+ if (execlp ("gnunet-helper-transport-wlan",
+ "gnunet-helper-transport-wlan",
+ argv[1],
+ NULL) == -1)
{
fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
_exit (1);