[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated: nicer loop structure
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated: nicer loop structure |
Date: |
Tue, 04 Jun 2019 11:58:40 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 58002acac nicer loop structure
58002acac is described below
commit 58002acac13b2eef407a20ee3ddc5f458cd5e483
Author: Christian Grothoff <address@hidden>
AuthorDate: Tue Jun 4 11:57:59 2019 +0200
nicer loop structure
---
src/namestore/gnunet-zoneimport.c | 844 ++++++++++++-------------------
src/peerstore/gnunet-service-peerstore.c | 264 ++++------
src/peerstore/peerstore_api.c | 247 ++++-----
src/regex/regex_internal.c | 717 +++++++++++++-------------
src/statistics/gnunet-statistics.c | 387 +++++++-------
5 files changed, 1073 insertions(+), 1386 deletions(-)
diff --git a/src/namestore/gnunet-zoneimport.c
b/src/namestore/gnunet-zoneimport.c
index f36106332..4c5205ab3 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.c
@@ -56,7 +56,8 @@
/**
* How long do we wait at least between series of requests?
*/
-#define SERIES_DELAY GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MICROSECONDS, 10)
+#define SERIES_DELAY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10)
/**
* How long do DNS records have to last at least after being imported?
@@ -97,7 +98,6 @@ struct Zone
* Private key of the zone.
*/
struct GNUNET_CRYPTO_EcdsaPrivateKey key;
-
};
@@ -120,7 +120,6 @@ struct Record
* GNS record.
*/
struct GNUNET_GNSRECORD_Data grd;
-
};
@@ -367,9 +366,8 @@ static struct GNUNET_TIME_Relative idle_time;
* @param cls closure
* @param rec a DNS record
*/
-typedef void
-(*RecordProcessor) (void *cls,
- const struct GNUNET_DNSPARSER_Record *rec);
+typedef void (*RecordProcessor) (void *cls,
+ const struct GNUNET_DNSPARSER_Record *rec);
/**
@@ -382,29 +380,26 @@ typedef void
*/
static void
for_all_records (const struct GNUNET_DNSPARSER_Packet *p,
- RecordProcessor rp,
- void *rp_cls)
+ RecordProcessor rp,
+ void *rp_cls)
{
- for (unsigned int i=0;i<p->num_answers;i++)
+ for (unsigned int i = 0; i < p->num_answers; i++)
{
struct GNUNET_DNSPARSER_Record *rs = &p->answers[i];
- rp (rp_cls,
- rs);
+ rp (rp_cls, rs);
}
- for (unsigned int i=0;i<p->num_authority_records;i++)
+ for (unsigned int i = 0; i < p->num_authority_records; i++)
{
struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i];
- rp (rp_cls,
- rs);
+ rp (rp_cls, rs);
}
- for (unsigned int i=0;i<p->num_additional_records;i++)
+ for (unsigned int i = 0; i < p->num_additional_records; i++)
{
struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i];
- rp (rp_cls,
- rs);
+ rp (rp_cls, rs);
}
}
@@ -422,8 +417,7 @@ get_label (struct Request *req)
static char label[64];
const char *dot;
- dot = strchr (req->hostname,
- (unsigned char) '.');
+ dot = strchr (req->hostname, (unsigned char) '.');
if (NULL == dot)
{
GNUNET_break (0);
@@ -434,9 +428,7 @@ get_label (struct Request *req)
GNUNET_break (0);
return NULL;
}
- GNUNET_memcpy (label,
- req->hostname,
- dot - req->hostname);
+ GNUNET_memcpy (label, req->hostname, dot - req->hostname);
label[dot - req->hostname] = '\0';
return label;
}
@@ -451,8 +443,7 @@ get_label (struct Request *req)
* allocated query buffer
*/
static void *
-build_dns_query (struct Request *req,
- size_t *raw_size)
+build_dns_query (struct Request *req, size_t *raw_size)
{
static char raw[512];
char *rawp;
@@ -464,16 +455,11 @@ build_dns_query (struct Request *req,
q.type = GNUNET_DNSPARSER_TYPE_NS;
q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
- memset (&p,
- 0,
- sizeof (p));
+ memset (&p, 0, sizeof (p));
p.num_queries = 1;
p.queries = &q;
p.id = req->id;
- ret = GNUNET_DNSPARSER_pack (&p,
- UINT16_MAX,
- &rawp,
- raw_size);
+ ret = GNUNET_DNSPARSER_pack (&p, UINT16_MAX, &rawp, raw_size);
if (GNUNET_OK != ret)
{
if (GNUNET_NO == ret)
@@ -494,15 +480,12 @@ build_dns_query (struct Request *req,
GNUNET_free (rawp);
return NULL;
}
- GNUNET_memcpy (raw,
- rawp,
- *raw_size);
+ GNUNET_memcpy (raw, rawp, *raw_size);
GNUNET_free (rawp);
return raw;
}
-
/**
* Free records associated with @a req.
*
@@ -516,9 +499,7 @@ free_records (struct Request *req)
/* Free records */
while (NULL != (rec = req->rec_head))
{
- GNUNET_CONTAINER_DLL_remove (req->rec_head,
- req->rec_tail,
- rec);
+ GNUNET_CONTAINER_DLL_remove (req->rec_head, req->rec_tail, rec);
GNUNET_free (rec);
}
}
@@ -554,17 +535,14 @@ process_queue (void *cls);
static void
insert_sorted (struct Request *req)
{
- req->hn = GNUNET_CONTAINER_heap_insert (req_heap,
- req,
- req->expires.abs_value_us);
+ req->hn =
+ GNUNET_CONTAINER_heap_insert (req_heap, req, req->expires.abs_value_us);
if (req == GNUNET_CONTAINER_heap_peek (req_heap))
{
if (NULL != t)
GNUNET_SCHEDULER_cancel (t);
sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
- t = GNUNET_SCHEDULER_add_at (req->expires,
- &process_queue,
- NULL);
+ t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL);
}
}
@@ -580,10 +558,10 @@ insert_sorted (struct Request *req)
*/
static void
add_record (struct Request *req,
- uint32_t type,
- struct GNUNET_TIME_Absolute expiration_time,
- const void *data,
- size_t data_len)
+ uint32_t type,
+ struct GNUNET_TIME_Absolute expiration_time,
+ const void *data,
+ size_t data_len)
{
struct Record *rec;
@@ -593,12 +571,8 @@ add_record (struct Request *req,
rec->grd.data_size = data_len;
rec->grd.record_type = type;
rec->grd.flags = GNUNET_GNSRECORD_RF_NONE;
- GNUNET_memcpy (&rec[1],
- data,
- data_len);
- GNUNET_CONTAINER_DLL_insert (req->rec_head,
- req->rec_tail,
- rec);
+ GNUNET_memcpy (&rec[1], data, data_len);
+ GNUNET_CONTAINER_DLL_insert (req->rec_head, req->rec_tail, rec);
}
@@ -631,20 +605,18 @@ struct GlueClosure
* @param rec record that may contain glue information
*/
static void
-check_for_glue (void *cls,
- const struct GNUNET_DNSPARSER_Record *rec)
+check_for_glue (void *cls, const struct GNUNET_DNSPARSER_Record *rec)
{
struct GlueClosure *gc = cls;
char dst[65536];
size_t dst_len;
size_t off;
- char ip[INET6_ADDRSTRLEN+1];
+ char ip[INET6_ADDRSTRLEN + 1];
socklen_t ip_size = (socklen_t) sizeof (ip);
struct GNUNET_TIME_Absolute expiration_time;
struct GNUNET_TIME_Relative left;
- if (0 != strcasecmp (rec->name,
- gc->ns))
+ if (0 != strcasecmp (rec->name, gc->ns))
return;
expiration_time = rec->expiration_time;
left = GNUNET_TIME_absolute_get_remaining (expiration_time);
@@ -652,7 +624,8 @@ check_for_glue (void *cls,
return; /* ignore expired glue records */
/* if expiration window is too short, bump it to configured minimum */
if (left.rel_value_us < minimum_expiration_time.rel_value_us)
- expiration_time = GNUNET_TIME_relative_to_absolute
(minimum_expiration_time);
+ expiration_time =
+ GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
dst_len = sizeof (dst);
off = 0;
switch (rec->type)
@@ -663,31 +636,23 @@ check_for_glue (void *cls,
GNUNET_break (0);
return;
}
- if (NULL ==
- inet_ntop (AF_INET,
- rec->data.raw.data,
- ip,
- ip_size))
+ if (NULL == inet_ntop (AF_INET, rec->data.raw.data, ip, ip_size))
{
GNUNET_break (0);
return;
}
- if ( (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- gc->req->hostname)) &&
- (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- ip)) )
+ if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
+ dst_len,
+ &off,
+ gc->req->hostname)) &&
+ (GNUNET_OK ==
+ GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip)))
{
add_record (gc->req,
- GNUNET_GNSRECORD_TYPE_GNS2DNS,
- expiration_time,
- dst,
- off);
+ GNUNET_GNSRECORD_TYPE_GNS2DNS,
+ expiration_time,
+ dst,
+ off);
gc->found = GNUNET_YES;
}
break;
@@ -697,51 +662,41 @@ check_for_glue (void *cls,
GNUNET_break (0);
return;
}
- if (NULL ==
- inet_ntop (AF_INET6,
- rec->data.raw.data,
- ip,
- ip_size))
+ if (NULL == inet_ntop (AF_INET6, rec->data.raw.data, ip, ip_size))
{
GNUNET_break (0);
return;
}
- if ( (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- gc->req->hostname)) &&
- (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- ip)) )
+ if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
+ dst_len,
+ &off,
+ gc->req->hostname)) &&
+ (GNUNET_OK ==
+ GNUNET_DNSPARSER_builder_add_name (dst, dst_len, &off, ip)))
{
add_record (gc->req,
- GNUNET_GNSRECORD_TYPE_GNS2DNS,
- expiration_time,
- dst,
- off);
+ GNUNET_GNSRECORD_TYPE_GNS2DNS,
+ expiration_time,
+ dst,
+ off);
gc->found = GNUNET_YES;
}
break;
case GNUNET_DNSPARSER_TYPE_CNAME:
- if ( (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- gc->req->hostname)) &&
- (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- rec->data.hostname)) )
+ if ((GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
+ dst_len,
+ &off,
+ gc->req->hostname)) &&
+ (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
+ dst_len,
+ &off,
+ rec->data.hostname)))
{
add_record (gc->req,
- GNUNET_GNSRECORD_TYPE_GNS2DNS,
- expiration_time,
- dst,
- off);
+ GNUNET_GNSRECORD_TYPE_GNS2DNS,
+ expiration_time,
+ dst,
+ off);
gc->found = GNUNET_YES;
}
break;
@@ -777,8 +732,7 @@ struct ProcessRecordContext
* @param rec response
*/
static void
-process_record (void *cls,
- const struct GNUNET_DNSPARSER_Record *rec)
+process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec)
{
struct ProcessRecordContext *prc = cls;
struct Request *req = prc->req;
@@ -791,14 +745,14 @@ process_record (void *cls,
dst_len = sizeof (dst);
off = 0;
records++;
- if (0 != strcasecmp (rec->name,
- req->hostname))
+ if (0 != strcasecmp (rec->name, req->hostname))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "DNS returned record from zone `%s' of type %u while resolving
`%s'\n",
- rec->name,
- (unsigned int) rec->type,
- req->hostname);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "DNS returned record from zone `%s' of type %u while resolving `%s'\n",
+ rec->name,
+ (unsigned int) rec->type,
+ req->hostname);
return; /* does not match hostname, might be glue, but
not useful for this pass! */
}
@@ -807,8 +761,8 @@ process_record (void *cls,
if (0 == left.rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "DNS returned expired record for `%s'\n",
- req->hostname);
+ "DNS returned expired record for `%s'\n",
+ req->hostname);
GNUNET_STATISTICS_update (stats,
"# expired records obtained from DNS",
1,
@@ -822,68 +776,59 @@ process_record (void *cls,
req->hostname);
/* if expiration window is too short, bump it to configured minimum */
if (left.rel_value_us < minimum_expiration_time.rel_value_us)
- expiration_time = GNUNET_TIME_relative_to_absolute
(minimum_expiration_time);
+ expiration_time =
+ GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
switch (rec->type)
{
- case GNUNET_DNSPARSER_TYPE_NS:
+ case GNUNET_DNSPARSER_TYPE_NS: {
+ struct GlueClosure gc;
+
+ /* check for glue */
+ gc.req = req;
+ gc.ns = rec->data.hostname;
+ gc.found = GNUNET_NO;
+ for_all_records (prc->p, &check_for_glue, &gc);
+ if ((GNUNET_NO == gc.found) &&
+ (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
+ dst_len,
+ &off,
+ req->hostname)) &&
+ (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
+ dst_len,
+ &off,
+ rec->data.hostname)))
{
- struct GlueClosure gc;
-
- /* check for glue */
- gc.req = req;
- gc.ns = rec->data.hostname;
- gc.found = GNUNET_NO;
- for_all_records (prc->p,
- &check_for_glue,
- &gc);
- if ( (GNUNET_NO == gc.found) &&
- (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- req->hostname)) &&
- (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- rec->data.hostname)) )
- {
- /* FIXME: actually check if this is out-of-bailiwick,
+ /* FIXME: actually check if this is out-of-bailiwick,
and if not request explicit resolution... */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Converted OOB (`%s') NS record for `%s'\n",
- rec->data.hostname,
- rec->name);
- add_record (req,
- GNUNET_GNSRECORD_TYPE_GNS2DNS,
- expiration_time,
- dst,
- off);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Converted NS record for `%s' using glue\n",
- rec->name);
- }
- break;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Converted OOB (`%s') NS record for `%s'\n",
+ rec->data.hostname,
+ rec->name);
+ add_record (req,
+ GNUNET_GNSRECORD_TYPE_GNS2DNS,
+ expiration_time,
+ dst,
+ off);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Converted NS record for `%s' using glue\n",
+ rec->name);
}
+ break;
+ }
case GNUNET_DNSPARSER_TYPE_CNAME:
- if (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- rec->data.hostname))
+ if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
+ dst_len,
+ &off,
+ rec->data.hostname))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Converting CNAME (`%s') record for `%s'\n",
- rec->data.hostname,
- rec->name);
- add_record (req,
- rec->type,
- expiration_time,
- dst,
- off);
+ "Converting CNAME (`%s') record for `%s'\n",
+ rec->data.hostname,
+ rec->name);
+ add_record (req, rec->type, expiration_time, dst, off);
}
break;
case GNUNET_DNSPARSER_TYPE_DNAME:
@@ -895,90 +840,57 @@ process_record (void *cls,
break;
case GNUNET_DNSPARSER_TYPE_MX:
if (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_mx (dst,
- dst_len,
- &off,
- rec->data.mx))
+ GNUNET_DNSPARSER_builder_add_mx (dst, dst_len, &off, rec->data.mx))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Converting MX (`%s') record for `%s'\n",
- rec->data.mx->mxhost,
- rec->name);
- add_record (req,
- rec->type,
- expiration_time,
- dst,
- off);
+ "Converting MX (`%s') record for `%s'\n",
+ rec->data.mx->mxhost,
+ rec->name);
+ add_record (req, rec->type, expiration_time, dst, off);
}
break;
case GNUNET_DNSPARSER_TYPE_SOA:
if (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_soa (dst,
- dst_len,
- &off,
- rec->data.soa))
+ GNUNET_DNSPARSER_builder_add_soa (dst, dst_len, &off, rec->data.soa))
{
/* NOTE: GNS does not really use SOAs */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Converting SOA record for `%s'\n",
- rec->name);
- add_record (req,
- rec->type,
- expiration_time,
- dst,
- off);
+ "Converting SOA record for `%s'\n",
+ rec->name);
+ add_record (req, rec->type, expiration_time, dst, off);
}
break;
case GNUNET_DNSPARSER_TYPE_SRV:
if (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_srv (dst,
- dst_len,
- &off,
- rec->data.srv))
+ GNUNET_DNSPARSER_builder_add_srv (dst, dst_len, &off, rec->data.srv))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Converting SRV record for `%s'\n",
- rec->name);
- add_record (req,
- rec->type,
- expiration_time,
- dst,
- off);
+ "Converting SRV record for `%s'\n",
+ rec->name);
+ add_record (req, rec->type, expiration_time, dst, off);
}
break;
case GNUNET_DNSPARSER_TYPE_PTR:
- if (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_name (dst,
- dst_len,
- &off,
- rec->data.hostname))
+ if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
+ dst_len,
+ &off,
+ rec->data.hostname))
{
/* !?: what does a PTR record do in a regular TLD??? */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Converting PTR record for `%s' (weird)\n",
- rec->name);
- add_record (req,
- rec->type,
- expiration_time,
- dst,
- off);
+ "Converting PTR record for `%s' (weird)\n",
+ rec->name);
+ add_record (req, rec->type, expiration_time, dst, off);
}
break;
case GNUNET_DNSPARSER_TYPE_CERT:
if (GNUNET_OK ==
- GNUNET_DNSPARSER_builder_add_cert (dst,
- dst_len,
- &off,
- rec->data.cert))
+ GNUNET_DNSPARSER_builder_add_cert (dst, dst_len, &off, rec->data.cert))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Converting CERT record for `%s'\n",
- rec->name);
- add_record (req,
- rec->type,
- expiration_time,
- dst,
- off);
+ "Converting CERT record for `%s'\n",
+ rec->name);
+ add_record (req, rec->type, expiration_time, dst, off);
}
break;
/* Rest is 'raw' encoded and just needs to be copied IF
@@ -989,14 +901,14 @@ process_record (void *cls,
case GNUNET_DNSPARSER_TYPE_TXT:
default:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Converting record of type %u for `%s'\n",
- (unsigned int) rec->type,
- rec->name);
+ "Converting record of type %u for `%s'\n",
+ (unsigned int) rec->type,
+ rec->name);
add_record (req,
- rec->type,
- expiration_time,
- rec->data.raw.data,
- rec->data.raw.data_len);
+ rec->type,
+ expiration_time,
+ rec->data.raw.data,
+ rec->data.raw.data_len);
break;
}
}
@@ -1013,9 +925,7 @@ process_record (void *cls,
* @param emsg NULL on success, otherwise an error message
*/
static void
-store_completed_cb (void *cls,
- int32_t success,
- const char *emsg)
+store_completed_cb (void *cls, int32_t success, const char *emsg)
{
static struct GNUNET_TIME_Absolute last;
struct Request *req = cls;
@@ -1024,15 +934,15 @@ store_completed_cb (void *cls,
if (GNUNET_SYSERR == success)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to store zone data for `%s': %s\n",
- req->hostname,
- emsg);
+ "Failed to store zone data for `%s': %s\n",
+ req->hostname,
+ emsg);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stored records under `%s' (%d)\n",
- req->hostname,
+ "Stored records under `%s' (%d)\n",
+ req->hostname,
success);
}
total_reg_proc_dns_ns++; /* finished regular processing */
@@ -1045,8 +955,7 @@ store_completed_cb (void *cls,
struct GNUNET_TIME_Relative ns_latency;
ns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time);
- total_ns_latency = GNUNET_TIME_relative_add (total_ns_latency,
- ns_latency);
+ total_ns_latency = GNUNET_TIME_relative_add (total_ns_latency, ns_latency);
if (0 == total_ns_latency_cnt)
last = GNUNET_TIME_absolute_get ();
total_ns_latency_cnt++;
@@ -1057,25 +966,25 @@ store_completed_cb (void *cls,
delta = GNUNET_TIME_absolute_get_duration (last);
last = GNUNET_TIME_absolute_get ();
fprintf (stderr,
- "Processed 1000 records in %s\n",
- GNUNET_STRINGS_relative_time_to_string (delta,
- GNUNET_YES));
+ "Processed 1000 records in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
GNUNET_STATISTICS_set (stats,
"# average NAMESTORE PUT latency (μs)",
- total_ns_latency.rel_value_us /
total_ns_latency_cnt,
+ total_ns_latency.rel_value_us /
+ total_ns_latency_cnt,
GNUNET_NO);
}
}
/* compute and publish overall velocity */
- if (0 == (total_reg_proc_dns_ns % 100) )
+ if (0 == (total_reg_proc_dns_ns % 100))
{
struct GNUNET_TIME_Relative runtime;
runtime = GNUNET_TIME_absolute_get_duration (start_time_reg_proc);
- runtime = GNUNET_TIME_relative_subtract (runtime,
- idle_time);
- runtime = GNUNET_TIME_relative_divide (runtime,
- total_reg_proc_dns +
total_reg_proc_dns_ns);
+ runtime = GNUNET_TIME_relative_subtract (runtime, idle_time);
+ runtime =
+ GNUNET_TIME_relative_divide (runtime,
+ total_reg_proc_dns + total_reg_proc_dns_ns);
GNUNET_STATISTICS_set (stats,
"# Regular processing completed without NAMESTORE",
total_reg_proc_dns,
@@ -1097,8 +1006,7 @@ store_completed_cb (void *cls,
if (NULL == t)
{
sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
- t = GNUNET_SCHEDULER_add_now (&process_queue,
- NULL);
+ t = GNUNET_SCHEDULER_add_now (&process_queue, NULL);
}
}
@@ -1124,31 +1032,22 @@ process_result (void *cls,
if (NULL == dns)
{
/* stub gave up */
- GNUNET_CONTAINER_DLL_remove (req_head,
- req_tail,
- req);
+ GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req);
pending--;
if (NULL == t)
{
sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
- t = GNUNET_SCHEDULER_add_now (&process_queue,
- NULL);
+ t = GNUNET_SCHEDULER_add_now (&process_queue, NULL);
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Stub gave up on DNS reply for `%s'\n",
req->hostname);
- GNUNET_STATISTICS_update (stats,
- "# DNS lookups timed out",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# DNS lookups timed out", 1, GNUNET_NO);
if (req->issue_num > MAX_RETRIES)
{
failures++;
free_request (req);
- GNUNET_STATISTICS_update (stats,
- "# requests given up on",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO);
return;
}
total_reg_proc_dns++;
@@ -1160,43 +1059,30 @@ process_result (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"DNS ID did not match request, ignoring reply\n");
- GNUNET_STATISTICS_update (stats,
- "# DNS ID mismatches",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# DNS ID mismatches", 1, GNUNET_NO);
return;
}
- GNUNET_CONTAINER_DLL_remove (req_head,
- req_tail,
- req);
+ GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req);
GNUNET_DNSSTUB_resolve_cancel (req->rs);
req->rs = NULL;
pending--;
- p = GNUNET_DNSPARSER_parse ((const char *) dns,
- dns_len);
+ p = GNUNET_DNSPARSER_parse ((const char *) dns, dns_len);
if (NULL == p)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to parse DNS reply for `%s'\n",
req->hostname);
- GNUNET_STATISTICS_update (stats,
- "# DNS parser errors",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# DNS parser errors", 1, GNUNET_NO);
if (NULL == t)
{
sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
- t = GNUNET_SCHEDULER_add_now (&process_queue,
- NULL);
+ t = GNUNET_SCHEDULER_add_now (&process_queue, NULL);
}
if (req->issue_num > MAX_RETRIES)
{
failures++;
free_request (req);
- GNUNET_STATISTICS_update (stats,
- "# requests given up on",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# requests given up on", 1, GNUNET_NO);
return;
}
insert_sorted (req);
@@ -1205,14 +1091,9 @@ process_result (void *cls,
/* import new records */
req->issue_num = 0; /* success, reset counter! */
{
- struct ProcessRecordContext prc = {
- .req = req,
- .p = p
- };
-
- for_all_records (p,
- &process_record,
- &prc);
+ struct ProcessRecordContext prc = {.req = req, .p = p};
+
+ for_all_records (p, &process_record, &prc);
}
GNUNET_DNSPARSER_free_packet (p);
/* count records found, determine minimum expiration time */
@@ -1221,14 +1102,15 @@ process_result (void *cls,
struct GNUNET_TIME_Relative dns_latency;
dns_latency = GNUNET_TIME_absolute_get_duration (req->op_start_time);
- total_dns_latency = GNUNET_TIME_relative_add (total_dns_latency,
- dns_latency);
+ total_dns_latency =
+ GNUNET_TIME_relative_add (total_dns_latency, dns_latency);
total_dns_latency_cnt++;
if (0 == (total_dns_latency_cnt % 1000))
{
GNUNET_STATISTICS_set (stats,
"# average DNS lookup latency (μs)",
- total_dns_latency.rel_value_us /
total_dns_latency_cnt,
+ total_dns_latency.rel_value_us /
+ total_dns_latency_cnt,
GNUNET_NO);
}
}
@@ -1238,20 +1120,18 @@ process_result (void *cls,
struct GNUNET_TIME_Absolute at;
at.abs_value_us = rec->grd.expiration_time;
- req->expires = GNUNET_TIME_absolute_min (req->expires,
- at);
+ req->expires = GNUNET_TIME_absolute_min (req->expires, at);
rd_count++;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Obtained %u records for `%s'\n",
- rd_count,
- req->hostname);
+ "Obtained %u records for `%s'\n",
+ rd_count,
+ req->hostname);
/* Instead of going for SOA, simplified for now to look each
day in case we got an empty response */
if (0 == rd_count)
{
- req->expires
- = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS);
+ req->expires = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS);
GNUNET_STATISTICS_update (stats,
"# empty DNS replies (usually NXDOMAIN)",
1,
@@ -1263,21 +1143,21 @@ process_result (void *cls,
}
/* convert records to namestore import format */
{
- struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
+ struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)];
unsigned int off = 0;
/* convert linked list into array */
- for (rec = req->rec_head; NULL != rec; rec =rec->next)
+ for (rec = req->rec_head; NULL != rec; rec = rec->next)
rd[off++] = rec->grd;
pending_rs++;
req->op_start_time = GNUNET_TIME_absolute_get ();
req->qe = GNUNET_NAMESTORE_records_store (ns,
- &req->zone->key,
- get_label (req),
- rd_count,
- rd,
- &store_completed_cb,
- req);
+ &req->zone->key,
+ get_label (req),
+ rd_count,
+ rd,
+ &store_completed_cb,
+ req);
GNUNET_assert (NULL != req->qe);
}
insert_sorted (req);
@@ -1300,8 +1180,7 @@ process_queue (void *cls)
(void) cls;
delay = GNUNET_TIME_absolute_get_duration (sleep_time_reg_proc);
- idle_time = GNUNET_TIME_relative_add (idle_time,
- delay);
+ idle_time = GNUNET_TIME_relative_add (idle_time, delay);
series = 0;
t = NULL;
while (pending + pending_rs < THRESH)
@@ -1318,18 +1197,14 @@ process_queue (void *cls)
}
if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0)
break;
- GNUNET_assert (req ==
- GNUNET_CONTAINER_heap_remove_root (req_heap));
+ GNUNET_assert (req == GNUNET_CONTAINER_heap_remove_root (req_heap));
req->hn = NULL;
- GNUNET_CONTAINER_DLL_insert (req_head,
- req_tail,
- req);
+ GNUNET_CONTAINER_DLL_insert (req_head, req_tail, req);
GNUNET_assert (NULL == req->rs);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting resolution for `%s'\n",
req->hostname);
- raw = build_dns_query (req,
- &raw_size);
+ raw = build_dns_query (req, &raw_size);
if (NULL == raw)
{
GNUNET_break (0);
@@ -1337,11 +1212,7 @@ process_queue (void *cls)
continue;
}
req->op_start_time = GNUNET_TIME_absolute_get ();
- req->rs = GNUNET_DNSSTUB_resolve (ctx,
- raw,
- raw_size,
- &process_result,
- req);
+ req->rs = GNUNET_DNSSTUB_resolve (ctx, raw, raw_size, &process_result,
req);
GNUNET_assert (NULL != req->rs);
req->issue_num++;
lookups++;
@@ -1353,41 +1224,36 @@ process_queue (void *cls)
if (pending + pending_rs >= THRESH)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopped processing queue (%u+%u/%u)]\n",
- pending,
- pending_rs,
- THRESH);
+ "Stopped processing queue (%u+%u/%u)]\n",
+ pending,
+ pending_rs,
+ THRESH);
return; /* wait for replies */
}
req = GNUNET_CONTAINER_heap_peek (req_heap);
if (NULL == req)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopped processing queue: empty queue\n");
+ "Stopped processing queue: empty queue\n");
return;
}
if (GNUNET_TIME_absolute_get_remaining (req->expires).rel_value_us > 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Waiting until %s for next record (`%s') to expire\n",
- GNUNET_STRINGS_absolute_time_to_string (req->expires),
- req->hostname);
+ "Waiting until %s for next record (`%s') to expire\n",
+ GNUNET_STRINGS_absolute_time_to_string (req->expires),
+ req->hostname);
if (NULL != t)
GNUNET_SCHEDULER_cancel (t);
sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
- t = GNUNET_SCHEDULER_add_at (req->expires,
- &process_queue,
- NULL);
+ t = GNUNET_SCHEDULER_add_at (req->expires, &process_queue, NULL);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Throttling\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Throttling\n");
if (NULL != t)
GNUNET_SCHEDULER_cancel (t);
sleep_time_reg_proc = GNUNET_TIME_absolute_get ();
- t = GNUNET_SCHEDULER_add_delayed (SERIES_DELAY,
- &process_queue,
- NULL);
+ t = GNUNET_SCHEDULER_add_delayed (SERIES_DELAY, &process_queue, NULL);
}
@@ -1401,9 +1267,7 @@ process_queue (void *cls)
* @return #GNUNET_OK
*/
static int
-free_request_it (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+free_request_it (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct Request *req = value;
@@ -1438,9 +1302,7 @@ do_shutdown (void *cls)
}
while (NULL != (req = req_head))
{
- GNUNET_CONTAINER_DLL_remove (req_head,
- req_tail,
- req);
+ GNUNET_CONTAINER_DLL_remove (req_head, req_tail, req);
if (NULL != req->qe)
GNUNET_NAMESTORE_cancel (req->qe);
free_request (req);
@@ -1474,17 +1336,13 @@ do_shutdown (void *cls)
}
if (NULL != ns_pending)
{
- GNUNET_CONTAINER_multihashmap_iterate (ns_pending,
- &free_request_it,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &free_request_it, NULL);
GNUNET_CONTAINER_multihashmap_destroy (ns_pending);
ns_pending = NULL;
}
while (NULL != (zone = zone_head))
{
- GNUNET_CONTAINER_DLL_remove (zone_head,
- zone_tail,
- zone);
+ GNUNET_CONTAINER_DLL_remove (zone_head, zone_tail, zone);
GNUNET_free (zone->domain);
GNUNET_free (zone);
}
@@ -1518,8 +1376,8 @@ ns_lookup_error_cb (void *cls)
struct Zone *zone = cls;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Failed to load data from namestore for zone `%s'\n",
- zone->domain);
+ "Failed to load data from namestore for zone `%s'\n",
+ zone->domain);
zone_it = NULL;
ns_iterator_trigger_next = 0;
iterate_zones (NULL);
@@ -1537,10 +1395,10 @@ ns_lookup_error_cb (void *cls)
*/
static void
ns_lookup_result_cb (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
- const char *label,
- unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
+ const char *label,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
{
struct Zone *zone = cls;
struct Request *req;
@@ -1549,8 +1407,8 @@ ns_lookup_result_cb (void *cls,
ns_iterator_trigger_next--;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Obtained NAMESTORE reply, %llu left in round\n",
- (unsigned long long) ns_iterator_trigger_next);
+ "Obtained NAMESTORE reply, %llu left in round\n",
+ (unsigned long long) ns_iterator_trigger_next);
if (0 == ns_iterator_trigger_next)
{
ns_iterator_trigger_next = NS_BATCH_SIZE;
@@ -1558,19 +1416,12 @@ ns_lookup_result_cb (void *cls,
"# NAMESTORE records requested from cache",
ns_iterator_trigger_next,
GNUNET_NO);
- GNUNET_NAMESTORE_zone_iterator_next (zone_it,
- ns_iterator_trigger_next);
+ GNUNET_NAMESTORE_zone_iterator_next (zone_it, ns_iterator_trigger_next);
}
- GNUNET_asprintf (&fqdn,
- "%s.%s",
- label,
- zone->domain);
- GNUNET_CRYPTO_hash (fqdn,
- strlen (fqdn) + 1,
- &hc);
+ GNUNET_asprintf (&fqdn, "%s.%s", label, zone->domain);
+ GNUNET_CRYPTO_hash (fqdn, strlen (fqdn) + 1, &hc);
GNUNET_free (fqdn);
- req = GNUNET_CONTAINER_multihashmap_get (ns_pending,
- &hc);
+ req = GNUNET_CONTAINER_multihashmap_get (ns_pending, &hc);
if (NULL == req)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -1580,14 +1431,10 @@ ns_lookup_result_cb (void *cls,
return;
}
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (ns_pending,
- &hc,
- req));
- GNUNET_break (0 == GNUNET_memcmp (key,
- &req->zone->key));
- GNUNET_break (0 == strcasecmp (label,
- get_label (req)));
- for (unsigned int i=0;i<rd_count;i++)
+ GNUNET_CONTAINER_multihashmap_remove (ns_pending, &hc, req));
+ GNUNET_break (0 == GNUNET_memcmp (key, &req->zone->key));
+ GNUNET_break (0 == strcasecmp (label, get_label (req)));
+ for (unsigned int i = 0; i < rd_count; i++)
{
struct GNUNET_TIME_Absolute at;
@@ -1602,17 +1449,13 @@ ns_lookup_result_cb (void *cls,
{
at.abs_value_us = rd->expiration_time;
}
- add_record (req,
- rd->record_type,
- at,
- rd->data,
- rd->data_size);
+ add_record (req, rd->record_type, at, rd->data, rd->data_size);
}
if (0 == rd_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Empty record set in namestore for `%s'\n",
- req->hostname);
+ "Empty record set in namestore for `%s'\n",
+ req->hostname);
}
else
{
@@ -1620,30 +1463,27 @@ ns_lookup_result_cb (void *cls,
cached++;
req->expires = GNUNET_TIME_UNIT_FOREVER_ABS;
- for (struct Record *rec = req->rec_head;
- NULL != rec;
- rec = rec->next)
+ for (struct Record *rec = req->rec_head; NULL != rec; rec = rec->next)
{
struct GNUNET_TIME_Absolute at;
at.abs_value_us = rec->grd.expiration_time;
- req->expires = GNUNET_TIME_absolute_min (req->expires,
- at);
+ req->expires = GNUNET_TIME_absolute_min (req->expires, at);
pos++;
}
if (0 == pos)
req->expires = GNUNET_TIME_UNIT_ZERO_ABS;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Hot-start with %u existing records for `%s'\n",
- pos,
+ pos,
req->hostname);
}
free_records (req);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding `%s' to worklist to start at %s\n",
- req->hostname,
- GNUNET_STRINGS_absolute_time_to_string (req->expires));
+ "Adding `%s' to worklist to start at %s\n",
+ req->hostname,
+ GNUNET_STRINGS_absolute_time_to_string (req->expires));
insert_sorted (req);
}
@@ -1662,8 +1502,7 @@ queue (const char *hostname)
size_t hlen;
struct GNUNET_HashCode hc;
- if (GNUNET_OK !=
- GNUNET_DNSPARSER_check_name (hostname))
+ if (GNUNET_OK != GNUNET_DNSPARSER_check_name (hostname))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Refusing invalid hostname `%s'\n",
@@ -1671,8 +1510,7 @@ queue (const char *hostname)
rejects++;
return;
}
- dot = strchr (hostname,
- (unsigned char) '.');
+ dot = strchr (hostname, (unsigned char) '.');
if (NULL == dot)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1682,8 +1520,7 @@ queue (const char *hostname)
return;
}
for (zone = zone_head; NULL != zone; zone = zone->next)
- if (0 == strcmp (zone->domain,
- dot + 1))
+ if (0 == strcmp (zone->domain, dot + 1))
break;
if (NULL == zone)
{
@@ -1698,19 +1535,15 @@ queue (const char *hostname)
req = GNUNET_malloc (sizeof (struct Request) + hlen);
req->zone = zone;
req->hostname = (char *) &req[1];
- GNUNET_memcpy (req->hostname,
- hostname,
- hlen);
+ GNUNET_memcpy (req->hostname, hostname, hlen);
req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- UINT16_MAX);
- GNUNET_CRYPTO_hash (req->hostname,
- hlen,
- &hc);
- if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_put (ns_pending,
- &hc,
- req,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ UINT16_MAX);
+ GNUNET_CRYPTO_hash (req->hostname, hlen, &hc);
+ if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (
+ ns_pending,
+ &hc,
+ req,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Duplicate hostname `%s' ignored\n",
@@ -1733,9 +1566,7 @@ queue (const char *hostname)
* @return #GNUNET_OK (continue to iterate)
*/
static int
-move_to_queue (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+move_to_queue (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct Request *req = value;
@@ -1766,9 +1597,9 @@ iterate_zones (void *cls)
last->domain);
/* subtract left-overs from previous iteration */
GNUNET_STATISTICS_update (stats,
- "# NAMESTORE records requested from cache",
- (long long) (- ns_iterator_trigger_next),
- GNUNET_NO);
+ "# NAMESTORE records requested from cache",
+ (long long) (-ns_iterator_trigger_next),
+ GNUNET_NO);
ns_iterator_trigger_next = 0;
}
GNUNET_assert (NULL != zone_tail);
@@ -1777,14 +1608,12 @@ iterate_zones (void *cls)
/* Done iterating over relevant zones in NAMESTORE, move
rest of hash map to work queue as well. */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Finished all NAMESTORE iterations!\n");
+ "Finished all NAMESTORE iterations!\n");
GNUNET_STATISTICS_set (stats,
- "# Domain names without cached reply",
- GNUNET_CONTAINER_multihashmap_size (ns_pending),
- GNUNET_NO);
- GNUNET_CONTAINER_multihashmap_iterate (ns_pending,
- &move_to_queue,
- NULL);
+ "# Domain names without cached reply",
+ GNUNET_CONTAINER_multihashmap_size (ns_pending),
+ GNUNET_NO);
+ GNUNET_CONTAINER_multihashmap_iterate (ns_pending, &move_to_queue, NULL);
GNUNET_CONTAINER_multihashmap_destroy (ns_pending);
ns_pending = NULL;
start_time_reg_proc = GNUNET_TIME_absolute_get ();
@@ -1801,14 +1630,11 @@ iterate_zones (void *cls)
last->domain);
/* subtract left-overs from previous iteration */
GNUNET_STATISTICS_update (stats,
- "# NAMESTORE records requested from cache",
- 1,
- GNUNET_NO);
+ "# NAMESTORE records requested from cache",
+ 1,
+ GNUNET_NO);
ns_iterator_trigger_next = 1;
- GNUNET_STATISTICS_update (stats,
- "# zones iterated",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# zones iterated", 1, GNUNET_NO);
zone_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
&last->key,
&ns_lookup_error_cb,
@@ -1817,7 +1643,6 @@ iterate_zones (void *cls)
last,
&iterate_zones,
NULL);
-
}
@@ -1840,13 +1665,10 @@ process_stdin (void *cls)
GNUNET_IDENTITY_disconnect (id);
id = NULL;
}
- while (NULL !=
- fgets (hn,
- sizeof (hn),
- stdin))
+ while (NULL != fgets (hn, sizeof (hn), stdin))
{
- if (strlen(hn) > 0)
- hn[strlen(hn)-1] = '\0'; /* eat newline */
+ if (strlen (hn) > 0)
+ hn[strlen (hn) - 1] = '\0'; /* eat newline */
if (0 == idot)
last = GNUNET_TIME_absolute_get ();
idot++;
@@ -1857,23 +1679,16 @@ process_stdin (void *cls)
delta = GNUNET_TIME_absolute_get_duration (last);
last = GNUNET_TIME_absolute_get ();
fprintf (stderr,
- "Read 100000 domain names in %s\n",
- GNUNET_STRINGS_relative_time_to_string (delta,
- GNUNET_YES));
- GNUNET_STATISTICS_set (stats,
- "# domain names provided",
- idot,
- GNUNET_NO);
+ "Read 100000 domain names in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
+ GNUNET_STATISTICS_set (stats, "# domain names provided", idot,
GNUNET_NO);
}
queue (hn);
}
fprintf (stderr,
"Done reading %llu domain names\n",
(unsigned long long) idot);
- GNUNET_STATISTICS_set (stats,
- "# domain names provided",
- idot,
- GNUNET_NO);
+ GNUNET_STATISTICS_set (stats, "# domain names provided", idot, GNUNET_NO);
iterate_zones (NULL);
}
@@ -1905,7 +1720,7 @@ process_stdin (void *cls)
* cleaned up).
*
* @param cls closure
- * @param ego ego handle
+ * @param ego ego handle, NULL for end of list
* @param ctx context for application to store data for this ego
* (during the lifetime of this process, initially NULL)
* @param name name assigned by the user for this ego,
@@ -1914,26 +1729,25 @@ process_stdin (void *cls)
*/
static void
identity_cb (void *cls,
- struct GNUNET_IDENTITY_Ego *ego,
- void **ctx,
- const char *name)
+ struct GNUNET_IDENTITY_Ego *ego,
+ void **ctx,
+ const char *name)
{
(void) cls;
(void) ctx;
+
if (NULL == ego)
{
- if (NULL != zone_head)
+ /* end of iteration */
+ if (NULL == zone_head)
{
- t = GNUNET_SCHEDULER_add_now (&process_stdin,
- NULL);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No zone found\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No zone found\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
+ /* zone_head non-null, process hostnames from stdin */
+ t = GNUNET_SCHEDULER_add_now (&process_stdin, NULL);
+ return;
}
if (NULL != name)
{
@@ -1942,9 +1756,7 @@ identity_cb (void *cls,
zone = GNUNET_new (struct Zone);
zone->key = *GNUNET_IDENTITY_ego_get_private_key (ego);
zone->domain = GNUNET_strdup (name);
- GNUNET_CONTAINER_DLL_insert (zone_head,
- zone_tail,
- zone);
+ GNUNET_CONTAINER_DLL_insert (zone_head, zone_tail, zone);
}
}
@@ -1967,22 +1779,18 @@ run (void *cls,
(void) cls;
(void) args;
(void) cfgfile;
- stats = GNUNET_STATISTICS_create ("zoneimport",
- cfg);
+ stats = GNUNET_STATISTICS_create ("zoneimport", cfg);
req_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
- ns_pending = GNUNET_CONTAINER_multihashmap_create (map_size,
- GNUNET_NO);
+ ns_pending = GNUNET_CONTAINER_multihashmap_create (map_size, GNUNET_NO);
if (NULL == ns_pending)
{
- fprintf (stderr,
- "Failed to allocate memory for main hash map\n");
+ fprintf (stderr, "Failed to allocate memory for main hash map\n");
return;
}
ctx = GNUNET_DNSSTUB_start (256);
if (NULL == ctx)
{
- fprintf (stderr,
- "Failed to initialize GNUnet DNS STUB\n");
+ fprintf (stderr, "Failed to initialize GNUnet DNS STUB\n");
return;
}
if (NULL == args[0])
@@ -1991,31 +1799,24 @@ run (void *cls,
"You must provide a list of DNS resolvers on the command line\n");
return;
}
- for (unsigned int i=0;NULL != args[i];i++)
+ for (unsigned int i = 0; NULL != args[i]; i++)
{
- if (GNUNET_OK !=
- GNUNET_DNSSTUB_add_dns_ip (ctx,
- args[i]))
+ if (GNUNET_OK != GNUNET_DNSSTUB_add_dns_ip (ctx, args[i]))
{
- fprintf (stderr,
- "Failed to use `%s' for DNS resolver\n",
- args[i]);
+ fprintf (stderr, "Failed to use `%s' for DNS resolver\n", args[i]);
return;
}
}
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
ns = GNUNET_NAMESTORE_connect (cfg);
if (NULL == ns)
{
GNUNET_SCHEDULER_shutdown ();
return;
}
- id = GNUNET_IDENTITY_connect (cfg,
- &identity_cb,
- NULL);
+ id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL);
}
@@ -2027,38 +1828,35 @@ run (void *cls,
* @return 0 on success
*/
int
-main (int argc,
- char *const*argv)
+main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_uint ('s',
- "size",
- "MAPSIZE",
- gettext_noop ("size to use for the main hash
map"),
- &map_size),
- GNUNET_GETOPT_option_relative_time ('m',
- "minimum-expiration",
- "RELATIVETIME",
- gettext_noop ("minimum expiration time
we assume for imported records"),
- &minimum_expiration_time),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_uint ('s',
+ "size",
+ "MAPSIZE",
+ gettext_noop (
+ "size to use for the main hash map"),
+ &map_size),
+ GNUNET_GETOPT_option_relative_time (
+ 'm',
+ "minimum-expiration",
+ "RELATIVETIME",
+ gettext_noop ("minimum expiration time we assume for imported records"),
+ &minimum_expiration_time),
+ 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;
- if (GNUNET_OK !=
- (ret = GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-zoneimport",
- "import DNS zone into namestore",
- options,
- &run,
- NULL)))
+ if (GNUNET_OK != (ret = GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-zoneimport",
+ "import DNS zone into namestore",
+ options,
+ &run,
+ NULL)))
return ret;
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
fprintf (stderr,
"Rejected %u names, had %u cached, did %u lookups, stored %u record
sets\n"
"Found %u records, %u lookups failed, %u/%u pending on shutdown\n",
diff --git a/src/peerstore/gnunet-service-peerstore.c
b/src/peerstore/gnunet-service-peerstore.c
index 9bce542b9..ed1c35535 100644
--- a/src/peerstore/gnunet-service-peerstore.c
+++ b/src/peerstore/gnunet-service-peerstore.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -33,7 +33,7 @@
/**
* Interval for expired records cleanup (in seconds)
*/
-#define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */
+#define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */
/**
* Our configuration.
@@ -79,9 +79,7 @@ do_shutdown ()
{
if (NULL != db_lib_name)
{
- GNUNET_break (NULL ==
- GNUNET_PLUGIN_unload (db_lib_name,
- db));
+ GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db));
GNUNET_free (db_lib_name);
db_lib_name = NULL;
}
@@ -108,15 +106,14 @@ static void
shutdown_task (void *cls)
{
in_shutdown = GNUNET_YES;
- if (0 == num_clients) /* Only when no connected clients. */
+ if (0 == num_clients) /* Only when no connected clients. */
do_shutdown ();
}
/* Forward declaration */
static void
-expire_records_continuation (void *cls,
- int success);
+expire_records_continuation (void *cls, int success);
/**
@@ -131,16 +128,16 @@ cleanup_expired_records (void *cls)
GNUNET_assert (NULL != db);
ret = db->expire_records (db->cls,
GNUNET_TIME_absolute_get (),
- &expire_records_continuation,
+ &expire_records_continuation,
NULL);
if (GNUNET_OK != ret)
{
GNUNET_assert (NULL == expire_task);
- expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
-
EXPIRED_RECORDS_CLEANUP_INTERVAL),
- &cleanup_expired_records,
- NULL);
+ expire_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ EXPIRED_RECORDS_CLEANUP_INTERVAL),
+ &cleanup_expired_records,
+ NULL);
}
}
@@ -152,19 +149,16 @@ cleanup_expired_records (void *cls)
* @param success count of records deleted or #GNUNET_SYSERR
*/
static void
-expire_records_continuation (void *cls,
- int success)
+expire_records_continuation (void *cls, int success)
{
if (success > 0)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "%d records expired.\n",
- success);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success);
GNUNET_assert (NULL == expire_task);
- expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
-
EXPIRED_RECORDS_CLEANUP_INTERVAL),
- &cleanup_expired_records,
- NULL);
+ expire_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ EXPIRED_RECORDS_CLEANUP_INTERVAL),
+ &cleanup_expired_records,
+ NULL);
}
@@ -195,15 +189,12 @@ client_connect_cb (void *cls,
* @return #GNUNET_OK to continue iterating
*/
static int
-client_disconnect_it (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void
*value)
{
if (value == cls)
{
- GNUNET_CONTAINER_multihashmap_remove (watchers,
- key,
- value);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (watchers, key,
value));
num_clients++;
}
return GNUNET_OK;
@@ -221,15 +212,13 @@ client_disconnect_cb (void *cls,
struct GNUNET_SERVICE_Client *client,
void *app_cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "A client disconnected, cleaning up.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning
up.\n");
if (NULL != watchers)
GNUNET_CONTAINER_multihashmap_iterate (watchers,
&client_disconnect_it,
client);
num_clients--;
- if ( (0 == num_clients) &&
- in_shutdown)
+ if ((0 == num_clients) && in_shutdown)
do_shutdown ();
}
@@ -255,10 +244,8 @@ record_iterator (void *cls,
/* No more records */
struct GNUNET_MessageHeader *endmsg;
- env = GNUNET_MQ_msg (endmsg,
- GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client),
- env);
+ env = GNUNET_MQ_msg (endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env);
if (NULL == emsg)
{
GNUNET_SERVICE_client_continue (cls_record->client);
@@ -266,25 +253,23 @@ record_iterator (void *cls,
else
{
GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to iterate: %s\n",
- emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg);
GNUNET_SERVICE_client_drop (cls_record->client);
}
PEERSTORE_destroy_record (cls_record);
return;
}
- env = PEERSTORE_create_record_mq_envelope (record->sub_system,
- &record->peer,
- record->key,
- record->value,
- record->value_size,
- record->expiry,
- 0,
-
GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client),
- env);
+ env = PEERSTORE_create_record_mq_envelope (
+ record->sub_system,
+ &record->peer,
+ record->key,
+ record->value,
+ record->value_size,
+ record->expiry,
+ 0,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env);
}
@@ -298,26 +283,23 @@ record_iterator (void *cls,
* @return #GNUNET_YES to continue iterating
*/
static int
-watch_notifier_it (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct GNUNET_PEERSTORE_Record *record = cls;
struct GNUNET_SERVICE_Client *client = value;
struct GNUNET_MQ_Envelope *env;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found a watcher to update.\n");
- env = PEERSTORE_create_record_mq_envelope (record->sub_system,
- &record->peer,
- record->key,
- record->value,
- record->value_size,
- record->expiry,
- 0,
-
GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n");
+ env = PEERSTORE_create_record_mq_envelope (
+ record->sub_system,
+ &record->peer,
+ record->key,
+ record->value,
+ record->value_size,
+ record->expiry,
+ 0,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
return GNUNET_YES;
}
@@ -332,10 +314,7 @@ watch_notifier (struct GNUNET_PEERSTORE_Record *record)
{
struct GNUNET_HashCode keyhash;
- PEERSTORE_hash_key (record->sub_system,
- &record->peer,
- record->key,
- &keyhash);
+ PEERSTORE_hash_key (record->sub_system, &record->peer, record->key,
&keyhash);
GNUNET_CONTAINER_multihashmap_get_multiple (watchers,
&keyhash,
&watch_notifier_it,
@@ -350,17 +329,13 @@ watch_notifier (struct GNUNET_PEERSTORE_Record *record)
* @param hm the actual message
*/
static void
-handle_watch_cancel (void *cls,
- const struct StoreKeyHashMessage *hm)
+handle_watch_cancel (void *cls, const struct StoreKeyHashMessage *hm)
{
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received a watch cancel request.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n");
if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_remove (watchers,
- &hm->keyhash,
- client))
+ GNUNET_CONTAINER_multihashmap_remove (watchers, &hm->keyhash, client))
{
GNUNET_break (0);
GNUNET_SERVICE_client_drop (client);
@@ -378,13 +353,11 @@ handle_watch_cancel (void *cls,
* @param hm the actual message
*/
static void
-handle_watch (void *cls,
- const struct StoreKeyHashMessage *hm)
+handle_watch (void *cls, const struct StoreKeyHashMessage *hm)
{
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received a watch request.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n");
num_clients--; /* do not count watchers */
GNUNET_SERVICE_client_mark_monitor (client);
GNUNET_CONTAINER_multihashmap_put (watchers,
@@ -403,8 +376,7 @@ handle_watch (void *cls,
* @return #GNUNET_OK if @a srm is well-formed
*/
static int
-check_iterate (void *cls,
- const struct StoreRecordMessage *srm)
+check_iterate (void *cls, const struct StoreRecordMessage *srm)
{
struct GNUNET_PEERSTORE_Record *record;
@@ -432,8 +404,7 @@ check_iterate (void *cls,
* @param srm the actual message
*/
static void
-handle_iterate (void *cls,
- const struct StoreRecordMessage *srm)
+handle_iterate (void *cls, const struct StoreRecordMessage *srm)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_PEERSTORE_Record *record;
@@ -467,8 +438,7 @@ handle_iterate (void *cls,
* @param success result
*/
static void
-store_record_continuation (void *cls,
- int success)
+store_record_continuation (void *cls, int success)
{
struct GNUNET_PEERSTORE_Record *record = cls;
@@ -494,8 +464,7 @@ store_record_continuation (void *cls,
* @return #GNUNET_OK if @a srm is well-formed
*/
static int
-check_store (void *cls,
- const struct StoreRecordMessage *srm)
+check_store (void *cls, const struct StoreRecordMessage *srm)
{
struct GNUNET_PEERSTORE_Record *record;
@@ -505,8 +474,7 @@ check_store (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- if ( (NULL == record->sub_system) ||
- (NULL == record->key) )
+ if ((NULL == record->sub_system) || (NULL == record->key))
{
GNUNET_break (0);
PEERSTORE_destroy_record (record);
@@ -524,31 +492,30 @@ check_store (void *cls,
* @param srm the actual message
*/
static void
-handle_store (void *cls,
- const struct StoreRecordMessage *srm)
+handle_store (void *cls, const struct StoreRecordMessage *srm)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_PEERSTORE_Record *record;
record = PEERSTORE_parse_record_message (srm);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received a store request. Sub system `%s' Peer `%s Key `%s'
Options: %u.\n",
- record->sub_system,
- GNUNET_i2s (&record->peer),
- record->key,
- (uint32_t) ntohl (srm->options));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ "Received a store request. Sub system `%s' Peer `%s Key `%s' Options:
%u.\n",
+ record->sub_system,
+ GNUNET_i2s (&record->peer),
+ record->key,
+ (uint32_t) ntohl (srm->options));
record->client = client;
- if (GNUNET_OK !=
- db->store_record (db->cls,
- record->sub_system,
- &record->peer,
- record->key,
- record->value,
- record->value_size,
- record->expiry,
- ntohl (srm->options),
- &store_record_continuation,
- record))
+ if (GNUNET_OK != db->store_record (db->cls,
+ record->sub_system,
+ &record->peer,
+ record->key,
+ record->value,
+ record->value_size,
+ record->expiry,
+ ntohl (srm->options),
+ &store_record_continuation,
+ record))
{
GNUNET_break (0);
PEERSTORE_destroy_record (record);
@@ -574,11 +541,10 @@ run (void *cls,
in_shutdown = GNUNET_NO;
cfg = c;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "peerstore",
- "DATABASE",
- &database))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ "peerstore",
+ "DATABASE",
+ &database))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"peerstore",
@@ -586,56 +552,50 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_asprintf (&db_lib_name,
- "libgnunet_plugin_peerstore_%s",
- database);
- db = GNUNET_PLUGIN_load (db_lib_name,
- (void *) cfg);
+ GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database);
+ db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
GNUNET_free (database);
if (NULL == db)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not load database backend `%s'\n"),
- db_lib_name);
+ _ ("Could not load database backend `%s'\n"),
+ db_lib_name);
GNUNET_SCHEDULER_shutdown ();
return;
}
- watchers = GNUNET_CONTAINER_multihashmap_create (10,
- GNUNET_NO);
- expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
+ expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("peerstore",
- GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_var_size (store,
- GNUNET_MESSAGE_TYPE_PEERSTORE_STORE,
- struct StoreRecordMessage,
- NULL),
- GNUNET_MQ_hd_var_size (iterate,
- GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE,
- struct StoreRecordMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (watch,
- GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH,
- struct StoreKeyHashMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (watch_cancel,
- GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL,
- struct StoreKeyHashMessage,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN (
+ "peerstore",
+ GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_var_size (store,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_STORE,
+ struct StoreRecordMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (iterate,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE,
+ struct StoreRecordMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (watch,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH,
+ struct StoreKeyHashMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (watch_cancel,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL,
+ struct StoreKeyHashMessage,
+ NULL),
+ GNUNET_MQ_handler_end ());
/* end of gnunet-service-peerstore.c */
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index 02f3e287a..64bc3ae72 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -28,7 +28,7 @@
#include "peerstore.h"
#include "peerstore_common.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "peerstore-api",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__)
/******************************************************************************/
/************************ DATA STRUCTURES
****************************/
@@ -89,7 +89,6 @@ struct GNUNET_PEERSTORE_Handle
* Are we in the process of disconnecting but need to sync first?
*/
int disconnecting;
-
};
/**
@@ -156,7 +155,6 @@ struct GNUNET_PEERSTORE_StoreContext
* Options for the store operation.
*/
enum GNUNET_PEERSTORE_StoreOption options;
-
};
/**
@@ -208,7 +206,6 @@ struct GNUNET_PEERSTORE_IterateContext
* #GNUNET_YES if we are currently processing records.
*/
int iterating;
-
};
/**
@@ -245,7 +242,6 @@ struct GNUNET_PEERSTORE_WatchContext
* Hash of the combined key
*/
struct GNUNET_HashCode keyhash;
-
};
/******************************************************************************/
@@ -271,8 +267,7 @@ disconnect (struct GNUNET_PEERSTORE_Handle *h)
{
struct GNUNET_PEERSTORE_IterateContext *next;
- for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head;
- NULL != ic;
+ for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL !=
ic;
ic = next)
{
next = ic->next;
@@ -285,9 +280,7 @@ disconnect (struct GNUNET_PEERSTORE_Handle *h)
icb_cls = ic->callback_cls;
GNUNET_PEERSTORE_iterate_cancel (ic);
if (NULL != icb)
- icb (icb_cls,
- NULL,
- "Iteration canceled due to reconnection");
+ icb (icb_cls, NULL, "Iteration canceled due to reconnection");
}
}
@@ -312,17 +305,13 @@ disconnect_and_schedule_reconnect (struct
GNUNET_PEERSTORE_Handle *h)
disconnect (h);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Scheduling task to reconnect to PEERSTORE service in %s.\n",
- GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
GNUNET_YES));
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
- &reconnect,
- h);
+ GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
-
/**
* Callback after MQ envelope is sent
*
@@ -352,8 +341,7 @@ store_request_sent (void *cls)
* Function called when we had trouble talking to the service.
*/
static void
-handle_client_error (void *cls,
- enum GNUNET_MQ_Error error)
+handle_client_error (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_PEERSTORE_Handle *h = cls;
@@ -373,9 +361,7 @@ handle_client_error (void *cls,
* @return #GNUNET_YES (continue to iterate)
*/
static int
-rewatch_it (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct GNUNET_PEERSTORE_Handle *h = cls;
struct GNUNET_PEERSTORE_WatchContext *wc = value;
@@ -398,9 +384,7 @@ rewatch_it (void *cls,
* @return #GNUNET_YES to continue iteration
*/
static int
-destroy_watch (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct GNUNET_PEERSTORE_WatchContext *wc = value;
@@ -461,8 +445,7 @@ GNUNET_PEERSTORE_connect (const struct
GNUNET_CONFIGURATION_Handle *cfg)
* @param sync_first send any pending STORE requests before disconnecting
*/
void
-GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h,
- int sync_first)
+GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first)
{
struct GNUNET_PEERSTORE_IterateContext *ic;
struct GNUNET_PEERSTORE_StoreContext *sc;
@@ -515,8 +498,7 @@ GNUNET_PEERSTORE_store_cancel (struct
GNUNET_PEERSTORE_StoreContext *sc)
GNUNET_free (sc->value);
GNUNET_free (sc->key);
GNUNET_free (sc);
- if ( (GNUNET_YES == h->disconnecting) &&
- (NULL == h->store_head) )
+ if ((GNUNET_YES == h->disconnecting) && (NULL == h->store_head))
final_disconnect (h);
}
@@ -542,7 +524,8 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
const char *sub_system,
const struct GNUNET_PeerIdentity *peer,
const char *key,
- const void *value, size_t size,
+ const void *value,
+ size_t size,
struct GNUNET_TIME_Absolute expiry,
enum GNUNET_PEERSTORE_StoreOption options,
GNUNET_PEERSTORE_Continuation cont,
@@ -553,10 +536,19 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n",
- size, sub_system, GNUNET_i2s (peer), key);
- ev = PEERSTORE_create_record_mq_envelope (sub_system, peer, key, value, size,
- expiry, options,
-
GNUNET_MESSAGE_TYPE_PEERSTORE_STORE);
+ size,
+ sub_system,
+ GNUNET_i2s (peer),
+ key);
+ ev =
+ PEERSTORE_create_record_mq_envelope (sub_system,
+ peer,
+ key,
+ value,
+ size,
+ expiry,
+ options,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_STORE);
sc = GNUNET_new (struct GNUNET_PEERSTORE_StoreContext);
sc->sub_system = GNUNET_strdup (sub_system);
@@ -574,7 +566,6 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
GNUNET_MQ_notify_sent (ev, &store_request_sent, sc);
GNUNET_MQ_send (h->mq, ev);
return sc;
-
}
@@ -590,8 +581,7 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
* @param msg message received
*/
static void
-handle_iterate_end (void *cls,
- const struct GNUNET_MessageHeader *msg)
+handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_PEERSTORE_Handle *h = cls;
struct GNUNET_PEERSTORE_IterateContext *ic;
@@ -602,7 +592,7 @@ handle_iterate_end (void *cls,
if (NULL == ic)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Unexpected iteration response, this should not happen.\n"));
+ _ ("Unexpected iteration response, this should not happen.\n"));
disconnect_and_schedule_reconnect (h);
return;
}
@@ -611,9 +601,7 @@ handle_iterate_end (void *cls,
ic->iterating = GNUNET_NO;
GNUNET_PEERSTORE_iterate_cancel (ic);
if (NULL != callback)
- callback (callback_cls,
- NULL,
- NULL);
+ callback (callback_cls, NULL, NULL);
h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
}
@@ -626,8 +614,7 @@ handle_iterate_end (void *cls,
* @param msg message received
*/
static int
-check_iterate_result (void *cls,
- const struct StoreRecordMessage *msg)
+check_iterate_result (void *cls, const struct StoreRecordMessage *msg)
{
/* we defer validation to #handle_iterate_result */
return GNUNET_OK;
@@ -641,8 +628,7 @@ check_iterate_result (void *cls,
* @param msg message received
*/
static void
-handle_iterate_result (void *cls,
- const struct StoreRecordMessage *msg)
+handle_iterate_result (void *cls, const struct StoreRecordMessage *msg)
{
struct GNUNET_PEERSTORE_Handle *h = cls;
struct GNUNET_PEERSTORE_IterateContext *ic;
@@ -654,7 +640,7 @@ handle_iterate_result (void *cls,
if (NULL == ic)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Unexpected iteration response, this should not happen.\n"));
+ _ ("Unexpected iteration response, this should not happen.\n"));
disconnect_and_schedule_reconnect (h);
return;
}
@@ -668,13 +654,11 @@ handle_iterate_result (void *cls,
{
callback (callback_cls,
NULL,
- _("Received a malformed response from service."));
+ _ ("Received a malformed response from service."));
}
else
{
- callback (callback_cls,
- record,
- NULL);
+ callback (callback_cls, record, NULL);
PEERSTORE_destroy_record (record);
}
}
@@ -691,9 +675,7 @@ GNUNET_PEERSTORE_iterate_cancel (struct
GNUNET_PEERSTORE_IterateContext *ic)
{
if (GNUNET_NO == ic->iterating)
{
- GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head,
- ic->h->iterate_tail,
- ic);
+ GNUNET_CONTAINER_DLL_remove (ic->h->iterate_head, ic->h->iterate_tail, ic);
GNUNET_free (ic->sub_system);
GNUNET_free_non_null (ic->key);
GNUNET_free (ic);
@@ -725,13 +707,15 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle
*h,
struct GNUNET_MQ_Envelope *ev;
struct GNUNET_PEERSTORE_IterateContext *ic;
- ev = PEERSTORE_create_record_mq_envelope (sub_system,
- peer,
- key,
- NULL, 0,
- GNUNET_TIME_UNIT_FOREVER_ABS,
- 0,
-
GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE);
+ ev =
+ PEERSTORE_create_record_mq_envelope (sub_system,
+ peer,
+ key,
+ NULL,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ 0,
+
GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE);
ic = GNUNET_new (struct GNUNET_PEERSTORE_IterateContext);
ic->callback = callback;
ic->callback_cls = callback_cls;
@@ -741,9 +725,7 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
ic->peer = *peer;
if (NULL != key)
ic->key = GNUNET_strdup (key);
- GNUNET_CONTAINER_DLL_insert_tail (h->iterate_head,
- h->iterate_tail,
- ic);
+ GNUNET_CONTAINER_DLL_insert_tail (h->iterate_head, h->iterate_tail, ic);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Sending an iterate request for sub system `%s'\n",
sub_system);
@@ -763,8 +745,7 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
* @param msg message received
*/
static int
-check_watch_record (void *cls,
- const struct StoreRecordMessage *msg)
+check_watch_record (void *cls, const struct StoreRecordMessage *msg)
{
/* we defer validation to #handle_watch_result */
return GNUNET_OK;
@@ -778,41 +759,33 @@ check_watch_record (void *cls,
* @param msg message received
*/
static void
-handle_watch_record (void *cls,
- const struct StoreRecordMessage *msg)
+handle_watch_record (void *cls, const struct StoreRecordMessage *msg)
{
struct GNUNET_PEERSTORE_Handle *h = cls;
struct GNUNET_PEERSTORE_Record *record;
struct GNUNET_HashCode keyhash;
struct GNUNET_PEERSTORE_WatchContext *wc;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received a watch record from service.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n");
record = PEERSTORE_parse_record_message (msg);
if (NULL == record)
{
disconnect_and_schedule_reconnect (h);
return;
}
- PEERSTORE_hash_key (record->sub_system,
- &record->peer,
- record->key,
- &keyhash);
+ PEERSTORE_hash_key (record->sub_system, &record->peer, record->key,
&keyhash);
// FIXME: what if there are multiple watches for the same key?
- wc = GNUNET_CONTAINER_multihashmap_get (h->watches,
- &keyhash);
+ wc = GNUNET_CONTAINER_multihashmap_get (h->watches, &keyhash);
if (NULL == wc)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Received a watch result for a non existing watch.\n"));
+ _ ("Received a watch result for a non existing watch.\n"));
PEERSTORE_destroy_record (record);
disconnect_and_schedule_reconnect (h);
return;
}
if (NULL != wc->callback)
- wc->callback (wc->callback_cls,
- record,
- NULL);
+ wc->callback (wc->callback_cls, record, NULL);
h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
PEERSTORE_destroy_record (record);
}
@@ -827,26 +800,24 @@ static void
reconnect (void *cls)
{
struct GNUNET_PEERSTORE_Handle *h = cls;
- struct GNUNET_MQ_MessageHandler mq_handlers[] = {
- GNUNET_MQ_hd_fixed_size (iterate_end,
- GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END,
- struct GNUNET_MessageHeader,
- h),
- GNUNET_MQ_hd_var_size (iterate_result,
- GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD,
- struct StoreRecordMessage,
- h),
- GNUNET_MQ_hd_var_size (watch_record,
- GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD,
- struct StoreRecordMessage,
- h),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler mq_handlers[] =
+ {GNUNET_MQ_hd_fixed_size (iterate_end,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END,
+ struct GNUNET_MessageHeader,
+ h),
+ GNUNET_MQ_hd_var_size (iterate_result,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD,
+ struct StoreRecordMessage,
+ h),
+ GNUNET_MQ_hd_var_size (watch_record,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD,
+ struct StoreRecordMessage,
+ h),
+ GNUNET_MQ_handler_end ()};
struct GNUNET_MQ_Envelope *ev;
h->reconnect_task = NULL;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Reconnecting...\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n");
h->mq = GNUNET_CLIENT_connect (h->cfg,
"peerstore",
mq_handlers,
@@ -857,39 +828,35 @@ reconnect (void *cls)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Resending pending requests after reconnect.\n");
if (NULL != h->watches)
- GNUNET_CONTAINER_multihashmap_iterate (h->watches,
- &rewatch_it,
- h);
- for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head;
- NULL != ic;
+ GNUNET_CONTAINER_multihashmap_iterate (h->watches, &rewatch_it, h);
+ for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL !=
ic;
ic = ic->next)
{
- ev = PEERSTORE_create_record_mq_envelope (ic->sub_system,
- &ic->peer,
- ic->key,
- NULL, 0,
- GNUNET_TIME_UNIT_FOREVER_ABS,
- 0,
-
GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE);
+ ev =
+ PEERSTORE_create_record_mq_envelope (ic->sub_system,
+ &ic->peer,
+ ic->key,
+ NULL,
+ 0,
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ 0,
+
GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE);
GNUNET_MQ_send (h->mq, ev);
}
- for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head;
- NULL != sc;
+ for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; NULL != sc;
sc = sc->next)
{
- ev = PEERSTORE_create_record_mq_envelope (sc->sub_system,
- &sc->peer,
- sc->key,
- sc->value,
- sc->size,
- sc->expiry,
- sc->options,
-
GNUNET_MESSAGE_TYPE_PEERSTORE_STORE);
- GNUNET_MQ_notify_sent (ev,
- &store_request_sent,
- sc);
- GNUNET_MQ_send (h->mq,
- ev);
+ ev =
+ PEERSTORE_create_record_mq_envelope (sc->sub_system,
+ &sc->peer,
+ sc->key,
+ sc->value,
+ sc->size,
+ sc->expiry,
+ sc->options,
+
GNUNET_MESSAGE_TYPE_PEERSTORE_STORE);
+ GNUNET_MQ_notify_sent (ev, &store_request_sent, sc);
+ GNUNET_MQ_send (h->mq, ev);
}
}
@@ -906,15 +873,13 @@ GNUNET_PEERSTORE_watch_cancel (struct
GNUNET_PEERSTORE_WatchContext *wc)
struct GNUNET_MQ_Envelope *ev;
struct StoreKeyHashMessage *hm;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Canceling watch.\n");
- ev = GNUNET_MQ_msg (hm,
- GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling watch.\n");
+ ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL);
hm->keyhash = wc->keyhash;
GNUNET_MQ_send (h->mq, ev);
- GNUNET_CONTAINER_multihashmap_remove (h->watches,
- &wc->keyhash,
- wc);
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (h->watches, &wc->keyhash, wc));
GNUNET_free (wc);
}
@@ -943,32 +908,26 @@ GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
struct StoreKeyHashMessage *hm;
struct GNUNET_PEERSTORE_WatchContext *wc;
- ev = GNUNET_MQ_msg (hm,
- GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH);
- PEERSTORE_hash_key (sub_system,
- peer,
- key,
- &hm->keyhash);
+ ev = GNUNET_MQ_msg (hm, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH);
+ PEERSTORE_hash_key (sub_system, peer, key, &hm->keyhash);
wc = GNUNET_new (struct GNUNET_PEERSTORE_WatchContext);
wc->callback = callback;
wc->callback_cls = callback_cls;
wc->h = h;
wc->keyhash = hm->keyhash;
if (NULL == h->watches)
- h->watches = GNUNET_CONTAINER_multihashmap_create (5,
- GNUNET_NO);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (h->watches,
- &wc->keyhash,
- wc,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ h->watches = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
+ GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
+ h->watches,
+ &wc->keyhash,
+ wc,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n",
sub_system,
GNUNET_i2s (peer),
key);
- GNUNET_MQ_send (h->mq,
- ev);
+ GNUNET_MQ_send (h->mq, ev);
return wc;
}
diff --git a/src/regex/regex_internal.c b/src/regex/regex_internal.c
index 3f667a11f..55d16129f 100644
--- a/src/regex/regex_internal.c
+++ b/src/regex/regex_internal.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -66,7 +66,7 @@ struct REGEX_INTERNAL_StateSet_MDLL
*/
static void
state_set_append (struct REGEX_INTERNAL_StateSet *set,
- struct REGEX_INTERNAL_State *state)
+ struct REGEX_INTERNAL_State *state)
{
if (set->off == set->size)
GNUNET_array_grow (set->states, set->size, set->size * 2 + 4);
@@ -114,8 +114,7 @@ state_add_transition (struct REGEX_INTERNAL_Context *ctx,
if (NULL == from_state)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not create Transition.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create Transition.\n");
return;
}
@@ -147,7 +146,9 @@ state_add_transition (struct REGEX_INTERNAL_Context *ctx,
/* Add outgoing transition to 'from_state' */
from_state->transition_count++;
GNUNET_CONTAINER_DLL_insert_before (from_state->transitions_head,
- from_state->transitions_tail, oth, t);
+ from_state->transitions_tail,
+ oth,
+ t);
}
@@ -170,7 +171,8 @@ state_remove_transition (struct REGEX_INTERNAL_State *state,
GNUNET_free_non_null (transition->label);
state->transition_count--;
- GNUNET_CONTAINER_DLL_remove (state->transitions_head,
state->transitions_tail,
+ GNUNET_CONTAINER_DLL_remove (state->transitions_head,
+ state->transitions_tail,
transition);
GNUNET_free (transition);
@@ -207,8 +209,7 @@ state_compare (const void *a, const void *b)
* @return number of edges.
*/
static unsigned int
-state_get_edges (struct REGEX_INTERNAL_State *s,
- struct REGEX_BLOCK_Edge *edges)
+state_get_edges (struct REGEX_INTERNAL_State *s, struct REGEX_BLOCK_Edge
*edges)
{
struct REGEX_INTERNAL_Transition *t;
unsigned int count;
@@ -463,10 +464,13 @@ automaton_add_state (struct REGEX_INTERNAL_Automaton *a,
* @param action_cls closure for action.
*/
static void
-automaton_state_traverse (struct REGEX_INTERNAL_State *s, int *marks,
+automaton_state_traverse (struct REGEX_INTERNAL_State *s,
+ int *marks,
unsigned int *count,
- REGEX_INTERNAL_traverse_check check, void *check_cls,
- REGEX_INTERNAL_traverse_action action, void
*action_cls)
+ REGEX_INTERNAL_traverse_check check,
+ void *check_cls,
+ REGEX_INTERNAL_traverse_action action,
+ void *action_cls)
{
struct REGEX_INTERNAL_Transition *t;
@@ -485,8 +489,13 @@ automaton_state_traverse (struct REGEX_INTERNAL_State *s,
int *marks,
if (NULL == check ||
(NULL != check && GNUNET_YES == check (check_cls, s, t)))
{
- automaton_state_traverse (t->to_state, marks, count, check, check_cls,
- action, action_cls);
+ automaton_state_traverse (t->to_state,
+ marks,
+ count,
+ check,
+ check_cls,
+ action,
+ action_cls);
}
}
}
@@ -535,9 +544,13 @@ REGEX_INTERNAL_automaton_traverse (const struct
REGEX_INTERNAL_Automaton *a,
else
s = start;
- automaton_state_traverse (s, marks, &count,
- check, check_cls,
- action, action_cls);
+ automaton_state_traverse (s,
+ marks,
+ &count,
+ check,
+ check_cls,
+ action,
+ action_cls);
}
@@ -582,7 +595,6 @@ struct StringBuffer
* most likely due to increased cache misses.
*/
int16_t synced;
-
};
@@ -595,14 +607,11 @@ struct StringBuffer
* @return 0 if the strings are the same or both NULL, 1 or -1 if not.
*/
static int
-sb_nullstrcmp (const struct StringBuffer *s1,
- const struct StringBuffer *s2)
+sb_nullstrcmp (const struct StringBuffer *s1, const struct StringBuffer *s2)
{
- if ( (GNUNET_YES == s1->null_flag) &&
- (GNUNET_YES == s2->null_flag) )
+ if ((GNUNET_YES == s1->null_flag) && (GNUNET_YES == s2->null_flag))
return 0;
- if ( (GNUNET_YES == s1->null_flag) ||
- (GNUNET_YES == s2->null_flag) )
+ if ((GNUNET_YES == s1->null_flag) || (GNUNET_YES == s2->null_flag))
return -1;
if (s1->slen != s2->slen)
return -1;
@@ -621,8 +630,7 @@ sb_nullstrcmp (const struct StringBuffer *s1,
* @return 0 if the strings are the same, 1 or -1 if not.
*/
static int
-sb_strcmp (const struct StringBuffer *s1,
- const struct StringBuffer *s2)
+sb_strcmp (const struct StringBuffer *s1, const struct StringBuffer *s2)
{
if (s1->slen != s2->slen)
return -1;
@@ -640,8 +648,7 @@ sb_strcmp (const struct StringBuffer *s1,
* @param nlen target length for the buffer, must be at least ret->slen
*/
static void
-sb_realloc (struct StringBuffer *ret,
- size_t nlen)
+sb_realloc (struct StringBuffer *ret, size_t nlen)
{
char *old;
@@ -649,9 +656,7 @@ sb_realloc (struct StringBuffer *ret,
old = ret->abuf;
ret->abuf = GNUNET_malloc (nlen);
ret->blen = nlen;
- GNUNET_memcpy (ret->abuf,
- ret->sbuf,
- ret->slen);
+ GNUNET_memcpy (ret->abuf, ret->sbuf, ret->slen);
ret->sbuf = ret->abuf;
GNUNET_free_non_null (old);
}
@@ -664,17 +669,14 @@ sb_realloc (struct StringBuffer *ret,
* @param sarg string to append
*/
static void
-sb_append (struct StringBuffer *ret,
- const struct StringBuffer *sarg)
+sb_append (struct StringBuffer *ret, const struct StringBuffer *sarg)
{
if (GNUNET_YES == ret->null_flag)
ret->slen = 0;
ret->null_flag = GNUNET_NO;
if (ret->blen < sarg->slen + ret->slen)
sb_realloc (ret, ret->blen + sarg->slen + 128);
- GNUNET_memcpy (&ret->sbuf[ret->slen],
- sarg->sbuf,
- sarg->slen);
+ GNUNET_memcpy (&ret->sbuf[ret->slen], sarg->sbuf, sarg->slen);
ret->slen += sarg->slen;
}
@@ -686,8 +688,7 @@ sb_append (struct StringBuffer *ret,
* @param cstr string to append
*/
static void
-sb_append_cstr (struct StringBuffer *ret,
- const char *cstr)
+sb_append_cstr (struct StringBuffer *ret, const char *cstr)
{
size_t cstr_len = strlen (cstr);
@@ -696,9 +697,7 @@ sb_append_cstr (struct StringBuffer *ret,
ret->null_flag = GNUNET_NO;
if (ret->blen < cstr_len + ret->slen)
sb_realloc (ret, ret->blen + cstr_len + 128);
- GNUNET_memcpy (&ret->sbuf[ret->slen],
- cstr,
- cstr_len);
+ GNUNET_memcpy (&ret->sbuf[ret->slen], cstr, cstr_len);
ret->slen += cstr_len;
}
@@ -714,9 +713,7 @@ sb_append_cstr (struct StringBuffer *ret,
* @param extra_chars how long will the result be, in addition to 'sarg' length
*/
static void
-sb_wrap (struct StringBuffer *ret,
- const char *format,
- size_t extra_chars)
+sb_wrap (struct StringBuffer *ret, const char *format, size_t extra_chars)
{
char *temp;
@@ -725,10 +722,10 @@ sb_wrap (struct StringBuffer *ret,
ret->null_flag = GNUNET_NO;
temp = GNUNET_malloc (ret->slen + extra_chars + 1);
GNUNET_snprintf (temp,
- ret->slen + extra_chars + 1,
- format,
- (int) ret->slen,
- ret->sbuf);
+ ret->slen + extra_chars + 1,
+ format,
+ (int) ret->slen,
+ ret->sbuf);
GNUNET_free_non_null (ret->abuf);
ret->abuf = temp;
ret->sbuf = temp;
@@ -748,21 +745,16 @@ sb_wrap (struct StringBuffer *ret,
*/
static void
sb_printf1 (struct StringBuffer *ret,
- const char *format,
- size_t extra_chars,
- const struct StringBuffer *sarg)
+ const char *format,
+ size_t extra_chars,
+ const struct StringBuffer *sarg)
{
if (ret->blen < sarg->slen + extra_chars + 1)
- sb_realloc (ret,
- sarg->slen + extra_chars + 1);
+ sb_realloc (ret, sarg->slen + extra_chars + 1);
ret->null_flag = GNUNET_NO;
ret->sbuf = ret->abuf;
ret->slen = sarg->slen + extra_chars;
- GNUNET_snprintf (ret->sbuf,
- ret->blen,
- format,
- (int) sarg->slen,
- sarg->sbuf);
+ GNUNET_snprintf (ret->sbuf, ret->blen, format, (int) sarg->slen, sarg->sbuf);
}
@@ -777,24 +769,23 @@ sb_printf1 (struct StringBuffer *ret,
*/
static void
sb_printf2 (struct StringBuffer *ret,
- const char *format,
- size_t extra_chars,
- const struct StringBuffer *sarg1,
- const struct StringBuffer *sarg2)
+ const char *format,
+ size_t extra_chars,
+ const struct StringBuffer *sarg1,
+ const struct StringBuffer *sarg2)
{
if (ret->blen < sarg1->slen + sarg2->slen + extra_chars + 1)
- sb_realloc (ret,
- sarg1->slen + sarg2->slen + extra_chars + 1);
+ sb_realloc (ret, sarg1->slen + sarg2->slen + extra_chars + 1);
ret->null_flag = GNUNET_NO;
ret->slen = sarg1->slen + sarg2->slen + extra_chars;
ret->sbuf = ret->abuf;
GNUNET_snprintf (ret->sbuf,
- ret->blen,
- format,
- (int) sarg1->slen,
- sarg1->sbuf,
- (int) sarg2->slen,
- sarg2->sbuf);
+ ret->blen,
+ format,
+ (int) sarg1->slen,
+ sarg1->sbuf,
+ (int) sarg2->slen,
+ sarg2->sbuf);
}
@@ -811,27 +802,26 @@ sb_printf2 (struct StringBuffer *ret,
*/
static void
sb_printf3 (struct StringBuffer *ret,
- const char *format,
- size_t extra_chars,
- const struct StringBuffer *sarg1,
- const struct StringBuffer *sarg2,
- const struct StringBuffer *sarg3)
+ const char *format,
+ size_t extra_chars,
+ const struct StringBuffer *sarg1,
+ const struct StringBuffer *sarg2,
+ const struct StringBuffer *sarg3)
{
if (ret->blen < sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1)
- sb_realloc (ret,
- sarg1->slen + sarg2->slen + sarg3->slen + extra_chars + 1);
+ sb_realloc (ret, sarg1->slen + sarg2->slen + sarg3->slen + extra_chars +
1);
ret->null_flag = GNUNET_NO;
ret->slen = sarg1->slen + sarg2->slen + sarg3->slen + extra_chars;
ret->sbuf = ret->abuf;
GNUNET_snprintf (ret->sbuf,
- ret->blen,
- format,
- (int) sarg1->slen,
- sarg1->sbuf,
- (int) sarg2->slen,
- sarg2->sbuf,
- (int) sarg3->slen,
- sarg3->sbuf);
+ ret->blen,
+ format,
+ (int) sarg1->slen,
+ sarg1->sbuf,
+ (int) sarg2->slen,
+ sarg2->sbuf,
+ (int) sarg3->slen,
+ sarg3->sbuf);
}
@@ -844,12 +834,10 @@ sb_printf3 (struct StringBuffer *ret,
static void
sb_free (struct StringBuffer *sb)
{
- GNUNET_array_grow (sb->abuf,
- sb->blen,
- 0);
+ GNUNET_array_grow (sb->abuf, sb->blen, 0);
sb->slen = 0;
sb->sbuf = NULL;
- sb->null_flag= GNUNET_YES;
+ sb->null_flag = GNUNET_YES;
}
@@ -860,8 +848,7 @@ sb_free (struct StringBuffer *sb)
* @param out output string
*/
static void
-sb_strdup (struct StringBuffer *out,
- const struct StringBuffer *in)
+sb_strdup (struct StringBuffer *out, const struct StringBuffer *in)
{
out->null_flag = in->null_flag;
@@ -869,9 +856,7 @@ sb_strdup (struct StringBuffer *out,
return;
if (out->blen < in->slen)
{
- GNUNET_array_grow (out->abuf,
- out->blen,
- in->slen);
+ GNUNET_array_grow (out->abuf, out->blen, in->slen);
}
out->sbuf = out->abuf;
out->slen = in->slen;
@@ -886,8 +871,7 @@ sb_strdup (struct StringBuffer *out,
* @param out output string
*/
static void
-sb_strdup_cstr (struct StringBuffer *out,
- const char *cstr)
+sb_strdup_cstr (struct StringBuffer *out, const char *cstr)
{
if (NULL == cstr)
{
@@ -898,9 +882,7 @@ sb_strdup_cstr (struct StringBuffer *out,
out->slen = strlen (cstr);
if (out->blen < out->slen)
{
- GNUNET_array_grow (out->abuf,
- out->blen,
- out->slen);
+ GNUNET_array_grow (out->abuf, out->blen, out->slen);
}
out->sbuf = out->abuf;
GNUNET_memcpy (out->sbuf, cstr, out->slen);
@@ -942,8 +924,7 @@ needs_parentheses (const struct StringBuffer *str)
return GNUNET_YES;
}
/* while '(' before ')', count opening parens */
- while ( (NULL != (op = memchr (pos, '(', end - pos))) &&
- (op < cl) )
+ while ((NULL != (op = memchr (pos, '(', end - pos))) && (op < cl))
{
cnt++;
pos = op + 1;
@@ -979,10 +960,8 @@ remove_parentheses (struct StringBuffer *str)
if (0)
return;
sbuf = str->sbuf;
- if ( (GNUNET_YES == str->null_flag) ||
- (1 >= (slen = str->slen)) ||
- ('(' != str->sbuf[0]) ||
- (')' != str->sbuf[slen - 1]) )
+ if ((GNUNET_YES == str->null_flag) || (1 >= (slen = str->slen)) ||
+ ('(' != str->sbuf[0]) || (')' != str->sbuf[slen - 1]))
return;
cnt = 0;
pos = &sbuf[1];
@@ -991,19 +970,16 @@ remove_parentheses (struct StringBuffer *str)
cp = memchr (pos, ')', end - pos);
while (NULL != cp)
{
- while ( (NULL != op) &&
- (op < cp) )
+ while ((NULL != op) && (op < cp))
{
cnt++;
pos = op + 1;
op = memchr (pos, '(', end - pos);
}
- while ( (NULL != cp) &&
- ( (NULL == op) ||
- (cp < op) ) )
+ while ((NULL != cp) && ((NULL == op) || (cp < op)))
{
if (0 == cnt)
- return; /* can't strip parens */
+ return; /* can't strip parens */
cnt--;
pos = cp + 1;
cp = memchr (pos, ')', end - pos);
@@ -1030,12 +1006,9 @@ remove_parentheses (struct StringBuffer *str)
static int
has_epsilon (const struct StringBuffer *str)
{
- return
- (GNUNET_YES != str->null_flag) &&
- (0 < str->slen) &&
- ('(' == str->sbuf[0]) &&
- ('|' == str->sbuf[1]) &&
- (')' == str->sbuf[str->slen - 1]);
+ return (GNUNET_YES != str->null_flag) && (0 < str->slen) &&
+ ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) &&
+ (')' == str->sbuf[str->slen - 1]);
}
@@ -1049,25 +1022,20 @@ has_epsilon (const struct StringBuffer *str)
* epsilon could be found, NULL if 'str' was NULL
*/
static void
-remove_epsilon (const struct StringBuffer *str,
- struct StringBuffer *ret)
+remove_epsilon (const struct StringBuffer *str, struct StringBuffer *ret)
{
if (GNUNET_YES == str->null_flag)
{
ret->null_flag = GNUNET_YES;
return;
}
- if ( (str->slen > 1) &&
- ('(' == str->sbuf[0]) &&
- ('|' == str->sbuf[1]) &&
- (')' == str->sbuf[str->slen - 1]) )
+ if ((str->slen > 1) && ('(' == str->sbuf[0]) && ('|' == str->sbuf[1]) &&
+ (')' == str->sbuf[str->slen - 1]))
{
/* remove epsilon */
if (ret->blen < str->slen - 3)
{
- GNUNET_array_grow (ret->abuf,
- ret->blen,
- str->slen - 3);
+ GNUNET_array_grow (ret->abuf, ret->blen, str->slen - 3);
}
ret->sbuf = ret->abuf;
ret->slen = str->slen - 3;
@@ -1089,13 +1057,12 @@ remove_epsilon (const struct StringBuffer *str,
*/
static int
sb_strncmp (const struct StringBuffer *str1,
- const struct StringBuffer *str2, size_t n)
+ const struct StringBuffer *str2,
+ size_t n)
{
size_t max;
- if ( (str1->slen != str2->slen) &&
- ( (str1->slen < n) ||
- (str2->slen < n) ) )
+ if ((str1->slen != str2->slen) && ((str1->slen < n) || (str2->slen < n)))
return -1;
max = GNUNET_MAX (str1->slen, str2->slen);
if (max > n)
@@ -1114,8 +1081,7 @@ sb_strncmp (const struct StringBuffer *str1,
* @return -1 if any of the strings is NULL, 0 if equal, non 0 otherwise
*/
static int
-sb_strncmp_cstr (const struct StringBuffer *str1,
- const char *str2, size_t n)
+sb_strncmp_cstr (const struct StringBuffer *str1, const char *str2, size_t n)
{
if (str1->slen < n)
return -1;
@@ -1131,8 +1097,7 @@ sb_strncmp_cstr (const struct StringBuffer *str1,
* @param n desired target length
*/
static void
-sb_init (struct StringBuffer *sb,
- size_t n)
+sb_init (struct StringBuffer *sb, size_t n)
{
sb->null_flag = GNUNET_NO;
sb->abuf = sb->sbuf = (0 == n) ? NULL : GNUNET_malloc (n);
@@ -1152,12 +1117,11 @@ sb_init (struct StringBuffer *sb,
*/
static int
sb_strkcmp (const struct StringBuffer *str1,
- const struct StringBuffer *str2, size_t k)
+ const struct StringBuffer *str2,
+ size_t k)
{
- if ( (GNUNET_YES == str1->null_flag) ||
- (GNUNET_YES == str2->null_flag) ||
- (k > str1->slen) ||
- (str1->slen - k != str2->slen) )
+ if ((GNUNET_YES == str1->null_flag) || (GNUNET_YES == str2->null_flag) ||
+ (k > str1->slen) || (str1->slen - k != str2->slen))
return -1;
return memcmp (&str1->sbuf[k], str2->sbuf, str2->slen);
}
@@ -1172,7 +1136,8 @@ sb_strkcmp (const struct StringBuffer *str1,
* @param s current state.
*/
static void
-number_states (void *cls, const unsigned int count,
+number_states (void *cls,
+ const unsigned int count,
struct REGEX_INTERNAL_State *s)
{
struct REGEX_INTERNAL_State **states = cls;
@@ -1183,10 +1148,9 @@ number_states (void *cls, const unsigned int count,
}
-
-#define PRIS(a) \
+#define PRIS(a) \
((GNUNET_YES == a.null_flag) ? 6 : (int) a.slen), \
- ((GNUNET_YES == a.null_flag) ? "(null)" : a.sbuf)
+ ((GNUNET_YES == a.null_flag) ? "(null)" : a.sbuf)
/**
@@ -1205,12 +1169,12 @@ number_states (void *cls, const unsigned int count,
*/
static void
automaton_create_proofs_simplify (const struct StringBuffer *R_last_ij,
- const struct StringBuffer *R_last_ik,
+ const struct StringBuffer *R_last_ik,
const struct StringBuffer *R_last_kk,
- const struct StringBuffer *R_last_kj,
+ const struct StringBuffer *R_last_kj,
struct StringBuffer *R_cur_ij,
- struct StringBuffer *R_cur_l,
- struct StringBuffer *R_cur_r)
+ struct StringBuffer *R_cur_l,
+ struct StringBuffer *R_cur_r)
{
struct StringBuffer R_temp_ij;
struct StringBuffer R_temp_ik;
@@ -1235,9 +1199,9 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
* R_cur_r == R^{(k-1)}_{ik} ( R^{(k-1)}_{kk} )^* R^{(k-1)}_{kj}
*/
- if ( (GNUNET_YES == R_last_ij->null_flag) &&
- ( (GNUNET_YES == R_last_ik->null_flag) ||
- (GNUNET_YES == R_last_kj->null_flag)))
+ if ((GNUNET_YES == R_last_ij->null_flag) &&
+ ((GNUNET_YES == R_last_ik->null_flag) ||
+ (GNUNET_YES == R_last_kj->null_flag)))
{
/* R^{(k)}_{ij} = N | N */
R_cur_ij->null_flag = GNUNET_YES;
@@ -1245,8 +1209,8 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
return;
}
- if ( (GNUNET_YES == R_last_ik->null_flag) ||
- (GNUNET_YES == R_last_kj->null_flag) )
+ if ((GNUNET_YES == R_last_ik->null_flag) ||
+ (GNUNET_YES == R_last_kj->null_flag))
{
/* R^{(k)}_{ij} = R^{(k-1)}_{ij} | N */
if (GNUNET_YES == R_last_ij->synced)
@@ -1299,9 +1263,9 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
remove_epsilon (R_last_ij, &R_temp_ij);
remove_parentheses (&R_temp_ij);
- if ( (0 == sb_strcmp (&R_temp_ij, &R_temp_ik)) &&
- (0 == sb_strcmp (&R_temp_ik, &R_temp_kk)) &&
- (0 == sb_strcmp (&R_temp_kk, &R_temp_kj)) )
+ if ((0 == sb_strcmp (&R_temp_ij, &R_temp_ik)) &&
+ (0 == sb_strcmp (&R_temp_ik, &R_temp_kk)) &&
+ (0 == sb_strcmp (&R_temp_kk, &R_temp_kj)))
{
if (0 == R_temp_ij.slen)
{
@@ -1340,7 +1304,8 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
sb_printf1 (R_cur_r, "%.*s+", 1, &R_temp_ij);
}
}
- else if ( (0 == ij_ik_cmp) && (0 == clean_kk_kj_cmp) && (0 !=
clean_ik_kk_cmp) )
+ else if ((0 == ij_ik_cmp) && (0 == clean_kk_kj_cmp) &&
+ (0 != clean_ik_kk_cmp))
{
/* a|ab*b = ab* */
if (0 == R_last_kk->slen)
@@ -1351,7 +1316,8 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, R_last_kk);
R_cur_l->null_flag = GNUNET_YES;
}
- else if ( (0 == ij_kj_cmp) && (0 == clean_ik_kk_cmp) && (0 !=
clean_kk_kj_cmp))
+ else if ((0 == ij_kj_cmp) && (0 == clean_ik_kk_cmp) &&
+ (0 != clean_kk_kj_cmp))
{
/* a|bb*a = b*a */
if (R_last_kk->slen < 1)
@@ -1365,8 +1331,8 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
R_cur_l->null_flag = GNUNET_YES;
}
- else if ( (0 == ij_ik_cmp) && (0 == kk_kj_cmp) && (! has_epsilon
(R_last_ij)) &&
- has_epsilon (R_last_kk))
+ else if ((0 == ij_ik_cmp) && (0 == kk_kj_cmp) &&
+ (! has_epsilon (R_last_ij)) && has_epsilon (R_last_kk))
{
/* a|a(e|b)*(e|b) = a|ab* = a|a|ab|abb|abbb|... = ab* */
if (needs_parentheses (&R_temp_kk))
@@ -1375,8 +1341,8 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
sb_printf2 (R_cur_r, "%.*s%.*s*", 1, R_last_ij, &R_temp_kk);
R_cur_l->null_flag = GNUNET_YES;
}
- else if ( (0 == ij_kj_cmp) && (0 == ik_kk_cmp) && (! has_epsilon
(R_last_ij)) &&
- has_epsilon (R_last_kk))
+ else if ((0 == ij_kj_cmp) && (0 == ik_kk_cmp) &&
+ (! has_epsilon (R_last_ij)) && has_epsilon (R_last_kk))
{
/* a|(e|b)(e|b)*a = a|b*a = a|a|ba|bba|bbba|... = b*a */
if (needs_parentheses (&R_temp_kk))
@@ -1403,15 +1369,12 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
length = R_temp_kk.slen - R_last_ik->slen;
/* a(ba)*bx = (ab)+x */
- if ( (length > 0) &&
- (GNUNET_YES != R_last_kk->null_flag) &&
- (0 < R_last_kk->slen) &&
- (GNUNET_YES != R_last_kj->null_flag) &&
- (0 < R_last_kj->slen) &&
- (GNUNET_YES != R_last_ik->null_flag) &&
- (0 < R_last_ik->slen) &&
- (0 == sb_strkcmp (&R_temp_kk, R_last_ik, length)) &&
- (0 == sb_strncmp (&R_temp_kk, R_last_kj, length)) )
+ if ((length > 0) && (GNUNET_YES != R_last_kk->null_flag) &&
+ (0 < R_last_kk->slen) && (GNUNET_YES != R_last_kj->null_flag) &&
+ (0 < R_last_kj->slen) && (GNUNET_YES != R_last_ik->null_flag) &&
+ (0 < R_last_ik->slen) &&
+ (0 == sb_strkcmp (&R_temp_kk, R_last_ik, length)) &&
+ (0 == sb_strncmp (&R_temp_kk, R_last_kj, length)))
{
struct StringBuffer temp_a;
struct StringBuffer temp_b;
@@ -1430,9 +1393,8 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
temp_b.slen = length_r;
/* e|(ab)+ = (ab)* */
- if ( (GNUNET_YES != R_cur_l->null_flag) &&
- (0 == R_cur_l->slen) &&
- (0 == temp_b.slen) )
+ if ((GNUNET_YES != R_cur_l->null_flag) && (0 == R_cur_l->slen) &&
+ (0 == temp_b.slen))
{
sb_printf2 (R_cur_r, "(%.*s%.*s)*", 3, R_last_ik, &temp_a);
sb_free (R_cur_l);
@@ -1460,9 +1422,8 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
sb_printf1 (R_cur_r, "%.*s*", 1, &R_temp_kk);
}
/* aa*a = a+a */
- else if ( (0 == clean_ik_kk_cmp) &&
- (0 == clean_kk_kj_cmp) &&
- (! has_epsilon (R_last_ik)) )
+ else if ((0 == clean_ik_kk_cmp) && (0 == clean_kk_kj_cmp) &&
+ (! has_epsilon (R_last_ik)))
{
if (needs_parentheses (&R_temp_kk))
sb_printf2 (R_cur_r, "(%.*s)+%.*s", 3, &R_temp_kk, &R_temp_kk);
@@ -1477,9 +1438,8 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
*/
else
{
- eps_check =
- (has_epsilon (R_last_ik) + has_epsilon (R_last_kk) +
- has_epsilon (R_last_kj));
+ eps_check = (has_epsilon (R_last_ik) + has_epsilon (R_last_kk) +
+ has_epsilon (R_last_kj));
if (1 == eps_check)
{
@@ -1538,18 +1498,26 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
{
if (needs_parentheses (&R_temp_kk))
{
- sb_printf3 (R_cur_r, "%.*s(%.*s)*%.*s", 3, R_last_ik, &R_temp_kk,
- R_last_kj);
+ sb_printf3 (R_cur_r,
+ "%.*s(%.*s)*%.*s",
+ 3,
+ R_last_ik,
+ &R_temp_kk,
+ R_last_kj);
}
else
{
- sb_printf3 (R_cur_r, "%.*s%.*s*%.*s", 1, R_last_ik, &R_temp_kk,
- R_last_kj);
+ sb_printf3 (R_cur_r,
+ "%.*s%.*s*%.*s",
+ 1,
+ R_last_ik,
+ &R_temp_kk,
+ R_last_kj);
}
}
else
{
- sb_printf2 (R_cur_r, "%.*s%.*s", 0, R_last_ik, R_last_kj);
+ sb_printf2 (R_cur_r, "%.*s%.*s", 0, R_last_ik, R_last_kj);
}
}
}
@@ -1558,15 +1526,13 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
sb_free (&R_temp_kk);
sb_free (&R_temp_kj);
- if ( (GNUNET_YES == R_cur_l->null_flag) &&
- (GNUNET_YES == R_cur_r->null_flag) )
+ if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag))
{
R_cur_ij->null_flag = GNUNET_YES;
return;
}
- if ( (GNUNET_YES != R_cur_l->null_flag) &&
- (GNUNET_YES == R_cur_r->null_flag) )
+ if ((GNUNET_YES != R_cur_l->null_flag) && (GNUNET_YES == R_cur_r->null_flag))
{
struct StringBuffer tmp;
@@ -1576,8 +1542,7 @@ automaton_create_proofs_simplify (const struct
StringBuffer *R_last_ij,
return;
}
- if ( (GNUNET_YES == R_cur_l->null_flag) &&
- (GNUNET_YES != R_cur_r->null_flag) )
+ if ((GNUNET_YES == R_cur_l->null_flag) && (GNUNET_YES != R_cur_r->null_flag))
{
struct StringBuffer tmp;
@@ -1629,8 +1594,7 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton
*a)
R_last = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n);
R_cur = GNUNET_malloc_large (sizeof (struct StringBuffer) * n * n);
- if ( (NULL == R_last) ||
- (NULL == R_cur) )
+ if ((NULL == R_last) || (NULL == R_cur))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
GNUNET_free_non_null (R_cur);
@@ -1639,14 +1603,18 @@ automaton_create_proofs (struct
REGEX_INTERNAL_Automaton *a)
}
/* create depth-first numbering of the states, initializes 'state' */
- REGEX_INTERNAL_automaton_traverse (a, a->start, NULL, NULL, &number_states,
- states);
+ REGEX_INTERNAL_automaton_traverse (a,
+ a->start,
+ NULL,
+ NULL,
+ &number_states,
+ states);
for (i = 0; i < n; i++)
GNUNET_assert (NULL != states[i]);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
- R_last[i *n + j].null_flag = GNUNET_YES;
+ R_last[i * n + j].null_flag = GNUNET_YES;
/* Compute regular expressions of length "1" between each pair of states */
for (i = 0; i < n; i++)
@@ -1660,8 +1628,8 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton
*a)
}
else
{
- sb_append_cstr (&R_last[i * n + j], "|");
- sb_append_cstr (&R_last[i * n + j], t->label);
+ sb_append_cstr (&R_last[i * n + j], "|");
+ sb_append_cstr (&R_last[i * n + j], t->label);
}
}
/* add self-loop: i is reachable from i via epsilon-transition */
@@ -1695,10 +1663,13 @@ automaton_create_proofs (struct
REGEX_INTERNAL_Automaton *a)
*/
/* Create R_cur[i][j] and simplify the expression */
- automaton_create_proofs_simplify (&R_last[i * n + j], &R_last[i * n +
k],
- &R_last[k * n + k], &R_last[k * n +
j],
+ automaton_create_proofs_simplify (&R_last[i * n + j],
+ &R_last[i * n + k],
+ &R_last[k * n + k],
+ &R_last[k * n + j],
&R_cur[i * n + j],
- &R_cur_l, &R_cur_r);
+ &R_cur_l,
+ &R_cur_r);
}
}
/* set R_last = R_cur */
@@ -1718,8 +1689,9 @@ automaton_create_proofs (struct REGEX_INTERNAL_Automaton
*a)
if (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag)
{
states[i]->proof = GNUNET_strndup (R_last[a->start->dfs_id * n + i].sbuf,
- R_last[a->start->dfs_id * n + i].slen);
- GNUNET_CRYPTO_hash (states[i]->proof, strlen (states[i]->proof),
+ R_last[a->start->dfs_id * n +
i].slen);
+ GNUNET_CRYPTO_hash (states[i]->proof,
+ strlen (states[i]->proof),
&states[i]->hash);
}
}
@@ -1731,22 +1703,21 @@ automaton_create_proofs (struct
REGEX_INTERNAL_Automaton *a)
{
if (states[i]->accepting)
{
- if ( (0 == complete_regex.slen) &&
- (0 < R_last[a->start->dfs_id * n + i].slen) )
+ if ((0 == complete_regex.slen) &&
+ (0 < R_last[a->start->dfs_id * n + i].slen))
{
- sb_append (&complete_regex,
- &R_last[a->start->dfs_id * n + i]);
+ sb_append (&complete_regex, &R_last[a->start->dfs_id * n + i]);
}
- else if ( (GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) &&
- (0 < R_last[a->start->dfs_id * n + i].slen) )
+ else if ((GNUNET_YES != R_last[a->start->dfs_id * n + i].null_flag) &&
+ (0 < R_last[a->start->dfs_id * n + i].slen))
{
- sb_append_cstr (&complete_regex, "|");
- sb_append (&complete_regex,
- &R_last[a->start->dfs_id * n + i]);
+ sb_append_cstr (&complete_regex, "|");
+ sb_append (&complete_regex, &R_last[a->start->dfs_id * n + i]);
}
}
}
- a->canonical_regex = GNUNET_strndup (complete_regex.sbuf,
complete_regex.slen);
+ a->canonical_regex =
+ GNUNET_strndup (complete_regex.sbuf, complete_regex.slen);
/* cleanup */
sb_free (&complete_regex);
@@ -1807,10 +1778,7 @@ dfa_state_create (struct REGEX_INTERNAL_Context *ctx,
for (i = 0; i < nfa_states->off; i++)
{
cstate = nfa_states->states[i];
- GNUNET_snprintf (pos,
- pos - s->name + len,
- "%i,",
- cstate->id);
+ GNUNET_snprintf (pos, pos - s->name + len, "%i,", cstate->id);
pos += strlen (pos);
/* Add a transition for each distinct label to NULL state */
@@ -1911,7 +1879,12 @@ dfa_remove_unreachable_states (struct
REGEX_INTERNAL_Automaton *a)
s->marked = GNUNET_NO;
/* 2. traverse dfa from start state and mark all visited states */
- REGEX_INTERNAL_automaton_traverse (a, a->start, NULL, NULL, &mark_states,
NULL);
+ REGEX_INTERNAL_automaton_traverse (a,
+ a->start,
+ NULL,
+ NULL,
+ &mark_states,
+ NULL);
/* 3. delete all states that were not visited */
for (s = a->states_head; NULL != s; s = s_next)
@@ -1990,7 +1963,7 @@ dfa_merge_nondistinguishable_states (struct
REGEX_INTERNAL_Context *ctx,
unsigned long long idx;
unsigned long long idx1;
- if ( (NULL == a) || (0 == a->state_count) )
+ if ((NULL == a) || (0 == a->state_count))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not merge nondistinguishable states, automaton was
NULL.\n");
@@ -1998,7 +1971,8 @@ dfa_merge_nondistinguishable_states (struct
REGEX_INTERNAL_Context *ctx,
}
state_cnt = a->state_count;
- table = GNUNET_malloc_large ((sizeof (uint32_t) * state_cnt * state_cnt /
32) + sizeof (uint32_t));
+ table = GNUNET_malloc_large (
+ (sizeof (uint32_t) * state_cnt * state_cnt / 32) + sizeof (uint32_t));
if (NULL == table)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
@@ -2011,10 +1985,10 @@ dfa_merge_nondistinguishable_states (struct
REGEX_INTERNAL_Context *ctx,
/* Mark all pairs of accepting/!accepting states */
for (s1 = a->states_head; NULL != s1; s1 = s1->next)
for (s2 = a->states_head; NULL != s2; s2 = s2->next)
- if ( (s1->accepting && !s2->accepting) ||
- (!s1->accepting && s2->accepting) )
+ if ((s1->accepting && ! s2->accepting) ||
+ (! s1->accepting && s2->accepting))
{
- idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
+ idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
table[idx / 32] |= (1U << (idx % 32));
}
@@ -2027,7 +2001,7 @@ dfa_merge_nondistinguishable_states (struct
REGEX_INTERNAL_Context *ctx,
{
for (s2 = a->states_head; NULL != s2 && s1 != s2; s2 = s2->next)
{
- idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
+ idx = (unsigned long long) s1->marked * state_cnt + s2->marked;
if (0 != (table[idx / 32] & (1U << (idx % 32))))
continue;
num_equal_edges = 0;
@@ -2036,28 +2010,30 @@ dfa_merge_nondistinguishable_states (struct
REGEX_INTERNAL_Context *ctx,
for (t2 = s2->transitions_head; NULL != t2; t2 = t2->next)
{
if (0 == strcmp (t1->label, t2->label))
- {
- num_equal_edges++;
- /* same edge, but targets definitively different, so we're
different
+ {
+ num_equal_edges++;
+ /* same edge, but targets definitively different, so we're
different
as well */
- if (t1->to_state->marked > t2->to_state->marked)
- idx1 = (unsigned long long) t1->to_state->marked * state_cnt +
t2->to_state->marked;
- else
- idx1 = (unsigned long long) t2->to_state->marked * state_cnt +
t1->to_state->marked;
- if (0 != (table[idx1 / 32] & (1U << (idx1 % 32))))
- {
- table[idx / 32] |= (1U << (idx % 32));
- change = 1; /* changed a marker, need to run again */
- }
- }
- }
+ if (t1->to_state->marked > t2->to_state->marked)
+ idx1 = (unsigned long long) t1->to_state->marked * state_cnt +
+ t2->to_state->marked;
+ else
+ idx1 = (unsigned long long) t2->to_state->marked * state_cnt +
+ t1->to_state->marked;
+ if (0 != (table[idx1 / 32] & (1U << (idx1 % 32))))
+ {
+ table[idx / 32] |= (1U << (idx % 32));
+ change = 1; /* changed a marker, need to run again */
+ }
+ }
+ }
}
- if ( (num_equal_edges != s1->transition_count) ||
- (num_equal_edges != s2->transition_count) )
+ if ((num_equal_edges != s1->transition_count) ||
+ (num_equal_edges != s2->transition_count))
{
/* Make sure ALL edges of possible equal states are the same */
- table[idx / 32] |= (1U << (idx % 32));
- change = 1; /* changed a marker, need to run again */
+ table[idx / 32] |= (1U << (idx % 32));
+ change = 1; /* changed a marker, need to run again */
}
}
}
@@ -2145,7 +2121,9 @@ struct REGEX_INTERNAL_Strided_Context
* @param s current state in the depth-first traversal
*/
static void
-dfa_add_multi_strides_helper (void *cls, const unsigned int depth, char *label,
+dfa_add_multi_strides_helper (void *cls,
+ const unsigned int depth,
+ char *label,
struct REGEX_INTERNAL_State *start,
struct REGEX_INTERNAL_State *s)
{
@@ -2159,7 +2137,8 @@ dfa_add_multi_strides_helper (void *cls, const unsigned
int depth, char *label,
t->label = GNUNET_strdup (label);
t->to_state = s;
t->from_state = start;
- GNUNET_CONTAINER_DLL_insert (ctx->transitions_head, ctx->transitions_tail,
+ GNUNET_CONTAINER_DLL_insert (ctx->transitions_head,
+ ctx->transitions_tail,
t);
}
else
@@ -2178,7 +2157,10 @@ dfa_add_multi_strides_helper (void *cls, const unsigned
int depth, char *label,
else
new_label = GNUNET_strdup (t->label);
- dfa_add_multi_strides_helper (cls, (depth + 1), new_label, start,
+ dfa_add_multi_strides_helper (cls,
+ (depth + 1),
+ new_label,
+ start,
t->to_state);
}
}
@@ -2195,7 +2177,8 @@ dfa_add_multi_strides_helper (void *cls, const unsigned
int depth, char *label,
* @param s current state.
*/
static void
-dfa_add_multi_strides (void *cls, const unsigned int count,
+dfa_add_multi_strides (void *cls,
+ const unsigned int count,
struct REGEX_INTERNAL_State *s)
{
dfa_add_multi_strides_helper (cls, 0, NULL, s, s);
@@ -2211,10 +2194,10 @@ dfa_add_multi_strides (void *cls, const unsigned int
count,
*/
void
REGEX_INTERNAL_dfa_add_multi_strides (struct REGEX_INTERNAL_Context *regex_ctx,
- struct REGEX_INTERNAL_Automaton *dfa,
- const unsigned int stride_len)
+ struct REGEX_INTERNAL_Automaton *dfa,
+ const unsigned int stride_len)
{
- struct REGEX_INTERNAL_Strided_Context ctx = { stride_len, NULL, NULL };
+ struct REGEX_INTERNAL_Strided_Context ctx = {stride_len, NULL, NULL};
struct REGEX_INTERNAL_Transition *t;
struct REGEX_INTERNAL_Transition *t_next;
@@ -2222,8 +2205,12 @@ REGEX_INTERNAL_dfa_add_multi_strides (struct
REGEX_INTERNAL_Context *regex_ctx,
return;
/* Compute the new transitions of given stride_len */
- REGEX_INTERNAL_automaton_traverse (dfa, dfa->start, NULL, NULL,
- &dfa_add_multi_strides, &ctx);
+ REGEX_INTERNAL_automaton_traverse (dfa,
+ dfa->start,
+ NULL,
+ NULL,
+ &dfa_add_multi_strides,
+ &ctx);
/* Add all the new transitions to the automaton. */
for (t = ctx.transitions_head; NULL != t; t = t_next)
@@ -2255,7 +2242,8 @@ REGEX_INTERNAL_dfa_add_multi_strides (struct
REGEX_INTERNAL_Context *regex_ctx,
void
dfa_compress_paths_helper (struct REGEX_INTERNAL_Automaton *dfa,
struct REGEX_INTERNAL_State *start,
- struct REGEX_INTERNAL_State *cur, char *label,
+ struct REGEX_INTERNAL_State *cur,
+ char *label,
unsigned int max_len,
struct REGEX_INTERNAL_Transition **transitions_head,
struct REGEX_INTERNAL_Transition **transitions_tail)
@@ -2266,8 +2254,8 @@ dfa_compress_paths_helper (struct
REGEX_INTERNAL_Automaton *dfa,
if (NULL != label &&
((cur->incoming_transition_count > 1 || GNUNET_YES == cur->accepting ||
- GNUNET_YES == cur->marked) || (start != dfa->start && max_len > 0 &&
- max_len == strlen (label)) ||
+ GNUNET_YES == cur->marked) ||
+ (start != dfa->start && max_len > 0 && max_len == strlen (label)) ||
(start == dfa->start && GNUNET_REGEX_INITIAL_BYTES == strlen (label))))
{
t = GNUNET_new (struct REGEX_INTERNAL_Transition);
@@ -2278,7 +2266,12 @@ dfa_compress_paths_helper (struct
REGEX_INTERNAL_Automaton *dfa,
if (GNUNET_NO == cur->marked)
{
- dfa_compress_paths_helper (dfa, cur, cur, NULL, max_len,
transitions_head,
+ dfa_compress_paths_helper (dfa,
+ cur,
+ cur,
+ NULL,
+ max_len,
+ transitions_head,
transitions_tail);
}
return;
@@ -2301,8 +2294,13 @@ dfa_compress_paths_helper (struct
REGEX_INTERNAL_Automaton *dfa,
if (t->to_state != cur)
{
- dfa_compress_paths_helper (dfa, start, t->to_state, new_label, max_len,
- transitions_head, transitions_tail);
+ dfa_compress_paths_helper (dfa,
+ start,
+ t->to_state,
+ new_label,
+ max_len,
+ transitions_head,
+ transitions_tail);
}
GNUNET_free (new_label);
}
@@ -2319,7 +2317,8 @@ dfa_compress_paths_helper (struct
REGEX_INTERNAL_Automaton *dfa,
*/
static void
dfa_compress_paths (struct REGEX_INTERNAL_Context *regex_ctx,
- struct REGEX_INTERNAL_Automaton *dfa, unsigned int max_len)
+ struct REGEX_INTERNAL_Automaton *dfa,
+ unsigned int max_len)
{
struct REGEX_INTERNAL_State *s;
struct REGEX_INTERNAL_State *s_next;
@@ -2349,8 +2348,13 @@ dfa_compress_paths (struct REGEX_INTERNAL_Context
*regex_ctx,
}
/* Add strides and mark states that can be deleted. */
- dfa_compress_paths_helper (dfa, dfa->start, dfa->start, NULL, max_len,
- &transitions_head, &transitions_tail);
+ dfa_compress_paths_helper (dfa,
+ dfa->start,
+ dfa->start,
+ NULL,
+ max_len,
+ &transitions_head,
+ &transitions_tail);
/* Add all the new transitions to the automaton. */
for (t = transitions_head; NULL != t; t = t_next)
@@ -2486,8 +2490,9 @@ nfa_state_create (struct REGEX_INTERNAL_Context *ctx, int
accepting)
*/
static void
nfa_closure_set_create (struct REGEX_INTERNAL_StateSet *ret,
- struct REGEX_INTERNAL_Automaton *nfa,
- struct REGEX_INTERNAL_StateSet *states, const char
*label)
+ struct REGEX_INTERNAL_Automaton *nfa,
+ struct REGEX_INTERNAL_StateSet *states,
+ const char *label)
{
struct REGEX_INTERNAL_State *s;
unsigned int i;
@@ -2516,23 +2521,27 @@ nfa_closure_set_create (struct REGEX_INTERNAL_StateSet
*ret,
while (NULL != (currentstate = cls_stack.tail))
{
- GNUNET_CONTAINER_MDLL_remove (ST, cls_stack.head, cls_stack.tail,
- currentstate);
+ GNUNET_CONTAINER_MDLL_remove (ST,
+ cls_stack.head,
+ cls_stack.tail,
+ currentstate);
cls_stack.len--;
for (ctran = currentstate->transitions_head; NULL != ctran;
- ctran = ctran->next)
+ ctran = ctran->next)
{
- if (NULL == (clsstate = ctran->to_state))
- continue;
- if (0 != clsstate->contained)
- continue;
- if (0 != nullstrcmp (label, ctran->label))
- continue;
- state_set_append (ret, clsstate);
- GNUNET_CONTAINER_MDLL_insert_tail (ST, cls_stack.head, cls_stack.tail,
- clsstate);
- cls_stack.len++;
- clsstate->contained = 1;
+ if (NULL == (clsstate = ctran->to_state))
+ continue;
+ if (0 != clsstate->contained)
+ continue;
+ if (0 != nullstrcmp (label, ctran->label))
+ continue;
+ state_set_append (ret, clsstate);
+ GNUNET_CONTAINER_MDLL_insert_tail (ST,
+ cls_stack.head,
+ cls_stack.tail,
+ clsstate);
+ cls_stack.len++;
+ clsstate->contained = 1;
}
}
}
@@ -2540,7 +2549,9 @@ nfa_closure_set_create (struct REGEX_INTERNAL_StateSet
*ret,
ret->states[i]->contained = 0;
if (ret->off > 1)
- qsort (ret->states, ret->off, sizeof (struct REGEX_INTERNAL_State *),
+ qsort (ret->states,
+ ret->off,
+ sizeof (struct REGEX_INTERNAL_State *),
&state_compare);
}
@@ -2598,8 +2609,9 @@ nfa_add_star_op (struct REGEX_INTERNAL_Context *ctx)
if (NULL == a)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "nfa_add_star_op failed, because there was no element on the
stack");
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ "nfa_add_star_op failed, because there was no element on the stack");
return;
}
@@ -2638,8 +2650,9 @@ nfa_add_plus_op (struct REGEX_INTERNAL_Context *ctx)
if (NULL == a)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "nfa_add_plus_op failed, because there was no element on the
stack");
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ "nfa_add_plus_op failed, because there was no element on the stack");
return;
}
@@ -2667,8 +2680,9 @@ nfa_add_question_op (struct REGEX_INTERNAL_Context *ctx)
a = ctx->stack_tail;
if (NULL == a)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "nfa_add_question_op failed, because there was no element on
the stack");
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ "nfa_add_question_op failed, because there was no element on the stack");
return;
}
@@ -2803,7 +2817,7 @@ REGEX_INTERNAL_construct_nfa (const char *regex, const
size_t len)
{
int altcount;
int atomcount;
- } *p;
+ } * p;
if (NULL == regex || 0 == strlen (regex) || 0 == len)
{
@@ -2935,7 +2949,12 @@ REGEX_INTERNAL_construct_nfa (const char *regex, const
size_t len)
nfa->regex = GNUNET_strdup (regex);
/* create depth-first numbering of the states for pretty printing */
- REGEX_INTERNAL_automaton_traverse (nfa, NULL, NULL, NULL, &number_states,
NULL);
+ REGEX_INTERNAL_automaton_traverse (nfa,
+ NULL,
+ NULL,
+ NULL,
+ &number_states,
+ NULL);
/* No multistriding added so far */
nfa->is_multistrided = GNUNET_NO;
@@ -2997,7 +3016,7 @@ construct_dfa_states (struct REGEX_INTERNAL_Context *ctx,
if (0 == state_set_compare (&state_iter->nfa_set, &nfa_set))
{
state_contains = state_iter;
- break;
+ break;
}
}
if (NULL == state_contains)
@@ -3034,7 +3053,8 @@ construct_dfa_states (struct REGEX_INTERNAL_Context *ctx,
* @return DFA, needs to be freed using REGEX_INTERNAL_automaton_destroy.
*/
struct REGEX_INTERNAL_Automaton *
-REGEX_INTERNAL_construct_dfa (const char *regex, const size_t len,
+REGEX_INTERNAL_construct_dfa (const char *regex,
+ const size_t len,
unsigned int max_path_len)
{
struct REGEX_INTERNAL_Context ctx;
@@ -3130,8 +3150,7 @@ REGEX_INTERNAL_automaton_destroy (struct
REGEX_INTERNAL_Automaton *a)
* @return 0 if string matches, non-0 otherwise
*/
static int
-evaluate_dfa (struct REGEX_INTERNAL_Automaton *a,
- const char *string)
+evaluate_dfa (struct REGEX_INTERNAL_Automaton *a, const char *string)
{
const char *strp;
struct REGEX_INTERNAL_State *s;
@@ -3173,8 +3192,7 @@ evaluate_dfa (struct REGEX_INTERNAL_Automaton *a,
* @return 0 if string matches, non-0 otherwise
*/
static int
-evaluate_nfa (struct REGEX_INTERNAL_Automaton *a,
- const char *string)
+evaluate_nfa (struct REGEX_INTERNAL_Automaton *a, const char *string)
{
const char *strp;
char str[2];
@@ -3215,7 +3233,7 @@ evaluate_nfa (struct REGEX_INTERNAL_Automaton *a,
for (i = 0; i < sset.off; i++)
{
s = sset.states[i];
- if ( (NULL != s) && (s->accepting) )
+ if ((NULL != s) && (s->accepting))
{
result = 0;
break;
@@ -3235,8 +3253,7 @@ evaluate_nfa (struct REGEX_INTERNAL_Automaton *a,
* @return 0 if string matches, non-0 otherwise
*/
int
-REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a,
- const char *string)
+REGEX_INTERNAL_eval (struct REGEX_INTERNAL_Automaton *a, const char *string)
{
int result;
@@ -3321,12 +3338,11 @@ REGEX_INTERNAL_get_first_key (const char *input_string,
{
size_t size;
- size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len :
- GNUNET_REGEX_INITIAL_BYTES;
+ size = string_len < GNUNET_REGEX_INITIAL_BYTES ? string_len
+ : GNUNET_REGEX_INITIAL_BYTES;
if (NULL == input_string)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Given input string was NULL!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Given input string was NULL!\n");
return 0;
}
GNUNET_CRYPTO_hash (input_string, size, key);
@@ -3367,21 +3383,16 @@ iterate_initial_edge (unsigned int min_len,
else
cur_len = 0;
- if ( ( (cur_len >= min_len) ||
- (GNUNET_YES == state->accepting) ) &&
- (cur_len > 0) &&
- (NULL != consumed_string) )
+ if (((cur_len >= min_len) || (GNUNET_YES == state->accepting)) &&
+ (cur_len > 0) && (NULL != consumed_string))
{
if (cur_len <= max_len)
{
- if ( (NULL != state->proof) &&
- (0 != strcmp (consumed_string,
- state->proof)) )
+ if ((NULL != state->proof) &&
+ (0 != strcmp (consumed_string, state->proof)))
{
(void) state_get_edges (state, edges);
- GNUNET_CRYPTO_hash (consumed_string,
- strlen (consumed_string),
- &hash);
+ GNUNET_CRYPTO_hash (consumed_string, strlen (consumed_string), &hash);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Start state for string `%s' is %s\n",
consumed_string,
@@ -3390,13 +3401,12 @@ iterate_initial_edge (unsigned int min_len,
&hash,
consumed_string,
state->accepting,
- num_edges, edges);
+ num_edges,
+ edges);
}
- if ( (GNUNET_YES == state->accepting) &&
- (cur_len > 1) &&
- (state->transition_count < 1) &&
- (cur_len < max_len) )
+ if ((GNUNET_YES == state->accepting) && (cur_len > 1) &&
+ (state->transition_count < 1) && (cur_len < max_len))
{
/* Special case for regex consisting of just a string that is shorter
than
* max_len */
@@ -3404,18 +3414,12 @@ iterate_initial_edge (unsigned int min_len,
edge[0].destination = state->hash;
temp = GNUNET_strdup (consumed_string);
temp[cur_len - 1] = '\0';
- GNUNET_CRYPTO_hash (temp,
- cur_len - 1,
- &hash_new);
+ GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash_new);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Start state for short string `%s' is %s\n",
temp,
GNUNET_h2s (&hash_new));
- iterator (iterator_cls,
- &hash_new,
- temp,
- GNUNET_NO, 1,
- edge);
+ iterator (iterator_cls, &hash_new, temp, GNUNET_NO, 1, edge);
GNUNET_free (temp);
}
}
@@ -3432,12 +3436,7 @@ iterate_initial_edge (unsigned int min_len,
temp,
edge[0].label,
GNUNET_h2s (&hash_new));
- iterator (iterator_cls,
- &hash,
- temp,
- GNUNET_NO,
- 1,
- edge);
+ iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edge);
GNUNET_free (temp);
}
}
@@ -3446,22 +3445,16 @@ iterate_initial_edge (unsigned int min_len,
{
for (t = state->transitions_head; NULL != t; t = t->next)
{
- if (NULL != strchr (t->label,
- (int) '.'))
+ if (NULL != strchr (t->label, (int) '.'))
{
/* Wildcards not allowed during starting states */
GNUNET_break (0);
continue;
}
if (NULL != consumed_string)
- GNUNET_asprintf (&temp,
- "%s%s",
- consumed_string,
- t->label);
+ GNUNET_asprintf (&temp, "%s%s", consumed_string, t->label);
else
- GNUNET_asprintf (&temp,
- "%s",
- t->label);
+ GNUNET_asprintf (&temp, "%s", t->label);
iterate_initial_edge (min_len,
max_len,
temp,
@@ -3489,30 +3482,32 @@ REGEX_INTERNAL_iterate_all_edges (struct
REGEX_INTERNAL_Automaton *a,
{
struct REGEX_INTERNAL_State *s;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Iterating over starting edges\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over starting edges\n");
iterate_initial_edge (GNUNET_REGEX_INITIAL_BYTES,
GNUNET_REGEX_INITIAL_BYTES,
- NULL, a->start,
- iterator, iterator_cls);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Iterating over DFA edges\n");
+ NULL,
+ a->start,
+ iterator,
+ iterator_cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating over DFA edges\n");
for (s = a->states_head; NULL != s; s = s->next)
{
struct REGEX_BLOCK_Edge edges[s->transition_count];
unsigned int num_edges;
num_edges = state_get_edges (s, edges);
- if ( ( (NULL != s->proof) &&
- (0 < strlen (s->proof)) ) || s->accepting)
+ if (((NULL != s->proof) && (0 < strlen (s->proof))) || s->accepting)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Creating DFA edges at `%s' under key %s\n",
s->proof,
GNUNET_h2s (&s->hash));
- iterator (iterator_cls, &s->hash, s->proof,
+ iterator (iterator_cls,
+ &s->hash,
+ s->proof,
s->accepting,
- num_edges, edges);
+ num_edges,
+ edges);
}
s->marked = GNUNET_NO;
}
@@ -3525,7 +3520,8 @@ REGEX_INTERNAL_iterate_all_edges (struct
REGEX_INTERNAL_Automaton *a,
* Contains the same info as the Regex Iterator parametes except the key,
* which comes directly from the HashMap iterator.
*/
-struct temporal_state_store {
+struct temporal_state_store
+{
int reachable;
char *proof;
int accepting;
@@ -3537,7 +3533,8 @@ struct temporal_state_store {
/**
* Store regex iterator and cls in one place to pass to the hashmap iterator.
*/
-struct client_iterator {
+struct client_iterator
+{
REGEX_INTERNAL_KeyIterator iterator;
void *iterator_cls;
};
@@ -3573,9 +3570,13 @@ store_all_states (void *cls,
tmp->num_edges = num_edges;
edges_size = sizeof (struct REGEX_BLOCK_Edge) * num_edges;
tmp->edges = GNUNET_malloc (edges_size);
- GNUNET_memcpy(tmp->edges, edges, edges_size);
- GNUNET_CONTAINER_multihashmap_put (hm, key, tmp,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ GNUNET_memcpy (tmp->edges, edges, edges_size);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_put (
+ hm,
+ key,
+ tmp,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
}
@@ -3601,8 +3602,8 @@ mark_as_reachable (struct temporal_state_store *state,
state->reachable = GNUNET_YES;
for (i = 0; i < state->num_edges; i++)
{
- child = GNUNET_CONTAINER_multihashmap_get (hm,
- &state->edges[i].destination);
+ child =
+ GNUNET_CONTAINER_multihashmap_get (hm, &state->edges[i].destination);
if (NULL == child)
{
GNUNET_break (0);
@@ -3655,24 +3656,24 @@ reachability_iterator (void *cls,
* #GNUNET_NO if not.
*/
static int
-iterate_reachables (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+iterate_reachables (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct client_iterator *ci = cls;
struct temporal_state_store *state = value;
if (GNUNET_YES == state->reachable)
{
- ci->iterator (ci->iterator_cls, key,
- state->proof, state->accepting,
- state->num_edges, state->edges);
+ ci->iterator (ci->iterator_cls,
+ key,
+ state->proof,
+ state->accepting,
+ state->num_edges,
+ state->edges);
}
GNUNET_free (state->edges);
GNUNET_free (state->proof);
GNUNET_free (state);
return GNUNET_YES;
-
}
/**
diff --git a/src/statistics/gnunet-statistics.c
b/src/statistics/gnunet-statistics.c
index bf111ade2..bc30670e9 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -93,7 +93,8 @@ static int set_value;
/**
* @brief Representation of all (testbed) nodes.
*/
-static struct Node {
+static struct Node
+{
/**
* @brief Index of the node in this array.
*/
@@ -117,7 +118,7 @@ static struct Node {
* @brief Identifier for shutdown task for this node.
*/
struct GNUNET_SCHEDULER_Task *shutdown_task;
-} *nodes;
+} * nodes;
/**
* @brief Number of configurations of all (testbed) nodes.
@@ -204,11 +205,9 @@ new_value_set (const char *subsystem,
* @return GNUNET_YES - continue iteration.
*/
static int
-printer (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+printer (void *cls, const struct GNUNET_HashCode *key, void *value)
{
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
const char *now_str;
struct ValueSet *value_set = value;
@@ -218,38 +217,38 @@ printer (void *cls,
{
now_str = GNUNET_STRINGS_absolute_time_to_string (now);
FPRINTF (stdout,
- "%24s%s %s%s%12s%s %s%50s%s%s ",
+ "%24s%s %s%s%12s%s %s%50s%s%s ",
now_str,
csv_separator,
value_set->is_persistent ? "!" : " ",
csv_separator,
value_set->subsystem,
csv_separator,
- (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
- _(value_set->name),
- (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
- (0 == strlen (csv_separator) ? ":": csv_separator));
+ (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
+ _ (value_set->name),
+ (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
+ (0 == strlen (csv_separator) ? ":" : csv_separator));
}
else
{
FPRINTF (stdout,
- "%s%s%12s%s %s%50s%s%s ",
+ "%s%s%12s%s %s%50s%s%s ",
value_set->is_persistent ? "!" : " ",
csv_separator,
value_set->subsystem,
csv_separator,
- (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
- _(value_set->name),
- (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
- (0 == strlen (csv_separator) ? ":": csv_separator));
+ (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
+ _ (value_set->name),
+ (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
+ (0 == strlen (csv_separator) ? ":" : csv_separator));
}
}
for (unsigned i = 0; i < num_nodes; i++)
{
FPRINTF (stdout,
- "%16llu%s",
- (unsigned long long) value_set->values[i],
- csv_separator);
+ "%16llu%s",
+ (unsigned long long) value_set->values[i],
+ csv_separator);
}
FPRINTF (stdout, "\n");
GNUNET_free (value_set->subsystem);
@@ -276,7 +275,7 @@ printer_watch (void *cls,
uint64_t value,
int is_persistent)
{
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
const char *now_str;
if (quiet == GNUNET_NO)
@@ -292,10 +291,10 @@ printer_watch (void *cls,
csv_separator,
subsystem,
csv_separator,
- (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
- _(name),
- (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
- (0 == strlen (csv_separator) ? ":": csv_separator),
+ (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
+ _ (name),
+ (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
+ (0 == strlen (csv_separator) ? ":" : csv_separator),
(unsigned long long) value);
}
else
@@ -306,17 +305,15 @@ printer_watch (void *cls,
csv_separator,
subsystem,
csv_separator,
- (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
- _(name),
- (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
- (0 == strlen (csv_separator) ? ":": csv_separator),
+ (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
+ _ (name),
+ (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
+ (0 == strlen (csv_separator) ? ":" : csv_separator),
(unsigned long long) value);
}
}
else
- FPRINTF (stdout,
- "%llu\n",
- (unsigned long long) value);
+ FPRINTF (stdout, "%llu\n", (unsigned long long) value);
return GNUNET_OK;
}
@@ -335,8 +332,8 @@ clean_node (void *cls)
struct GNUNET_STATISTICS_Handle *h;
struct GNUNET_STATISTICS_GetHandle *gh;
- if ( (NULL != path_testbed) && /* were issued with -t <testbed-path> option
*/
- (NULL != nodes[index_node].conf) )
+ if ((NULL != path_testbed) && /* were issued with -t <testbed-path> option */
+ (NULL != nodes[index_node].conf))
{
GNUNET_CONFIGURATION_destroy (nodes[index_node].conf);
nodes[index_node].conf = NULL;
@@ -352,7 +349,8 @@ clean_node (void *cls)
}
if (GNUNET_YES == watch)
{
- GNUNET_assert (GNUNET_OK ==
+ GNUNET_assert (
+ GNUNET_OK ==
GNUNET_STATISTICS_watch_cancel (h,
subsystem,
name,
@@ -383,7 +381,7 @@ static void
print_finish (void *cls)
{
GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL);
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
}
/**
@@ -395,8 +393,7 @@ print_finish (void *cls)
* @param succes Whether statistics were obtained successfully.
*/
static void
-continuation_print (void *cls,
- int success)
+continuation_print (void *cls, int success)
{
const unsigned index_node = *(unsigned *) cls;
@@ -404,12 +401,10 @@ continuation_print (void *cls,
if (GNUNET_OK != success)
{
if (NULL == remote_host)
- FPRINTF (stderr,
- "%s",
- _("Failed to obtain statistics.\n"));
+ FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n"));
else
FPRINTF (stderr,
- _("Failed to obtain statistics from host `%s:%llu'\n"),
+ _ ("Failed to obtain statistics from host `%s:%llu'\n"),
remote_host,
remote_port);
ret = 1;
@@ -435,8 +430,7 @@ continuation_print (void *cls,
* successfully obtained, #GNUNET_SYSERR if not.
*/
static void
-cleanup (void *cls,
- int success)
+cleanup (void *cls, int success)
{
for (unsigned i = 0; i < num_nodes; i++)
{
@@ -445,12 +439,10 @@ cleanup (void *cls,
if (GNUNET_OK != success)
{
if (NULL == remote_host)
- FPRINTF (stderr,
- "%s",
- _("Failed to obtain statistics.\n"));
+ FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n"));
else
FPRINTF (stderr,
- _("Failed to obtain statistics from host `%s:%llu'\n"),
+ _ ("Failed to obtain statistics from host `%s:%llu'\n"),
remote_host,
remote_port);
ret = 1;
@@ -492,19 +484,19 @@ collector (void *cls,
GNUNET_free (subsys_name);
if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (values, key))
{
- // get
value_set = GNUNET_CONTAINER_multihashmap_get (values, key);
}
else
{
- // new
value_set = new_value_set (subsystem, name, num_nodes, is_persistent);
}
- // write
value_set->values[index_node] = value;
- // put
- GNUNET_CONTAINER_multihashmap_put (values, key, value_set,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_put (
+ values,
+ key,
+ value_set,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return GNUNET_OK;
}
@@ -523,22 +515,17 @@ main_task (void *cls)
{
if (NULL == subsystem)
{
- FPRINTF (stderr,
- "%s",
- _("Missing argument: subsystem \n"));
+ FPRINTF (stderr, "%s", _ ("Missing argument: subsystem \n"));
ret = 1;
return;
}
if (NULL == name)
{
- FPRINTF (stderr,
- "%s",
- _("Missing argument: name\n"));
+ FPRINTF (stderr, "%s", _ ("Missing argument: name\n"));
ret = 1;
return;
}
- nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem,
- cfg);
+ nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem, cfg);
if (NULL == nodes[index_node].handle)
{
ret = 1;
@@ -548,59 +535,51 @@ main_task (void *cls)
name,
(uint64_t) set_val,
persistent);
- GNUNET_STATISTICS_destroy (nodes[index_node].handle,
- GNUNET_YES);
+ GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_YES);
nodes[index_node].handle = NULL;
return;
}
- if (NULL == (nodes[index_node].handle = GNUNET_STATISTICS_create
("gnunet-statistics",
- cfg)))
+ if (NULL == (nodes[index_node].handle =
+ GNUNET_STATISTICS_create ("gnunet-statistics", cfg)))
{
ret = 1;
return;
}
if (GNUNET_NO == watch)
{
- if (NULL ==
- (nodes[index_node].gh = GNUNET_STATISTICS_get
(nodes[index_node].handle,
- subsystem,
- name,
- &continuation_print,
- &collector,
- &nodes[index_node].index_node)) )
- cleanup (nodes[index_node].handle,
- GNUNET_SYSERR);
+ if (NULL == (nodes[index_node].gh =
+ GNUNET_STATISTICS_get (nodes[index_node].handle,
+ subsystem,
+ name,
+ &continuation_print,
+ &collector,
+ &nodes[index_node].index_node)))
+ cleanup (nodes[index_node].handle, GNUNET_SYSERR);
}
else
{
- if ( (NULL == subsystem) ||
- (NULL == name) )
+ if ((NULL == subsystem) || (NULL == name))
{
- printf (_("No subsystem or name given\n"));
- GNUNET_STATISTICS_destroy (nodes[index_node].handle,
- GNUNET_NO);
+ printf (_ ("No subsystem or name given\n"));
+ GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_NO);
nodes[index_node].handle = NULL;
ret = 1;
return;
}
- if (GNUNET_OK !=
- GNUNET_STATISTICS_watch (nodes[index_node].handle,
- subsystem,
- name,
- &printer_watch,
- &nodes[index_node].index_node))
+ if (GNUNET_OK != GNUNET_STATISTICS_watch (nodes[index_node].handle,
+ subsystem,
+ name,
+ &printer_watch,
+ &nodes[index_node].index_node))
{
- fprintf (stderr,
- _("Failed to initialize watch routine\n"));
+ fprintf (stderr, _ ("Failed to initialize watch routine\n"));
nodes[index_node].shutdown_task =
- GNUNET_SCHEDULER_add_now (&clean_node,
- &nodes[index_node].index_node);
+ GNUNET_SCHEDULER_add_now (&clean_node, &nodes[index_node].index_node);
return;
}
}
nodes[index_node].shutdown_task =
- GNUNET_SCHEDULER_add_shutdown (&clean_node,
- &nodes[index_node].index_node);
+ GNUNET_SCHEDULER_add_shutdown (&clean_node, &nodes[index_node].index_node);
}
/**
@@ -615,16 +594,16 @@ main_task (void *cls)
* @return to continue iteration or not to
*/
static int
-iter_check_config (void *cls,
- const char *filename)
+iter_check_config (void *cls, const char *filename)
{
if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6))
{
/* Found the config - stop iteration successfully */
- GNUNET_array_grow (nodes, num_nodes, num_nodes+1);
- nodes[num_nodes-1].conf = GNUNET_CONFIGURATION_create();
- nodes[num_nodes-1].index_node = num_nodes-1;
- if (GNUNET_OK != GNUNET_CONFIGURATION_load (nodes[num_nodes-1].conf,
filename))
+ GNUNET_array_grow (nodes, num_nodes, num_nodes + 1);
+ nodes[num_nodes - 1].conf = GNUNET_CONFIGURATION_create ();
+ nodes[num_nodes - 1].index_node = num_nodes - 1;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_load (nodes[num_nodes - 1].conf, filename))
{
FPRINTF (stderr, "Failed loading config `%s'\n", filename);
return GNUNET_SYSERR;
@@ -652,19 +631,14 @@ iter_check_config (void *cls,
* @return status whether to continue iteration
*/
static int
-iter_testbed_path (void *cls,
- const char *filename)
+iter_testbed_path (void *cls, const char *filename)
{
unsigned index_node;
GNUNET_assert (NULL != filename);
- if (1 == SSCANF (GNUNET_STRINGS_get_short_name (filename),
- "%u",
- &index_node))
+ if (1 == SSCANF (GNUNET_STRINGS_get_short_name (filename), "%u",
&index_node))
{
- if (-1 == GNUNET_DISK_directory_scan (filename,
- iter_check_config,
- NULL))
+ if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL))
{
/* This is probably no directory for a testbed node
* Go on with iteration */
@@ -687,14 +661,11 @@ discover_testbed_nodes (const char *path_testbed)
{
int num_dir_entries;
- num_dir_entries = GNUNET_DISK_directory_scan (path_testbed,
- iter_testbed_path,
- NULL);
+ num_dir_entries =
+ GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL);
if (-1 == num_dir_entries)
{
- FPRINTF (stderr,
- "Failure during scanning directory `%s'\n",
- path_testbed);
+ FPRINTF (stderr, "Failure during scanning directory `%s'\n", path_testbed);
return -1;
}
return 0;
@@ -718,16 +689,13 @@ run (void *cls,
c = (struct GNUNET_CONFIGURATION_Handle *) cfg;
set_value = GNUNET_NO;
- if (NULL == csv_separator) csv_separator = "";
+ if (NULL == csv_separator)
+ csv_separator = "";
if (NULL != args[0])
{
- if (1 != SSCANF (args[0],
- "%llu",
- &set_val))
+ if (1 != SSCANF (args[0], "%llu", &set_val))
{
- FPRINTF (stderr,
- _("Invalid argument `%s'\n"),
- args[0]);
+ FPRINTF (stderr, _ ("Invalid argument `%s'\n"), args[0]);
ret = 1;
return;
}
@@ -737,39 +705,36 @@ run (void *cls,
{
if (0 == remote_port)
{
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "statistics",
- "PORT",
- &remote_port))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
+ "statistics",
+ "PORT",
+
&remote_port))
{
- FPRINTF (stderr,
- _("A port is required to connect to host `%s'\n"),
- remote_host);
- return;
+ FPRINTF (stderr,
+ _ ("A port is required to connect to host `%s'\n"),
+ remote_host);
+ return;
}
}
else if (65535 <= remote_port)
{
FPRINTF (stderr,
- _("A port has to be between 1 and 65535 to connect to host
`%s'\n"),
- remote_host);
+ _ (
+ "A port has to be between 1 and 65535 to connect to host
`%s'\n"),
+ remote_host);
return;
}
/* Manipulate configuration */
+ GNUNET_CONFIGURATION_set_value_string (c, "statistics", "UNIXPATH", "");
GNUNET_CONFIGURATION_set_value_string (c,
- "statistics",
- "UNIXPATH",
- "");
- GNUNET_CONFIGURATION_set_value_string (c,
- "statistics",
- "HOSTNAME",
- remote_host);
+ "statistics",
+ "HOSTNAME",
+ remote_host);
GNUNET_CONFIGURATION_set_value_number (c,
- "statistics",
- "PORT",
- remote_port);
+ "statistics",
+ "PORT",
+ remote_port);
}
if (NULL == path_testbed)
{
@@ -783,7 +748,8 @@ run (void *cls,
{
if (GNUNET_YES == watch)
{
- printf (_("Not able to watch testbed nodes (yet - feel free to
implement)\n"));
+ printf (
+ _ ("Not able to watch testbed nodes (yet - feel free to
implement)\n"));
ret = 1;
return;
}
@@ -795,8 +761,7 @@ run (void *cls,
/* For each config/node collect statistics */
for (unsigned i = 0; i < num_nodes; i++)
{
- GNUNET_SCHEDULER_add_now (&main_task,
- &nodes[i].index_node);
+ GNUNET_SCHEDULER_add_now (&main_task, &nodes[i].index_node);
}
}
}
@@ -812,78 +777,82 @@ run (void *cls,
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_string ('n',
- "name",
- "NAME",
- gettext_noop ("limit output to statistics for
the given NAME"),
- &name),
-
- GNUNET_GETOPT_option_flag ('p',
- "persistent",
- gettext_noop ("make the value being set
persistent"),
- &persistent),
-
- GNUNET_GETOPT_option_string ('s',
- "subsystem",
- "SUBSYSTEM",
- gettext_noop ("limit output to the given
SUBSYSTEM"),
- &subsystem),
-
- GNUNET_GETOPT_option_string ('S',
- "csv-separator",
- "CSV_SEPARATOR",
- gettext_noop ("use as csv separator"),
- &csv_separator),
-
- GNUNET_GETOPT_option_filename ('t',
- "testbed",
- "TESTBED",
- gettext_noop ("path to the folder containing
the testbed data"),
- &path_testbed),
-
- GNUNET_GETOPT_option_flag ('q',
- "quiet",
- gettext_noop ("just print the statistics
value"),
- &quiet),
-
- GNUNET_GETOPT_option_flag ('w',
- "watch",
- gettext_noop ("watch value continuously"),
- &watch),
-
- GNUNET_GETOPT_option_string ('r',
- "remote",
- "REMOTE",
- gettext_noop ("connect to remote host"),
- &remote_host),
-
- GNUNET_GETOPT_option_ulong ('o',
- "port",
- "PORT",
- gettext_noop ("port for remote host"),
- &remote_port),
-
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_string (
+ 'n',
+ "name",
+ "NAME",
+ gettext_noop ("limit output to statistics for the given NAME"),
+ &name),
+
+ GNUNET_GETOPT_option_flag ('p',
+ "persistent",
+ gettext_noop (
+ "make the value being set persistent"),
+ &persistent),
+
+ GNUNET_GETOPT_option_string ('s',
+ "subsystem",
+ "SUBSYSTEM",
+ gettext_noop (
+ "limit output to the given SUBSYSTEM"),
+ &subsystem),
+
+ GNUNET_GETOPT_option_string ('S',
+ "csv-separator",
+ "CSV_SEPARATOR",
+ gettext_noop ("use as csv separator"),
+ &csv_separator),
+
+ GNUNET_GETOPT_option_filename (
+ 't',
+ "testbed",
+ "TESTBED",
+ gettext_noop ("path to the folder containing the testbed data"),
+ &path_testbed),
+
+ GNUNET_GETOPT_option_flag ('q',
+ "quiet",
+ gettext_noop (
+ "just print the statistics value"),
+ &quiet),
+
+ GNUNET_GETOPT_option_flag ('w',
+ "watch",
+ gettext_noop ("watch value continuously"),
+ &watch),
+
+ GNUNET_GETOPT_option_string ('r',
+ "remote",
+ "REMOTE",
+ gettext_noop ("connect to remote host"),
+ &remote_host),
+
+ GNUNET_GETOPT_option_ulong ('o',
+ "port",
+ "PORT",
+ gettext_noop ("port for remote host"),
+ &remote_port),
+
+ GNUNET_GETOPT_OPTION_END};
remote_port = 0;
remote_host = NULL;
- 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-statistics [options [value]]",
- gettext_noop
- ("Print statistics about GNUnet operations."),
- options,
- &run,
- NULL)) ? ret : 1;
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-statistics [options [value]]",
+ gettext_noop (
+ "Print statistics about GNUnet operations."),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
GNUNET_free_non_null (remote_host);
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
return ret;
}
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [gnunet] branch master updated: nicer loop structure,
gnunet <=