summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2019-06-22 22:58:04 +0200
committerxrs <xrs@mail36.net>2019-06-22 22:58:04 +0200
commitea20a69462912d46cf4f9dc47e6c7945c9da5f97 (patch)
treebc75b6e04ba593d06b4f615a2ce628a6fce29daf
parentd6c25f60406596d84900aa6ac012bf8ce111d57c (diff)
parent4b3469ce52759581bf8833a3093cfe7ddad8aa9d (diff)
Merge branch 'master' of ssh://git.gnunet.org/gnunet
-rw-r--r--doc/handbook/chapters/developer.texi332
-rw-r--r--doc/handbook/chapters/installation.texi28
-rw-r--r--doc/handbook/chapters/keyconcepts.texi1
-rw-r--r--doc/handbook/chapters/user.texi273
-rw-r--r--doc/man/gnunet-config.13
-rw-r--r--src/arm/arm_api.c287
-rw-r--r--src/arm/arm_monitor_api.c55
-rw-r--r--src/arm/mockup-service.c49
-rw-r--r--src/core/core_api.c5
-rw-r--r--src/core/core_api_monitor_peers.c34
-rw-r--r--src/core/gnunet-core.c80
-rw-r--r--src/curl/curl.c57
-rw-r--r--src/curl/curl_reschedule.c29
-rw-r--r--src/gns/Makefile.am2
-rw-r--r--src/gns/gnunet-gns-proxy-ca.template303
-rw-r--r--src/gns/gnunet-gns-proxy-setup-ca.in45
-rw-r--r--src/include/gnunet_common.h31
-rw-r--r--src/include/gnunet_container_lib.h1127
-rw-r--r--src/namestore/gnunet-service-namestore.c67
-rw-r--r--src/nse/gnunet-nse.c38
-rw-r--r--src/nse/gnunet-service-nse.c21
-rw-r--r--src/nse/nse_api.c43
-rw-r--r--src/transport/gnunet-service-tng.c243
-rw-r--r--src/util/Makefile.am1
-rw-r--r--src/util/common_logging.c393
-rw-r--r--src/util/container_multiuuidmap.c1015
-rw-r--r--src/util/crypto_random.c84
-rw-r--r--src/util/gnunet-config.c58
-rw-r--r--src/util/gnunet-scrypt.c213
-rw-r--r--src/util/gnunet-uri.c84
-rw-r--r--src/util/test_common_logging_dummy.c59
-rw-r--r--src/util/tun.c163
32 files changed, 3329 insertions, 1894 deletions
diff --git a/doc/handbook/chapters/developer.texi b/doc/handbook/chapters/developer.texi
index 228603cda..a43bd7b37 100644
--- a/doc/handbook/chapters/developer.texi
+++ b/doc/handbook/chapters/developer.texi
@@ -79,6 +79,7 @@ new chapters, sections or insightful comments.
* File-sharing (FS) Subsystem::
* REGEX Subsystem::
* REST Subsystem::
+* RPS Subsystem::
@end menu
@node Developer Introduction
@@ -556,7 +557,7 @@ stacked together to construct complex buildings and it is generally easy
to swap one block for a different one that has the same shape. GNUnet's
architecture is based on LEGOs:
-@c @image{images/service_lego_block,5in,,picture of a LEGO block stack - 3 APIs as connectors upon Network Protocol on top of a Service}
+@image{images/service_lego_block,5in,,picture of a LEGO block stack - 3 APIs upon IPC/network protocol provided by a service}
This chapter documents the GNUnet LEGO system, also known as GNUnet's
system architecture.
@@ -573,10 +574,14 @@ Like services, they have holes to be filled by APIs of other services.
Unlike services, daemons do not implement their own network protocol and
they have no API:
+@image{images/daemon_lego_block,5in,,A daemon in GNUnet is a component that does not offer an API for others to build upon}
+
The GNUnet system provides a range of services, daemons and user
interfaces, which are then combined into a layered GNUnet instance (also
known as a peer).
+@image{images/service_stack,5in,,A GNUnet peer consists of many layers of services}
+
Note that while it is generally possible to swap one service for another
compatible service, there is often only one implementation. However,
during development we often have a "new" version of a service in parallel
@@ -587,7 +592,7 @@ easily investigated by swapping out individual components. This is
typically achieved by simply changing the name of the "BINARY" in the
respective configuration section.
-Key properties of GNUnet services are that they must be separate
+Key properties of GNUnet services are that they must be separate
processes and that they must protect themselves by applying tight error
checking against the network protocol they implement (thereby achieving a
certain degree of robustness).
@@ -1876,7 +1881,6 @@ Testbed API can accessed by including the
* Hosts file format::
* Topology file format::
* Testbed Barriers::
-* Automatic large-scale deployment in the PlanetLab testbed::
* TESTBED Caveats::
@end menu
@@ -2140,168 +2144,6 @@ message from its upward propagation --- the upward propagation is needed
for ensuring that the barrier is reached by all the controllers and the
downward propagation is for triggering that the barrier is crossed.
-@cindex PlanetLab testbed
-@node Automatic large-scale deployment in the PlanetLab testbed
-@subsection Automatic large-scale deployment in the PlanetLab testbed
-
-PlanetLab is a testbed for computer networking and distributed systems
-research. It was established in 2002 and as of June 2010 was composed of
-1090 nodes at 507 sites worldwide.
-
-To automate the GNUnet we created a set of automation tools to simplify
-the large-scale deployment. We provide you a set of scripts you can use
-to deploy GNUnet on a set of nodes and manage your installation.
-
-Please also check @uref{https://old.gnunet.org/installation-fedora8-svn} and
-@uref{https://old.gnunet.org/installation-fedora12-svn} to find detailed
-instructions how to install GNUnet on a PlanetLab node.
-
-
-@c ***********************************************************************
-@menu
-* PlanetLab Automation for Fedora8 nodes::
-* Install buildslave on PlanetLab nodes running fedora core 8::
-* Setup a new PlanetLab testbed using GPLMT::
-* Why do i get an ssh error when using the regex profiler?::
-@end menu
-
-@node PlanetLab Automation for Fedora8 nodes
-@subsubsection PlanetLab Automation for Fedora8 nodes
-
-@c ***********************************************************************
-@node Install buildslave on PlanetLab nodes running fedora core 8
-@subsubsection Install buildslave on PlanetLab nodes running fedora core 8
-@c ** Actually this is a subsubsubsection, but must be fixed differently
-@c ** as subsubsection is the lowest.
-
-Since most of the PlanetLab nodes are running the very old Fedora core 8
-image, installing the buildslave software is quite some pain. For our
-PlanetLab testbed we figured out how to install the buildslave software
-best.
-
-@c This is a very terrible way to suggest installing software.
-@c FIXME: Is there an official, safer way instead of blind-piping a
-@c script?
-@c FIXME: Use newer pypi URLs below.
-Install Distribute for Python:
-
-@example
-curl http://python-distribute.org/distribute_setup.py | sudo python
-@end example
-
-Install Distribute for zope.interface <= 3.8.0 (4.0 and 4.0.1 will not
-work):
-
-@example
-export PYPI=@value{PYPI-URL}
-wget $PYPI/z/zope.interface/zope.interface-3.8.0.tar.gz
-tar xzvf zope.interface-3.8.0.tar.gz
-cd zope.interface-3.8.0
-sudo python setup.py install
-@end example
-
-Install the buildslave software (0.8.6 was the latest version):
-
-@example
-export GCODE="http://buildbot.googlecode.com/files"
-wget $GCODE/buildbot-slave-0.8.6p1.tar.gz
-tar xvfz buildbot-slave-0.8.6p1.tar.gz
-cd buildslave-0.8.6p1
-sudo python setup.py install
-@end example
-
-The setup will download the matching twisted package and install it.
-It will also try to install the latest version of zope.interface which
-will fail to install. Buildslave will work anyway since version 3.8.0
-was installed before!
-
-@c ***********************************************************************
-@node Setup a new PlanetLab testbed using GPLMT
-@subsubsection Setup a new PlanetLab testbed using GPLMT
-
-@itemize @bullet
-@item Get a new slice and assign nodes
-Ask your PlanetLab PI to give you a new slice and assign the nodes you
-need
-@item Install a buildmaster
-You can stick to the buildbot documentation:@
-@uref{http://buildbot.net/buildbot/docs/current/manual/installation.html}
-@item Install the buildslave software on all nodes
-To install the buildslave on all nodes assigned to your slice you can use
-the tasklist @code{install_buildslave_fc8.xml} provided with GPLMT:
-
-@example
-./gplmt.py -c contrib/tumple_gnunet.conf -t \
-contrib/tasklists/install_buildslave_fc8.xml -a -p <planetlab password>
-@end example
-
-@item Create the buildmaster configuration and the slave setup commands
-
-The master and the and the slaves have need to have credentials and the
-master has to have all nodes configured. This can be done with the
-@file{create_buildbot_configuration.py} script in the @file{scripts}
-directory.
-
-This scripts takes a list of nodes retrieved directly from PlanetLab or
-read from a file and a configuration template and creates:
-
-@itemize @bullet
-@item a tasklist which can be executed with gplmt to setup the slaves
-@item a master.cfg file containing a PlanetLab nodes
-@end itemize
-
-A configuration template is included in the <contrib>, most important is
-that the script replaces the following tags in the template:
-
-%GPLMT_BUILDER_DEFINITION :@ GPLMT_BUILDER_SUMMARY@ GPLMT_SLAVES@
-%GPLMT_SCHEDULER_BUILDERS
-
-Create configuration for all nodes assigned to a slice:
-
-@example
-./create_buildbot_configuration.py -u <planetlab username> \
--p <planetlab password> -s <slice> -m <buildmaster+port> \
--t <template>
-@end example
-
-Create configuration for some nodes in a file:
-
-@example
-./create_buildbot_configuration.p -f <node_file> \
--m <buildmaster+port> -t <template>
-@end example
-
-@item Copy the @file{master.cfg} to the buildmaster and start it
-Use @code{buildbot start <basedir>} to start the server
-@item Setup the buildslaves
-@end itemize
-
-@c ***********************************************************************
-@node Why do i get an ssh error when using the regex profiler?
-@subsubsection Why do i get an ssh error when using the regex profiler?
-
-Why do i get an ssh error "Permission denied (publickey,password)." when
-using the regex profiler although passwordless ssh to localhost works
-using publickey and ssh-agent?
-
-You have to generate a public/private-key pair with no password:@
-@code{ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_localhost}@
-and then add the following to your ~/.ssh/config file:
-
-@code{Host 127.0.0.1@ IdentityFile ~/.ssh/id_localhost}
-
-now make sure your hostsfile looks like
-
-@example
-[USERNAME]@@127.0.0.1:22@
-[USERNAME]@@127.0.0.1:22
-@end example
-
-You can test your setup by running @code{ssh 127.0.0.1} in a
-terminal and then in the opened session run it again.
-If you were not asked for a password on either login,
-then you should be good to go.
-
@cindex TESTBED Caveats
@node TESTBED Caveats
@subsection TESTBED Caveats
@@ -8126,9 +7968,9 @@ future.
@node Conversions between DNS and GNS
@subsubsection Conversions between DNS and GNS
-The differences between the two name systems lies in the details
-and is not always transparent.
-For instance an SRV record is converted to a GNS only BOX record.
+The differences between the two name systems lies in the details and is not
+always transparent. For instance an SRV record is converted to a BOX record
+which is unique to GNS.
This is done by converting to a BOX record from an existing SRV record:
@@ -8141,7 +7983,7 @@ _sip._tcp.example.com. 14000 IN SRV 0 0 5060 www.example.com.
14000 BOX n 5060 6 33 0 0 5060 www.example.com
@end example
-Other records that have such a transformation is the MX record type,
+Other records that need to undergo such transformation is the MX record type,
as well as the SOA record type.
Transformation of a SOA record into GNS works as described in the
@@ -8156,8 +7998,9 @@ following example. Very important to note are the rname and mname keys.
604800 ; expire
600 ) ; ttl
# Recordline for adding the record
-$ gnunet-namestore -z example.com -a -n @ -t SOA -V rname=master.example.com \
- mname=hostmaster.example.com 2017030300,3600,1800,604800,600 -e 7200s
+$ gnunet-namestore -z example.com -a -n @ -t SOA -V \
+ rname=master.example.com mname=hostmaster.example.com \
+ 2017030300,3600,1800,604800,600 -e 7200s
@end example
The transformation of MX records is done in a simple way.
@@ -8166,10 +8009,10 @@ The transformation of MX records is done in a simple way.
$ gnunet-namestore -z example.com -n mail -R 3600 MX n 10,mail
@end example
-Finally, one of the biggest struggling points were the NS records that are found
-in top level domain zones. The intended behaviour for those is to add GNS2DNS
-records for those so that gnunet-gns can resolve records for those domains on
-its own. This requires migration of the DNS GLUE records as well, provided that
+Finally, one of the biggest struggling points were the NS records that are
+found in top level domain zones. The intended behaviour for those is to add
+GNS2DNS records for those so that gnunet-gns can resolve records for those
+domains on its own. Those require the values from DNS GLUE records, provided
they are within the same zone.
The following two examples show one record with a GLUE record and the other one
@@ -8178,10 +8021,12 @@ does not have a GLUE record. This takes place in the 'com' TLD.
@example
# ns1.example.com 86400 IN A 127.0.0.1
# example.com 86400 IN NS ns1.example.com.
-$ gnunet-namestore -z com -n example -R 86400 GNS2DNS n example.com@@127.0.0.1
+$ gnunet-namestore -z com -n example -R 86400 GNS2DNS n \
+ example.com@@127.0.0.1
# example.com 86400 IN NS ns1.example.org.
-$ gnunet-namestore -z com -n example -R 86400 GNS2DNS n example.com@@ns1.example.org
+$ gnunet-namestore -z com -n example -R 86400 GNS2DNS n \
+ example.com@@ns1.example.org
@end example
As you can see, one of the GNS2DNS records has an IP address listed and the
@@ -8204,7 +8049,7 @@ Currently the following record types are supported:
@item TXT
@end itemize
-This is not due to a technical limitation but rather a practical one. The
+This is not due to technical limitations but rather a practical ones. The
problem occurs with DNSSEC enabled DNS zones. As records within those zones are
signed periodically, and every new signature is an update to the zone, there are
many revisions of zones. This results in a problem with bigger zones as there
@@ -8214,16 +8059,22 @@ as they cause a CLI call of the namestore. Furthermore certain record types
need transformation into a GNS compatible format which, depending on the record
type, takes more time.
+Further a blacklist was added to drop for instance DNSSEC related records. Also
+if a record type is neither in the white list nor the blacklist it is considered
+as a loss of data and a message is shown to the user. This helps with
+transparency and also with contributing, as the not supported record types can
+then be added accordingly.
+
@node DNS Zone Size
@subsubsection DNS Zone Size
-
Another very big problem exists with very large zones. When migrating a small
zone the delay between adding of records and their expiry is negligible. However
-when working with a TLD zone that has more that 1 million records this delay
-becomes a problem.
+when working with big zones that easily have more than a few million records
+this delay becomes a problem.
Records will start to expire well before the zone has finished migrating. This
-causes unwanted anomalies when trying to resolve records.
+is usually not a problem but can cause a high CPU load when a peer is restarted
+and the records have expired.
A good solution has not been found yet. One of the idea that floated around was
that the records should be added with the s (shadow) flag to keep the records
@@ -8233,45 +8084,51 @@ of said record(s).
Another problem that still persists is how to refresh records. Expired records
are still displayed when calling gnunet-namestore but do not resolve with
-gnunet-gns. When doing incremental zone transfers this becomes especially
-apparent.
+gnunet-gns. Zonemaster will sign the expired records again and make sure that
+the records are still valid. With a recent change this was fixed as gnunet-gns
+to improve the suffix lookup which allows for a fast lookup even with thousands
+of local egos.
+
+Currently the pace of adding records in general is around 10 records per second.
+Crypto is the upper limit for adding of records. The performance of your machine
+can be tested with the perf_crypto_* tools. There is still a big discrepancy
+between the pace of Ascension and the theoretical limit.
-I estimate that the limit lies at about 200'000 records in a zone as this is
-the limit that my machine is capable of adding within one hour. This was
-calculated by running cProfile on the application with a zone of 5000 records
-and calculating what abouts a much bigger zones with 8 million records would
-take. This results in a nice metric of records migrated per hour.
+A performance metric for measuring improvements has not yet been implemented in
+Ascension.
@node Performance
@subsubsection Performance
The performance when migrating a zone using the Ascension tool is limited by a
handful of factors. First of all ascension is written in Python3 and calls the
-CLI tools of GNUnet. Furthermore all the records that are added to the same
+CLI tools of GNUnet. This is comparable to a fork and exec call which costs a
+few CPU cycles. Furthermore all the records that are added to the same
label are signed using the zones private key. This signing operation is very
resource heavy and was optimized during development by adding the '-R'
-(Recordline) option to gnunet-namestore. This allows to add multiple records
-at once using the CLI.
-
-The result of this was a much faster migration of TLD zones, as most records
-with the same label have two name servers.
+(Recordline) option to gnunet-namestore which allows to specify multiple records
+using the CLI tool. Assuming that in a TLD zone every domain has at least two
+name servers this halves the amount of signatures needed.
Another improvement that could be made is with the addition of multiple threads
-when opening the GNUnet CLI tools. This could be implemented by simply creating
-more workers in the program but performance improvements were not tested.
+or using asynchronous subprocesses when opening the GNUnet CLI tools. This could
+be implemented by simply creating more workers in the program but performance
+improvements were not tested.
-During the entire development of Ascension sqlite was used as a database
-backend for GNUnet. Other backends have not been tested yet.
+Ascension was tested using different hardware and database backends. Performance
+differences between SQLite and postgresql are marginal and almost non existent.
+What did make a huge impact on record adding performance was the storage medium.
+On a traditional mechanical hard drive adding of records were slow compared to a
+solid state disk.
In conclusion there are many bottlenecks still around in the program, namely the
-signing process and the single threaded implementation. In the future a solution
-that uses the C API would be cleaner and better.
+single threaded implementation and inefficient, sequential calls of
+gnunet-namestore. In the future a solution that uses the C API would be cleaner
+and better.
@cindex GNS Namecache
@node GNS Namecache
@section GNS Namecache
-
-
The NAMECACHE subsystem is responsible for caching (encrypted) resolution
results of the GNU Name System (GNS). GNS makes zone information available
to other users via the DHT. However, as accessing the DHT for every
@@ -9007,3 +8864,72 @@ so please make sure that endpoints are unambiguous.
This is WIP. Endpoints should be documented appropriately.
Preferably using annotations.
+
+
+@cindex RPS Subsystem
+@node RPS Subsystem
+@section RPS Subsystem
+
+In literature, Random Peer Sampling (RPS) refers to the problem of
+reliably drawing random samples from an unstructured p2p network.
+
+Doing so in a reliable manner is not only hard because of inherent
+problems but also because of possible malicious peers that could try to
+bias the selection.
+
+It is useful for all kind of gossip protocols that require the selection
+of random peers in the whole network like gathering statistics,
+spreading and aggregating information in the network, load balancing and
+overlay topology management.
+
+The approach chosen in the rps implementation in GNUnet follows the
+Brahms@uref{https://bib.gnunet.org/full/date.html\#2009_5f0} design.
+
+The current state is "work in progress". There are a lot of things that
+need to be done, primarily finishing the experimental evaluation and a
+re-design of the API.
+
+The abstract idea is to subscribe to connect to/start the rps service
+and request random peers that will be returned when they represent a
+random selection from the whole network with high probability.
+
+An additional feature to the original Brahms-design is the selection of
+sub-groups: The GNUnet implementation of rps enables clients to ask for
+random peers from a group that is defined by a common shared secret.
+(The secret could of course also be public, depending on the use-case.)
+
+Another addition to the original protocol was made: The sampler
+mechanism that was introduced in Brahms was slightly adapted and used to
+actually sample the peers and returned to the client.
+This is necessary as the original design only keeps peers connected to
+random other peers in the network. In order to return random peers to
+client requests independently random, they cannot be drawn from the
+connected peers.
+The adapted sampler makes sure that each request for random peers is
+independent from the others.
+
+@node Brahms
+@subsection Brahms
+The high-level concept of Brahms is two-fold: Combining push-pull gossip
+with locally fixing a assumed bias using cryptographic min-wise
+permutations.
+The central data structure is the view - a peer's current local sample.
+This view is used to select peers to push to and pull from.
+This simple mechanism can be biased easily. For this reason Brahms
+'fixes' the bias by using the so-called sampler. A data structure that
+takes a list of elements as input and outputs a random one of them
+independently of the frequency in the input set. Both an element that
+was put into the sampler a single time and an element that was put into
+it a million times have the same probability of being the output.
+This is achieved this is achieved with exploiting min-wise independent
+permutations. In rps we use HMACs: On the initialisation of a sampler
+element, a key is chosen at random. On each input the HMAC with the
+random key is computed. The sampler element keeps the element with the
+minimal HMAC.
+
+In order to fix the bias in the view, a fraction of the elements in the
+view are sampled through the sampler from the random stream of peer IDs.
+
+According to the theoretical analysis of Bortnikov et al. this suffices
+to keep the network connected and having random peers in the view.
+
diff --git a/doc/handbook/chapters/installation.texi b/doc/handbook/chapters/installation.texi
index c3b9c6cbc..a508feb6a 100644
--- a/doc/handbook/chapters/installation.texi
+++ b/doc/handbook/chapters/installation.texi
@@ -1727,12 +1727,19 @@ $ gnunet-namestore -a -e "1 d" -n "homepage" \
At this point we can start the proxy. Simply execute
@example
-$ gnunet-gns-proxy
+$ gnunet-arm -i gns-proxy
+@end example
+
+To run the proxy at all times in the future, you should
+change your configuration as follows:
+
+@example
+$ gnunet-config -s gns-proxy -o AUTOSTART -V YES
@end example
@noindent
-Configure your browser to use this SOCKSv5 proxy on port 7777 and visit
-this link.
+Configure your browser to use this SOCKSv5 proxy using
+@code{localhost} on port 7777.
If you use @command{Firefox} (or one of its derivatives/forks such as
Icecat) you also have to go to @code{about:config} and set the key
@code{network.proxy.socks_remote_dns} to @code{true}.
@@ -1779,10 +1786,21 @@ Keeping a virtual environment helps with keeping things tidy and prevents
breaking of Ascension through a future Python update.
The advantage of using a virtual environment is, that all the dependencies can
-be installed separately in different versions without touching your system
+be installed separately in different versions without touching your systems
Python installation and its dependencies.
-@xref{Migrating an existing DNS zone into GNS}, for usage manual of the tool.
+Another way to install Ascension on Debian is to install the python3-ascension
+package. It can be found within the above mentioned Ascension git repository.
+This also adds a system user ascension and runs a GNUnet peer in the
+background. Attention: This only works if a recent version of GNUnet is
+installed on your system. The version number of Ascension is chosen according
+to the required feature level of GNUnet. I.e. Ascension 0.11.5 is only
+compatible with GNUnet 0.11.5 and upwards. As Debian's packages for GNUnet are
+outdated even in experimental, you will need to install GNUnet manually.
+@xref{Installing GNUnet}
+
+Please check @xref{Migrating an existing DNS zone into GNS}, for usage manual
+of the tool.
@node Configuring the GNUnet VPN
@subsection Configuring the GNUnet VPN
diff --git a/doc/handbook/chapters/keyconcepts.texi b/doc/handbook/chapters/keyconcepts.texi
index 4900ed328..bdfa5b631 100644
--- a/doc/handbook/chapters/keyconcepts.texi
+++ b/doc/handbook/chapters/keyconcepts.texi
@@ -319,3 +319,4 @@ Egos are your "identities" in GNUnet. Any user can assume multiple
identities, for example to separate their activities online. Egos can
correspond to "pseudonyms" or "real-world identities". Technically an
ego is first of all a key pair of a public- and private-key.
+
diff --git a/doc/handbook/chapters/user.texi b/doc/handbook/chapters/user.texi
index 55518bc34..fcf5e7871 100644
--- a/doc/handbook/chapters/user.texi
+++ b/doc/handbook/chapters/user.texi
@@ -526,7 +526,7 @@ shell) and create an entry home-phone in your master zone.
For the record type, select PHONE. You should then see the
PHONE dialog:
-@c image here
+@image{images/gnunet-namestore-gtk-phone,5in,,Dialog to publish a PHONE record}
Note: Do not choose the expiry time to be 'Never'. If you
do that, you assert that this record will never change and
@@ -645,7 +645,7 @@ Now, using your normal user (not the @code{gnunet} system user), run
master zone. For the record type, select @code{VPN}. You should then
see the VPN dialog:
-@c insert image
+@image{images/gnunet-namestore-gtk-vpn,5in,,Dialog to publish a VPN record}
Under peer, you need to supply the peer identity of your own peer. You can
obtain the respective string by running @command{gnunet-peerinfo -sq}
@@ -926,7 +926,7 @@ concepts that are used to achieve these goals.
* Files::
* Keywords::
* Directories::
-* Pseudonyms::
+* Egos and File-Sharing::
* Namespaces::
* Advertisements::
* Anonymity level::
@@ -984,69 +984,55 @@ typically includes the mime-type, description, a filename and
other meta information, and possibly even the full original file
(if it was small).
-@node Pseudonyms
-@subsubsection Pseudonyms
+@node Egos and File-Sharing
+@subsubsection Egos and File-Sharing
+When sharing files, it is sometimes desirable to build a reputation as
+a source for quality information. With egos, publishers can
+(cryptographically) sign files, thereby demonstrating that various
+files were published by the same entity. An ego thus allows users to
+link different publication events, thereby deliberately reducing
+anonymity to pseudonymity.
-@b{Please note that the text in this subsection is outdated and needs}
-@b{to be rewritten for version 0.10!}
-@b{This especially concerns the terminology of Pseudonym/Ego/Identity.}
+Egos used in GNUnet's file-sharing for such pseudonymous publishing
+also correspond to the egos used to identify and sign zones in the
+GNU Name System. However, if the same ego is used for file-sharing
+and for a GNS zone, this will weaken the privacy assurances provided
+by the anonymous file-sharing protocol.
-Pseudonyms in GNUnet are essentially public-private (RSA) key pairs
-that allow a GNUnet user to maintain an identity (which may or may not
-be detached from their real-life identity). GNUnet's pseudonyms are not
-file-sharing specific --- and they will likely be used by many GNUnet
-applications where a user identity is required.
+Note that an ego is NOT bound to a GNUnet peer. There can be multiple
+egos for a single user, and users could (theoretically) share
+the private keys of an ego by copying the respective private keys.
-Note that a pseudonym is NOT bound to a GNUnet peer. There can be multiple
-pseudonyms for a single user, and users could (theoretically) share the
-private pseudonym keys (currently only out-of-band by knowing which files
-to copy around).
@node Namespaces
@subsubsection Namespaces
+A namespace is a set of files that were signed by the same ego.
+Today, namespaces are implemented independently of GNS zones, but
+in the future we plan to merge the two such that a GNS zone can
+basically contain files using a file-sharing specific record type.
-@b{Please note that the text in this subsection is outdated and needs}
-@b{to be rewritten for version 0.10!}
-@b{This especially concerns the terminology of Pseudonym/Ego/Identity.}
-
-A namespace is a set of files that were signed by the same pseudonym.
-Files (or directories) that have been signed and placed into a namespace
-can be updated. Updates are identified as authentic if the same secret
-key was used to sign the update. Namespaces are also useful to establish
-a reputation, since all of the content in the namespace comes from the
-same entity (which does not have to be the same person).
+Files (or directories) that have been signed and placed into a
+namespace can be updated. Updates are identified as authentic if the
+same secret key was used to sign the update.
@node Advertisements
@subsubsection Advertisements
-
-@b{Please note that the text in this subsection is outdated and needs}
-@b{to be rewritten for version 0.10!}
-@b{This especially concerns the terminology of Pseudonym/Ego/Identity.}
-
Advertisements are used to notify other users about the existence of a
-namespace. Advertisements are propagated using the normal keyword search.
-When an advertisement is received (in response to a search), the namespace
-is added to the list of namespaces available in the namespace-search
-dialogs of gnunet-fs-gtk and printed by @code{gnunet-identity}. Whenever a
-namespace is created, an appropriate advertisement can be generated.
-The default keyword for the advertising of namespaces is "namespace".
-
-Note that GNUnet differentiates between your pseudonyms (the identities
-that you control) and namespaces. If you create a pseudonym, you will
-not automatically see the respective namespace. You first have to create
-an advertisement for the namespace and find it using keyword
-search --- even for your own namespaces. The @command{gnunet-identity}
-tool is currently responsible for both managing pseudonyms and namespaces.
-This will likely change in the future to reduce the potential for
-confusion.
+namespace. Advertisements are propagated using the normal keyword
+search. When an advertisement is received (in response to a search),
+the namespace is added to the list of namespaces available in the
+namespace-search dialogs of gnunet-fs-gtk and printed by
+@code{gnunet-identity}. Whenever a namespace is created, an
+appropriate advertisement can be generated. The default keyword for
+the advertising of namespaces is "namespace".
+
@node Anonymity level
@subsubsection Anonymity level
-
The anonymity level determines how hard it should be for an adversary to
determine the identity of the publisher or the searcher/downloader. An
anonymity level of zero means that anonymity is not required. The default
@@ -1066,10 +1052,10 @@ delays traffic.
While higher anonymity levels may offer better privacy, they can also
significantly hurt performance.
+
@node Content Priority
@subsubsection Content Priority
-
Depending on the peer's configuration, GNUnet peers migrate content
between peers. Content in this sense are individual blocks of a file,
not necessarily entire files. When peers run out of space (due to
@@ -1083,10 +1069,10 @@ lowest priority. The priority of a block is decided by its popularity
published locally, the base-priority that was specified by the user
when the block was published initially.
+
@node Replication
@subsubsection Replication
-
When peers migrate content to other systems, the replication level
of a block is used to decide which blocks need to be migrated most
urgently. GNUnet will always push the block with the highest
@@ -1098,99 +1084,37 @@ selection is simply random.
@node Namespace Management
@subsection Namespace Management
-
-@b{Please note that the text in this subsection is outdated and needs}
-@b{to be rewritten for version 0.10!}
-
-The @code{gnunet-identity} tool can be used to create pseudonyms and
-to advertise namespaces. By default, @code{gnunet-identity -D} simply
-lists all locally available pseudonyms.
+The @code{gnunet-identity} tool can be used to create egos.
+By default, @code{gnunet-identity -D} simply
+lists all locally available egos.
@menu
-* Creating Pseudonyms::
-* Deleting Pseudonyms::
-* Advertising namespaces::
-* Namespace names::
-* Namespace root::
+* Creating Egos::
+* Deleting Egos::
@end menu
-@node Creating Pseudonyms
-@subsubsection Creating Pseudonyms
+@node Creating Egos
+@subsubsection Creating Egos
+With the @command{-C NICK} option it can also be used to create a new
+ego. An ego is the virtual identity of the entity in control of a
+namespace or GNS zone. Anyone can create any number of egos. The
+provided NICK name automatically corresponds to a GNU Name System
+domain name. Thus, henceforth name resolution for any name ending in
+``.NICK'' will use the NICK's zone. You should avoid using NICKs that
+collide with well-known DNS names.
-@b{Please note that the text in this subsection is outdated and needs}
-@b{to be rewritten for version 0.10!}
-@b{This especially concerns the terminology of Pseudonym/Ego/Identity.}
+@node Deleting Egos
+@subsubsection Deleting Egos
-With the @command{-C NICK} option it can also be used to
-create a new pseudonym. A pseudonym is the virtual identity
-of the entity in control of a namespace. Anyone can create
-any number of pseudonyms. Note that creating a pseudonym can
-take a few minutes depending on the performance of the machine
-used.
+With the @command{-D NICK} option egos can be deleted. Once the ego
+has been deleted it is impossible to add content to the corresponding
+namespace or zone. However, the existing GNS zone data is currently
+not dropped. This may change in the future.
-@node Deleting Pseudonyms
-@subsubsection Deleting Pseudonyms
-
-
-@b{Please note that the text in this subsection is outdated and needs}
-@b{to be rewritten for version 0.10!}
-@b{This especially concerns the terminology of Pseudonym/Ego/Identity.}
-
-With the @command{-D NICK} option pseudonyms can be deleted.
-Once the pseudonym has been deleted it is impossible to add
-content to the corresponding namespace. Deleting the
-pseudonym does not make the namespace or any content in it
-unavailable.
-
-@node Advertising namespaces
-@subsubsection Advertising namespaces
-
-
-@b{Please note that the text in this subsection is outdated and needs}
-@b{to be rewritten for version 0.10!}
-@b{This especially concerns the terminology of Pseudonym/Ego/Identity.}
-
-Each namespace is associated with meta-data that describes
-the namespace. This meta-data is provided by the user at
-the time that the namespace is advertised. Advertisements
-are published under keywords so that they can be found using
-normal keyword-searches. This way, users can learn about new
-namespaces without relying on out-of-band communication or directories.
-A suggested keyword to use for all namespaces is simply "namespace".
-When a keyword-search finds a namespace advertisement,
-it is automatically stored in a local list of known namespaces.
-Users can then associate a rank with the namespace to remember
-the quality of the content found in it.
-
-@node Namespace names
-@subsubsection Namespace names
-
-
-@b{Please note that the text in this subsection is outdated and needs}
-@b{to be rewritten for version 0.10!}
-@b{This especially concerns the terminology of Pseudonym/Ego/Identity.}
-
-While the namespace is uniquely identified by its ID, another way
-to refer to the namespace is to use the NICKNAME.
-The NICKNAME can be freely chosen by the creator of the namespace and
-hence conflicts are possible. If a GNUnet client learns about more
-than one namespace using the same NICKNAME, the ID is appended
-to the NICKNAME to get a unique identifier.
-
-@node Namespace root
-@subsubsection Namespace root
-
-
-@b{Please note that the text in this subsection is outdated and needs}
-@b{to be rewritten for version 0.10!}
-@b{This especially concerns the terminology of Pseudonym/Ego/Identity.}
-
-An item of particular interest in the namespace advertisement is
-the ROOT. The ROOT is the identifier of a designated entry in the
-namespace. The idea is that the ROOT can be used to advertise an
-entry point to the content of the namespace.
+Deleting the pseudonym does not make the namespace or any content in
+it unavailable.
@node File-Sharing URIs
@subsection File-Sharing URIs
@@ -1314,12 +1238,12 @@ To publish a file, select "File Sharing" in the menu bar just below the
Afterwards, the following publishing dialog will appear:
-@c Add image here
+@image{images/gnunet-gtk-0-10-fs-publish,5in,,The gnunet-fs-gtk publishing dialog}
In this dialog, select the "Add File" button. This will open a
file selection dialog:
-@c Add image here
+@image{images/gnunet-gtk-0-10-fs-publish-select,5in,,Dialog to select the file to publish (looks may differ for other Gtk+ versions)}
Now, you should select a file from your computer to be published on
GNUnet. To see more of GNUnet's features later, you should pick a
@@ -1335,12 +1259,12 @@ and potential errors that might be encountered during processing.
After the progress dialog automatically disappears, your file
should now appear in the publishing dialog:
-@c Add image here
+@image{images/gnunet-gtk-0-10-fs-publish-with-file,5in,,Publishing dialog with file added}
Now, select the file (by clicking on the file name) and then click
the "Edit" button. This will open the editing dialog:
-@c Add image here
+@image{images/gnunet-gtk-0-10-fs-publish-editing,5in,,Editing meta data of a file to be published}
In this dialog, you can see many details about your file. In the
top left area, you can see meta data extracted about the file,
@@ -1364,9 +1288,7 @@ You should now be back at the "Publish content on GNUnet" dialog. Select
"Execute" in the bottom right to close the dialog and publish your file
on GNUnet! Afterwards, you should see the main dialog with a new area
showing the list of published files (or ongoing publishing operations
-with progress indicators):
-
-@c Add image here
+with progress indicators).
@node gtk-Searching
@subsubsection Searching
@@ -1920,33 +1842,42 @@ options:
@example
Ascension
-
Usage:
- ascension <domain> [-d] [-p]
- ascension <domain> <port> [-d] [-p]
- ascension <domain> -n <transferns> [-d] [-p]
- ascension <domain> -n <transferns> <port> [-d] [-p]
+ ascension <domain> [-d] [-p] [-s] [--minimum-ttl=<ttl>] \
+ [--dry-run]
+ ascension <domain> <port> [-d] [-p] [-s] \
+ [--minimum-ttl=<ttl>] [--dry-run]
+ ascension <domain> -n <transferns> [-d] [-p] \
+ [-s] [--minimum-ttl=<ttl>] [--dry-run]
+ ascension <domain> -n <transferns> <port> [-d] \
+ [-p] [-s] [--minimum-ttl=<ttl>] [--dry-run]
ascension -p | --public
+ ascension -d | --debug
+ ascension -s | --standalone
ascension -h | --help
ascension -v | --version
Options:
- <domain> Domain to migrate
- <port> Port for zone transfer
- <transferns> DNS Server that does the zone transfer
- -p --public Make records public on the DHT
- -d --debug Enable debugging
- -h --help Show this screen.
- -v --version Show version.
+ <domain> Domain to migrate
+ <port> Port for zone transfer
+ <transferns> DNS Server that does the zone transfer
+ --minimum-ttl=<ttl> Minimum TTL for records to migrate \
+ [default: 3600]
+ --dry-run Only try if a zone transfer is allowed
+ -p --public Make records public on the DHT
+ -s --standalone Run ascension once
+ -d --debug Enable debugging
+ -h --help Show this screen.
+ -v --version Show version.
@end example
-Before you can migrate any zone though, you need to start the GNUnet peer:
+Before you can migrate any zone though, you need to start a local GNUnet peer:
@example
$ gnunet-arm -s
@end example
To migrate the Syrian top level domain - one of the few top level domains that
-still supports zone transfers - into GNS use the following command:
+support zone transfers - into GNS use the following command:
@example
$ ascension sy. -n ns1.tld.sy. -p
@@ -1959,33 +1890,39 @@ Once the zone is migrated, Ascension will output a message telling you, that it
will refresh the zone after the time has elapsed. You can resolve the names in
the zone directly using GNS or if you want to use it with your browser, check
out the GNS manual section. @ref{Configuring the GNU Name System}. To resolve
-the records from another system you need the zone PKEY. To get the zone key,
-you can run the following command:
+the records from another system you need the respective zones PKEY. To get the
+zones public key, you can run the following command:
@example
-$ gnunet-identity -d | grep ^sy | cut -d " " -f3
+$ gnunet-identity -dqe sy
@end example
Where "sy" is the name of the zone you want to migrate.
-As soon as the public flag is implemented, you can share the PKEY of the zone
-with your friends. They can then resolve records in the zone by doing a lookup
-replacing the zone label with your PKEY:
+You can share the PKEY of the zone with your friends. They can then resolve
+records in the zone by doing a lookup replacing the zone label with your PKEY:
@example
-$ gnunet-gns -t SOA -u "@.$PKEY"
+$ gnunet-gns -t SOA -u "$PKEY"
@end example
The program will continue to run as a daemon and update once the refresh time
specified in the zones SOA record has elapsed.
-The next step would be to add the PKEY record as a DNScurve style NS record
-into the existing DNS zone to enable clients to detect that this zone has
-already been migrated to GNS and to also have a means of distributing the PKEY
-seamlessly.
+DNSCurve style records are supported in the latest release and they are added
+as a PKEY record to be referred to the respective GNS public key. Key
+distribution is still a problem but provided someone else has a public key
+under a given label it can be looked up.
+
+There is an unofficial Debian package called python3-ascension that adds a
+system user ascension and runs a GNUnet peer in the background.
-At this point you might want to write for example a systemd unit file to start
-and enable the service, so that your zone is migrated automatically.
+Ascension-bind is also an unofficial Debian package that on installation checks
+for running DNS zones and whether or not they are transferable using DNS zone
+transfer (AXFR). It asks the administrator which zones to migrate into GNS and
+installs a systemd unit file to keep the zone up to date. If you want to
+migrate different zones you might want to check the unit file from the package
+as a guide.
@node reclaimID Identity Provider
@section reclaimID Identity Provider
diff --git a/doc/man/gnunet-config.1 b/doc/man/gnunet-config.1
index 0e612fe29..95dc98811 100644
--- a/doc/man/gnunet-config.1
+++ b/doc/man/gnunet-config.1
@@ -30,6 +30,7 @@
manipulate GNUnet configuration files
.Sh SYNOPSIS
.Nm
+.Op Fl b Ar BACKEND | Fl \-supported-backend= Ns Ar BACKEND
.Op Fl c Ar FILENAME | Fl \-config= Ns Ar FILENAME
.Op Fl f | \-filename
.Op Fl h | \-help
@@ -44,6 +45,8 @@ manipulate GNUnet configuration files
.Nm
can be used to read or modify GNUnet configuration files.
.Bl -tag -width indent
+.It Fl b Ar BACKEND | Fl \-supported-backend= Ns Ar BACKEND
+Tests whether the specified BACKEND is supported by the current installation. The backend must match the name of a plugin, i.e. "namestore_postgres" for the Postgres database backend of the "NAMESTORE" service. If the BACKEND is supported, gnunet-config will return a status code of 0 (success), otherwise 77 (unsupported). When this option is specified, no other options may be specified. Specifying this option together with other options will cause gnunet-config to return a status code of 1 (error).
.It Fl c Ar FILENAME | Fl \-config= Ns Ar FILENAME
Use the configuration file FILENAME.
.It Fl f | \-filename
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index c8103c877..bf0acbcb9 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -30,7 +30,7 @@
#include "gnunet_protocols.h"
#include "arm.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "arm-api",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "arm-api", __VA_ARGS__)
/**
@@ -156,7 +156,6 @@ struct GNUNET_ARM_Handle
* Have we detected that ARM is up?
*/
int currently_up;
-
};
@@ -204,27 +203,19 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h)
h->currently_up = GNUNET_NO;
GNUNET_assert (NULL == h->reconnect_task);
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
- &reconnect_arm_task,
- h);
+ GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h);
while (NULL != (op = h->operation_pending_head))
{
if (NULL != op->result_cont)
- op->result_cont (op->cont_cls,
- GNUNET_ARM_REQUEST_DISCONNECTED,
- 0);
+ op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0);
if (NULL != op->list_cont)
- op->list_cont (op->cont_cls,
- GNUNET_ARM_REQUEST_DISCONNECTED,
- 0,
- NULL);
+ op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL);
GNUNET_ARM_operation_cancel (op);
}
GNUNET_assert (NULL == h->operation_pending_head);
h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
if (NULL != h->conn_status)
- h->conn_status (h->conn_status_cls,
- GNUNET_NO);
+ h->conn_status (h->conn_status_cls, GNUNET_NO);
}
@@ -236,12 +227,12 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h)
* @return NULL if not found
*/
static struct GNUNET_ARM_Operation *
-find_op_by_id (struct GNUNET_ARM_Handle *h,
- uint64_t id)
+find_op_by_id (struct GNUNET_ARM_Handle *h, uint64_t id)
{
struct GNUNET_ARM_Operation *result;
- for (result = h->operation_pending_head; NULL != result; result = result->next)
+ for (result = h->operation_pending_head; NULL != result;
+ result = result->next)
if (id == result->id)
return result;
return NULL;
@@ -255,8 +246,7 @@ find_op_by_id (struct GNUNET_ARM_Handle *h,
* @param res the message received from the arm service
*/
static void
-handle_arm_result (void *cls,
- const struct GNUNET_ARM_ResultMessage *res)
+handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res)
{
struct GNUNET_ARM_Handle *h = cls;
struct GNUNET_ARM_Operation *op;
@@ -266,8 +256,7 @@ handle_arm_result (void *cls,
void *result_cont_cls;
id = GNUNET_ntohll (res->arm_msg.request_id);
- op = find_op_by_id (h,
- id);
+ op = find_op_by_id (h, id);
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -277,8 +266,7 @@ handle_arm_result (void *cls,
}
result = (enum GNUNET_ARM_Result) ntohl (res->result);
- if ( (GNUNET_YES == op->is_arm_stop) &&
- (GNUNET_ARM_RESULT_STOPPING == result) )
+ if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result))
{
/* special case: if we are stopping 'gnunet-service-arm', we do not just
wait for the result message, but also wait for the service to close
@@ -289,8 +277,8 @@ handle_arm_result (void *cls,
{
GNUNET_break (0);
op->result_cont (h->thm->cont_cls,
- GNUNET_ARM_REQUEST_SENT_OK,
- GNUNET_ARM_RESULT_IS_NOT_KNOWN);
+ GNUNET_ARM_REQUEST_SENT_OK,
+ GNUNET_ARM_RESULT_IS_NOT_KNOWN);
GNUNET_free (h->thm);
}
GNUNET_CONTAINER_DLL_remove (h->operation_pending_head,
@@ -303,9 +291,7 @@ handle_arm_result (void *cls,
result_cont_cls = op->cont_cls;
GNUNET_ARM_operation_cancel (op);
if (NULL != result_cont)
- result_cont (result_cont_cls,
- GNUNET_ARM_REQUEST_SENT_OK,
- result);
+ result_cont (result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result);
}
@@ -325,6 +311,7 @@ check_arm_list_result (void *cls,
uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres);
uint16_t size_check;
+ (void) cls;
size_check = 0;
for (unsigned int i = 0; i < rcount; i++)
{
@@ -361,8 +348,7 @@ handle_arm_list_result (void *cls,
uint64_t id;
id = GNUNET_ntohll (lres->arm_msg.request_id);
- op = find_op_by_id (h,
- id);
+ op = find_op_by_id (h, id);
if (NULL == op)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -373,9 +359,7 @@ handle_arm_list_result (void *cls,
size_check = 0;
for (unsigned int i = 0; i < rcount; i++)
{
- const char *end = memchr (pos,
- 0,
- msize - size_check);
+ const char *end = memchr (pos, 0, msize - size_check);
/* Assert, as this was already checked in #check_arm_list_result() */
GNUNET_assert (NULL != end);
@@ -384,10 +368,7 @@ handle_arm_list_result (void *cls,
pos = end + 1;
}
if (NULL != op->list_cont)
- op->list_cont (op->cont_cls,
- GNUNET_ARM_REQUEST_SENT_OK,
- rcount,
- list);
+ op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list);
GNUNET_ARM_operation_cancel (op);
}
@@ -399,19 +380,17 @@ handle_arm_list_result (void *cls,
* @param msg message received
*/
static void
-handle_confirm (void *cls,
- const struct GNUNET_MessageHeader *msg)
+handle_confirm (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_ARM_Handle *h = cls;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Got confirmation from ARM that we are up!\n");
+ (void) msg;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n");
if (GNUNET_NO == h->currently_up)
{
h->currently_up = GNUNET_YES;
if (NULL != h->conn_status)
- h->conn_status (h->conn_status_cls,
- GNUNET_YES);
+ h->conn_status (h->conn_status_cls, GNUNET_YES);
}
}
@@ -425,19 +404,19 @@ handle_confirm (void *cls,
* @param error error code
*/
static void
-mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_ARM_Handle *h = cls;
struct GNUNET_ARM_Operation *op;
+ (void) error;
h->currently_up = GNUNET_NO;
if (NULL != (op = h->thm))
{
h->thm = NULL;
op->result_cont (op->cont_cls,
- GNUNET_ARM_REQUEST_SENT_OK,
- GNUNET_ARM_RESULT_STOPPED);
+ GNUNET_ARM_REQUEST_SENT_OK,
+ GNUNET_ARM_RESULT_STOPPED);
GNUNET_free (op);
}
reconnect_arm_later (h);
@@ -453,47 +432,37 @@ mq_error_handler (void *cls,
static int
reconnect_arm (struct GNUNET_ARM_Handle *h)
{
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (arm_result,
- GNUNET_MESSAGE_TYPE_ARM_RESULT,
- struct GNUNET_ARM_ResultMessage,
- h),
- GNUNET_MQ_hd_var_size (arm_list_result,
- GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT,
- struct GNUNET_ARM_ListResultMessage,
- h),
- GNUNET_MQ_hd_fixed_size (confirm,
- GNUNET_MESSAGE_TYPE_ARM_TEST,
- struct GNUNET_MessageHeader,
- h),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_fixed_size (arm_result,
+ GNUNET_MESSAGE_TYPE_ARM_RESULT,
+ struct GNUNET_ARM_ResultMessage,
+ h),
+ GNUNET_MQ_hd_var_size (arm_list_result,
+ GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT,
+ struct GNUNET_ARM_ListResultMessage,
+ h),
+ GNUNET_MQ_hd_fixed_size (confirm,
+ GNUNET_MESSAGE_TYPE_ARM_TEST,
+ struct GNUNET_MessageHeader,
+ h),
+ GNUNET_MQ_handler_end ()};
struct GNUNET_MessageHeader *test;
struct GNUNET_MQ_Envelope *env;
if (NULL != h->mq)
return GNUNET_OK;
GNUNET_assert (GNUNET_NO == h->currently_up);
- h->mq = GNUNET_CLIENT_connect (h->cfg,
- "arm",
- handlers,
- &mq_error_handler,
- h);
+ h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h);
if (NULL == h->mq)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "GNUNET_CLIENT_connect returned NULL\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n");
if (NULL != h->conn_status)
- h->conn_status (h->conn_status_cls,
- GNUNET_SYSERR);
+ h->conn_status (h->conn_status_cls, GNUNET_SYSERR);
return GNUNET_SYSERR;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending TEST message to ARM\n");
- env = GNUNET_MQ_msg (test,
- GNUNET_MESSAGE_TYPE_ARM_TEST);
- GNUNET_MQ_send (h->mq,
- env);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n");
+ env = GNUNET_MQ_msg (test, GNUNET_MESSAGE_TYPE_ARM_TEST);
+ GNUNET_MQ_send (h->mq, env);
return GNUNET_OK;
}
@@ -512,7 +481,7 @@ reconnect_arm (struct GNUNET_ARM_Handle *h)
struct GNUNET_ARM_Handle *
GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_ARM_ConnectionStatusCallback conn_status,
- void *conn_status_cls)
+ void *conn_status_cls)
{
struct GNUNET_ARM_Handle *h;
@@ -539,22 +508,16 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h)
{
struct GNUNET_ARM_Operation *op;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from ARM service\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n");
while (NULL != (op = h->operation_pending_head))
{
GNUNET_CONTAINER_DLL_remove (h->operation_pending_head,
h->operation_pending_tail,
op);
if (NULL != op->result_cont)
- op->result_cont (op->cont_cls,
- GNUNET_ARM_REQUEST_DISCONNECTED,
- 0);
+ op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0);
if (NULL != op->list_cont)
- op->list_cont (op->cont_cls,
- GNUNET_ARM_REQUEST_DISCONNECTED,
- 0,
- NULL);
+ op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL);
if (NULL != op->async)
{
GNUNET_SCHEDULER_cancel (op->async);
@@ -596,60 +559,43 @@ start_arm_service (struct GNUNET_ARM_Handle *h,
char *loprefix;
char *lopostfix;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (h->cfg,
- "arm",
- "PREFIX",
- &loprefix))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
+ "arm",
+ "PREFIX",
+ &loprefix))
loprefix = GNUNET_strdup ("");
else
- loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg,
- loprefix);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (h->cfg,
- "arm",
- "OPTIONS",
- &lopostfix))
+ loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix);
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg,
+ "arm",
+ "OPTIONS",
+ &lopostfix))
lopostfix = GNUNET_strdup ("");
else
- lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg,
- lopostfix);
+ lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, lopostfix);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (h->cfg,
- "arm",
- "BINARY",
- &cbinary))
+ GNUNET_CONFIGURATION_get_value_string (h->cfg, "arm", "BINARY", &cbinary))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "arm",
- "BINARY");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY");
GNUNET_free (loprefix);
GNUNET_free (lopostfix);
return GNUNET_ARM_RESULT_IS_NOT_KNOWN;
}
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (h->cfg,
- "arm",
- "CONFIG",
- &config))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg,
+ "arm",
+ "CONFIG",
+ &config))
config = NULL;
binary = GNUNET_OS_get_libexec_binary_path (cbinary);
- GNUNET_asprintf (&quotedbinary,
- "\"%s\"",
- binary);
+ GNUNET_asprintf (&quotedbinary, "\"%s\"", binary);
GNUNET_free (cbinary);
- if ( (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (h->cfg,
- "TESTING",
- "WEAKRANDOM")) &&
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (h->cfg,
- "TESTING",
- "WEAKRANDOM")) &&
- (GNUNET_NO ==
- GNUNET_CONFIGURATION_have_value (h->cfg,
- "TESTING",
- "HOSTFILE")))
+ if ((GNUNET_YES ==
+ GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "WEAKRANDOM")) &&
+ (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (h->cfg,
+ "TESTING",
+ "WEAKRANDOM")) &&
+ (GNUNET_NO ==
+ GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "HOSTFILE")))
{
/* Means we are ONLY running locally */
/* we're clearly running a test, don't daemonize */
@@ -668,7 +614,8 @@ start_arm_service (struct GNUNET_ARM_Handle *h,
NULL,
loprefix,
quotedbinary,
- "-c", config,
+ "-c",
+ config,
/* no daemonization! */
lopostfix,
NULL);
@@ -683,14 +630,15 @@ start_arm_service (struct GNUNET_ARM_Handle *h,
quotedbinary,
"-d", /* do daemonize */
lopostfix,
- NULL);
+ NULL);
else
proc = GNUNET_OS_start_process_s (GNUNET_NO,
std_inheritance,
NULL,
loprefix,
quotedbinary,
- "-c", config,
+ "-c",
+ config,
"-d", /* do daemonize */
lopostfix,
NULL);
@@ -744,7 +692,7 @@ static struct GNUNET_ARM_Operation *
change_service (struct GNUNET_ARM_Handle *h,
const char *service_name,
GNUNET_ARM_ResultCallback cb,
- void *cb_cls,
+ void *cb_cls,
uint16_t type)
{
struct GNUNET_ARM_Operation *op;
@@ -753,8 +701,7 @@ change_service (struct GNUNET_ARM_Handle *h,
struct GNUNET_ARM_Message *msg;
slen = strlen (service_name) + 1;
- if (slen + sizeof (struct GNUNET_ARM_Message) >=
- GNUNET_MAX_MESSAGE_SIZE)
+ if (slen + sizeof (struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
return NULL;
@@ -769,16 +716,11 @@ change_service (struct GNUNET_ARM_Handle *h,
GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
h->operation_pending_tail,
op);
- env = GNUNET_MQ_msg_extra (msg,
- slen,
- type);
+ env = GNUNET_MQ_msg_extra (msg, slen, type);
msg->reserved = htonl (0);
msg->request_id = GNUNET_htonll (op->id);
- GNUNET_memcpy (&msg[1],
- service_name,
- slen);
- GNUNET_MQ_send (h->mq,
- env);
+ GNUNET_memcpy (&msg[1], service_name, slen);
+ GNUNET_MQ_send (h->mq, env);
return op;
}
@@ -802,10 +744,8 @@ notify_running (void *cls)
op->result_cont (op->cont_cls,
GNUNET_ARM_REQUEST_SENT_OK,
GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
- if ( (GNUNET_YES == h->currently_up) &&
- (NULL != h->conn_status) )
- h->conn_status (h->conn_status_cls,
- GNUNET_YES);
+ if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status))
+ h->conn_status (h->conn_status_cls, GNUNET_YES);
GNUNET_free (op);
}
@@ -846,20 +786,18 @@ notify_starting (void *cls)
* @return handle for the operation, NULL on error
*/
struct GNUNET_ARM_Operation *
-GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
- const char *service_name,
- enum GNUNET_OS_InheritStdioFlags std_inheritance,
- GNUNET_ARM_ResultCallback cont,
- void *cont_cls)
+GNUNET_ARM_request_service_start (
+ struct GNUNET_ARM_Handle *h,
+ const char *service_name,
+ enum GNUNET_OS_InheritStdioFlags std_inheritance,
+ GNUNET_ARM_ResultCallback cont,
+ void *cont_cls)
{
struct GNUNET_ARM_Operation *op;
enum GNUNET_ARM_Result ret;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Starting service `%s'\n",
- service_name);
- if (0 != strcasecmp ("arm",
- service_name))
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name);
+ if (0 != strcasecmp ("arm", service_name))
return change_service (h,
service_name,
cont,
@@ -874,8 +812,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
*/
if (GNUNET_YES == h->currently_up)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "ARM is already running\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n");
op = GNUNET_new (struct GNUNET_ARM_Operation);
op->h = h;
op->result_cont = cont;
@@ -883,8 +820,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
h->operation_pending_tail,
op);
- op->async = GNUNET_SCHEDULER_add_now (&notify_running,
- op);
+ op->async = GNUNET_SCHEDULER_add_now (&notify_running, op);
return op;
}
/* This is an inherently uncertain choice, as it is of course
@@ -893,10 +829,8 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
are unlikely to hammer 'gnunet-arm -s' on a busy system,
the above check should catch 99.99% of the cases where ARM
is already running. */
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Starting ARM service\n");
- ret = start_arm_service (h,
- std_inheritance);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n");
+ ret = start_arm_service (h, std_inheritance);
if (GNUNET_ARM_RESULT_STARTING == ret)
reconnect_arm (h);
op = GNUNET_new (struct GNUNET_ARM_Operation);
@@ -907,8 +841,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
h->operation_pending_tail,
op);
op->starting_ret = ret;
- op->async = GNUNET_SCHEDULER_add_now (&notify_starting,
- op);
+ op->async = GNUNET_SCHEDULER_add_now (&notify_starting, op);
return op;
}
@@ -929,15 +862,13 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
*/
struct GNUNET_ARM_Operation *
GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
- const char *service_name,
- GNUNET_ARM_ResultCallback cont,
- void *cont_cls)
+ const char *service_name,
+ GNUNET_ARM_ResultCallback cont,
+ void *cont_cls)
{
struct GNUNET_ARM_Operation *op;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping service `%s'\n",
- service_name);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name);
op = change_service (h,
service_name,
cont,
@@ -947,8 +878,7 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
return NULL;
/* If the service is ARM, set a flag as we will use MQ errors
to detect that the process is really gone. */
- if (0 == strcasecmp (service_name,
- "arm"))
+ if (0 == strcasecmp (service_name, "arm"))
op->is_arm_stop = GNUNET_YES;
return op;
}
@@ -971,8 +901,7 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
struct GNUNET_MQ_Envelope *env;
struct GNUNET_ARM_Message *msg;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Requesting LIST from ARM service\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n");
if (0 == h->request_id_counter)
h->request_id_counter++;
op = GNUNET_new (struct GNUNET_ARM_Operation);
@@ -983,12 +912,10 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head,
h->operation_pending_tail,
op);
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_ARM_LIST);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_LIST);
msg->reserved = htonl (0);
msg->request_id = GNUNET_htonll (op->id);
- GNUNET_MQ_send (h->mq,
- env);
+ GNUNET_MQ_send (h->mq, env);
return op;
}
diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c
index 15f91c036..55b12240f 100644
--- a/src/arm/arm_monitor_api.c
+++ b/src/arm/arm_monitor_api.c
@@ -32,7 +32,7 @@
#define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
-#define LOG(kind,...) GNUNET_log_from (kind, "arm-monitor-api",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__)
/**
* Handle for interacting with ARM.
@@ -69,7 +69,6 @@ struct GNUNET_ARM_MonitorHandle
* Closure for @e service_status.
*/
void *service_status_cls;
-
};
@@ -115,9 +114,9 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h)
h->mq = NULL;
}
GNUNET_assert (NULL == h->reconnect_task);
- h->reconnect_task
- = GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
- &reconnect_arm_monitor_task, h);
+ h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
+ &reconnect_arm_monitor_task,
+ h);
h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
}
@@ -130,14 +129,14 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h)
* @return #GNUNET_OK if the message is well-formed
*/
static int
-check_monitor_notify (void *cls,
- const struct GNUNET_ARM_StatusMessage *msg)
+check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg)
{
- size_t sl = ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage);
+ size_t sl =
+ ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage);
const char *name = (const char *) &msg[1];
- if ( (0 == sl) ||
- ('\0' != name[sl-1]) )
+ (void) cls;
+ if ((0 == sl) || ('\0' != name[sl - 1]))
{
GNUNET_break (0);
return GNUNET_SYSERR;
@@ -153,8 +152,7 @@ check_monitor_notify (void *cls,
* @param res the message received from the arm service
*/
static void
-handle_monitor_notify (void *cls,
- const struct GNUNET_ARM_StatusMessage *res)
+handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res)
{
struct GNUNET_ARM_MonitorHandle *h = cls;
enum GNUNET_ARM_ServiceStatus status;
@@ -165,9 +163,7 @@ handle_monitor_notify (void *cls,
(const char *) &res[1],
(int) status);
if (NULL != h->service_status)
- h->service_status (h->service_status_cls,
- (const char *) &res[1],
- status);
+ h->service_status (h->service_status_cls, (const char *) &res[1], status);
}
@@ -180,11 +176,11 @@ handle_monitor_notify (void *cls,
* @param error error code
*/
static void
-mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_ARM_MonitorHandle *h = cls;
+ (void) error;
reconnect_arm_monitor_later (h);
}
@@ -198,22 +194,17 @@ mq_error_handler (void *cls,
static int
reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
{
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_var_size (monitor_notify,
- GNUNET_MESSAGE_TYPE_ARM_STATUS,
- struct GNUNET_ARM_StatusMessage,
- h),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_var_size (monitor_notify,
+ GNUNET_MESSAGE_TYPE_ARM_STATUS,
+ struct GNUNET_ARM_StatusMessage,
+ h),
+ GNUNET_MQ_handler_end ()};
struct GNUNET_MessageHeader *msg;
struct GNUNET_MQ_Envelope *env;
GNUNET_assert (NULL == h->mq);
- h->mq = GNUNET_CLIENT_connect (h->cfg,
- "arm",
- handlers,
- &mq_error_handler,
- h);
+ h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h);
if (NULL == h->mq)
{
if (NULL != h->service_status)
@@ -222,10 +213,8 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
GNUNET_ARM_SERVICE_STOPPED);
return GNUNET_SYSERR;
}
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_ARM_MONITOR);
- GNUNET_MQ_send (h->mq,
- env);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR);
+ GNUNET_MQ_send (h->mq, env);
return GNUNET_OK;
}
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c
index c9f00b5dd..667556314 100644
--- a/src/arm/mockup-service.c
+++ b/src/arm/mockup-service.c
@@ -33,13 +33,13 @@ static int special_ret = 0;
* @param message the actual message
*/
static void
-handle_stop (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_stop (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
+ (void) message;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Initiating shutdown as requested by client.\n"));
+ _ ("Initiating shutdown as requested by client.\n"));
GNUNET_SERVICE_client_persist (client);
GNUNET_SCHEDULER_shutdown ();
/* ARM won't exponentially increase restart delay if we
@@ -59,9 +59,11 @@ handle_stop (void *cls,
*/
static void *
client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *c,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_SERVICE_Client *c,
+ struct GNUNET_MQ_Handle *mq)
{
+ (void) cls;
+ (void) mq;
return c;
}
@@ -75,9 +77,10 @@ client_connect_cb (void *cls,
*/
static void
client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *c,
- void *internal_cls)
+ struct GNUNET_SERVICE_Client *c,
+ void *internal_cls)
{
+ (void) cls;
GNUNET_assert (c == internal_cls);
}
@@ -87,6 +90,9 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_SERVICE_Handle *service)
{
+ (void) cls;
+ (void) cfg;
+ (void) service;
/* nothing to do */
}
@@ -94,25 +100,20 @@ run (void *cls,
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("do-nothing",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_fixed_size (stop,
- GNUNET_MESSAGE_TYPE_ARM_STOP,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN ("do-nothing",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_fixed_size (stop,
+ GNUNET_MESSAGE_TYPE_ARM_STOP,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ());
/**
* MINIMIZE heap size (way below 128k) since this process doesn't need much.
*/
-void __attribute__ ((destructor))
-GNUNET_mockup_done ()
-{
- _exit (special_ret);
-}
+void __attribute__ ((destructor)) GNUNET_mockup_done () { _exit (special_ret); }
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 6381d9097..223677a5b 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -341,6 +341,7 @@ core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct PeerRecord *pr = impl_state;
+ (void) mq;
GNUNET_assert (NULL != pr->env);
GNUNET_MQ_discard (pr->env);
pr->env = NULL;
@@ -359,7 +360,8 @@ static void
core_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
/* struct PeerRecord *pr = cls; */
-
+ (void) cls;
+ (void) error;
GNUNET_break_op (0);
}
@@ -530,6 +532,7 @@ check_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm)
uint16_t msize;
const struct GNUNET_MessageHeader *em;
+ (void) cls;
msize = ntohs (ntm->header.size) - sizeof (struct NotifyTrafficMessage);
if (msize < sizeof (struct GNUNET_MessageHeader))
{
diff --git a/src/core/core_api_monitor_peers.c b/src/core/core_api_monitor_peers.c
index 0ebb94d7b..165f741d2 100644
--- a/src/core/core_api_monitor_peers.c
+++ b/src/core/core_api_monitor_peers.c
@@ -54,7 +54,6 @@ struct GNUNET_CORE_MonitorHandle
* Closure for @e peer_cb.
*/
void *peer_cb_cls;
-
};
@@ -77,11 +76,11 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh);
* @param error error code
*/
static void
-handle_mq_error (void *cls,
- enum GNUNET_MQ_Error error)
+handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_CORE_MonitorHandle *mh = cls;
+ (void) error;
reconnect (mh);
}
@@ -93,8 +92,7 @@ handle_mq_error (void *cls,
* @param mon_message monitor message
*/
static void
-handle_receive_info (void *cls,
- const struct MonitorNotifyMessage *mon_message)
+handle_receive_info (void *cls, const struct MonitorNotifyMessage *mon_message)
{
struct GNUNET_CORE_MonitorHandle *mh = cls;
@@ -114,24 +112,20 @@ handle_receive_info (void *cls,
static void
reconnect (struct GNUNET_CORE_MonitorHandle *mh)
{
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (receive_info,
- GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY,
- struct MonitorNotifyMessage,
- mh),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_fixed_size (receive_info,
+ GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY,
+ struct MonitorNotifyMessage,
+ mh),
+ GNUNET_MQ_handler_end ()};
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
if (NULL != mh->mq)
GNUNET_MQ_destroy (mh->mq);
/* FIXME: use backoff? */
- mh->mq = GNUNET_CLIENT_connect (mh->cfg,
- "core",
- handlers,
- &handle_mq_error,
- mh);
+ mh->mq =
+ GNUNET_CLIENT_connect (mh->cfg, "core", handlers, &handle_mq_error, mh);
if (NULL == mh->mq)
return;
/* notify callback about reconnect */
@@ -140,10 +134,8 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh)
NULL,
GNUNET_CORE_KX_CORE_DISCONNECT,
GNUNET_TIME_UNIT_FOREVER_ABS);
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS);
- GNUNET_MQ_send (mh->mq,
- env);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS);
+ GNUNET_MQ_send (mh->mq, env);
}
diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c
index 7180754a9..674da705a 100644
--- a/src/core/gnunet-core.c
+++ b/src/core/gnunet-core.c
@@ -48,6 +48,7 @@ static struct GNUNET_CORE_MonitorHandle *mh;
static void
shutdown_task (void *cls)
{
+ (void) cls;
if (NULL != mh)
{
GNUNET_CORE_monitor_stop (mh);
@@ -71,13 +72,13 @@ monitor_cb (void *cls,
enum GNUNET_CORE_KxState state,
struct GNUNET_TIME_Absolute timeout)
{
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
const char *now_str;
const char *state_str;
- if ( ( (NULL == peer) ||
- (GNUNET_CORE_KX_ITERATION_FINISHED == state) ) &&
- (GNUNET_NO == monitor_connections) )
+ (void) cls;
+ if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) &&
+ (GNUNET_NO == monitor_connections))
{
GNUNET_SCHEDULER_shutdown ();
return;
@@ -87,42 +88,43 @@ monitor_cb (void *cls,
{
case GNUNET_CORE_KX_STATE_DOWN:
/* should never happen, as we immediately send the key */
- state_str = _("fresh connection");
+ state_str = _ ("fresh connection");
break;
case GNUNET_CORE_KX_STATE_KEY_SENT:
- state_str = _("key sent");
+ state_str = _ ("key sent");
break;
case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
- state_str = _("key received");
+ state_str = _ ("key received");
break;
case GNUNET_CORE_KX_STATE_UP:
- state_str = _("connection established");
+ state_str = _ ("connection established");
break;
case GNUNET_CORE_KX_STATE_REKEY_SENT:
- state_str = _("rekeying");
+ state_str = _ ("rekeying");
break;
case GNUNET_CORE_KX_PEER_DISCONNECT:
- state_str = _("disconnected");
+ state_str = _ ("disconnected");
break;
case GNUNET_CORE_KX_ITERATION_FINISHED:
return;
case GNUNET_CORE_KX_CORE_DISCONNECT:
FPRINTF (stderr,
"%s\n",
- _("Connection to CORE service lost (reconnecting)"));
+ _ ("Connection to CORE service lost (reconnecting)"));
return;
default:
- state_str = _("unknown state");
+ state_str = _ ("unknown state");
break;
}
now_str = GNUNET_STRINGS_absolute_time_to_string (now);
FPRINTF (stdout,
- _("%24s: %-30s %4s (timeout in %6s)\n"),
+ _ ("%24s: %-30s %4s (timeout in %6s)\n"),
now_str,
state_str,
GNUNET_i2s (peer),
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (timeout),
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_remaining (timeout),
+ GNUNET_YES));
}
@@ -135,24 +137,22 @@ monitor_cb (void *cls,
* @param cfg configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ (void) cls;
+ (void) cfgfile;
if (NULL != args[0])
{
- FPRINTF (stderr,
- _("Invalid command line argument `%s'\n"),
- args[0]);
+ FPRINTF (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
return;
}
- mh = GNUNET_CORE_monitor_start (cfg,
- &monitor_cb,
- NULL);
+ mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL);
if (NULL == mh)
{
- FPRINTF (stderr,
- "%s",
- _("Failed to connect to CORE service!\n"));
+ FPRINTF (stderr, "%s", _ ("Failed to connect to CORE service!\n"));
return;
}
GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
@@ -167,24 +167,28 @@ run (void *cls, char *const *args, const char *cfgfile,
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
int res;
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('m',
- "monitor",
- gettext_noop ("provide information about all current connections (continuously)"),
- &monitor_connections),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag (
+ 'm',
+ "monitor",
+ gettext_noop (
+ "provide information about all current connections (continuously)"),
+ &monitor_connections),
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- res = GNUNET_PROGRAM_run (argc, argv, "gnunet-core",
- gettext_noop
- ("Print information about connected peers."),
- options, &run, NULL);
+ res = GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-core",
+ gettext_noop (
+ "Print information about connected peers."),
+ options,
+ &run,
+ NULL);
GNUNET_free ((void *) argv);
if (GNUNET_OK == res)
diff --git a/src/curl/curl.c b/src/curl/curl.c
index 749094800..38a1f5fcd 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -111,7 +111,6 @@ struct GNUNET_CURL_Job
* after the job has finished.
*/
struct curl_slist *job_headers;
-
};
@@ -161,7 +160,6 @@ struct GNUNET_CURL_Context
* Closure for @e cb.
*/
void *cb_cls;
-
};
@@ -213,7 +211,8 @@ GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls)
* @param header_name name of the header to send.
*/
void
-GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, const char *header_name)
+GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx,
+ const char *header_name)
{
ctx->async_scope_id_header = header_name;
}
@@ -279,30 +278,26 @@ download_cb (char *bufptr, size_t size, size_t nitems, void *cls)
*/
struct GNUNET_CURL_Job *
GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx,
- CURL *eh,
- const struct curl_slist *job_headers,
- GNUNET_CURL_JobCompletionCallback jcc,
- void *jcc_cls)
+ CURL *eh,
+ const struct curl_slist *job_headers,
+ GNUNET_CURL_JobCompletionCallback jcc,
+ void *jcc_cls)
{
struct GNUNET_CURL_Job *job;
struct curl_slist *all_headers = NULL;
- for (const struct curl_slist *curr = job_headers;
- curr != NULL;
+ for (const struct curl_slist *curr = job_headers; curr != NULL;
curr = curr->next)
{
- GNUNET_assert (
- NULL != (all_headers =
- curl_slist_append (all_headers, curr->data)));
+ GNUNET_assert (NULL !=
+ (all_headers = curl_slist_append (all_headers, curr->data)));
}
- for (const struct curl_slist *curr = ctx->common_headers;
- curr != NULL;
+ for (const struct curl_slist *curr = ctx->common_headers; curr != NULL;
curr = curr->next)
{
- GNUNET_assert (
- NULL != (all_headers =
- curl_slist_append (all_headers, curr->data)));
+ GNUNET_assert (NULL !=
+ (all_headers = curl_slist_append (all_headers, curr->data)));
}
if (NULL != ctx->async_scope_id_header)
@@ -313,8 +308,10 @@ GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx,
if (GNUNET_YES == scope.have_scope)
{
char *aid_header = NULL;
- aid_header = GNUNET_STRINGS_data_to_string_alloc (&scope.scope_id,
- sizeof (struct GNUNET_AsyncScopeId));
+ aid_header =
+ GNUNET_STRINGS_data_to_string_alloc (&scope.scope_id,
+ sizeof (
+ struct GNUNET_AsyncScopeId));
GNUNET_assert (NULL != aid_header);
GNUNET_assert (NULL != curl_slist_append (all_headers, aid_header));
GNUNET_free (aid_header);
@@ -378,7 +375,9 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
GNUNET_CURL_JobCompletionCallback jcc,
void *jcc_cls)
{
+ struct GNUNET_CURL_Job *job;
struct curl_slist *job_headers = NULL;
+
if (GNUNET_YES == add_json)
{
GNUNET_assert (
@@ -386,7 +385,9 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx,
curl_slist_append (NULL, "Content-Type: application/json")));
}
- return GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls);
+ job = GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls);
+ curl_slist_free_all (job_headers);
+ return job;
}
@@ -430,9 +431,9 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job)
* @return NULL if downloading a JSON reply failed.
*/
void *
-download_get_result (struct GNUNET_CURL_DownloadBuffer *db,
- CURL *eh,
- long *response_code)
+GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
+ CURL *eh,
+ long *response_code)
{
json_t *json;
json_error_t error;
@@ -522,15 +523,16 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx,
GNUNET_CURL_ResponseCleaner rc)
{
CURLMsg *cmsg;
- struct GNUNET_CURL_Job *job;
int n_running;
int n_completed;
- long response_code;
- void *response;
(void) curl_multi_perform (ctx->multi, &n_running);
while (NULL != (cmsg = curl_multi_info_read (ctx->multi, &n_completed)))
{
+ struct GNUNET_CURL_Job *job;
+ long response_code;
+ void *response;
+
/* Only documented return value is CURLMSG_DONE */
GNUNET_break (CURLMSG_DONE == cmsg->msg);
GNUNET_assert (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle,
@@ -619,9 +621,8 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx,
void
GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx)
{
-
GNUNET_CURL_perform2 (ctx,
- download_get_result,
+ &GNUNET_CURL_download_get_result_,
(GNUNET_CURL_ResponseCleaner) &json_decref);
}
diff --git a/src/curl/curl_reschedule.c b/src/curl/curl_reschedule.c
index 1b0f2e440..354ba13df 100644
--- a/src/curl/curl_reschedule.c
+++ b/src/curl/curl_reschedule.c
@@ -28,9 +28,9 @@
#include "gnunet_util_lib.h"
extern void *
-download_get_result (struct GNUNET_CURL_DownloadBuffer *db,
- CURL *eh,
- long *response_code);
+GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db,
+ CURL *eh,
+ long *response_code);
/**
* Closure for #GNUNET_CURL_gnunet_scheduler_reschedule().
@@ -105,7 +105,7 @@ GNUNET_CURL_gnunet_rc_create (struct GNUNET_CURL_Context *ctx)
rc = GNUNET_new (struct GNUNET_CURL_RescheduleContext);
rc->ctx = ctx;
- rc->parser = &download_get_result;
+ rc->parser = &GNUNET_CURL_download_get_result_;
rc->cleaner = &clean_result;
return rc;
}
@@ -145,9 +145,7 @@ context_task (void *cls)
rc->task = NULL;
- GNUNET_CURL_perform2 (rc->ctx,
- rc->parser,
- rc->cleaner);
+ GNUNET_CURL_perform2 (rc->ctx, rc->parser, rc->cleaner);
max_fd = -1;
timeout = -1;
FD_ZERO (&read_fd_set);
@@ -160,18 +158,14 @@ context_task (void *cls)
&max_fd,
&timeout);
if (timeout >= 0)
- delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- timeout);
+ delay =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout);
else
delay = GNUNET_TIME_UNIT_FOREVER_REL;
rs = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_copy_native (rs,
- &read_fd_set,
- max_fd + 1);
+ GNUNET_NETWORK_fdset_copy_native (rs, &read_fd_set, max_fd + 1);
ws = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_copy_native (ws,
- &write_fd_set,
- max_fd + 1);
+ GNUNET_NETWORK_fdset_copy_native (ws, &write_fd_set, max_fd + 1);
if (NULL == rc->task)
rc->task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
delay,
@@ -196,12 +190,11 @@ context_task (void *cls)
void
GNUNET_CURL_gnunet_scheduler_reschedule (void *cls)
{
- struct GNUNET_CURL_RescheduleContext *rc = *(void**) cls;
+ struct GNUNET_CURL_RescheduleContext *rc = *(void **) cls;
if (NULL != rc->task)
GNUNET_SCHEDULER_cancel (rc->task);
- rc->task = GNUNET_SCHEDULER_add_now (&context_task,
- rc);
+ rc->task = GNUNET_SCHEDULER_add_now (&context_task, rc);
}
/* end of curl_reschedule.c */
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 0a68e7cba..932b8d218 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -81,7 +81,7 @@ noinst_PROGRAMS = \
gnunet-gns-benchmark
pkgdata_DATA = \
- openssl.cnf
+ gnunet-gns-proxy-ca.template
if HAVE_MHD
if LINUX
diff --git a/src/gns/gnunet-gns-proxy-ca.template b/src/gns/gnunet-gns-proxy-ca.template
new file mode 100644
index 000000000..32ee27fcd
--- /dev/null
+++ b/src/gns/gnunet-gns-proxy-ca.template
@@ -0,0 +1,303 @@
+# X.509 Certificate options
+#
+# DN options
+
+# The organization of the subject.
+organization = "GNU"
+
+# The organizational unit of the subject.
+unit = "GNUnet"
+
+# The locality of the subject.
+locality = World
+
+# The state of the certificate owner.
+# state = "Attiki"
+
+# The country of the subject. Two letter code.
+country = ZZ
+
+# The common name of the certificate owner.
+cn = "GNS Proxy CA"
+
+# A user id of the certificate owner.
+#uid = "clauper"
+
+# Set domain components
+#dc = "name"
+#dc = "domain"
+
+# If the supported DN OIDs are not adequate you can set
+# any OID here.
+# For example set the X.520 Title and the X.520 Pseudonym
+# by using OID and string pairs.
+#dn_oid = "2.5.4.12 Dr."
+#dn_oid = "2.5.4.65 jackal"
+
+# This is deprecated and should not be used in new
+# certificates.
+# pkcs9_email = "none@none.org"
+
+# An alternative way to set the certificate's distinguished name directly
+# is with the "dn" option. The attribute names allowed are:
+# C (country), street, O (organization), OU (unit), title, CN (common name),
+# L (locality), ST (state), placeOfBirth, gender, countryOfCitizenship,
+# countryOfResidence, serialNumber, telephoneNumber, surName, initials,
+# generationQualifier, givenName, pseudonym, dnQualifier, postalCode, name,
+# businessCategory, DC, UID, jurisdictionOfIncorporationLocalityName,
+# jurisdictionOfIncorporationStateOrProvinceName,
+# jurisdictionOfIncorporationCountryName, XmppAddr, and numeric OIDs.
+
+#dn = "cn = Nikos,st = New\, Something,C=GR,surName=Mavrogiannopoulos,2.5.4.9=Arkadias"
+
+# The serial number of the certificate
+# The value is in decimal (i.e. 1963) or hex (i.e. 0x07ab).
+# Comment the field for a random serial number.
+#serial = 007
+
+# In how many days, counting from today, this certificate will expire.
+# Use -1 if there is no expiration date.
+expiration_days = 3650
+
+# Alternatively you may set concrete dates and time. The GNU date string
+# formats are accepted. See:
+# https://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html
+
+#activation_date = "2004-02-29 16:21:42"
+#expiration_date = "2025-02-29 16:24:41"
+
+# X.509 v3 extensions
+
+# A dnsname in case of a WWW server.
+#dns_name = "www.none.org"
+#dns_name = "www.morethanone.org"
+
+# An othername defined by an OID and a hex encoded string
+#other_name = "1.3.6.1.5.2.2 302ca00d1b0b56414e5245494e2e4f5247a11b3019a006020400000002a10f300d1b047269636b1b0561646d696e"
+#other_name_utf8 = "1.2.4.5.6 A UTF8 string"
+#other_name_octet = "1.2.4.5.6 A string that will be encoded as ASN.1 octet string"
+
+# Allows writing an XmppAddr Identifier
+#xmpp_name = juliet@im.example.com
+
+# Names used in PKINIT
+#krb5_principal = user@REALM.COM
+#krb5_principal = HTTP/user@REALM.COM
+
+# A subject alternative name URI
+#uri = "https://www.example.com"
+
+# An IP address in case of a server.
+#ip_address = "192.168.1.1"
+
+# An email in case of a person
+email = "bounce@gnunet.org"
+
+# TLS feature (rfc7633) extension. That can is used to indicate mandatory TLS
+# extension features to be provided by the server. In practice this is used
+# to require the Status Request (extid: 5) extension from the server. That is,
+# to require the server holding this certificate to provide a stapled OCSP response.
+# You can have multiple lines for multiple TLS features.
+
+# To ask for OCSP status request use:
+#tls_feature = 5
+
+# Challenge password used in certificate requests
+challenge_password = 123456
+
+# Password when encrypting a private key
+#password = secret
+
+# An URL that has CRLs (certificate revocation lists)
+# available. Needed in CA certificates.
+#crl_dist_points = "https://www.getcrl.crl/getcrl/"
+
+# Whether this is a CA certificate or not
+ca
+
+# Subject Unique ID (in hex)
+#subject_unique_id = 00153224
+
+# Issuer Unique ID (in hex)
+#issuer_unique_id = 00153225
+
+#### Key usage
+
+# The following key usage flags are used by CAs and end certificates
+
+# Whether this certificate will be used to sign data (needed
+# in TLS DHE ciphersuites). This is the digitalSignature flag
+# in RFC5280 terminology.
+signing_key
+
+# Whether this certificate will be used to encrypt data (needed
+# in TLS RSA ciphersuites). Note that it is preferred to use different
+# keys for encryption and signing. This is the keyEncipherment flag
+# in RFC5280 terminology.
+encryption_key
+
+# Whether this key will be used to sign other certificates. The
+# keyCertSign flag in RFC5280 terminology.
+cert_signing_key
+
+# Whether this key will be used to sign CRLs. The
+# cRLSign flag in RFC5280 terminology.
+#crl_signing_key
+
+# The keyAgreement flag of RFC5280. It's purpose is loosely
+# defined. Not use it unless required by a protocol.
+#key_agreement
+
+# The dataEncipherment flag of RFC5280. It's purpose is loosely
+# defined. Not use it unless required by a protocol.
+#data_encipherment
+
+# The nonRepudiation flag of RFC5280. It's purpose is loosely
+# defined. Not use it unless required by a protocol.
+#non_repudiation
+
+#### Extended key usage (key purposes)
+
+# The following extensions are used in an end certificate
+# to clarify its purpose. Some CAs also use it to indicate
+# the types of certificates they are purposed to sign.
+
+
+# Whether this certificate will be used for a TLS client;
+# this sets the id-kp-clientAuth (1.3.6.1.5.5.7.3.2) of
+# extended key usage.
+#tls_www_client
+
+# Whether this certificate will be used for a TLS server;
+# this sets the id-kp-serverAuth (1.3.6.1.5.5.7.3.1) of
+# extended key usage.
+tls_www_server
+
+# Whether this key will be used to sign code. This sets the
+# id-kp-codeSigning (1.3.6.1.5.5.7.3.3) of extended key usage
+# extension.
+#code_signing_key
+
+# Whether this key will be used to sign OCSP data. This sets the
+# id-kp-OCSPSigning (1.3.6.1.5.5.7.3.9) of extended key usage extension.
+#ocsp_signing_key
+
+# Whether this key will be used for time stamping. This sets the
+# id-kp-timeStamping (1.3.6.1.5.5.7.3.8) of extended key usage extension.
+#time_stamping_key
+
+# Whether this key will be used for email protection. This sets the
+# id-kp-emailProtection (1.3.6.1.5.5.7.3.4) of extended key usage extension.
+#email_protection_key
+
+# Whether this key will be used for IPsec IKE operations (1.3.6.1.5.5.7.3.17).
+#ipsec_ike_key
+
+## adding custom key purpose OIDs
+
+# for microsoft smart card logon
+# key_purpose_oid = 1.3.6.1.4.1.311.20.2.2
+
+# for email protection
+# key_purpose_oid = 1.3.6.1.5.5.7.3.4
+
+# for any purpose (must not be used in intermediate CA certificates)
+# key_purpose_oid = 2.5.29.37.0
+
+### end of key purpose OIDs
+
+### Adding arbitrary extensions
+# This requires to provide the extension OIDs, as well as the extension data in
+# hex format. The following two options are available since GnuTLS 3.5.3.
+#add_extension = "1.2.3.4 0x0AAB01ACFE"
+
+# As above but encode the data as an octet string
+#add_extension = "1.2.3.4 octet_string(0x0AAB01ACFE)"
+
+# For portability critical extensions shouldn't be set to certificates.
+#add_critical_extension = "5.6.7.8 0x1AAB01ACFE"
+
+# When generating a certificate from a certificate
+# request, then honor the extensions stored in the request
+# and store them in the real certificate.
+#honor_crq_extensions
+
+# Alternatively only specific extensions can be copied.
+#honor_crq_ext = 2.5.29.17
+#honor_crq_ext = 2.5.29.15
+
+# Path length contraint. Sets the maximum number of
+# certificates that can be used to certify this certificate.
+# (i.e. the certificate chain length)
+#path_len = -1
+#path_len = 2
+
+# OCSP URI
+# ocsp_uri = https://my.ocsp.server/ocsp
+
+# CA issuers URI
+# ca_issuers_uri = https://my.ca.issuer
+
+# Certificate policies
+#policy1 = 1.3.6.1.4.1.5484.1.10.99.1.0
+#policy1_txt = "This is a long policy to summarize"
+#policy1_url = https://www.example.com/a-policy-to-read
+
+#policy2 = 1.3.6.1.4.1.5484.1.10.99.1.1
+#policy2_txt = "This is a short policy"
+#policy2_url = https://www.example.com/another-policy-to-read
+
+# The number of additional certificates that may appear in a
+# path before the anyPolicy is no longer acceptable.
+#inhibit_anypolicy_skip_certs 1
+
+# Name constraints
+
+# DNS
+#nc_permit_dns = example.com
+#nc_exclude_dns = test.example.com
+
+# EMAIL
+#nc_permit_email = "nmav@ex.net"
+
+# Exclude subdomains of example.com
+#nc_exclude_email = .example.com
+
+# Exclude all e-mail addresses of example.com
+#nc_exclude_email = example.com
+
+# IP
+#nc_permit_ip = 192.168.0.0/16
+#nc_exclude_ip = 192.168.5.0/24
+#nc_permit_ip = fc0a:eef2:e7e7:a56e::/64
+
+
+# Options for proxy certificates
+#proxy_policy_language = 1.3.6.1.5.5.7.21.1
+
+
+# Options for generating a CRL
+
+# The number of days the next CRL update will be due.
+# next CRL update will be in 43 days
+#crl_next_update = 43
+
+# this is the 5th CRL by this CA
+# The value is in decimal (i.e. 1963) or hex (i.e. 0x07ab).
+# Comment the field for a time-based number.
+# Time-based CRL numbers generated in GnuTLS 3.6.3 and later
+# are significantly larger than those generated in previous
+# versions. Since CRL numbers need to be monotonic, you need
+# to specify the CRL number here manually if you intend to
+# downgrade to an earlier version than 3.6.3 after publishing
+# the CRL as it is not possible to specify CRL numbers greater
+# than 2**63-2 using hex notation in those versions.
+#crl_number = 5
+
+# Specify the update dates more precisely.
+#crl_this_update_date = "2004-02-29 16:21:42"
+#crl_next_update_date = "2025-02-29 16:24:41"
+
+# The date that the certificates will be made seen as
+# being revoked.
+#crl_revocation_date = "2025-02-29 16:24:41"
diff --git a/src/gns/gnunet-gns-proxy-setup-ca.in b/src/gns/gnunet-gns-proxy-setup-ca.in
index cd5d8c70f..b19b6c001 100644
--- a/src/gns/gnunet-gns-proxy-setup-ca.in
+++ b/src/gns/gnunet-gns-proxy-setup-ca.in
@@ -133,13 +133,29 @@ generate_ca()
# ------------- openssl
+ GNUTLS_CA_TEMPLATE=@pkgdatadir@/gnunet-gns-proxy-ca.template
OPENSSLCFG=@pkgdatadir@/openssl.cnf
- if test -z "`openssl version`" > /dev/null
+ CERTTOOL=""
+ OPENSSL=0
+ if test -z "`gnutls-certtool --version`" > /dev/null
then
- warningmsg "'openssl' command not found. Please install it."
- infomsg "Cleaning up."
- rm -f $GNSCAKY $GNSCANO $GNSCERT
- exit 1
+ # We only support gnutls certtool for now
+ if test -z "`certtool --version | grep gnutls`" > /dev/null
+ then
+ warningmsg "'gnutls-certtool' or 'certtool' command not found. Trying openssl."
+ if test -z "`openssl version`" > /dev/null
+ then
+ $OPENSSL=1
+ else
+ warningmsg "Install either gnutls certtool or openssl for certificate generation!"
+ infomsg "Cleaning up."
+ rm -f $GNSCAKY $GNSCERT
+ exit 1
+ fi
+ fi
+ CERTTOOL="certtool"
+ else
+ CERTTOOL="gnutls-certtool"
fi
if [ -n "${GNUNET_CONFIG_FILE}" ]; then
GNUNET_CONFIG="-c ${GNUNET_CONFIG_FILE}"
@@ -149,13 +165,18 @@ generate_ca()
GNS_CA_CERT_PEM=`gnunet-config ${GNUNET_CONFIG} -s gns-proxy -o PROXY_CACERT -f ${options}`
mkdir -p `dirname $GNS_CA_CERT_PEM`
- openssl req -config $OPENSSLCFG -new -x509 -days 3650 -extensions v3_ca -keyout $GNSCAKY -out $GNSCERT -subj "/C=ZZ/L=World/O=GNU/OU=GNUnet/CN=GNS Proxy CA/emailAddress=bounce@gnunet.org" -passout pass:"GNU Name System"
-
- infomsg "Removing passphrase from key"
- openssl rsa -passin pass:"GNU Name System" -in $GNSCAKY -out $GNSCANO
-
- infomsg "Making private key available to gnunet-gns-proxy"
- cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM
+ if test 1 -eq $OPENSSL
+ then
+ openssl req -config $OPENSSLCFG -new -x509 -days 3650 -extensions v3_ca -keyout $GNSCAKY -out $GNSCERT -subj "/C=ZZ/L=World/O=GNU/OU=GNUnet/CN=GNS Proxy CA/emailAddress=bounce@gnunet.org" -passout pass:"GNU Name System"
+ infomsg "Removing passphrase from key"
+ openssl rsa -passin pass:"GNU Name System" -in $GNSCAKY -out $GNSCANO
+ cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM
+ else
+ $CERTTOOL --generate-privkey --outfile $GNSCAKY
+ $CERTTOOL --template $GNUTLS_CA_TEMPLATE --generate-self-signed --load-privkey $GNSCAKY --outfile $GNSCERT
+ infomsg "Making private key available to gnunet-gns-proxy"
+ cat $GNSCERT $GNSCAKY > $GNS_CA_CERT_PEM
+ fi
}
importbrowsers()
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 0fca53b7f..66d0b8ac3 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -273,6 +273,18 @@ struct GNUNET_ShortHashCode
/**
+ * A UUID, a 128 bit random value.
+ */
+struct GNUNET_Uuid
+{
+ /**
+ * 128 random bits.
+ */
+ uint32_t value[4];
+};
+
+
+/**
* Header for all communications.
*/
struct GNUNET_MessageHeader
@@ -495,7 +507,6 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
#define GNUNET_log_from(kind, comp, ...) \
do \
{ \
- int log_line = __LINE__; \
static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
if ((GNUNET_EXTRA_LOGGING > 0) || \
((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
@@ -506,7 +517,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
(comp), \
__FILE__, \
__FUNCTION__, \
- log_line); \
+ __LINE__); \
if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
{ \
GNUNET_log_skip (-1, GNUNET_NO); \
@@ -522,7 +533,6 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
#define GNUNET_log(kind, ...) \
do \
{ \
- int log_line = __LINE__; \
static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
if ((GNUNET_EXTRA_LOGGING > 0) || \
((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
@@ -533,7 +543,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
NULL, \
__FILE__, \
__FUNCTION__, \
- log_line); \
+ __LINE__); \
if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
{ \
GNUNET_log_skip (-1, GNUNET_NO); \
@@ -655,6 +665,19 @@ GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
/**
* @ingroup logging
+ * Convert a UUID to a string (for printing debug messages).
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
+ *
+ * @param uuid the UUID
+ * @return string
+ */
+const char *
+GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
+
+
+/**
+ * @ingroup logging
* Convert a hash value to a string (for printing debug messages).
* This is one of the very few calls in the entire API that is
* NOT reentrant!
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index fee851e1c..fbfbf2d40 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -84,9 +84,7 @@ GNUNET_try_compression (const char *data,
* @return NULL on error, buffer of @a output_size decompressed bytes otherwise
*/
char *
-GNUNET_decompress (const char *input,
- size_t input_size,
- size_t output_size);
+GNUNET_decompress (const char *input, size_t input_size, size_t output_size);
#if HAVE_EXTRACTOR_H
@@ -101,7 +99,8 @@ GNUNET_decompress (const char *input,
* Enumeration defining various sources of keywords. See also
* http://dublincore.org/documents/1998/09/dces/
*/
-enum EXTRACTOR_MetaType {
+enum EXTRACTOR_MetaType
+{
EXTRACTOR_METATYPE_RESERVED = 0,
EXTRACTOR_METATYPE_MIMETYPE = 1,
EXTRACTOR_METATYPE_FILENAME = 2,
@@ -131,7 +130,8 @@ enum EXTRACTOR_MetaType {
/**
* Format in which the extracted meta data is presented.
*/
-enum EXTRACTOR_MetaFormat {
+enum EXTRACTOR_MetaFormat
+{
/**
* Format is unknown.
*/
@@ -173,14 +173,13 @@ enum EXTRACTOR_MetaFormat {
* @param data_len number of bytes in @a data
* @return 0 to continue extracting, 1 to abort
*/
-typedef int
-(*EXTRACTOR_MetaDataProcessor) (void *cls,
- const char *plugin_name,
- enum EXTRACTOR_MetaType type,
- enum EXTRACTOR_MetaFormat format,
- const char *data_mime_type,
- const char *data,
- size_t data_len);
+typedef int (*EXTRACTOR_MetaDataProcessor) (void *cls,
+ const char *plugin_name,
+ enum EXTRACTOR_MetaType type,
+ enum EXTRACTOR_MetaFormat format,
+ const char *data_mime_type,
+ const char *data,
+ size_t data_len);
#endif
@@ -190,9 +189,8 @@ typedef int
#endif
#ifdef __cplusplus
-extern "C"
-{
-#if 0 /* keep Emacsens' auto-indent happy */
+extern "C" {
+#if 0 /* keep Emacsens' auto-indent happy */
}
#endif
#endif
@@ -216,9 +214,8 @@ struct GNUNET_CONTAINER_BloomFilter;
* @return #GNUNET_YES if next was updated
* #GNUNET_NO if there are no more entries
*/
-typedef int
-(*GNUNET_CONTAINER_HashCodeIterator) (void *cls,
- struct GNUNET_HashCode *next);
+typedef int (*GNUNET_CONTAINER_HashCodeIterator) (void *cls,
+ struct GNUNET_HashCode *next);
/**
@@ -269,9 +266,10 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data,
* @return #GNUNET_SYSERR if the data array of the wrong size
*/
int
-GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct GNUNET_CONTAINER_BloomFilter *bf,
- char *data,
- size_t size);
+GNUNET_CONTAINER_bloomfilter_get_raw_data (
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
+ char *data,
+ size_t size);
/**
@@ -283,8 +281,9 @@ GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct GNUNET_CONTAINER_BloomFi
* @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_HashCode *e);
+GNUNET_CONTAINER_bloomfilter_test (
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
+ const struct GNUNET_HashCode *e);
/**
@@ -319,8 +318,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
* @return copy of bf
*/
struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf);
-
+GNUNET_CONTAINER_bloomfilter_copy (
+ const struct GNUNET_CONTAINER_BloomFilter *bf);
/**
@@ -342,7 +341,8 @@ GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter *bf);
* @return addresses set per element in the bf
*/
size_t
-GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter *bf);
+GNUNET_CONTAINER_bloomfilter_get_element_addresses (
+ const struct GNUNET_CONTAINER_BloomFilter *bf);
/**
@@ -353,7 +353,8 @@ GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINE
* @return number of bytes used for the data of the bloom filter
*/
size_t
-GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter *bf);
+GNUNET_CONTAINER_bloomfilter_get_size (
+ const struct GNUNET_CONTAINER_BloomFilter *bf);
/**
@@ -380,7 +381,8 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf);
*/
int
GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
- const char *data, size_t size);
+ const char *data,
+ size_t size);
/**
@@ -394,8 +396,9 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
* @return #GNUNET_OK on success
*/
int
-GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_CONTAINER_BloomFilter *to_or);
+GNUNET_CONTAINER_bloomfilter_or2 (
+ struct GNUNET_CONTAINER_BloomFilter *bf,
+ const struct GNUNET_CONTAINER_BloomFilter *to_or);
/**
@@ -445,7 +448,8 @@ GNUNET_CONTAINER_meta_data_create (void);
* @return duplicate meta-data container
*/
struct GNUNET_CONTAINER_MetaData *
-GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData *md);
+GNUNET_CONTAINER_meta_data_duplicate (
+ const struct GNUNET_CONTAINER_MetaData *md);
/**
@@ -470,8 +474,9 @@ GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
* @return #GNUNET_YES if they are equal
*/
int
-GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData *md1,
- const struct GNUNET_CONTAINER_MetaData *md2);
+GNUNET_CONTAINER_meta_data_test_equal (
+ const struct GNUNET_CONTAINER_MetaData *md1,
+ const struct GNUNET_CONTAINER_MetaData *md2);
/**
@@ -551,7 +556,8 @@ GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
* @param md metadata to modify
*/
void
-GNUNET_CONTAINER_meta_data_add_publication_date (struct GNUNET_CONTAINER_MetaData *md);
+GNUNET_CONTAINER_meta_data_add_publication_date (
+ struct GNUNET_CONTAINER_MetaData *md);
/**
@@ -582,8 +588,9 @@ GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
* @return NULL if no entry was found
*/
char *
-GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData *md,
- enum EXTRACTOR_MetaType type);
+GNUNET_CONTAINER_meta_data_get_by_type (
+ const struct GNUNET_CONTAINER_MetaData *md,
+ enum EXTRACTOR_MetaType type);
/**
@@ -599,8 +606,9 @@ GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData *
* otherwise client is responsible for freeing the value!
*/
char *
-GNUNET_CONTAINER_meta_data_get_first_by_types (const struct GNUNET_CONTAINER_MetaData *md,
- ...);
+GNUNET_CONTAINER_meta_data_get_first_by_types (
+ const struct GNUNET_CONTAINER_MetaData *md,
+ ...);
/**
* @ingroup metadata
@@ -613,9 +621,9 @@ GNUNET_CONTAINER_meta_data_get_first_by_types (const struct GNUNET_CONTAINER_Met
* @return number of bytes in thumbnail, 0 if not available
*/
size_t
-GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData *md,
- unsigned char **thumb);
-
+GNUNET_CONTAINER_meta_data_get_thumbnail (
+ const struct GNUNET_CONTAINER_MetaData *md,
+ unsigned char **thumb);
/**
@@ -661,10 +669,11 @@ enum GNUNET_CONTAINER_MetaDataSerializationOptions
* space)
*/
ssize_t
-GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData *md,
- char **target,
- size_t max,
- enum GNUNET_CONTAINER_MetaDataSerializationOptions opt);
+GNUNET_CONTAINER_meta_data_serialize (
+ const struct GNUNET_CONTAINER_MetaData *md,
+ char **target,
+ size_t max,
+ enum GNUNET_CONTAINER_MetaDataSerializationOptions opt);
/**
@@ -675,7 +684,8 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData *md
* @return number of bytes needed for serialization, -1 on error
*/
ssize_t
-GNUNET_CONTAINER_meta_data_get_serialized_size (const struct GNUNET_CONTAINER_MetaData *md);
+GNUNET_CONTAINER_meta_data_get_serialized_size (
+ const struct GNUNET_CONTAINER_MetaData *md);
/**
@@ -688,8 +698,7 @@ GNUNET_CONTAINER_meta_data_get_serialized_size (const struct GNUNET_CONTAINER_Me
* bad format)
*/
struct GNUNET_CONTAINER_MetaData *
-GNUNET_CONTAINER_meta_data_deserialize (const char *input,
- size_t size);
+GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size);
/* ******************************* HashMap **************************** */
@@ -759,10 +768,10 @@ enum GNUNET_CONTAINER_MultiHashMapOption
* iterate,
* #GNUNET_NO if not.
*/
-typedef int
-(*GNUNET_CONTAINER_HashMapIterator) (void *cls,
- const struct GNUNET_HashCode *key,
- void *value);
+typedef int (*GNUNET_CONTAINER_HashMapIterator) (
+ void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value);
/**
@@ -782,8 +791,7 @@ typedef int
* @return NULL on error
*/
struct GNUNET_CONTAINER_MultiHashMap *
-GNUNET_CONTAINER_multihashmap_create (unsigned int len,
- int do_not_copy_keys);
+GNUNET_CONTAINER_multihashmap_create (unsigned int len, int do_not_copy_keys);
/**
@@ -794,7 +802,8 @@ GNUNET_CONTAINER_multihashmap_create (unsigned int len,
* @param map the map
*/
void
-GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map);
+GNUNET_CONTAINER_multihashmap_destroy (
+ struct GNUNET_CONTAINER_MultiHashMap *map);
/**
@@ -809,8 +818,9 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap *map
* key-value pairs with value NULL
*/
void *
-GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key);
+GNUNET_CONTAINER_multihashmap_get (
+ const struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key);
/**
@@ -828,7 +838,7 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap *m
int
GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
const struct GNUNET_HashCode *key,
- const void *value);
+ const void *value);
/**
* @ingroup hashmap
@@ -840,8 +850,9 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map,
* @return number of values removed
*/
int
-GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key);
+GNUNET_CONTAINER_multihashmap_remove_all (
+ struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key);
/**
@@ -867,8 +878,9 @@ GNUNET_CONTAINER_multihashmap_clear (struct GNUNET_CONTAINER_MultiHashMap *map);
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode * key);
+GNUNET_CONTAINER_multihashmap_contains (
+ const struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key);
/**
@@ -883,9 +895,10 @@ GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashM
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key,
- const void *value);
+GNUNET_CONTAINER_multihashmap_contains_value (
+ const struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key,
+ const void *value);
/**
@@ -902,11 +915,11 @@ GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_Mult
* value already exists
*/
int
-GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key,
- void *value,
- enum GNUNET_CONTAINER_MultiHashMapOption
- opt);
+GNUNET_CONTAINER_multihashmap_put (
+ struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key,
+ void *value,
+ enum GNUNET_CONTAINER_MultiHashMapOption opt);
/**
* @ingroup hashmap
@@ -916,7 +929,8 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
* @return the number of key value pairs
*/
unsigned int
-GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *map);
+GNUNET_CONTAINER_multihashmap_size (
+ const struct GNUNET_CONTAINER_MultiHashMap *map);
/**
@@ -930,9 +944,10 @@ GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap *
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map,
- GNUNET_CONTAINER_HashMapIterator it,
- void *it_cls);
+GNUNET_CONTAINER_multihashmap_iterate (
+ struct GNUNET_CONTAINER_MultiHashMap *map,
+ GNUNET_CONTAINER_HashMapIterator it,
+ void *it_cls);
/**
@@ -949,7 +964,8 @@ GNUNET_CONTAINER_multihashmap_iterate (struct GNUNET_CONTAINER_MultiHashMap *map
* @return an iterator over the given multihashmap @a map
*/
struct GNUNET_CONTAINER_MultiHashMapIterator *
-GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap *map);
+GNUNET_CONTAINER_multihashmap_iterator_create (
+ const struct GNUNET_CONTAINER_MultiHashMap *map);
/**
@@ -968,9 +984,10 @@ GNUNET_CONTAINER_multihashmap_iterator_create (const struct GNUNET_CONTAINER_Mul
* #GNUNET_NO if we are out of elements
*/
int
-GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMapIterator *iter,
- struct GNUNET_HashCode *key,
- const void **value);
+GNUNET_CONTAINER_multihashmap_iterator_next (
+ struct GNUNET_CONTAINER_MultiHashMapIterator *iter,
+ struct GNUNET_HashCode *key,
+ const void **value);
/**
@@ -980,7 +997,8 @@ GNUNET_CONTAINER_multihashmap_iterator_next (struct GNUNET_CONTAINER_MultiHashMa
* @param iter the iterator to destroy
*/
void
-GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
+GNUNET_CONTAINER_multihashmap_iterator_destroy (
+ struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
/**
@@ -995,10 +1013,11 @@ GNUNET_CONTAINER_multihashmap_iterator_destroy (struct GNUNET_CONTAINER_MultiHas
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap *map,
- const struct GNUNET_HashCode *key,
- GNUNET_CONTAINER_HashMapIterator it,
- void *it_cls);
+GNUNET_CONTAINER_multihashmap_get_multiple (
+ struct GNUNET_CONTAINER_MultiHashMap *map,
+ const struct GNUNET_HashCode *key,
+ GNUNET_CONTAINER_HashMapIterator it,
+ void *it_cls);
/**
@@ -1013,9 +1032,10 @@ GNUNET_CONTAINER_multihashmap_get_multiple (struct GNUNET_CONTAINER_MultiHashMap
* @return the number of key value pairs processed, zero or one.
*/
unsigned int
-GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHashMap *map,
- GNUNET_CONTAINER_HashMapIterator it,
- void *it_cls);
+GNUNET_CONTAINER_multihashmap_get_random (
+ const struct GNUNET_CONTAINER_MultiHashMap *map,
+ GNUNET_CONTAINER_HashMapIterator it,
+ void *it_cls);
/* ***************** Version of Multihashmap for peer identities ****************** */
@@ -1031,10 +1051,10 @@ GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHas
* iterate,
* #GNUNET_NO if not.
*/
-typedef int
-(*GNUNET_CONTAINER_PeerMapIterator) (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value);
+typedef int (*GNUNET_CONTAINER_PeerMapIterator) (
+ void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value);
/**
@@ -1060,8 +1080,7 @@ struct GNUNET_CONTAINER_MultiPeerMap;
* @return NULL on error
*/
struct GNUNET_CONTAINER_MultiPeerMap *
-GNUNET_CONTAINER_multipeermap_create (unsigned int len,
- int do_not_copy_keys);
+GNUNET_CONTAINER_multipeermap_create (unsigned int len, int do_not_copy_keys);
/**
@@ -1072,7 +1091,8 @@ GNUNET_CONTAINER_multipeermap_create (unsigned int len,
* @param map the map
*/
void
-GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map);
+GNUNET_CONTAINER_multipeermap_destroy (
+ struct GNUNET_CONTAINER_MultiPeerMap *map);
/**
@@ -1087,8 +1107,9 @@ GNUNET_CONTAINER_multipeermap_destroy (struct GNUNET_CONTAINER_MultiPeerMap *map
* key-value pairs with value NULL
*/
void *
-GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key);
+GNUNET_CONTAINER_multipeermap_get (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key);
/**
@@ -1105,8 +1126,8 @@ GNUNET_CONTAINER_multipeermap_get (const struct GNUNET_CONTAINER_MultiPeerMap *m
*/
int
GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity * key,
- const void *value);
+ const struct GNUNET_PeerIdentity *key,
+ const void *value);
/**
* @ingroup hashmap
@@ -1118,8 +1139,9 @@ GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map,
* @return number of values removed
*/
int
-GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key);
+GNUNET_CONTAINER_multipeermap_remove_all (
+ struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key);
/**
@@ -1133,8 +1155,9 @@ GNUNET_CONTAINER_multipeermap_remove_all (struct GNUNET_CONTAINER_MultiPeerMap *
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key);
+GNUNET_CONTAINER_multipeermap_contains (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key);
/**
@@ -1149,9 +1172,10 @@ GNUNET_CONTAINER_multipeermap_contains (const struct GNUNET_CONTAINER_MultiPeerM
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity * key,
- const void *value);
+GNUNET_CONTAINER_multipeermap_contains_value (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key,
+ const void *value);
/**
@@ -1168,10 +1192,11 @@ GNUNET_CONTAINER_multipeermap_contains_value (const struct GNUNET_CONTAINER_Mult
* value already exists
*/
int
-GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key,
- void *value,
- enum GNUNET_CONTAINER_MultiHashMapOption opt);
+GNUNET_CONTAINER_multipeermap_put (
+ struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key,
+ void *value,
+ enum GNUNET_CONTAINER_MultiHashMapOption opt);
/**
@@ -1182,7 +1207,8 @@ GNUNET_CONTAINER_multipeermap_put (struct GNUNET_CONTAINER_MultiPeerMap *map,
* @return the number of key value pairs
*/
unsigned int
-GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *map);
+GNUNET_CONTAINER_multipeermap_size (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map);
/**
@@ -1196,9 +1222,10 @@ GNUNET_CONTAINER_multipeermap_size (const struct GNUNET_CONTAINER_MultiPeerMap *
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multipeermap_iterate (struct GNUNET_CONTAINER_MultiPeerMap *map,
- GNUNET_CONTAINER_PeerMapIterator it,
- void *it_cls);
+GNUNET_CONTAINER_multipeermap_iterate (
+ struct GNUNET_CONTAINER_MultiPeerMap *map,
+ GNUNET_CONTAINER_PeerMapIterator it,
+ void *it_cls);
struct GNUNET_CONTAINER_MultiPeerMapIterator;
@@ -1216,7 +1243,8 @@ struct GNUNET_CONTAINER_MultiPeerMapIterator;
* @return an iterator over the given multihashmap @a map
*/
struct GNUNET_CONTAINER_MultiPeerMapIterator *
-GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_MultiPeerMap *map);
+GNUNET_CONTAINER_multipeermap_iterator_create (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map);
/**
@@ -1235,9 +1263,10 @@ GNUNET_CONTAINER_multipeermap_iterator_create (const struct GNUNET_CONTAINER_Mul
* #GNUNET_NO if we are out of elements
*/
int
-GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter,
- struct GNUNET_PeerIdentity *key,
- const void **value);
+GNUNET_CONTAINER_multipeermap_iterator_next (
+ struct GNUNET_CONTAINER_MultiPeerMapIterator *iter,
+ struct GNUNET_PeerIdentity *key,
+ const void **value);
/**
@@ -1247,7 +1276,8 @@ GNUNET_CONTAINER_multipeermap_iterator_next (struct GNUNET_CONTAINER_MultiPeerMa
* @param iter the iterator to destroy
*/
void
-GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPeerMapIterator *iter);
+GNUNET_CONTAINER_multipeermap_iterator_destroy (
+ struct GNUNET_CONTAINER_MultiPeerMapIterator *iter);
/**
@@ -1262,10 +1292,11 @@ GNUNET_CONTAINER_multipeermap_iterator_destroy (struct GNUNET_CONTAINER_MultiPee
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap *map,
- const struct GNUNET_PeerIdentity *key,
- GNUNET_CONTAINER_PeerMapIterator it,
- void *it_cls);
+GNUNET_CONTAINER_multipeermap_get_multiple (
+ struct GNUNET_CONTAINER_MultiPeerMap *map,
+ const struct GNUNET_PeerIdentity *key,
+ GNUNET_CONTAINER_PeerMapIterator it,
+ void *it_cls);
/**
@@ -1280,9 +1311,10 @@ GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap
* @return the number of key value pairs processed, zero or one.
*/
unsigned int
-GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPeerMap *map,
- GNUNET_CONTAINER_PeerMapIterator it,
- void *it_cls);
+GNUNET_CONTAINER_multipeermap_get_random (
+ const struct GNUNET_CONTAINER_MultiPeerMap *map,
+ GNUNET_CONTAINER_PeerMapIterator it,
+ void *it_cls);
/* ***************** Version of Multihashmap for short hashes ****************** */
@@ -1298,10 +1330,10 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPee
* iterate,
* #GNUNET_NO if not.
*/
-typedef int
-(*GNUNET_CONTAINER_ShortmapIterator) (void *cls,
- const struct GNUNET_ShortHashCode *key,
- void *value);
+typedef int (*GNUNET_CONTAINER_ShortmapIterator) (
+ void *cls,
+ const struct GNUNET_ShortHashCode *key,
+ void *value);
/**
@@ -1327,8 +1359,7 @@ struct GNUNET_CONTAINER_MultiShortmap;
* @return NULL on error
*/
struct GNUNET_CONTAINER_MultiShortmap *
-GNUNET_CONTAINER_multishortmap_create (unsigned int len,
- int do_not_copy_keys);
+GNUNET_CONTAINER_multishortmap_create (unsigned int len, int do_not_copy_keys);
/**
@@ -1339,7 +1370,8 @@ GNUNET_CONTAINER_multishortmap_create (unsigned int len,
* @param map the map
*/
void
-GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *map);
+GNUNET_CONTAINER_multishortmap_destroy (
+ struct GNUNET_CONTAINER_MultiShortmap *map);
/**
@@ -1354,8 +1386,9 @@ GNUNET_CONTAINER_multishortmap_destroy (struct GNUNET_CONTAINER_MultiShortmap *m
* key-value pairs with value NULL
*/
void *
-GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key);
+GNUNET_CONTAINER_multishortmap_get (
+ const struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key);
/**
@@ -1371,9 +1404,10 @@ GNUNET_CONTAINER_multishortmap_get (const struct GNUNET_CONTAINER_MultiShortmap
* is not in the map
*/
int
-GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode * key,
- const void *value);
+GNUNET_CONTAINER_multishortmap_remove (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key,
+ const void *value);
/**
* @ingroup hashmap
@@ -1385,8 +1419,9 @@ GNUNET_CONTAINER_multishortmap_remove (struct GNUNET_CONTAINER_MultiShortmap *ma
* @return number of values removed
*/
int
-GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key);
+GNUNET_CONTAINER_multishortmap_remove_all (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key);
/**
@@ -1400,8 +1435,9 @@ GNUNET_CONTAINER_multishortmap_remove_all (struct GNUNET_CONTAINER_MultiShortmap
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key);
+GNUNET_CONTAINER_multishortmap_contains (
+ const struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key);
/**
@@ -1416,9 +1452,10 @@ GNUNET_CONTAINER_multishortmap_contains (const struct GNUNET_CONTAINER_MultiShor
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode * key,
- const void *value);
+GNUNET_CONTAINER_multishortmap_contains_value (
+ const struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key,
+ const void *value);
/**
@@ -1435,10 +1472,11 @@ GNUNET_CONTAINER_multishortmap_contains_value (const struct GNUNET_CONTAINER_Mul
* value already exists
*/
int
-GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key,
- void *value,
- enum GNUNET_CONTAINER_MultiHashMapOption opt);
+GNUNET_CONTAINER_multishortmap_put (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key,
+ void *value,
+ enum GNUNET_CONTAINER_MultiHashMapOption opt);
/**
@@ -1449,7 +1487,8 @@ GNUNET_CONTAINER_multishortmap_put (struct GNUNET_CONTAINER_MultiShortmap *map,
* @return the number of key value pairs
*/
unsigned int
-GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap *map);
+GNUNET_CONTAINER_multishortmap_size (
+ const struct GNUNET_CONTAINER_MultiShortmap *map);
/**
@@ -1463,9 +1502,10 @@ GNUNET_CONTAINER_multishortmap_size (const struct GNUNET_CONTAINER_MultiShortmap
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multishortmap_iterate (struct GNUNET_CONTAINER_MultiShortmap *map,
- GNUNET_CONTAINER_ShortmapIterator it,
- void *it_cls);
+GNUNET_CONTAINER_multishortmap_iterate (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ GNUNET_CONTAINER_ShortmapIterator it,
+ void *it_cls);
struct GNUNET_CONTAINER_MultiShortmapIterator;
@@ -1485,7 +1525,8 @@ struct GNUNET_CONTAINER_MultiShortmapIterator;
* @return an iterator over the given multihashmap @a map
*/
struct GNUNET_CONTAINER_MultiShortmapIterator *
-GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_MultiShortmap *map);
+GNUNET_CONTAINER_multishortmap_iterator_create (
+ const struct GNUNET_CONTAINER_MultiShortmap *map);
/**
@@ -1504,9 +1545,10 @@ GNUNET_CONTAINER_multishortmap_iterator_create (const struct GNUNET_CONTAINER_Mu
* #GNUNET_NO if we are out of elements
*/
int
-GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShortmapIterator *iter,
- struct GNUNET_ShortHashCode *key,
- const void **value);
+GNUNET_CONTAINER_multishortmap_iterator_next (
+ struct GNUNET_CONTAINER_MultiShortmapIterator *iter,
+ struct GNUNET_ShortHashCode *key,
+ const void **value);
/**
@@ -1516,7 +1558,8 @@ GNUNET_CONTAINER_multishortmap_iterator_next (struct GNUNET_CONTAINER_MultiShort
* @param iter the iterator to destroy
*/
void
-GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiShortmapIterator *iter);
+GNUNET_CONTAINER_multishortmap_iterator_destroy (
+ struct GNUNET_CONTAINER_MultiShortmapIterator *iter);
/**
@@ -1531,10 +1574,11 @@ GNUNET_CONTAINER_multishortmap_iterator_destroy (struct GNUNET_CONTAINER_MultiSh
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortmap *map,
- const struct GNUNET_ShortHashCode *key,
- GNUNET_CONTAINER_ShortmapIterator it,
- void *it_cls);
+GNUNET_CONTAINER_multishortmap_get_multiple (
+ struct GNUNET_CONTAINER_MultiShortmap *map,
+ const struct GNUNET_ShortHashCode *key,
+ GNUNET_CONTAINER_ShortmapIterator it,
+ void *it_cls);
/**
@@ -1549,9 +1593,292 @@ GNUNET_CONTAINER_multishortmap_get_multiple (struct GNUNET_CONTAINER_MultiShortm
* @return the number of key value pairs processed, zero or one.
*/
unsigned int
-GNUNET_CONTAINER_multishortmap_get_random (const struct GNUNET_CONTAINER_MultiShortmap *map,
- GNUNET_CONTAINER_ShortmapIterator it,
- void *it_cls);
+GNUNET_CONTAINER_multishortmap_get_random (
+ const struct GNUNET_CONTAINER_MultiShortmap *map,
+ GNUNET_CONTAINER_ShortmapIterator it,
+ void *it_cls);
+
+
+/* ***************** Version of Multihashmap for UUIDs ****************** */
+
+
+/**
+ * @ingroup hashmap
+ * Iterator over uuid map entries.
+ *
+ * @param cls closure
+ * @param key current public key
+ * @param value value in the hash map
+ * @return #GNUNET_YES if we should continue to
+ * iterate,
+ * #GNUNET_NO if not.
+ */
+typedef int (*GNUNET_CONTAINER_MultiUuidmapIterator) (
+ void *cls,
+ const struct GNUNET_Uuid *key,
+ void *value);
+
+
+/**
+ * Hash map from peer identities to values.
+ */
+struct GNUNET_CONTAINER_MultiUuidmap;
+
+
+/**
+ * @ingroup hashmap
+ * Create a multi peer map (hash map for public keys of peers).
+ *
+ * @param len initial size (map will grow as needed)
+ * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default;
+ * #GNUNET_YES means that on 'put', the 'key' does not have
+ * to be copied as the destination of the pointer is
+ * guaranteed to be life as long as the value is stored in
+ * the hashmap. This can significantly reduce memory
+ * consumption, but of course is also a recipie for
+ * heap corruption if the assumption is not true. Only
+ * use this if (1) memory use is important in this case and
+ * (2) you have triple-checked that the invariant holds
+ * @return NULL on error
+ */
+struct GNUNET_CONTAINER_MultiUuidmap *
+GNUNET_CONTAINER_multiuuidmap_create (unsigned int len, int do_not_copy_keys);
+
+
+/**
+ * @ingroup hashmap
+ * Destroy a hash map. Will not free any values
+ * stored in the hash map!
+ *
+ * @param map the map
+ */
+void
+GNUNET_CONTAINER_multiuuidmap_destroy (
+ struct GNUNET_CONTAINER_MultiUuidmap *map);
+
+
+/**
+ * @ingroup hashmap
+ * Given a key find a value in the map matching the key.
+ *
+ * @param map the map
+ * @param key what to look for
+ * @return NULL if no value was found; note that
+ * this is indistinguishable from values that just
+ * happen to be NULL; use "contains" to test for
+ * key-value pairs with value NULL
+ */
+void *
+GNUNET_CONTAINER_multiuuidmap_get (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key);
+
+
+/**
+ * @ingroup hashmap
+ * Remove the given key-value pair from the map. Note that if the
+ * key-value pair is in the map multiple times, only one of the pairs
+ * will be removed.
+ *
+ * @param map the map
+ * @param key key of the key-value pair
+ * @param value value of the key-value pair
+ * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
+ * is not in the map
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key,
+ const void *value);
+
+/**
+ * @ingroup hashmap
+ * Remove all entries for the given key from the map.
+ * Note that the values would not be "freed".
+ *
+ * @param map the map
+ * @param key identifies values to be removed
+ * @return number of values removed
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_remove_all (
+ struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key);
+
+
+/**
+ * @ingroup hashmap
+ * Check if the map contains any value under the given
+ * key (including values that are NULL).
+ *
+ * @param map the map
+ * @param key the key to test if a value exists for it
+ * @return #GNUNET_YES if such a value exists,
+ * #GNUNET_NO if not
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_contains (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key);
+
+
+/**
+ * @ingroup hashmap
+ * Check if the map contains the given value under the given
+ * key.
+ *
+ * @param map the map
+ * @param key the key to test if a value exists for it
+ * @param value value to test for
+ * @return #GNUNET_YES if such a value exists,
+ * #GNUNET_NO if not
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_contains_value (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key,
+ const void *value);
+
+
+/**
+ * @ingroup hashmap
+ * Store a key-value pair in the map.
+ *
+ * @param map the map
+ * @param key key to use
+ * @param value value to use
+ * @param opt options for put
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO if a value was replaced (with REPLACE)
+ * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
+ * value already exists
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_put (
+ struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key,
+ void *value,
+ enum GNUNET_CONTAINER_MultiHashMapOption opt);
+
+
+/**
+ * @ingroup hashmap
+ * Get the number of key-value pairs in the map.
+ *
+ * @param map the map
+ * @return the number of key value pairs
+ */
+unsigned int
+GNUNET_CONTAINER_multiuuidmap_size (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map);
+
+
+/**
+ * @ingroup hashmap
+ * Iterate over all entries in the map.
+ *
+ * @param map the map
+ * @param it function to call on each entry
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed,
+ * #GNUNET_SYSERR if it aborted iteration
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_iterate (
+ struct GNUNET_CONTAINER_MultiUuidmap *map,
+ GNUNET_CONTAINER_MultiUuidmapIterator it,
+ void *it_cls);
+
+
+struct GNUNET_CONTAINER_MultiUuidmapIterator;
+
+
+/**
+ * @ingroup hashmap
+ * Create an iterator for a multihashmap.
+ * The iterator can be used to retrieve all the elements in the multihashmap
+ * one by one, without having to handle all elements at once (in contrast to
+ * #GNUNET_CONTAINER_multiuuidmap_iterate). Note that the iterator can not be
+ * used anymore if elements have been removed from @a map after the creation of
+ * the iterator, or 'map' has been destroyed. Adding elements to @a map may
+ * result in skipped or repeated elements.
+ *
+ * @param map the map to create an iterator for
+ * @return an iterator over the given multihashmap @a map
+ */
+struct GNUNET_CONTAINER_MultiUuidmapIterator *
+GNUNET_CONTAINER_multiuuidmap_iterator_create (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map);
+
+
+/**
+ * @ingroup hashmap
+ * Retrieve the next element from the hash map at the iterator's
+ * position. If there are no elements left, #GNUNET_NO is returned,
+ * and @a key and @a value are not modified. This operation is only
+ * allowed if no elements have been removed from the multihashmap
+ * since the creation of @a iter, and the map has not been destroyed.
+ * Adding elements may result in repeating or skipping elements.
+ *
+ * @param iter the iterator to get the next element from
+ * @param key pointer to store the key in, can be NULL
+ * @param value pointer to store the value in, can be NULL
+ * @return #GNUNET_YES we returned an element,
+ * #GNUNET_NO if we are out of elements
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_iterator_next (
+ struct GNUNET_CONTAINER_MultiUuidmapIterator *iter,
+ struct GNUNET_Uuid *key,
+ const void **value);
+
+
+/**
+ * @ingroup hashmap
+ * Destroy a multiuuidmap iterator.
+ *
+ * @param iter the iterator to destroy
+ */
+void
+GNUNET_CONTAINER_multiuuidmap_iterator_destroy (
+ struct GNUNET_CONTAINER_MultiUuidmapIterator *iter);
+
+
+/**
+ * @ingroup hashmap
+ * Iterate over all entries in the map that match a particular key.
+ *
+ * @param map the map
+ * @param key public key that the entries must correspond to
+ * @param it function to call on each entry
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed,
+ * #GNUNET_SYSERR if it aborted iteration
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_get_multiple (
+ struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key,
+ GNUNET_CONTAINER_MultiUuidmapIterator it,
+ void *it_cls);
+
+
+/**
+ * @ingroup hashmap
+ * Call @a it on a random value from the map, or not at all
+ * if the map is empty. Note that this function has linear
+ * complexity (in the size of the map).
+ *
+ * @param map the map
+ * @param it function to call on a random entry
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed, zero or one.
+ */
+unsigned int
+GNUNET_CONTAINER_multiuuidmap_get_random (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map,
+ GNUNET_CONTAINER_MultiUuidmapIterator it,
+ void *it_cls);
/* Version of multihashmap with 32 bit keys */
@@ -1582,10 +1909,9 @@ struct GNUNET_CONTAINER_MultiHashMap32Iterator;
* iterate,
* #GNUNET_NO if not.
*/
-typedef int
-(*GNUNET_CONTAINER_HashMapIterator32) (void *cls,
- uint32_t key,
- void *value);
+typedef int (*GNUNET_CONTAINER_HashMapIterator32) (void *cls,
+ uint32_t key,
+ void *value);
/**
@@ -1607,7 +1933,8 @@ GNUNET_CONTAINER_multihashmap32_create (unsigned int len);
* @param map the map
*/
void
-GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32 *map);
+GNUNET_CONTAINER_multihashmap32_destroy (
+ struct GNUNET_CONTAINER_MultiHashMap32 *map);
/**
@@ -1618,8 +1945,8 @@ GNUNET_CONTAINER_multihashmap32_destroy (struct GNUNET_CONTAINER_MultiHashMap32
* @return the number of key value pairs
*/
unsigned int
-GNUNET_CONTAINER_multihashmap32_size (const struct
- GNUNET_CONTAINER_MultiHashMap32 *map);
+GNUNET_CONTAINER_multihashmap32_size (
+ const struct GNUNET_CONTAINER_MultiHashMap32 *map);
/**
@@ -1634,9 +1961,9 @@ GNUNET_CONTAINER_multihashmap32_size (const struct
* key-value pairs with value NULL
*/
void *
-GNUNET_CONTAINER_multihashmap32_get (const struct
- GNUNET_CONTAINER_MultiHashMap32 *map,
- uint32_t key);
+GNUNET_CONTAINER_multihashmap32_get (
+ const struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key);
/**
@@ -1650,9 +1977,10 @@ GNUNET_CONTAINER_multihashmap32_get (const struct
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32 *map,
- GNUNET_CONTAINER_HashMapIterator32 it,
- void *it_cls);
+GNUNET_CONTAINER_multihashmap32_iterate (
+ struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ GNUNET_CONTAINER_HashMapIterator32 it,
+ void *it_cls);
/**
@@ -1668,9 +1996,10 @@ GNUNET_CONTAINER_multihashmap32_iterate (struct GNUNET_CONTAINER_MultiHashMap32
* is not in the map
*/
int
-GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *map,
- uint32_t key,
- const void *value);
+GNUNET_CONTAINER_multihashmap32_remove (
+ struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key,
+ const void *value);
/**
@@ -1683,8 +2012,9 @@ GNUNET_CONTAINER_multihashmap32_remove (struct GNUNET_CONTAINER_MultiHashMap32 *
* @return number of values removed
*/
int
-GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap32 *map,
- uint32_t key);
+GNUNET_CONTAINER_multihashmap32_remove_all (
+ struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key);
/**
@@ -1698,8 +2028,9 @@ GNUNET_CONTAINER_multihashmap32_remove_all (struct GNUNET_CONTAINER_MultiHashMap
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
- uint32_t key);
+GNUNET_CONTAINER_multihashmap32_contains (
+ const struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key);
/**
@@ -1714,9 +2045,10 @@ GNUNET_CONTAINER_multihashmap32_contains (const struct GNUNET_CONTAINER_MultiHas
* #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_MultiHashMap32 *map,
- uint32_t key,
- const void *value);
+GNUNET_CONTAINER_multihashmap32_contains_value (
+ const struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key,
+ const void *value);
/**
@@ -1733,10 +2065,11 @@ GNUNET_CONTAINER_multihashmap32_contains_value (const struct GNUNET_CONTAINER_Mu
* value already exists
*/
int
-GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map,
- uint32_t key,
- void *value,
- enum GNUNET_CONTAINER_MultiHashMapOption opt);
+GNUNET_CONTAINER_multihashmap32_put (
+ struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key,
+ void *value,
+ enum GNUNET_CONTAINER_MultiHashMapOption opt);
/**
@@ -1751,10 +2084,11 @@ GNUNET_CONTAINER_multihashmap32_put (struct GNUNET_CONTAINER_MultiHashMap32 *map
* #GNUNET_SYSERR if it aborted iteration
*/
int
-GNUNET_CONTAINER_multihashmap32_get_multiple (struct GNUNET_CONTAINER_MultiHashMap32 *map,
- uint32_t key,
- GNUNET_CONTAINER_HashMapIterator32 it,
- void *it_cls);
+GNUNET_CONTAINER_multihashmap32_get_multiple (
+ struct GNUNET_CONTAINER_MultiHashMap32 *map,
+ uint32_t key,
+ GNUNET_CONTAINER_HashMapIterator32 it,
+ void *it_cls);
/**
@@ -1770,7 +2104,8 @@ GNUNET_CONTAINER_multihashmap32_get_multiple (struct GNUNET_CONTAINER_MultiHashM
* @return an iterator over the given multihashmap map
*/
struct GNUNET_CONTAINER_MultiHashMap32Iterator *
-GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_MultiHashMap32 *map);
+GNUNET_CONTAINER_multihashmap32_iterator_create (
+ const struct GNUNET_CONTAINER_MultiHashMap32 *map);
/**
@@ -1788,9 +2123,10 @@ GNUNET_CONTAINER_multihashmap32_iterator_create (const struct GNUNET_CONTAINER_M
* #GNUNET_NO if we are out of elements
*/
int
-GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
- uint32_t *key,
- const void **value);
+GNUNET_CONTAINER_multihashmap32_iterator_next (
+ struct GNUNET_CONTAINER_MultiHashMap32Iterator *iter,
+ uint32_t *key,
+ const void **value);
/**
@@ -1799,7 +2135,8 @@ GNUNET_CONTAINER_multihashmap32_iterator_next (struct GNUNET_CONTAINER_MultiHash
* @param iter the iterator to destroy
*/
void
-GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
+GNUNET_CONTAINER_multihashmap32_iterator_destroy (
+ struct GNUNET_CONTAINER_MultiHashMapIterator *iter);
/* ******************** doubly-linked list *************** */
@@ -1814,16 +2151,19 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param tail pointer to the tail of the DLL
* @param element element to insert
*/
-#define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \
- GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
- GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
- (element)->next = (head); \
- (element)->prev = NULL; \
- if ((tail) == NULL) \
- (tail) = element; \
- else \
- (head)->prev = element; \
- (head) = (element); } while (0)
+#define GNUNET_CONTAINER_DLL_insert(head, tail, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev == NULL) && ((head) != (element))); \
+ GNUNET_assert (((element)->next == NULL) && ((tail) != (element))); \
+ (element)->next = (head); \
+ (element)->prev = NULL; \
+ if ((tail) == NULL) \
+ (tail) = element; \
+ else \
+ (head)->prev = element; \
+ (head) = (element); \
+ } while (0)
/**
@@ -1835,16 +2175,19 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param tail pointer to the tail of the DLL
* @param element element to insert
*/
-#define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \
- GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
- GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
- (element)->prev = (tail); \
- (element)->next = NULL; \
- if ((head) == NULL) \
- (head) = element; \
- else \
- (tail)->next = element; \
- (tail) = (element); } while (0)
+#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev == NULL) && ((head) != (element))); \
+ GNUNET_assert (((element)->next == NULL) && ((tail) != (element))); \
+ (element)->prev = (tail); \
+ (element)->next = NULL; \
+ if ((head) == NULL) \
+ (head) = element; \
+ else \
+ (tail)->next = element; \
+ (tail) = (element); \
+ } while (0)
/**
@@ -1857,24 +2200,27 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param other prior element, NULL for insertion at head of DLL
* @param element element to insert
*/
-#define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
- GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
- GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
- (element)->prev = (other); \
- if (NULL == other) \
- { \
- (element)->next = (head); \
- (head) = (element); \
- } \
- else \
- { \
- (element)->next = (other)->next; \
- (other)->next = (element); \
- } \
- if (NULL == (element)->next) \
- (tail) = (element); \
- else \
- (element)->next->prev = (element); } while (0)
+#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev == NULL) && ((head) != (element))); \
+ GNUNET_assert (((element)->next == NULL) && ((tail) != (element))); \
+ (element)->prev = (other); \
+ if (NULL == other) \
+ { \
+ (element)->next = (head); \
+ (head) = (element); \
+ } \
+ else \
+ { \
+ (element)->next = (other)->next; \
+ (other)->next = (element); \
+ } \
+ if (NULL == (element)->next) \
+ (tail) = (element); \
+ else \
+ (element)->next->prev = (element); \
+ } while (0)
/**
@@ -1887,24 +2233,27 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param other prior element, NULL for insertion at head of DLL
* @param element element to insert
*/
-#define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \
- GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
- GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
- (element)->next = (other); \
- if (NULL == other) \
- { \
- (element)->prev = (tail); \
- (tail) = (element); \
- } \
- else \
- { \
- (element)->prev = (other)->prev; \
- (other)->prev = (element); \
- } \
- if (NULL == (element)->prev) \
- (head) = (element); \
- else \
- (element)->prev->next = (element); } while (0)
+#define GNUNET_CONTAINER_DLL_insert_before(head, tail, other, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev == NULL) && ((head) != (element))); \
+ GNUNET_assert (((element)->next == NULL) && ((tail) != (element))); \
+ (element)->next = (other); \
+ if (NULL == other) \
+ { \
+ (element)->prev = (tail); \
+ (tail) = (element); \
+ } \
+ else \
+ { \
+ (element)->prev = (other)->prev; \
+ (other)->prev = (element); \
+ } \
+ if (NULL == (element)->prev) \
+ (head) = (element); \
+ else \
+ (element)->prev->next = (element); \
+ } while (0)
/**
@@ -1921,19 +2270,22 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param tail pointer to the tail of the DLL
* @param element element to remove
*/
-#define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \
- GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
- GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
- if ((element)->prev == NULL) \
- (head) = (element)->next; \
- else \
- (element)->prev->next = (element)->next; \
- if ((element)->next == NULL) \
- (tail) = (element)->prev; \
- else \
- (element)->next->prev = (element)->prev; \
- (element)->next = NULL; \
- (element)->prev = NULL; } while (0)
+#define GNUNET_CONTAINER_DLL_remove(head, tail, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev != NULL) || ((head) == (element))); \
+ GNUNET_assert (((element)->next != NULL) || ((tail) == (element))); \
+ if ((element)->prev == NULL) \
+ (head) = (element)->next; \
+ else \
+ (element)->prev->next = (element)->next; \
+ if ((element)->next == NULL) \
+ (tail) = (element)->prev; \
+ else \
+ (element)->next->prev = (element)->prev; \
+ (element)->next = NULL; \
+ (element)->prev = NULL; \
+ } while (0)
/* ************ Multi-DLL interface, allows DLL elements to be
@@ -1949,16 +2301,19 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param tail pointer to the tail of the MDLL
* @param element element to insert
*/
-#define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \
- GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
- GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
- (element)->next_##mdll = (head); \
- (element)->prev_##mdll = NULL; \
- if ((tail) == NULL) \
- (tail) = element; \
- else \
- (head)->prev_##mdll = element; \
- (head) = (element); } while (0)
+#define GNUNET_CONTAINER_MDLL_insert(mdll, head, tail, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev_##mdll == NULL) && ((head) != (element))); \
+ GNUNET_assert (((element)->next_##mdll == NULL) && ((tail) != (element))); \
+ (element)->next_##mdll = (head); \
+ (element)->prev_##mdll = NULL; \
+ if ((tail) == NULL) \
+ (tail) = element; \
+ else \
+ (head)->prev_##mdll = element; \
+ (head) = (element); \
+ } while (0)
/**
@@ -1971,16 +2326,19 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param tail pointer to the tail of the MDLL
* @param element element to insert
*/
-#define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \
- GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
- GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
- (element)->prev_##mdll = (tail); \
- (element)->next_##mdll = NULL; \
- if ((head) == NULL) \
- (head) = element; \
- else \
- (tail)->next_##mdll = element; \
- (tail) = (element); } while (0)
+#define GNUNET_CONTAINER_MDLL_insert_tail(mdll, head, tail, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev_##mdll == NULL) && ((head) != (element))); \
+ GNUNET_assert (((element)->next_##mdll == NULL) && ((tail) != (element))); \
+ (element)->prev_##mdll = (tail); \
+ (element)->next_##mdll = NULL; \
+ if ((head) == NULL) \
+ (head) = element; \
+ else \
+ (tail)->next_##mdll = element; \
+ (tail) = (element); \
+ } while (0)
/**
@@ -1994,24 +2352,27 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param other prior element, NULL for insertion at head of MDLL
* @param element element to insert
*/
-#define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \
- GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
- GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
- (element)->prev_##mdll = (other); \
- if (NULL == other) \
- { \
- (element)->next_##mdll = (head); \
- (head) = (element); \
- } \
- else \
- { \
- (element)->next_##mdll = (other)->next_##mdll; \
- (other)->next_##mdll = (element); \
- } \
- if (NULL == (element)->next_##mdll) \
- (tail) = (element); \
- else \
- (element)->next_##mdll->prev_##mdll = (element); } while (0)
+#define GNUNET_CONTAINER_MDLL_insert_after(mdll, head, tail, other, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev_##mdll == NULL) && ((head) != (element))); \
+ GNUNET_assert (((element)->next_##mdll == NULL) && ((tail) != (element))); \
+ (element)->prev_##mdll = (other); \
+ if (NULL == other) \
+ { \
+ (element)->next_##mdll = (head); \
+ (head) = (element); \
+ } \
+ else \
+ { \
+ (element)->next_##mdll = (other)->next_##mdll; \
+ (other)->next_##mdll = (element); \
+ } \
+ if (NULL == (element)->next_##mdll) \
+ (tail) = (element); \
+ else \
+ (element)->next_##mdll->prev_##mdll = (element); \
+ } while (0)
/**
@@ -2025,24 +2386,27 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param other prior element, NULL for insertion at head of MDLL
* @param element element to insert
*/
-#define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \
- GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \
- GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \
- (element)->next_##mdll = (other); \
- if (NULL == other) \
- { \
- (element)->prev = (tail); \
- (tail) = (element); \
- } \
- else \
- { \
- (element)->prev_##mdll = (other)->prev_##mdll; \
- (other)->prev_##mdll = (element); \
- } \
- if (NULL == (element)->prev_##mdll) \
- (head) = (element); \
- else \
- (element)->prev_##mdll->next_##mdll = (element); } while (0)
+#define GNUNET_CONTAINER_MDLL_insert_before(mdll, head, tail, other, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev_##mdll == NULL) && ((head) != (element))); \
+ GNUNET_assert (((element)->next_##mdll == NULL) && ((tail) != (element))); \
+ (element)->next_##mdll = (other); \
+ if (NULL == other) \
+ { \
+ (element)->prev = (tail); \
+ (tail) = (element); \
+ } \
+ else \
+ { \
+ (element)->prev_##mdll = (other)->prev_##mdll; \
+ (other)->prev_##mdll = (element); \
+ } \
+ if (NULL == (element)->prev_##mdll) \
+ (head) = (element); \
+ else \
+ (element)->prev_##mdll->next_##mdll = (element); \
+ } while (0)
/**
@@ -2056,20 +2420,22 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param tail pointer to the tail of the MDLL
* @param element element to remove
*/
-#define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \
- GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \
- GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \
- if ((element)->prev_##mdll == NULL) \
- (head) = (element)->next_##mdll; \
- else \
- (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \
- if ((element)->next_##mdll == NULL) \
- (tail) = (element)->prev_##mdll; \
- else \
- (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \
- (element)->next_##mdll = NULL; \
- (element)->prev_##mdll = NULL; } while (0)
-
+#define GNUNET_CONTAINER_MDLL_remove(mdll, head, tail, element) \
+ do \
+ { \
+ GNUNET_assert (((element)->prev_##mdll != NULL) || ((head) == (element))); \
+ GNUNET_assert (((element)->next_##mdll != NULL) || ((tail) == (element))); \
+ if ((element)->prev_##mdll == NULL) \
+ (head) = (element)->next_##mdll; \
+ else \
+ (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \
+ if ((element)->next_##mdll == NULL) \
+ (tail) = (element)->prev_##mdll; \
+ else \
+ (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \
+ (element)->next_##mdll = NULL; \
+ (element)->prev_##mdll = NULL; \
+ } while (0)
/**
@@ -2085,44 +2451,36 @@ GNUNET_CONTAINER_multihashmap32_iterator_destroy (struct GNUNET_CONTAINER_MultiH
* @param[in,out] tail tail of DLL
* @param element element to insert
*/
-#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE,comparator,comparator_cls,head,tail,element) do { \
- if ( (NULL == head) || \
- (0 < comparator (comparator_cls, \
- element, \
- head)) ) \
- { \
- /* insert at head, element < head */ \
- GNUNET_CONTAINER_DLL_insert (head, \
- tail, \
- element); \
- } \
- else \
- { \
- TYPE *pos; \
- \
- for (pos = head; \
- NULL != pos; \
- pos = pos->next) \
- if (0 < \
- comparator (comparator_cls, \
- element, \
- pos)) \
- break; /* element < pos */ \
- if (NULL == pos) /* => element > tail */ \
- { \
- GNUNET_CONTAINER_DLL_insert_tail (head, \
- tail, \
- element); \
- } \
- else /* prev < element < pos */ \
- { \
- GNUNET_CONTAINER_DLL_insert_after (head, \
- tail, \
- pos->prev, \
- element); \
- } \
- } \
-} while (0)
+#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE, \
+ comparator, \
+ comparator_cls, \
+ head, \
+ tail, \
+ element) \
+ do \
+ { \
+ if ((NULL == head) || (0 < comparator (comparator_cls, element, head))) \
+ { \
+ /* insert at head, element < head */ \
+ GNUNET_CONTAINER_DLL_insert (head, tail, element); \
+ } \
+ else \
+ { \
+ TYPE *pos; \
+ \
+ for (pos = head; NULL != pos; pos = pos->next) \
+ if (0 < comparator (comparator_cls, element, pos)) \
+ break; /* element < pos */ \
+ if (NULL == pos) /* => element > tail */ \
+ { \
+ GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); \
+ } \
+ else /* prev < element < pos */ \
+ { \
+ GNUNET_CONTAINER_DLL_insert_after (head, tail, pos->prev, element); \
+ } \
+ } \
+ } while (0)
/* ******************** Heap *************** */
@@ -2236,7 +2594,8 @@ GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
* @return cost of the node
*/
GNUNET_CONTAINER_HeapCostType
-GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *node);
+GNUNET_CONTAINER_heap_node_get_cost (
+ const struct GNUNET_CONTAINER_HeapNode *node);
/**
@@ -2250,11 +2609,11 @@ GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *nod
* @return #GNUNET_YES if we should continue to iterate,
* #GNUNET_NO if not.
*/
-typedef int
-(*GNUNET_CONTAINER_HeapIterator) (void *cls,
- struct GNUNET_CONTAINER_HeapNode *node,
- void *element,
- GNUNET_CONTAINER_HeapCostType cost);
+typedef int (*GNUNET_CONTAINER_HeapIterator) (
+ void *cls,
+ struct GNUNET_CONTAINER_HeapNode *node,
+ void *element,
+ GNUNET_CONTAINER_HeapCostType cost);
/**
@@ -2335,7 +2694,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_HeapNode *node,
GNUNET_CONTAINER_HeapCostType new_cost);
-#if 0 /* keep Emacsens' auto-indent happy */
+#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
#ifdef __cplusplus
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index d2a09087e..4d23b91c6 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -23,12 +23,6 @@
* @brief namestore for the GNUnet naming system
* @author Matthias Wachs
* @author Christian Grothoff
- *
- * TODO:
- * - "get_nick_record" is a bottleneck, introduce a cache to
- * avoid looking it up again and again (for the same few
- * zones that the user will typically manage!)
- * - run testcases, make sure everything works!
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -562,13 +556,20 @@ cache_nick (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
}
GNUNET_free_non_null (oldest->rd);
oldest->zone = *zone;
- oldest->rd = GNUNET_malloc (sizeof (*nick) +
- nick->data_size);
- *oldest->rd = *nick;
- oldest->rd->data = &oldest->rd[1];
- memcpy (&oldest->rd[1],
- nick->data,
- nick->data_size);
+ if (NULL != nick)
+ {
+ oldest->rd = GNUNET_malloc (sizeof (*nick) +
+ nick->data_size);
+ *oldest->rd = *nick;
+ oldest->rd->data = &oldest->rd[1];
+ memcpy (&oldest->rd[1],
+ nick->data,
+ nick->data_size);
+ }
+ else
+ {
+ oldest->rd = NULL;
+ }
oldest->last_used = GNUNET_TIME_absolute_get ();
}
@@ -592,8 +593,10 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
struct NickCache *pos = &nick_cache[i];
if ( (NULL != pos->rd) &&
(0 == GNUNET_memcmp (zone,
- &pos->zone)) )
+ &pos->zone)) )
{
+ if (NULL == pos->rd)
+ return NULL;
nick = GNUNET_malloc (sizeof (*nick) +
pos->rd->data_size);
*nick = *pos->rd;
@@ -615,10 +618,25 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
if ( (GNUNET_OK != res) ||
(NULL == nick) )
{
- GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
- "No nick name set for zone `%s'\n",
- GNUNET_GNSRECORD_z2s (&pub));
+ static int do_log = GNUNET_LOG_CALL_STATUS;
+
+ if (0 == do_log)
+ do_log
+ = GNUNET_get_log_call_status (GNUNET_ERROR_TYPE_DEBUG,
+ "namestore",
+ __FILE__,
+ __FUNCTION__,
+ __LINE__);
+ if (1 == do_log)
+ {
+ GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
+ "No nick name set for zone `%s'\n",
+ GNUNET_GNSRECORD_z2s (&pub));
+ }
+ /* update cache */
+ cache_nick (zone,
+ NULL);
return NULL;
}
@@ -1603,8 +1621,10 @@ handle_record_store (void *cls,
#GNUNET_GNS_EMPTY_LABEL_AT label */
struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
unsigned int rd_clean_off;
+ int have_nick;
rd_clean_off = 0;
+ have_nick = GNUNET_NO;
for (unsigned int i=0;i<rd_count;i++)
{
rd_clean[rd_clean_off] = rd[i];
@@ -1616,8 +1636,19 @@ handle_record_store (void *cls,
if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT,
conv_name)) &&
(GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) )
+ {
cache_nick (&rp_msg->private_key,
&rd[i]);
+ have_nick = GNUNET_YES;
+ }
+ }
+ if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT,
+ conv_name)) &&
+ (GNUNET_NO == have_nick) )
+ {
+ /* remove nick record from cache, in case we have one there */
+ cache_nick (&rp_msg->private_key,
+ NULL);
}
res = GSN_database->store_records (GSN_database->cls,
&rp_msg->private_key,
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c
index bf2fe11c3..c8ffa152e 100644
--- a/src/nse/gnunet-nse.c
+++ b/src/nse/gnunet-nse.c
@@ -46,6 +46,7 @@ static int status;
static void
do_shutdown (void *cls)
{
+ (void) cls;
if (NULL != nse)
{
GNUNET_NSE_disconnect (nse);
@@ -65,12 +66,14 @@ do_shutdown (void *cls)
*/
static void
handle_estimate (void *cls,
- struct GNUNET_TIME_Absolute timestamp,
+ struct GNUNET_TIME_Absolute timestamp,
double estimate,
- double std_dev)
+ double std_dev)
{
+ (void) cls;
status = 0;
- FPRINTF (stdout, "%llu %f %f %f\n",
+ FPRINTF (stdout,
+ "%llu %f %f %f\n",
(unsigned long long) timestamp.abs_value_us,
GNUNET_NSE_log_estimate_to_n (estimate),
estimate,
@@ -92,11 +95,11 @@ run (void *cls,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- nse = GNUNET_NSE_connect (cfg,
- &handle_estimate,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+ nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
@@ -106,22 +109,21 @@ run (void *cls,
* @return 0 on success
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
static struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
status = 1;
if (GNUNET_OK !=
GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-nse",
- gettext_noop
- ("Show network size estimates from NSE service."),
- options,
- &run, NULL))
+ argv,
+ "gnunet-nse",
+ gettext_noop (
+ "Show network size estimates from NSE service."),
+ options,
+ &run,
+ NULL))
return 2;
return status;
}
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 09316dbcf..fd83d2b67 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -430,6 +430,7 @@ handle_start (void *cls, const struct GNUNET_MessageHeader *message)
struct GNUNET_NSE_ClientMessage em;
struct GNUNET_MQ_Envelope *env;
+ (void) message;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
mq = GNUNET_SERVICE_client_get_mq (client);
GNUNET_notification_context_add (nc, mq);
@@ -717,6 +718,8 @@ schedule_current_round (void *cls,
struct NSEPeerEntry *peer_entry = value;
struct GNUNET_TIME_Relative delay;
+ (void) cls;
+ (void) key;
if (NULL != peer_entry->transmit_task)
{
GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
@@ -749,8 +752,8 @@ static void
update_flood_message (void *cls)
{
struct GNUNET_TIME_Relative offset;
- unsigned int i;
+ (void) cls;
flood_task = NULL;
offset = GNUNET_TIME_absolute_get_remaining (next_timestamp);
if (0 != offset.rel_value_us)
@@ -780,7 +783,7 @@ update_flood_message (void *cls)
setup_flood_message (estimate_index, current_timestamp);
next_message.matching_bits = htonl (0); /* reset for 'next' round */
hop_count_max = 0;
- for (i = 0; i < HISTORY_SIZE; i++)
+ for (unsigned int i = 0; i < HISTORY_SIZE; i++)
hop_count_max =
GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max);
GNUNET_CONTAINER_multipeermap_iterate (peers, &schedule_current_round, NULL);
@@ -869,6 +872,7 @@ find_proof (void *cls)
struct GNUNET_HashCode result;
unsigned int i;
+ (void) cls;
proof_task = NULL;
GNUNET_memcpy (&buf[sizeof (uint64_t)],
&my_identity,
@@ -967,6 +971,7 @@ update_flood_times (void *cls,
struct NSEPeerEntry *peer_entry = value;
struct GNUNET_TIME_Relative delay;
+ (void) key;
if (peer_entry == exclude)
return GNUNET_OK; /* trigger of the update */
if (GNUNET_NO == peer_entry->previous_round)
@@ -1178,6 +1183,7 @@ handle_core_connect (void *cls,
{
struct NSEPeerEntry *peer_entry;
+ (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer `%s' connected to us\n",
GNUNET_i2s (peer));
@@ -1217,6 +1223,7 @@ handle_core_disconnect (void *cls,
{
struct NSEPeerEntry *pos = internal_cls;
+ (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer `%s' disconnected from us\n",
GNUNET_i2s (peer));
@@ -1243,6 +1250,8 @@ handle_core_disconnect (void *cls,
static void
flush_comp_cb (void *cls, size_t size)
{
+ (void) cls;
+ (void) size;
GNUNET_TESTBED_LOGGER_disconnect (lh);
lh = NULL;
}
@@ -1257,6 +1266,7 @@ flush_comp_cb (void *cls, size_t size)
static void
shutdown_task (void *cls)
{
+ (void) cls;
if (NULL != flood_task)
{
GNUNET_SCHEDULER_cancel (flood_task);
@@ -1324,6 +1334,7 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *identity)
struct GNUNET_TIME_Absolute now;
struct GNUNET_TIME_Absolute prev_time;
+ (void) cls;
if (NULL == identity)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n");
@@ -1365,6 +1376,7 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *identity)
static void
status_cb (void *cls, int status)
{
+ (void) cls;
logger_test = NULL;
if (GNUNET_YES != status)
{
@@ -1402,6 +1414,8 @@ run (void *cls,
char *proof;
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
+ (void) cls;
+ (void) service;
cfg = c;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg,
"NSE",
@@ -1524,6 +1538,8 @@ client_connect_cb (void *cls,
struct GNUNET_SERVICE_Client *c,
struct GNUNET_MQ_Handle *mq)
{
+ (void) cls;
+ (void) mq;
return c;
}
@@ -1540,6 +1556,7 @@ client_disconnect_cb (void *cls,
struct GNUNET_SERVICE_Client *c,
void *internal_cls)
{
+ (void) cls;
GNUNET_assert (c == internal_cls);
}
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c
index e9eaada93..259be75ed 100644
--- a/src/nse/nse_api.c
+++ b/src/nse/nse_api.c
@@ -32,7 +32,7 @@
#include "gnunet_nse_service.h"
#include "nse.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "nse-api",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "nse-api", __VA_ARGS__)
/**
* Handle for talking with the NSE service.
@@ -68,7 +68,6 @@ struct GNUNET_NSE_Handle
* Closure to pass to @e recv_cb callback.
*/
void *recv_cb_cls;
-
};
@@ -91,17 +90,15 @@ reconnect (void *cls);
* @param error error code
*/
static void
-mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_NSE_Handle *h = cls;
+ (void) error;
GNUNET_MQ_destroy (h->mq);
h->mq = NULL;
- h->reconnect_task
- = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
- &reconnect,
- h);
+ h->reconnect_task =
+ GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
@@ -114,8 +111,7 @@ mq_error_handler (void *cls,
* @param client_msg message received
*/
static void
-handle_estimate (void *cls,
- const struct GNUNET_NSE_ClientMessage *client_msg)
+handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg)
{
struct GNUNET_NSE_Handle *h = cls;
@@ -123,7 +119,7 @@ handle_estimate (void *cls,
h->recv_cb (h->recv_cb_cls,
GNUNET_TIME_absolute_ntoh (client_msg->timestamp),
GNUNET_ntoh_double (client_msg->size_estimate),
- GNUNET_ntoh_double (client_msg->std_deviation));
+ GNUNET_ntoh_double (client_msg->std_deviation));
}
@@ -136,13 +132,12 @@ static void
reconnect (void *cls)
{
struct GNUNET_NSE_Handle *h = cls;
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (estimate,
- GNUNET_MESSAGE_TYPE_NSE_ESTIMATE,
- struct GNUNET_NSE_ClientMessage,
- h),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_fixed_size (estimate,
+ GNUNET_MESSAGE_TYPE_NSE_ESTIMATE,
+ struct GNUNET_NSE_ClientMessage,
+ h),
+ GNUNET_MQ_handler_end ()};
struct GNUNET_MessageHeader *msg;
struct GNUNET_MQ_Envelope *env;
@@ -150,17 +145,11 @@ reconnect (void *cls)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connecting to network size estimation service.\n");
GNUNET_assert (NULL == h->mq);
- h->mq = GNUNET_CLIENT_connect (h->cfg,
- "nse",
- handlers,
- &mq_error_handler,
- h);
+ h->mq = GNUNET_CLIENT_connect (h->cfg, "nse", handlers, &mq_error_handler, h);
if (NULL == h->mq)
return;
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_NSE_START);
- GNUNET_MQ_send (h->mq,
- env);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NSE_START);
+ GNUNET_MQ_send (h->mq, env);
}
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 18a80b3c5..bae187e7c 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -27,71 +27,50 @@
* - review retransmission logic, right now there is no smartness there!
* => congestion control, etc [PERFORMANCE-BASICS]
*
- * Optimizations:
+ * Optimizations-Statistics:
+ * - Track ACK losses based on ACK-counter [ROUTING]
+ * - Need to track total bandwidth per VirtualLink and adjust how frequently
+ * we send FC messages based on bandwidth-delay-product (and relation
+ * to the window size!). See OPTIMIZE-FC-BDP.
+ * - Consider more statistics in #check_connection_quality() [FIXME-CONQ-STATISTICS]
+ * - Adapt available_fc_window_size, using larger values for high-bandwidth
+ * and high-latency links *if* we have the RAM [GOODPUT / utilization / stalls]
+ * - Set last_window_consum_limit promise properly based on
+ * latency and bandwidth of the respective connection [GOODPUT / utilization / stalls]
+ *
+ * Optimizations-DV:
* - When forwarding DV learn messages, if a peer is reached that
* has a *bidirectional* link to the origin beyond 1st hop,
* do NOT forward it to peers _other_ than the origin, as
* there is clearly a better path directly from the origin to
* whatever else we could reach.
- * - AcknowledgementUUIDPs are overkill with 256 bits (128 would do)
- * => Need 128 bit hash map though! [BANDWIDTH, MEMORY]
- * - queue_send_msg by API design has to make a copy
- * of the payload, and route_message on top of that requires a malloc/free.
- * Change design to approximate "zero" copy better... [CPU]
- * - could avoid copying body of message into each fragment and keep
- * fragments as just pointers into the original message and only
- * fully build fragments just before transmission (optimization, should
- * reduce CPU and memory use) [CPU, MEMORY]
- * - if messages are below MTU, consider adding ACKs and other stuff
- * to the same transmission to avoid tiny messages (requires planning at
- * receiver, and additional MST-style demultiplex at receiver!) [PACKET COUNT]
* - When we passively learned DV (with unconfirmed freshness), we
* right now add the path to our list but with a zero path_valid_until
* time and only use it for unconfirmed routes. However, we could consider
* triggering an explicit validation mechansim ourselves, specifically routing
* a challenge-response message over the path [ROUTING]
- * - Track ACK losses based on ACK-counter [ROUTING]
- * - Fragments send over a reliable channel could do without the
- * AcknowledgementUUIDP altogether, as they won't be acked! [BANDWIDTH]
- * (-> have 2nd type of acknowledgment message; low priority, as we
- * do not have an MTU-limited *reliable* communicator)
- * - Adapt available_fc_window_size, using larger values for high-bandwidth
- * and high-latency links *if* we have the RAM [GOODPUT / utilization / stalls]
- * - Set last_window_consum_limit promise properly based on
- * latency and bandwidth of the respective connection [GOODPUT / utilization / stalls]
- * - Need to track total bandwidth per VirtualLink and adjust how frequently
- * we send FC messages based on bandwidth-delay-product (and relation
- * to the window size!). See OPTIMIZE-FC-BDP.
- * - if available, try to confirm unconfirmed DV paths when trying to establish
+ * = if available, try to confirm unconfirmed DV paths when trying to establish
* virtual link for a `struct IncomingRequest`. (i.e. if DVH is
* unconfirmed, incoming requests cause us to try to validate a passively
* learned path (requires new message type!))
*
- * Design realizations / discussion:
- * - communicators do flow control by calling MQ "notify sent"
- * when 'ready'. They determine flow implicitly (i.e. TCP blocking)
- * or explicitly via backchannel FC ACKs. As long as the
- * channel is not full, they may 'notify sent' even if the other
- * peer has not yet confirmed receipt. The other peer confirming
- * is _only_ for FC, not for more reliable transmission; reliable
- * transmission (i.e. of fragments) is left to _transport_.
- * - ACKs sent back in uni-directional communicators are done via
- * the background channel API; here transport _may_ initially
- * broadcast (with bounded # hops) if no path is known;
- * - transport should _integrate_ DV-routing and build a view of
- * the network; then background channel traffic can be
- * routed via DV as well as explicit "DV" traffic.
- * - background channel is also used for ACKs and NAT traversal support
- * - transport service is responsible for AEAD'ing the background
- * channel, timestamps and monotonic time are used against replay
- * of old messages -> peerstore needs to be supplied with
- * "latest timestamps seen" data
- * - if transport implements DV, we likely need a 3rd peermap
- * in addition to ephemerals and (direct) neighbours
- * ==> check if stuff needs to be moved out of "Neighbour"
- * - transport should encapsualte core-level messages and do its
- * own ACKing for RTT/goodput/loss measurements _and_ fragment
- * for retransmission
+ * Optimizations-Fragmentation:
+ * - Fragments send over a reliable channel could do without the
+ * AcknowledgementUUIDP altogether, as they won't be acked! [BANDWIDTH]
+ * (-> have 2nd type of acknowledgment message; low priority, as we
+ * do not have an MTU-limited *reliable* communicator) [FIXME-FRAG-REL-UUID]
+ * - if messages are below MTU, consider adding ACKs and other stuff
+ * to the same transmission to avoid tiny messages (requires planning at
+ * receiver, and additional MST-style demultiplex at receiver!) [PACKET COUNT]
+ *
+ * Optimizations-internals:
+ * - queue_send_msg by API design has to make a copy
+ * of the payload, and route_message on top of that requires a malloc/free.
+ * Change design to approximate "zero" copy better... [CPU]
+ * - could avoid copying body of message into each fragment and keep
+ * fragments as just pointers into the original message and only
+ * fully build fragments just before transmission (optimization, should
+ * reduce CPU and memory use) [CPU, MEMORY]
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -345,9 +324,9 @@ struct MessageUUIDP
struct AcknowledgementUUIDP
{
/**
- * The UUID value. Not actually a hash, but a random value.
+ * The UUID value.
*/
- struct GNUNET_ShortHashCode value;
+ struct GNUNET_Uuid value;
};
@@ -1311,18 +1290,6 @@ struct VirtualLink
struct DistanceVector *dv;
/**
- * Last challenge we received from @a n.
- * FIXME: where do we need this?
- */
- struct ChallengeNonceP n_challenge;
-
- /**
- * Last challenge we used with @a n for flow control.
- * FIXME: where do we need this?
- */
- struct ChallengeNonceP my_challenge;
-
- /**
* Sender timestamp of @e n_challenge, used to generate out-of-order
* challenges (as sender's timestamps must be monotonically
* increasing). FIXME: where do we need this?
@@ -2736,7 +2703,7 @@ static struct GNUNET_CONTAINER_MultiPeerMap *ack_cummulators;
* Map of pending acknowledgements, mapping `struct AcknowledgementUUID` to
* a `struct PendingAcknowledgement`.
*/
-static struct GNUNET_CONTAINER_MultiShortmap *pending_acks;
+static struct GNUNET_CONTAINER_MultiUuidmap *pending_acks;
/**
* Map from PIDs to `struct DistanceVector` entries describing
@@ -2910,9 +2877,9 @@ free_pending_acknowledgement (struct PendingAcknowledgement *pa)
pa->queue = NULL;
}
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multishortmap_remove (pending_acks,
- &pa->ack_uuid.value,
- pa));
+ GNUNET_CONTAINER_multiuuidmap_remove (pending_acks,
+ &pa->ack_uuid.value,
+ pa));
GNUNET_free (pa);
}
@@ -3905,11 +3872,12 @@ client_send_response (struct PendingMessage *pm)
{
struct TransportClient *tc = pm->client;
struct VirtualLink *vl = pm->vl;
- struct GNUNET_MQ_Envelope *env;
- struct SendOkMessage *som;
if (NULL != tc)
{
+ struct GNUNET_MQ_Envelope *env;
+ struct SendOkMessage *som;
+
env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
som->peer = vl->target;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -4225,7 +4193,7 @@ queue_send_msg (struct Queue *queue,
GNUNET_ERROR_TYPE_DEBUG,
"Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n",
(unsigned int) payload_size,
- pm->logging_uuid,
+ (NULL == pm) ? 0 : pm->logging_uuid,
(unsigned long long) queue->qid,
GNUNET_i2s (&queue->neighbour->pid));
env = GNUNET_MQ_msg_extra (smt,
@@ -4626,11 +4594,11 @@ encapsulate_for_dv (struct DistanceVector *dv,
char *path;
path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity));
- for (unsigned int i = 0; i <= num_hops; i++)
+ for (unsigned int j = 0; j <= num_hops; j++)
{
char *tmp;
- GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[i]));
+ GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[j]));
GNUNET_free (path);
path = tmp;
}
@@ -5468,7 +5436,7 @@ cummulative_ack (const struct GNUNET_PeerIdentity *pid,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Scheduling ACK %s for transmission to %s\n",
- GNUNET_sh2s (&ack_uuid->value),
+ GNUNET_uuid2s (&ack_uuid->value),
GNUNET_i2s (pid));
ac = GNUNET_CONTAINER_multipeermap_get (ack_cummulators, pid);
if (NULL == ac)
@@ -5743,7 +5711,7 @@ handle_reliability_box (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received reliability box from %s with UUID %s of type %u\n",
GNUNET_i2s (&cmc->im.sender),
- GNUNET_sh2s (&rb->ack_uuid.value),
+ GNUNET_uuid2s (&rb->ack_uuid.value),
(unsigned int) ntohs (inbox->type));
rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we
do not really have an RTT for the
@@ -5971,7 +5939,6 @@ handle_reliability_ack (void *cls,
{
struct CommunicatorMessageContext *cmc = cls;
const struct TransportCummulativeAckPayloadP *ack;
- struct PendingAcknowledgement *pa;
unsigned int n_acks;
uint32_t ack_counter;
@@ -5980,14 +5947,14 @@ handle_reliability_ack (void *cls,
ack = (const struct TransportCummulativeAckPayloadP *) &ra[1];
for (unsigned int i = 0; i < n_acks; i++)
{
- pa =
- GNUNET_CONTAINER_multishortmap_get (pending_acks, &ack[i].ack_uuid.value);
+ struct PendingAcknowledgement *pa =
+ GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value);
if (NULL == pa)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received ACK from %s with UUID %s which is unknown to us!\n",
GNUNET_i2s (&cmc->im.sender),
- GNUNET_sh2s (&ack[i].ack_uuid.value));
+ GNUNET_uuid2s (&ack[i].ack_uuid.value));
GNUNET_STATISTICS_update (
GST_stats,
"# FRAGMENT_ACKS dropped, no matching pending message",
@@ -5998,7 +5965,7 @@ handle_reliability_ack (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received ACK from %s with UUID %s\n",
GNUNET_i2s (&cmc->im.sender),
- GNUNET_sh2s (&ack[i].ack_uuid.value));
+ GNUNET_uuid2s (&ack[i].ack_uuid.value));
handle_acknowledged (pa, GNUNET_TIME_relative_ntoh (ack[i].ack_delay));
}
@@ -6919,7 +6886,7 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
if (0 == (bi_history & (1 << i)))
break; /* i-th hop not bi-directional, stop learning! */
- if (i == nhops)
+ if (i == nhops - 1)
{
path[i + 2] = dvl->initiator;
}
@@ -7557,89 +7524,6 @@ check_incoming_msg (void *cls,
}
-#if 0
-/**
- * We received a @a challenge from another peer, check if we can
- * increase the flow control window to that peer.
- *
- * @param vl virtual link
- * @param challenge the challenge we received
- * @param sender_time when did the peer send the message?
- * @param last_window_consum_limit maximum number of kb the sender
- * promises to use of the previous window (if any)
- */
-static void
-update_fc_window (struct VirtualLink *vl,
- struct GNUNET_TIME_Absolute sender_time,
- uint32_t last_window_consum_limit)
-{
- // FIXME: update to new FC logic
- if (0 == GNUNET_memcmp (challenge, &vl->n_challenge))
- {
- uint32_t avail;
-
- /* Challenge identical to last one, update
- @a last_window_consum_limit (to minimum) */
- vl->last_fc_window_size_remaining =
- GNUNET_MIN (last_window_consum_limit, vl->last_fc_window_size_remaining);
- /* window could have shrunk! */
- if (vl->available_fc_window_size > vl->last_fc_window_size_remaining)
- avail = vl->available_fc_window_size - vl->last_fc_window_size_remaining;
- else
- avail = 0;
- /* guard against integer overflow */
- if (vl->incoming_fc_window_size_used + avail >=
- vl->incoming_fc_window_size_used)
- vl->incoming_fc_window_size = vl->incoming_fc_window_size_used + avail;
- else
- vl->incoming_fc_window_size = UINT32_MAX;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Updated window to %u/%u kb (%u used) for virtual link to %s!\n",
- vl->incoming_fc_window_size,
- vl->available_fc_window_size,
- vl->incoming_fc_window_size_used,
- GNUNET_i2s (&vl->target));
- return;
- }
- if (vl->n_challenge_time.abs_value_us >= sender_time.abs_value_us)
- {
- GNUNET_STATISTICS_update (GST_stats,
- "# Challenges ignored: sender time not increasing",
- 1,
- GNUNET_NO);
- return;
- }
- /* new challenge! */
- if (vl->incoming_fc_window_size_used > last_window_consum_limit)
- {
- /* lying peer: it already used more than it promised it would ever use! */
- GNUNET_break_op (0);
- last_window_consum_limit = vl->incoming_fc_window_size_used;
- }
- /* What remains is at most the difference between what we already processed
- and what the sender promises to limit itself to. */
- vl->last_fc_window_size_remaining =
- last_window_consum_limit - vl->incoming_fc_window_size_used;
- vl->n_challenge = *challenge;
- vl->n_challenge_time = sender_time;
- vl->incoming_fc_window_size_used = 0;
- /* window could have shrunk! */
- if (vl->available_fc_window_size > vl->last_fc_window_size_remaining)
- vl->incoming_fc_window_size =
- vl->available_fc_window_size - vl->last_fc_window_size_remaining;
- else
- vl->incoming_fc_window_size = 0;
- GNUNET_log (
- GNUNET_ERROR_TYPE_DEBUG,
- "New window at %u/%u kb (%u left on previous) for virtual link to %s!\n",
- vl->incoming_fc_window_size,
- vl->available_fc_window_size,
- vl->last_fc_window_size_remaining,
- GNUNET_i2s (&vl->target));
-}
-#endif
-
-
/**
* Closure for #check_known_address.
*/
@@ -8155,7 +8039,6 @@ handle_validation_response (
n->vl = vl;
vl->core_recv_window = RECV_WINDOW_SIZE;
vl->available_fc_window_size = DEFAULT_WINDOW_SIZE;
- vl->my_challenge = tvr->challenge;
vl->visibility_task =
GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl);
GNUNET_break (GNUNET_YES ==
@@ -8412,7 +8295,7 @@ prepare_pending_acknowledgement (struct Queue *queue,
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
&pa->ack_uuid,
sizeof (pa->ack_uuid));
- } while (GNUNET_YES != GNUNET_CONTAINER_multishortmap_put (
+ } while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put (
pending_acks,
&pa->ack_uuid.value,
pa,
@@ -8425,7 +8308,7 @@ prepare_pending_acknowledgement (struct Queue *queue,
pa->message_size = pm->bytes_msg;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Waiting for ACKnowledgment `%s' for <%llu>\n",
- GNUNET_sh2s (&pa->ack_uuid.value),
+ GNUNET_uuid2s (&pa->ack_uuid.value),
pm->logging_uuid);
return pa;
}
@@ -8746,10 +8629,9 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc,
this queue */) )
{
frag = GNUNET_YES;
- relb = GNUNET_NO; /* if we fragment, we never also reliability box */
if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)
{
- /* FIXME-OPTIMIZE: we could use an optimized, shorter fragmentation
+ /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation
header without the ACK UUID when using a *reliable* channel! */
}
real_overhead = overhead + sizeof (struct TransportFragmentBoxMessage);
@@ -8946,8 +8828,9 @@ transmit_on_queue (void *cls)
"Fragmentation failed queue %s to %s for <%llu>, trying again\n",
queue->address,
GNUNET_i2s (&n->pid),
- pm->logging_uuid);
+ sc.best->logging_uuid);
schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
+ return;
}
}
else if (GNUNET_YES == sc.relb)
@@ -8961,7 +8844,7 @@ transmit_on_queue (void *cls)
"Reliability boxing failed queue %s to %s for <%llu>, trying again\n",
queue->address,
GNUNET_i2s (&n->pid),
- pm->logging_uuid);
+ sc.best->logging_uuid);
schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
return;
}
@@ -9442,7 +9325,7 @@ check_connection_quality (void *cls,
ctx->num_queues++;
if (0 == ctx->k--)
ctx->q = q;
- /* OPTIMIZE-FIXME: in the future, add reliability / goodput
+ /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput
statistics and consider those as well here? */
if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us)
do_inc = GNUNET_YES;
@@ -10017,9 +9900,7 @@ free_validation_state_cb (void *cls,
* @return #GNUNET_OK (always)
*/
static int
-free_pending_ack_cb (void *cls,
- const struct GNUNET_ShortHashCode *key,
- void *value)
+free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value)
{
struct PendingAcknowledgement *pa = value;
@@ -10085,10 +9966,10 @@ do_shutdown (void *cls)
NULL);
GNUNET_CONTAINER_multipeermap_destroy (ack_cummulators);
ack_cummulators = NULL;
- GNUNET_CONTAINER_multishortmap_iterate (pending_acks,
- &free_pending_ack_cb,
- NULL);
- GNUNET_CONTAINER_multishortmap_destroy (pending_acks);
+ GNUNET_CONTAINER_multiuuidmap_iterate (pending_acks,
+ &free_pending_ack_cb,
+ NULL);
+ GNUNET_CONTAINER_multiuuidmap_destroy (pending_acks);
pending_acks = NULL;
GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (neighbours));
GNUNET_CONTAINER_multipeermap_destroy (neighbours);
@@ -10142,7 +10023,7 @@ run (void *cls,
hello_mono_time = GNUNET_TIME_absolute_get_monotonic (c);
GST_cfg = c;
backtalkers = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES);
- pending_acks = GNUNET_CONTAINER_multishortmap_create (32768, GNUNET_YES);
+ pending_acks = GNUNET_CONTAINER_multiuuidmap_create (32768, GNUNET_YES);
ack_cummulators = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES);
neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
links = GNUNET_CONTAINER_multipeermap_create (512, GNUNET_YES);
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 8a99197f8..fe5cc6e72 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -78,6 +78,7 @@ libgnunetutil_la_SOURCES = \
container_meta_data.c \
container_multihashmap.c \
container_multishortmap.c \
+ container_multiuuidmap.c \
container_multipeermap.c \
container_multihashmap32.c \
crypto_symmetric.c \
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 5052134f8..b5678e5be 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -107,7 +107,8 @@ static __thread struct GNUNET_AsyncScopeSave current_async_scope;
* Note that this message maybe truncated to the first BULK_TRACK_SIZE
* characters, in which case it is NOT 0-terminated!
*/
-static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE] __attribute__ ((nonstring));
+static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE]
+ __attribute__ ((nonstring));
/**
* Type of the last bulk message.
@@ -211,7 +212,7 @@ struct LogDef
};
-#if !defined(GNUNET_CULL_LOGGING)
+#if ! defined(GNUNET_CULL_LOGGING)
/**
* Dynamic array of logging definitions
*/
@@ -263,17 +264,17 @@ get_type (const char *log)
{
if (NULL == log)
return GNUNET_ERROR_TYPE_UNSPECIFIED;
- if (0 == strcasecmp (log, _("DEBUG")))
+ if (0 == strcasecmp (log, _ ("DEBUG")))
return GNUNET_ERROR_TYPE_DEBUG;
- if (0 == strcasecmp (log, _("INFO")))
+ if (0 == strcasecmp (log, _ ("INFO")))
return GNUNET_ERROR_TYPE_INFO;
- if (0 == strcasecmp (log, _("MESSAGE")))
+ if (0 == strcasecmp (log, _ ("MESSAGE")))
return GNUNET_ERROR_TYPE_MESSAGE;
- if (0 == strcasecmp (log, _("WARNING")))
+ if (0 == strcasecmp (log, _ ("WARNING")))
return GNUNET_ERROR_TYPE_WARNING;
- if (0 == strcasecmp (log, _("ERROR")))
+ if (0 == strcasecmp (log, _ ("ERROR")))
return GNUNET_ERROR_TYPE_ERROR;
- if (0 == strcasecmp (log, _("NONE")))
+ if (0 == strcasecmp (log, _ ("NONE")))
return GNUNET_ERROR_TYPE_NONE;
return GNUNET_ERROR_TYPE_INVALID;
}
@@ -292,7 +293,7 @@ GNUNET_abort_ ()
}
-#if !defined(GNUNET_CULL_LOGGING)
+#if ! defined(GNUNET_CULL_LOGGING)
/**
* Utility function - reallocates logdefs array to be twice as large.
*/
@@ -353,7 +354,7 @@ setup_log_file (const struct tm *tm)
if (0 == strftime (fn, sizeof (fn), log_file_name, tm))
return GNUNET_SYSERR;
leftsquare = strrchr (fn, '[');
- if ( (NULL != leftsquare) && (']' == leftsquare[1]) )
+ if ((NULL != leftsquare) && (']' == leftsquare[1]))
{
char *logfile_copy = GNUNET_strdup (fn);
@@ -371,8 +372,7 @@ setup_log_file (const struct tm *tm)
return GNUNET_OK; /* no change */
log_rotate (last_fn);
strcpy (last_fn, fn);
- if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_create_for_file (fn))
+ if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (fn))
{
fprintf (stderr,
"Failed to create directory for `%s': %s\n",
@@ -381,14 +381,12 @@ setup_log_file (const struct tm *tm)
return GNUNET_SYSERR;
}
#if WINDOWS
- altlog_fd = OPEN (fn, O_APPEND |
- O_BINARY |
- O_WRONLY | O_CREAT,
- _S_IREAD | _S_IWRITE);
+ altlog_fd =
+ OPEN (fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE);
#else
- altlog_fd = OPEN (fn, O_APPEND |
- O_WRONLY | O_CREAT,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ altlog_fd = OPEN (fn,
+ O_APPEND | O_WRONLY | O_CREAT,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
#endif
if (-1 != altlog_fd)
{
@@ -512,7 +510,7 @@ GNUNET_get_log_call_status (int caller_level,
/* We have no definitions to override globally configured log level,
* so just use it right away.
*/
- if ( (min_level >= 0) && (GNUNET_NO == gnunet_force_log_present) )
+ if ((min_level >= 0) && (GNUNET_NO == gnunet_force_log_present))
return caller_level <= min_level;
/* Only look for forced definitions? */
@@ -520,7 +518,7 @@ GNUNET_get_log_call_status (int caller_level,
for (i = 0; i < logdefs_len; i++)
{
ld = &logdefs[i];
- if (( (!force_only) || ld->force) &&
+ if (((! force_only) || ld->force) &&
(line >= ld->from_line && line <= ld->to_line) &&
(0 == regexec (&ld->component_regex, comp, 0, NULL, 0)) &&
(0 == regexec (&ld->file_regex, file, 0, NULL, 0)) &&
@@ -591,73 +589,79 @@ parse_definitions (const char *constname, int force)
{
switch (p[0])
{
- case ';': /* found a field separator */
+ case ';': /* found a field separator */
p[0] = '\0';
switch (state)
{
- case 0: /* within a component name */
+ case 0: /* within a component name */
comp = start;
break;
- case 1: /* within a file name */
+ case 1: /* within a file name */
file = start;
break;
- case 2: /* within a function name */
+ case 2: /* within a function name */
/* after a file name there must be a function name */
function = start;
break;
- case 3: /* within a from-to line range */
+ case 3: /* within a from-to line range */
if (strlen (start) > 0)
{
errno = 0;
from_line = strtol (start, &t, 10);
- if ( (0 != errno) || (from_line < 0) )
+ if ((0 != errno) || (from_line < 0))
{
GNUNET_free (def);
return counter;
}
- if ( (t < p) && ('-' == t[0]) )
+ if ((t < p) && ('-' == t[0]))
{
errno = 0;
start = t + 1;
to_line = strtol (start, &t, 10);
- if ( (0 != errno) || (to_line < 0) || (t != p) )
+ if ((0 != errno) || (to_line < 0) || (t != p))
{
GNUNET_free (def);
return counter;
}
}
- else /* one number means "match this line only" */
+ else /* one number means "match this line only" */
to_line = from_line;
}
- else /* default to 0-max */
+ else /* default to 0-max */
{
from_line = 0;
to_line = INT_MAX;
}
break;
default:
- fprintf(stderr,
- _("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"),
- p);
+ fprintf (
+ stderr,
+ _ ("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"),
+ p);
break;
}
start = p + 1;
state++;
break;
- case '\0': /* found EOL */
+ case '\0': /* found EOL */
keep_looking = 0;
/* fall through to '/' */
- case '/': /* found a definition separator */
+ case '/': /* found a definition separator */
switch (state)
{
- case 4: /* within a log level */
+ case 4: /* within a log level */
p[0] = '\0';
state = 0;
level = get_type ((const char *) start);
- if ( (GNUNET_ERROR_TYPE_INVALID == level) ||
- (GNUNET_ERROR_TYPE_UNSPECIFIED == level) ||
- (0 != add_definition (comp, file, function, from_line, to_line,
- level, force)) )
+ if ((GNUNET_ERROR_TYPE_INVALID == level) ||
+ (GNUNET_ERROR_TYPE_UNSPECIFIED == level) ||
+ (0 != add_definition (comp,
+ file,
+ function,
+ from_line,
+ to_line,
+ level,
+ force)))
{
GNUNET_free (def);
return counter;
@@ -666,9 +670,10 @@ parse_definitions (const char *constname, int force)
start = p + 1;
break;
default:
- fprintf(stderr,
- _("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"),
- p);
+ fprintf (
+ stderr,
+ _ ("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"),
+ p);
break;
}
default:
@@ -688,7 +693,7 @@ parse_all_definitions ()
{
if (GNUNET_NO == gnunet_force_log_parsed)
gnunet_force_log_present =
- parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO;
+ parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO;
gnunet_force_log_parsed = GNUNET_YES;
if (GNUNET_NO == gnunet_log_parsed)
@@ -707,14 +712,12 @@ parse_all_definitions ()
* @return #GNUNET_OK on success
*/
int
-GNUNET_log_setup (const char *comp,
- const char *loglevel,
- const char *logfile)
+GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile)
{
const char *env_logfile;
min_level = get_type (loglevel);
-#if !defined(GNUNET_CULL_LOGGING)
+#if ! defined(GNUNET_CULL_LOGGING)
parse_all_definitions ();
#endif
#ifdef WINDOWS
@@ -761,8 +764,7 @@ GNUNET_log_setup (const char *comp,
* @param logger_cls closure for @a logger
*/
void
-GNUNET_logger_add (GNUNET_Logger logger,
- void *logger_cls)
+GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls)
{
struct CustomLogger *entry;
@@ -781,8 +783,7 @@ GNUNET_logger_add (GNUNET_Logger logger,
* @param logger_cls closure for @a logger
*/
void
-GNUNET_logger_remove (GNUNET_Logger logger,
- void *logger_cls)
+GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls)
{
struct CustomLogger *pos;
struct CustomLogger *prev;
@@ -828,8 +829,7 @@ output_message (enum GNUNET_ErrorType kind,
EnterCriticalSection (&output_message_cs);
#endif
/* only use the standard logger if no custom loggers are present */
- if ( (NULL != GNUNET_stderr) &&
- (NULL == loggers) )
+ if ((NULL != GNUNET_stderr) && (NULL == loggers))
{
if (kind == GNUNET_ERROR_TYPE_MESSAGE)
{
@@ -841,9 +841,7 @@ output_message (enum GNUNET_ErrorType kind,
* this way if the output is going to logfiles or robots
* instead.
*/
- FPRINTF (GNUNET_stderr,
- "* %s",
- msg);
+ FPRINTF (GNUNET_stderr, "* %s", msg);
}
else if (GNUNET_YES == current_async_scope.have_scope)
{
@@ -881,11 +879,7 @@ output_message (enum GNUNET_ErrorType kind,
pos = loggers;
while (NULL != pos)
{
- pos->logger (pos->logger_cls,
- kind,
- comp,
- datestr,
- msg);
+ pos->logger (pos->logger_cls, kind, comp, datestr, msg);
pos = pos->next;
}
#if WINDOWS
@@ -907,8 +901,7 @@ flush_bulk (const char *datestr)
char *last;
const char *ft;
- if ( (0 == last_bulk_time.abs_value_us) ||
- (0 == last_bulk_repeat) )
+ if ((0 == last_bulk_time.abs_value_us) || (0 == last_bulk_repeat))
return;
rev = 0;
last = memchr (last_bulk, '\0', BULK_TRACK_SIZE);
@@ -921,11 +914,17 @@ flush_bulk (const char *datestr)
rev = 1;
last[0] = '\0';
}
- ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
- (last_bulk_time), GNUNET_YES);
- snprintf (msg, sizeof (msg),
- _("Message `%.*s' repeated %u times in the last %s\n"),
- BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft);
+ ft =
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (
+ last_bulk_time),
+ GNUNET_YES);
+ snprintf (msg,
+ sizeof (msg),
+ _ ("Message `%.*s' repeated %u times in the last %s\n"),
+ BULK_TRACK_SIZE,
+ last_bulk,
+ last_bulk_repeat,
+ ft);
if (rev == 1)
last[0] = '\n';
output_message (last_bulk_kind, last_bulk_comp, datestr, msg);
@@ -941,8 +940,7 @@ flush_bulk (const char *datestr)
* @param check_reset #GNUNET_YES to assert that the log skip counter is currently zero
*/
void
-GNUNET_log_skip (int n,
- int check_reset)
+GNUNET_log_skip (int n, int check_reset)
{
int ok;
@@ -993,15 +991,10 @@ mylog (enum GNUNET_ErrorType kind,
va_list vacp;
va_copy (vacp, va);
- size = VSNPRINTF (NULL,
- 0,
- message,
- vacp) + 1;
+ size = VSNPRINTF (NULL, 0, message, vacp) + 1;
GNUNET_assert (0 != size);
va_end (vacp);
- memset (date,
- 0,
- DATE_STR_SIZE);
+ memset (date, 0, DATE_STR_SIZE);
{
char buf[size];
long long offset;
@@ -1022,24 +1015,19 @@ mylog (enum GNUNET_ErrorType kind,
else
{
if (0 ==
- strftime (date2,
- DATE_STR_SIZE,
- "%b %d %H:%M:%S-%%020llu",
- tmptr))
- abort ();
- if (0 >
- snprintf (date,
- sizeof (date),
- date2,
- (long long) (pc.QuadPart /
- (performance_frequency.QuadPart / 1000))))
- abort ();
+ strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr))
+ abort ();
+ if (0 > snprintf (date,
+ sizeof (date),
+ date2,
+ (long long) (pc.QuadPart /
+ (performance_frequency.QuadPart / 1000))))
+ abort ();
}
#else
struct timeval timeofday;
- gettimeofday (&timeofday,
- NULL);
+ gettimeofday (&timeofday, NULL);
offset = GNUNET_TIME_get_offset ();
if (offset > 0)
{
@@ -1047,80 +1035,59 @@ mylog (enum GNUNET_ErrorType kind,
timeofday.tv_usec += (offset % 1000LL) * 1000LL;
if (timeofday.tv_usec > 1000000LL)
{
- timeofday.tv_usec -= 1000000LL;
- timeofday.tv_sec++;
+ timeofday.tv_usec -= 1000000LL;
+ timeofday.tv_sec++;
}
}
else
{
timeofday.tv_sec += offset / 1000LL;
- if (timeofday.tv_usec > - (offset % 1000LL) * 1000LL)
+ if (timeofday.tv_usec > -(offset % 1000LL) * 1000LL)
{
- timeofday.tv_usec += (offset % 1000LL) * 1000LL;
+ timeofday.tv_usec += (offset % 1000LL) * 1000LL;
}
else
{
- timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL;
- timeofday.tv_sec--;
+ timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL;
+ timeofday.tv_sec--;
}
}
tmptr = localtime (&timeofday.tv_sec);
if (NULL == tmptr)
{
- strcpy (date,
- "localtime error");
+ strcpy (date, "localtime error");
}
else
{
- if (0 ==
- strftime (date2,
- DATE_STR_SIZE,
- "%b %d %H:%M:%S-%%06u",
- tmptr))
- abort ();
- if (0 >
- snprintf (date,
- sizeof (date),
- date2,
- timeofday.tv_usec))
- abort ();
+ if (0 == strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr))
+ abort ();
+ if (0 > snprintf (date, sizeof (date), date2, timeofday.tv_usec))
+ abort ();
}
#endif
- VSNPRINTF (buf,
- size,
- message,
- va);
+ VSNPRINTF (buf, size, message, va);
#if ! (defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY)
if (NULL != tmptr)
(void) setup_log_file (tmptr);
#endif
if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) &&
(0 != last_bulk_time.abs_value_us) &&
- (0 == strncmp (buf,
- last_bulk,
- sizeof (last_bulk))))
+ (0 == strncmp (buf, last_bulk, sizeof (last_bulk))))
{
last_bulk_repeat++;
- if ( (GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value_us >
- BULK_DELAY_THRESHOLD) ||
- (last_bulk_repeat > BULK_REPEAT_THRESHOLD) )
+ if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value_us >
+ BULK_DELAY_THRESHOLD) ||
+ (last_bulk_repeat > BULK_REPEAT_THRESHOLD))
flush_bulk (date);
return;
}
flush_bulk (date);
- strncpy (last_bulk,
- buf,
- sizeof (last_bulk));
+ strncpy (last_bulk, buf, sizeof (last_bulk));
last_bulk_repeat = 0;
last_bulk_kind = kind;
last_bulk_time = GNUNET_TIME_absolute_get ();
- strncpy (last_bulk_comp,
- comp,
- COMP_TRACK_SIZE);
- output_message (kind,
- comp,
- date,
- buf);
+ strncpy (last_bulk_comp, comp, COMP_TRACK_SIZE);
+ output_message (kind, comp, date, buf);
}
}
@@ -1133,8 +1100,7 @@ mylog (enum GNUNET_ErrorType kind,
* @param ... arguments for format string
*/
void
-GNUNET_log_nocheck (enum GNUNET_ErrorType kind,
- const char *message, ...)
+GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
{
va_list va;
@@ -1154,8 +1120,10 @@ GNUNET_log_nocheck (enum GNUNET_ErrorType kind,
* @param ... arguments for format string
*/
void
-GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
- const char *message, ...)
+GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
+ const char *comp,
+ const char *message,
+ ...)
{
va_list va;
char comp_w_pid[128];
@@ -1180,18 +1148,18 @@ const char *
GNUNET_error_type_to_string (enum GNUNET_ErrorType kind)
{
if ((kind & GNUNET_ERROR_TYPE_ERROR) > 0)
- return _("ERROR");
+ return _ ("ERROR");
if ((kind & GNUNET_ERROR_TYPE_WARNING) > 0)
- return _("WARNING");
+ return _ ("WARNING");
if ((kind & GNUNET_ERROR_TYPE_MESSAGE) > 0)
- return _("MESSAGE");
+ return _ ("MESSAGE");
if ((kind & GNUNET_ERROR_TYPE_INFO) > 0)
- return _("INFO");
+ return _ ("INFO");
if ((kind & GNUNET_ERROR_TYPE_DEBUG) > 0)
- return _("DEBUG");
+ return _ ("DEBUG");
if ((kind & ~GNUNET_ERROR_TYPE_BULK) == 0)
- return _("NONE");
- return _("INVALID");
+ return _ ("NONE");
+ return _ ("INVALID");
}
@@ -1202,7 +1170,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind)
* @return string form; will be overwritten by next call to GNUNET_h2s.
*/
const char *
-GNUNET_h2s (const struct GNUNET_HashCode * hc)
+GNUNET_h2s (const struct GNUNET_HashCode *hc)
{
static GNUNET_THREAD_LOCAL struct GNUNET_CRYPTO_HashAsciiEncoded ret;
@@ -1223,7 +1191,7 @@ GNUNET_h2s (const struct GNUNET_HashCode * hc)
* @return string form; will be overwritten by next call to GNUNET_h2s.
*/
const char *
-GNUNET_h2s2 (const struct GNUNET_HashCode * hc)
+GNUNET_h2s2 (const struct GNUNET_HashCode *hc)
{
static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
@@ -1248,11 +1216,8 @@ GNUNET_p2s (const struct GNUNET_CRYPTO_EddsaPublicKey *p)
static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
struct GNUNET_HashCode hc;
- GNUNET_CRYPTO_hash (p,
- sizeof (*p),
- &hc);
- GNUNET_CRYPTO_hash_to_enc (&hc,
- &ret);
+ GNUNET_CRYPTO_hash (p, sizeof (*p), &hc);
+ GNUNET_CRYPTO_hash_to_enc (&hc, &ret);
ret.encoding[6] = '\0';
return (const char *) ret.encoding;
}
@@ -1273,11 +1238,8 @@ GNUNET_p2s2 (const struct GNUNET_CRYPTO_EddsaPublicKey *p)
static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
struct GNUNET_HashCode hc;
- GNUNET_CRYPTO_hash (p,
- sizeof (*p),
- &hc);
- GNUNET_CRYPTO_hash_to_enc (&hc,
- &ret);
+ GNUNET_CRYPTO_hash (p, sizeof (*p), &hc);
+ GNUNET_CRYPTO_hash_to_enc (&hc, &ret);
ret.encoding[6] = '\0';
return (const char *) ret.encoding;
}
@@ -1298,11 +1260,8 @@ GNUNET_e2s (const struct GNUNET_CRYPTO_EcdhePublicKey *p)
static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
struct GNUNET_HashCode hc;
- GNUNET_CRYPTO_hash (p,
- sizeof (*p),
- &hc);
- GNUNET_CRYPTO_hash_to_enc (&hc,
- &ret);
+ GNUNET_CRYPTO_hash (p, sizeof (*p), &hc);
+ GNUNET_CRYPTO_hash_to_enc (&hc, &ret);
ret.encoding[6] = '\0';
return (const char *) ret.encoding;
}
@@ -1323,11 +1282,8 @@ GNUNET_e2s2 (const struct GNUNET_CRYPTO_EcdhePublicKey *p)
static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
struct GNUNET_HashCode hc;
- GNUNET_CRYPTO_hash (p,
- sizeof (*p),
- &hc);
- GNUNET_CRYPTO_hash_to_enc (&hc,
- &ret);
+ GNUNET_CRYPTO_hash (p, sizeof (*p), &hc);
+ GNUNET_CRYPTO_hash_to_enc (&hc, &ret);
ret.encoding[6] = '\0';
return (const char *) ret.encoding;
}
@@ -1347,10 +1303,27 @@ GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc)
{
static char buf[64];
- GNUNET_STRINGS_data_to_string (shc,
- sizeof (*shc),
- buf,
- sizeof (buf));
+ GNUNET_STRINGS_data_to_string (shc, sizeof (*shc), buf, sizeof (buf));
+ buf[6] = '\0';
+ return (const char *) buf;
+}
+
+
+/**
+ * @ingroup logging
+ * Convert a UUID to a string (for printing debug messages).
+ * This is one of the very few calls in the entire API that is
+ * NOT reentrant!
+ *
+ * @param uuid the UUID
+ * @return string
+ */
+const char *
+GNUNET_uuid2s (const struct GNUNET_Uuid *uuid)
+{
+ static char buf[32];
+
+ GNUNET_STRINGS_data_to_string (uuid, sizeof (*uuid), buf, sizeof (buf));
buf[6] = '\0';
return (const char *) buf;
}
@@ -1365,7 +1338,7 @@ GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc)
* @return string form; will be overwritten by next call to GNUNET_h2s_full.
*/
const char *
-GNUNET_h2s_full (const struct GNUNET_HashCode * hc)
+GNUNET_h2s_full (const struct GNUNET_HashCode *hc)
{
static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
@@ -1391,9 +1364,7 @@ GNUNET_i2s (const struct GNUNET_PeerIdentity *pid)
if (NULL == pid)
return "NULL";
ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key);
- strncpy (buf,
- ret,
- sizeof (buf) - 1);
+ strncpy (buf, ret, sizeof (buf) - 1);
GNUNET_free (ret);
buf[4] = '\0';
return buf;
@@ -1419,9 +1390,7 @@ GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid)
if (NULL == pid)
return "NULL";
ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key);
- strncpy (buf,
- ret,
- sizeof (buf) - 1);
+ strncpy (buf, ret, sizeof (buf) - 1);
GNUNET_free (ret);
buf[4] = '\0';
return buf;
@@ -1459,12 +1428,12 @@ GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid)
* will be overwritten by next call to #GNUNET_a2s.
*/
const char *
-GNUNET_a2s (const struct sockaddr *addr,
- socklen_t addrlen)
+GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen)
{
#ifndef WINDOWS
-#define LEN GNUNET_MAX ((INET6_ADDRSTRLEN + 8), \
- (1 + sizeof (struct sockaddr_un) - sizeof (sa_family_t)))
+#define LEN \
+ GNUNET_MAX ((INET6_ADDRSTRLEN + 8), \
+ (1 + sizeof (struct sockaddr_un) - sizeof (sa_family_t)))
#else
#define LEN (INET6_ADDRSTRLEN + 8)
#endif
@@ -1477,24 +1446,18 @@ GNUNET_a2s (const struct sockaddr *addr,
unsigned int off;
if (addr == NULL)
- return _("unknown address");
+ return _ ("unknown address");
switch (addr->sa_family)
{
case AF_INET:
if (addrlen != sizeof (struct sockaddr_in))
return "<invalid v4 address>";
v4 = (const struct sockaddr_in *) addr;
- inet_ntop (AF_INET,
- &v4->sin_addr,
- buf,
- INET_ADDRSTRLEN);
+ inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
if (0 == ntohs (v4->sin_port))
return buf;
strcat (buf, ":");
- GNUNET_snprintf (b2,
- sizeof (b2),
- "%u",
- ntohs (v4->sin_port));
+ GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port));
strcat (buf, b2);
return buf;
case AF_INET6:
@@ -1502,19 +1465,12 @@ GNUNET_a2s (const struct sockaddr *addr,
return "<invalid v4 address>";
v6 = (const struct sockaddr_in6 *) addr;
buf[0] = '[';
- inet_ntop (AF_INET6,
- &v6->sin6_addr,
- &buf[1],
- INET6_ADDRSTRLEN);
+ inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
if (0 == ntohs (v6->sin6_port))
return &buf[1];
strcat (buf, "]:");
- GNUNET_snprintf (b2,
- sizeof (b2),
- "%u",
- ntohs (v6->sin6_port));
- strcat (buf,
- b2);
+ GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port));
+ strcat (buf, b2);
return buf;
case AF_UNIX:
if (addrlen <= sizeof (sa_family_t))
@@ -1532,7 +1488,7 @@ GNUNET_a2s (const struct sockaddr *addr,
&un->sun_path[off]);
return buf;
default:
- return _("invalid address");
+ return _ ("invalid address");
}
}
@@ -1546,13 +1502,14 @@ GNUNET_a2s (const struct sockaddr *addr,
*/
void
GNUNET_log_config_missing (enum GNUNET_ErrorType kind,
- const char *section,
- const char *option)
+ const char *section,
+ const char *option)
{
GNUNET_log (kind,
- _("Configuration fails to specify option `%s' in section `%s'!\n"),
- option,
- section);
+ _ (
+ "Configuration fails to specify option `%s' in section `%s'!\n"),
+ option,
+ section);
}
@@ -1566,13 +1523,17 @@ GNUNET_log_config_missing (enum GNUNET_ErrorType kind,
*/
void
GNUNET_log_config_invalid (enum GNUNET_ErrorType kind,
- const char *section,
- const char *option,
- const char *required)
+ const char *section,
+ const char *option,
+ const char *required)
{
- GNUNET_log (kind,
- _("Configuration specifies invalid value for option `%s' in section `%s': %s\n"),
- option, section, required);
+ GNUNET_log (
+ kind,
+ _ (
+ "Configuration specifies invalid value for option `%s' in section `%s': %s\n"),
+ option,
+ section,
+ required);
}
@@ -1633,15 +1594,14 @@ GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret)
/**
* Initializer
*/
-void __attribute__ ((constructor))
-GNUNET_util_cl_init ()
+void __attribute__ ((constructor)) GNUNET_util_cl_init ()
{
GNUNET_stderr = stderr;
#ifdef MINGW
GNInitWinEnv (NULL);
#endif
#if WINDOWS
- if (!InitializeCriticalSectionAndSpinCount (&output_message_cs, 0x00000400))
+ if (! InitializeCriticalSectionAndSpinCount (&output_message_cs, 0x00000400))
GNUNET_abort_ ();
#endif
}
@@ -1650,8 +1610,7 @@ GNUNET_util_cl_init ()
/**
* Destructor
*/
-void __attribute__ ((destructor))
-GNUNET_util_cl_fini ()
+void __attribute__ ((destructor)) GNUNET_util_cl_fini ()
{
#if WINDOWS
DeleteCriticalSection (&output_message_cs);
diff --git a/src/util/container_multiuuidmap.c b/src/util/container_multiuuidmap.c
new file mode 100644
index 000000000..49eb64cfe
--- /dev/null
+++ b/src/util/container_multiuuidmap.c
@@ -0,0 +1,1015 @@
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2008, 2012 GNUnet e.V.
+
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ 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/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+*/
+/**
+ * @file util/container_multiuuidmap.c
+ * @brief hash map for UUIDs where the same key may be present multiple times
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "util-container-multiuuidmap", __VA_ARGS__)
+
+/**
+ * Maximum recursion depth for callbacks of
+ * #GNUNET_CONTAINER_multihashmap_get_multiple() themselve s
+ * again calling #GNUNET_CONTAINER_multihashmap_get_multiple().
+ * Should be totally excessive, but if violated we die.
+ */
+#define NEXT_CACHE_SIZE 16
+
+
+/**
+ * An entry in the hash map with the full key.
+ */
+struct BigMapEntry
+{
+
+ /**
+ * Value of the entry.
+ */
+ void *value;
+
+ /**
+ * If there is a hash collision, we create a linked list.
+ */
+ struct BigMapEntry *next;
+
+ /**
+ * Key for the entry.
+ */
+ struct GNUNET_Uuid key;
+};
+
+
+/**
+ * An entry in the hash map with just a pointer to the key.
+ */
+struct SmallMapEntry
+{
+
+ /**
+ * Value of the entry.
+ */
+ void *value;
+
+ /**
+ * If there is a hash collision, we create a linked list.
+ */
+ struct SmallMapEntry *next;
+
+ /**
+ * Key for the entry.
+ */
+ const struct GNUNET_Uuid *key;
+};
+
+
+/**
+ * Entry in the map.
+ */
+union MapEntry
+{
+ /**
+ * Variant used if map entries only contain a pointer to the key.
+ */
+ struct SmallMapEntry *sme;
+
+ /**
+ * Variant used if map entries contain the full key.
+ */
+ struct BigMapEntry *bme;
+};
+
+
+/**
+ * Internal representation of the hash map.
+ */
+struct GNUNET_CONTAINER_MultiUuidmap
+{
+ /**
+ * All of our buckets.
+ */
+ union MapEntry *map;
+
+ /**
+ * Number of entries in the map.
+ */
+ unsigned int size;
+
+ /**
+ * Length of the "map" array.
+ */
+ unsigned int map_length;
+
+ /**
+ * #GNUNET_NO if the map entries are of type 'struct BigMapEntry',
+ * #GNUNET_YES if the map entries are of type 'struct SmallMapEntry'.
+ */
+ int use_small_entries;
+
+ /**
+ * Counts the destructive modifications (grow, remove)
+ * to the map, so that iterators can check if they are still valid.
+ */
+ unsigned int modification_counter;
+
+ /**
+ * Map entries indicating iteration positions currently
+ * in use by #GNUNET_CONTAINER_multihashmap_get_multiple().
+ * Only used up to @e next_cache_off.
+ */
+ union MapEntry next_cache[NEXT_CACHE_SIZE];
+
+ /**
+ * Offset of @e next_cache entries in use, must be smaller
+ * than #NEXT_CACHE_SIZE.
+ */
+ unsigned int next_cache_off;
+};
+
+
+/**
+ * Cursor into a multiuuidmap.
+ * Allows to enumerate elements asynchronously.
+ */
+struct GNUNET_CONTAINER_MultiUuidmapIterator
+{
+ /**
+ * Position in the bucket 'idx'
+ */
+ union MapEntry me;
+
+ /**
+ * Current bucket index.
+ */
+ unsigned int idx;
+
+ /**
+ * Modification counter as observed on the map when the iterator
+ * was created.
+ */
+ unsigned int modification_counter;
+
+ /**
+ * Map that we are iterating over.
+ */
+ const struct GNUNET_CONTAINER_MultiUuidmap *map;
+};
+
+
+/**
+ * Create a multi hash map.
+ *
+ * @param len initial size (map will grow as needed)
+ * @param do_not_copy_keys #GNUNET_NO is always safe and should be used by default;
+ * #GNUNET_YES means that on 'put', the 'key' does not have
+ * to be copied as the destination of the pointer is
+ * guaranteed to be life as long as the value is stored in
+ * the hashmap. This can significantly reduce memory
+ * consumption, but of course is also a recipie for
+ * heap corruption if the assumption is not true. Only
+ * use this if (1) memory use is important in this case and
+ * (2) you have triple-checked that the invariant holds
+ * @return NULL on error
+ */
+struct GNUNET_CONTAINER_MultiUuidmap *
+GNUNET_CONTAINER_multiuuidmap_create (unsigned int len, int do_not_copy_keys)
+{
+ struct GNUNET_CONTAINER_MultiUuidmap *map;
+
+ GNUNET_assert (len > 0);
+ map = GNUNET_new (struct GNUNET_CONTAINER_MultiUuidmap);
+ map->map = GNUNET_malloc_large (len * sizeof (union MapEntry));
+ if (NULL == map->map)
+ {
+ GNUNET_free (map);
+ return NULL;
+ }
+ map->map_length = len;
+ map->use_small_entries = do_not_copy_keys;
+ return map;
+}
+
+
+/**
+ * Destroy a hash map. Will not free any values
+ * stored in the hash map!
+ *
+ * @param map the map
+ */
+void
+GNUNET_CONTAINER_multiuuidmap_destroy (
+ struct GNUNET_CONTAINER_MultiUuidmap *map)
+{
+ GNUNET_assert (0 == map->next_cache_off);
+ for (unsigned int i = 0; i < map->map_length; i++)
+ {
+ union MapEntry me;
+
+ me = map->map[i];
+ if (map->use_small_entries)
+ {
+ struct SmallMapEntry *sme;
+ struct SmallMapEntry *nxt;
+
+ nxt = me.sme;
+ while (NULL != (sme = nxt))
+ {
+ nxt = sme->next;
+ GNUNET_free (sme);
+ }
+ me.sme = NULL;
+ }
+ else
+ {
+ struct BigMapEntry *bme;
+ struct BigMapEntry *nxt;
+
+ nxt = me.bme;
+ while (NULL != (bme = nxt))
+ {
+ nxt = bme->next;
+ GNUNET_free (bme);
+ }
+ me.bme = NULL;
+ }
+ }
+ GNUNET_free (map->map);
+ GNUNET_free (map);
+}
+
+
+/**
+ * Compute the index of the bucket for the given key.
+ *
+ * @param map hash map for which to compute the index
+ * @param key what key should the index be computed for
+ * @return offset into the "map" array of "map"
+ */
+static unsigned int
+idx_of (const struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key)
+{
+ unsigned int kx;
+
+ GNUNET_assert (NULL != map);
+ GNUNET_memcpy (&kx, key, sizeof (kx));
+ return kx % map->map_length;
+}
+
+
+/**
+ * Get the number of key-value pairs in the map.
+ *
+ * @param map the map
+ * @return the number of key value pairs
+ */
+unsigned int
+GNUNET_CONTAINER_multiuuidmap_size (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map)
+{
+ return map->size;
+}
+
+
+/**
+ * Given a key find a value in the map matching the key.
+ *
+ * @param map the map
+ * @param key what to look for
+ * @return NULL if no value was found; note that
+ * this is indistinguishable from values that just
+ * happen to be NULL; use "contains" to test for
+ * key-value pairs with value NULL
+ */
+void *
+GNUNET_CONTAINER_multiuuidmap_get (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key)
+{
+ union MapEntry me;
+
+ me = map->map[idx_of (map, key)];
+ if (map->use_small_entries)
+ {
+ for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
+ if (0 == GNUNET_memcmp (key, sme->key))
+ return sme->value;
+ }
+ else
+ {
+ for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ return bme->value;
+ }
+ return NULL;
+}
+
+
+/**
+ * Iterate over all entries in the map.
+ *
+ * @param map the map
+ * @param it function to call on each entry
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed,
+ * #GNUNET_SYSERR if it aborted iteration
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_iterate (
+ struct GNUNET_CONTAINER_MultiUuidmap *map,
+ GNUNET_CONTAINER_MultiUuidmapIterator it,
+ void *it_cls)
+{
+ int count;
+ union MapEntry me;
+ union MapEntry *ce;
+ struct GNUNET_Uuid kc;
+
+ count = 0;
+ GNUNET_assert (NULL != map);
+ ce = &map->next_cache[map->next_cache_off];
+ GNUNET_assert (++map->next_cache_off < NEXT_CACHE_SIZE);
+ for (unsigned int i = 0; i < map->map_length; i++)
+ {
+ me = map->map[i];
+ if (map->use_small_entries)
+ {
+ struct SmallMapEntry *sme;
+
+ ce->sme = me.sme;
+ while (NULL != (sme = ce->sme))
+ {
+ ce->sme = sme->next;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, sme->key, sme->value)))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ count++;
+ }
+ }
+ else
+ {
+ struct BigMapEntry *bme;
+
+ ce->bme = me.bme;
+ while (NULL != (bme = ce->bme))
+ {
+ ce->bme = bme->next;
+ if (NULL != it)
+ {
+ kc = bme->key;
+ if (GNUNET_OK != it (it_cls, &kc, bme->value))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ }
+ count++;
+ }
+ }
+ }
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return count;
+}
+
+
+/**
+ * We are about to free() the @a bme, make sure it is not in
+ * the list of next values for any iterator in the @a map's next_cache.
+ *
+ * @param map the map to check
+ * @param bme the entry that is about to be free'd
+ */
+static void
+update_next_cache_bme (struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct BigMapEntry *bme)
+{
+ for (unsigned int i = 0; i < map->next_cache_off; i++)
+ if (map->next_cache[i].bme == bme)
+ map->next_cache[i].bme = bme->next;
+}
+
+
+/**
+ * We are about to free() the @a sme, make sure it is not in
+ * the list of next values for any iterator in the @a map's next_cache.
+ *
+ * @param map the map to check
+ * @param sme the entry that is about to be free'd
+ */
+static void
+update_next_cache_sme (struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct SmallMapEntry *sme)
+{
+ for (unsigned int i = 0; i < map->next_cache_off; i++)
+ if (map->next_cache[i].sme == sme)
+ map->next_cache[i].sme = sme->next;
+}
+
+
+/**
+ * Remove the given key-value pair from the map. Note that if the
+ * key-value pair is in the map multiple times, only one of the pairs
+ * will be removed.
+ *
+ * @param map the map
+ * @param key key of the key-value pair
+ * @param value value of the key-value pair
+ * @return #GNUNET_YES on success, #GNUNET_NO if the key-value pair
+ * is not in the map
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_remove (struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key,
+ const void *value)
+{
+ union MapEntry me;
+ unsigned int i;
+
+ map->modification_counter++;
+ i = idx_of (map, key);
+ me = map->map[i];
+ if (map->use_small_entries)
+ {
+ struct SmallMapEntry *p = NULL;
+
+ for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
+ {
+ if ((0 == GNUNET_memcmp (key, sme->key)) && (value == sme->value))
+ {
+ if (NULL == p)
+ map->map[i].sme = sme->next;
+ else
+ p->next = sme->next;
+ update_next_cache_sme (map, sme);
+ GNUNET_free (sme);
+ map->size--;
+ return GNUNET_YES;
+ }
+ p = sme;
+ }
+ }
+ else
+ {
+ struct BigMapEntry *p = NULL;
+
+ for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
+ {
+ if ((0 == GNUNET_memcmp (key, &bme->key)) && (value == bme->value))
+ {
+ if (NULL == p)
+ map->map[i].bme = bme->next;
+ else
+ p->next = bme->next;
+ update_next_cache_bme (map, bme);
+ GNUNET_free (bme);
+ map->size--;
+ return GNUNET_YES;
+ }
+ p = bme;
+ }
+ }
+ return GNUNET_NO;
+}
+
+
+/**
+ * Remove all entries for the given key from the map.
+ * Note that the values would not be "freed".
+ *
+ * @param map the map
+ * @param key identifies values to be removed
+ * @return number of values removed
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_remove_all (
+ struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key)
+{
+ union MapEntry me;
+ unsigned int i;
+ int ret;
+
+ map->modification_counter++;
+
+ ret = 0;
+ i = idx_of (map, key);
+ me = map->map[i];
+ if (map->use_small_entries)
+ {
+ struct SmallMapEntry *sme;
+ struct SmallMapEntry *p;
+
+ p = NULL;
+ sme = me.sme;
+ while (NULL != sme)
+ {
+ if (0 == GNUNET_memcmp (key, sme->key))
+ {
+ if (NULL == p)
+ map->map[i].sme = sme->next;
+ else
+ p->next = sme->next;
+ update_next_cache_sme (map, sme);
+ GNUNET_free (sme);
+ map->size--;
+ if (NULL == p)
+ sme = map->map[i].sme;
+ else
+ sme = p->next;
+ ret++;
+ }
+ else
+ {
+ p = sme;
+ sme = sme->next;
+ }
+ }
+ }
+ else
+ {
+ struct BigMapEntry *bme;
+ struct BigMapEntry *p;
+
+ p = NULL;
+ bme = me.bme;
+ while (NULL != bme)
+ {
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ {
+ if (NULL == p)
+ map->map[i].bme = bme->next;
+ else
+ p->next = bme->next;
+ update_next_cache_bme (map, bme);
+ GNUNET_free (bme);
+ map->size--;
+ if (NULL == p)
+ bme = map->map[i].bme;
+ else
+ bme = p->next;
+ ret++;
+ }
+ else
+ {
+ p = bme;
+ bme = bme->next;
+ }
+ }
+ }
+ return ret;
+}
+
+
+/**
+ * Check if the map contains any value under the given
+ * key (including values that are NULL).
+ *
+ * @param map the map
+ * @param key the key to test if a value exists for it
+ * @return #GNUNET_YES if such a value exists,
+ * #GNUNET_NO if not
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_contains (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key)
+{
+ union MapEntry me;
+
+ me = map->map[idx_of (map, key)];
+ if (map->use_small_entries)
+ {
+ for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
+ if (0 == GNUNET_memcmp (key, sme->key))
+ return GNUNET_YES;
+ }
+ else
+ {
+ for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ return GNUNET_YES;
+ }
+ return GNUNET_NO;
+}
+
+
+/**
+ * Check if the map contains the given value under the given
+ * key.
+ *
+ * @param map the map
+ * @param key the key to test if a value exists for it
+ * @param value value to test for
+ * @return #GNUNET_YES if such a value exists,
+ * #GNUNET_NO if not
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_contains_value (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key,
+ const void *value)
+{
+ union MapEntry me;
+
+ me = map->map[idx_of (map, key)];
+ if (map->use_small_entries)
+ {
+ for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
+ if ((0 == GNUNET_memcmp (key, sme->key)) && (sme->value == value))
+ return GNUNET_YES;
+ }
+ else
+ {
+ for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
+ if ((0 == GNUNET_memcmp (key, &bme->key)) && (bme->value == value))
+ return GNUNET_YES;
+ }
+ return GNUNET_NO;
+}
+
+
+/**
+ * Grow the given map to a more appropriate size.
+ *
+ * @param map the hash map to grow
+ */
+static void
+grow (struct GNUNET_CONTAINER_MultiUuidmap *map)
+{
+ union MapEntry *old_map;
+ union MapEntry *new_map;
+ unsigned int old_len;
+ unsigned int new_len;
+ unsigned int idx;
+
+ old_map = map->map;
+ old_len = map->map_length;
+ new_len = old_len * 2;
+ if (0 == new_len) /* 2^31 * 2 == 0 */
+ new_len = old_len; /* never use 0 */
+ if (new_len == old_len)
+ return; /* nothing changed */
+ new_map = GNUNET_malloc_large (new_len * sizeof (union MapEntry));
+ if (NULL == new_map)
+ return; /* grow not possible */
+ map->modification_counter++;
+ map->map_length = new_len;
+ map->map = new_map;
+ for (unsigned int i = 0; i < old_len; i++)
+ {
+ if (map->use_small_entries)
+ {
+ struct SmallMapEntry *sme;
+
+ while (NULL != (sme = old_map[i].sme))
+ {
+ old_map[i].sme = sme->next;
+ idx = idx_of (map, sme->key);
+ sme->next = new_map[idx].sme;
+ new_map[idx].sme = sme;
+ }
+ }
+ else
+ {
+ struct BigMapEntry *bme;
+
+ while (NULL != (bme = old_map[i].bme))
+ {
+ old_map[i].bme = bme->next;
+ idx = idx_of (map, &bme->key);
+ bme->next = new_map[idx].bme;
+ new_map[idx].bme = bme;
+ }
+ }
+ }
+ GNUNET_free (old_map);
+}
+
+
+/**
+ * Store a key-value pair in the map.
+ *
+ * @param map the map
+ * @param key key to use
+ * @param value value to use
+ * @param opt options for put
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO if a value was replaced (with REPLACE)
+ * #GNUNET_SYSERR if #GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY was the option and the
+ * value already exists
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_put (struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key,
+ void *value,
+ enum GNUNET_CONTAINER_MultiHashMapOption opt)
+{
+ union MapEntry me;
+ unsigned int i;
+
+ i = idx_of (map, key);
+ if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) &&
+ (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
+ {
+ me = map->map[i];
+ if (map->use_small_entries)
+ {
+ for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
+ if (0 == GNUNET_memcmp (key, sme->key))
+ {
+ if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ return GNUNET_SYSERR;
+ sme->value = value;
+ return GNUNET_NO;
+ }
+ }
+ else
+ {
+ for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
+ if (0 == GNUNET_memcmp (key, &bme->key))
+ {
+ if (opt == GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
+ return GNUNET_SYSERR;
+ bme->value = value;
+ return GNUNET_NO;
+ }
+ }
+ }
+ if (map->size / 3 >= map->map_length / 4)
+ {
+ grow (map);
+ i = idx_of (map, key);
+ }
+ if (map->use_small_entries)
+ {
+ struct SmallMapEntry *sme;
+
+ sme = GNUNET_new (struct SmallMapEntry);
+ sme->key = key;
+ sme->value = value;
+ sme->next = map->map[i].sme;
+ map->map[i].sme = sme;
+ }
+ else
+ {
+ struct BigMapEntry *bme;
+
+ bme = GNUNET_new (struct BigMapEntry);
+ bme->key = *key;
+ bme->value = value;
+ bme->next = map->map[i].bme;
+ map->map[i].bme = bme;
+ }
+ map->size++;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Iterate over all entries in the map that match a particular key.
+ *
+ * @param map the map
+ * @param key key that the entries must correspond to
+ * @param it function to call on each entry
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed,
+ * #GNUNET_SYSERR if it aborted iteration
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_get_multiple (
+ struct GNUNET_CONTAINER_MultiUuidmap *map,
+ const struct GNUNET_Uuid *key,
+ GNUNET_CONTAINER_MultiUuidmapIterator it,
+ void *it_cls)
+{
+ int count;
+ union MapEntry me;
+ union MapEntry *ce;
+
+ ce = &map->next_cache[map->next_cache_off];
+ GNUNET_assert (++map->next_cache_off < NEXT_CACHE_SIZE);
+ count = 0;
+ me = map->map[idx_of (map, key)];
+ if (map->use_small_entries)
+ {
+ struct SmallMapEntry *sme;
+
+ ce->sme = me.sme;
+ while (NULL != (sme = ce->sme))
+ {
+ ce->sme = sme->next;
+ if (0 != GNUNET_memcmp (key, sme->key))
+ continue;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, key, sme->value)))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ count++;
+ }
+ }
+ else
+ {
+ struct BigMapEntry *bme;
+
+ ce->bme = me.bme;
+ while (NULL != (bme = ce->bme))
+ {
+ ce->bme = bme->next;
+ if (0 != GNUNET_memcmp (key, &bme->key))
+ continue;
+ if ((NULL != it) && (GNUNET_OK != it (it_cls, key, bme->value)))
+ {
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return GNUNET_SYSERR;
+ }
+ count++;
+ }
+ }
+ GNUNET_assert (--map->next_cache_off < NEXT_CACHE_SIZE);
+ return count;
+}
+
+
+/**
+ * @ingroup hashmap
+ * Call @a it on a random value from the map, or not at all
+ * if the map is empty. Note that this function has linear
+ * complexity (in the size of the map).
+ *
+ * @param map the map
+ * @param it function to call on a random entry
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed, zero or one.
+ */
+unsigned int
+GNUNET_CONTAINER_multiuuidmap_get_random (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map,
+ GNUNET_CONTAINER_MultiUuidmapIterator it,
+ void *it_cls)
+{
+ unsigned int off;
+ union MapEntry me;
+
+ if (0 == map->size)
+ return 0;
+ if (NULL == it)
+ return 1;
+ off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, map->size);
+ for (unsigned int idx = 0; idx < map->map_length; idx++)
+ {
+ me = map->map[idx];
+ if (map->use_small_entries)
+ {
+ for (struct SmallMapEntry *sme = me.sme; NULL != sme; sme = sme->next)
+ {
+ if (0 == off)
+ {
+ if (GNUNET_OK != it (it_cls, sme->key, sme->value))
+ return GNUNET_SYSERR;
+ return 1;
+ }
+ off--;
+ }
+ }
+ else
+ {
+ for (struct BigMapEntry *bme = me.bme; NULL != bme; bme = bme->next)
+ {
+ if (0 == off)
+ {
+ if (GNUNET_OK != it (it_cls, &bme->key, bme->value))
+ return GNUNET_SYSERR;
+ return 1;
+ }
+ off--;
+ }
+ }
+ }
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Create an iterator for a multiuuidmap.
+ * The iterator can be used to retrieve all the elements in the multiuuidmap
+ * one by one, without having to handle all elements at once (in contrast to
+ * #GNUNET_CONTAINER_multiuuidmap_iterate). Note that the iterator can not be
+ * used anymore if elements have been removed from 'map' after the creation of
+ * the iterator, or 'map' has been destroyed. Adding elements to 'map' may
+ * result in skipped or repeated elements.
+ *
+ * @param map the map to create an iterator for
+ * @return an iterator over the given multiuuidmap 'map'
+ */
+struct GNUNET_CONTAINER_MultiUuidmapIterator *
+GNUNET_CONTAINER_multiuuidmap_iterator_create (
+ const struct GNUNET_CONTAINER_MultiUuidmap *map)
+{
+ struct GNUNET_CONTAINER_MultiUuidmapIterator *iter;
+
+ iter = GNUNET_new (struct GNUNET_CONTAINER_MultiUuidmapIterator);
+ iter->map = map;
+ iter->modification_counter = map->modification_counter;
+ iter->me = map->map[0];
+ return iter;
+}
+
+
+/**
+ * Retrieve the next element from the hash map at the iterator's position.
+ * If there are no elements left, GNUNET_NO is returned, and 'key' and 'value'
+ * are not modified.
+ * This operation is only allowed if no elements have been removed from the
+ * multiuuidmap since the creation of 'iter', and the map has not been destroyed.
+ * Adding elements may result in repeating or skipping elements.
+ *
+ * @param iter the iterator to get the next element from
+ * @param key pointer to store the key in, can be NULL
+ * @param value pointer to store the value in, can be NULL
+ * @return #GNUNET_YES we returned an element,
+ * #GNUNET_NO if we are out of elements
+ */
+int
+GNUNET_CONTAINER_multiuuidmap_iterator_next (
+ struct GNUNET_CONTAINER_MultiUuidmapIterator *iter,
+ struct GNUNET_Uuid *key,
+ const void **value)
+{
+ /* make sure the map has not been modified */
+ GNUNET_assert (iter->modification_counter == iter->map->modification_counter);
+
+ /* look for the next entry, skipping empty buckets */
+ while (1)
+ {
+ if (iter->idx >= iter->map->map_length)
+ return GNUNET_NO;
+ if (GNUNET_YES == iter->map->use_small_entries)
+ {
+ if (NULL != iter->me.sme)
+ {
+ if (NULL != key)
+ *key = *iter->me.sme->key;
+ if (NULL != value)
+ *value = iter->me.sme->value;
+ iter->me.sme = iter->me.sme->next;
+ return GNUNET_YES;
+ }
+ }
+ else
+ {
+ if (NULL != iter->me.bme)
+ {
+ if (NULL != key)
+ *key = iter->me.bme->key;
+ if (NULL != value)
+ *value = iter->me.bme->value;
+ iter->me.bme = iter->me.bme->next;
+ return GNUNET_YES;
+ }
+ }
+ iter->idx += 1;
+ if (iter->idx < iter->map->map_length)
+ iter->me = iter->map->map[iter->idx];
+ }
+}
+
+
+/**
+ * Destroy a multiuuidmap iterator.
+ *
+ * @param iter the iterator to destroy
+ */
+void
+GNUNET_CONTAINER_multiuuidmap_iterator_destroy (
+ struct GNUNET_CONTAINER_MultiUuidmapIterator *iter)
+{
+ GNUNET_free (iter);
+}
+
+
+/* end of container_multiuuidmap.c */
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 8bb5f0587..71eaab87a 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -28,22 +28,23 @@
#include "gnunet_crypto_lib.h"
#include <gcrypt.h>
-#define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-random", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-crypto-random", syscall)
/* TODO: ndurner, move this to plibc? */
/* The code is derived from glibc, obviously */
-#if !HAVE_RANDOM || !HAVE_SRANDOM
+#if ! HAVE_RANDOM || ! HAVE_SRANDOM
#ifdef RANDOM
#undef RANDOM
#endif
#ifdef SRANDOM
#undef SRANDOM
#endif
-#define RANDOM() glibc_weak_rand32()
-#define SRANDOM(s) glibc_weak_srand32(s)
+#define RANDOM() glibc_weak_rand32 ()
+#define SRANDOM(s) glibc_weak_srand32 (s)
#if defined(RAND_MAX)
#undef RAND_MAX
#endif
@@ -105,17 +106,12 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed)
* @param length buffer length
*/
void
-GNUNET_CRYPTO_zero_keys (void *buffer,
- size_t length)
+GNUNET_CRYPTO_zero_keys (void *buffer, size_t length)
{
#if HAVE_MEMSET_S
- memset_s (buffer,
- length,
- 0,
- length);
+ memset_s (buffer, length, 0, length);
#elif HAVE_EXPLICIT_BZERO
- explicit_bzero (buffer,
- length);
+ explicit_bzero (buffer, length);
#else
volatile unsigned char *p = buffer;
while (length--)
@@ -175,8 +171,7 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode,
* @return a random value in the interval [0,i[.
*/
uint32_t
-GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
- uint32_t i)
+GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i)
{
#ifdef gcry_fast_random_poll
static unsigned int invokeCount;
@@ -197,18 +192,17 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
ul = UINT32_MAX - (UINT32_MAX % i);
do
{
- gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t),
+ gcry_randomize ((unsigned char *) &ret,
+ sizeof (uint32_t),
GCRY_STRONG_RANDOM);
- }
- while (ret >= ul);
+ } while (ret >= ul);
return ret % i;
case GNUNET_CRYPTO_QUALITY_NONCE:
ul = UINT32_MAX - (UINT32_MAX % i);
do
{
gcry_create_nonce (&ret, sizeof (ret));
- }
- while (ret >= ul);
+ } while (ret >= ul);
return ret % i;
case GNUNET_CRYPTO_QUALITY_WEAK:
ret = i * get_weak_random ();
@@ -231,8 +225,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
* @return the permutation array (allocated from heap)
*/
unsigned int *
-GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode,
- unsigned int n)
+GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n)
{
unsigned int *ret;
unsigned int i;
@@ -262,8 +255,7 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode,
* @return random 64-bit number
*/
uint64_t
-GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
- uint64_t max)
+GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
{
uint64_t ret;
uint64_t ul;
@@ -275,18 +267,17 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
ul = UINT64_MAX - (UINT64_MAX % max);
do
{
- gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t),
+ gcry_randomize ((unsigned char *) &ret,
+ sizeof (uint64_t),
GCRY_STRONG_RANDOM);
- }
- while (ret >= ul);
+ } while (ret >= ul);
return ret % max;
case GNUNET_CRYPTO_QUALITY_NONCE:
ul = UINT64_MAX - (UINT64_MAX % max);
do
{
gcry_create_nonce (&ret, sizeof (ret));
- }
- while (ret >= ul);
+ } while (ret >= ul);
return ret % max;
case GNUNET_CRYPTO_QUALITY_WEAK:
@@ -319,6 +310,7 @@ w_malloc (size_t n)
static int
w_check (const void *p)
{
+ (void) p;
return 0; /* not secure memory */
}
@@ -326,50 +318,45 @@ w_check (const void *p)
/**
* Initialize libgcrypt.
*/
-void __attribute__ ((constructor))
-GNUNET_CRYPTO_random_init ()
+void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
{
gcry_error_t rc;
if (! gcry_check_version (NEED_LIBGCRYPT_VERSION))
{
- FPRINTF (stderr,
- _("libgcrypt has not the expected version (version %s is required).\n"),
- NEED_LIBGCRYPT_VERSION);
+ FPRINTF (
+ stderr,
+ _ ("libgcrypt has not the expected version (version %s is required).\n"),
+ NEED_LIBGCRYPT_VERSION);
GNUNET_assert (0);
}
/* set custom allocators */
- gcry_set_allocation_handler (&w_malloc,
- &w_malloc,
- &w_check,
- &realloc,
- &free);
+ gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free);
/* Disable use of secure memory */
if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
FPRINTF (stderr,
"Failed to set libgcrypt option %s: %s\n",
"DISABLE_SECMEM",
- gcry_strerror (rc));
+ gcry_strerror (rc));
/* Otherwise gnunet-ecc takes forever to complete, besides
we are fine with "just" using GCRY_STRONG_RANDOM */
if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0)))
FPRINTF (stderr,
- "Failed to set libgcrypt option %s: %s\n",
- "ENABLE_QUICK_RANDOM",
- gcry_strerror (rc));
+ "Failed to set libgcrypt option %s: %s\n",
+ "ENABLE_QUICK_RANDOM",
+ gcry_strerror (rc));
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
gcry_fast_random_poll ();
- GNUNET_CRYPTO_seed_weak_random (time (NULL) ^
- GNUNET_CRYPTO_random_u32
- (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
+ GNUNET_CRYPTO_seed_weak_random (
+ time (NULL) ^
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
}
/**
* Nicely shut down libgcrypt.
*/
-void __attribute__ ((destructor))
-GNUNET_CRYPTO_random_fini ()
+void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini ()
{
gcry_set_progress_handler (NULL, NULL);
#ifdef GCRYCTL_CLOSE_RANDOM_DEVICE
@@ -378,5 +365,4 @@ GNUNET_CRYPTO_random_fini ()
}
-
/* end of crypto_random.c */
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c
index f700428a2..9c292205a 100644
--- a/src/util/gnunet-config.c
+++ b/src/util/gnunet-config.c
@@ -43,6 +43,13 @@ static char *option;
static char *value;
/**
+ * Backend to check if the respective plugin is
+ * loadable. NULL if no check is to be performed.
+ * The value is the "basename" of the plugin to load.
+ */
+static char *backend_check;
+
+/**
* Treat option as a filename.
*/
static int is_filename;
@@ -55,7 +62,7 @@ static int list_sections;
/**
* Return value from 'main'.
*/
-static int ret;
+static int global_ret;
/**
* Should we generate a configuration file that is clean and
@@ -63,6 +70,7 @@ static int ret;
*/
static int rewrite;
+
/**
* Print each option in a given section.
*
@@ -149,6 +157,17 @@ run (void *cls,
(void) cls;
(void) args;
+ if (NULL != backend_check)
+ {
+ char *name;
+
+ GNUNET_asprintf (&name,
+ "libgnunet_plugin_%s",
+ backend_check);
+ global_ret = (GNUNET_OK == GNUNET_PLUGIN_test (name)) ? 0 : 77;
+ GNUNET_free (name);
+ return;
+ }
if (rewrite)
{
struct GNUNET_CONFIGURATION_Handle *def;
@@ -159,7 +178,7 @@ run (void *cls,
{
fprintf (stderr,
_("failed to load configuration defaults"));
- ret = 1;
+ global_ret = 1;
return;
}
diff = GNUNET_CONFIGURATION_get_diff (def,
@@ -174,7 +193,7 @@ run (void *cls,
_("%s or %s argument is required\n"),
"--section",
"--list-sections");
- ret = 1;
+ global_ret = 1;
}
else
{
@@ -208,7 +227,7 @@ run (void *cls,
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
section, option);
- ret = 3;
+ global_ret = 3;
goto cleanup;
}
}
@@ -220,7 +239,7 @@ run (void *cls,
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
section, option);
- ret = 3;
+ global_ret = 3;
goto cleanup;
}
}
@@ -232,7 +251,7 @@ run (void *cls,
if (NULL == option)
{
fprintf (stderr, _("--option argument required to set value\n"));
- ret = 1;
+ global_ret = 1;
goto cleanup;
}
out = GNUNET_CONFIGURATION_dup (cfg);
@@ -260,7 +279,7 @@ run (void *cls,
if (GNUNET_OK !=
GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out,
cfgfile))
- ret = 2;
+ global_ret = 2;
}
GNUNET_free_non_null (cfg_fn);
if (NULL != out)
@@ -287,6 +306,12 @@ main (int argc,
"filename",
gettext_noop ("interpret option value as a filename (with $-expansion)"),
&is_filename),
+ //GNUNET_GETOPT_option_exclusive
+ (GNUNET_GETOPT_option_string ('b',
+ "supported-backend",
+ "BACKEND",
+ gettext_noop ("test if the current installation supports the specified BACKEND"),
+ &backend_check)),
GNUNET_GETOPT_option_string ('s',
"section",
"SECTION",
@@ -312,20 +337,23 @@ main (int argc,
&rewrite),
GNUNET_GETOPT_OPTION_END
};
+ int ret;
+
if (GNUNET_OK !=
GNUNET_STRINGS_get_utf8_args (argc, argv,
&argc, &argv))
return 2;
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-config [OPTIONS]",
- gettext_noop ("Manipulate GNUnet configuration files"),
- options,
- &run, NULL)) ? 0 : ret;
+ ret = GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-config [OPTIONS]",
+ gettext_noop ("Manipulate GNUnet configuration files"),
+ options,
+ &run, NULL);
GNUNET_free ((void*) argv);
- return ret;
+ if (GNUNET_OK == ret)
+ return global_ret;
+ return 1;
}
/* end of gnunet-config.c */
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index 5e15eb16a..f4149a398 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -57,15 +57,13 @@ static char *pwfn;
static void
shutdown_task (void *cls)
{
- if (sizeof (proof) !=
- GNUNET_DISK_fn_write (pwfn,
- &proof,
- sizeof (proof),
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "write",
- pwfn);
+ (void) cls;
+ if (sizeof (proof) != GNUNET_DISK_fn_write (pwfn,
+ &proof,
+ sizeof (proof),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", pwfn);
}
@@ -77,17 +75,18 @@ shutdown_task (void *cls)
* @param result where to write the resulting hash
*/
static void
-pow_hash (const void *buf,
- size_t buf_len,
- struct GNUNET_HashCode *result)
+pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
{
- GNUNET_break (0 ==
- gcry_kdf_derive (buf, buf_len,
- GCRY_KDF_SCRYPT,
- 1 /* subalgo */,
- "gnunet-proof-of-work", strlen ("gnunet-proof-of-work"),
- 2 /* iterations; keep cost of individual op small */,
- sizeof (struct GNUNET_HashCode), result));
+ GNUNET_break (
+ 0 == gcry_kdf_derive (buf,
+ buf_len,
+ GCRY_KDF_SCRYPT,
+ 1 /* subalgo */,
+ "gnunet-proof-of-work",
+ strlen ("gnunet-proof-of-work"),
+ 2 /* iterations; keep cost of individual op small */,
+ sizeof (struct GNUNET_HashCode),
+ result));
}
@@ -118,7 +117,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash)
static void
find_proof (void *cls)
{
- #define ROUND_SIZE 10
+#define ROUND_SIZE 10
uint64_t counter;
char buf[sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) +
sizeof (uint64_t)] GNUNET_ALIGN;
@@ -127,12 +126,14 @@ find_proof (void *cls)
struct GNUNET_TIME_Absolute timestamp;
struct GNUNET_TIME_Relative elapsed;
+ (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got Proof of Work %llu\n",
- (unsigned long long) proof);
+ "Got Proof of Work %llu\n",
+ (unsigned long long) proof);
proof_task = NULL;
- GNUNET_memcpy (&buf[sizeof (uint64_t)], &pub,
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+ GNUNET_memcpy (&buf[sizeof (uint64_t)],
+ &pub,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
i = 0;
counter = proof;
timestamp = GNUNET_TIME_absolute_get ();
@@ -143,7 +144,8 @@ find_proof (void *cls)
if (nse_work_required <= count_leading_zeroes (&result))
{
proof = counter;
- FPRINTF (stdout, "Proof of work found: %llu!\n",
+ FPRINTF (stdout,
+ "Proof of work found: %llu!\n",
(unsigned long long) proof);
GNUNET_SCHEDULER_shutdown ();
return;
@@ -159,7 +161,8 @@ find_proof (void *cls)
GNUNET_STRINGS_relative_time_to_string (elapsed, 0));
if (proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing proofs currently at %llu\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing proofs currently at %llu\n",
(unsigned long long) counter);
/* remember progress every 100 rounds */
proof = counter;
@@ -171,8 +174,9 @@ find_proof (void *cls)
}
proof_task =
GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof, NULL);
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &find_proof,
+ NULL);
}
@@ -193,54 +197,46 @@ run (void *cls,
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
char *pids;
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
cfg = config;
/* load proof of work */
if (NULL == pwfn)
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "NSE",
- "PROOFFILE",
- &pwfn))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "NSE",
+ "PROOFFILE",
+ &pwfn))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "PROOFFILE");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE");
GNUNET_SCHEDULER_shutdown ();
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Proof of Work file: %s\n",
- pwfn);
- if ( (GNUNET_YES != GNUNET_DISK_file_test (pwfn)) ||
- (sizeof (proof) !=
- GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof))))
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Proof of Work file: %s\n", pwfn);
+ if ((GNUNET_YES != GNUNET_DISK_file_test (pwfn)) ||
+ (sizeof (proof) != GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof))))
proof = 0;
/* load private key */
if (NULL == pkfn)
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "PEER",
- "PRIVATE_KEY",
- &pkfn))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PEER",
+ "PRIVATE_KEY",
+ &pkfn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"PEER",
- "PRIVATE_KEY");
+ "PRIVATE_KEY");
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Private Key file: %s\n",
- pkfn);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn);
if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn)))
{
- FPRINTF (stderr,
- _("Loading hostkey from `%s' failed.\n"),
- pkfn);
+ FPRINTF (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn);
GNUNET_free (pkfn);
return;
}
@@ -248,32 +244,27 @@ run (void *cls,
GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub);
GNUNET_free (pk);
pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Peer ID: %s\n",
- pids);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", pids);
GNUNET_free (pids);
/* get target bit amount */
if (0 == nse_work_required)
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "NSE",
- "WORKBITS",
- &nse_work_required))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ "NSE",
+ "WORKBITS",
+ &nse_work_required))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "WORKBITS");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS");
GNUNET_SCHEDULER_shutdown ();
return;
}
if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8)
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "WORKBITS",
- _("Value is too large.\n"));
+ "NSE",
+ "WORKBITS",
+ _ ("Value is too large.\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -283,19 +274,16 @@ run (void *cls,
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Bits: %llu\n",
- nse_work_required);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bits: %llu\n", nse_work_required);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delay between tries: %s\n",
GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1));
proof_task =
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ &find_proof,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
@@ -307,46 +295,51 @@ run (void *cls,
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_ulong ('b',
- "bits",
- "BITS",
- gettext_noop ("number of bits to require for the proof of work"),
- &nse_work_required),
- GNUNET_GETOPT_option_filename ('k',
- "keyfile",
- "FILE",
- gettext_noop ("file with private key, otherwise default is used"),
- &pkfn),
- GNUNET_GETOPT_option_filename ('o',
- "outfile",
- "FILE",
- gettext_noop ("file with proof of work, otherwise default is used"),
- &pwfn),
- GNUNET_GETOPT_option_relative_time ('t',
- "timeout",
- "TIME",
- gettext_noop ("time to wait between calculations"),
- &proof_find_delay),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_ulong (
+ 'b',
+ "bits",
+ "BITS",
+ gettext_noop ("number of bits to require for the proof of work"),
+ &nse_work_required),
+ GNUNET_GETOPT_option_filename (
+ 'k',
+ "keyfile",
+ "FILE",
+ gettext_noop ("file with private key, otherwise default is used"),
+ &pkfn),
+ GNUNET_GETOPT_option_filename (
+ 'o',
+ "outfile",
+ "FILE",
+ gettext_noop ("file with proof of work, otherwise default is used"),
+ &pwfn),
+ GNUNET_GETOPT_option_relative_time ('t',
+ "timeout",
+ "TIME",
+ gettext_noop (
+ "time to wait between calculations"),
+ &proof_find_delay),
+ GNUNET_GETOPT_OPTION_END};
int ret;
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv,
- "gnunet-scrypt [OPTIONS] prooffile",
- gettext_noop ("Manipulate GNUnet proof of work files"),
- options,
- &run,
- NULL)) ? 0 : 1;
- GNUNET_free ((void*) argv);
+ ret =
+ (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-scrypt [OPTIONS] prooffile",
+ gettext_noop ("Manipulate GNUnet proof of work files"),
+ options,
+ &run,
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free ((void *) argv);
GNUNET_free_non_null (pwfn);
return ret;
}
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c
index 58f9e331c..33ff7b1e6 100644
--- a/src/util/gnunet-uri.c
+++ b/src/util/gnunet-uri.c
@@ -53,9 +53,9 @@ maint_child_death (void *cls)
{
enum GNUNET_OS_ProcessStatusType type;
- if ( (GNUNET_OK !=
- GNUNET_OS_process_status (p, &type, &exit_code)) ||
- (type != GNUNET_OS_PROCESS_EXITED) )
+ (void) cls;
+ if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) ||
+ (type != GNUNET_OS_PROCESS_EXITED))
GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG));
GNUNET_OS_process_destroy (p);
}
@@ -70,56 +70,60 @@ maint_child_death (void *cls)
* @param cfg configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *uri;
const char *slash;
char *subsystem;
char *program;
- struct GNUNET_SCHEDULER_Task * rt;
+ struct GNUNET_SCHEDULER_Task *rt;
+ (void) cls;
+ (void) cfgfile;
if (NULL == (uri = args[0]))
{
- fprintf (stderr,
- _("No URI specified on command line\n"));
+ fprintf (stderr, _ ("No URI specified on command line\n"));
return;
}
if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://")))
{
fprintf (stderr,
- _("Invalid URI: does not start with `%s'\n"),
- "gnunet://");
+ _ ("Invalid URI: does not start with `%s'\n"),
+ "gnunet://");
return;
}
uri += strlen ("gnunet://");
if (NULL == (slash = strchr (uri, '/')))
{
- fprintf (stderr, _("Invalid URI: fails to specify subsystem\n"));
+ fprintf (stderr, _ ("Invalid URI: fails to specify subsystem\n"));
return;
}
subsystem = GNUNET_strndup (uri, slash - uri);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "uri",
- subsystem,
- &program))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "uri", subsystem, &program))
{
- fprintf (stderr, _("No handler known for subsystem `%s'\n"), subsystem);
+ fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem);
GNUNET_free (subsystem);
return;
}
GNUNET_free (subsystem);
- rt = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_READ),
- &maint_child_death, NULL);
- p = GNUNET_OS_start_process (GNUNET_NO, 0,
- NULL, NULL, NULL,
- program,
- program,
- args[0],
- NULL);
+ rt = GNUNET_SCHEDULER_add_read_file (
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
+ &maint_child_death,
+ NULL);
+ p = GNUNET_OS_start_process (GNUNET_NO,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ program,
+ program,
+ args[0],
+ NULL);
GNUNET_free (program);
if (NULL == p)
GNUNET_SCHEDULER_cancel (rt);
@@ -134,13 +138,15 @@ static void
sighandler_child_death ()
{
static char c;
- int old_errno = errno; /* back-up errno */
-
- GNUNET_break (1 ==
- GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
- (sigpipe, GNUNET_DISK_PIPE_END_WRITE),
- &c, sizeof (c)));
- errno = old_errno; /* restore errno */
+ int old_errno = errno; /* back-up errno */
+
+ GNUNET_break (
+ 1 ==
+ GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe,
+ GNUNET_DISK_PIPE_END_WRITE),
+ &c,
+ sizeof (c)));
+ errno = old_errno; /* restore errno */
}
@@ -155,8 +161,7 @@ int
main (int argc, char *const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
struct GNUNET_SIGNAL_Context *shc_chld;
int ret;
@@ -166,9 +171,14 @@ main (int argc, char *const *argv)
GNUNET_assert (sigpipe != NULL);
shc_chld =
GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
- ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-uri URI",
- gettext_noop ("Perform default-actions for GNUnet URIs"),
- options, &run, NULL);
+ ret = GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-uri URI",
+ gettext_noop (
+ "Perform default-actions for GNUnet URIs"),
+ options,
+ &run,
+ NULL);
GNUNET_SIGNAL_handler_uninstall (shc_chld);
shc_chld = NULL;
GNUNET_DISK_pipe_close (sigpipe);
diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c
index b8f2bef91..5c3709206 100644
--- a/src/util/test_common_logging_dummy.c
+++ b/src/util/test_common_logging_dummy.c
@@ -35,12 +35,20 @@
* This must be long enough for us to not to mistake skipped log call
* on a slow machine for a non-skipped one.
*/
-#define OUTPUT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000)
+#define OUTPUT_DELAY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000)
static void
-my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
- const char *date, const char *msg)
+my_log (void *ctx,
+ enum GNUNET_ErrorType kind,
+ const char *component,
+ const char *date,
+ const char *msg)
{
+ (void) ctx;
+ (void) kind;
+ (void) component;
+ (void) date;
if (strncmp ("test-common-logging-dummy", component, 25) != 0)
return;
FPRINTF (stdout, "%s", msg);
@@ -48,7 +56,7 @@ my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
}
-#if !defined(GNUNET_CULL_LOGGING)
+#if ! defined(GNUNET_CULL_LOGGING)
static int
expensive_func ()
{
@@ -57,27 +65,36 @@ expensive_func ()
#endif
-#define pr(kind,lvl) {\
- struct GNUNET_TIME_Absolute t1, t2;\
- t1 = GNUNET_TIME_absolute_get ();\
- GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\
- t2 = GNUNET_TIME_absolute_get ();\
- printf ("1%s %llu\n", lvl,\
- (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \
-}
+#define pr(kind, lvl) \
+ { \
+ struct GNUNET_TIME_Absolute t1, t2; \
+ t1 = GNUNET_TIME_absolute_get (); \
+ GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \
+ t2 = GNUNET_TIME_absolute_get (); \
+ printf ("1%s %llu\n", \
+ lvl, \
+ (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \
+ .rel_value_us); \
+ }
+
+#define pr2(kind, lvl) \
+ { \
+ struct GNUNET_TIME_Absolute t1, t2; \
+ t1 = GNUNET_TIME_absolute_get (); \
+ GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \
+ t2 = GNUNET_TIME_absolute_get (); \
+ printf ("2%s %llu\n", \
+ lvl, \
+ (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \
+ .rel_value_us); \
+ }
-#define pr2(kind,lvl) {\
- struct GNUNET_TIME_Absolute t1, t2;\
- t1 = GNUNET_TIME_absolute_get ();\
- GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\
- t2 = GNUNET_TIME_absolute_get ();\
- printf ("2%s %llu\n", lvl,\
- (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \
-}
int
main (int argc, char *argv[])
{
+ (void) argc;
+ (void) argv;
/* We set up logging with NULL level - will be overrided by
* GNUNET_LOG or GNUNET_FORCE_LOG at runtime.
*/
@@ -97,6 +114,6 @@ main (int argc, char *argv[])
pr2 (GNUNET_ERROR_TYPE_INFO, "INFO");
pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG");
return 0;
-} /* end of main */
+} /* end of main */
/* end of test_common_logging_dummy.c */
diff --git a/src/util/tun.c b/src/util/tun.c
index 97fbaa83b..e3643d0c6 100644
--- a/src/util/tun.c
+++ b/src/util/tun.c
@@ -44,24 +44,27 @@
*/
void
GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
- uint8_t protocol,
- uint16_t payload_length,
- const struct in_addr *src,
- const struct in_addr *dst)
+ uint8_t protocol,
+ uint16_t payload_length,
+ const struct in_addr *src,
+ const struct in_addr *dst)
{
GNUNET_assert (20 == sizeof (struct GNUNET_TUN_IPv4Header));
- GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header));
+ GNUNET_assert (payload_length <=
+ UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header));
memset (ip, 0, sizeof (struct GNUNET_TUN_IPv4Header));
- ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
+ ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
ip->version = 4;
- ip->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length);
- ip->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 65536);
+ ip->total_length =
+ htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length);
+ ip->identification =
+ (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 65536);
ip->ttl = FRESH_TTL;
ip->protocol = protocol;
ip->source_address = *src;
ip->destination_address = *dst;
- ip->checksum = GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header));
+ ip->checksum =
+ GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header));
}
@@ -76,13 +79,14 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
*/
void
GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
- uint8_t protocol,
- uint16_t payload_length,
- const struct in6_addr *src,
- const struct in6_addr *dst)
+ uint8_t protocol,
+ uint16_t payload_length,
+ const struct in6_addr *src,
+ const struct in6_addr *dst)
{
GNUNET_assert (40 == sizeof (struct GNUNET_TUN_IPv6Header));
- GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header));
+ GNUNET_assert (payload_length <=
+ UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header));
memset (ip, 0, sizeof (struct GNUNET_TUN_IPv6Header));
ip->version = 6;
ip->next_header = protocol;
@@ -103,27 +107,29 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
*/
void
GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
- struct GNUNET_TUN_TcpHeader *tcp,
- const void *payload,
- uint16_t payload_length)
+ struct GNUNET_TUN_TcpHeader *tcp,
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
uint16_t tmp;
GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader));
- GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_TcpHeader) ==
- ntohs (ip->total_length));
+ GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) +
+ sizeof (struct GNUNET_TUN_TcpHeader) ==
+ ntohs (ip->total_length));
GNUNET_assert (IPPROTO_TCP == ip->protocol);
tcp->crc = 0;
sum = GNUNET_CRYPTO_crc16_step (0,
- &ip->source_address,
- sizeof (struct in_addr) * 2);
+ &ip->source_address,
+ sizeof (struct in_addr) * 2);
tmp = htons (IPPROTO_TCP);
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
tmp = htons (payload_length + sizeof (struct GNUNET_TUN_TcpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
- sum = GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader));
+ sum =
+ GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -139,25 +145,27 @@ GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
*/
void
GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
- struct GNUNET_TUN_TcpHeader *tcp,
- const void *payload,
- uint16_t payload_length)
+ struct GNUNET_TUN_TcpHeader *tcp,
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
uint32_t tmp;
GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader));
GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_TcpHeader) ==
- ntohs (ip->payload_length));
+ ntohs (ip->payload_length));
GNUNET_assert (IPPROTO_TCP == ip->next_header);
tcp->crc = 0;
- sum = GNUNET_CRYPTO_crc16_step (0, &ip->source_address, 2 * sizeof (struct in6_addr));
+ sum = GNUNET_CRYPTO_crc16_step (0,
+ &ip->source_address,
+ 2 * sizeof (struct in6_addr));
tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length);
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
tmp = htonl (IPPROTO_TCP);
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
- sum = GNUNET_CRYPTO_crc16_step (sum, tcp,
- sizeof (struct GNUNET_TUN_TcpHeader));
+ sum =
+ GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -173,36 +181,31 @@ GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
*/
void
GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
- struct GNUNET_TUN_UdpHeader *udp,
- const void *payload,
- uint16_t payload_length)
+ struct GNUNET_TUN_UdpHeader *udp,
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
uint16_t tmp;
GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
- GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_UdpHeader) ==
- ntohs (ip->total_length));
+ GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) +
+ sizeof (struct GNUNET_TUN_UdpHeader) ==
+ ntohs (ip->total_length));
GNUNET_assert (IPPROTO_UDP == ip->protocol);
- udp->crc = 0; /* technically optional, but we calculate it anyway, just to be sure */
+ udp->crc =
+ 0; /* technically optional, but we calculate it anyway, just to be sure */
sum = GNUNET_CRYPTO_crc16_step (0,
- &ip->source_address,
- sizeof (struct in_addr) * 2);
+ &ip->source_address,
+ sizeof (struct in_addr) * 2);
tmp = htons (IPPROTO_UDP);
- sum = GNUNET_CRYPTO_crc16_step (sum,
- &tmp,
- sizeof (uint16_t));
+ sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length);
- sum = GNUNET_CRYPTO_crc16_step (sum,
- &tmp,
- sizeof (uint16_t));
- sum = GNUNET_CRYPTO_crc16_step (sum,
- udp,
- sizeof (struct GNUNET_TUN_UdpHeader));
- sum = GNUNET_CRYPTO_crc16_step (sum,
- payload,
- payload_length);
+ sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
+ sum =
+ GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader));
+ sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
udp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -217,28 +220,30 @@ GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
*/
void
GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
- struct GNUNET_TUN_UdpHeader *udp,
- const void *payload,
- uint16_t payload_length)
+ struct GNUNET_TUN_UdpHeader *udp,
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
uint32_t tmp;
GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) ==
- ntohs (ip->payload_length));
+ ntohs (ip->payload_length));
GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) ==
- ntohs (udp->len));
+ ntohs (udp->len));
GNUNET_assert (IPPROTO_UDP == ip->next_header);
udp->crc = 0;
sum = GNUNET_CRYPTO_crc16_step (0,
- &ip->source_address,
- sizeof (struct in6_addr) * 2);
- tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); /* aka udp->len */
+ &ip->source_address,
+ sizeof (struct in6_addr) * 2);
+ tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) +
+ payload_length); /* aka udp->len */
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
tmp = htons (ip->next_header);
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
- sum = GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader));
+ sum =
+ GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
udp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -253,16 +258,15 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
*/
void
GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
- const void *payload,
- uint16_t payload_length)
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
GNUNET_assert (8 == sizeof (struct GNUNET_TUN_IcmpHeader));
icmp->crc = 0;
- sum = GNUNET_CRYPTO_crc16_step (0,
- icmp,
- sizeof (struct GNUNET_TUN_IcmpHeader));
+ sum =
+ GNUNET_CRYPTO_crc16_step (0, icmp, sizeof (struct GNUNET_TUN_IcmpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
icmp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -286,21 +290,22 @@ GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa,
switch (sa->sa_family)
{
- case AF_INET:
- {
- const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa;
- const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb;
- return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr);
- }
- case AF_INET6:
- {
- const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa;
- const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb;
-
- return (0 == memcmp(&sa6->sin6_addr,
- &sb6->sin6_addr,
- sizeof (struct in6_addr)));
- }
+ case AF_INET: {
+ const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa;
+ const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb;
+ if ((include_port) && (sa4->sin_port != sb4->sin_port))
+ return GNUNET_NO;
+ return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr);
+ }
+ case AF_INET6: {
+ const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa;
+ const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb;
+
+ if ((include_port) && (sa6->sin6_port != sb6->sin6_port))
+ return GNUNET_NO;
+ return (
+ 0 == memcmp (&sa6->sin6_addr, &sb6->sin6_addr, sizeof (struct in6_addr)));
+ }
default:
GNUNET_break (0);
return GNUNET_SYSERR;