summaryrefslogtreecommitdiff
path: root/src/pt
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/pt
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/pt')
-rw-r--r--src/pt/gnunet-daemon-pt.c1096
-rw-r--r--src/pt/test_gns_vpn.c905
-rw-r--r--src/pt/test_gnunet_vpn.c525
3 files changed, 1271 insertions, 1255 deletions
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c
index ad22eaab8..675c71732 100644
--- a/src/pt/gnunet-daemon-pt.c
+++ b/src/pt/gnunet-daemon-pt.c
@@ -58,7 +58,8 @@
/**
* Which group of DNS records are we currently processing?
*/
-enum RequestGroup {
+enum RequestGroup
+{
/**
* DNS answers
*/
@@ -84,7 +85,8 @@ enum RequestGroup {
/**
* Information tracked per DNS reply that we are processing.
*/
-struct ReplyContext {
+struct ReplyContext
+{
/**
* Handle to submit the final result.
*/
@@ -122,7 +124,8 @@ struct ReplyContext {
* as a DNS exit. We try to keep a few channels open and a few
* peers in reserve.
*/
-struct CadetExit {
+struct CadetExit
+{
/**
* Kept in a DLL.
*/
@@ -180,7 +183,8 @@ struct CadetExit {
/**
* State we keep for a request that is going out via CADET.
*/
-struct RequestContext {
+struct RequestContext
+{
/**
* We keep these in a DLL.
*/
@@ -302,7 +306,7 @@ static unsigned int dns_exit_available;
* We are short on cadet exits, try to open another one.
*/
static void
-try_open_exit(void);
+try_open_exit (void);
/**
@@ -315,23 +319,23 @@ try_open_exit(void);
* @return weight of the channel
*/
static uint32_t
-get_channel_weight(struct CadetExit *exit)
+get_channel_weight (struct CadetExit *exit)
{
uint32_t dropped;
uint32_t drop_percent;
uint32_t good_percent;
- GNUNET_assert(exit->num_transmitted >= exit->num_answered);
+ GNUNET_assert (exit->num_transmitted >= exit->num_answered);
dropped = exit->num_transmitted - exit->num_answered;
if (exit->num_transmitted > 0)
- drop_percent = (uint32_t)((100LL * dropped) / exit->num_transmitted);
+ drop_percent = (uint32_t) ((100LL * dropped) / exit->num_transmitted);
else
drop_percent = 50; /* no data */
if ((exit->num_transmitted > 20) &&
(drop_percent > 25))
return 0; /* statistically significant, and > 25% loss, die */
good_percent = 100 - drop_percent;
- GNUNET_assert(0 != good_percent);
+ GNUNET_assert (0 != good_percent);
if (UINT32_MAX / good_percent / good_percent < exit->num_transmitted)
return UINT32_MAX; /* formula below would overflow */
return 1 + good_percent * good_percent * exit->num_transmitted;
@@ -350,7 +354,7 @@ get_channel_weight(struct CadetExit *exit)
* exit that we should use to queue a message with
*/
static struct CadetExit *
-choose_exit()
+choose_exit ()
{
struct CadetExit *pos;
uint64_t total_transmitted;
@@ -359,36 +363,36 @@ choose_exit()
total_transmitted = 0;
for (pos = exit_head; NULL != pos; pos = pos->next)
- {
- if (NULL == pos->cadet_channel)
- break;
- channel_weight = get_channel_weight(pos);
+ {
+ if (NULL == pos->cadet_channel)
+ break;
+ channel_weight = get_channel_weight (pos);
+ total_transmitted += channel_weight;
+ /* double weight for idle channels */
+ if (0 != pos->idle)
total_transmitted += channel_weight;
- /* double weight for idle channels */
- if (0 != pos->idle)
- total_transmitted += channel_weight;
- }
+ }
if (0 == total_transmitted)
- {
- /* no channels available, or only a very bad one... */
- return exit_head;
- }
- selected_offset = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
- total_transmitted);
+ {
+ /* no channels available, or only a very bad one... */
+ return exit_head;
+ }
+ selected_offset = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ total_transmitted);
total_transmitted = 0;
for (pos = exit_head; NULL != pos; pos = pos->next)
- {
- if (NULL == pos->cadet_channel)
- break;
- channel_weight = get_channel_weight(pos);
+ {
+ if (NULL == pos->cadet_channel)
+ break;
+ channel_weight = get_channel_weight (pos);
+ total_transmitted += channel_weight;
+ /* double weight for idle channels */
+ if (0 != pos->idle)
total_transmitted += channel_weight;
- /* double weight for idle channels */
- if (0 != pos->idle)
- total_transmitted += channel_weight;
- if (total_transmitted > selected_offset)
- return pos;
- }
- GNUNET_break(0);
+ if (total_transmitted > selected_offset)
+ return pos;
+ }
+ GNUNET_break (0);
return NULL;
}
@@ -400,33 +404,33 @@ choose_exit()
* @param rc context to process
*/
static void
-finish_request(struct ReplyContext *rc)
+finish_request (struct ReplyContext *rc)
{
char *buf;
size_t buf_len;
if (GNUNET_SYSERR ==
- GNUNET_DNSPARSER_pack(rc->dns,
- MAX_DNS_SIZE,
- &buf,
- &buf_len))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Failed to pack DNS request. Dropping.\n"));
- GNUNET_DNS_request_drop(rc->rh);
- }
+ GNUNET_DNSPARSER_pack (rc->dns,
+ MAX_DNS_SIZE,
+ &buf,
+ &buf_len))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to pack DNS request. Dropping.\n"));
+ GNUNET_DNS_request_drop (rc->rh);
+ }
else
- {
- GNUNET_STATISTICS_update(stats,
- gettext_noop("# DNS requests mapped to VPN"),
- 1, GNUNET_NO);
- GNUNET_DNS_request_answer(rc->rh,
- buf_len,
- buf);
- GNUNET_free(buf);
- }
- GNUNET_DNSPARSER_free_packet(rc->dns);
- GNUNET_free(rc);
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS requests mapped to VPN"),
+ 1, GNUNET_NO);
+ GNUNET_DNS_request_answer (rc->rh,
+ buf_len,
+ buf);
+ GNUNET_free (buf);
+ }
+ GNUNET_DNSPARSER_free_packet (rc->dns);
+ GNUNET_free (rc);
}
@@ -438,7 +442,7 @@ finish_request(struct ReplyContext *rc)
* @param rc context to process
*/
static void
-submit_request(struct ReplyContext *rc);
+submit_request (struct ReplyContext *rc);
/**
@@ -457,46 +461,46 @@ submit_request(struct ReplyContext *rc);
* specified target peer; NULL on error
*/
static void
-vpn_allocation_callback(void *cls,
- int af,
- const void *address)
+vpn_allocation_callback (void *cls,
+ int af,
+ const void *address)
{
struct ReplyContext *rc = cls;
rc->rr = NULL;
if (af == AF_UNSPEC)
- {
- GNUNET_DNS_request_drop(rc->rh);
- GNUNET_DNSPARSER_free_packet(rc->dns);
- GNUNET_free(rc);
- return;
- }
- GNUNET_STATISTICS_update(stats,
- gettext_noop("# DNS records modified"),
- 1,
- GNUNET_NO);
+ {
+ GNUNET_DNS_request_drop (rc->rh);
+ GNUNET_DNSPARSER_free_packet (rc->dns);
+ GNUNET_free (rc);
+ return;
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS records modified"),
+ 1,
+ GNUNET_NO);
switch (rc->rec->type)
- {
- case GNUNET_DNSPARSER_TYPE_A:
- GNUNET_assert(AF_INET == af);
- GNUNET_memcpy(rc->rec->data.raw.data,
- address,
- sizeof(struct in_addr));
- break;
-
- case GNUNET_DNSPARSER_TYPE_AAAA:
- GNUNET_assert(AF_INET6 == af);
- GNUNET_memcpy(rc->rec->data.raw.data,
- address,
- sizeof(struct in6_addr));
- break;
-
- default:
- GNUNET_assert(0);
- return;
- }
+ {
+ case GNUNET_DNSPARSER_TYPE_A:
+ GNUNET_assert (AF_INET == af);
+ GNUNET_memcpy (rc->rec->data.raw.data,
+ address,
+ sizeof(struct in_addr));
+ break;
+
+ case GNUNET_DNSPARSER_TYPE_AAAA:
+ GNUNET_assert (AF_INET6 == af);
+ GNUNET_memcpy (rc->rec->data.raw.data,
+ address,
+ sizeof(struct in6_addr));
+ break;
+
+ default:
+ GNUNET_assert (0);
+ return;
+ }
rc->rec = NULL;
- submit_request(rc);
+ submit_request (rc);
}
@@ -510,35 +514,36 @@ vpn_allocation_callback(void *cls,
* @param rec record to modify
*/
static void
-modify_address(struct ReplyContext *rc,
- struct GNUNET_DNSPARSER_Record *rec)
+modify_address (struct ReplyContext *rc,
+ struct GNUNET_DNSPARSER_Record *rec)
{
int af;
switch (rec->type)
- {
- case GNUNET_DNSPARSER_TYPE_A:
- af = AF_INET;
- GNUNET_assert(rec->data.raw.data_len == sizeof(struct in_addr));
- break;
-
- case GNUNET_DNSPARSER_TYPE_AAAA:
- af = AF_INET6;
- GNUNET_assert(rec->data.raw.data_len == sizeof(struct in6_addr));
- break;
-
- default:
- GNUNET_assert(0);
- return;
- }
+ {
+ case GNUNET_DNSPARSER_TYPE_A:
+ af = AF_INET;
+ GNUNET_assert (rec->data.raw.data_len == sizeof(struct in_addr));
+ break;
+
+ case GNUNET_DNSPARSER_TYPE_AAAA:
+ af = AF_INET6;
+ GNUNET_assert (rec->data.raw.data_len == sizeof(struct in6_addr));
+ break;
+
+ default:
+ GNUNET_assert (0);
+ return;
+ }
rc->rec = rec;
- rc->rr = GNUNET_VPN_redirect_to_ip(vpn_handle,
- af,
- af,
- rec->data.raw.data,
- GNUNET_TIME_relative_to_absolute(TIMEOUT),
- &vpn_allocation_callback,
- rc);
+ rc->rr = GNUNET_VPN_redirect_to_ip (vpn_handle,
+ af,
+ af,
+ rec->data.raw.data,
+ GNUNET_TIME_relative_to_absolute (
+ TIMEOUT),
+ &vpn_allocation_callback,
+ rc);
}
@@ -550,65 +555,65 @@ modify_address(struct ReplyContext *rc,
* @param rc context to process
*/
static void
-submit_request(struct ReplyContext *rc)
+submit_request (struct ReplyContext *rc)
{
struct GNUNET_DNSPARSER_Record *ra;
unsigned int ra_len;
unsigned int i;
while (1)
+ {
+ switch (rc->group)
+ {
+ case ANSWERS:
+ ra = rc->dns->answers;
+ ra_len = rc->dns->num_answers;
+ break;
+
+ case AUTHORITY_RECORDS:
+ ra = rc->dns->authority_records;
+ ra_len = rc->dns->num_authority_records;
+ break;
+
+ case ADDITIONAL_RECORDS:
+ ra = rc->dns->additional_records;
+ ra_len = rc->dns->num_additional_records;
+ break;
+
+ case END:
+ finish_request (rc);
+ return;
+
+ default:
+ GNUNET_assert (0);
+ }
+ for (i = rc->offset; i < ra_len; i++)
{
- switch (rc->group)
+ switch (ra[i].type)
+ {
+ case GNUNET_DNSPARSER_TYPE_A:
+ if (ipv4_pt)
{
- case ANSWERS:
- ra = rc->dns->answers;
- ra_len = rc->dns->num_answers;
- break;
-
- case AUTHORITY_RECORDS:
- ra = rc->dns->authority_records;
- ra_len = rc->dns->num_authority_records;
- break;
-
- case ADDITIONAL_RECORDS:
- ra = rc->dns->additional_records;
- ra_len = rc->dns->num_additional_records;
- break;
-
- case END:
- finish_request(rc);
+ rc->offset = i + 1;
+ modify_address (rc,
+ &ra[i]);
return;
-
- default:
- GNUNET_assert(0);
}
- for (i = rc->offset; i < ra_len; i++)
+ break;
+
+ case GNUNET_DNSPARSER_TYPE_AAAA:
+ if (ipv6_pt)
{
- switch (ra[i].type)
- {
- case GNUNET_DNSPARSER_TYPE_A:
- if (ipv4_pt)
- {
- rc->offset = i + 1;
- modify_address(rc,
- &ra[i]);
- return;
- }
- break;
-
- case GNUNET_DNSPARSER_TYPE_AAAA:
- if (ipv6_pt)
- {
- rc->offset = i + 1;
- modify_address(rc,
- &ra[i]);
- return;
- }
- break;
- }
+ rc->offset = i + 1;
+ modify_address (rc,
+ &ra[i]);
+ return;
}
- rc->group++;
+ break;
+ }
}
+ rc->group++;
+ }
}
@@ -620,26 +625,26 @@ submit_request(struct ReplyContext *rc)
* @return #GNUNET_YES if any of the given records require protocol-translation
*/
static int
-work_test(const struct GNUNET_DNSPARSER_Record *ra,
- unsigned int ra_len)
+work_test (const struct GNUNET_DNSPARSER_Record *ra,
+ unsigned int ra_len)
{
unsigned int i;
for (i = 0; i < ra_len; i++)
+ {
+ switch (ra[i].type)
{
- switch (ra[i].type)
- {
- case GNUNET_DNSPARSER_TYPE_A:
- if (ipv4_pt)
- return GNUNET_YES;
- break;
-
- case GNUNET_DNSPARSER_TYPE_AAAA:
- if (ipv6_pt)
- return GNUNET_YES;
- break;
- }
+ case GNUNET_DNSPARSER_TYPE_A:
+ if (ipv4_pt)
+ return GNUNET_YES;
+ break;
+
+ case GNUNET_DNSPARSER_TYPE_AAAA:
+ if (ipv6_pt)
+ return GNUNET_YES;
+ break;
}
+ }
return GNUNET_NO;
}
@@ -656,46 +661,46 @@ work_test(const struct GNUNET_DNSPARSER_Record *ra,
* @param request udp payload of the DNS request
*/
static void
-dns_post_request_handler(void *cls,
- struct GNUNET_DNS_RequestHandle *rh,
- size_t request_length,
- const char *request)
+dns_post_request_handler (void *cls,
+ struct GNUNET_DNS_RequestHandle *rh,
+ size_t request_length,
+ const char *request)
{
struct GNUNET_DNSPARSER_Packet *dns;
struct ReplyContext *rc;
int work;
- GNUNET_STATISTICS_update(stats,
- gettext_noop("# DNS replies intercepted"),
- 1, GNUNET_NO);
- dns = GNUNET_DNSPARSER_parse(request,
- request_length);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS replies intercepted"),
+ 1, GNUNET_NO);
+ dns = GNUNET_DNSPARSER_parse (request,
+ request_length);
if (NULL == dns)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Failed to parse DNS request. Dropping.\n"));
- GNUNET_DNS_request_drop(rh);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to parse DNS request. Dropping.\n"));
+ GNUNET_DNS_request_drop (rh);
+ return;
+ }
work = GNUNET_NO;
- work |= work_test(dns->answers,
- dns->num_answers);
- work |= work_test(dns->authority_records,
- dns->num_authority_records);
- work |= work_test(dns->additional_records,
- dns->num_additional_records);
- if (!work)
- {
- GNUNET_DNS_request_forward(rh);
- GNUNET_DNSPARSER_free_packet(dns);
- return;
- }
- rc = GNUNET_new(struct ReplyContext);
+ work |= work_test (dns->answers,
+ dns->num_answers);
+ work |= work_test (dns->authority_records,
+ dns->num_authority_records);
+ work |= work_test (dns->additional_records,
+ dns->num_additional_records);
+ if (! work)
+ {
+ GNUNET_DNS_request_forward (rh);
+ GNUNET_DNSPARSER_free_packet (dns);
+ return;
+ }
+ rc = GNUNET_new (struct ReplyContext);
rc->rh = rh;
rc->dns = dns;
rc->offset = 0;
rc->group = ANSWERS;
- submit_request(rc);
+ submit_request (rc);
}
@@ -705,41 +710,41 @@ dns_post_request_handler(void *cls,
* @param cls the `struct RequestContext` to abort
*/
static void
-timeout_request(void *cls)
+timeout_request (void *cls)
{
struct RequestContext *rc = cls;
struct CadetExit *exit = rc->exit;
- GNUNET_STATISTICS_update(stats,
- gettext_noop("# DNS requests dropped (timeout)"),
- 1,
- GNUNET_NO);
- GNUNET_DNS_request_drop(rc->rh);
- GNUNET_free(rc);
- if ((0 == get_channel_weight(exit)) &&
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS requests dropped (timeout)"),
+ 1,
+ GNUNET_NO);
+ GNUNET_DNS_request_drop (rc->rh);
+ GNUNET_free (rc);
+ if ((0 == get_channel_weight (exit)) &&
(NULL == exit->receive_queue_head))
- {
- /* this straw broke the camel's back: this channel now has
- such a low score that it will not be used; close it! */
- GNUNET_CADET_channel_destroy(exit->cadet_channel);
- exit->cadet_channel = NULL;
- GNUNET_CONTAINER_DLL_remove(exit_head,
- exit_tail,
- exit);
- GNUNET_CONTAINER_DLL_insert_tail(exit_head,
- exit_tail,
- exit);
- /* go back to semi-innocent: mark as not great, but
- avoid a prohibitively negative score (see
- #get_channel_weight(), which checks for a certain
- minimum number of transmissions before making
- up an opinion) */
- exit->num_transmitted = 5;
- exit->num_answered = 0;
- dns_exit_available--;
- /* now try to open an alternative exit */
- try_open_exit();
- }
+ {
+ /* this straw broke the camel's back: this channel now has
+ such a low score that it will not be used; close it! */
+ GNUNET_CADET_channel_destroy (exit->cadet_channel);
+ exit->cadet_channel = NULL;
+ GNUNET_CONTAINER_DLL_remove (exit_head,
+ exit_tail,
+ exit);
+ GNUNET_CONTAINER_DLL_insert_tail (exit_head,
+ exit_tail,
+ exit);
+ /* go back to semi-innocent: mark as not great, but
+ avoid a prohibitively negative score (see
+ #get_channel_weight(), which checks for a certain
+ minimum number of transmissions before making
+ up an opinion) */
+ exit->num_transmitted = 5;
+ exit->num_answered = 0;
+ dns_exit_available--;
+ /* now try to open an alternative exit */
+ try_open_exit ();
+ }
}
@@ -755,10 +760,10 @@ timeout_request(void *cls)
* @param request udp payload of the DNS request
*/
static void
-dns_pre_request_handler(void *cls,
- struct GNUNET_DNS_RequestHandle *rh,
- size_t request_length,
- const char *request)
+dns_pre_request_handler (void *cls,
+ struct GNUNET_DNS_RequestHandle *rh,
+ size_t request_length,
+ const char *request)
{
struct RequestContext *rc;
struct GNUNET_MQ_Envelope *env;
@@ -766,54 +771,56 @@ dns_pre_request_handler(void *cls,
struct GNUNET_TUN_DnsHeader dns;
struct CadetExit *exit;
- GNUNET_STATISTICS_update(stats,
- gettext_noop("# DNS requests intercepted"),
- 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS requests intercepted"),
+ 1, GNUNET_NO);
if (0 == dns_exit_available)
- {
- GNUNET_STATISTICS_update(stats,
- gettext_noop("# DNS requests dropped (DNS cadet channel down)"),
- 1, GNUNET_NO);
- GNUNET_DNS_request_drop(rh);
- return;
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop (
+ "# DNS requests dropped (DNS cadet channel down)"),
+ 1, GNUNET_NO);
+ GNUNET_DNS_request_drop (rh);
+ return;
+ }
if (request_length < sizeof(dns))
- {
- GNUNET_STATISTICS_update(stats,
- gettext_noop("# DNS requests dropped (malformed)"),
- 1, GNUNET_NO);
- GNUNET_DNS_request_drop(rh);
- return;
- }
- exit = choose_exit();
- GNUNET_assert(NULL != exit);
- GNUNET_assert(NULL != exit->cadet_channel);
-
- env = GNUNET_MQ_msg_extra(hdr,
- request_length,
- GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET);
- GNUNET_memcpy(&hdr[1],
- request,
- request_length);
- rc = GNUNET_new(struct RequestContext);
+ {
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop (
+ "# DNS requests dropped (malformed)"),
+ 1, GNUNET_NO);
+ GNUNET_DNS_request_drop (rh);
+ return;
+ }
+ exit = choose_exit ();
+ GNUNET_assert (NULL != exit);
+ GNUNET_assert (NULL != exit->cadet_channel);
+
+ env = GNUNET_MQ_msg_extra (hdr,
+ request_length,
+ GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET);
+ GNUNET_memcpy (&hdr[1],
+ request,
+ request_length);
+ rc = GNUNET_new (struct RequestContext);
rc->exit = exit;
rc->rh = rh;
- rc->timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
- &timeout_request,
- rc);
- GNUNET_memcpy(&dns,
- request,
- sizeof(dns));
+ rc->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &timeout_request,
+ rc);
+ GNUNET_memcpy (&dns,
+ request,
+ sizeof(dns));
rc->dns_id = dns.id;
rc->env = env;
- GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head,
- exit->receive_queue_tail,
- rc);
+ GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head,
+ exit->receive_queue_tail,
+ rc);
if (0 < exit->idle)
exit->idle--;
exit->num_transmitted++;
- GNUNET_MQ_send(GNUNET_CADET_get_mq(exit->cadet_channel),
- GNUNET_MQ_env_copy(env));
+ GNUNET_MQ_send (GNUNET_CADET_get_mq (exit->cadet_channel),
+ GNUNET_MQ_env_copy (env));
}
@@ -822,7 +829,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
/**
* Message with a DNS response.
*/
-struct DnsResponseMessage {
+struct DnsResponseMessage
+{
/**
* GNUnet header, of type #GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET
*/
@@ -847,8 +855,8 @@ GNUNET_NETWORK_STRUCT_END
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
-check_dns_response(void *cls,
- const struct DnsResponseMessage *msg)
+check_dns_response (void *cls,
+ const struct DnsResponseMessage *msg)
{
return GNUNET_OK; /* all OK */
}
@@ -861,38 +869,38 @@ check_dns_response(void *cls,
* @param msg the actual message
*/
static void
-handle_dns_response(void *cls,
- const struct DnsResponseMessage *msg)
+handle_dns_response (void *cls,
+ const struct DnsResponseMessage *msg)
{
struct CadetExit *exit = cls;
size_t mlen;
struct RequestContext *rc;
- mlen = ntohs(msg->header.size) - sizeof(*msg);
+ mlen = ntohs (msg->header.size) - sizeof(*msg);
for (rc = exit->receive_queue_head; NULL != rc; rc = rc->next)
+ {
+ if (msg->dns.id == rc->dns_id)
{
- if (msg->dns.id == rc->dns_id)
- {
- GNUNET_STATISTICS_update(stats,
- gettext_noop("# DNS replies received"),
- 1,
- GNUNET_NO);
- GNUNET_DNS_request_answer(rc->rh,
- mlen + sizeof(struct GNUNET_TUN_DnsHeader),
- (const void*)&msg->dns);
- GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head,
- exit->receive_queue_tail,
- rc);
- GNUNET_SCHEDULER_cancel(rc->timeout_task);
- GNUNET_MQ_discard(rc->env);
- GNUNET_free(rc);
- exit->num_answered++;
- return;
- }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS replies received"),
+ 1,
+ GNUNET_NO);
+ GNUNET_DNS_request_answer (rc->rh,
+ mlen + sizeof(struct GNUNET_TUN_DnsHeader),
+ (const void*) &msg->dns);
+ GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head,
+ exit->receive_queue_tail,
+ rc);
+ GNUNET_SCHEDULER_cancel (rc->timeout_task);
+ GNUNET_MQ_discard (rc->env);
+ GNUNET_free (rc);
+ exit->num_answered++;
+ return;
}
- GNUNET_STATISTICS_update(stats,
- gettext_noop("# DNS replies dropped (too late?)"),
- 1, GNUNET_NO);
+ }
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS replies dropped (too late?)"),
+ 1, GNUNET_NO);
}
@@ -902,20 +910,20 @@ handle_dns_response(void *cls,
* @param exit cadet exit to abort requests for
*/
static void
-abort_all_requests(struct CadetExit *exit)
+abort_all_requests (struct CadetExit *exit)
{
struct RequestContext *rc;
while (NULL != (rc = exit->receive_queue_head))
- {
- GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head,
- exit->receive_queue_tail,
- rc);
- GNUNET_DNS_request_drop(rc->rh);
- GNUNET_SCHEDULER_cancel(rc->timeout_task);
- GNUNET_MQ_discard(rc->env);
- GNUNET_free(rc);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head,
+ exit->receive_queue_tail,
+ rc);
+ GNUNET_DNS_request_drop (rc->rh);
+ GNUNET_SCHEDULER_cancel (rc->timeout_task);
+ GNUNET_MQ_discard (rc->env);
+ GNUNET_free (rc);
+ }
}
@@ -925,60 +933,60 @@ abort_all_requests(struct CadetExit *exit)
* @param cls closure, NULL
*/
static void
-cleanup(void *cls)
+cleanup (void *cls)
{
struct CadetExit *exit;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Protocol translation daemon is shutting down now\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Protocol translation daemon is shutting down now\n");
if (NULL != vpn_handle)
- {
- GNUNET_VPN_disconnect(vpn_handle);
- vpn_handle = NULL;
- }
+ {
+ GNUNET_VPN_disconnect (vpn_handle);
+ vpn_handle = NULL;
+ }
while (NULL != (exit = exit_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (exit_head,
+ exit_tail,
+ exit);
+ if (NULL != exit->cadet_channel)
{
- GNUNET_CONTAINER_DLL_remove(exit_head,
- exit_tail,
- exit);
- if (NULL != exit->cadet_channel)
- {
- GNUNET_CADET_channel_destroy(exit->cadet_channel);
- exit->cadet_channel = NULL;
- }
- abort_all_requests(exit);
- GNUNET_free(exit);
+ GNUNET_CADET_channel_destroy (exit->cadet_channel);
+ exit->cadet_channel = NULL;
}
+ abort_all_requests (exit);
+ GNUNET_free (exit);
+ }
if (NULL != cadet_handle)
- {
- GNUNET_CADET_disconnect(cadet_handle);
- cadet_handle = NULL;
- }
+ {
+ GNUNET_CADET_disconnect (cadet_handle);
+ cadet_handle = NULL;
+ }
if (NULL != dns_post_handle)
- {
- GNUNET_DNS_disconnect(dns_post_handle);
- dns_post_handle = NULL;
- }
+ {
+ GNUNET_DNS_disconnect (dns_post_handle);
+ dns_post_handle = NULL;
+ }
if (NULL != dns_pre_handle)
- {
- GNUNET_DNS_disconnect(dns_pre_handle);
- dns_pre_handle = NULL;
- }
+ {
+ GNUNET_DNS_disconnect (dns_pre_handle);
+ dns_pre_handle = NULL;
+ }
if (NULL != stats)
- {
- GNUNET_STATISTICS_destroy(stats, GNUNET_YES);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ stats = NULL;
+ }
if (NULL != dht_get)
- {
- GNUNET_DHT_get_stop(dht_get);
- dht_get = NULL;
- }
+ {
+ GNUNET_DHT_get_stop (dht_get);
+ dht_get = NULL;
+ }
if (NULL != dht)
- {
- GNUNET_DHT_disconnect(dht);
- dht = NULL;
- }
+ {
+ GNUNET_DHT_disconnect (dht);
+ dht = NULL;
+ }
}
@@ -994,8 +1002,8 @@ cleanup(void *cls)
* with the channel is stored
*/
static void
-cadet_channel_end_cb(void *cls,
- const struct GNUNET_CADET_Channel *channel)
+cadet_channel_end_cb (void *cls,
+ const struct GNUNET_CADET_Channel *channel)
{
struct CadetExit *exit = cls;
struct CadetExit *alt;
@@ -1006,20 +1014,20 @@ cadet_channel_end_cb(void *cls,
/* open alternative channels */
/* our channel is now closed, move our requests to an alternative
channel */
- alt = choose_exit();
+ alt = choose_exit ();
while (NULL != (rc = exit->receive_queue_head))
- {
- GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head,
- exit->receive_queue_tail,
- rc);
- rc->exit = alt;
- GNUNET_CONTAINER_DLL_insert(alt->receive_queue_head,
- alt->receive_queue_tail,
- rc);
- GNUNET_MQ_send(GNUNET_CADET_get_mq(alt->cadet_channel),
- GNUNET_MQ_env_copy(rc->env));
- }
- try_open_exit();
+ {
+ GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head,
+ exit->receive_queue_tail,
+ rc);
+ rc->exit = alt;
+ GNUNET_CONTAINER_DLL_insert (alt->receive_queue_head,
+ alt->receive_queue_tail,
+ rc);
+ GNUNET_MQ_send (GNUNET_CADET_get_mq (alt->cadet_channel),
+ GNUNET_MQ_env_copy (rc->env));
+ }
+ try_open_exit ();
}
@@ -1031,9 +1039,9 @@ cadet_channel_end_cb(void *cls,
* @param window_size how much capacity do we have
*/
static void
-channel_idle_notify_cb(void *cls,
- const struct GNUNET_CADET_Channel *channel,
- int window_size)
+channel_idle_notify_cb (void *cls,
+ const struct GNUNET_CADET_Channel *channel,
+ int window_size)
{
struct CadetExit *pos = cls;
@@ -1045,69 +1053,69 @@ channel_idle_notify_cb(void *cls,
* We are short on cadet exits, try to open another one.
*/
static void
-try_open_exit()
+try_open_exit ()
{
struct CadetExit *pos;
uint32_t candidate_count;
uint32_t candidate_selected;
struct GNUNET_HashCode port;
- GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER,
- strlen(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER),
- &port);
+ GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER,
+ strlen (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER),
+ &port);
candidate_count = 0;
for (pos = exit_head; NULL != pos; pos = pos->next)
if (NULL == pos->cadet_channel)
candidate_count++;
if (0 == candidate_count)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "No DNS exits available yet.\n");
- return;
- }
- candidate_selected = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
- candidate_count);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "No DNS exits available yet.\n");
+ return;
+ }
+ candidate_selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ candidate_count);
candidate_count = 0;
for (pos = exit_head; NULL != pos; pos = pos->next)
if (NULL == pos->cadet_channel)
+ {
+ candidate_count++;
+ if (candidate_selected < candidate_count)
{
- candidate_count++;
- if (candidate_selected < candidate_count)
- {
- struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
- GNUNET_MQ_hd_var_size(dns_response,
- GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET,
- struct DnsResponseMessage,
- pos),
- GNUNET_MQ_handler_end()
- };
-
-
- /* move to the head of the DLL */
- pos->cadet_channel
- = GNUNET_CADET_channel_create(cadet_handle,
- pos,
- &pos->peer,
- &port,
- &channel_idle_notify_cb,
- &cadet_channel_end_cb,
- cadet_handlers);
- if (NULL == pos->cadet_channel)
- {
- GNUNET_break(0);
- continue;
- }
- GNUNET_CONTAINER_DLL_remove(exit_head,
- exit_tail,
- pos);
- GNUNET_CONTAINER_DLL_insert(exit_head,
- exit_tail,
- pos);
- dns_exit_available++;
- return;
- }
+ struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
+ GNUNET_MQ_hd_var_size (dns_response,
+ GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET,
+ struct DnsResponseMessage,
+ pos),
+ GNUNET_MQ_handler_end ()
+ };
+
+
+ /* move to the head of the DLL */
+ pos->cadet_channel
+ = GNUNET_CADET_channel_create (cadet_handle,
+ pos,
+ &pos->peer,
+ &port,
+ &channel_idle_notify_cb,
+ &cadet_channel_end_cb,
+ cadet_handlers);
+ if (NULL == pos->cadet_channel)
+ {
+ GNUNET_break (0);
+ continue;
+ }
+ GNUNET_CONTAINER_DLL_remove (exit_head,
+ exit_tail,
+ pos);
+ GNUNET_CONTAINER_DLL_insert (exit_head,
+ exit_tail,
+ pos);
+ dns_exit_available++;
+ return;
}
- GNUNET_assert(NULL == exit_head);
+ }
+ GNUNET_assert (NULL == exit_head);
}
@@ -1131,42 +1139,43 @@ try_open_exit()
* @param data pointer to the result data
*/
static void
-handle_dht_result(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,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type,
- size_t size, const void *data)
+handle_dht_result (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,
+ unsigned int put_path_length,
+ enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
{
const struct GNUNET_DNS_Advertisement *ad;
struct CadetExit *exit;
if (sizeof(struct GNUNET_DNS_Advertisement) != size)
- {
- GNUNET_break(0);
- return;
- }
+ {
+ GNUNET_break (0);
+ return;
+ }
ad = data;
for (exit = exit_head; NULL != exit; exit = exit->next)
- if (0 == GNUNET_memcmp(&ad->peer,
- &exit->peer))
+ if (0 == GNUNET_memcmp (&ad->peer,
+ &exit->peer))
break;
if (NULL == exit)
- {
- exit = GNUNET_new(struct CadetExit);
- exit->peer = ad->peer;
- /* channel is closed, so insert at the end */
- GNUNET_CONTAINER_DLL_insert_tail(exit_head,
- exit_tail,
- exit);
- }
- exit->expiration = GNUNET_TIME_absolute_max(exit->expiration,
- GNUNET_TIME_absolute_ntoh(ad->expiration_time));
+ {
+ exit = GNUNET_new (struct CadetExit);
+ exit->peer = ad->peer;
+ /* channel is closed, so insert at the end */
+ GNUNET_CONTAINER_DLL_insert_tail (exit_head,
+ exit_tail,
+ exit);
+ }
+ exit->expiration = GNUNET_TIME_absolute_max (exit->expiration,
+ GNUNET_TIME_absolute_ntoh (
+ ad->expiration_time));
if (dns_exit_available < MAX_OPEN_TUNNELS)
- try_open_exit();
+ try_open_exit ();
}
@@ -1179,102 +1188,102 @@ handle_dht_result(void *cls,
* @param cfg_ configuration
*/
static void
-run(void *cls, char *const *args GNUNET_UNUSED,
- const char *cfgfile GNUNET_UNUSED,
- const struct GNUNET_CONFIGURATION_Handle *cfg_)
+run (void *cls, char *const *args GNUNET_UNUSED,
+ const char *cfgfile GNUNET_UNUSED,
+ const struct GNUNET_CONFIGURATION_Handle *cfg_)
{
struct GNUNET_HashCode dns_key;
cfg = cfg_;
- stats = GNUNET_STATISTICS_create("pt",
- cfg);
- ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno(cfg,
- "pt",
- "TUNNEL_IPV4");
- ipv6_pt = GNUNET_CONFIGURATION_get_value_yesno(cfg,
- "pt",
- "TUNNEL_IPV6");
- dns_channel = GNUNET_CONFIGURATION_get_value_yesno(cfg,
- "pt",
- "TUNNEL_DNS");
- if (!(ipv4_pt || ipv6_pt || dns_channel))
+ stats = GNUNET_STATISTICS_create ("pt",
+ cfg);
+ ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "pt",
+ "TUNNEL_IPV4");
+ ipv6_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "pt",
+ "TUNNEL_IPV6");
+ dns_channel = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "pt",
+ "TUNNEL_DNS");
+ if (! (ipv4_pt || ipv6_pt || dns_channel))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("No useful service enabled. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_SCHEDULER_add_shutdown (&cleanup, cls);
+ if (ipv4_pt || ipv6_pt)
+ {
+ dns_post_handle
+ = GNUNET_DNS_connect (cfg,
+ GNUNET_DNS_FLAG_POST_RESOLUTION,
+ &dns_post_request_handler,
+ NULL);
+ if (NULL == dns_post_handle)
{
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("No useful service enabled. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to connect to %s service. Exiting.\n"),
+ "DNS");
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_shutdown(&cleanup, cls);
- if (ipv4_pt || ipv6_pt)
+ vpn_handle = GNUNET_VPN_connect (cfg);
+ if (NULL == vpn_handle)
{
- dns_post_handle
- = GNUNET_DNS_connect(cfg,
- GNUNET_DNS_FLAG_POST_RESOLUTION,
- &dns_post_request_handler,
- NULL);
- if (NULL == dns_post_handle)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to %s service. Exiting.\n"),
- "DNS");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- vpn_handle = GNUNET_VPN_connect(cfg);
- if (NULL == vpn_handle)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to %s service. Exiting.\n"),
- "VPN");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to connect to %s service. Exiting.\n"),
+ "VPN");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
}
+ }
if (dns_channel)
+ {
+ dns_pre_handle
+ = GNUNET_DNS_connect (cfg,
+ GNUNET_DNS_FLAG_PRE_RESOLUTION,
+ &dns_pre_request_handler,
+ NULL);
+ if (NULL == dns_pre_handle)
{
- dns_pre_handle
- = GNUNET_DNS_connect(cfg,
- GNUNET_DNS_FLAG_PRE_RESOLUTION,
- &dns_pre_request_handler,
- NULL);
- if (NULL == dns_pre_handle)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to %s service. Exiting.\n"),
- "DNS");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- cadet_handle = GNUNET_CADET_connect(cfg);
- if (NULL == cadet_handle)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to %s service. Exiting.\n"),
- "CADET");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- dht = GNUNET_DHT_connect(cfg, 1);
- if (NULL == dht)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to %s service. Exiting.\n"),
- "DHT");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- GNUNET_CRYPTO_hash("dns",
- strlen("dns"),
- &dns_key);
- dht_get = GNUNET_DHT_get_start(dht,
- GNUNET_BLOCK_TYPE_DNS,
- &dns_key,
- 1,
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, 0,
- &handle_dht_result,
- NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to connect to %s service. Exiting.\n"),
+ "DNS");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ cadet_handle = GNUNET_CADET_connect (cfg);
+ if (NULL == cadet_handle)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to connect to %s service. Exiting.\n"),
+ "CADET");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ dht = GNUNET_DHT_connect (cfg, 1);
+ if (NULL == dht)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to connect to %s service. Exiting.\n"),
+ "DHT");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
}
+ GNUNET_CRYPTO_hash ("dns",
+ strlen ("dns"),
+ &dns_key);
+ dht_get = GNUNET_DHT_get_start (dht,
+ GNUNET_BLOCK_TYPE_DNS,
+ &dns_key,
+ 1,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ NULL, 0,
+ &handle_dht_result,
+ NULL);
+ }
}
@@ -1286,30 +1295,31 @@ run(void *cls, char *const *args GNUNET_UNUSED,
* @return 0 ok, 1 on error
*/
int
-main(int argc,
- char *const *argv)
+main (int argc,
+ char *const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
int ret;
- 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-daemon-pt",
- gettext_noop("Daemon to run to perform IP protocol translation to GNUnet"),
- options,
- &run,
- NULL))
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-daemon-pt",
+ gettext_noop (
+ "Daemon to run to perform IP protocol translation to GNUnet"),
+ options,
+ &run,
+ NULL))
? 0
: 1;
- GNUNET_free((void*)argv);
+ GNUNET_free ((void*) argv);
return ret;
}
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c
index dbbdc830e..a51320eae 100644
--- a/src/pt/test_gns_vpn.c
+++ b/src/pt/test_gns_vpn.c
@@ -49,7 +49,7 @@
#define PORT 8080
#define TEST_DOMAIN "www.gnu"
-#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
/**
* Return value for #main().
@@ -96,7 +96,8 @@ static int src_af;
static int use_v6;
-struct CBC {
+struct CBC
+{
char buf[1024];
size_t pos;
};
@@ -105,102 +106,103 @@ static struct CBC cbc;
static size_t
-copy_buffer(void *ptr,
- size_t size,
- size_t nmemb,
- void *ctx)
+copy_buffer (void *ptr,
+ size_t size,
+ size_t nmemb,
+ void *ctx)
{
struct CBC *cbc = ctx;
if (cbc->pos + size * nmemb > sizeof(cbc->buf))
return 0; /* overflow */
- GNUNET_memcpy(&cbc->buf[cbc->pos], ptr, size * nmemb);
+ GNUNET_memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
cbc->pos += size * nmemb;
return size * nmemb;
}
static int
-mhd_ahc(void *cls,
- struct MHD_Connection *connection,
- const char *url,
- const char *method,
- const char *version,
- const char *upload_data, size_t *upload_data_size,
- void **unused)
+mhd_ahc (void *cls,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *version,
+ const char *upload_data, size_t *upload_data_size,
+ void **unused)
{
static int ptr;
struct MHD_Response *response;
int ret;
- if (0 != strcmp("GET", method))
+ if (0 != strcmp ("GET", method))
return MHD_NO; /* unexpected method */
if (&ptr != *unused)
- {
- *unused = &ptr;
- return MHD_YES;
- }
+ {
+ *unused = &ptr;
+ return MHD_YES;
+ }
*unused = NULL;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url);
- response = MHD_create_response_from_buffer(strlen(url),
- (void *)url,
- MHD_RESPMEM_MUST_COPY);
- ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
- MHD_destroy_response(response);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MHD sends respose for request to URL `%s'\n", url);
+ response = MHD_create_response_from_buffer (strlen (url),
+ (void *) url,
+ MHD_RESPMEM_MUST_COPY);
+ ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
+ MHD_destroy_response (response);
if (ret == MHD_NO)
- abort();
+ abort ();
return ret;
}
static void
-do_shutdown(void *cls)
+do_shutdown (void *cls)
{
if (NULL != mhd_task_id)
- {
- GNUNET_SCHEDULER_cancel(mhd_task_id);
- mhd_task_id = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (mhd_task_id);
+ mhd_task_id = NULL;
+ }
if (NULL != curl_task_id)
- {
- GNUNET_SCHEDULER_cancel(curl_task_id);
- curl_task_id = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (curl_task_id);
+ curl_task_id = NULL;
+ }
if (NULL != timeout_task)
- {
- GNUNET_SCHEDULER_cancel(timeout_task);
- timeout_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (timeout_task);
+ timeout_task = NULL;
+ }
if (NULL != mhd)
- {
- MHD_stop_daemon(mhd);
- mhd = NULL;
- }
+ {
+ MHD_stop_daemon (mhd);
+ mhd = NULL;
+ }
if (NULL != identity)
- {
- GNUNET_IDENTITY_disconnect(identity);
- identity = NULL;
- }
+ {
+ GNUNET_IDENTITY_disconnect (identity);
+ identity = NULL;
+ }
if (NULL != qe)
- {
- GNUNET_NAMESTORE_cancel(qe);
- qe = NULL;
- }
+ {
+ GNUNET_NAMESTORE_cancel (qe);
+ qe = NULL;
+ }
if (NULL != namestore)
- {
- GNUNET_NAMESTORE_disconnect(namestore);
- namestore = NULL;
- }
- GNUNET_free_non_null(url);
+ {
+ GNUNET_NAMESTORE_disconnect (namestore);
+ namestore = NULL;
+ }
+ GNUNET_free_non_null (url);
url = NULL;
}
static void
-do_timeout(void *cls)
+do_timeout (void *cls)
{
timeout_task = NULL;
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -208,19 +210,19 @@ do_timeout(void *cls)
* Function to run the HTTP client.
*/
static void
-curl_main(void);
+curl_main (void);
static void
-curl_task(void *cls)
+curl_task (void *cls)
{
curl_task_id = NULL;
- curl_main();
+ curl_main ();
}
static void
-curl_main()
+curl_main ()
{
fd_set rs;
fd_set ws;
@@ -234,102 +236,103 @@ curl_main()
struct CURLMsg *msg;
max = 0;
- FD_ZERO(&rs);
- FD_ZERO(&ws);
- FD_ZERO(&es);
- curl_multi_perform(multi, &running);
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
+ curl_multi_perform (multi, &running);
if (running == 0)
+ {
+ GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running)));
+ if (msg->msg == CURLMSG_DONE)
{
- GNUNET_assert(NULL != (msg = curl_multi_info_read(multi, &running)));
- if (msg->msg == CURLMSG_DONE)
- {
- if (msg->data.result != CURLE_OK)
- {
- fprintf(stderr,
- "%s failed at %s:%d: `%s'\n",
- "curl_multi_perform",
- __FILE__,
- __LINE__, curl_easy_strerror(msg->data.result));
- global_ret = 1;
- }
- }
- curl_multi_remove_handle(multi, curl);
- curl_multi_cleanup(multi);
- curl_easy_cleanup(curl);
- curl = NULL;
- multi = NULL;
- if (cbc.pos != strlen("/hello_world"))
- {
- GNUNET_break(0);
- global_ret = 2;
- }
- if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world")))
- {
- GNUNET_break(0);
- global_ret = 3;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Download complete, shutting down!\n");
- GNUNET_SCHEDULER_shutdown();
- return;
+ if (msg->data.result != CURLE_OK)
+ {
+ fprintf (stderr,
+ "%s failed at %s:%d: `%s'\n",
+ "curl_multi_perform",
+ __FILE__,
+ __LINE__, curl_easy_strerror (msg->data.result));
+ global_ret = 1;
+ }
+ }
+ curl_multi_remove_handle (multi, curl);
+ curl_multi_cleanup (multi);
+ curl_easy_cleanup (curl);
+ curl = NULL;
+ multi = NULL;
+ if (cbc.pos != strlen ("/hello_world"))
+ {
+ GNUNET_break (0);
+ global_ret = 2;
+ }
+ if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
+ {
+ GNUNET_break (0);
+ global_ret = 3;
}
- GNUNET_assert(CURLM_OK == curl_multi_fdset(multi, &rs, &ws, &es, &max));
- if ((CURLM_OK != curl_multi_timeout(multi, &timeout)) ||
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Download complete, shutting down!\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max));
+ if ((CURLM_OK != curl_multi_timeout (multi, &timeout)) ||
(-1 == timeout))
delay = GNUNET_TIME_UNIT_SECONDS;
else
- delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int)timeout);
- GNUNET_NETWORK_fdset_copy_native(&nrs,
- &rs,
- max + 1);
- GNUNET_NETWORK_fdset_copy_native(&nws,
- &ws,
- max + 1);
- curl_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- delay,
- &nrs,
- &nws,
- &curl_task,
- NULL);
+ delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ (unsigned int) timeout);
+ GNUNET_NETWORK_fdset_copy_native (&nrs,
+ &rs,
+ max + 1);
+ GNUNET_NETWORK_fdset_copy_native (&nws,
+ &ws,
+ max + 1);
+ curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ delay,
+ &nrs,
+ &nws,
+ &curl_task,
+ NULL);
}
static void
-start_curl(void *cls)
+start_curl (void *cls)
{
CURLcode ec;
curl_task_id = NULL;
- GNUNET_asprintf(&url,
- "http://%s/hello_world",
- TEST_DOMAIN);
- curl = curl_easy_init();
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cbc);
- curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 150L);
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 150L);
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+ GNUNET_asprintf (&url,
+ "http://%s/hello_world",
+ TEST_DOMAIN);
+ curl = curl_easy_init ();
+ curl_easy_setopt (curl, CURLOPT_URL, url);
+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc);
+ curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L);
+ curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 150L);
+ curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
if (CURLE_OK !=
- (ec = curl_easy_setopt(curl,
- CURLOPT_DNS_SERVERS,
- "127.0.0.1:53")))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "curl build without support for CURLOPT_DNS_SERVERS (%s), cannot run test\n",
- curl_easy_strerror(ec));
- global_ret = 77;
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- multi = curl_multi_init();
- GNUNET_assert(multi != NULL);
- GNUNET_assert(CURLM_OK == curl_multi_add_handle(multi, curl));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Beginning HTTP download from `%s'\n",
- url);
- curl_main();
+ (ec = curl_easy_setopt (curl,
+ CURLOPT_DNS_SERVERS,
+ "127.0.0.1:53")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "curl build without support for CURLOPT_DNS_SERVERS (%s), cannot run test\n",
+ curl_easy_strerror (ec));
+ global_ret = 77;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ multi = curl_multi_init ();
+ GNUNET_assert (multi != NULL);
+ GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Beginning HTTP download from `%s'\n",
+ url);
+ curl_main ();
}
@@ -346,28 +349,28 @@ start_curl(void *cls)
* specified target peer; NULL on error
*/
static void
-commence_testing(void *cls,
- int32_t success,
- const char *emsg)
+commence_testing (void *cls,
+ int32_t success,
+ const char *emsg)
{
qe = NULL;
if ((NULL != emsg) &&
(GNUNET_YES != success))
- {
- fprintf(stderr,
- "NS failed to create record %s\n",
- emsg);
- GNUNET_SCHEDULER_shutdown();
- return;
- }
+ {
+ fprintf (stderr,
+ "NS failed to create record %s\n",
+ emsg);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
/* wait a little bit before downloading, as we just created the record */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Launching cURL request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Launching cURL request\n");
curl_task_id
- = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
- &start_curl,
- NULL);
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &start_curl,
+ NULL);
}
@@ -375,20 +378,20 @@ commence_testing(void *cls,
* Function to keep the HTTP server running.
*/
static void
-mhd_main(void);
+mhd_main (void);
static void
-mhd_task(void *cls)
+mhd_task (void *cls)
{
mhd_task_id = NULL;
- MHD_run(mhd);
- mhd_main();
+ MHD_run (mhd);
+ mhd_main ();
}
static void
-mhd_main()
+mhd_main ()
{
struct GNUNET_NETWORK_FDSet nrs;
struct GNUNET_NETWORK_FDSet nws;
@@ -399,30 +402,30 @@ mhd_main()
unsigned MHD_LONG_LONG timeout;
struct GNUNET_TIME_Relative delay;
- GNUNET_assert(NULL == mhd_task_id);
- FD_ZERO(&rs);
- FD_ZERO(&ws);
- FD_ZERO(&es);
+ GNUNET_assert (NULL == mhd_task_id);
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
max_fd = -1;
- GNUNET_assert(MHD_YES ==
- MHD_get_fdset(mhd, &rs, &ws, &es, &max_fd));
- if (MHD_YES == MHD_get_timeout(mhd, &timeout))
- delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
- (unsigned int)timeout);
+ GNUNET_assert (MHD_YES ==
+ MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd));
+ if (MHD_YES == MHD_get_timeout (mhd, &timeout))
+ delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ (unsigned int) timeout);
else
delay = GNUNET_TIME_UNIT_FOREVER_REL;
- GNUNET_NETWORK_fdset_copy_native(&nrs,
- &rs,
- max_fd + 1);
- GNUNET_NETWORK_fdset_copy_native(&nws,
- &ws,
- max_fd + 1);
- mhd_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- delay,
- &nrs,
- &nws,
- &mhd_task,
- NULL);
+ GNUNET_NETWORK_fdset_copy_native (&nrs,
+ &rs,
+ max_fd + 1);
+ GNUNET_NETWORK_fdset_copy_native (&nws,
+ &ws,
+ max_fd + 1);
+ mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ delay,
+ &nrs,
+ &nws,
+ &mhd_task,
+ NULL);
}
@@ -435,22 +438,22 @@ mhd_main()
* @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);
+ fd = open ("/dev/null", flags);
if (-1 == fd)
- abort();
+ abort ();
if (fd == target_fd)
return;
- if (-1 == dup2(fd, target_fd))
- {
- (void)close(fd);
- abort();
- }
- (void)close(fd);
+ if (-1 == dup2 (fd, target_fd))
+ {
+ (void) close (fd);
+ abort ();
+ }
+ (void) close (fd);
}
@@ -462,56 +465,56 @@ open_dev_null(int target_fd,
* @return 0 on success, 1 on any error
*/
static int
-fork_and_exec(const char *file,
- char *const cmd[])
+fork_and_exec (const char *file,
+ char *const cmd[])
{
int status;
pid_t pid;
pid_t ret;
- pid = fork();
+ pid = fork ();
if (-1 == pid)
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
- "fork");
- return 1;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "fork");
+ return 1;
+ }
if (0 == pid)
- {
- /* we are the child process */
- /* close stdin/stdout to not cause interference
- with the helper's main protocol! */
- (void)close(0);
- open_dev_null(0, O_RDONLY);
- (void)close(1);
- open_dev_null(1, O_WRONLY);
- (void)execv(file, cmd);
- /* can only get here on error */
- GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR,
- "exec",
- file);
- _exit(1);
- }
+ {
+ /* we are the child process */
+ /* close stdin/stdout to not cause interference
+ with the helper's main protocol! */
+ (void) close (0);
+ open_dev_null (0, O_RDONLY);
+ (void) close (1);
+ open_dev_null (1, O_WRONLY);
+ (void) execv (file, cmd);
+ /* can only get here on error */
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "exec",
+ file);
+ _exit (1);
+ }
/* keep running waitpid as long as the only error we get is 'EINTR' */
- while ((-1 == (ret = waitpid(pid, &status, 0))) &&
+ while ((-1 == (ret = waitpid (pid, &status, 0))) &&
(errno == EINTR))
;
if (-1 == ret)
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
- "waitpid");
- return 1;
- }
- if (!(WIFEXITED(status) &&
- (0 == WEXITSTATUS(status))))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Process `%s` returned status code %d/%d.\n",
- file,
- WIFEXITED(status),
- WEXITSTATUS(status));
- return 1;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "waitpid");
+ return 1;
+ }
+ if (! (WIFEXITED (status) &&
+ (0 == WEXITSTATUS (status))))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Process `%s` returned status code %d/%d.\n",
+ file,
+ WIFEXITED (status),
+ WEXITSTATUS (status));
+ return 1;
+ }
/* child process completed and returned success, we're happy */
return 0;
}
@@ -553,10 +556,10 @@ fork_and_exec(const char *file,
* must thus no longer be used
*/
static void
-identity_cb(void *cls,
- struct GNUNET_IDENTITY_Ego *ego,
- void **ctx,
- const char *name)
+identity_cb (void *cls,
+ struct GNUNET_IDENTITY_Ego *ego,
+ void **ctx,
+ const char *name)
{
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key;
struct GNUNET_GNSRECORD_Data rd;
@@ -566,59 +569,59 @@ identity_cb(void *cls,
if (NULL == name)
return;
if (NULL == ego)
+ {
+ if (NULL == qe)
{
- if (NULL == qe)
- {
- fprintf(stderr,
- "Failed to find master-zone ego\n");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- GNUNET_IDENTITY_disconnect(identity);
- identity = NULL;
- return;
- }
- GNUNET_assert(NULL != name);
- if (0 != strcmp(name,
- "master-zone"))
- {
- fprintf(stderr,
- "Unexpected name %s\n",
- name);
+ fprintf (stderr,
+ "Failed to find master-zone ego\n");
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- zone_key = GNUNET_IDENTITY_ego_get_private_key(ego);
+ GNUNET_IDENTITY_disconnect (identity);
+ identity = NULL;
+ return;
+ }
+ GNUNET_assert (NULL != name);
+ if (0 != strcmp (name,
+ "master-zone"))
+ {
+ fprintf (stderr,
+ "Unexpected name %s\n",
+ name);
+ return;
+ }
+ zone_key = GNUNET_IDENTITY_ego_get_private_key (ego);
rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
- peername = GNUNET_strdup(GNUNET_i2s_full(&id));
- GNUNET_asprintf(&rd_string,
- "6 %s %s",
- peername,
- "www");
- GNUNET_free(peername);
- GNUNET_assert(GNUNET_OK ==
- GNUNET_GNSRECORD_string_to_value(GNUNET_GNSRECORD_TYPE_VPN,
- rd_string,
- (void**)&rd.data,
- &rd.data_size));
+ peername = GNUNET_strdup (GNUNET_i2s_full (&id));
+ GNUNET_asprintf (&rd_string,
+ "6 %s %s",
+ peername,
+ "www");
+ GNUNET_free (peername);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_GNSRECORD_string_to_value (GNUNET_GNSRECORD_TYPE_VPN,
+ rd_string,
+ (void**) &rd.data,
+ &rd.data_size));
rd.record_type = GNUNET_GNSRECORD_TYPE_VPN;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Creating `www` record\n");
- qe = GNUNET_NAMESTORE_records_store(namestore,
- zone_key,
- "www",
- 1, &rd,
- &commence_testing,
- NULL);
- GNUNET_free((void**)rd.data);
- GNUNET_free(rd_string);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating `www` record\n");
+ qe = GNUNET_NAMESTORE_records_store (namestore,
+ zone_key,
+ "www",
+ 1, &rd,
+ &commence_testing,
+ NULL);
+ GNUNET_free ((void**) rd.data);
+ GNUNET_free (rd_string);
}
static void
-run(void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Peer *peer)
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
{
enum MHD_FLAG flags;
@@ -628,239 +631,235 @@ run(void *cls,
char *bin_arm;
char *config;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Test logic starting...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test logic starting...\n");
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string(cfg,
- "arm",
- "CONFIG",
- &config))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to locate configuration file. Skipping test.\n");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
-
- char *const identity_args[] =
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "arm",
+ "CONFIG",
+ &config))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to locate configuration file. Skipping test.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
+ char *const identity_args[] = {
"gnunet-identity",
"-C", "master-zone",
"-c", config,
NULL
};
- char *const identity2_args[] =
- {
+ char *const identity2_args[] = {
"gnunet-identity",
"-e", "master-zone",
"-s", "gns-master",
"-c", config,
NULL
};
- char *const identity3_args[] =
- {
+ char *const identity3_args[] = {
"gnunet-identity",
"-e", "master-zone",
"-s", "dns2gns",
"-c", config,
NULL
};
- char *const arm_args[] =
- {
+ char *const arm_args[] = {
"gnunet-arm",
"-i", "dns2gns",
"-c", config,
NULL
};
- char *const gns_args[] =
- {
+ char *const gns_args[] = {
"gnunet-gns",
"-u", "www.gnu",
"-c", config,
NULL
};
- GNUNET_TESTING_peer_get_identity(peer,
- &id);
- GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
- NULL);
- timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
- &do_timeout,
- NULL);
- bin = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_BINDIR);
- GNUNET_asprintf(&bin_identity,
- "%s/%s",
- bin,
- "gnunet-identity");
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Creating `master-zone` ego\n");
- if (0 != fork_and_exec(bin_identity, identity_args))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `gnunet-identity -C`. Skipping test.\n");
- GNUNET_SCHEDULER_shutdown();
- GNUNET_free(bin_identity);
- GNUNET_free(config);
- GNUNET_free(bin);
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Setting `master-zone` ego as default for `gns-master` and `dns2gns`\n");
- if (0 != fork_and_exec(bin_identity, identity2_args))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `gnunet-identity -e`. Skipping test.\n");
- GNUNET_SCHEDULER_shutdown();
- GNUNET_free(bin_identity);
- GNUNET_free(config);
- GNUNET_free(bin);
- return;
- }
- if (0 != fork_and_exec(bin_identity, identity3_args))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `gnunet-identity -e`. Skipping test.\n");
- GNUNET_SCHEDULER_shutdown();
- GNUNET_free(bin_identity);
- GNUNET_free(config);
- GNUNET_free(bin);
- return;
- }
- GNUNET_free(bin_identity);
+ GNUNET_TESTING_peer_get_identity (peer,
+ &id);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &do_timeout,
+ NULL);
+ bin = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
+ GNUNET_asprintf (&bin_identity,
+ "%s/%s",
+ bin,
+ "gnunet-identity");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating `master-zone` ego\n");
+ if (0 != fork_and_exec (bin_identity, identity_args))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run `gnunet-identity -C`. Skipping test.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (bin_identity);
+ GNUNET_free (config);
+ GNUNET_free (bin);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Setting `master-zone` ego as default for `gns-master` and `dns2gns`\n");
+ if (0 != fork_and_exec (bin_identity, identity2_args))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run `gnunet-identity -e`. Skipping test.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (bin_identity);
+ GNUNET_free (config);
+ GNUNET_free (bin);
+ return;
+ }
+ if (0 != fork_and_exec (bin_identity, identity3_args))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run `gnunet-identity -e`. Skipping test.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (bin_identity);
+ GNUNET_free (config);
+ GNUNET_free (bin);
+ return;
+ }
+ GNUNET_free (bin_identity);
/* do lookup just to launch GNS service */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Resolving `www.gnu` zone entry to launch GNS (will yield no answer yet)\n");
- GNUNET_asprintf(&bin_gns,
- "%s/%s",
- bin,
- "gnunet-gns");
- if (0 != fork_and_exec(bin_gns,
- gns_args))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `gnunet-gns -u. Skipping test.\n");
- GNUNET_SCHEDULER_shutdown();
- GNUNET_free(bin_gns);
- GNUNET_free(config);
- GNUNET_free(bin);
- return;
- }
- GNUNET_free(bin_gns);
-
- GNUNET_asprintf(&bin_arm,
- "%s/%s",
- bin,
- "gnunet-arm");
- if (0 != fork_and_exec(bin_arm,
- arm_args))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `gnunet-arm -i dns2gns. Skipping test.\n");
- GNUNET_SCHEDULER_shutdown();
- GNUNET_free(bin_arm);
- GNUNET_free(config);
- GNUNET_free(bin);
- return;
- }
- GNUNET_free(bin_arm);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Resolving `www.gnu` zone entry to launch GNS (will yield no answer yet)\n");
+ GNUNET_asprintf (&bin_gns,
+ "%s/%s",
+ bin,
+ "gnunet-gns");
+ if (0 != fork_and_exec (bin_gns,
+ gns_args))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run `gnunet-gns -u. Skipping test.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (bin_gns);
+ GNUNET_free (config);
+ GNUNET_free (bin);
+ return;
+ }
+ GNUNET_free (bin_gns);
+
+ GNUNET_asprintf (&bin_arm,
+ "%s/%s",
+ bin,
+ "gnunet-arm");
+ if (0 != fork_and_exec (bin_arm,
+ arm_args))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run `gnunet-arm -i dns2gns. Skipping test.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (bin_arm);
+ GNUNET_free (config);
+ GNUNET_free (bin);
+ return;
+ }
+ GNUNET_free (bin_arm);
- GNUNET_free(config);
- GNUNET_free(bin);
- sleep(1); /* give dns2gns chance to really run */
+ GNUNET_free (config);
+ GNUNET_free (bin);
+ sleep (1); /* give dns2gns chance to really run */
- namestore = GNUNET_NAMESTORE_connect(cfg);
- GNUNET_assert(NULL != namestore);
+ namestore = GNUNET_NAMESTORE_connect (cfg);
+ GNUNET_assert (NULL != namestore);
flags = MHD_USE_DEBUG;
if (GNUNET_YES == use_v6)
flags |= MHD_USE_DUAL_STACK;
- mhd = MHD_start_daemon(flags,
- PORT,
- NULL, NULL,
- &mhd_ahc, NULL,
- MHD_OPTION_END);
- GNUNET_assert(NULL != mhd);
- mhd_main();
-
- identity = GNUNET_IDENTITY_connect(cfg,
- &identity_cb,
- NULL);
+ mhd = MHD_start_daemon (flags,
+ PORT,
+ NULL, NULL,
+ &mhd_ahc, NULL,
+ MHD_OPTION_END);
+ GNUNET_assert (NULL != mhd);
+ mhd_main ();
+
+ identity = GNUNET_IDENTITY_connect (cfg,
+ &identity_cb,
+ NULL);
}
int
-main(int argc,
- char *const *argv)
+main (int argc,
+ char *const *argv)
{
char *bin_vpn;
char *bin_exit;
- GNUNET_log_setup("test-gns-vpn",
- "WARNING",
- NULL);
- if (0 != access("/dev/net/tun", R_OK))
- {
- GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR,
- "access",
- "/dev/net/tun");
- fprintf(stderr,
- "WARNING: System unable to run test, skipping.\n");
- return 77;
- }
-
- bin_vpn = GNUNET_OS_get_libexec_binary_path("gnunet-helper-vpn");
- bin_exit = GNUNET_OS_get_libexec_binary_path("gnunet-helper-exit");
- if ((0 != geteuid()) &&
+ GNUNET_log_setup ("test-gns-vpn",
+ "WARNING",
+ NULL);
+ if (0 != access ("/dev/net/tun", R_OK))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "access",
+ "/dev/net/tun");
+ fprintf (stderr,
+ "WARNING: System unable to run test, skipping.\n");
+ return 77;
+ }
+
+ bin_vpn = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
+ bin_exit = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit");
+ if ((0 != geteuid ()) &&
((GNUNET_YES !=
- GNUNET_OS_check_helper_binary(bin_vpn,
- GNUNET_YES,
- "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) || //ipv4 only please!
+ GNUNET_OS_check_helper_binary (bin_vpn,
+ GNUNET_YES,
+ "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))
+ || // ipv4 only please!
(GNUNET_YES !=
- GNUNET_OS_check_helper_binary(bin_exit,
- GNUNET_YES,
- "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only
- {
- fprintf(stderr,
- "WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n");
- fprintf(stderr,
- "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
- GNUNET_free(bin_vpn);
- GNUNET_free(bin_exit);
- return 77;
- }
- GNUNET_free(bin_vpn);
- GNUNET_free(bin_exit);
+ GNUNET_OS_check_helper_binary (bin_exit,
+ GNUNET_YES,
+ "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) // no nat, ipv4 only
+ {
+ fprintf (stderr,
+ "WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n");
+ fprintf (stderr,
+ "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
+ GNUNET_free (bin_vpn);
+ GNUNET_free (bin_exit);
+ return 77;
+ }
+ GNUNET_free (bin_vpn);
+ GNUNET_free (bin_exit);
dest_ip = "169.254.86.1";
dest_af = AF_INET;
src_af = AF_INET;
- if (GNUNET_OK == GNUNET_NETWORK_test_pf(PF_INET6))
+ if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
use_v6 = GNUNET_YES;
else
use_v6 = GNUNET_NO;
- if ((GNUNET_OK != GNUNET_NETWORK_test_pf(src_af)) ||
- (GNUNET_OK != GNUNET_NETWORK_test_pf(dest_af)))
- {
- fprintf(stderr,
- "Required address families not supported by this system, skipping test.\n");
- return 77;
- }
- if (0 != curl_global_init(CURL_GLOBAL_WIN32))
- {
- fprintf(stderr, "failed to initialize curl\n");
- return 2;
- }
+ if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
+ (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)))
+ {
+ fprintf (stderr,
+ "Required address families not supported by this system, skipping test.\n");
+ return 77;
+ }
+ if (0 != curl_global_init (CURL_GLOBAL_WIN32))
+ {
+ fprintf (stderr, "failed to initialize curl\n");
+ return 2;
+ }
if (0 !=
- GNUNET_TESTING_peer_run("test_gns_vpn",
- "test_gns_vpn.conf",
- &run,
- NULL))
+ GNUNET_TESTING_peer_run ("test_gns_vpn",
+ "test_gns_vpn.conf",
+ &run,
+ NULL))
return 1;
- GNUNET_DISK_directory_remove("/tmp/gnunet-test-vpn");
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn");
return global_ret;
}
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c
index c52c0c6c9..dcf3c5d93 100644
--- a/src/pt/test_gnunet_vpn.c
+++ b/src/pt/test_gnunet_vpn.c
@@ -32,7 +32,7 @@
#define PORT 48080
-#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
/**
@@ -74,7 +74,8 @@ static int dest_af;
static int src_af;
-struct CBC {
+struct CBC
+{
char buf[1024];
size_t pos;
};
@@ -83,87 +84,87 @@ static struct CBC cbc;
static size_t
-copy_buffer(void *ptr, size_t size, size_t nmemb, void *ctx)
+copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
{
struct CBC *cbc = ctx;
if (cbc->pos + size * nmemb > sizeof(cbc->buf))
return 0; /* overflow */
- GNUNET_memcpy(&cbc->buf[cbc->pos], ptr, size * nmemb);
+ GNUNET_memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
cbc->pos += size * nmemb;
return size * nmemb;
}
static int
-mhd_ahc(void *cls,
- struct MHD_Connection *connection,
- const char *url,
- const char *method,
- const char *version,
- const char *upload_data,
- size_t * upload_data_size,
- void **unused)
+mhd_ahc (void *cls,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *version,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **unused)
{
static int ptr;
struct MHD_Response *response;
int ret;
- if (0 != strcmp("GET", method))
+ if (0 != strcmp ("GET", method))
return MHD_NO; /* unexpected method */
if (&ptr != *unused)
- {
- *unused = &ptr;
- return MHD_YES;
- }
+ {
+ *unused = &ptr;
+ return MHD_YES;
+ }
*unused = NULL;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "MHD sends respose for request to URL `%s'\n", url);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MHD sends respose for request to URL `%s'\n", url);
response =
- MHD_create_response_from_buffer(strlen(url), (void *)url,
- MHD_RESPMEM_MUST_COPY);
- ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
- MHD_destroy_response(response);
+ MHD_create_response_from_buffer (strlen (url), (void *) url,
+ MHD_RESPMEM_MUST_COPY);
+ ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
+ MHD_destroy_response (response);
if (ret == MHD_NO)
- abort();
+ abort ();
return ret;
}
static void
-do_shutdown(void *cls)
+do_shutdown (void *cls)
{
if (NULL != mhd_task_id)
- {
- GNUNET_SCHEDULER_cancel(mhd_task_id);
- mhd_task_id = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (mhd_task_id);
+ mhd_task_id = NULL;
+ }
if (NULL != curl_task_id)
- {
- GNUNET_SCHEDULER_cancel(curl_task_id);
- curl_task_id = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (curl_task_id);
+ curl_task_id = NULL;
+ }
if (NULL != timeout_task_id)
- {
- GNUNET_SCHEDULER_cancel(timeout_task_id);
- timeout_task_id = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (timeout_task_id);
+ timeout_task_id = NULL;
+ }
if (NULL != mhd)
- {
- MHD_stop_daemon(mhd);
- mhd = NULL;
- }
+ {
+ MHD_stop_daemon (mhd);
+ mhd = NULL;
+ }
if (NULL != rr)
- {
- GNUNET_VPN_cancel_request(rr);
- rr = NULL;
- }
+ {
+ GNUNET_VPN_cancel_request (rr);
+ rr = NULL;
+ }
if (NULL != vpn)
- {
- GNUNET_VPN_disconnect(vpn);
- vpn = NULL;
- }
- GNUNET_free_non_null(url);
+ {
+ GNUNET_VPN_disconnect (vpn);
+ vpn = NULL;
+ }
+ GNUNET_free_non_null (url);
url = NULL;
}
@@ -172,7 +173,7 @@ do_shutdown(void *cls)
* Function to run the HTTP client.
*/
static void
-curl_main(void *cls)
+curl_main (void *cls)
{
fd_set rs;
fd_set ws;
@@ -187,55 +188,55 @@ curl_main(void *cls)
curl_task_id = NULL;
max = 0;
- FD_ZERO(&rs);
- FD_ZERO(&ws);
- FD_ZERO(&es);
- curl_multi_perform(multi, &running);
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
+ curl_multi_perform (multi, &running);
if (running == 0)
+ {
+ GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running)));
+ if (msg->msg == CURLMSG_DONE)
+ {
+ if (msg->data.result != CURLE_OK)
+ {
+ fprintf (stderr, "%s failed at %s:%d: `%s'\n", "curl_multi_perform",
+ __FILE__, __LINE__, curl_easy_strerror (msg->data.result));
+ global_ret = 1;
+ }
+ }
+ curl_multi_remove_handle (multi, curl);
+ curl_multi_cleanup (multi);
+ curl_easy_cleanup (curl);
+ curl = NULL;
+ multi = NULL;
+ if (cbc.pos != strlen ("/hello_world"))
+ {
+ GNUNET_break (0);
+ global_ret = 2;
+ }
+ if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
{
- GNUNET_assert(NULL != (msg = curl_multi_info_read(multi, &running)));
- if (msg->msg == CURLMSG_DONE)
- {
- if (msg->data.result != CURLE_OK)
- {
- fprintf(stderr, "%s failed at %s:%d: `%s'\n", "curl_multi_perform",
- __FILE__, __LINE__, curl_easy_strerror(msg->data.result));
- global_ret = 1;
- }
- }
- curl_multi_remove_handle(multi, curl);
- curl_multi_cleanup(multi);
- curl_easy_cleanup(curl);
- curl = NULL;
- multi = NULL;
- if (cbc.pos != strlen("/hello_world"))
- {
- GNUNET_break(0);
- global_ret = 2;
- }
- if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world")))
- {
- GNUNET_break(0);
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "You might want to check if your host-based firewall is blocking the connections.\n");
- global_ret = 3;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n");
- GNUNET_SCHEDULER_shutdown();
- return;
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "You might want to check if your host-based firewall is blocking the connections.\n");
+ global_ret = 3;
}
- GNUNET_assert(CURLM_OK == curl_multi_fdset(multi, &rs, &ws, &es, &max));
- if ((CURLM_OK != curl_multi_timeout(multi, &timeout)) || (-1 == timeout))
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max));
+ if ((CURLM_OK != curl_multi_timeout (multi, &timeout)) || (-1 == timeout))
delay = GNUNET_TIME_UNIT_SECONDS;
else
delay =
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
- (unsigned int)timeout);
- GNUNET_NETWORK_fdset_copy_native(&nrs, &rs, max + 1);
- GNUNET_NETWORK_fdset_copy_native(&nws, &ws, max + 1);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ (unsigned int) timeout);
+ GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max + 1);
+ GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max + 1);
curl_task_id =
- GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay,
- &nrs, &nws, &curl_main, NULL);
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay,
+ &nrs, &nws, &curl_main, NULL);
}
@@ -253,53 +254,53 @@ curl_main(void *cls)
* 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 ips[INET6_ADDRSTRLEN];
rr = NULL;
if (src_af != af)
- {
- fprintf(stderr,
- "VPN failed to allocate appropriate address\n");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
+ {
+ fprintf (stderr,
+ "VPN failed to allocate appropriate address\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
if (AF_INET6 == af)
- GNUNET_asprintf(&url,
- "http://[%s]:%u/hello_world",
- inet_ntop(af,
- address,
- ips,
- sizeof(ips)),
- (unsigned int)PORT);
+ GNUNET_asprintf (&url,
+ "http://[%s]:%u/hello_world",
+ inet_ntop (af,
+ address,
+ ips,
+ sizeof(ips)),
+ (unsigned int) PORT);
else
- GNUNET_asprintf(&url,
- "http://%s:%u/hello_world",
- inet_ntop(af,
- address,
- ips,
- sizeof(ips)),
- (unsigned int)PORT);
- curl = curl_easy_init();
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cbc);
- curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 150L);
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15L);
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
-
- multi = curl_multi_init();
- GNUNET_assert(multi != NULL);
- GNUNET_assert(CURLM_OK == curl_multi_add_handle(multi, curl));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Beginning HTTP download from `%s'\n",
- url);
- GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
- &curl_main,
- NULL);
+ GNUNET_asprintf (&url,
+ "http://%s:%u/hello_world",
+ inet_ntop (af,
+ address,
+ ips,
+ sizeof(ips)),
+ (unsigned int) PORT);
+ curl = curl_easy_init ();
+ curl_easy_setopt (curl, CURLOPT_URL, url);
+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc);
+ curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L);
+ curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L);
+ curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
+ curl_easy_setopt (curl, CURLOPT_VERBOSE, 0);
+
+ multi = curl_multi_init ();
+ GNUNET_assert (multi != NULL);
+ GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Beginning HTTP download from `%s'\n",
+ url);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &curl_main,
+ NULL);
}
@@ -307,30 +308,30 @@ allocation_cb(void *cls, int af, const void *address)
* Function to keep the HTTP server running.
*/
static void
-mhd_main(void);
+mhd_main (void);
static void
-mhd_task(void *cls)
+mhd_task (void *cls)
{
mhd_task_id = NULL;
- MHD_run(mhd);
- mhd_main();
+ MHD_run (mhd);
+ mhd_main ();
}
static void
-do_timeout(void *cls)
+do_timeout (void *cls)
{
timeout_task_id = NULL;
- GNUNET_SCHEDULER_shutdown();
- GNUNET_break(0);
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_break (0);
global_ret = 1;
}
static void
-mhd_main()
+mhd_main ()
{
struct GNUNET_NETWORK_FDSet nrs;
struct GNUNET_NETWORK_FDSet nws;
@@ -341,78 +342,78 @@ mhd_main()
unsigned MHD_LONG_LONG timeout;
struct GNUNET_TIME_Relative delay;
- GNUNET_assert(NULL == mhd_task_id);
- FD_ZERO(&rs);
- FD_ZERO(&ws);
- FD_ZERO(&es);
+ GNUNET_assert (NULL == mhd_task_id);
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
max_fd = -1;
- GNUNET_assert(MHD_YES == MHD_get_fdset(mhd, &rs, &ws, &es, &max_fd));
- if (MHD_YES == MHD_get_timeout(mhd, &timeout))
+ GNUNET_assert (MHD_YES == MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd));
+ if (MHD_YES == MHD_get_timeout (mhd, &timeout))
delay =
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
- (unsigned int)timeout);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ (unsigned int) timeout);
else
delay = GNUNET_TIME_UNIT_FOREVER_REL;
- GNUNET_NETWORK_fdset_copy_native(&nrs, &rs, max_fd + 1);
- GNUNET_NETWORK_fdset_copy_native(&nws, &ws, max_fd + 1);
+ GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max_fd + 1);
+ GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max_fd + 1);
mhd_task_id =
- GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay,
- &nrs, &nws, &mhd_task, NULL);
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay,
+ &nrs, &nws, &mhd_task, NULL);
}
static void
-run(void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Peer *peer)
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
{
struct in_addr v4;
struct in6_addr v6;
void *addr;
enum MHD_FLAG flags;
- vpn = GNUNET_VPN_connect(cfg);
- GNUNET_assert(NULL != vpn);
+ vpn = GNUNET_VPN_connect (cfg);
+ GNUNET_assert (NULL != vpn);
flags = MHD_USE_DEBUG;
if (AF_INET6 == dest_af)
flags |= MHD_USE_IPv6;
mhd =
- MHD_start_daemon(flags, PORT, NULL, NULL, &mhd_ahc, NULL,
- MHD_OPTION_END);
+ MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL,
+ MHD_OPTION_END);
- GNUNET_assert(NULL != mhd);
- mhd_main();
+ GNUNET_assert (NULL != mhd);
+ mhd_main ();
addr = NULL;
switch (dest_af)
- {
- case AF_INET:
- GNUNET_assert(1 == inet_pton(dest_af, dest_ip, &v4));
- addr = &v4;
- break;
-
- case AF_INET6:
- GNUNET_assert(1 == inet_pton(dest_af, dest_ip, &v6));
- addr = &v6;
- break;
-
- default:
- GNUNET_assert(0);
- }
- rr = GNUNET_VPN_redirect_to_ip(vpn, src_af, dest_af, addr,
- GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb,
- NULL);
+ {
+ case AF_INET:
+ GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v4));
+ addr = &v4;
+ break;
+
+ case AF_INET6:
+ GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v6));
+ addr = &v6;
+ break;
+
+ default:
+ GNUNET_assert (0);
+ }
+ rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr,
+ GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb,
+ NULL);
timeout_task_id =
- GNUNET_SCHEDULER_add_delayed(TIMEOUT,
- &do_timeout,
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &do_timeout,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
- GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
- NULL);
}
int
-main(int argc, char *const *argv)
+main (int argc, char *const *argv)
{
const char *type;
const char *bin;
@@ -420,90 +421,96 @@ main(int argc, char *const *argv)
char *exit_binary;
int ret = 0;
- if (0 != access("/dev/net/tun", R_OK))
- {
- GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR,
- "access",
- "/dev/net/tun");
- fprintf(stderr,
- "WARNING: System unable to run test, skipping.\n");
- return 77;
- }
-
- vpn_binary = GNUNET_OS_get_libexec_binary_path("gnunet-helper-vpn");
- exit_binary = GNUNET_OS_get_libexec_binary_path("gnunet-helper-exit");
- if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary(vpn_binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))) || //ipv4 only please!
- (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary(exit_binary, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only
- {
- GNUNET_free(vpn_binary);
- GNUNET_free(exit_binary);
- fprintf(stderr,
- "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n", ret);
- return 77;
- }
-
- GNUNET_free(vpn_binary);
- GNUNET_free(exit_binary);
+ if (0 != access ("/dev/net/tun", R_OK))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "access",
+ "/dev/net/tun");
+ fprintf (stderr,
+ "WARNING: System unable to run test, skipping.\n");
+ return 77;
+ }
+
+ vpn_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
+ exit_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit");
+ if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (vpn_binary,
+ GNUNET_YES,
+ "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")))
+ || // ipv4 only please!
+ (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (exit_binary,
+ GNUNET_YES,
+ "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) // no nat, ipv4 only
+ {
+ GNUNET_free (vpn_binary);
+ GNUNET_free (exit_binary);
+ fprintf (stderr,
+ "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n",
+ ret);
+ return 77;
+ }
+
+ GNUNET_free (vpn_binary);
+ GNUNET_free (exit_binary);
bin = argv[0];
- if (NULL != strstr(bin, "lt-"))
- bin = strstr(bin, "lt-") + 4;
- type = strstr(bin, "-");
+ if (NULL != strstr (bin, "lt-"))
+ bin = strstr (bin, "lt-") + 4;
+ type = strstr (bin, "-");
if (NULL == type)
- {
- fprintf(stderr,
- "invalid binary name\n");
- return 1;
- }
+ {
+ fprintf (stderr,
+ "invalid binary name\n");
+ return 1;
+ }
type++;
/* on Windows, .exe is suffixed to these binaries,
* thus cease comparison after the 6th char.
*/
- if (0 == strncmp(type, "4_to_6", 6))
- {
- dest_ip = "FC5A:04E1:C2BA::1";
- dest_af = AF_INET6;
- src_af = AF_INET;
- }
- else if (0 == strncmp(type, "6_to_4", 6))
- {
- dest_ip = "169.254.86.1";
- dest_af = AF_INET;
- src_af = AF_INET6;
- }
- else if (0 == strncmp(type, "4_over", 6))
- {
- dest_ip = "169.254.86.1";
- dest_af = AF_INET;
- src_af = AF_INET;
- }
- else if (0 == strncmp(type, "6_over", 6))
- {
- dest_ip = "FC5A:04E1:C2BA::1";
- dest_af = AF_INET6;
- src_af = AF_INET6;
- }
+ if (0 == strncmp (type, "4_to_6", 6))
+ {
+ dest_ip = "FC5A:04E1:C2BA::1";
+ dest_af = AF_INET6;
+ src_af = AF_INET;
+ }
+ else if (0 == strncmp (type, "6_to_4", 6))
+ {
+ dest_ip = "169.254.86.1";
+ dest_af = AF_INET;
+ src_af = AF_INET6;
+ }
+ else if (0 == strncmp (type, "4_over", 6))
+ {
+ dest_ip = "169.254.86.1";
+ dest_af = AF_INET;
+ src_af = AF_INET;
+ }
+ else if (0 == strncmp (type, "6_over", 6))
+ {
+ dest_ip = "FC5A:04E1:C2BA::1";
+ dest_af = AF_INET6;
+ src_af = AF_INET6;
+ }
else
- {
- fprintf(stderr, "invalid binary suffix `%s'\n", type);
- return 1;
- }
- if ((GNUNET_OK != GNUNET_NETWORK_test_pf(src_af)) ||
- (GNUNET_OK != GNUNET_NETWORK_test_pf(dest_af)))
- {
- fprintf(stderr,
- "Required address families not supported by this system, skipping test.\n");
- return 0;
- }
- if (0 != curl_global_init(CURL_GLOBAL_WIN32))
- {
- fprintf(stderr, "failed to initialize curl\n");
- return 2;
- }
+ {
+ fprintf (stderr, "invalid binary suffix `%s'\n", type);
+ return 1;
+ }
+ if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
+ (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)))
+ {
+ fprintf (stderr,
+ "Required address families not supported by this system, skipping test.\n");
+ return 0;
+ }
+ if (0 != curl_global_init (CURL_GLOBAL_WIN32))
+ {
+ fprintf (stderr, "failed to initialize curl\n");
+ return 2;
+ }
if (0 !=
- GNUNET_TESTING_peer_run("test-gnunet-vpn", "test_gnunet_vpn.conf", &run,
- NULL))
+ GNUNET_TESTING_peer_run ("test-gnunet-vpn", "test_gnunet_vpn.conf", &run,
+ NULL))
return 1;
- GNUNET_DISK_directory_remove("/tmp/gnunet-test-vpn");
+ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn");
return global_ret;
}