diff options
author | t3sserakt <t3ss@posteo.de> | 2019-06-25 15:53:30 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2019-06-25 15:53:30 +0200 |
commit | 28d3e0676f262e495c6d5c49bbedd5ce65502cee (patch) | |
tree | 3631b2f033a913aac3cd806e541e3391f0cec7e5 | |
parent | d2ed51b63d955a590a461e911a3d6fa6a9248fe5 (diff) | |
parent | 17611641fe7da3d2711e1f20eaf2ee81faf0e702 (diff) | |
download | gnunet-28d3e0676f262e495c6d5c49bbedd5ce65502cee.tar.gz gnunet-28d3e0676f262e495c6d5c49bbedd5ce65502cee.zip |
Merge branch 'master' into cadet_option
34 files changed, 1850 insertions, 1682 deletions
diff --git a/doc/handbook/chapters/developer.texi b/doc/handbook/chapters/developer.texi index 228603cda..830a345a8 100644 --- a/doc/handbook/chapters/developer.texi +++ b/doc/handbook/chapters/developer.texi | |||
@@ -79,6 +79,7 @@ new chapters, sections or insightful comments. | |||
79 | * File-sharing (FS) Subsystem:: | 79 | * File-sharing (FS) Subsystem:: |
80 | * REGEX Subsystem:: | 80 | * REGEX Subsystem:: |
81 | * REST Subsystem:: | 81 | * REST Subsystem:: |
82 | * RPS Subsystem:: | ||
82 | @end menu | 83 | @end menu |
83 | 84 | ||
84 | @node Developer Introduction | 85 | @node Developer Introduction |
@@ -556,7 +557,7 @@ stacked together to construct complex buildings and it is generally easy | |||
556 | to swap one block for a different one that has the same shape. GNUnet's | 557 | to swap one block for a different one that has the same shape. GNUnet's |
557 | architecture is based on LEGOs: | 558 | architecture is based on LEGOs: |
558 | 559 | ||
559 | @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} | 560 | @image{images/service_lego_block,5in,,picture of a LEGO block stack - 3 APIs upon IPC/network protocol provided by a service} |
560 | 561 | ||
561 | This chapter documents the GNUnet LEGO system, also known as GNUnet's | 562 | This chapter documents the GNUnet LEGO system, also known as GNUnet's |
562 | system architecture. | 563 | system architecture. |
@@ -573,10 +574,14 @@ Like services, they have holes to be filled by APIs of other services. | |||
573 | Unlike services, daemons do not implement their own network protocol and | 574 | Unlike services, daemons do not implement their own network protocol and |
574 | they have no API: | 575 | they have no API: |
575 | 576 | ||
577 | @image{images/daemon_lego_block,5in,,A daemon in GNUnet is a component that does not offer an API for others to build upon} | ||
578 | |||
576 | The GNUnet system provides a range of services, daemons and user | 579 | The GNUnet system provides a range of services, daemons and user |
577 | interfaces, which are then combined into a layered GNUnet instance (also | 580 | interfaces, which are then combined into a layered GNUnet instance (also |
578 | known as a peer). | 581 | known as a peer). |
579 | 582 | ||
583 | @image{images/service_stack,5in,,A GNUnet peer consists of many layers of services} | ||
584 | |||
580 | Note that while it is generally possible to swap one service for another | 585 | Note that while it is generally possible to swap one service for another |
581 | compatible service, there is often only one implementation. However, | 586 | compatible service, there is often only one implementation. However, |
582 | during development we often have a "new" version of a service in parallel | 587 | during development we often have a "new" version of a service in parallel |
@@ -1876,7 +1881,6 @@ Testbed API can accessed by including the | |||
1876 | * Hosts file format:: | 1881 | * Hosts file format:: |
1877 | * Topology file format:: | 1882 | * Topology file format:: |
1878 | * Testbed Barriers:: | 1883 | * Testbed Barriers:: |
1879 | * Automatic large-scale deployment in the PlanetLab testbed:: | ||
1880 | * TESTBED Caveats:: | 1884 | * TESTBED Caveats:: |
1881 | @end menu | 1885 | @end menu |
1882 | 1886 | ||
@@ -2140,168 +2144,6 @@ message from its upward propagation --- the upward propagation is needed | |||
2140 | for ensuring that the barrier is reached by all the controllers and the | 2144 | for ensuring that the barrier is reached by all the controllers and the |
2141 | downward propagation is for triggering that the barrier is crossed. | 2145 | downward propagation is for triggering that the barrier is crossed. |
2142 | 2146 | ||
2143 | @cindex PlanetLab testbed | ||
2144 | @node Automatic large-scale deployment in the PlanetLab testbed | ||
2145 | @subsection Automatic large-scale deployment in the PlanetLab testbed | ||
2146 | |||
2147 | PlanetLab is a testbed for computer networking and distributed systems | ||
2148 | research. It was established in 2002 and as of June 2010 was composed of | ||
2149 | 1090 nodes at 507 sites worldwide. | ||
2150 | |||
2151 | To automate the GNUnet we created a set of automation tools to simplify | ||
2152 | the large-scale deployment. We provide you a set of scripts you can use | ||
2153 | to deploy GNUnet on a set of nodes and manage your installation. | ||
2154 | |||
2155 | Please also check @uref{https://old.gnunet.org/installation-fedora8-svn} and | ||
2156 | @uref{https://old.gnunet.org/installation-fedora12-svn} to find detailed | ||
2157 | instructions how to install GNUnet on a PlanetLab node. | ||
2158 | |||
2159 | |||
2160 | @c *********************************************************************** | ||
2161 | @menu | ||
2162 | * PlanetLab Automation for Fedora8 nodes:: | ||
2163 | * Install buildslave on PlanetLab nodes running fedora core 8:: | ||
2164 | * Setup a new PlanetLab testbed using GPLMT:: | ||
2165 | * Why do i get an ssh error when using the regex profiler?:: | ||
2166 | @end menu | ||
2167 | |||
2168 | @node PlanetLab Automation for Fedora8 nodes | ||
2169 | @subsubsection PlanetLab Automation for Fedora8 nodes | ||
2170 | |||
2171 | @c *********************************************************************** | ||
2172 | @node Install buildslave on PlanetLab nodes running fedora core 8 | ||
2173 | @subsubsection Install buildslave on PlanetLab nodes running fedora core 8 | ||
2174 | @c ** Actually this is a subsubsubsection, but must be fixed differently | ||
2175 | @c ** as subsubsection is the lowest. | ||
2176 | |||
2177 | Since most of the PlanetLab nodes are running the very old Fedora core 8 | ||
2178 | image, installing the buildslave software is quite some pain. For our | ||
2179 | PlanetLab testbed we figured out how to install the buildslave software | ||
2180 | best. | ||
2181 | |||
2182 | @c This is a very terrible way to suggest installing software. | ||
2183 | @c FIXME: Is there an official, safer way instead of blind-piping a | ||
2184 | @c script? | ||
2185 | @c FIXME: Use newer pypi URLs below. | ||
2186 | Install Distribute for Python: | ||
2187 | |||
2188 | @example | ||
2189 | curl http://python-distribute.org/distribute_setup.py | sudo python | ||
2190 | @end example | ||
2191 | |||
2192 | Install Distribute for zope.interface <= 3.8.0 (4.0 and 4.0.1 will not | ||
2193 | work): | ||
2194 | |||
2195 | @example | ||
2196 | export PYPI=@value{PYPI-URL} | ||
2197 | wget $PYPI/z/zope.interface/zope.interface-3.8.0.tar.gz | ||
2198 | tar xzvf zope.interface-3.8.0.tar.gz | ||
2199 | cd zope.interface-3.8.0 | ||
2200 | sudo python setup.py install | ||
2201 | @end example | ||
2202 | |||
2203 | Install the buildslave software (0.8.6 was the latest version): | ||
2204 | |||
2205 | @example | ||
2206 | export GCODE="http://buildbot.googlecode.com/files" | ||
2207 | wget $GCODE/buildbot-slave-0.8.6p1.tar.gz | ||
2208 | tar xvfz buildbot-slave-0.8.6p1.tar.gz | ||
2209 | cd buildslave-0.8.6p1 | ||
2210 | sudo python setup.py install | ||
2211 | @end example | ||
2212 | |||
2213 | The setup will download the matching twisted package and install it. | ||
2214 | It will also try to install the latest version of zope.interface which | ||
2215 | will fail to install. Buildslave will work anyway since version 3.8.0 | ||
2216 | was installed before! | ||
2217 | |||
2218 | @c *********************************************************************** | ||
2219 | @node Setup a new PlanetLab testbed using GPLMT | ||
2220 | @subsubsection Setup a new PlanetLab testbed using GPLMT | ||
2221 | |||
2222 | @itemize @bullet | ||
2223 | @item Get a new slice and assign nodes | ||
2224 | Ask your PlanetLab PI to give you a new slice and assign the nodes you | ||
2225 | need | ||
2226 | @item Install a buildmaster | ||
2227 | You can stick to the buildbot documentation:@ | ||
2228 | @uref{http://buildbot.net/buildbot/docs/current/manual/installation.html} | ||
2229 | @item Install the buildslave software on all nodes | ||
2230 | To install the buildslave on all nodes assigned to your slice you can use | ||
2231 | the tasklist @code{install_buildslave_fc8.xml} provided with GPLMT: | ||
2232 | |||
2233 | @example | ||
2234 | ./gplmt.py -c contrib/tumple_gnunet.conf -t \ | ||
2235 | contrib/tasklists/install_buildslave_fc8.xml -a -p <planetlab password> | ||
2236 | @end example | ||
2237 | |||
2238 | @item Create the buildmaster configuration and the slave setup commands | ||
2239 | |||
2240 | The master and the and the slaves have need to have credentials and the | ||
2241 | master has to have all nodes configured. This can be done with the | ||
2242 | @file{create_buildbot_configuration.py} script in the @file{scripts} | ||
2243 | directory. | ||
2244 | |||
2245 | This scripts takes a list of nodes retrieved directly from PlanetLab or | ||
2246 | read from a file and a configuration template and creates: | ||
2247 | |||
2248 | @itemize @bullet | ||
2249 | @item a tasklist which can be executed with gplmt to setup the slaves | ||
2250 | @item a master.cfg file containing a PlanetLab nodes | ||
2251 | @end itemize | ||
2252 | |||
2253 | A configuration template is included in the <contrib>, most important is | ||
2254 | that the script replaces the following tags in the template: | ||
2255 | |||
2256 | %GPLMT_BUILDER_DEFINITION :@ GPLMT_BUILDER_SUMMARY@ GPLMT_SLAVES@ | ||
2257 | %GPLMT_SCHEDULER_BUILDERS | ||
2258 | |||
2259 | Create configuration for all nodes assigned to a slice: | ||
2260 | |||
2261 | @example | ||
2262 | ./create_buildbot_configuration.py -u <planetlab username> \ | ||
2263 | -p <planetlab password> -s <slice> -m <buildmaster+port> \ | ||
2264 | -t <template> | ||
2265 | @end example | ||
2266 | |||
2267 | Create configuration for some nodes in a file: | ||
2268 | |||
2269 | @example | ||
2270 | ./create_buildbot_configuration.p -f <node_file> \ | ||
2271 | -m <buildmaster+port> -t <template> | ||
2272 | @end example | ||
2273 | |||
2274 | @item Copy the @file{master.cfg} to the buildmaster and start it | ||
2275 | Use @code{buildbot start <basedir>} to start the server | ||
2276 | @item Setup the buildslaves | ||
2277 | @end itemize | ||
2278 | |||
2279 | @c *********************************************************************** | ||
2280 | @node Why do i get an ssh error when using the regex profiler? | ||
2281 | @subsubsection Why do i get an ssh error when using the regex profiler? | ||
2282 | |||
2283 | Why do i get an ssh error "Permission denied (publickey,password)." when | ||
2284 | using the regex profiler although passwordless ssh to localhost works | ||
2285 | using publickey and ssh-agent? | ||
2286 | |||
2287 | You have to generate a public/private-key pair with no password:@ | ||
2288 | @code{ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_localhost}@ | ||
2289 | and then add the following to your ~/.ssh/config file: | ||
2290 | |||
2291 | @code{Host 127.0.0.1@ IdentityFile ~/.ssh/id_localhost} | ||
2292 | |||
2293 | now make sure your hostsfile looks like | ||
2294 | |||
2295 | @example | ||
2296 | [USERNAME]@@127.0.0.1:22@ | ||
2297 | [USERNAME]@@127.0.0.1:22 | ||
2298 | @end example | ||
2299 | |||
2300 | You can test your setup by running @code{ssh 127.0.0.1} in a | ||
2301 | terminal and then in the opened session run it again. | ||
2302 | If you were not asked for a password on either login, | ||
2303 | then you should be good to go. | ||
2304 | |||
2305 | @cindex TESTBED Caveats | 2147 | @cindex TESTBED Caveats |
2306 | @node TESTBED Caveats | 2148 | @node TESTBED Caveats |
2307 | @subsection TESTBED Caveats | 2149 | @subsection TESTBED Caveats |
@@ -8116,6 +7958,14 @@ This section discusses the challenges and problems faced when writing the | |||
8116 | Ascension tool. It also takes a look at possible improvements in the | 7958 | Ascension tool. It also takes a look at possible improvements in the |
8117 | future. | 7959 | future. |
8118 | 7960 | ||
7961 | Consider the following diagram that shows the workflow of Ascension: | ||
7962 | |||
7963 | @image{images/ascension_ssd,6in,,Ascensions workflow} | ||
7964 | |||
7965 | Further the interaction between components of GNUnet are shown in the diagram | ||
7966 | below: | ||
7967 | @center @image{images/ascension_interaction,,6in,Ascensions workflow} | ||
7968 | |||
8119 | @menu | 7969 | @menu |
8120 | * Conversions between DNS and GNS:: | 7970 | * Conversions between DNS and GNS:: |
8121 | * DNS Zone Size:: | 7971 | * DNS Zone Size:: |
@@ -8126,9 +7976,9 @@ future. | |||
8126 | @node Conversions between DNS and GNS | 7976 | @node Conversions between DNS and GNS |
8127 | @subsubsection Conversions between DNS and GNS | 7977 | @subsubsection Conversions between DNS and GNS |
8128 | 7978 | ||
8129 | The differences between the two name systems lies in the details | 7979 | The differences between the two name systems lies in the details and is not |
8130 | and is not always transparent. | 7980 | always transparent. For instance an SRV record is converted to a BOX record |
8131 | For instance an SRV record is converted to a GNS only BOX record. | 7981 | which is unique to GNS. |
8132 | 7982 | ||
8133 | This is done by converting to a BOX record from an existing SRV record: | 7983 | This is done by converting to a BOX record from an existing SRV record: |
8134 | 7984 | ||
@@ -8141,7 +7991,7 @@ _sip._tcp.example.com. 14000 IN SRV 0 0 5060 www.example.com. | |||
8141 | 14000 BOX n 5060 6 33 0 0 5060 www.example.com | 7991 | 14000 BOX n 5060 6 33 0 0 5060 www.example.com |
8142 | @end example | 7992 | @end example |
8143 | 7993 | ||
8144 | Other records that have such a transformation is the MX record type, | 7994 | Other records that need to undergo such transformation is the MX record type, |
8145 | as well as the SOA record type. | 7995 | as well as the SOA record type. |
8146 | 7996 | ||
8147 | Transformation of a SOA record into GNS works as described in the | 7997 | Transformation of a SOA record into GNS works as described in the |
@@ -8156,8 +8006,9 @@ following example. Very important to note are the rname and mname keys. | |||
8156 | 604800 ; expire | 8006 | 604800 ; expire |
8157 | 600 ) ; ttl | 8007 | 600 ) ; ttl |
8158 | # Recordline for adding the record | 8008 | # Recordline for adding the record |
8159 | $ gnunet-namestore -z example.com -a -n @ -t SOA -V rname=master.example.com \ | 8009 | $ gnunet-namestore -z example.com -a -n @ -t SOA -V \ |
8160 | mname=hostmaster.example.com 2017030300,3600,1800,604800,600 -e 7200s | 8010 | rname=master.example.com mname=hostmaster.example.com \ |
8011 | 2017030300,3600,1800,604800,600 -e 7200s | ||
8161 | @end example | 8012 | @end example |
8162 | 8013 | ||
8163 | The transformation of MX records is done in a simple way. | 8014 | The transformation of MX records is done in a simple way. |
@@ -8166,10 +8017,10 @@ The transformation of MX records is done in a simple way. | |||
8166 | $ gnunet-namestore -z example.com -n mail -R 3600 MX n 10,mail | 8017 | $ gnunet-namestore -z example.com -n mail -R 3600 MX n 10,mail |
8167 | @end example | 8018 | @end example |
8168 | 8019 | ||
8169 | Finally, one of the biggest struggling points were the NS records that are found | 8020 | Finally, one of the biggest struggling points were the NS records that are |
8170 | in top level domain zones. The intended behaviour for those is to add GNS2DNS | 8021 | found in top level domain zones. The intended behaviour for those is to add |
8171 | records for those so that gnunet-gns can resolve records for those domains on | 8022 | GNS2DNS records for those so that gnunet-gns can resolve records for those |
8172 | its own. This requires migration of the DNS GLUE records as well, provided that | 8023 | domains on its own. Those require the values from DNS GLUE records, provided |
8173 | they are within the same zone. | 8024 | they are within the same zone. |
8174 | 8025 | ||
8175 | The following two examples show one record with a GLUE record and the other one | 8026 | The following two examples show one record with a GLUE record and the other one |
@@ -8178,10 +8029,12 @@ does not have a GLUE record. This takes place in the 'com' TLD. | |||
8178 | @example | 8029 | @example |
8179 | # ns1.example.com 86400 IN A 127.0.0.1 | 8030 | # ns1.example.com 86400 IN A 127.0.0.1 |
8180 | # example.com 86400 IN NS ns1.example.com. | 8031 | # example.com 86400 IN NS ns1.example.com. |
8181 | $ gnunet-namestore -z com -n example -R 86400 GNS2DNS n example.com@@127.0.0.1 | 8032 | $ gnunet-namestore -z com -n example -R 86400 GNS2DNS n \ |
8033 | example.com@@127.0.0.1 | ||
8182 | 8034 | ||
8183 | # example.com 86400 IN NS ns1.example.org. | 8035 | # example.com 86400 IN NS ns1.example.org. |
8184 | $ gnunet-namestore -z com -n example -R 86400 GNS2DNS n example.com@@ns1.example.org | 8036 | $ gnunet-namestore -z com -n example -R 86400 GNS2DNS n \ |
8037 | example.com@@ns1.example.org | ||
8185 | @end example | 8038 | @end example |
8186 | 8039 | ||
8187 | As you can see, one of the GNS2DNS records has an IP address listed and the | 8040 | As you can see, one of the GNS2DNS records has an IP address listed and the |
@@ -8204,7 +8057,7 @@ Currently the following record types are supported: | |||
8204 | @item TXT | 8057 | @item TXT |
8205 | @end itemize | 8058 | @end itemize |
8206 | 8059 | ||
8207 | This is not due to a technical limitation but rather a practical one. The | 8060 | This is not due to technical limitations but rather a practical ones. The |
8208 | problem occurs with DNSSEC enabled DNS zones. As records within those zones are | 8061 | problem occurs with DNSSEC enabled DNS zones. As records within those zones are |
8209 | signed periodically, and every new signature is an update to the zone, there are | 8062 | signed periodically, and every new signature is an update to the zone, there are |
8210 | many revisions of zones. This results in a problem with bigger zones as there | 8063 | many revisions of zones. This results in a problem with bigger zones as there |
@@ -8214,16 +8067,22 @@ as they cause a CLI call of the namestore. Furthermore certain record types | |||
8214 | need transformation into a GNS compatible format which, depending on the record | 8067 | need transformation into a GNS compatible format which, depending on the record |
8215 | type, takes more time. | 8068 | type, takes more time. |
8216 | 8069 | ||
8070 | Further a blacklist was added to drop for instance DNSSEC related records. Also | ||
8071 | if a record type is neither in the white list nor the blacklist it is considered | ||
8072 | as a loss of data and a message is shown to the user. This helps with | ||
8073 | transparency and also with contributing, as the not supported record types can | ||
8074 | then be added accordingly. | ||
8075 | |||
8217 | @node DNS Zone Size | 8076 | @node DNS Zone Size |
8218 | @subsubsection DNS Zone Size | 8077 | @subsubsection DNS Zone Size |
8219 | |||
8220 | Another very big problem exists with very large zones. When migrating a small | 8078 | Another very big problem exists with very large zones. When migrating a small |
8221 | zone the delay between adding of records and their expiry is negligible. However | 8079 | zone the delay between adding of records and their expiry is negligible. However |
8222 | when working with a TLD zone that has more that 1 million records this delay | 8080 | when working with big zones that easily have more than a few million records |
8223 | becomes a problem. | 8081 | this delay becomes a problem. |
8224 | 8082 | ||
8225 | Records will start to expire well before the zone has finished migrating. This | 8083 | Records will start to expire well before the zone has finished migrating. This |
8226 | causes unwanted anomalies when trying to resolve records. | 8084 | is usually not a problem but can cause a high CPU load when a peer is restarted |
8085 | and the records have expired. | ||
8227 | 8086 | ||
8228 | A good solution has not been found yet. One of the idea that floated around was | 8087 | A good solution has not been found yet. One of the idea that floated around was |
8229 | that the records should be added with the s (shadow) flag to keep the records | 8088 | that the records should be added with the s (shadow) flag to keep the records |
@@ -8233,45 +8092,51 @@ of said record(s). | |||
8233 | 8092 | ||
8234 | Another problem that still persists is how to refresh records. Expired records | 8093 | Another problem that still persists is how to refresh records. Expired records |
8235 | are still displayed when calling gnunet-namestore but do not resolve with | 8094 | are still displayed when calling gnunet-namestore but do not resolve with |
8236 | gnunet-gns. When doing incremental zone transfers this becomes especially | 8095 | gnunet-gns. Zonemaster will sign the expired records again and make sure that |
8237 | apparent. | 8096 | the records are still valid. With a recent change this was fixed as gnunet-gns |
8097 | to improve the suffix lookup which allows for a fast lookup even with thousands | ||
8098 | of local egos. | ||
8099 | |||
8100 | Currently the pace of adding records in general is around 10 records per second. | ||
8101 | Crypto is the upper limit for adding of records. The performance of your machine | ||
8102 | can be tested with the perf_crypto_* tools. There is still a big discrepancy | ||
8103 | between the pace of Ascension and the theoretical limit. | ||
8238 | 8104 | ||
8239 | I estimate that the limit lies at about 200'000 records in a zone as this is | 8105 | A performance metric for measuring improvements has not yet been implemented in |
8240 | the limit that my machine is capable of adding within one hour. This was | 8106 | Ascension. |
8241 | calculated by running cProfile on the application with a zone of 5000 records | ||
8242 | and calculating what abouts a much bigger zones with 8 million records would | ||
8243 | take. This results in a nice metric of records migrated per hour. | ||
8244 | 8107 | ||
8245 | @node Performance | 8108 | @node Performance |
8246 | @subsubsection Performance | 8109 | @subsubsection Performance |
8247 | The performance when migrating a zone using the Ascension tool is limited by a | 8110 | The performance when migrating a zone using the Ascension tool is limited by a |
8248 | handful of factors. First of all ascension is written in Python3 and calls the | 8111 | handful of factors. First of all ascension is written in Python3 and calls the |
8249 | CLI tools of GNUnet. Furthermore all the records that are added to the same | 8112 | CLI tools of GNUnet. This is comparable to a fork and exec call which costs a |
8113 | few CPU cycles. Furthermore all the records that are added to the same | ||
8250 | label are signed using the zones private key. This signing operation is very | 8114 | label are signed using the zones private key. This signing operation is very |
8251 | resource heavy and was optimized during development by adding the '-R' | 8115 | resource heavy and was optimized during development by adding the '-R' |
8252 | (Recordline) option to gnunet-namestore. This allows to add multiple records | 8116 | (Recordline) option to gnunet-namestore which allows to specify multiple records |
8253 | at once using the CLI. | 8117 | using the CLI tool. Assuming that in a TLD zone every domain has at least two |
8254 | 8118 | name servers this halves the amount of signatures needed. | |
8255 | The result of this was a much faster migration of TLD zones, as most records | ||
8256 | with the same label have two name servers. | ||
8257 | 8119 | ||
8258 | Another improvement that could be made is with the addition of multiple threads | 8120 | Another improvement that could be made is with the addition of multiple threads |
8259 | when opening the GNUnet CLI tools. This could be implemented by simply creating | 8121 | or using asynchronous subprocesses when opening the GNUnet CLI tools. This could |
8260 | more workers in the program but performance improvements were not tested. | 8122 | be implemented by simply creating more workers in the program but performance |
8123 | improvements were not tested. | ||
8261 | 8124 | ||
8262 | During the entire development of Ascension sqlite was used as a database | 8125 | Ascension was tested using different hardware and database backends. Performance |
8263 | backend for GNUnet. Other backends have not been tested yet. | 8126 | differences between SQLite and postgresql are marginal and almost non existent. |
8127 | What did make a huge impact on record adding performance was the storage medium. | ||
8128 | On a traditional mechanical hard drive adding of records were slow compared to a | ||
8129 | solid state disk. | ||
8264 | 8130 | ||
8265 | In conclusion there are many bottlenecks still around in the program, namely the | 8131 | In conclusion there are many bottlenecks still around in the program, namely the |
8266 | signing process and the single threaded implementation. In the future a solution | 8132 | single threaded implementation and inefficient, sequential calls of |
8267 | that uses the C API would be cleaner and better. | 8133 | gnunet-namestore. In the future a solution that uses the C API would be cleaner |
8134 | and better. | ||
8268 | 8135 | ||
8269 | @cindex GNS Namecache | 8136 | @cindex GNS Namecache |
8270 | @node GNS Namecache | 8137 | @node GNS Namecache |
8271 | @section GNS Namecache | 8138 | @section GNS Namecache |
8272 | 8139 | ||
8273 | |||
8274 | |||
8275 | The NAMECACHE subsystem is responsible for caching (encrypted) resolution | 8140 | The NAMECACHE subsystem is responsible for caching (encrypted) resolution |
8276 | results of the GNU Name System (GNS). GNS makes zone information available | 8141 | results of the GNU Name System (GNS). GNS makes zone information available |
8277 | to other users via the DHT. However, as accessing the DHT for every | 8142 | to other users via the DHT. However, as accessing the DHT for every |
@@ -9007,3 +8872,72 @@ so please make sure that endpoints are unambiguous. | |||
9007 | 8872 | ||
9008 | This is WIP. Endpoints should be documented appropriately. | 8873 | This is WIP. Endpoints should be documented appropriately. |
9009 | Preferably using annotations. | 8874 | Preferably using annotations. |
8875 | |||
8876 | |||
8877 | @cindex RPS Subsystem | ||
8878 | @node RPS Subsystem | ||
8879 | @section RPS Subsystem | ||
8880 | |||
8881 | In literature, Random Peer Sampling (RPS) refers to the problem of | ||
8882 | reliably drawing random samples from an unstructured p2p network. | ||
8883 | |||
8884 | Doing so in a reliable manner is not only hard because of inherent | ||
8885 | problems but also because of possible malicious peers that could try to | ||
8886 | bias the selection. | ||
8887 | |||
8888 | It is useful for all kind of gossip protocols that require the selection | ||
8889 | of random peers in the whole network like gathering statistics, | ||
8890 | spreading and aggregating information in the network, load balancing and | ||
8891 | overlay topology management. | ||
8892 | |||
8893 | The approach chosen in the rps implementation in GNUnet follows the | ||
8894 | Brahms@uref{https://bib.gnunet.org/full/date.html\#2009_5f0} design. | ||
8895 | |||
8896 | The current state is "work in progress". There are a lot of things that | ||
8897 | need to be done, primarily finishing the experimental evaluation and a | ||
8898 | re-design of the API. | ||
8899 | |||
8900 | The abstract idea is to subscribe to connect to/start the rps service | ||
8901 | and request random peers that will be returned when they represent a | ||
8902 | random selection from the whole network with high probability. | ||
8903 | |||
8904 | An additional feature to the original Brahms-design is the selection of | ||
8905 | sub-groups: The GNUnet implementation of rps enables clients to ask for | ||
8906 | random peers from a group that is defined by a common shared secret. | ||
8907 | (The secret could of course also be public, depending on the use-case.) | ||
8908 | |||
8909 | Another addition to the original protocol was made: The sampler | ||
8910 | mechanism that was introduced in Brahms was slightly adapted and used to | ||
8911 | actually sample the peers and returned to the client. | ||
8912 | This is necessary as the original design only keeps peers connected to | ||
8913 | random other peers in the network. In order to return random peers to | ||
8914 | client requests independently random, they cannot be drawn from the | ||
8915 | connected peers. | ||
8916 | The adapted sampler makes sure that each request for random peers is | ||
8917 | independent from the others. | ||
8918 | |||
8919 | @node Brahms | ||
8920 | @subsection Brahms | ||
8921 | The high-level concept of Brahms is two-fold: Combining push-pull gossip | ||
8922 | with locally fixing a assumed bias using cryptographic min-wise | ||
8923 | permutations. | ||
8924 | The central data structure is the view - a peer's current local sample. | ||
8925 | This view is used to select peers to push to and pull from. | ||
8926 | This simple mechanism can be biased easily. For this reason Brahms | ||
8927 | 'fixes' the bias by using the so-called sampler. A data structure that | ||
8928 | takes a list of elements as input and outputs a random one of them | ||
8929 | independently of the frequency in the input set. Both an element that | ||
8930 | was put into the sampler a single time and an element that was put into | ||
8931 | it a million times have the same probability of being the output. | ||
8932 | This is achieved this is achieved with exploiting min-wise independent | ||
8933 | permutations. In rps we use HMACs: On the initialisation of a sampler | ||
8934 | element, a key is chosen at random. On each input the HMAC with the | ||
8935 | random key is computed. The sampler element keeps the element with the | ||
8936 | minimal HMAC. | ||
8937 | |||
8938 | In order to fix the bias in the view, a fraction of the elements in the | ||
8939 | view are sampled through the sampler from the random stream of peer IDs. | ||
8940 | |||
8941 | According to the theoretical analysis of Bortnikov et al. this suffices | ||
8942 | to keep the network connected and having random peers in the view. | ||
8943 | |||
diff --git a/doc/handbook/chapters/installation.texi b/doc/handbook/chapters/installation.texi index d02fc7f82..a508feb6a 100644 --- a/doc/handbook/chapters/installation.texi +++ b/doc/handbook/chapters/installation.texi | |||
@@ -1786,10 +1786,21 @@ Keeping a virtual environment helps with keeping things tidy and prevents | |||
1786 | breaking of Ascension through a future Python update. | 1786 | breaking of Ascension through a future Python update. |
1787 | 1787 | ||
1788 | The advantage of using a virtual environment is, that all the dependencies can | 1788 | The advantage of using a virtual environment is, that all the dependencies can |
1789 | be installed separately in different versions without touching your system | 1789 | be installed separately in different versions without touching your systems |
1790 | Python installation and its dependencies. | 1790 | Python installation and its dependencies. |
1791 | 1791 | ||
1792 | @xref{Migrating an existing DNS zone into GNS}, for usage manual of the tool. | 1792 | Another way to install Ascension on Debian is to install the python3-ascension |
1793 | package. It can be found within the above mentioned Ascension git repository. | ||
1794 | This also adds a system user ascension and runs a GNUnet peer in the | ||
1795 | background. Attention: This only works if a recent version of GNUnet is | ||
1796 | installed on your system. The version number of Ascension is chosen according | ||
1797 | to the required feature level of GNUnet. I.e. Ascension 0.11.5 is only | ||
1798 | compatible with GNUnet 0.11.5 and upwards. As Debian's packages for GNUnet are | ||
1799 | outdated even in experimental, you will need to install GNUnet manually. | ||
1800 | @xref{Installing GNUnet} | ||
1801 | |||
1802 | Please check @xref{Migrating an existing DNS zone into GNS}, for usage manual | ||
1803 | of the tool. | ||
1793 | 1804 | ||
1794 | @node Configuring the GNUnet VPN | 1805 | @node Configuring the GNUnet VPN |
1795 | @subsection Configuring the GNUnet VPN | 1806 | @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 | |||
319 | identities, for example to separate their activities online. Egos can | 319 | identities, for example to separate their activities online. Egos can |
320 | correspond to "pseudonyms" or "real-world identities". Technically an | 320 | correspond to "pseudonyms" or "real-world identities". Technically an |
321 | ego is first of all a key pair of a public- and private-key. | 321 | ego is first of all a key pair of a public- and private-key. |
322 | |||
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. | |||
526 | For the record type, select PHONE. You should then see the | 526 | For the record type, select PHONE. You should then see the |
527 | PHONE dialog: | 527 | PHONE dialog: |
528 | 528 | ||
529 | @c image here | 529 | @image{images/gnunet-namestore-gtk-phone,5in,,Dialog to publish a PHONE record} |
530 | 530 | ||
531 | Note: Do not choose the expiry time to be 'Never'. If you | 531 | Note: Do not choose the expiry time to be 'Never'. If you |
532 | do that, you assert that this record will never change and | 532 | 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 | |||
645 | master zone. For the record type, select @code{VPN}. You should then | 645 | master zone. For the record type, select @code{VPN}. You should then |
646 | see the VPN dialog: | 646 | see the VPN dialog: |
647 | 647 | ||
648 | @c insert image | 648 | @image{images/gnunet-namestore-gtk-vpn,5in,,Dialog to publish a VPN record} |
649 | 649 | ||
650 | Under peer, you need to supply the peer identity of your own peer. You can | 650 | Under peer, you need to supply the peer identity of your own peer. You can |
651 | obtain the respective string by running @command{gnunet-peerinfo -sq} | 651 | obtain the respective string by running @command{gnunet-peerinfo -sq} |
@@ -926,7 +926,7 @@ concepts that are used to achieve these goals. | |||
926 | * Files:: | 926 | * Files:: |
927 | * Keywords:: | 927 | * Keywords:: |
928 | * Directories:: | 928 | * Directories:: |
929 | * Pseudonyms:: | 929 | * Egos and File-Sharing:: |
930 | * Namespaces:: | 930 | * Namespaces:: |
931 | * Advertisements:: | 931 | * Advertisements:: |
932 | * Anonymity level:: | 932 | * Anonymity level:: |
@@ -984,69 +984,55 @@ typically includes the mime-type, description, a filename and | |||
984 | other meta information, and possibly even the full original file | 984 | other meta information, and possibly even the full original file |
985 | (if it was small). | 985 | (if it was small). |
986 | 986 | ||
987 | @node Pseudonyms | 987 | @node Egos and File-Sharing |
988 | @subsubsection Pseudonyms | 988 | @subsubsection Egos and File-Sharing |
989 | 989 | ||
990 | When sharing files, it is sometimes desirable to build a reputation as | ||
991 | a source for quality information. With egos, publishers can | ||
992 | (cryptographically) sign files, thereby demonstrating that various | ||
993 | files were published by the same entity. An ego thus allows users to | ||
994 | link different publication events, thereby deliberately reducing | ||
995 | anonymity to pseudonymity. | ||
990 | 996 | ||
991 | @b{Please note that the text in this subsection is outdated and needs} | 997 | Egos used in GNUnet's file-sharing for such pseudonymous publishing |
992 | @b{to be rewritten for version 0.10!} | 998 | also correspond to the egos used to identify and sign zones in the |
993 | @b{This especially concerns the terminology of Pseudonym/Ego/Identity.} | 999 | GNU Name System. However, if the same ego is used for file-sharing |
1000 | and for a GNS zone, this will weaken the privacy assurances provided | ||
1001 | by the anonymous file-sharing protocol. | ||
994 | 1002 | ||
995 | Pseudonyms in GNUnet are essentially public-private (RSA) key pairs | 1003 | Note that an ego is NOT bound to a GNUnet peer. There can be multiple |
996 | that allow a GNUnet user to maintain an identity (which may or may not | 1004 | egos for a single user, and users could (theoretically) share |
997 | be detached from their real-life identity). GNUnet's pseudonyms are not | 1005 | the private keys of an ego by copying the respective private keys. |
998 | file-sharing specific --- and they will likely be used by many GNUnet | ||
999 | applications where a user identity is required. | ||
1000 | 1006 | ||
1001 | Note that a pseudonym is NOT bound to a GNUnet peer. There can be multiple | ||
1002 | pseudonyms for a single user, and users could (theoretically) share the | ||
1003 | private pseudonym keys (currently only out-of-band by knowing which files | ||
1004 | to copy around). | ||
1005 | 1007 | ||
1006 | @node Namespaces | 1008 | @node Namespaces |
1007 | @subsubsection Namespaces | 1009 | @subsubsection Namespaces |
1008 | 1010 | ||
1011 | A namespace is a set of files that were signed by the same ego. | ||
1012 | Today, namespaces are implemented independently of GNS zones, but | ||
1013 | in the future we plan to merge the two such that a GNS zone can | ||
1014 | basically contain files using a file-sharing specific record type. | ||
1009 | 1015 | ||
1010 | @b{Please note that the text in this subsection is outdated and needs} | 1016 | Files (or directories) that have been signed and placed into a |
1011 | @b{to be rewritten for version 0.10!} | 1017 | namespace can be updated. Updates are identified as authentic if the |
1012 | @b{This especially concerns the terminology of Pseudonym/Ego/Identity.} | 1018 | same secret key was used to sign the update. |
1013 | |||
1014 | A namespace is a set of files that were signed by the same pseudonym. | ||
1015 | Files (or directories) that have been signed and placed into a namespace | ||
1016 | can be updated. Updates are identified as authentic if the same secret | ||
1017 | key was used to sign the update. Namespaces are also useful to establish | ||
1018 | a reputation, since all of the content in the namespace comes from the | ||
1019 | same entity (which does not have to be the same person). | ||
1020 | 1019 | ||
1021 | @node Advertisements | 1020 | @node Advertisements |
1022 | @subsubsection Advertisements | 1021 | @subsubsection Advertisements |
1023 | 1022 | ||
1024 | |||
1025 | @b{Please note that the text in this subsection is outdated and needs} | ||
1026 | @b{to be rewritten for version 0.10!} | ||
1027 | @b{This especially concerns the terminology of Pseudonym/Ego/Identity.} | ||
1028 | |||
1029 | Advertisements are used to notify other users about the existence of a | 1023 | Advertisements are used to notify other users about the existence of a |
1030 | namespace. Advertisements are propagated using the normal keyword search. | 1024 | namespace. Advertisements are propagated using the normal keyword |
1031 | When an advertisement is received (in response to a search), the namespace | 1025 | search. When an advertisement is received (in response to a search), |
1032 | is added to the list of namespaces available in the namespace-search | 1026 | the namespace is added to the list of namespaces available in the |
1033 | dialogs of gnunet-fs-gtk and printed by @code{gnunet-identity}. Whenever a | 1027 | namespace-search dialogs of gnunet-fs-gtk and printed by |
1034 | namespace is created, an appropriate advertisement can be generated. | 1028 | @code{gnunet-identity}. Whenever a namespace is created, an |
1035 | The default keyword for the advertising of namespaces is "namespace". | 1029 | appropriate advertisement can be generated. The default keyword for |
1036 | 1030 | the advertising of namespaces is "namespace". | |
1037 | Note that GNUnet differentiates between your pseudonyms (the identities | 1031 | |
1038 | that you control) and namespaces. If you create a pseudonym, you will | ||
1039 | not automatically see the respective namespace. You first have to create | ||
1040 | an advertisement for the namespace and find it using keyword | ||
1041 | search --- even for your own namespaces. The @command{gnunet-identity} | ||
1042 | tool is currently responsible for both managing pseudonyms and namespaces. | ||
1043 | This will likely change in the future to reduce the potential for | ||
1044 | confusion. | ||
1045 | 1032 | ||
1046 | @node Anonymity level | 1033 | @node Anonymity level |
1047 | @subsubsection Anonymity level | 1034 | @subsubsection Anonymity level |
1048 | 1035 | ||
1049 | |||
1050 | The anonymity level determines how hard it should be for an adversary to | 1036 | The anonymity level determines how hard it should be for an adversary to |
1051 | determine the identity of the publisher or the searcher/downloader. An | 1037 | determine the identity of the publisher or the searcher/downloader. An |
1052 | anonymity level of zero means that anonymity is not required. The default | 1038 | anonymity level of zero means that anonymity is not required. The default |
@@ -1066,10 +1052,10 @@ delays traffic. | |||
1066 | While higher anonymity levels may offer better privacy, they can also | 1052 | While higher anonymity levels may offer better privacy, they can also |
1067 | significantly hurt performance. | 1053 | significantly hurt performance. |
1068 | 1054 | ||
1055 | |||
1069 | @node Content Priority | 1056 | @node Content Priority |
1070 | @subsubsection Content Priority | 1057 | @subsubsection Content Priority |
1071 | 1058 | ||
1072 | |||
1073 | Depending on the peer's configuration, GNUnet peers migrate content | 1059 | Depending on the peer's configuration, GNUnet peers migrate content |
1074 | between peers. Content in this sense are individual blocks of a file, | 1060 | between peers. Content in this sense are individual blocks of a file, |
1075 | not necessarily entire files. When peers run out of space (due to | 1061 | 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 | |||
1083 | published locally, the base-priority that was specified by the user | 1069 | published locally, the base-priority that was specified by the user |
1084 | when the block was published initially. | 1070 | when the block was published initially. |
1085 | 1071 | ||
1072 | |||
1086 | @node Replication | 1073 | @node Replication |
1087 | @subsubsection Replication | 1074 | @subsubsection Replication |
1088 | 1075 | ||
1089 | |||
1090 | When peers migrate content to other systems, the replication level | 1076 | When peers migrate content to other systems, the replication level |
1091 | of a block is used to decide which blocks need to be migrated most | 1077 | of a block is used to decide which blocks need to be migrated most |
1092 | urgently. GNUnet will always push the block with the highest | 1078 | urgently. GNUnet will always push the block with the highest |
@@ -1098,99 +1084,37 @@ selection is simply random. | |||
1098 | @node Namespace Management | 1084 | @node Namespace Management |
1099 | @subsection Namespace Management | 1085 | @subsection Namespace Management |
1100 | 1086 | ||
1101 | 1087 | The @code{gnunet-identity} tool can be used to create egos. | |
1102 | @b{Please note that the text in this subsection is outdated and needs} | 1088 | By default, @code{gnunet-identity -D} simply |
1103 | @b{to be rewritten for version 0.10!} | 1089 | lists all locally available egos. |
1104 | |||
1105 | The @code{gnunet-identity} tool can be used to create pseudonyms and | ||
1106 | to advertise namespaces. By default, @code{gnunet-identity -D} simply | ||
1107 | lists all locally available pseudonyms. | ||
1108 | 1090 | ||
1109 | 1091 | ||
1110 | @menu | 1092 | @menu |
1111 | * Creating Pseudonyms:: | 1093 | * Creating Egos:: |
1112 | * Deleting Pseudonyms:: | 1094 | * Deleting Egos:: |
1113 | * Advertising namespaces:: | ||
1114 | * Namespace names:: | ||
1115 | * Namespace root:: | ||
1116 | @end menu | 1095 | @end menu |
1117 | 1096 | ||
1118 | @node Creating Pseudonyms | 1097 | @node Creating Egos |
1119 | @subsubsection Creating Pseudonyms | 1098 | @subsubsection Creating Egos |
1120 | 1099 | ||
1100 | With the @command{-C NICK} option it can also be used to create a new | ||
1101 | ego. An ego is the virtual identity of the entity in control of a | ||
1102 | namespace or GNS zone. Anyone can create any number of egos. The | ||
1103 | provided NICK name automatically corresponds to a GNU Name System | ||
1104 | domain name. Thus, henceforth name resolution for any name ending in | ||
1105 | ``.NICK'' will use the NICK's zone. You should avoid using NICKs that | ||
1106 | collide with well-known DNS names. | ||
1121 | 1107 | ||
1122 | @b{Please note that the text in this subsection is outdated and needs} | 1108 | @node Deleting Egos |
1123 | @b{to be rewritten for version 0.10!} | 1109 | @subsubsection Deleting Egos |
1124 | @b{This especially concerns the terminology of Pseudonym/Ego/Identity.} | ||
1125 | 1110 | ||
1126 | With the @command{-C NICK} option it can also be used to | 1111 | With the @command{-D NICK} option egos can be deleted. Once the ego |
1127 | create a new pseudonym. A pseudonym is the virtual identity | 1112 | has been deleted it is impossible to add content to the corresponding |
1128 | of the entity in control of a namespace. Anyone can create | 1113 | namespace or zone. However, the existing GNS zone data is currently |
1129 | any number of pseudonyms. Note that creating a pseudonym can | 1114 | not dropped. This may change in the future. |
1130 | take a few minutes depending on the performance of the machine | ||
1131 | used. | ||
1132 | 1115 | ||
1133 | @node Deleting Pseudonyms | 1116 | Deleting the pseudonym does not make the namespace or any content in |
1134 | @subsubsection Deleting Pseudonyms | 1117 | it unavailable. |
1135 | |||
1136 | |||
1137 | @b{Please note that the text in this subsection is outdated and needs} | ||
1138 | @b{to be rewritten for version 0.10!} | ||
1139 | @b{This especially concerns the terminology of Pseudonym/Ego/Identity.} | ||
1140 | |||
1141 | With the @command{-D NICK} option pseudonyms can be deleted. | ||
1142 | Once the pseudonym has been deleted it is impossible to add | ||
1143 | content to the corresponding namespace. Deleting the | ||
1144 | pseudonym does not make the namespace or any content in it | ||
1145 | unavailable. | ||
1146 | |||
1147 | @node Advertising namespaces | ||
1148 | @subsubsection Advertising namespaces | ||
1149 | |||
1150 | |||
1151 | @b{Please note that the text in this subsection is outdated and needs} | ||
1152 | @b{to be rewritten for version 0.10!} | ||
1153 | @b{This especially concerns the terminology of Pseudonym/Ego/Identity.} | ||
1154 | |||
1155 | Each namespace is associated with meta-data that describes | ||
1156 | the namespace. This meta-data is provided by the user at | ||
1157 | the time that the namespace is advertised. Advertisements | ||
1158 | are published under keywords so that they can be found using | ||
1159 | normal keyword-searches. This way, users can learn about new | ||
1160 | namespaces without relying on out-of-band communication or directories. | ||
1161 | A suggested keyword to use for all namespaces is simply "namespace". | ||
1162 | When a keyword-search finds a namespace advertisement, | ||
1163 | it is automatically stored in a local list of known namespaces. | ||
1164 | Users can then associate a rank with the namespace to remember | ||
1165 | the quality of the content found in it. | ||
1166 | |||
1167 | @node Namespace names | ||
1168 | @subsubsection Namespace names | ||
1169 | |||
1170 | |||
1171 | @b{Please note that the text in this subsection is outdated and needs} | ||
1172 | @b{to be rewritten for version 0.10!} | ||
1173 | @b{This especially concerns the terminology of Pseudonym/Ego/Identity.} | ||
1174 | |||
1175 | While the namespace is uniquely identified by its ID, another way | ||
1176 | to refer to the namespace is to use the NICKNAME. | ||
1177 | The NICKNAME can be freely chosen by the creator of the namespace and | ||
1178 | hence conflicts are possible. If a GNUnet client learns about more | ||
1179 | than one namespace using the same NICKNAME, the ID is appended | ||
1180 | to the NICKNAME to get a unique identifier. | ||
1181 | |||
1182 | @node Namespace root | ||
1183 | @subsubsection Namespace root | ||
1184 | |||
1185 | |||
1186 | @b{Please note that the text in this subsection is outdated and needs} | ||
1187 | @b{to be rewritten for version 0.10!} | ||
1188 | @b{This especially concerns the terminology of Pseudonym/Ego/Identity.} | ||
1189 | |||
1190 | An item of particular interest in the namespace advertisement is | ||
1191 | the ROOT. The ROOT is the identifier of a designated entry in the | ||
1192 | namespace. The idea is that the ROOT can be used to advertise an | ||
1193 | entry point to the content of the namespace. | ||
1194 | 1118 | ||
1195 | @node File-Sharing URIs | 1119 | @node File-Sharing URIs |
1196 | @subsection File-Sharing URIs | 1120 | @subsection File-Sharing URIs |
@@ -1314,12 +1238,12 @@ To publish a file, select "File Sharing" in the menu bar just below the | |||
1314 | 1238 | ||
1315 | Afterwards, the following publishing dialog will appear: | 1239 | Afterwards, the following publishing dialog will appear: |
1316 | 1240 | ||
1317 | @c Add image here | 1241 | @image{images/gnunet-gtk-0-10-fs-publish,5in,,The gnunet-fs-gtk publishing dialog} |
1318 | 1242 | ||
1319 | In this dialog, select the "Add File" button. This will open a | 1243 | In this dialog, select the "Add File" button. This will open a |
1320 | file selection dialog: | 1244 | file selection dialog: |
1321 | 1245 | ||
1322 | @c Add image here | 1246 | @image{images/gnunet-gtk-0-10-fs-publish-select,5in,,Dialog to select the file to publish (looks may differ for other Gtk+ versions)} |
1323 | 1247 | ||
1324 | Now, you should select a file from your computer to be published on | 1248 | Now, you should select a file from your computer to be published on |
1325 | GNUnet. To see more of GNUnet's features later, you should pick a | 1249 | 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. | |||
1335 | After the progress dialog automatically disappears, your file | 1259 | After the progress dialog automatically disappears, your file |
1336 | should now appear in the publishing dialog: | 1260 | should now appear in the publishing dialog: |
1337 | 1261 | ||
1338 | @c Add image here | 1262 | @image{images/gnunet-gtk-0-10-fs-publish-with-file,5in,,Publishing dialog with file added} |
1339 | 1263 | ||
1340 | Now, select the file (by clicking on the file name) and then click | 1264 | Now, select the file (by clicking on the file name) and then click |
1341 | the "Edit" button. This will open the editing dialog: | 1265 | the "Edit" button. This will open the editing dialog: |
1342 | 1266 | ||
1343 | @c Add image here | 1267 | @image{images/gnunet-gtk-0-10-fs-publish-editing,5in,,Editing meta data of a file to be published} |
1344 | 1268 | ||
1345 | In this dialog, you can see many details about your file. In the | 1269 | In this dialog, you can see many details about your file. In the |
1346 | top left area, you can see meta data extracted about the file, | 1270 | 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 | |||
1364 | "Execute" in the bottom right to close the dialog and publish your file | 1288 | "Execute" in the bottom right to close the dialog and publish your file |
1365 | on GNUnet! Afterwards, you should see the main dialog with a new area | 1289 | on GNUnet! Afterwards, you should see the main dialog with a new area |
1366 | showing the list of published files (or ongoing publishing operations | 1290 | showing the list of published files (or ongoing publishing operations |
1367 | with progress indicators): | 1291 | with progress indicators). |
1368 | |||
1369 | @c Add image here | ||
1370 | 1292 | ||
1371 | @node gtk-Searching | 1293 | @node gtk-Searching |
1372 | @subsubsection Searching | 1294 | @subsubsection Searching |
@@ -1920,33 +1842,42 @@ options: | |||
1920 | 1842 | ||
1921 | @example | 1843 | @example |
1922 | Ascension | 1844 | Ascension |
1923 | |||
1924 | Usage: | 1845 | Usage: |
1925 | ascension <domain> [-d] [-p] | 1846 | ascension <domain> [-d] [-p] [-s] [--minimum-ttl=<ttl>] \ |
1926 | ascension <domain> <port> [-d] [-p] | 1847 | [--dry-run] |
1927 | ascension <domain> -n <transferns> [-d] [-p] | 1848 | ascension <domain> <port> [-d] [-p] [-s] \ |
1928 | ascension <domain> -n <transferns> <port> [-d] [-p] | 1849 | [--minimum-ttl=<ttl>] [--dry-run] |
1850 | ascension <domain> -n <transferns> [-d] [-p] \ | ||
1851 | [-s] [--minimum-ttl=<ttl>] [--dry-run] | ||
1852 | ascension <domain> -n <transferns> <port> [-d] \ | ||
1853 | [-p] [-s] [--minimum-ttl=<ttl>] [--dry-run] | ||
1929 | ascension -p | --public | 1854 | ascension -p | --public |
1855 | ascension -d | --debug | ||
1856 | ascension -s | --standalone | ||
1930 | ascension -h | --help | 1857 | ascension -h | --help |
1931 | ascension -v | --version | 1858 | ascension -v | --version |
1932 | 1859 | ||
1933 | Options: | 1860 | Options: |
1934 | <domain> Domain to migrate | 1861 | <domain> Domain to migrate |
1935 | <port> Port for zone transfer | 1862 | <port> Port for zone transfer |
1936 | <transferns> DNS Server that does the zone transfer | 1863 | <transferns> DNS Server that does the zone transfer |
1937 | -p --public Make records public on the DHT | 1864 | --minimum-ttl=<ttl> Minimum TTL for records to migrate \ |
1938 | -d --debug Enable debugging | 1865 | [default: 3600] |
1939 | -h --help Show this screen. | 1866 | --dry-run Only try if a zone transfer is allowed |
1940 | -v --version Show version. | 1867 | -p --public Make records public on the DHT |
1868 | -s --standalone Run ascension once | ||
1869 | -d --debug Enable debugging | ||
1870 | -h --help Show this screen. | ||
1871 | -v --version Show version. | ||
1941 | @end example | 1872 | @end example |
1942 | 1873 | ||
1943 | Before you can migrate any zone though, you need to start the GNUnet peer: | 1874 | Before you can migrate any zone though, you need to start a local GNUnet peer: |
1944 | @example | 1875 | @example |
1945 | $ gnunet-arm -s | 1876 | $ gnunet-arm -s |
1946 | @end example | 1877 | @end example |
1947 | 1878 | ||
1948 | To migrate the Syrian top level domain - one of the few top level domains that | 1879 | To migrate the Syrian top level domain - one of the few top level domains that |
1949 | still supports zone transfers - into GNS use the following command: | 1880 | support zone transfers - into GNS use the following command: |
1950 | 1881 | ||
1951 | @example | 1882 | @example |
1952 | $ ascension sy. -n ns1.tld.sy. -p | 1883 | $ 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 | |||
1959 | will refresh the zone after the time has elapsed. You can resolve the names in | 1890 | will refresh the zone after the time has elapsed. You can resolve the names in |
1960 | the zone directly using GNS or if you want to use it with your browser, check | 1891 | the zone directly using GNS or if you want to use it with your browser, check |
1961 | out the GNS manual section. @ref{Configuring the GNU Name System}. To resolve | 1892 | out the GNS manual section. @ref{Configuring the GNU Name System}. To resolve |
1962 | the records from another system you need the zone PKEY. To get the zone key, | 1893 | the records from another system you need the respective zones PKEY. To get the |
1963 | you can run the following command: | 1894 | zones public key, you can run the following command: |
1964 | 1895 | ||
1965 | @example | 1896 | @example |
1966 | $ gnunet-identity -d | grep ^sy | cut -d " " -f3 | 1897 | $ gnunet-identity -dqe sy |
1967 | @end example | 1898 | @end example |
1968 | 1899 | ||
1969 | Where "sy" is the name of the zone you want to migrate. | 1900 | Where "sy" is the name of the zone you want to migrate. |
1970 | 1901 | ||
1971 | As soon as the public flag is implemented, you can share the PKEY of the zone | 1902 | You can share the PKEY of the zone with your friends. They can then resolve |
1972 | with your friends. They can then resolve records in the zone by doing a lookup | 1903 | records in the zone by doing a lookup replacing the zone label with your PKEY: |
1973 | replacing the zone label with your PKEY: | ||
1974 | 1904 | ||
1975 | @example | 1905 | @example |
1976 | $ gnunet-gns -t SOA -u "@.$PKEY" | 1906 | $ gnunet-gns -t SOA -u "$PKEY" |
1977 | @end example | 1907 | @end example |
1978 | 1908 | ||
1979 | The program will continue to run as a daemon and update once the refresh time | 1909 | The program will continue to run as a daemon and update once the refresh time |
1980 | specified in the zones SOA record has elapsed. | 1910 | specified in the zones SOA record has elapsed. |
1981 | 1911 | ||
1982 | The next step would be to add the PKEY record as a DNScurve style NS record | 1912 | DNSCurve style records are supported in the latest release and they are added |
1983 | into the existing DNS zone to enable clients to detect that this zone has | 1913 | as a PKEY record to be referred to the respective GNS public key. Key |
1984 | already been migrated to GNS and to also have a means of distributing the PKEY | 1914 | distribution is still a problem but provided someone else has a public key |
1985 | seamlessly. | 1915 | under a given label it can be looked up. |
1916 | |||
1917 | There is an unofficial Debian package called python3-ascension that adds a | ||
1918 | system user ascension and runs a GNUnet peer in the background. | ||
1986 | 1919 | ||
1987 | At this point you might want to write for example a systemd unit file to start | 1920 | Ascension-bind is also an unofficial Debian package that on installation checks |
1988 | and enable the service, so that your zone is migrated automatically. | 1921 | for running DNS zones and whether or not they are transferable using DNS zone |
1922 | transfer (AXFR). It asks the administrator which zones to migrate into GNS and | ||
1923 | installs a systemd unit file to keep the zone up to date. If you want to | ||
1924 | migrate different zones you might want to check the unit file from the package | ||
1925 | as a guide. | ||
1989 | 1926 | ||
1990 | @node reclaimID Identity Provider | 1927 | @node reclaimID Identity Provider |
1991 | @section reclaimID Identity Provider | 1928 | @section reclaimID Identity Provider |
diff --git a/doc/handbook/images/ascension_interaction.png b/doc/handbook/images/ascension_interaction.png new file mode 100644 index 000000000..84e2e9c0f --- /dev/null +++ b/doc/handbook/images/ascension_interaction.png | |||
Binary files differ | |||
diff --git a/doc/handbook/images/ascension_ssd.png b/doc/handbook/images/ascension_ssd.png new file mode 100644 index 000000000..3b142ab31 --- /dev/null +++ b/doc/handbook/images/ascension_ssd.png | |||
Binary files differ | |||
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 @@ | |||
30 | manipulate GNUnet configuration files | 30 | manipulate GNUnet configuration files |
31 | .Sh SYNOPSIS | 31 | .Sh SYNOPSIS |
32 | .Nm | 32 | .Nm |
33 | .Op Fl b Ar BACKEND | Fl \-supported-backend= Ns Ar BACKEND | ||
33 | .Op Fl c Ar FILENAME | Fl \-config= Ns Ar FILENAME | 34 | .Op Fl c Ar FILENAME | Fl \-config= Ns Ar FILENAME |
34 | .Op Fl f | \-filename | 35 | .Op Fl f | \-filename |
35 | .Op Fl h | \-help | 36 | .Op Fl h | \-help |
@@ -44,6 +45,8 @@ manipulate GNUnet configuration files | |||
44 | .Nm | 45 | .Nm |
45 | can be used to read or modify GNUnet configuration files. | 46 | can be used to read or modify GNUnet configuration files. |
46 | .Bl -tag -width indent | 47 | .Bl -tag -width indent |
48 | .It Fl b Ar BACKEND | Fl \-supported-backend= Ns Ar BACKEND | ||
49 | 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). | ||
47 | .It Fl c Ar FILENAME | Fl \-config= Ns Ar FILENAME | 50 | .It Fl c Ar FILENAME | Fl \-config= Ns Ar FILENAME |
48 | Use the configuration file FILENAME. | 51 | Use the configuration file FILENAME. |
49 | .It Fl f | \-filename | 52 | .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 @@ | |||
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "arm.h" | 31 | #include "arm.h" |
32 | 32 | ||
33 | #define LOG(kind,...) GNUNET_log_from (kind, "arm-api",__VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from (kind, "arm-api", __VA_ARGS__) |
34 | 34 | ||
35 | 35 | ||
36 | /** | 36 | /** |
@@ -156,7 +156,6 @@ struct GNUNET_ARM_Handle | |||
156 | * Have we detected that ARM is up? | 156 | * Have we detected that ARM is up? |
157 | */ | 157 | */ |
158 | int currently_up; | 158 | int currently_up; |
159 | |||
160 | }; | 159 | }; |
161 | 160 | ||
162 | 161 | ||
@@ -204,27 +203,19 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h) | |||
204 | h->currently_up = GNUNET_NO; | 203 | h->currently_up = GNUNET_NO; |
205 | GNUNET_assert (NULL == h->reconnect_task); | 204 | GNUNET_assert (NULL == h->reconnect_task); |
206 | h->reconnect_task = | 205 | h->reconnect_task = |
207 | GNUNET_SCHEDULER_add_delayed (h->retry_backoff, | 206 | GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h); |
208 | &reconnect_arm_task, | ||
209 | h); | ||
210 | while (NULL != (op = h->operation_pending_head)) | 207 | while (NULL != (op = h->operation_pending_head)) |
211 | { | 208 | { |
212 | if (NULL != op->result_cont) | 209 | if (NULL != op->result_cont) |
213 | op->result_cont (op->cont_cls, | 210 | op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); |
214 | GNUNET_ARM_REQUEST_DISCONNECTED, | ||
215 | 0); | ||
216 | if (NULL != op->list_cont) | 211 | if (NULL != op->list_cont) |
217 | op->list_cont (op->cont_cls, | 212 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); |
218 | GNUNET_ARM_REQUEST_DISCONNECTED, | ||
219 | 0, | ||
220 | NULL); | ||
221 | GNUNET_ARM_operation_cancel (op); | 213 | GNUNET_ARM_operation_cancel (op); |
222 | } | 214 | } |
223 | GNUNET_assert (NULL == h->operation_pending_head); | 215 | GNUNET_assert (NULL == h->operation_pending_head); |
224 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | 216 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); |
225 | if (NULL != h->conn_status) | 217 | if (NULL != h->conn_status) |
226 | h->conn_status (h->conn_status_cls, | 218 | h->conn_status (h->conn_status_cls, GNUNET_NO); |
227 | GNUNET_NO); | ||
228 | } | 219 | } |
229 | 220 | ||
230 | 221 | ||
@@ -236,12 +227,12 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h) | |||
236 | * @return NULL if not found | 227 | * @return NULL if not found |
237 | */ | 228 | */ |
238 | static struct GNUNET_ARM_Operation * | 229 | static struct GNUNET_ARM_Operation * |
239 | find_op_by_id (struct GNUNET_ARM_Handle *h, | 230 | find_op_by_id (struct GNUNET_ARM_Handle *h, uint64_t id) |
240 | uint64_t id) | ||
241 | { | 231 | { |
242 | struct GNUNET_ARM_Operation *result; | 232 | struct GNUNET_ARM_Operation *result; |
243 | 233 | ||
244 | for (result = h->operation_pending_head; NULL != result; result = result->next) | 234 | for (result = h->operation_pending_head; NULL != result; |
235 | result = result->next) | ||
245 | if (id == result->id) | 236 | if (id == result->id) |
246 | return result; | 237 | return result; |
247 | return NULL; | 238 | return NULL; |
@@ -255,8 +246,7 @@ find_op_by_id (struct GNUNET_ARM_Handle *h, | |||
255 | * @param res the message received from the arm service | 246 | * @param res the message received from the arm service |
256 | */ | 247 | */ |
257 | static void | 248 | static void |
258 | handle_arm_result (void *cls, | 249 | handle_arm_result (void *cls, const struct GNUNET_ARM_ResultMessage *res) |
259 | const struct GNUNET_ARM_ResultMessage *res) | ||
260 | { | 250 | { |
261 | struct GNUNET_ARM_Handle *h = cls; | 251 | struct GNUNET_ARM_Handle *h = cls; |
262 | struct GNUNET_ARM_Operation *op; | 252 | struct GNUNET_ARM_Operation *op; |
@@ -266,8 +256,7 @@ handle_arm_result (void *cls, | |||
266 | void *result_cont_cls; | 256 | void *result_cont_cls; |
267 | 257 | ||
268 | id = GNUNET_ntohll (res->arm_msg.request_id); | 258 | id = GNUNET_ntohll (res->arm_msg.request_id); |
269 | op = find_op_by_id (h, | 259 | op = find_op_by_id (h, id); |
270 | id); | ||
271 | if (NULL == op) | 260 | if (NULL == op) |
272 | { | 261 | { |
273 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 262 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -277,8 +266,7 @@ handle_arm_result (void *cls, | |||
277 | } | 266 | } |
278 | 267 | ||
279 | result = (enum GNUNET_ARM_Result) ntohl (res->result); | 268 | result = (enum GNUNET_ARM_Result) ntohl (res->result); |
280 | if ( (GNUNET_YES == op->is_arm_stop) && | 269 | if ((GNUNET_YES == op->is_arm_stop) && (GNUNET_ARM_RESULT_STOPPING == result)) |
281 | (GNUNET_ARM_RESULT_STOPPING == result) ) | ||
282 | { | 270 | { |
283 | /* special case: if we are stopping 'gnunet-service-arm', we do not just | 271 | /* special case: if we are stopping 'gnunet-service-arm', we do not just |
284 | wait for the result message, but also wait for the service to close | 272 | wait for the result message, but also wait for the service to close |
@@ -289,8 +277,8 @@ handle_arm_result (void *cls, | |||
289 | { | 277 | { |
290 | GNUNET_break (0); | 278 | GNUNET_break (0); |
291 | op->result_cont (h->thm->cont_cls, | 279 | op->result_cont (h->thm->cont_cls, |
292 | GNUNET_ARM_REQUEST_SENT_OK, | 280 | GNUNET_ARM_REQUEST_SENT_OK, |
293 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); | 281 | GNUNET_ARM_RESULT_IS_NOT_KNOWN); |
294 | GNUNET_free (h->thm); | 282 | GNUNET_free (h->thm); |
295 | } | 283 | } |
296 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | 284 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, |
@@ -303,9 +291,7 @@ handle_arm_result (void *cls, | |||
303 | result_cont_cls = op->cont_cls; | 291 | result_cont_cls = op->cont_cls; |
304 | GNUNET_ARM_operation_cancel (op); | 292 | GNUNET_ARM_operation_cancel (op); |
305 | if (NULL != result_cont) | 293 | if (NULL != result_cont) |
306 | result_cont (result_cont_cls, | 294 | result_cont (result_cont_cls, GNUNET_ARM_REQUEST_SENT_OK, result); |
307 | GNUNET_ARM_REQUEST_SENT_OK, | ||
308 | result); | ||
309 | } | 295 | } |
310 | 296 | ||
311 | 297 | ||
@@ -325,6 +311,7 @@ check_arm_list_result (void *cls, | |||
325 | uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres); | 311 | uint16_t msize = ntohs (lres->arm_msg.header.size) - sizeof (*lres); |
326 | uint16_t size_check; | 312 | uint16_t size_check; |
327 | 313 | ||
314 | (void) cls; | ||
328 | size_check = 0; | 315 | size_check = 0; |
329 | for (unsigned int i = 0; i < rcount; i++) | 316 | for (unsigned int i = 0; i < rcount; i++) |
330 | { | 317 | { |
@@ -361,8 +348,7 @@ handle_arm_list_result (void *cls, | |||
361 | uint64_t id; | 348 | uint64_t id; |
362 | 349 | ||
363 | id = GNUNET_ntohll (lres->arm_msg.request_id); | 350 | id = GNUNET_ntohll (lres->arm_msg.request_id); |
364 | op = find_op_by_id (h, | 351 | op = find_op_by_id (h, id); |
365 | id); | ||
366 | if (NULL == op) | 352 | if (NULL == op) |
367 | { | 353 | { |
368 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 354 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -373,9 +359,7 @@ handle_arm_list_result (void *cls, | |||
373 | size_check = 0; | 359 | size_check = 0; |
374 | for (unsigned int i = 0; i < rcount; i++) | 360 | for (unsigned int i = 0; i < rcount; i++) |
375 | { | 361 | { |
376 | const char *end = memchr (pos, | 362 | const char *end = memchr (pos, 0, msize - size_check); |
377 | 0, | ||
378 | msize - size_check); | ||
379 | 363 | ||
380 | /* Assert, as this was already checked in #check_arm_list_result() */ | 364 | /* Assert, as this was already checked in #check_arm_list_result() */ |
381 | GNUNET_assert (NULL != end); | 365 | GNUNET_assert (NULL != end); |
@@ -384,10 +368,7 @@ handle_arm_list_result (void *cls, | |||
384 | pos = end + 1; | 368 | pos = end + 1; |
385 | } | 369 | } |
386 | if (NULL != op->list_cont) | 370 | if (NULL != op->list_cont) |
387 | op->list_cont (op->cont_cls, | 371 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount, list); |
388 | GNUNET_ARM_REQUEST_SENT_OK, | ||
389 | rcount, | ||
390 | list); | ||
391 | GNUNET_ARM_operation_cancel (op); | 372 | GNUNET_ARM_operation_cancel (op); |
392 | } | 373 | } |
393 | 374 | ||
@@ -399,19 +380,17 @@ handle_arm_list_result (void *cls, | |||
399 | * @param msg message received | 380 | * @param msg message received |
400 | */ | 381 | */ |
401 | static void | 382 | static void |
402 | handle_confirm (void *cls, | 383 | handle_confirm (void *cls, const struct GNUNET_MessageHeader *msg) |
403 | const struct GNUNET_MessageHeader *msg) | ||
404 | { | 384 | { |
405 | struct GNUNET_ARM_Handle *h = cls; | 385 | struct GNUNET_ARM_Handle *h = cls; |
406 | 386 | ||
407 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 387 | (void) msg; |
408 | "Got confirmation from ARM that we are up!\n"); | 388 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got confirmation from ARM that we are up!\n"); |
409 | if (GNUNET_NO == h->currently_up) | 389 | if (GNUNET_NO == h->currently_up) |
410 | { | 390 | { |
411 | h->currently_up = GNUNET_YES; | 391 | h->currently_up = GNUNET_YES; |
412 | if (NULL != h->conn_status) | 392 | if (NULL != h->conn_status) |
413 | h->conn_status (h->conn_status_cls, | 393 | h->conn_status (h->conn_status_cls, GNUNET_YES); |
414 | GNUNET_YES); | ||
415 | } | 394 | } |
416 | } | 395 | } |
417 | 396 | ||
@@ -425,19 +404,19 @@ handle_confirm (void *cls, | |||
425 | * @param error error code | 404 | * @param error error code |
426 | */ | 405 | */ |
427 | static void | 406 | static void |
428 | mq_error_handler (void *cls, | 407 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
429 | enum GNUNET_MQ_Error error) | ||
430 | { | 408 | { |
431 | struct GNUNET_ARM_Handle *h = cls; | 409 | struct GNUNET_ARM_Handle *h = cls; |
432 | struct GNUNET_ARM_Operation *op; | 410 | struct GNUNET_ARM_Operation *op; |
433 | 411 | ||
412 | (void) error; | ||
434 | h->currently_up = GNUNET_NO; | 413 | h->currently_up = GNUNET_NO; |
435 | if (NULL != (op = h->thm)) | 414 | if (NULL != (op = h->thm)) |
436 | { | 415 | { |
437 | h->thm = NULL; | 416 | h->thm = NULL; |
438 | op->result_cont (op->cont_cls, | 417 | op->result_cont (op->cont_cls, |
439 | GNUNET_ARM_REQUEST_SENT_OK, | 418 | GNUNET_ARM_REQUEST_SENT_OK, |
440 | GNUNET_ARM_RESULT_STOPPED); | 419 | GNUNET_ARM_RESULT_STOPPED); |
441 | GNUNET_free (op); | 420 | GNUNET_free (op); |
442 | } | 421 | } |
443 | reconnect_arm_later (h); | 422 | reconnect_arm_later (h); |
@@ -453,47 +432,37 @@ mq_error_handler (void *cls, | |||
453 | static int | 432 | static int |
454 | reconnect_arm (struct GNUNET_ARM_Handle *h) | 433 | reconnect_arm (struct GNUNET_ARM_Handle *h) |
455 | { | 434 | { |
456 | struct GNUNET_MQ_MessageHandler handlers[] = { | 435 | struct GNUNET_MQ_MessageHandler handlers[] = |
457 | GNUNET_MQ_hd_fixed_size (arm_result, | 436 | {GNUNET_MQ_hd_fixed_size (arm_result, |
458 | GNUNET_MESSAGE_TYPE_ARM_RESULT, | 437 | GNUNET_MESSAGE_TYPE_ARM_RESULT, |
459 | struct GNUNET_ARM_ResultMessage, | 438 | struct GNUNET_ARM_ResultMessage, |
460 | h), | 439 | h), |
461 | GNUNET_MQ_hd_var_size (arm_list_result, | 440 | GNUNET_MQ_hd_var_size (arm_list_result, |
462 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, | 441 | GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, |
463 | struct GNUNET_ARM_ListResultMessage, | 442 | struct GNUNET_ARM_ListResultMessage, |
464 | h), | 443 | h), |
465 | GNUNET_MQ_hd_fixed_size (confirm, | 444 | GNUNET_MQ_hd_fixed_size (confirm, |
466 | GNUNET_MESSAGE_TYPE_ARM_TEST, | 445 | GNUNET_MESSAGE_TYPE_ARM_TEST, |
467 | struct GNUNET_MessageHeader, | 446 | struct GNUNET_MessageHeader, |
468 | h), | 447 | h), |
469 | GNUNET_MQ_handler_end () | 448 | GNUNET_MQ_handler_end ()}; |
470 | }; | ||
471 | struct GNUNET_MessageHeader *test; | 449 | struct GNUNET_MessageHeader *test; |
472 | struct GNUNET_MQ_Envelope *env; | 450 | struct GNUNET_MQ_Envelope *env; |
473 | 451 | ||
474 | if (NULL != h->mq) | 452 | if (NULL != h->mq) |
475 | return GNUNET_OK; | 453 | return GNUNET_OK; |
476 | GNUNET_assert (GNUNET_NO == h->currently_up); | 454 | GNUNET_assert (GNUNET_NO == h->currently_up); |
477 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 455 | h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); |
478 | "arm", | ||
479 | handlers, | ||
480 | &mq_error_handler, | ||
481 | h); | ||
482 | if (NULL == h->mq) | 456 | if (NULL == h->mq) |
483 | { | 457 | { |
484 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 458 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CLIENT_connect returned NULL\n"); |
485 | "GNUNET_CLIENT_connect returned NULL\n"); | ||
486 | if (NULL != h->conn_status) | 459 | if (NULL != h->conn_status) |
487 | h->conn_status (h->conn_status_cls, | 460 | h->conn_status (h->conn_status_cls, GNUNET_SYSERR); |
488 | GNUNET_SYSERR); | ||
489 | return GNUNET_SYSERR; | 461 | return GNUNET_SYSERR; |
490 | } | 462 | } |
491 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 463 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending TEST message to ARM\n"); |
492 | "Sending TEST message to ARM\n"); | 464 | env = GNUNET_MQ_msg (test, GNUNET_MESSAGE_TYPE_ARM_TEST); |
493 | env = GNUNET_MQ_msg (test, | 465 | GNUNET_MQ_send (h->mq, env); |
494 | GNUNET_MESSAGE_TYPE_ARM_TEST); | ||
495 | GNUNET_MQ_send (h->mq, | ||
496 | env); | ||
497 | return GNUNET_OK; | 466 | return GNUNET_OK; |
498 | } | 467 | } |
499 | 468 | ||
@@ -512,7 +481,7 @@ reconnect_arm (struct GNUNET_ARM_Handle *h) | |||
512 | struct GNUNET_ARM_Handle * | 481 | struct GNUNET_ARM_Handle * |
513 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 482 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
514 | GNUNET_ARM_ConnectionStatusCallback conn_status, | 483 | GNUNET_ARM_ConnectionStatusCallback conn_status, |
515 | void *conn_status_cls) | 484 | void *conn_status_cls) |
516 | { | 485 | { |
517 | struct GNUNET_ARM_Handle *h; | 486 | struct GNUNET_ARM_Handle *h; |
518 | 487 | ||
@@ -539,22 +508,16 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h) | |||
539 | { | 508 | { |
540 | struct GNUNET_ARM_Operation *op; | 509 | struct GNUNET_ARM_Operation *op; |
541 | 510 | ||
542 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 511 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); |
543 | "Disconnecting from ARM service\n"); | ||
544 | while (NULL != (op = h->operation_pending_head)) | 512 | while (NULL != (op = h->operation_pending_head)) |
545 | { | 513 | { |
546 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, | 514 | GNUNET_CONTAINER_DLL_remove (h->operation_pending_head, |
547 | h->operation_pending_tail, | 515 | h->operation_pending_tail, |
548 | op); | 516 | op); |
549 | if (NULL != op->result_cont) | 517 | if (NULL != op->result_cont) |
550 | op->result_cont (op->cont_cls, | 518 | op->result_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0); |
551 | GNUNET_ARM_REQUEST_DISCONNECTED, | ||
552 | 0); | ||
553 | if (NULL != op->list_cont) | 519 | if (NULL != op->list_cont) |
554 | op->list_cont (op->cont_cls, | 520 | op->list_cont (op->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED, 0, NULL); |
555 | GNUNET_ARM_REQUEST_DISCONNECTED, | ||
556 | 0, | ||
557 | NULL); | ||
558 | if (NULL != op->async) | 521 | if (NULL != op->async) |
559 | { | 522 | { |
560 | GNUNET_SCHEDULER_cancel (op->async); | 523 | GNUNET_SCHEDULER_cancel (op->async); |
@@ -596,60 +559,43 @@ start_arm_service (struct GNUNET_ARM_Handle *h, | |||
596 | char *loprefix; | 559 | char *loprefix; |
597 | char *lopostfix; | 560 | char *lopostfix; |
598 | 561 | ||
599 | if (GNUNET_OK != | 562 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, |
600 | GNUNET_CONFIGURATION_get_value_string (h->cfg, | 563 | "arm", |
601 | "arm", | 564 | "PREFIX", |
602 | "PREFIX", | 565 | &loprefix)) |
603 | &loprefix)) | ||
604 | loprefix = GNUNET_strdup (""); | 566 | loprefix = GNUNET_strdup (""); |
605 | else | 567 | else |
606 | loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, | 568 | loprefix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, loprefix); |
607 | loprefix); | 569 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (h->cfg, |
608 | if (GNUNET_OK != | 570 | "arm", |
609 | GNUNET_CONFIGURATION_get_value_string (h->cfg, | 571 | "OPTIONS", |
610 | "arm", | 572 | &lopostfix)) |
611 | "OPTIONS", | ||
612 | &lopostfix)) | ||
613 | lopostfix = GNUNET_strdup (""); | 573 | lopostfix = GNUNET_strdup (""); |
614 | else | 574 | else |
615 | lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, | 575 | lopostfix = GNUNET_CONFIGURATION_expand_dollar (h->cfg, lopostfix); |
616 | lopostfix); | ||
617 | if (GNUNET_OK != | 576 | if (GNUNET_OK != |
618 | GNUNET_CONFIGURATION_get_value_string (h->cfg, | 577 | GNUNET_CONFIGURATION_get_value_string (h->cfg, "arm", "BINARY", &cbinary)) |
619 | "arm", | ||
620 | "BINARY", | ||
621 | &cbinary)) | ||
622 | { | 578 | { |
623 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, | 579 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); |
624 | "arm", | ||
625 | "BINARY"); | ||
626 | GNUNET_free (loprefix); | 580 | GNUNET_free (loprefix); |
627 | GNUNET_free (lopostfix); | 581 | GNUNET_free (lopostfix); |
628 | return GNUNET_ARM_RESULT_IS_NOT_KNOWN; | 582 | return GNUNET_ARM_RESULT_IS_NOT_KNOWN; |
629 | } | 583 | } |
630 | if (GNUNET_OK != | 584 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, |
631 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, | 585 | "arm", |
632 | "arm", | 586 | "CONFIG", |
633 | "CONFIG", | 587 | &config)) |
634 | &config)) | ||
635 | config = NULL; | 588 | config = NULL; |
636 | binary = GNUNET_OS_get_libexec_binary_path (cbinary); | 589 | binary = GNUNET_OS_get_libexec_binary_path (cbinary); |
637 | GNUNET_asprintf ("edbinary, | 590 | GNUNET_asprintf ("edbinary, "\"%s\"", binary); |
638 | "\"%s\"", | ||
639 | binary); | ||
640 | GNUNET_free (cbinary); | 591 | GNUNET_free (cbinary); |
641 | if ( (GNUNET_YES == | 592 | if ((GNUNET_YES == |
642 | GNUNET_CONFIGURATION_have_value (h->cfg, | 593 | GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "WEAKRANDOM")) && |
643 | "TESTING", | 594 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (h->cfg, |
644 | "WEAKRANDOM")) && | 595 | "TESTING", |
645 | (GNUNET_YES == | 596 | "WEAKRANDOM")) && |
646 | GNUNET_CONFIGURATION_get_value_yesno (h->cfg, | 597 | (GNUNET_NO == |
647 | "TESTING", | 598 | GNUNET_CONFIGURATION_have_value (h->cfg, "TESTING", "HOSTFILE"))) |
648 | "WEAKRANDOM")) && | ||
649 | (GNUNET_NO == | ||
650 | GNUNET_CONFIGURATION_have_value (h->cfg, | ||
651 | "TESTING", | ||
652 | "HOSTFILE"))) | ||
653 | { | 599 | { |
654 | /* Means we are ONLY running locally */ | 600 | /* Means we are ONLY running locally */ |
655 | /* we're clearly running a test, don't daemonize */ | 601 | /* we're clearly running a test, don't daemonize */ |
@@ -668,7 +614,8 @@ start_arm_service (struct GNUNET_ARM_Handle *h, | |||
668 | NULL, | 614 | NULL, |
669 | loprefix, | 615 | loprefix, |
670 | quotedbinary, | 616 | quotedbinary, |
671 | "-c", config, | 617 | "-c", |
618 | config, | ||
672 | /* no daemonization! */ | 619 | /* no daemonization! */ |
673 | lopostfix, | 620 | lopostfix, |
674 | NULL); | 621 | NULL); |
@@ -683,14 +630,15 @@ start_arm_service (struct GNUNET_ARM_Handle *h, | |||
683 | quotedbinary, | 630 | quotedbinary, |
684 | "-d", /* do daemonize */ | 631 | "-d", /* do daemonize */ |
685 | lopostfix, | 632 | lopostfix, |
686 | NULL); | 633 | NULL); |
687 | else | 634 | else |
688 | proc = GNUNET_OS_start_process_s (GNUNET_NO, | 635 | proc = GNUNET_OS_start_process_s (GNUNET_NO, |
689 | std_inheritance, | 636 | std_inheritance, |
690 | NULL, | 637 | NULL, |
691 | loprefix, | 638 | loprefix, |
692 | quotedbinary, | 639 | quotedbinary, |
693 | "-c", config, | 640 | "-c", |
641 | config, | ||
694 | "-d", /* do daemonize */ | 642 | "-d", /* do daemonize */ |
695 | lopostfix, | 643 | lopostfix, |
696 | NULL); | 644 | NULL); |
@@ -744,7 +692,7 @@ static struct GNUNET_ARM_Operation * | |||
744 | change_service (struct GNUNET_ARM_Handle *h, | 692 | change_service (struct GNUNET_ARM_Handle *h, |
745 | const char *service_name, | 693 | const char *service_name, |
746 | GNUNET_ARM_ResultCallback cb, | 694 | GNUNET_ARM_ResultCallback cb, |
747 | void *cb_cls, | 695 | void *cb_cls, |
748 | uint16_t type) | 696 | uint16_t type) |
749 | { | 697 | { |
750 | struct GNUNET_ARM_Operation *op; | 698 | struct GNUNET_ARM_Operation *op; |
@@ -753,8 +701,7 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
753 | struct GNUNET_ARM_Message *msg; | 701 | struct GNUNET_ARM_Message *msg; |
754 | 702 | ||
755 | slen = strlen (service_name) + 1; | 703 | slen = strlen (service_name) + 1; |
756 | if (slen + sizeof (struct GNUNET_ARM_Message) >= | 704 | if (slen + sizeof (struct GNUNET_ARM_Message) >= GNUNET_MAX_MESSAGE_SIZE) |
757 | GNUNET_MAX_MESSAGE_SIZE) | ||
758 | { | 705 | { |
759 | GNUNET_break (0); | 706 | GNUNET_break (0); |
760 | return NULL; | 707 | return NULL; |
@@ -769,16 +716,11 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
769 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 716 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, |
770 | h->operation_pending_tail, | 717 | h->operation_pending_tail, |
771 | op); | 718 | op); |
772 | env = GNUNET_MQ_msg_extra (msg, | 719 | env = GNUNET_MQ_msg_extra (msg, slen, type); |
773 | slen, | ||
774 | type); | ||
775 | msg->reserved = htonl (0); | 720 | msg->reserved = htonl (0); |
776 | msg->request_id = GNUNET_htonll (op->id); | 721 | msg->request_id = GNUNET_htonll (op->id); |
777 | GNUNET_memcpy (&msg[1], | 722 | GNUNET_memcpy (&msg[1], service_name, slen); |
778 | service_name, | 723 | GNUNET_MQ_send (h->mq, env); |
779 | slen); | ||
780 | GNUNET_MQ_send (h->mq, | ||
781 | env); | ||
782 | return op; | 724 | return op; |
783 | } | 725 | } |
784 | 726 | ||
@@ -802,10 +744,8 @@ notify_running (void *cls) | |||
802 | op->result_cont (op->cont_cls, | 744 | op->result_cont (op->cont_cls, |
803 | GNUNET_ARM_REQUEST_SENT_OK, | 745 | GNUNET_ARM_REQUEST_SENT_OK, |
804 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); | 746 | GNUNET_ARM_RESULT_IS_STARTED_ALREADY); |
805 | if ( (GNUNET_YES == h->currently_up) && | 747 | if ((GNUNET_YES == h->currently_up) && (NULL != h->conn_status)) |
806 | (NULL != h->conn_status) ) | 748 | h->conn_status (h->conn_status_cls, GNUNET_YES); |
807 | h->conn_status (h->conn_status_cls, | ||
808 | GNUNET_YES); | ||
809 | GNUNET_free (op); | 749 | GNUNET_free (op); |
810 | } | 750 | } |
811 | 751 | ||
@@ -846,20 +786,18 @@ notify_starting (void *cls) | |||
846 | * @return handle for the operation, NULL on error | 786 | * @return handle for the operation, NULL on error |
847 | */ | 787 | */ |
848 | struct GNUNET_ARM_Operation * | 788 | struct GNUNET_ARM_Operation * |
849 | GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, | 789 | GNUNET_ARM_request_service_start ( |
850 | const char *service_name, | 790 | struct GNUNET_ARM_Handle *h, |
851 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | 791 | const char *service_name, |
852 | GNUNET_ARM_ResultCallback cont, | 792 | enum GNUNET_OS_InheritStdioFlags std_inheritance, |
853 | void *cont_cls) | 793 | GNUNET_ARM_ResultCallback cont, |
794 | void *cont_cls) | ||
854 | { | 795 | { |
855 | struct GNUNET_ARM_Operation *op; | 796 | struct GNUNET_ARM_Operation *op; |
856 | enum GNUNET_ARM_Result ret; | 797 | enum GNUNET_ARM_Result ret; |
857 | 798 | ||
858 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 799 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting service `%s'\n", service_name); |
859 | "Starting service `%s'\n", | 800 | if (0 != strcasecmp ("arm", service_name)) |
860 | service_name); | ||
861 | if (0 != strcasecmp ("arm", | ||
862 | service_name)) | ||
863 | return change_service (h, | 801 | return change_service (h, |
864 | service_name, | 802 | service_name, |
865 | cont, | 803 | cont, |
@@ -874,8 +812,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, | |||
874 | */ | 812 | */ |
875 | if (GNUNET_YES == h->currently_up) | 813 | if (GNUNET_YES == h->currently_up) |
876 | { | 814 | { |
877 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 815 | LOG (GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n"); |
878 | "ARM is already running\n"); | ||
879 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 816 | op = GNUNET_new (struct GNUNET_ARM_Operation); |
880 | op->h = h; | 817 | op->h = h; |
881 | op->result_cont = cont; | 818 | op->result_cont = cont; |
@@ -883,8 +820,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, | |||
883 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 820 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, |
884 | h->operation_pending_tail, | 821 | h->operation_pending_tail, |
885 | op); | 822 | op); |
886 | op->async = GNUNET_SCHEDULER_add_now (¬ify_running, | 823 | op->async = GNUNET_SCHEDULER_add_now (¬ify_running, op); |
887 | op); | ||
888 | return op; | 824 | return op; |
889 | } | 825 | } |
890 | /* This is an inherently uncertain choice, as it is of course | 826 | /* 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, | |||
893 | are unlikely to hammer 'gnunet-arm -s' on a busy system, | 829 | are unlikely to hammer 'gnunet-arm -s' on a busy system, |
894 | the above check should catch 99.99% of the cases where ARM | 830 | the above check should catch 99.99% of the cases where ARM |
895 | is already running. */ | 831 | is already running. */ |
896 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 832 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting ARM service\n"); |
897 | "Starting ARM service\n"); | 833 | ret = start_arm_service (h, std_inheritance); |
898 | ret = start_arm_service (h, | ||
899 | std_inheritance); | ||
900 | if (GNUNET_ARM_RESULT_STARTING == ret) | 834 | if (GNUNET_ARM_RESULT_STARTING == ret) |
901 | reconnect_arm (h); | 835 | reconnect_arm (h); |
902 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 836 | op = GNUNET_new (struct GNUNET_ARM_Operation); |
@@ -907,8 +841,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, | |||
907 | h->operation_pending_tail, | 841 | h->operation_pending_tail, |
908 | op); | 842 | op); |
909 | op->starting_ret = ret; | 843 | op->starting_ret = ret; |
910 | op->async = GNUNET_SCHEDULER_add_now (¬ify_starting, | 844 | op->async = GNUNET_SCHEDULER_add_now (¬ify_starting, op); |
911 | op); | ||
912 | return op; | 845 | return op; |
913 | } | 846 | } |
914 | 847 | ||
@@ -929,15 +862,13 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h, | |||
929 | */ | 862 | */ |
930 | struct GNUNET_ARM_Operation * | 863 | struct GNUNET_ARM_Operation * |
931 | GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, | 864 | GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, |
932 | const char *service_name, | 865 | const char *service_name, |
933 | GNUNET_ARM_ResultCallback cont, | 866 | GNUNET_ARM_ResultCallback cont, |
934 | void *cont_cls) | 867 | void *cont_cls) |
935 | { | 868 | { |
936 | struct GNUNET_ARM_Operation *op; | 869 | struct GNUNET_ARM_Operation *op; |
937 | 870 | ||
938 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 871 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping service `%s'\n", service_name); |
939 | "Stopping service `%s'\n", | ||
940 | service_name); | ||
941 | op = change_service (h, | 872 | op = change_service (h, |
942 | service_name, | 873 | service_name, |
943 | cont, | 874 | cont, |
@@ -947,8 +878,7 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h, | |||
947 | return NULL; | 878 | return NULL; |
948 | /* If the service is ARM, set a flag as we will use MQ errors | 879 | /* If the service is ARM, set a flag as we will use MQ errors |
949 | to detect that the process is really gone. */ | 880 | to detect that the process is really gone. */ |
950 | if (0 == strcasecmp (service_name, | 881 | if (0 == strcasecmp (service_name, "arm")) |
951 | "arm")) | ||
952 | op->is_arm_stop = GNUNET_YES; | 882 | op->is_arm_stop = GNUNET_YES; |
953 | return op; | 883 | return op; |
954 | } | 884 | } |
@@ -971,8 +901,7 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, | |||
971 | struct GNUNET_MQ_Envelope *env; | 901 | struct GNUNET_MQ_Envelope *env; |
972 | struct GNUNET_ARM_Message *msg; | 902 | struct GNUNET_ARM_Message *msg; |
973 | 903 | ||
974 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 904 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting LIST from ARM service\n"); |
975 | "Requesting LIST from ARM service\n"); | ||
976 | if (0 == h->request_id_counter) | 905 | if (0 == h->request_id_counter) |
977 | h->request_id_counter++; | 906 | h->request_id_counter++; |
978 | op = GNUNET_new (struct GNUNET_ARM_Operation); | 907 | op = GNUNET_new (struct GNUNET_ARM_Operation); |
@@ -983,12 +912,10 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h, | |||
983 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, | 912 | GNUNET_CONTAINER_DLL_insert_tail (h->operation_pending_head, |
984 | h->operation_pending_tail, | 913 | h->operation_pending_tail, |
985 | op); | 914 | op); |
986 | env = GNUNET_MQ_msg (msg, | 915 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_LIST); |
987 | GNUNET_MESSAGE_TYPE_ARM_LIST); | ||
988 | msg->reserved = htonl (0); | 916 | msg->reserved = htonl (0); |
989 | msg->request_id = GNUNET_htonll (op->id); | 917 | msg->request_id = GNUNET_htonll (op->id); |
990 | GNUNET_MQ_send (h->mq, | 918 | GNUNET_MQ_send (h->mq, env); |
991 | env); | ||
992 | return op; | 919 | return op; |
993 | } | 920 | } |
994 | 921 | ||
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 @@ | |||
32 | 32 | ||
33 | #define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 33 | #define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "arm-monitor-api",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Handle for interacting with ARM. | 38 | * Handle for interacting with ARM. |
@@ -69,7 +69,6 @@ struct GNUNET_ARM_MonitorHandle | |||
69 | * Closure for @e service_status. | 69 | * Closure for @e service_status. |
70 | */ | 70 | */ |
71 | void *service_status_cls; | 71 | void *service_status_cls; |
72 | |||
73 | }; | 72 | }; |
74 | 73 | ||
75 | 74 | ||
@@ -115,9 +114,9 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) | |||
115 | h->mq = NULL; | 114 | h->mq = NULL; |
116 | } | 115 | } |
117 | GNUNET_assert (NULL == h->reconnect_task); | 116 | GNUNET_assert (NULL == h->reconnect_task); |
118 | h->reconnect_task | 117 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, |
119 | = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, | 118 | &reconnect_arm_monitor_task, |
120 | &reconnect_arm_monitor_task, h); | 119 | h); |
121 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | 120 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); |
122 | } | 121 | } |
123 | 122 | ||
@@ -130,14 +129,14 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) | |||
130 | * @return #GNUNET_OK if the message is well-formed | 129 | * @return #GNUNET_OK if the message is well-formed |
131 | */ | 130 | */ |
132 | static int | 131 | static int |
133 | check_monitor_notify (void *cls, | 132 | check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg) |
134 | const struct GNUNET_ARM_StatusMessage *msg) | ||
135 | { | 133 | { |
136 | size_t sl = ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage); | 134 | size_t sl = |
135 | ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage); | ||
137 | const char *name = (const char *) &msg[1]; | 136 | const char *name = (const char *) &msg[1]; |
138 | 137 | ||
139 | if ( (0 == sl) || | 138 | (void) cls; |
140 | ('\0' != name[sl-1]) ) | 139 | if ((0 == sl) || ('\0' != name[sl - 1])) |
141 | { | 140 | { |
142 | GNUNET_break (0); | 141 | GNUNET_break (0); |
143 | return GNUNET_SYSERR; | 142 | return GNUNET_SYSERR; |
@@ -153,8 +152,7 @@ check_monitor_notify (void *cls, | |||
153 | * @param res the message received from the arm service | 152 | * @param res the message received from the arm service |
154 | */ | 153 | */ |
155 | static void | 154 | static void |
156 | handle_monitor_notify (void *cls, | 155 | handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res) |
157 | const struct GNUNET_ARM_StatusMessage *res) | ||
158 | { | 156 | { |
159 | struct GNUNET_ARM_MonitorHandle *h = cls; | 157 | struct GNUNET_ARM_MonitorHandle *h = cls; |
160 | enum GNUNET_ARM_ServiceStatus status; | 158 | enum GNUNET_ARM_ServiceStatus status; |
@@ -165,9 +163,7 @@ handle_monitor_notify (void *cls, | |||
165 | (const char *) &res[1], | 163 | (const char *) &res[1], |
166 | (int) status); | 164 | (int) status); |
167 | if (NULL != h->service_status) | 165 | if (NULL != h->service_status) |
168 | h->service_status (h->service_status_cls, | 166 | h->service_status (h->service_status_cls, (const char *) &res[1], status); |
169 | (const char *) &res[1], | ||
170 | status); | ||
171 | } | 167 | } |
172 | 168 | ||
173 | 169 | ||
@@ -180,11 +176,11 @@ handle_monitor_notify (void *cls, | |||
180 | * @param error error code | 176 | * @param error error code |
181 | */ | 177 | */ |
182 | static void | 178 | static void |
183 | mq_error_handler (void *cls, | 179 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
184 | enum GNUNET_MQ_Error error) | ||
185 | { | 180 | { |
186 | struct GNUNET_ARM_MonitorHandle *h = cls; | 181 | struct GNUNET_ARM_MonitorHandle *h = cls; |
187 | 182 | ||
183 | (void) error; | ||
188 | reconnect_arm_monitor_later (h); | 184 | reconnect_arm_monitor_later (h); |
189 | } | 185 | } |
190 | 186 | ||
@@ -198,22 +194,17 @@ mq_error_handler (void *cls, | |||
198 | static int | 194 | static int |
199 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | 195 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) |
200 | { | 196 | { |
201 | struct GNUNET_MQ_MessageHandler handlers[] = { | 197 | struct GNUNET_MQ_MessageHandler handlers[] = |
202 | GNUNET_MQ_hd_var_size (monitor_notify, | 198 | {GNUNET_MQ_hd_var_size (monitor_notify, |
203 | GNUNET_MESSAGE_TYPE_ARM_STATUS, | 199 | GNUNET_MESSAGE_TYPE_ARM_STATUS, |
204 | struct GNUNET_ARM_StatusMessage, | 200 | struct GNUNET_ARM_StatusMessage, |
205 | h), | 201 | h), |
206 | GNUNET_MQ_handler_end () | 202 | GNUNET_MQ_handler_end ()}; |
207 | }; | ||
208 | struct GNUNET_MessageHeader *msg; | 203 | struct GNUNET_MessageHeader *msg; |
209 | struct GNUNET_MQ_Envelope *env; | 204 | struct GNUNET_MQ_Envelope *env; |
210 | 205 | ||
211 | GNUNET_assert (NULL == h->mq); | 206 | GNUNET_assert (NULL == h->mq); |
212 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 207 | h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); |
213 | "arm", | ||
214 | handlers, | ||
215 | &mq_error_handler, | ||
216 | h); | ||
217 | if (NULL == h->mq) | 208 | if (NULL == h->mq) |
218 | { | 209 | { |
219 | if (NULL != h->service_status) | 210 | if (NULL != h->service_status) |
@@ -222,10 +213,8 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | |||
222 | GNUNET_ARM_SERVICE_STOPPED); | 213 | GNUNET_ARM_SERVICE_STOPPED); |
223 | return GNUNET_SYSERR; | 214 | return GNUNET_SYSERR; |
224 | } | 215 | } |
225 | env = GNUNET_MQ_msg (msg, | 216 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); |
226 | GNUNET_MESSAGE_TYPE_ARM_MONITOR); | 217 | GNUNET_MQ_send (h->mq, env); |
227 | GNUNET_MQ_send (h->mq, | ||
228 | env); | ||
229 | return GNUNET_OK; | 218 | return GNUNET_OK; |
230 | } | 219 | } |
231 | 220 | ||
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 5a4acb31a..7d705733a 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c | |||
@@ -799,25 +799,26 @@ main (int argc, char *const *argv) | |||
799 | gettext_noop ("don't let gnunet-service-arm inherit standard error"), | 799 | gettext_noop ("don't let gnunet-service-arm inherit standard error"), |
800 | &no_stderr), | 800 | &no_stderr), |
801 | GNUNET_GETOPT_OPTION_END}; | 801 | GNUNET_GETOPT_OPTION_END}; |
802 | int lret; | ||
802 | 803 | ||
803 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 804 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
804 | return 2; | 805 | return 2; |
805 | if (GNUNET_OK == | 806 | if (GNUNET_OK == |
806 | GNUNET_PROGRAM_run ( | 807 | (lret = GNUNET_PROGRAM_run ( |
807 | argc, | 808 | argc, |
808 | argv, | 809 | argv, |
809 | "gnunet-arm", | 810 | "gnunet-arm", |
810 | gettext_noop ( | 811 | gettext_noop ( |
811 | "Control services and the Automated Restart Manager (ARM)"), | 812 | "Control services and the Automated Restart Manager (ARM)"), |
812 | options, | 813 | options, |
813 | &run, | 814 | &run, |
814 | NULL)) | 815 | NULL))) |
815 | { | 816 | { |
816 | GNUNET_free ((void *) argv); | 817 | GNUNET_free ((void *) argv); |
817 | return ret; | 818 | return ret; |
818 | } | 819 | } |
819 | GNUNET_free ((void *) argv); | 820 | GNUNET_free ((void *) argv); |
820 | return 1; | 821 | return lret; |
821 | } | 822 | } |
822 | 823 | ||
823 | /* end of gnunet-arm.c */ | 824 | /* end of gnunet-arm.c */ |
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; | |||
33 | * @param message the actual message | 33 | * @param message the actual message |
34 | */ | 34 | */ |
35 | static void | 35 | static void |
36 | handle_stop (void *cls, | 36 | handle_stop (void *cls, const struct GNUNET_MessageHeader *message) |
37 | const struct GNUNET_MessageHeader *message) | ||
38 | { | 37 | { |
39 | struct GNUNET_SERVICE_Client *client = cls; | 38 | struct GNUNET_SERVICE_Client *client = cls; |
40 | 39 | ||
40 | (void) message; | ||
41 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 41 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
42 | _("Initiating shutdown as requested by client.\n")); | 42 | _ ("Initiating shutdown as requested by client.\n")); |
43 | GNUNET_SERVICE_client_persist (client); | 43 | GNUNET_SERVICE_client_persist (client); |
44 | GNUNET_SCHEDULER_shutdown (); | 44 | GNUNET_SCHEDULER_shutdown (); |
45 | /* ARM won't exponentially increase restart delay if we | 45 | /* ARM won't exponentially increase restart delay if we |
@@ -59,9 +59,11 @@ handle_stop (void *cls, | |||
59 | */ | 59 | */ |
60 | static void * | 60 | static void * |
61 | client_connect_cb (void *cls, | 61 | client_connect_cb (void *cls, |
62 | struct GNUNET_SERVICE_Client *c, | 62 | struct GNUNET_SERVICE_Client *c, |
63 | struct GNUNET_MQ_Handle *mq) | 63 | struct GNUNET_MQ_Handle *mq) |
64 | { | 64 | { |
65 | (void) cls; | ||
66 | (void) mq; | ||
65 | return c; | 67 | return c; |
66 | } | 68 | } |
67 | 69 | ||
@@ -75,9 +77,10 @@ client_connect_cb (void *cls, | |||
75 | */ | 77 | */ |
76 | static void | 78 | static void |
77 | client_disconnect_cb (void *cls, | 79 | client_disconnect_cb (void *cls, |
78 | struct GNUNET_SERVICE_Client *c, | 80 | struct GNUNET_SERVICE_Client *c, |
79 | void *internal_cls) | 81 | void *internal_cls) |
80 | { | 82 | { |
83 | (void) cls; | ||
81 | GNUNET_assert (c == internal_cls); | 84 | GNUNET_assert (c == internal_cls); |
82 | } | 85 | } |
83 | 86 | ||
@@ -87,6 +90,9 @@ run (void *cls, | |||
87 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 90 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
88 | struct GNUNET_SERVICE_Handle *service) | 91 | struct GNUNET_SERVICE_Handle *service) |
89 | { | 92 | { |
93 | (void) cls; | ||
94 | (void) cfg; | ||
95 | (void) service; | ||
90 | /* nothing to do */ | 96 | /* nothing to do */ |
91 | } | 97 | } |
92 | 98 | ||
@@ -94,25 +100,20 @@ run (void *cls, | |||
94 | /** | 100 | /** |
95 | * Define "main" method using service macro. | 101 | * Define "main" method using service macro. |
96 | */ | 102 | */ |
97 | GNUNET_SERVICE_MAIN | 103 | GNUNET_SERVICE_MAIN ("do-nothing", |
98 | ("do-nothing", | 104 | GNUNET_SERVICE_OPTION_NONE, |
99 | GNUNET_SERVICE_OPTION_NONE, | 105 | &run, |
100 | &run, | 106 | &client_connect_cb, |
101 | &client_connect_cb, | 107 | &client_disconnect_cb, |
102 | &client_disconnect_cb, | 108 | NULL, |
103 | NULL, | 109 | GNUNET_MQ_hd_fixed_size (stop, |
104 | GNUNET_MQ_hd_fixed_size (stop, | 110 | GNUNET_MESSAGE_TYPE_ARM_STOP, |
105 | GNUNET_MESSAGE_TYPE_ARM_STOP, | 111 | struct GNUNET_MessageHeader, |
106 | struct GNUNET_MessageHeader, | 112 | NULL), |
107 | NULL), | 113 | GNUNET_MQ_handler_end ()); |
108 | GNUNET_MQ_handler_end ()); | ||
109 | 114 | ||
110 | 115 | ||
111 | /** | 116 | /** |
112 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 117 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
113 | */ | 118 | */ |
114 | void __attribute__ ((destructor)) | 119 | void __attribute__ ((destructor)) GNUNET_mockup_done () { _exit (special_ret); } |
115 | GNUNET_mockup_done () | ||
116 | { | ||
117 | _exit (special_ret); | ||
118 | } | ||
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h index f6cc860cc..ff3e47d19 100644 --- a/src/cadet/cadet.h +++ b/src/cadet/cadet.h | |||
@@ -27,29 +27,29 @@ | |||
27 | #define CADET_H_ | 27 | #define CADET_H_ |
28 | 28 | ||
29 | #ifdef __cplusplus | 29 | #ifdef __cplusplus |
30 | extern "C" | 30 | extern "C" { |
31 | { | 31 | #if 0 /* keep Emacsens' auto-indent happy */ |
32 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
33 | } | 32 | } |
34 | #endif | 33 | #endif |
35 | #endif | 34 | #endif |
36 | 35 | ||
37 | #include <stdint.h> | 36 | #include <stdint.h> |
38 | 37 | ||
39 | #if !defined(GNUNET_CULL_LOGGING) | 38 | #if ! defined(GNUNET_CULL_LOGGING) |
40 | #define CADET_TIMING_START \ | 39 | #define CADET_TIMING_START \ |
41 | struct GNUNET_TIME_Absolute __timestamp;\ | 40 | struct GNUNET_TIME_Absolute __timestamp; \ |
42 | __timestamp = GNUNET_TIME_absolute_get() | 41 | __timestamp = GNUNET_TIME_absolute_get () |
43 | 42 | ||
44 | #define CADET_TIMING_END \ | 43 | #define CADET_TIMING_END \ |
45 | struct GNUNET_TIME_Relative __duration;\ | 44 | struct GNUNET_TIME_Relative __duration; \ |
46 | __duration = GNUNET_TIME_absolute_get_duration (__timestamp);\ | 45 | __duration = GNUNET_TIME_absolute_get_duration (__timestamp); \ |
47 | LOG (GNUNET_ERROR_TYPE_INFO, " %s duration %s\n",\ | 46 | LOG (GNUNET_ERROR_TYPE_INFO, \ |
48 | __FUNCTION__,\ | 47 | " %s duration %s\n", \ |
49 | GNUNET_STRINGS_relative_time_to_string (__duration, GNUNET_YES)); | 48 | __FUNCTION__, \ |
49 | GNUNET_STRINGS_relative_time_to_string (__duration, GNUNET_YES)); | ||
50 | #else | 50 | #else |
51 | #define CADET_TIMING_START | 51 | #define CADET_TIMING_START |
52 | #define CADET_TIMING_END | 52 | #define CADET_TIMING_END |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | 55 | ||
@@ -68,17 +68,17 @@ extern "C" | |||
68 | /** | 68 | /** |
69 | * Minimum value for channel IDs of local clients. | 69 | * Minimum value for channel IDs of local clients. |
70 | */ | 70 | */ |
71 | #define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000U | 71 | #define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000U |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * FIXME. | 74 | * FIXME. |
75 | */ | 75 | */ |
76 | #define HIGH_PID 0xFF000000 | 76 | #define HIGH_PID 0xFF000000 |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * FIXME. | 79 | * FIXME. |
80 | */ | 80 | */ |
81 | #define LOW_PID 0x00FFFFFF | 81 | #define LOW_PID 0x00FFFFFF |
82 | 82 | ||
83 | 83 | ||
84 | /** | 84 | /** |
@@ -199,6 +199,12 @@ struct GNUNET_CADET_LocalData | |||
199 | struct GNUNET_CADET_ClientChannelNumber ccn; | 199 | struct GNUNET_CADET_ClientChannelNumber ccn; |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * Priority and preferences (an enum GNUNET_MQ_PriorityPreferences) | ||
203 | * of the message in NBO. | ||
204 | */ | ||
205 | uint32_t pp GNUNET_PACKED; | ||
206 | |||
207 | /** | ||
202 | * Payload follows | 208 | * Payload follows |
203 | */ | 209 | */ |
204 | }; | 210 | }; |
@@ -219,7 +225,6 @@ struct GNUNET_CADET_LocalAck | |||
219 | * ID of the channel allowed to send more data. | 225 | * ID of the channel allowed to send more data. |
220 | */ | 226 | */ |
221 | struct GNUNET_CADET_ClientChannelNumber ccn; | 227 | struct GNUNET_CADET_ClientChannelNumber ccn; |
222 | |||
223 | }; | 228 | }; |
224 | 229 | ||
225 | 230 | ||
@@ -308,7 +313,6 @@ struct GNUNET_CADET_RequestChannelInfoMessage | |||
308 | * Target of the channel. | 313 | * Target of the channel. |
309 | */ | 314 | */ |
310 | struct GNUNET_PeerIdentity target; | 315 | struct GNUNET_PeerIdentity target; |
311 | |||
312 | }; | 316 | }; |
313 | 317 | ||
314 | 318 | ||
@@ -358,7 +362,6 @@ struct GNUNET_CADET_LocalInfoPeers | |||
358 | * ID of the peer (can be local peer). | 362 | * ID of the peer (can be local peer). |
359 | */ | 363 | */ |
360 | struct GNUNET_PeerIdentity destination; | 364 | struct GNUNET_PeerIdentity destination; |
361 | |||
362 | }; | 365 | }; |
363 | 366 | ||
364 | 367 | ||
@@ -465,9 +468,7 @@ GC_min_pid (uint32_t a, uint32_t b); | |||
465 | * @return The size of the output. | 468 | * @return The size of the output. |
466 | */ | 469 | */ |
467 | size_t | 470 | size_t |
468 | GC_bin2s (void *bin, | 471 | GC_bin2s (void *bin, unsigned int len, char **output); |
469 | unsigned int len, | ||
470 | char **output); | ||
471 | 472 | ||
472 | 473 | ||
473 | /** | 474 | /** |
@@ -483,7 +484,7 @@ GC_bin2s (void *bin, | |||
483 | const char * | 484 | const char * |
484 | GC_m2s (uint16_t m); | 485 | GC_m2s (uint16_t m); |
485 | 486 | ||
486 | #if 0 /* keep Emacsens' auto-indent happy */ | 487 | #if 0 /* keep Emacsens' auto-indent happy */ |
487 | { | 488 | { |
488 | #endif | 489 | #endif |
489 | #ifdef __cplusplus | 490 | #ifdef __cplusplus |
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 8638be27d..b16520429 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include "cadet.h" | 30 | #include "cadet.h" |
31 | #include "cadet_protocol.h" | 31 | #include "cadet_protocol.h" |
32 | 32 | ||
33 | #define LOG(kind,...) GNUNET_log_from (kind, "cadet-api",__VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from (kind, "cadet-api", __VA_ARGS__) |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Opaque handle to the service. | 36 | * Opaque handle to the service. |
@@ -71,7 +71,6 @@ struct GNUNET_CADET_Handle | |||
71 | * Time to the next reconnect in case one reconnect fails | 71 | * Time to the next reconnect in case one reconnect fails |
72 | */ | 72 | */ |
73 | struct GNUNET_TIME_Relative reconnect_time; | 73 | struct GNUNET_TIME_Relative reconnect_time; |
74 | |||
75 | }; | 74 | }; |
76 | 75 | ||
77 | 76 | ||
@@ -138,7 +137,6 @@ struct GNUNET_CADET_Channel | |||
138 | * How many messages are we allowed to send to the service right now? | 137 | * How many messages are we allowed to send to the service right now? |
139 | */ | 138 | */ |
140 | unsigned int allow_send; | 139 | unsigned int allow_send; |
141 | |||
142 | }; | 140 | }; |
143 | 141 | ||
144 | 142 | ||
@@ -199,10 +197,9 @@ struct GNUNET_CADET_Port | |||
199 | */ | 197 | */ |
200 | static struct GNUNET_CADET_Port * | 198 | static struct GNUNET_CADET_Port * |
201 | find_port (const struct GNUNET_CADET_Handle *h, | 199 | find_port (const struct GNUNET_CADET_Handle *h, |
202 | const struct GNUNET_HashCode *hash) | 200 | const struct GNUNET_HashCode *hash) |
203 | { | 201 | { |
204 | return GNUNET_CONTAINER_multihashmap_get (h->ports, | 202 | return GNUNET_CONTAINER_multihashmap_get (h->ports, hash); |
205 | hash); | ||
206 | } | 203 | } |
207 | 204 | ||
208 | 205 | ||
@@ -240,11 +237,10 @@ create_channel (struct GNUNET_CADET_Handle *h, | |||
240 | ch->cadet = h; | 237 | ch->cadet = h; |
241 | if (NULL == ccnp) | 238 | if (NULL == ccnp) |
242 | { | 239 | { |
243 | while (NULL != | 240 | while (NULL != find_channel (h, h->next_ccn)) |
244 | find_channel (h, | 241 | h->next_ccn.channel_of_client = |
245 | h->next_ccn)) | 242 | htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI | |
246 | h->next_ccn.channel_of_client | 243 | (1 + ntohl (h->next_ccn.channel_of_client))); |
247 | = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI | (1 + ntohl (h->next_ccn.channel_of_client))); | ||
248 | ccn = h->next_ccn; | 244 | ccn = h->next_ccn; |
249 | } | 245 | } |
250 | else | 246 | else |
@@ -253,10 +249,11 @@ create_channel (struct GNUNET_CADET_Handle *h, | |||
253 | } | 249 | } |
254 | ch->ccn = ccn; | 250 | ch->ccn = ccn; |
255 | GNUNET_assert (GNUNET_OK == | 251 | GNUNET_assert (GNUNET_OK == |
256 | GNUNET_CONTAINER_multihashmap32_put (h->channels, | 252 | GNUNET_CONTAINER_multihashmap32_put ( |
257 | ntohl (ch->ccn.channel_of_client), | 253 | h->channels, |
258 | ch, | 254 | ntohl (ch->ccn.channel_of_client), |
259 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 255 | ch, |
256 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
260 | return ch; | 257 | return ch; |
261 | } | 258 | } |
262 | 259 | ||
@@ -280,10 +277,11 @@ destroy_channel (struct GNUNET_CADET_Channel *ch) | |||
280 | "Destroying channel %X of %p\n", | 277 | "Destroying channel %X of %p\n", |
281 | htonl (ch->ccn.channel_of_client), | 278 | htonl (ch->ccn.channel_of_client), |
282 | h); | 279 | h); |
283 | GNUNET_assert (GNUNET_YES == | 280 | GNUNET_assert ( |
284 | GNUNET_CONTAINER_multihashmap32_remove (h->channels, | 281 | GNUNET_YES == |
285 | ntohl (ch->ccn.channel_of_client), | 282 | GNUNET_CONTAINER_multihashmap32_remove (h->channels, |
286 | ch)); | 283 | ntohl (ch->ccn.channel_of_client), |
284 | ch)); | ||
287 | if (NULL != ch->mq_cont) | 285 | if (NULL != ch->mq_cont) |
288 | { | 286 | { |
289 | GNUNET_SCHEDULER_cancel (ch->mq_cont); | 287 | GNUNET_SCHEDULER_cancel (ch->mq_cont); |
@@ -291,8 +289,7 @@ destroy_channel (struct GNUNET_CADET_Channel *ch) | |||
291 | } | 289 | } |
292 | /* signal channel destruction */ | 290 | /* signal channel destruction */ |
293 | if (NULL != ch->disconnects) | 291 | if (NULL != ch->disconnects) |
294 | ch->disconnects (ch->ctx, | 292 | ch->disconnects (ch->ctx, ch); |
295 | ch); | ||
296 | if (NULL != ch->pending_env) | 293 | if (NULL != ch->pending_env) |
297 | GNUNET_MQ_discard (ch->pending_env); | 294 | GNUNET_MQ_discard (ch->pending_env); |
298 | GNUNET_MQ_destroy (ch->mq); | 295 | GNUNET_MQ_destroy (ch->mq); |
@@ -320,9 +317,7 @@ reconnect (struct GNUNET_CADET_Handle *h); | |||
320 | * @return #GNUNET_OK (continue to iterate) | 317 | * @return #GNUNET_OK (continue to iterate) |
321 | */ | 318 | */ |
322 | static int | 319 | static int |
323 | open_port_cb (void *cls, | 320 | open_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value) |
324 | const struct GNUNET_HashCode *id, | ||
325 | void *value) | ||
326 | { | 321 | { |
327 | struct GNUNET_CADET_Handle *h = cls; | 322 | struct GNUNET_CADET_Handle *h = cls; |
328 | struct GNUNET_CADET_Port *port = value; | 323 | struct GNUNET_CADET_Port *port = value; |
@@ -330,11 +325,9 @@ open_port_cb (void *cls, | |||
330 | struct GNUNET_MQ_Envelope *env; | 325 | struct GNUNET_MQ_Envelope *env; |
331 | 326 | ||
332 | (void) id; | 327 | (void) id; |
333 | env = GNUNET_MQ_msg (msg, | 328 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN); |
334 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN); | ||
335 | msg->port = port->id; | 329 | msg->port = port->id; |
336 | GNUNET_MQ_send (h->mq, | 330 | GNUNET_MQ_send (h->mq, env); |
337 | env); | ||
338 | return GNUNET_OK; | 331 | return GNUNET_OK; |
339 | } | 332 | } |
340 | 333 | ||
@@ -351,12 +344,9 @@ reconnect_cbk (void *cls) | |||
351 | struct GNUNET_CADET_Handle *h = cls; | 344 | struct GNUNET_CADET_Handle *h = cls; |
352 | 345 | ||
353 | h->reconnect_task = NULL; | 346 | h->reconnect_task = NULL; |
354 | h->reconnect_time | 347 | h->reconnect_time = GNUNET_TIME_STD_BACKOFF (h->reconnect_time); |
355 | = GNUNET_TIME_STD_BACKOFF (h->reconnect_time); | ||
356 | reconnect (h); | 348 | reconnect (h); |
357 | GNUNET_CONTAINER_multihashmap_iterate (h->ports, | 349 | GNUNET_CONTAINER_multihashmap_iterate (h->ports, &open_port_cb, h); |
358 | &open_port_cb, | ||
359 | h); | ||
360 | } | 350 | } |
361 | 351 | ||
362 | 352 | ||
@@ -405,8 +395,7 @@ cadet_mq_send_now (void *cls) | |||
405 | "Sending message on channel %s to CADET, new window size is %u\n", | 395 | "Sending message on channel %s to CADET, new window size is %u\n", |
406 | GNUNET_i2s (&ch->peer), | 396 | GNUNET_i2s (&ch->peer), |
407 | ch->allow_send); | 397 | ch->allow_send); |
408 | GNUNET_MQ_send (ch->cadet->mq, | 398 | GNUNET_MQ_send (ch->cadet->mq, env); |
409 | env); | ||
410 | GNUNET_MQ_impl_send_continue (ch->mq); | 399 | GNUNET_MQ_impl_send_continue (ch->mq); |
411 | } | 400 | } |
412 | 401 | ||
@@ -431,8 +420,10 @@ cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
431 | struct GNUNET_CADET_Channel *ch = impl_state; | 420 | struct GNUNET_CADET_Channel *ch = impl_state; |
432 | struct GNUNET_CADET_Handle *h = ch->cadet; | 421 | struct GNUNET_CADET_Handle *h = ch->cadet; |
433 | uint16_t msize; | 422 | uint16_t msize; |
423 | struct GNUNET_MQ_Envelope *orig_env; | ||
434 | struct GNUNET_MQ_Envelope *env; | 424 | struct GNUNET_MQ_Envelope *env; |
435 | struct GNUNET_CADET_LocalData *cadet_msg = NULL; | 425 | struct GNUNET_CADET_LocalData *cadet_msg; |
426 | enum GNUNET_MQ_PriorityPreferences pp; | ||
436 | 427 | ||
437 | if (NULL == h->mq) | 428 | if (NULL == h->mq) |
438 | { | 429 | { |
@@ -440,6 +431,8 @@ cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
440 | GNUNET_MQ_impl_send_continue (mq); | 431 | GNUNET_MQ_impl_send_continue (mq); |
441 | return; | 432 | return; |
442 | } | 433 | } |
434 | orig_env = GNUNET_MQ_get_current_envelope (mq); | ||
435 | pp = GNUNET_MQ_env_get_options (orig_env); | ||
443 | 436 | ||
444 | /* check message size for sanity */ | 437 | /* check message size for sanity */ |
445 | msize = ntohs (msg->size); | 438 | msize = ntohs (msg->size); |
@@ -453,12 +446,11 @@ cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
453 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, | 446 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, |
454 | msg); | 447 | msg); |
455 | cadet_msg->ccn = ch->ccn; | 448 | cadet_msg->ccn = ch->ccn; |
449 | cadet_msg->pp = htonl ((uint32_t) pp); | ||
456 | GNUNET_assert (NULL == ch->pending_env); | 450 | GNUNET_assert (NULL == ch->pending_env); |
457 | ch->pending_env = env; | 451 | ch->pending_env = env; |
458 | if (0 < ch->allow_send) | 452 | if (0 < ch->allow_send) |
459 | ch->mq_cont | 453 | ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, ch); |
460 | = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, | ||
461 | ch); | ||
462 | } | 454 | } |
463 | 455 | ||
464 | 456 | ||
@@ -470,8 +462,7 @@ cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
470 | * @param impl_state state of the implementation | 462 | * @param impl_state state of the implementation |
471 | */ | 463 | */ |
472 | static void | 464 | static void |
473 | cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, | 465 | cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
474 | void *impl_state) | ||
475 | { | 466 | { |
476 | struct GNUNET_CADET_Channel *ch = impl_state; | 467 | struct GNUNET_CADET_Channel *ch = impl_state; |
477 | 468 | ||
@@ -489,8 +480,7 @@ cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, | |||
489 | * @param error error code | 480 | * @param error error code |
490 | */ | 481 | */ |
491 | static void | 482 | static void |
492 | cadet_mq_error_handler (void *cls, | 483 | cadet_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
493 | enum GNUNET_MQ_Error error) | ||
494 | { | 484 | { |
495 | struct GNUNET_CADET_Channel *ch = cls; | 485 | struct GNUNET_CADET_Channel *ch = cls; |
496 | 486 | ||
@@ -503,11 +493,10 @@ cadet_mq_error_handler (void *cls, | |||
503 | else | 493 | else |
504 | { | 494 | { |
505 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 495 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
506 | "MQ error in communication with CADET: %d\n", | 496 | "MQ error in communication with CADET: %d\n", |
507 | error); | 497 | error); |
508 | if (NULL != ch->disconnects) | 498 | if (NULL != ch->disconnects) |
509 | ch->disconnects (ch->ctx, | 499 | ch->disconnects (ch->ctx, ch); |
510 | ch); | ||
511 | GNUNET_CADET_channel_destroy (ch); | 500 | GNUNET_CADET_channel_destroy (ch); |
512 | } | 501 | } |
513 | } | 502 | } |
@@ -521,8 +510,7 @@ cadet_mq_error_handler (void *cls, | |||
521 | * @param impl_state state specific to the implementation | 510 | * @param impl_state state specific to the implementation |
522 | */ | 511 | */ |
523 | static void | 512 | static void |
524 | cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, | 513 | cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
525 | void *impl_state) | ||
526 | { | 514 | { |
527 | struct GNUNET_CADET_Channel *ch = impl_state; | 515 | struct GNUNET_CADET_Channel *ch = impl_state; |
528 | 516 | ||
@@ -545,8 +533,9 @@ cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, | |||
545 | * @param msg A message with the details of the new incoming channel | 533 | * @param msg A message with the details of the new incoming channel |
546 | */ | 534 | */ |
547 | static void | 535 | static void |
548 | handle_channel_created (void *cls, | 536 | handle_channel_created ( |
549 | const struct GNUNET_CADET_LocalChannelCreateMessage *msg) | 537 | void *cls, |
538 | const struct GNUNET_CADET_LocalChannelCreateMessage *msg) | ||
550 | { | 539 | { |
551 | struct GNUNET_CADET_Handle *h = cls; | 540 | struct GNUNET_CADET_Handle *h = cls; |
552 | struct GNUNET_CADET_Channel *ch; | 541 | struct GNUNET_CADET_Channel *ch; |
@@ -561,8 +550,7 @@ handle_channel_created (void *cls, | |||
561 | GNUNET_break (0); | 550 | GNUNET_break (0); |
562 | return; | 551 | return; |
563 | } | 552 | } |
564 | port = find_port (h, | 553 | port = find_port (h, port_number); |
565 | port_number); | ||
566 | if (NULL == port) | 554 | if (NULL == port) |
567 | { | 555 | { |
568 | /* We could have closed the port but the service didn't know about it yet | 556 | /* We could have closed the port but the service didn't know about it yet |
@@ -575,16 +563,14 @@ handle_channel_created (void *cls, | |||
575 | "No handler for incoming channel %X (on port %s, recently closed?)\n", | 563 | "No handler for incoming channel %X (on port %s, recently closed?)\n", |
576 | ntohl (ccn.channel_of_client), | 564 | ntohl (ccn.channel_of_client), |
577 | GNUNET_h2s (port_number)); | 565 | GNUNET_h2s (port_number)); |
578 | env = GNUNET_MQ_msg (d_msg, | 566 | env = |
579 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); | 567 | GNUNET_MQ_msg (d_msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); |
580 | d_msg->ccn = msg->ccn; | 568 | d_msg->ccn = msg->ccn; |
581 | GNUNET_MQ_send (h->mq, | 569 | GNUNET_MQ_send (h->mq, env); |
582 | env); | ||
583 | return; | 570 | return; |
584 | } | 571 | } |
585 | 572 | ||
586 | ch = create_channel (h, | 573 | ch = create_channel (h, &ccn); |
587 | &ccn); | ||
588 | ch->peer = msg->peer; | 574 | ch->peer = msg->peer; |
589 | ch->incoming_port = port; | 575 | ch->incoming_port = port; |
590 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 576 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -603,11 +589,8 @@ handle_channel_created (void *cls, | |||
603 | port->handlers, | 589 | port->handlers, |
604 | &cadet_mq_error_handler, | 590 | &cadet_mq_error_handler, |
605 | ch); | 591 | ch); |
606 | ch->ctx = port->connects (port->cls, | 592 | ch->ctx = port->connects (port->cls, ch, &msg->peer); |
607 | ch, | 593 | GNUNET_MQ_set_handlers_closure (ch->mq, ch->ctx); |
608 | &msg->peer); | ||
609 | GNUNET_MQ_set_handlers_closure (ch->mq, | ||
610 | ch->ctx); | ||
611 | } | 594 | } |
612 | 595 | ||
613 | 596 | ||
@@ -618,14 +601,14 @@ handle_channel_created (void *cls, | |||
618 | * @param msg A message with the details of the channel being destroyed | 601 | * @param msg A message with the details of the channel being destroyed |
619 | */ | 602 | */ |
620 | static void | 603 | static void |
621 | handle_channel_destroy (void *cls, | 604 | handle_channel_destroy ( |
622 | const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) | 605 | void *cls, |
606 | const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) | ||
623 | { | 607 | { |
624 | struct GNUNET_CADET_Handle *h = cls; | 608 | struct GNUNET_CADET_Handle *h = cls; |
625 | struct GNUNET_CADET_Channel *ch; | 609 | struct GNUNET_CADET_Channel *ch; |
626 | 610 | ||
627 | ch = find_channel (h, | 611 | ch = find_channel (h, msg->ccn); |
628 | msg->ccn); | ||
629 | if (NULL == ch) | 612 | if (NULL == ch) |
630 | { | 613 | { |
631 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 614 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -649,8 +632,7 @@ handle_channel_destroy (void *cls, | |||
649 | * #GNUNET_SYSERR otherwise | 632 | * #GNUNET_SYSERR otherwise |
650 | */ | 633 | */ |
651 | static int | 634 | static int |
652 | check_local_data (void *cls, | 635 | check_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) |
653 | const struct GNUNET_CADET_LocalData *message) | ||
654 | { | 636 | { |
655 | uint16_t size; | 637 | uint16_t size; |
656 | 638 | ||
@@ -672,8 +654,7 @@ check_local_data (void *cls, | |||
672 | * @param message A message encapsulating the data | 654 | * @param message A message encapsulating the data |
673 | */ | 655 | */ |
674 | static void | 656 | static void |
675 | handle_local_data (void *cls, | 657 | handle_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) |
676 | const struct GNUNET_CADET_LocalData *message) | ||
677 | { | 658 | { |
678 | struct GNUNET_CADET_Handle *h = cls; | 659 | struct GNUNET_CADET_Handle *h = cls; |
679 | const struct GNUNET_MessageHeader *payload; | 660 | const struct GNUNET_MessageHeader *payload; |
@@ -681,8 +662,7 @@ handle_local_data (void *cls, | |||
681 | uint16_t type; | 662 | uint16_t type; |
682 | int fwd; | 663 | int fwd; |
683 | 664 | ||
684 | ch = find_channel (h, | 665 | ch = find_channel (h, message->ccn); |
685 | message->ccn); | ||
686 | if (NULL == ch) | 666 | if (NULL == ch) |
687 | { | 667 | { |
688 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 668 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -700,8 +680,7 @@ handle_local_data (void *cls, | |||
700 | GNUNET_i2s (&ch->peer), | 680 | GNUNET_i2s (&ch->peer), |
701 | ntohl (message->ccn.channel_of_client), | 681 | ntohl (message->ccn.channel_of_client), |
702 | type); | 682 | type); |
703 | GNUNET_MQ_inject_message (ch->mq, | 683 | GNUNET_MQ_inject_message (ch->mq, payload); |
704 | payload); | ||
705 | } | 684 | } |
706 | 685 | ||
707 | 686 | ||
@@ -713,14 +692,12 @@ handle_local_data (void *cls, | |||
713 | * @param message Message itself. | 692 | * @param message Message itself. |
714 | */ | 693 | */ |
715 | static void | 694 | static void |
716 | handle_local_ack (void *cls, | 695 | handle_local_ack (void *cls, const struct GNUNET_CADET_LocalAck *message) |
717 | const struct GNUNET_CADET_LocalAck *message) | ||
718 | { | 696 | { |
719 | struct GNUNET_CADET_Handle *h = cls; | 697 | struct GNUNET_CADET_Handle *h = cls; |
720 | struct GNUNET_CADET_Channel *ch; | 698 | struct GNUNET_CADET_Channel *ch; |
721 | 699 | ||
722 | ch = find_channel (h, | 700 | ch = find_channel (h, message->ccn); |
723 | message->ccn); | ||
724 | if (NULL == ch) | 701 | if (NULL == ch) |
725 | { | 702 | { |
726 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 703 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -745,9 +722,7 @@ handle_local_ack (void *cls, | |||
745 | } | 722 | } |
746 | if (NULL != ch->mq_cont) | 723 | if (NULL != ch->mq_cont) |
747 | return; /* already working on it! */ | 724 | return; /* already working on it! */ |
748 | ch->mq_cont | 725 | ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, ch); |
749 | = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, | ||
750 | ch); | ||
751 | } | 726 | } |
752 | 727 | ||
753 | 728 | ||
@@ -761,9 +736,7 @@ handle_local_ack (void *cls, | |||
761 | * @return #GNUNET_OK (continue to iterate) | 736 | * @return #GNUNET_OK (continue to iterate) |
762 | */ | 737 | */ |
763 | static int | 738 | static int |
764 | destroy_channel_cb (void *cls, | 739 | destroy_channel_cb (void *cls, uint32_t cid, void *value) |
765 | uint32_t cid, | ||
766 | void *value) | ||
767 | { | 740 | { |
768 | /* struct GNUNET_CADET_Handle *handle = cls; */ | 741 | /* struct GNUNET_CADET_Handle *handle = cls; */ |
769 | struct GNUNET_CADET_Channel *ch = value; | 742 | struct GNUNET_CADET_Channel *ch = value; |
@@ -771,7 +744,7 @@ destroy_channel_cb (void *cls, | |||
771 | (void) cls; | 744 | (void) cls; |
772 | (void) cid; | 745 | (void) cid; |
773 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 746 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
774 | "Destroying channel due to GNUNET_CADET_disconnect()\n"); | 747 | "Destroying channel due to GNUNET_CADET_disconnect()\n"); |
775 | destroy_channel (ch); | 748 | destroy_channel (ch); |
776 | return GNUNET_OK; | 749 | return GNUNET_OK; |
777 | } | 750 | } |
@@ -786,23 +759,17 @@ destroy_channel_cb (void *cls, | |||
786 | * @param error error code | 759 | * @param error error code |
787 | */ | 760 | */ |
788 | static void | 761 | static void |
789 | handle_mq_error (void *cls, | 762 | handle_mq_error (void *cls, enum GNUNET_MQ_Error error) |
790 | enum GNUNET_MQ_Error error) | ||
791 | { | 763 | { |
792 | struct GNUNET_CADET_Handle *h = cls; | 764 | struct GNUNET_CADET_Handle *h = cls; |
793 | 765 | ||
794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error); |
795 | "MQ ERROR: %u\n", | 767 | GNUNET_CONTAINER_multihashmap32_iterate (h->channels, &destroy_channel_cb, h); |
796 | error); | ||
797 | GNUNET_CONTAINER_multihashmap32_iterate (h->channels, | ||
798 | &destroy_channel_cb, | ||
799 | h); | ||
800 | GNUNET_MQ_destroy (h->mq); | 768 | GNUNET_MQ_destroy (h->mq); |
801 | h->mq = NULL; | 769 | h->mq = NULL; |
802 | GNUNET_assert (NULL == h->reconnect_task); | 770 | GNUNET_assert (NULL == h->reconnect_task); |
803 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time, | 771 | h->reconnect_task = |
804 | &reconnect_cbk, | 772 | GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h); |
805 | h); | ||
806 | } | 773 | } |
807 | 774 | ||
808 | 775 | ||
@@ -815,32 +782,28 @@ handle_mq_error (void *cls, | |||
815 | static void | 782 | static void |
816 | reconnect (struct GNUNET_CADET_Handle *h) | 783 | reconnect (struct GNUNET_CADET_Handle *h) |
817 | { | 784 | { |
818 | struct GNUNET_MQ_MessageHandler handlers[] = { | 785 | struct GNUNET_MQ_MessageHandler handlers[] = |
819 | GNUNET_MQ_hd_fixed_size (channel_created, | 786 | {GNUNET_MQ_hd_fixed_size (channel_created, |
820 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, | 787 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, |
821 | struct GNUNET_CADET_LocalChannelCreateMessage, | 788 | struct GNUNET_CADET_LocalChannelCreateMessage, |
822 | h), | 789 | h), |
823 | GNUNET_MQ_hd_fixed_size (channel_destroy, | 790 | GNUNET_MQ_hd_fixed_size (channel_destroy, |
824 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, | 791 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, |
825 | struct GNUNET_CADET_LocalChannelDestroyMessage, | 792 | struct GNUNET_CADET_LocalChannelDestroyMessage, |
826 | h), | 793 | h), |
827 | GNUNET_MQ_hd_var_size (local_data, | 794 | GNUNET_MQ_hd_var_size (local_data, |
828 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, | 795 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, |
829 | struct GNUNET_CADET_LocalData, | 796 | struct GNUNET_CADET_LocalData, |
830 | h), | 797 | h), |
831 | GNUNET_MQ_hd_fixed_size (local_ack, | 798 | GNUNET_MQ_hd_fixed_size (local_ack, |
832 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, | 799 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, |
833 | struct GNUNET_CADET_LocalAck, | 800 | struct GNUNET_CADET_LocalAck, |
834 | h), | 801 | h), |
835 | GNUNET_MQ_handler_end () | 802 | GNUNET_MQ_handler_end ()}; |
836 | }; | ||
837 | 803 | ||
838 | GNUNET_assert (NULL == h->mq); | 804 | GNUNET_assert (NULL == h->mq); |
839 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 805 | h->mq = |
840 | "cadet", | 806 | GNUNET_CLIENT_connect (h->cfg, "cadet", handlers, &handle_mq_error, h); |
841 | handlers, | ||
842 | &handle_mq_error, | ||
843 | h); | ||
844 | } | 807 | } |
845 | 808 | ||
846 | 809 | ||
@@ -854,9 +817,7 @@ reconnect (struct GNUNET_CADET_Handle *h) | |||
854 | * @return #GNUNET_OK (continue to iterate) | 817 | * @return #GNUNET_OK (continue to iterate) |
855 | */ | 818 | */ |
856 | static int | 819 | static int |
857 | destroy_port_cb (void *cls, | 820 | destroy_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value) |
858 | const struct GNUNET_HashCode *id, | ||
859 | void *value) | ||
860 | { | 821 | { |
861 | /* struct GNUNET_CADET_Handle *handle = cls; */ | 822 | /* struct GNUNET_CADET_Handle *handle = cls; */ |
862 | struct GNUNET_CADET_Port *port = value; | 823 | struct GNUNET_CADET_Port *port = value; |
@@ -914,20 +875,17 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle) | |||
914 | void | 875 | void |
915 | GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p) | 876 | GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p) |
916 | { | 877 | { |
917 | GNUNET_assert (GNUNET_YES == | 878 | GNUNET_assert ( |
918 | GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports, | 879 | GNUNET_YES == |
919 | &p->id, | 880 | GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports, &p->id, p)); |
920 | p)); | ||
921 | if (NULL != p->cadet->mq) | 881 | if (NULL != p->cadet->mq) |
922 | { | 882 | { |
923 | struct GNUNET_CADET_PortMessage *msg; | 883 | struct GNUNET_CADET_PortMessage *msg; |
924 | struct GNUNET_MQ_Envelope *env; | 884 | struct GNUNET_MQ_Envelope *env; |
925 | 885 | ||
926 | env = GNUNET_MQ_msg (msg, | 886 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE); |
927 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE); | ||
928 | msg->port = p->id; | 887 | msg->port = p->id; |
929 | GNUNET_MQ_send (p->cadet->mq, | 888 | GNUNET_MQ_send (p->cadet->mq, env); |
930 | env); | ||
931 | } | 889 | } |
932 | GNUNET_free_non_null (p->handlers); | 890 | GNUNET_free_non_null (p->handlers); |
933 | GNUNET_free (p); | 891 | GNUNET_free (p); |
@@ -952,14 +910,12 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel) | |||
952 | 910 | ||
953 | if (NULL != h->mq) | 911 | if (NULL != h->mq) |
954 | { | 912 | { |
955 | env = GNUNET_MQ_msg (msg, | 913 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); |
956 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); | ||
957 | msg->ccn = channel->ccn; | 914 | msg->ccn = channel->ccn; |
958 | GNUNET_MQ_send (h->mq, | 915 | GNUNET_MQ_send (h->mq, env); |
959 | env); | ||
960 | } | 916 | } |
961 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 917 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
962 | "Destroying channel due to GNUNET_CADET_channel_destroy()\n"); | 918 | "Destroying channel due to GNUNET_CADET_channel_destroy()\n"); |
963 | channel->disconnects = NULL; | 919 | channel->disconnects = NULL; |
964 | destroy_channel (channel); | 920 | destroy_channel (channel); |
965 | } | 921 | } |
@@ -993,14 +949,12 @@ GNUNET_CADET_receive_done (struct GNUNET_CADET_Channel *channel) | |||
993 | struct GNUNET_CADET_LocalAck *msg; | 949 | struct GNUNET_CADET_LocalAck *msg; |
994 | struct GNUNET_MQ_Envelope *env; | 950 | struct GNUNET_MQ_Envelope *env; |
995 | 951 | ||
996 | env = GNUNET_MQ_msg (msg, | 952 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); |
997 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); | ||
998 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 953 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
999 | "Sending ACK on channel %X\n", | 954 | "Sending ACK on channel %X\n", |
1000 | ntohl (channel->ccn.channel_of_client)); | 955 | ntohl (channel->ccn.channel_of_client)); |
1001 | msg->ccn = channel->ccn; | 956 | msg->ccn = channel->ccn; |
1002 | GNUNET_MQ_send (channel->cadet->mq, | 957 | GNUNET_MQ_send (channel->cadet->mq, env); |
1003 | env); | ||
1004 | } | 958 | } |
1005 | 959 | ||
1006 | 960 | ||
@@ -1016,12 +970,10 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1016 | { | 970 | { |
1017 | struct GNUNET_CADET_Handle *h; | 971 | struct GNUNET_CADET_Handle *h; |
1018 | 972 | ||
1019 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 973 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n"); |
1020 | "GNUNET_CADET_connect()\n"); | ||
1021 | h = GNUNET_new (struct GNUNET_CADET_Handle); | 974 | h = GNUNET_new (struct GNUNET_CADET_Handle); |
1022 | h->cfg = cfg; | 975 | h->cfg = cfg; |
1023 | h->ports = GNUNET_CONTAINER_multihashmap_create (4, | 976 | h->ports = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_YES); |
1024 | GNUNET_YES); | ||
1025 | h->channels = GNUNET_CONTAINER_multihashmap32_create (4); | 977 | h->channels = GNUNET_CONTAINER_multihashmap32_create (4); |
1026 | reconnect (h); | 978 | reconnect (h); |
1027 | if (NULL == h->mq) | 979 | if (NULL == h->mq) |
@@ -1051,7 +1003,7 @@ struct GNUNET_CADET_Port * | |||
1051 | GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, | 1003 | GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, |
1052 | const struct GNUNET_HashCode *port, | 1004 | const struct GNUNET_HashCode *port, |
1053 | GNUNET_CADET_ConnectEventHandler connects, | 1005 | GNUNET_CADET_ConnectEventHandler connects, |
1054 | void * connects_cls, | 1006 | void *connects_cls, |
1055 | GNUNET_CADET_WindowSizeEventHandler window_changes, | 1007 | GNUNET_CADET_WindowSizeEventHandler window_changes, |
1056 | GNUNET_CADET_DisconnectEventHandler disconnects, | 1008 | GNUNET_CADET_DisconnectEventHandler disconnects, |
1057 | const struct GNUNET_MQ_MessageHandler *handlers) | 1009 | const struct GNUNET_MQ_MessageHandler *handlers) |
@@ -1061,17 +1013,17 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, | |||
1061 | GNUNET_assert (NULL != connects); | 1013 | GNUNET_assert (NULL != connects); |
1062 | GNUNET_assert (NULL != disconnects); | 1014 | GNUNET_assert (NULL != disconnects); |
1063 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1015 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1064 | "Listening to CADET port %s\n", | 1016 | "Listening to CADET port %s\n", |
1065 | GNUNET_h2s (port)); | 1017 | GNUNET_h2s (port)); |
1066 | 1018 | ||
1067 | p = GNUNET_new (struct GNUNET_CADET_Port); | 1019 | p = GNUNET_new (struct GNUNET_CADET_Port); |
1068 | p->cadet = h; | 1020 | p->cadet = h; |
1069 | p->id = *port; | 1021 | p->id = *port; |
1070 | if (GNUNET_OK != | 1022 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( |
1071 | GNUNET_CONTAINER_multihashmap_put (h->ports, | 1023 | h->ports, |
1072 | &p->id, | 1024 | &p->id, |
1073 | p, | 1025 | p, |
1074 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 1026 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
1075 | { | 1027 | { |
1076 | GNUNET_free (p); | 1028 | GNUNET_free (p); |
1077 | return NULL; | 1029 | return NULL; |
@@ -1081,11 +1033,8 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, | |||
1081 | p->window_changes = window_changes; | 1033 | p->window_changes = window_changes; |
1082 | p->disconnects = disconnects; | 1034 | p->disconnects = disconnects; |
1083 | p->handlers = GNUNET_MQ_copy_handlers (handlers); | 1035 | p->handlers = GNUNET_MQ_copy_handlers (handlers); |
1084 | 1036 | ||
1085 | GNUNET_assert (GNUNET_OK == | 1037 | GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p)); |
1086 | open_port_cb (h, | ||
1087 | &p->id, | ||
1088 | p)); | ||
1089 | return p; | 1038 | return p; |
1090 | } | 1039 | } |
1091 | 1040 | ||
@@ -1124,11 +1073,10 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h, | |||
1124 | 1073 | ||
1125 | GNUNET_assert (NULL != disconnects); | 1074 | GNUNET_assert (NULL != disconnects); |
1126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1127 | "Creating channel to peer %s at port %s\n", | 1076 | "Creating channel to peer %s at port %s\n", |
1128 | GNUNET_i2s (destination), | 1077 | GNUNET_i2s (destination), |
1129 | GNUNET_h2s (port)); | 1078 | GNUNET_h2s (port)); |
1130 | ch = create_channel (h, | 1079 | ch = create_channel (h, NULL); |
1131 | NULL); | ||
1132 | ch->ctx = channel_cls; | 1080 | ch->ctx = channel_cls; |
1133 | ch->peer = *destination; | 1081 | ch->peer = *destination; |
1134 | ch->window_changes = window_changes; | 1082 | ch->window_changes = window_changes; |
@@ -1142,17 +1090,14 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h, | |||
1142 | handlers, | 1090 | handlers, |
1143 | &cadet_mq_error_handler, | 1091 | &cadet_mq_error_handler, |
1144 | ch); | 1092 | ch); |
1145 | GNUNET_MQ_set_handlers_closure (ch->mq, | 1093 | GNUNET_MQ_set_handlers_closure (ch->mq, channel_cls); |
1146 | channel_cls); | ||
1147 | 1094 | ||
1148 | /* Request channel creation to service */ | 1095 | /* Request channel creation to service */ |
1149 | env = GNUNET_MQ_msg (msg, | 1096 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); |
1150 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); | ||
1151 | msg->ccn = ch->ccn; | 1097 | msg->ccn = ch->ccn; |
1152 | msg->port = *port; | 1098 | msg->port = *port; |
1153 | msg->peer = *destination; | 1099 | msg->peer = *destination; |
1154 | GNUNET_MQ_send (h->mq, | 1100 | GNUNET_MQ_send (h->mq, env); |
1155 | env); | ||
1156 | return ch; | 1101 | return ch; |
1157 | } | 1102 | } |
1158 | 1103 | ||
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index e29330f99..209f7d392 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c | |||
@@ -32,7 +32,6 @@ | |||
32 | * - channel: logical link between two clients, on the same or different peers. | 32 | * - channel: logical link between two clients, on the same or different peers. |
33 | * have properties like reliability. | 33 | * have properties like reliability. |
34 | */ | 34 | */ |
35 | |||
36 | #include "platform.h" | 35 | #include "platform.h" |
37 | #include "gnunet_util_lib.h" | 36 | #include "gnunet_util_lib.h" |
38 | #include "cadet.h" | 37 | #include "cadet.h" |
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) | |||
341 | { | 341 | { |
342 | struct PeerRecord *pr = impl_state; | 342 | struct PeerRecord *pr = impl_state; |
343 | 343 | ||
344 | (void) mq; | ||
344 | GNUNET_assert (NULL != pr->env); | 345 | GNUNET_assert (NULL != pr->env); |
345 | GNUNET_MQ_discard (pr->env); | 346 | GNUNET_MQ_discard (pr->env); |
346 | pr->env = NULL; | 347 | pr->env = NULL; |
@@ -359,7 +360,8 @@ static void | |||
359 | core_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 360 | core_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
360 | { | 361 | { |
361 | /* struct PeerRecord *pr = cls; */ | 362 | /* struct PeerRecord *pr = cls; */ |
362 | 363 | (void) cls; | |
364 | (void) error; | ||
363 | GNUNET_break_op (0); | 365 | GNUNET_break_op (0); |
364 | } | 366 | } |
365 | 367 | ||
@@ -530,6 +532,7 @@ check_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm) | |||
530 | uint16_t msize; | 532 | uint16_t msize; |
531 | const struct GNUNET_MessageHeader *em; | 533 | const struct GNUNET_MessageHeader *em; |
532 | 534 | ||
535 | (void) cls; | ||
533 | msize = ntohs (ntm->header.size) - sizeof (struct NotifyTrafficMessage); | 536 | msize = ntohs (ntm->header.size) - sizeof (struct NotifyTrafficMessage); |
534 | if (msize < sizeof (struct GNUNET_MessageHeader)) | 537 | if (msize < sizeof (struct GNUNET_MessageHeader)) |
535 | { | 538 | { |
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 | |||
54 | * Closure for @e peer_cb. | 54 | * Closure for @e peer_cb. |
55 | */ | 55 | */ |
56 | void *peer_cb_cls; | 56 | void *peer_cb_cls; |
57 | |||
58 | }; | 57 | }; |
59 | 58 | ||
60 | 59 | ||
@@ -77,11 +76,11 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh); | |||
77 | * @param error error code | 76 | * @param error error code |
78 | */ | 77 | */ |
79 | static void | 78 | static void |
80 | handle_mq_error (void *cls, | 79 | handle_mq_error (void *cls, enum GNUNET_MQ_Error error) |
81 | enum GNUNET_MQ_Error error) | ||
82 | { | 80 | { |
83 | struct GNUNET_CORE_MonitorHandle *mh = cls; | 81 | struct GNUNET_CORE_MonitorHandle *mh = cls; |
84 | 82 | ||
83 | (void) error; | ||
85 | reconnect (mh); | 84 | reconnect (mh); |
86 | } | 85 | } |
87 | 86 | ||
@@ -93,8 +92,7 @@ handle_mq_error (void *cls, | |||
93 | * @param mon_message monitor message | 92 | * @param mon_message monitor message |
94 | */ | 93 | */ |
95 | static void | 94 | static void |
96 | handle_receive_info (void *cls, | 95 | handle_receive_info (void *cls, const struct MonitorNotifyMessage *mon_message) |
97 | const struct MonitorNotifyMessage *mon_message) | ||
98 | { | 96 | { |
99 | struct GNUNET_CORE_MonitorHandle *mh = cls; | 97 | struct GNUNET_CORE_MonitorHandle *mh = cls; |
100 | 98 | ||
@@ -114,24 +112,20 @@ handle_receive_info (void *cls, | |||
114 | static void | 112 | static void |
115 | reconnect (struct GNUNET_CORE_MonitorHandle *mh) | 113 | reconnect (struct GNUNET_CORE_MonitorHandle *mh) |
116 | { | 114 | { |
117 | struct GNUNET_MQ_MessageHandler handlers[] = { | 115 | struct GNUNET_MQ_MessageHandler handlers[] = |
118 | GNUNET_MQ_hd_fixed_size (receive_info, | 116 | {GNUNET_MQ_hd_fixed_size (receive_info, |
119 | GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, | 117 | GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, |
120 | struct MonitorNotifyMessage, | 118 | struct MonitorNotifyMessage, |
121 | mh), | 119 | mh), |
122 | GNUNET_MQ_handler_end () | 120 | GNUNET_MQ_handler_end ()}; |
123 | }; | ||
124 | struct GNUNET_MQ_Envelope *env; | 121 | struct GNUNET_MQ_Envelope *env; |
125 | struct GNUNET_MessageHeader *msg; | 122 | struct GNUNET_MessageHeader *msg; |
126 | 123 | ||
127 | if (NULL != mh->mq) | 124 | if (NULL != mh->mq) |
128 | GNUNET_MQ_destroy (mh->mq); | 125 | GNUNET_MQ_destroy (mh->mq); |
129 | /* FIXME: use backoff? */ | 126 | /* FIXME: use backoff? */ |
130 | mh->mq = GNUNET_CLIENT_connect (mh->cfg, | 127 | mh->mq = |
131 | "core", | 128 | GNUNET_CLIENT_connect (mh->cfg, "core", handlers, &handle_mq_error, mh); |
132 | handlers, | ||
133 | &handle_mq_error, | ||
134 | mh); | ||
135 | if (NULL == mh->mq) | 129 | if (NULL == mh->mq) |
136 | return; | 130 | return; |
137 | /* notify callback about reconnect */ | 131 | /* notify callback about reconnect */ |
@@ -140,10 +134,8 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh) | |||
140 | NULL, | 134 | NULL, |
141 | GNUNET_CORE_KX_CORE_DISCONNECT, | 135 | GNUNET_CORE_KX_CORE_DISCONNECT, |
142 | GNUNET_TIME_UNIT_FOREVER_ABS); | 136 | GNUNET_TIME_UNIT_FOREVER_ABS); |
143 | env = GNUNET_MQ_msg (msg, | 137 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS); |
144 | GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS); | 138 | GNUNET_MQ_send (mh->mq, env); |
145 | GNUNET_MQ_send (mh->mq, | ||
146 | env); | ||
147 | } | 139 | } |
148 | 140 | ||
149 | 141 | ||
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; | |||
48 | static void | 48 | static void |
49 | shutdown_task (void *cls) | 49 | shutdown_task (void *cls) |
50 | { | 50 | { |
51 | (void) cls; | ||
51 | if (NULL != mh) | 52 | if (NULL != mh) |
52 | { | 53 | { |
53 | GNUNET_CORE_monitor_stop (mh); | 54 | GNUNET_CORE_monitor_stop (mh); |
@@ -71,13 +72,13 @@ monitor_cb (void *cls, | |||
71 | enum GNUNET_CORE_KxState state, | 72 | enum GNUNET_CORE_KxState state, |
72 | struct GNUNET_TIME_Absolute timeout) | 73 | struct GNUNET_TIME_Absolute timeout) |
73 | { | 74 | { |
74 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); | 75 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
75 | const char *now_str; | 76 | const char *now_str; |
76 | const char *state_str; | 77 | const char *state_str; |
77 | 78 | ||
78 | if ( ( (NULL == peer) || | 79 | (void) cls; |
79 | (GNUNET_CORE_KX_ITERATION_FINISHED == state) ) && | 80 | if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) && |
80 | (GNUNET_NO == monitor_connections) ) | 81 | (GNUNET_NO == monitor_connections)) |
81 | { | 82 | { |
82 | GNUNET_SCHEDULER_shutdown (); | 83 | GNUNET_SCHEDULER_shutdown (); |
83 | return; | 84 | return; |
@@ -87,42 +88,43 @@ monitor_cb (void *cls, | |||
87 | { | 88 | { |
88 | case GNUNET_CORE_KX_STATE_DOWN: | 89 | case GNUNET_CORE_KX_STATE_DOWN: |
89 | /* should never happen, as we immediately send the key */ | 90 | /* should never happen, as we immediately send the key */ |
90 | state_str = _("fresh connection"); | 91 | state_str = _ ("fresh connection"); |
91 | break; | 92 | break; |
92 | case GNUNET_CORE_KX_STATE_KEY_SENT: | 93 | case GNUNET_CORE_KX_STATE_KEY_SENT: |
93 | state_str = _("key sent"); | 94 | state_str = _ ("key sent"); |
94 | break; | 95 | break; |
95 | case GNUNET_CORE_KX_STATE_KEY_RECEIVED: | 96 | case GNUNET_CORE_KX_STATE_KEY_RECEIVED: |
96 | state_str = _("key received"); | 97 | state_str = _ ("key received"); |
97 | break; | 98 | break; |
98 | case GNUNET_CORE_KX_STATE_UP: | 99 | case GNUNET_CORE_KX_STATE_UP: |
99 | state_str = _("connection established"); | 100 | state_str = _ ("connection established"); |
100 | break; | 101 | break; |
101 | case GNUNET_CORE_KX_STATE_REKEY_SENT: | 102 | case GNUNET_CORE_KX_STATE_REKEY_SENT: |
102 | state_str = _("rekeying"); | 103 | state_str = _ ("rekeying"); |
103 | break; | 104 | break; |
104 | case GNUNET_CORE_KX_PEER_DISCONNECT: | 105 | case GNUNET_CORE_KX_PEER_DISCONNECT: |
105 | state_str = _("disconnected"); | 106 | state_str = _ ("disconnected"); |
106 | break; | 107 | break; |
107 | case GNUNET_CORE_KX_ITERATION_FINISHED: | 108 | case GNUNET_CORE_KX_ITERATION_FINISHED: |
108 | return; | 109 | return; |
109 | case GNUNET_CORE_KX_CORE_DISCONNECT: | 110 | case GNUNET_CORE_KX_CORE_DISCONNECT: |
110 | FPRINTF (stderr, | 111 | FPRINTF (stderr, |
111 | "%s\n", | 112 | "%s\n", |
112 | _("Connection to CORE service lost (reconnecting)")); | 113 | _ ("Connection to CORE service lost (reconnecting)")); |
113 | return; | 114 | return; |
114 | default: | 115 | default: |
115 | state_str = _("unknown state"); | 116 | state_str = _ ("unknown state"); |
116 | break; | 117 | break; |
117 | } | 118 | } |
118 | now_str = GNUNET_STRINGS_absolute_time_to_string (now); | 119 | now_str = GNUNET_STRINGS_absolute_time_to_string (now); |
119 | FPRINTF (stdout, | 120 | FPRINTF (stdout, |
120 | _("%24s: %-30s %4s (timeout in %6s)\n"), | 121 | _ ("%24s: %-30s %4s (timeout in %6s)\n"), |
121 | now_str, | 122 | now_str, |
122 | state_str, | 123 | state_str, |
123 | GNUNET_i2s (peer), | 124 | GNUNET_i2s (peer), |
124 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (timeout), | 125 | GNUNET_STRINGS_relative_time_to_string ( |
125 | GNUNET_YES)); | 126 | GNUNET_TIME_absolute_get_remaining (timeout), |
127 | GNUNET_YES)); | ||
126 | } | 128 | } |
127 | 129 | ||
128 | 130 | ||
@@ -135,24 +137,22 @@ monitor_cb (void *cls, | |||
135 | * @param cfg configuration | 137 | * @param cfg configuration |
136 | */ | 138 | */ |
137 | static void | 139 | static void |
138 | run (void *cls, char *const *args, const char *cfgfile, | 140 | run (void *cls, |
141 | char *const *args, | ||
142 | const char *cfgfile, | ||
139 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 143 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
140 | { | 144 | { |
145 | (void) cls; | ||
146 | (void) cfgfile; | ||
141 | if (NULL != args[0]) | 147 | if (NULL != args[0]) |
142 | { | 148 | { |
143 | FPRINTF (stderr, | 149 | FPRINTF (stderr, _ ("Invalid command line argument `%s'\n"), args[0]); |
144 | _("Invalid command line argument `%s'\n"), | ||
145 | args[0]); | ||
146 | return; | 150 | return; |
147 | } | 151 | } |
148 | mh = GNUNET_CORE_monitor_start (cfg, | 152 | mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL); |
149 | &monitor_cb, | ||
150 | NULL); | ||
151 | if (NULL == mh) | 153 | if (NULL == mh) |
152 | { | 154 | { |
153 | FPRINTF (stderr, | 155 | FPRINTF (stderr, "%s", _ ("Failed to connect to CORE service!\n")); |
154 | "%s", | ||
155 | _("Failed to connect to CORE service!\n")); | ||
156 | return; | 156 | return; |
157 | } | 157 | } |
158 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 158 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
@@ -167,24 +167,28 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
167 | * @return 0 ok, 1 on error | 167 | * @return 0 ok, 1 on error |
168 | */ | 168 | */ |
169 | int | 169 | int |
170 | main (int argc, | 170 | main (int argc, char *const *argv) |
171 | char *const *argv) | ||
172 | { | 171 | { |
173 | int res; | 172 | int res; |
174 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 173 | struct GNUNET_GETOPT_CommandLineOption options[] = |
175 | GNUNET_GETOPT_option_flag ('m', | 174 | {GNUNET_GETOPT_option_flag ( |
176 | "monitor", | 175 | 'm', |
177 | gettext_noop ("provide information about all current connections (continuously)"), | 176 | "monitor", |
178 | &monitor_connections), | 177 | gettext_noop ( |
179 | GNUNET_GETOPT_OPTION_END | 178 | "provide information about all current connections (continuously)"), |
180 | }; | 179 | &monitor_connections), |
180 | GNUNET_GETOPT_OPTION_END}; | ||
181 | 181 | ||
182 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 182 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
183 | return 2; | 183 | return 2; |
184 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-core", | 184 | res = GNUNET_PROGRAM_run (argc, |
185 | gettext_noop | 185 | argv, |
186 | ("Print information about connected peers."), | 186 | "gnunet-core", |
187 | options, &run, NULL); | 187 | gettext_noop ( |
188 | "Print information about connected peers."), | ||
189 | options, | ||
190 | &run, | ||
191 | NULL); | ||
188 | 192 | ||
189 | GNUNET_free ((void *) argv); | 193 | GNUNET_free ((void *) argv); |
190 | if (GNUNET_OK == res) | 194 | if (GNUNET_OK == res) |
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 = \ | |||
81 | gnunet-gns-benchmark | 81 | gnunet-gns-benchmark |
82 | 82 | ||
83 | pkgdata_DATA = \ | 83 | pkgdata_DATA = \ |
84 | openssl.cnf | 84 | gnunet-gns-proxy-ca.template |
85 | 85 | ||
86 | if HAVE_MHD | 86 | if HAVE_MHD |
87 | if LINUX | 87 | 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 @@ | |||
1 | # X.509 Certificate options | ||
2 | # | ||
3 | # DN options | ||
4 | |||
5 | # The organization of the subject. | ||
6 | organization = "GNU" | ||
7 | |||
8 | # The organizational unit of the subject. | ||
9 | unit = "GNUnet" | ||
10 | |||
11 | # The locality of the subject. | ||
12 | locality = World | ||
13 | |||
14 | # The state of the certificate owner. | ||
15 | # state = "Attiki" | ||
16 | |||
17 | # The country of the subject. Two letter code. | ||
18 | country = ZZ | ||
19 | |||
20 | # The common name of the certificate owner. | ||
21 | cn = "GNS Proxy CA" | ||
22 | |||
23 | # A user id of the certificate owner. | ||
24 | #uid = "clauper" | ||
25 | |||
26 | # Set domain components | ||
27 | #dc = "name" | ||
28 | #dc = "domain" | ||
29 | |||
30 | # If the supported DN OIDs are not adequate you can set | ||
31 | # any OID here. | ||
32 | # For example set the X.520 Title and the X.520 Pseudonym | ||
33 | # by using OID and string pairs. | ||
34 | #dn_oid = "2.5.4.12 Dr." | ||
35 | #dn_oid = "2.5.4.65 jackal" | ||
36 | |||
37 | # This is deprecated and should not be used in new | ||
38 | # certificates. | ||
39 | # pkcs9_email = "none@none.org" | ||
40 | |||
41 | # An alternative way to set the certificate's distinguished name directly | ||
42 | # is with the "dn" option. The attribute names allowed are: | ||
43 | # C (country), street, O (organization), OU (unit), title, CN (common name), | ||
44 | # L (locality), ST (state), placeOfBirth, gender, countryOfCitizenship, | ||
45 | # countryOfResidence, serialNumber, telephoneNumber, surName, initials, | ||
46 | # generationQualifier, givenName, pseudonym, dnQualifier, postalCode, name, | ||
47 | # businessCategory, DC, UID, jurisdictionOfIncorporationLocalityName, | ||
48 | # jurisdictionOfIncorporationStateOrProvinceName, | ||
49 | # jurisdictionOfIncorporationCountryName, XmppAddr, and numeric OIDs. | ||
50 | |||
51 | #dn = "cn = Nikos,st = New\, Something,C=GR,surName=Mavrogiannopoulos,2.5.4.9=Arkadias" | ||
52 | |||
53 | # The serial number of the certificate | ||
54 | # The value is in decimal (i.e. 1963) or hex (i.e. 0x07ab). | ||
55 | # Comment the field for a random serial number. | ||
56 | #serial = 007 | ||
57 | |||
58 | # In how many days, counting from today, this certificate will expire. | ||
59 | # Use -1 if there is no expiration date. | ||
60 | expiration_days = 3650 | ||
61 | |||
62 | # Alternatively you may set concrete dates and time. The GNU date string | ||
63 | # formats are accepted. See: | ||
64 | # https://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html | ||
65 | |||
66 | #activation_date = "2004-02-29 16:21:42" | ||
67 | #expiration_date = "2025-02-29 16:24:41" | ||
68 | |||
69 | # X.509 v3 extensions | ||
70 | |||
71 | # A dnsname in case of a WWW server. | ||
72 | #dns_name = "www.none.org" | ||
73 | #dns_name = "www.morethanone.org" | ||
74 | |||
75 | # An othername defined by an OID and a hex encoded string | ||
76 | #other_name = "1.3.6.1.5.2.2 302ca00d1b0b56414e5245494e2e4f5247a11b3019a006020400000002a10f300d1b047269636b1b0561646d696e" | ||
77 | #other_name_utf8 = "1.2.4.5.6 A UTF8 string" | ||
78 | #other_name_octet = "1.2.4.5.6 A string that will be encoded as ASN.1 octet string" | ||
79 | |||
80 | # Allows writing an XmppAddr Identifier | ||
81 | #xmpp_name = juliet@im.example.com | ||
82 | |||
83 | # Names used in PKINIT | ||
84 | #krb5_principal = user@REALM.COM | ||
85 | #krb5_principal = HTTP/user@REALM.COM | ||
86 | |||
87 | # A subject alternative name URI | ||
88 | #uri = "https://www.example.com" | ||
89 | |||
90 | # An IP address in case of a server. | ||
91 | #ip_address = "192.168.1.1" | ||
92 | |||
93 | # An email in case of a person | ||
94 | email = "bounce@gnunet.org" | ||
95 | |||
96 | # TLS feature (rfc7633) extension. That can is used to indicate mandatory TLS | ||
97 | # extension features to be provided by the server. In practice this is used | ||
98 | # to require the Status Request (extid: 5) extension from the server. That is, | ||
99 | # to require the server holding this certificate to provide a stapled OCSP response. | ||
100 | # You can have multiple lines for multiple TLS features. | ||
101 | |||
102 | # To ask for OCSP status request use: | ||
103 | #tls_feature = 5 | ||
104 | |||
105 | # Challenge password used in certificate requests | ||
106 | challenge_password = 123456 | ||
107 | |||
108 | # Password when encrypting a private key | ||
109 | #password = secret | ||
110 | |||
111 | # An URL that has CRLs (certificate revocation lists) | ||
112 | # available. Needed in CA certificates. | ||
113 | #crl_dist_points = "https://www.getcrl.crl/getcrl/" | ||
114 | |||
115 | # Whether this is a CA certificate or not | ||
116 | ca | ||
117 | |||
118 | # Subject Unique ID (in hex) | ||
119 | #subject_unique_id = 00153224 | ||
120 | |||
121 | # Issuer Unique ID (in hex) | ||
122 | #issuer_unique_id = 00153225 | ||
123 | |||
124 | #### Key usage | ||
125 | |||
126 | # The following key usage flags are used by CAs and end certificates | ||
127 | |||
128 | # Whether this certificate will be used to sign data (needed | ||
129 | # in TLS DHE ciphersuites). This is the digitalSignature flag | ||
130 | # in RFC5280 terminology. | ||
131 | signing_key | ||
132 | |||
133 | # Whether this certificate will be used to encrypt data (needed | ||
134 | # in TLS RSA ciphersuites). Note that it is preferred to use different | ||
135 | # keys for encryption and signing. This is the keyEncipherment flag | ||
136 | # in RFC5280 terminology. | ||
137 | encryption_key | ||
138 | |||
139 | # Whether this key will be used to sign other certificates. The | ||
140 | # keyCertSign flag in RFC5280 terminology. | ||
141 | cert_signing_key | ||
142 | |||
143 | # Whether this key will be used to sign CRLs. The | ||
144 | # cRLSign flag in RFC5280 terminology. | ||
145 | #crl_signing_key | ||
146 | |||
147 | # The keyAgreement flag of RFC5280. It's purpose is loosely | ||
148 | # defined. Not use it unless required by a protocol. | ||
149 | #key_agreement | ||
150 | |||
151 | # The dataEncipherment flag of RFC5280. It's purpose is loosely | ||
152 | # defined. Not use it unless required by a protocol. | ||
153 | #data_encipherment | ||
154 | |||
155 | # The nonRepudiation flag of RFC5280. It's purpose is loosely | ||
156 | # defined. Not use it unless required by a protocol. | ||
157 | #non_repudiation | ||
158 | |||
159 | #### Extended key usage (key purposes) | ||
160 | |||
161 | # The following extensions are used in an end certificate | ||
162 | # to clarify its purpose. Some CAs also use it to indicate | ||
163 | # the types of certificates they are purposed to sign. | ||
164 | |||
165 | |||
166 | # Whether this certificate will be used for a TLS client; | ||
167 | # this sets the id-kp-clientAuth (1.3.6.1.5.5.7.3.2) of | ||
168 | # extended key usage. | ||
169 | #tls_www_client | ||
170 | |||
171 | # Whether this certificate will be used for a TLS server; | ||
172 | # this sets the id-kp-serverAuth (1.3.6.1.5.5.7.3.1) of | ||
173 | # extended key usage. | ||
174 | tls_www_server | ||
175 | |||
176 | # Whether this key will be used to sign code. This sets the | ||
177 | # id-kp-codeSigning (1.3.6.1.5.5.7.3.3) of extended key usage | ||
178 | # extension. | ||
179 | #code_signing_key | ||
180 | |||
181 | # Whether this key will be used to sign OCSP data. This sets the | ||
182 | # id-kp-OCSPSigning (1.3.6.1.5.5.7.3.9) of extended key usage extension. | ||
183 | #ocsp_signing_key | ||
184 | |||
185 | # Whether this key will be used for time stamping. This sets the | ||
186 | # id-kp-timeStamping (1.3.6.1.5.5.7.3.8) of extended key usage extension. | ||
187 | #time_stamping_key | ||
188 | |||
189 | # Whether this key will be used for email protection. This sets the | ||
190 | # id-kp-emailProtection (1.3.6.1.5.5.7.3.4) of extended key usage extension. | ||
191 | #email_protection_key | ||
192 | |||
193 | # Whether this key will be used for IPsec IKE operations (1.3.6.1.5.5.7.3.17). | ||
194 | #ipsec_ike_key | ||
195 | |||
196 | ## adding custom key purpose OIDs | ||
197 | |||
198 | # for microsoft smart card logon | ||
199 | # key_purpose_oid = 1.3.6.1.4.1.311.20.2.2 | ||
200 | |||
201 | # for email protection | ||
202 | # key_purpose_oid = 1.3.6.1.5.5.7.3.4 | ||
203 | |||
204 | # for any purpose (must not be used in intermediate CA certificates) | ||
205 | # key_purpose_oid = 2.5.29.37.0 | ||
206 | |||
207 | ### end of key purpose OIDs | ||
208 | |||
209 | ### Adding arbitrary extensions | ||
210 | # This requires to provide the extension OIDs, as well as the extension data in | ||
211 | # hex format. The following two options are available since GnuTLS 3.5.3. | ||
212 | #add_extension = "1.2.3.4 0x0AAB01ACFE" | ||
213 | |||
214 | # As above but encode the data as an octet string | ||
215 | #add_extension = "1.2.3.4 octet_string(0x0AAB01ACFE)" | ||
216 | |||
217 | # For portability critical extensions shouldn't be set to certificates. | ||
218 | #add_critical_extension = "5.6.7.8 0x1AAB01ACFE" | ||
219 | |||
220 | # When generating a certificate from a certificate | ||
221 | # request, then honor the extensions stored in the request | ||
222 | # and store them in the real certificate. | ||
223 | #honor_crq_extensions | ||
224 | |||
225 | # Alternatively only specific extensions can be copied. | ||
226 | #honor_crq_ext = 2.5.29.17 | ||
227 | #honor_crq_ext = 2.5.29.15 | ||
228 | |||
229 | # Path length contraint. Sets the maximum number of | ||
230 | # certificates that can be used to certify this certificate. | ||
231 | # (i.e. the certificate chain length) | ||
232 | #path_len = -1 | ||
233 | #path_len = 2 | ||
234 | |||
235 | # OCSP URI | ||
236 | # ocsp_uri = https://my.ocsp.server/ocsp | ||
237 | |||
238 | # CA issuers URI | ||
239 | # ca_issuers_uri = https://my.ca.issuer | ||
240 | |||
241 | # Certificate policies | ||
242 | #policy1 = 1.3.6.1.4.1.5484.1.10.99.1.0 | ||
243 | #policy1_txt = "This is a long policy to summarize" | ||
244 | #policy1_url = https://www.example.com/a-policy-to-read | ||
245 | |||
246 | #policy2 = 1.3.6.1.4.1.5484.1.10.99.1.1 | ||
247 | #policy2_txt = "This is a short policy" | ||
248 | #policy2_url = https://www.example.com/another-policy-to-read | ||
249 | |||
250 | # The number of additional certificates that may appear in a | ||
251 | # path before the anyPolicy is no longer acceptable. | ||
252 | #inhibit_anypolicy_skip_certs 1 | ||
253 | |||
254 | # Name constraints | ||
255 | |||
256 | # DNS | ||
257 | #nc_permit_dns = example.com | ||
258 | #nc_exclude_dns = test.example.com | ||
259 | |||
260 | |||
261 | #nc_permit_email = "nmav@ex.net" | ||
262 | |||
263 | # Exclude subdomains of example.com | ||
264 | #nc_exclude_email = .example.com | ||
265 | |||
266 | # Exclude all e-mail addresses of example.com | ||
267 | #nc_exclude_email = example.com | ||
268 | |||
269 | # IP | ||
270 | #nc_permit_ip = 192.168.0.0/16 | ||
271 | #nc_exclude_ip = 192.168.5.0/24 | ||
272 | #nc_permit_ip = fc0a:eef2:e7e7:a56e::/64 | ||
273 | |||
274 | |||
275 | # Options for proxy certificates | ||
276 | #proxy_policy_language = 1.3.6.1.5.5.7.21.1 | ||
277 | |||
278 | |||
279 | # Options for generating a CRL | ||
280 | |||
281 | # The number of days the next CRL update will be due. | ||
282 | # next CRL update will be in 43 days | ||
283 | #crl_next_update = 43 | ||
284 | |||
285 | # this is the 5th CRL by this CA | ||
286 | # The value is in decimal (i.e. 1963) or hex (i.e. 0x07ab). | ||
287 | # Comment the field for a time-based number. | ||
288 | # Time-based CRL numbers generated in GnuTLS 3.6.3 and later | ||
289 | # are significantly larger than those generated in previous | ||
290 | # versions. Since CRL numbers need to be monotonic, you need | ||
291 | # to specify the CRL number here manually if you intend to | ||
292 | # downgrade to an earlier version than 3.6.3 after publishing | ||
293 | # the CRL as it is not possible to specify CRL numbers greater | ||
294 | # than 2**63-2 using hex notation in those versions. | ||
295 | #crl_number = 5 | ||
296 | |||
297 | # Specify the update dates more precisely. | ||
298 | #crl_this_update_date = "2004-02-29 16:21:42" | ||
299 | #crl_next_update_date = "2025-02-29 16:24:41" | ||
300 | |||
301 | # The date that the certificates will be made seen as | ||
302 | # being revoked. | ||
303 | #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() | |||
133 | 133 | ||
134 | # ------------- openssl | 134 | # ------------- openssl |
135 | 135 | ||
136 | GNUTLS_CA_TEMPLATE=@pkgdatadir@/gnunet-gns-proxy-ca.template | ||
136 | OPENSSLCFG=@pkgdatadir@/openssl.cnf | 137 | OPENSSLCFG=@pkgdatadir@/openssl.cnf |
137 | if test -z "`openssl version`" > /dev/null | 138 | CERTTOOL="" |
139 | OPENSSL=0 | ||
140 | if test -z "`gnutls-certtool --version`" > /dev/null | ||
138 | then | 141 | then |
139 | warningmsg "'openssl' command not found. Please install it." | 142 | # We only support gnutls certtool for now |
140 | infomsg "Cleaning up." | 143 | if test -z "`certtool --version | grep gnutls`" > /dev/null |
141 | rm -f $GNSCAKY $GNSCANO $GNSCERT | 144 | then |
142 | exit 1 | 145 | warningmsg "'gnutls-certtool' or 'certtool' command not found. Trying openssl." |
146 | if test -z "`openssl version`" > /dev/null | ||
147 | then | ||
148 | $OPENSSL=1 | ||
149 | else | ||
150 | warningmsg "Install either gnutls certtool or openssl for certificate generation!" | ||
151 | infomsg "Cleaning up." | ||
152 | rm -f $GNSCAKY $GNSCERT | ||
153 | exit 1 | ||
154 | fi | ||
155 | fi | ||
156 | CERTTOOL="certtool" | ||
157 | else | ||
158 | CERTTOOL="gnutls-certtool" | ||
143 | fi | 159 | fi |
144 | if [ -n "${GNUNET_CONFIG_FILE}" ]; then | 160 | if [ -n "${GNUNET_CONFIG_FILE}" ]; then |
145 | GNUNET_CONFIG="-c ${GNUNET_CONFIG_FILE}" | 161 | GNUNET_CONFIG="-c ${GNUNET_CONFIG_FILE}" |
@@ -149,13 +165,18 @@ generate_ca() | |||
149 | GNS_CA_CERT_PEM=`gnunet-config ${GNUNET_CONFIG} -s gns-proxy -o PROXY_CACERT -f ${options}` | 165 | GNS_CA_CERT_PEM=`gnunet-config ${GNUNET_CONFIG} -s gns-proxy -o PROXY_CACERT -f ${options}` |
150 | mkdir -p `dirname $GNS_CA_CERT_PEM` | 166 | mkdir -p `dirname $GNS_CA_CERT_PEM` |
151 | 167 | ||
152 | 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" | 168 | if test 1 -eq $OPENSSL |
153 | 169 | then | |
154 | infomsg "Removing passphrase from key" | 170 | 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" |
155 | openssl rsa -passin pass:"GNU Name System" -in $GNSCAKY -out $GNSCANO | 171 | infomsg "Removing passphrase from key" |
156 | 172 | openssl rsa -passin pass:"GNU Name System" -in $GNSCAKY -out $GNSCANO | |
157 | infomsg "Making private key available to gnunet-gns-proxy" | 173 | cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM |
158 | cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM | 174 | else |
175 | $CERTTOOL --generate-privkey --outfile $GNSCAKY | ||
176 | $CERTTOOL --template $GNUTLS_CA_TEMPLATE --generate-self-signed --load-privkey $GNSCAKY --outfile $GNSCERT | ||
177 | infomsg "Making private key available to gnunet-gns-proxy" | ||
178 | cat $GNSCERT $GNSCAKY > $GNS_CA_CERT_PEM | ||
179 | fi | ||
159 | } | 180 | } |
160 | 181 | ||
161 | importbrowsers() | 182 | importbrowsers() |
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h index ddeeffef4..1e99c63d0 100644 --- a/src/include/gnunet_getopt_lib.h +++ b/src/include/gnunet_getopt_lib.h | |||
@@ -33,9 +33,8 @@ | |||
33 | #define GNUNET_GETOPT_LIB_H | 33 | #define GNUNET_GETOPT_LIB_H |
34 | 34 | ||
35 | #ifdef __cplusplus | 35 | #ifdef __cplusplus |
36 | extern "C" | 36 | extern "C" { |
37 | { | 37 | #if 0 /* keep Emacsens' auto-indent happy */ |
38 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
39 | } | 38 | } |
40 | #endif | 39 | #endif |
41 | #endif | 40 | #endif |
@@ -77,7 +76,6 @@ struct GNUNET_GETOPT_CommandLineProcessorContext | |||
77 | * Current argument. | 76 | * Current argument. |
78 | */ | 77 | */ |
79 | unsigned int currentArgument; | 78 | unsigned int currentArgument; |
80 | |||
81 | }; | 79 | }; |
82 | 80 | ||
83 | 81 | ||
@@ -90,12 +88,11 @@ struct GNUNET_GETOPT_CommandLineProcessorContext | |||
90 | * @param value argument, NULL if none was given | 88 | * @param value argument, NULL if none was given |
91 | * @return #GNUNET_OK to continue processing other options, #GNUNET_SYSERR to abort | 89 | * @return #GNUNET_OK to continue processing other options, #GNUNET_SYSERR to abort |
92 | */ | 90 | */ |
93 | typedef int | 91 | typedef int (*GNUNET_GETOPT_CommandLineOptionProcessor) ( |
94 | (*GNUNET_GETOPT_CommandLineOptionProcessor) (struct | 92 | struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
95 | GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 93 | void *scls, |
96 | void *scls, | 94 | const char *option, |
97 | const char *option, | 95 | const char *value); |
98 | const char *value); | ||
99 | 96 | ||
100 | 97 | ||
101 | /** | 98 | /** |
@@ -136,6 +133,11 @@ struct GNUNET_GETOPT_CommandLineOption | |||
136 | int option_mandatory; | 133 | int option_mandatory; |
137 | 134 | ||
138 | /** | 135 | /** |
136 | * Is the option exclusive? | ||
137 | */ | ||
138 | int option_exclusive; | ||
139 | |||
140 | /** | ||
139 | * Handler for the option. | 141 | * Handler for the option. |
140 | */ | 142 | */ |
141 | GNUNET_GETOPT_CommandLineOptionProcessor processor; | 143 | GNUNET_GETOPT_CommandLineOptionProcessor processor; |
@@ -144,13 +146,12 @@ struct GNUNET_GETOPT_CommandLineOption | |||
144 | * Function to call on @e scls to clean up after processing all | 146 | * Function to call on @e scls to clean up after processing all |
145 | * the arguments. Can be NULL. | 147 | * the arguments. Can be NULL. |
146 | */ | 148 | */ |
147 | void (*cleaner)(void *cls); | 149 | void (*cleaner) (void *cls); |
148 | 150 | ||
149 | /** | 151 | /** |
150 | * Specific closure to pass to the processor. | 152 | * Specific closure to pass to the processor. |
151 | */ | 153 | */ |
152 | void *scls; | 154 | void *scls; |
153 | |||
154 | }; | 155 | }; |
155 | 156 | ||
156 | 157 | ||
@@ -174,7 +175,6 @@ struct GNUNET_GETOPT_CommandLineOption | |||
174 | GNUNET_GETOPT_option_version (const char *version); | 175 | GNUNET_GETOPT_option_version (const char *version); |
175 | 176 | ||
176 | 177 | ||
177 | |||
178 | /** | 178 | /** |
179 | * Allow user to specify log file name (-l option) | 179 | * Allow user to specify log file name (-l option) |
180 | * | 180 | * |
@@ -249,8 +249,17 @@ GNUNET_GETOPT_option_base32_fixed_size (char shortName, | |||
249 | * @param[out] val binary value decoded from Crockford Base32-encoded argument; | 249 | * @param[out] val binary value decoded from Crockford Base32-encoded argument; |
250 | * size is determined by type (sizeof (*val)). | 250 | * size is determined by type (sizeof (*val)). |
251 | */ | 251 | */ |
252 | #define GNUNET_GETOPT_option_base32_auto(shortName,name,argumentHelp,description,val) \ | 252 | #define GNUNET_GETOPT_option_base32_auto(shortName, \ |
253 | GNUNET_GETOPT_option_base32_fixed_size(shortName,name,argumentHelp,description,val,sizeof(*val)) | 253 | name, \ |
254 | argumentHelp, \ | ||
255 | description, \ | ||
256 | val) \ | ||
257 | GNUNET_GETOPT_option_base32_fixed_size (shortName, \ | ||
258 | name, \ | ||
259 | argumentHelp, \ | ||
260 | description, \ | ||
261 | val, \ | ||
262 | sizeof (*val)) | ||
254 | 263 | ||
255 | 264 | ||
256 | /** | 265 | /** |
@@ -297,10 +306,10 @@ GNUNET_GETOPT_option_uint (char shortName, | |||
297 | */ | 306 | */ |
298 | struct GNUNET_GETOPT_CommandLineOption | 307 | struct GNUNET_GETOPT_CommandLineOption |
299 | GNUNET_GETOPT_option_uint16 (char shortName, | 308 | GNUNET_GETOPT_option_uint16 (char shortName, |
300 | const char *name, | 309 | const char *name, |
301 | const char *argumentHelp, | 310 | const char *argumentHelp, |
302 | const char *description, | 311 | const char *description, |
303 | uint16_t *val); | 312 | uint16_t *val); |
304 | 313 | ||
305 | 314 | ||
306 | /** | 315 | /** |
@@ -421,10 +430,22 @@ GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt); | |||
421 | 430 | ||
422 | 431 | ||
423 | /** | 432 | /** |
433 | * Make the given option mutually exclusive with other options. | ||
434 | * | ||
435 | * @param opt option to modify | ||
436 | * @return @a opt with the exclusive flag set. | ||
437 | */ | ||
438 | struct GNUNET_GETOPT_CommandLineOption | ||
439 | GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt); | ||
440 | |||
441 | |||
442 | /** | ||
424 | * Marker for the end of the list of options. | 443 | * Marker for the end of the list of options. |
425 | */ | 444 | */ |
426 | #define GNUNET_GETOPT_OPTION_END \ | 445 | #define GNUNET_GETOPT_OPTION_END \ |
427 | { '\0', NULL, NULL, NULL, 0, 0, NULL, NULL, NULL } | 446 | { \ |
447 | '\0', NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL \ | ||
448 | } | ||
428 | 449 | ||
429 | 450 | ||
430 | /** | 451 | /** |
@@ -444,7 +465,7 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
444 | char *const *argv); | 465 | char *const *argv); |
445 | 466 | ||
446 | 467 | ||
447 | #if 0 /* keep Emacsens' auto-indent happy */ | 468 | #if 0 /* keep Emacsens' auto-indent happy */ |
448 | { | 469 | { |
449 | #endif | 470 | #endif |
450 | #ifdef __cplusplus | 471 | #ifdef __cplusplus |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 26b5a704b..5d292525e 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -1647,6 +1647,7 @@ main (int argc, char *const *argv) | |||
1647 | "name of the ego controlling the zone"), | 1647 | "name of the ego controlling the zone"), |
1648 | &ego_name), | 1648 | &ego_name), |
1649 | GNUNET_GETOPT_OPTION_END}; | 1649 | GNUNET_GETOPT_OPTION_END}; |
1650 | int lret; | ||
1650 | 1651 | ||
1651 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 1652 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
1652 | return 2; | 1653 | return 2; |
@@ -1654,17 +1655,18 @@ main (int argc, char *const *argv) | |||
1654 | is_public = -1; | 1655 | is_public = -1; |
1655 | is_shadow = -1; | 1656 | is_shadow = -1; |
1656 | GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL); | 1657 | GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL); |
1657 | if (GNUNET_OK != GNUNET_PROGRAM_run (argc, | 1658 | if (GNUNET_OK != |
1658 | argv, | 1659 | (lret = GNUNET_PROGRAM_run (argc, |
1659 | "gnunet-namestore", | 1660 | argv, |
1660 | _ ("GNUnet zone manipulation tool"), | 1661 | "gnunet-namestore", |
1661 | options, | 1662 | _ ("GNUnet zone manipulation tool"), |
1662 | &run, | 1663 | options, |
1663 | NULL)) | 1664 | &run, |
1665 | NULL))) | ||
1664 | { | 1666 | { |
1665 | GNUNET_free ((void *) argv); | 1667 | GNUNET_free ((void *) argv); |
1666 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); | 1668 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); |
1667 | return 1; | 1669 | return lret; |
1668 | } | 1670 | } |
1669 | GNUNET_free ((void *) argv); | 1671 | GNUNET_free ((void *) argv); |
1670 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); | 1672 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); |
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 @@ | |||
23 | * @brief namestore for the GNUnet naming system | 23 | * @brief namestore for the GNUnet naming system |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | * | ||
27 | * TODO: | ||
28 | * - "get_nick_record" is a bottleneck, introduce a cache to | ||
29 | * avoid looking it up again and again (for the same few | ||
30 | * zones that the user will typically manage!) | ||
31 | * - run testcases, make sure everything works! | ||
32 | */ | 26 | */ |
33 | #include "platform.h" | 27 | #include "platform.h" |
34 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
@@ -562,13 +556,20 @@ cache_nick (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
562 | } | 556 | } |
563 | GNUNET_free_non_null (oldest->rd); | 557 | GNUNET_free_non_null (oldest->rd); |
564 | oldest->zone = *zone; | 558 | oldest->zone = *zone; |
565 | oldest->rd = GNUNET_malloc (sizeof (*nick) + | 559 | if (NULL != nick) |
566 | nick->data_size); | 560 | { |
567 | *oldest->rd = *nick; | 561 | oldest->rd = GNUNET_malloc (sizeof (*nick) + |
568 | oldest->rd->data = &oldest->rd[1]; | 562 | nick->data_size); |
569 | memcpy (&oldest->rd[1], | 563 | *oldest->rd = *nick; |
570 | nick->data, | 564 | oldest->rd->data = &oldest->rd[1]; |
571 | nick->data_size); | 565 | memcpy (&oldest->rd[1], |
566 | nick->data, | ||
567 | nick->data_size); | ||
568 | } | ||
569 | else | ||
570 | { | ||
571 | oldest->rd = NULL; | ||
572 | } | ||
572 | oldest->last_used = GNUNET_TIME_absolute_get (); | 573 | oldest->last_used = GNUNET_TIME_absolute_get (); |
573 | } | 574 | } |
574 | 575 | ||
@@ -592,8 +593,10 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | |||
592 | struct NickCache *pos = &nick_cache[i]; | 593 | struct NickCache *pos = &nick_cache[i]; |
593 | if ( (NULL != pos->rd) && | 594 | if ( (NULL != pos->rd) && |
594 | (0 == GNUNET_memcmp (zone, | 595 | (0 == GNUNET_memcmp (zone, |
595 | &pos->zone)) ) | 596 | &pos->zone)) ) |
596 | { | 597 | { |
598 | if (NULL == pos->rd) | ||
599 | return NULL; | ||
597 | nick = GNUNET_malloc (sizeof (*nick) + | 600 | nick = GNUNET_malloc (sizeof (*nick) + |
598 | pos->rd->data_size); | 601 | pos->rd->data_size); |
599 | *nick = *pos->rd; | 602 | *nick = *pos->rd; |
@@ -615,10 +618,25 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | |||
615 | if ( (GNUNET_OK != res) || | 618 | if ( (GNUNET_OK != res) || |
616 | (NULL == nick) ) | 619 | (NULL == nick) ) |
617 | { | 620 | { |
618 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub); | 621 | static int do_log = GNUNET_LOG_CALL_STATUS; |
619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 622 | |
620 | "No nick name set for zone `%s'\n", | 623 | if (0 == do_log) |
621 | GNUNET_GNSRECORD_z2s (&pub)); | 624 | do_log |
625 | = GNUNET_get_log_call_status (GNUNET_ERROR_TYPE_DEBUG, | ||
626 | "namestore", | ||
627 | __FILE__, | ||
628 | __FUNCTION__, | ||
629 | __LINE__); | ||
630 | if (1 == do_log) | ||
631 | { | ||
632 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub); | ||
633 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | ||
634 | "No nick name set for zone `%s'\n", | ||
635 | GNUNET_GNSRECORD_z2s (&pub)); | ||
636 | } | ||
637 | /* update cache */ | ||
638 | cache_nick (zone, | ||
639 | NULL); | ||
622 | return NULL; | 640 | return NULL; |
623 | } | 641 | } |
624 | 642 | ||
@@ -1603,8 +1621,10 @@ handle_record_store (void *cls, | |||
1603 | #GNUNET_GNS_EMPTY_LABEL_AT label */ | 1621 | #GNUNET_GNS_EMPTY_LABEL_AT label */ |
1604 | struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)]; | 1622 | struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)]; |
1605 | unsigned int rd_clean_off; | 1623 | unsigned int rd_clean_off; |
1624 | int have_nick; | ||
1606 | 1625 | ||
1607 | rd_clean_off = 0; | 1626 | rd_clean_off = 0; |
1627 | have_nick = GNUNET_NO; | ||
1608 | for (unsigned int i=0;i<rd_count;i++) | 1628 | for (unsigned int i=0;i<rd_count;i++) |
1609 | { | 1629 | { |
1610 | rd_clean[rd_clean_off] = rd[i]; | 1630 | rd_clean[rd_clean_off] = rd[i]; |
@@ -1616,8 +1636,19 @@ handle_record_store (void *cls, | |||
1616 | if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, | 1636 | if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, |
1617 | conv_name)) && | 1637 | conv_name)) && |
1618 | (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) ) | 1638 | (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) ) |
1639 | { | ||
1619 | cache_nick (&rp_msg->private_key, | 1640 | cache_nick (&rp_msg->private_key, |
1620 | &rd[i]); | 1641 | &rd[i]); |
1642 | have_nick = GNUNET_YES; | ||
1643 | } | ||
1644 | } | ||
1645 | if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, | ||
1646 | conv_name)) && | ||
1647 | (GNUNET_NO == have_nick) ) | ||
1648 | { | ||
1649 | /* remove nick record from cache, in case we have one there */ | ||
1650 | cache_nick (&rp_msg->private_key, | ||
1651 | NULL); | ||
1621 | } | 1652 | } |
1622 | res = GSN_database->store_records (GSN_database->cls, | 1653 | res = GSN_database->store_records (GSN_database->cls, |
1623 | &rp_msg->private_key, | 1654 | &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; | |||
46 | static void | 46 | static void |
47 | do_shutdown (void *cls) | 47 | do_shutdown (void *cls) |
48 | { | 48 | { |
49 | (void) cls; | ||
49 | if (NULL != nse) | 50 | if (NULL != nse) |
50 | { | 51 | { |
51 | GNUNET_NSE_disconnect (nse); | 52 | GNUNET_NSE_disconnect (nse); |
@@ -65,12 +66,14 @@ do_shutdown (void *cls) | |||
65 | */ | 66 | */ |
66 | static void | 67 | static void |
67 | handle_estimate (void *cls, | 68 | handle_estimate (void *cls, |
68 | struct GNUNET_TIME_Absolute timestamp, | 69 | struct GNUNET_TIME_Absolute timestamp, |
69 | double estimate, | 70 | double estimate, |
70 | double std_dev) | 71 | double std_dev) |
71 | { | 72 | { |
73 | (void) cls; | ||
72 | status = 0; | 74 | status = 0; |
73 | FPRINTF (stdout, "%llu %f %f %f\n", | 75 | FPRINTF (stdout, |
76 | "%llu %f %f %f\n", | ||
74 | (unsigned long long) timestamp.abs_value_us, | 77 | (unsigned long long) timestamp.abs_value_us, |
75 | GNUNET_NSE_log_estimate_to_n (estimate), | 78 | GNUNET_NSE_log_estimate_to_n (estimate), |
76 | estimate, | 79 | estimate, |
@@ -92,11 +95,11 @@ run (void *cls, | |||
92 | const char *cfgfile, | 95 | const char *cfgfile, |
93 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 96 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
94 | { | 97 | { |
95 | nse = GNUNET_NSE_connect (cfg, | 98 | (void) cls; |
96 | &handle_estimate, | 99 | (void) args; |
97 | NULL); | 100 | (void) cfgfile; |
98 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 101 | nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL); |
99 | NULL); | 102 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
100 | } | 103 | } |
101 | 104 | ||
102 | 105 | ||
@@ -106,22 +109,21 @@ run (void *cls, | |||
106 | * @return 0 on success | 109 | * @return 0 on success |
107 | */ | 110 | */ |
108 | int | 111 | int |
109 | main (int argc, | 112 | main (int argc, char *const *argv) |
110 | char *const *argv) | ||
111 | { | 113 | { |
112 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 114 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
113 | GNUNET_GETOPT_OPTION_END | 115 | GNUNET_GETOPT_OPTION_END}; |
114 | }; | ||
115 | 116 | ||
116 | status = 1; | 117 | status = 1; |
117 | if (GNUNET_OK != | 118 | if (GNUNET_OK != |
118 | GNUNET_PROGRAM_run (argc, | 119 | GNUNET_PROGRAM_run (argc, |
119 | argv, | 120 | argv, |
120 | "gnunet-nse", | 121 | "gnunet-nse", |
121 | gettext_noop | 122 | gettext_noop ( |
122 | ("Show network size estimates from NSE service."), | 123 | "Show network size estimates from NSE service."), |
123 | options, | 124 | options, |
124 | &run, NULL)) | 125 | &run, |
126 | NULL)) | ||
125 | return 2; | 127 | return 2; |
126 | return status; | 128 | return status; |
127 | } | 129 | } |
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) | |||
430 | struct GNUNET_NSE_ClientMessage em; | 430 | struct GNUNET_NSE_ClientMessage em; |
431 | struct GNUNET_MQ_Envelope *env; | 431 | struct GNUNET_MQ_Envelope *env; |
432 | 432 | ||
433 | (void) message; | ||
433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); | 434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); |
434 | mq = GNUNET_SERVICE_client_get_mq (client); | 435 | mq = GNUNET_SERVICE_client_get_mq (client); |
435 | GNUNET_notification_context_add (nc, mq); | 436 | GNUNET_notification_context_add (nc, mq); |
@@ -717,6 +718,8 @@ schedule_current_round (void *cls, | |||
717 | struct NSEPeerEntry *peer_entry = value; | 718 | struct NSEPeerEntry *peer_entry = value; |
718 | struct GNUNET_TIME_Relative delay; | 719 | struct GNUNET_TIME_Relative delay; |
719 | 720 | ||
721 | (void) cls; | ||
722 | (void) key; | ||
720 | if (NULL != peer_entry->transmit_task) | 723 | if (NULL != peer_entry->transmit_task) |
721 | { | 724 | { |
722 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 725 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
@@ -749,8 +752,8 @@ static void | |||
749 | update_flood_message (void *cls) | 752 | update_flood_message (void *cls) |
750 | { | 753 | { |
751 | struct GNUNET_TIME_Relative offset; | 754 | struct GNUNET_TIME_Relative offset; |
752 | unsigned int i; | ||
753 | 755 | ||
756 | (void) cls; | ||
754 | flood_task = NULL; | 757 | flood_task = NULL; |
755 | offset = GNUNET_TIME_absolute_get_remaining (next_timestamp); | 758 | offset = GNUNET_TIME_absolute_get_remaining (next_timestamp); |
756 | if (0 != offset.rel_value_us) | 759 | if (0 != offset.rel_value_us) |
@@ -780,7 +783,7 @@ update_flood_message (void *cls) | |||
780 | setup_flood_message (estimate_index, current_timestamp); | 783 | setup_flood_message (estimate_index, current_timestamp); |
781 | next_message.matching_bits = htonl (0); /* reset for 'next' round */ | 784 | next_message.matching_bits = htonl (0); /* reset for 'next' round */ |
782 | hop_count_max = 0; | 785 | hop_count_max = 0; |
783 | for (i = 0; i < HISTORY_SIZE; i++) | 786 | for (unsigned int i = 0; i < HISTORY_SIZE; i++) |
784 | hop_count_max = | 787 | hop_count_max = |
785 | GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max); | 788 | GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max); |
786 | GNUNET_CONTAINER_multipeermap_iterate (peers, &schedule_current_round, NULL); | 789 | GNUNET_CONTAINER_multipeermap_iterate (peers, &schedule_current_round, NULL); |
@@ -869,6 +872,7 @@ find_proof (void *cls) | |||
869 | struct GNUNET_HashCode result; | 872 | struct GNUNET_HashCode result; |
870 | unsigned int i; | 873 | unsigned int i; |
871 | 874 | ||
875 | (void) cls; | ||
872 | proof_task = NULL; | 876 | proof_task = NULL; |
873 | GNUNET_memcpy (&buf[sizeof (uint64_t)], | 877 | GNUNET_memcpy (&buf[sizeof (uint64_t)], |
874 | &my_identity, | 878 | &my_identity, |
@@ -967,6 +971,7 @@ update_flood_times (void *cls, | |||
967 | struct NSEPeerEntry *peer_entry = value; | 971 | struct NSEPeerEntry *peer_entry = value; |
968 | struct GNUNET_TIME_Relative delay; | 972 | struct GNUNET_TIME_Relative delay; |
969 | 973 | ||
974 | (void) key; | ||
970 | if (peer_entry == exclude) | 975 | if (peer_entry == exclude) |
971 | return GNUNET_OK; /* trigger of the update */ | 976 | return GNUNET_OK; /* trigger of the update */ |
972 | if (GNUNET_NO == peer_entry->previous_round) | 977 | if (GNUNET_NO == peer_entry->previous_round) |
@@ -1178,6 +1183,7 @@ handle_core_connect (void *cls, | |||
1178 | { | 1183 | { |
1179 | struct NSEPeerEntry *peer_entry; | 1184 | struct NSEPeerEntry *peer_entry; |
1180 | 1185 | ||
1186 | (void) cls; | ||
1181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1182 | "Peer `%s' connected to us\n", | 1188 | "Peer `%s' connected to us\n", |
1183 | GNUNET_i2s (peer)); | 1189 | GNUNET_i2s (peer)); |
@@ -1217,6 +1223,7 @@ handle_core_disconnect (void *cls, | |||
1217 | { | 1223 | { |
1218 | struct NSEPeerEntry *pos = internal_cls; | 1224 | struct NSEPeerEntry *pos = internal_cls; |
1219 | 1225 | ||
1226 | (void) cls; | ||
1220 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1221 | "Peer `%s' disconnected from us\n", | 1228 | "Peer `%s' disconnected from us\n", |
1222 | GNUNET_i2s (peer)); | 1229 | GNUNET_i2s (peer)); |
@@ -1243,6 +1250,8 @@ handle_core_disconnect (void *cls, | |||
1243 | static void | 1250 | static void |
1244 | flush_comp_cb (void *cls, size_t size) | 1251 | flush_comp_cb (void *cls, size_t size) |
1245 | { | 1252 | { |
1253 | (void) cls; | ||
1254 | (void) size; | ||
1246 | GNUNET_TESTBED_LOGGER_disconnect (lh); | 1255 | GNUNET_TESTBED_LOGGER_disconnect (lh); |
1247 | lh = NULL; | 1256 | lh = NULL; |
1248 | } | 1257 | } |
@@ -1257,6 +1266,7 @@ flush_comp_cb (void *cls, size_t size) | |||
1257 | static void | 1266 | static void |
1258 | shutdown_task (void *cls) | 1267 | shutdown_task (void *cls) |
1259 | { | 1268 | { |
1269 | (void) cls; | ||
1260 | if (NULL != flood_task) | 1270 | if (NULL != flood_task) |
1261 | { | 1271 | { |
1262 | GNUNET_SCHEDULER_cancel (flood_task); | 1272 | GNUNET_SCHEDULER_cancel (flood_task); |
@@ -1324,6 +1334,7 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *identity) | |||
1324 | struct GNUNET_TIME_Absolute now; | 1334 | struct GNUNET_TIME_Absolute now; |
1325 | struct GNUNET_TIME_Absolute prev_time; | 1335 | struct GNUNET_TIME_Absolute prev_time; |
1326 | 1336 | ||
1337 | (void) cls; | ||
1327 | if (NULL == identity) | 1338 | if (NULL == identity) |
1328 | { | 1339 | { |
1329 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n"); | 1340 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n"); |
@@ -1365,6 +1376,7 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *identity) | |||
1365 | static void | 1376 | static void |
1366 | status_cb (void *cls, int status) | 1377 | status_cb (void *cls, int status) |
1367 | { | 1378 | { |
1379 | (void) cls; | ||
1368 | logger_test = NULL; | 1380 | logger_test = NULL; |
1369 | if (GNUNET_YES != status) | 1381 | if (GNUNET_YES != status) |
1370 | { | 1382 | { |
@@ -1402,6 +1414,8 @@ run (void *cls, | |||
1402 | char *proof; | 1414 | char *proof; |
1403 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 1415 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
1404 | 1416 | ||
1417 | (void) cls; | ||
1418 | (void) service; | ||
1405 | cfg = c; | 1419 | cfg = c; |
1406 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, | 1420 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, |
1407 | "NSE", | 1421 | "NSE", |
@@ -1524,6 +1538,8 @@ client_connect_cb (void *cls, | |||
1524 | struct GNUNET_SERVICE_Client *c, | 1538 | struct GNUNET_SERVICE_Client *c, |
1525 | struct GNUNET_MQ_Handle *mq) | 1539 | struct GNUNET_MQ_Handle *mq) |
1526 | { | 1540 | { |
1541 | (void) cls; | ||
1542 | (void) mq; | ||
1527 | return c; | 1543 | return c; |
1528 | } | 1544 | } |
1529 | 1545 | ||
@@ -1540,6 +1556,7 @@ client_disconnect_cb (void *cls, | |||
1540 | struct GNUNET_SERVICE_Client *c, | 1556 | struct GNUNET_SERVICE_Client *c, |
1541 | void *internal_cls) | 1557 | void *internal_cls) |
1542 | { | 1558 | { |
1559 | (void) cls; | ||
1543 | GNUNET_assert (c == internal_cls); | 1560 | GNUNET_assert (c == internal_cls); |
1544 | } | 1561 | } |
1545 | 1562 | ||
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 @@ | |||
32 | #include "gnunet_nse_service.h" | 32 | #include "gnunet_nse_service.h" |
33 | #include "nse.h" | 33 | #include "nse.h" |
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "nse-api",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "nse-api", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Handle for talking with the NSE service. | 38 | * Handle for talking with the NSE service. |
@@ -68,7 +68,6 @@ struct GNUNET_NSE_Handle | |||
68 | * Closure to pass to @e recv_cb callback. | 68 | * Closure to pass to @e recv_cb callback. |
69 | */ | 69 | */ |
70 | void *recv_cb_cls; | 70 | void *recv_cb_cls; |
71 | |||
72 | }; | 71 | }; |
73 | 72 | ||
74 | 73 | ||
@@ -91,17 +90,15 @@ reconnect (void *cls); | |||
91 | * @param error error code | 90 | * @param error error code |
92 | */ | 91 | */ |
93 | static void | 92 | static void |
94 | mq_error_handler (void *cls, | 93 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
95 | enum GNUNET_MQ_Error error) | ||
96 | { | 94 | { |
97 | struct GNUNET_NSE_Handle *h = cls; | 95 | struct GNUNET_NSE_Handle *h = cls; |
98 | 96 | ||
97 | (void) error; | ||
99 | GNUNET_MQ_destroy (h->mq); | 98 | GNUNET_MQ_destroy (h->mq); |
100 | h->mq = NULL; | 99 | h->mq = NULL; |
101 | h->reconnect_task | 100 | h->reconnect_task = |
102 | = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, | 101 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); |
103 | &reconnect, | ||
104 | h); | ||
105 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 102 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
106 | } | 103 | } |
107 | 104 | ||
@@ -114,8 +111,7 @@ mq_error_handler (void *cls, | |||
114 | * @param client_msg message received | 111 | * @param client_msg message received |
115 | */ | 112 | */ |
116 | static void | 113 | static void |
117 | handle_estimate (void *cls, | 114 | handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) |
118 | const struct GNUNET_NSE_ClientMessage *client_msg) | ||
119 | { | 115 | { |
120 | struct GNUNET_NSE_Handle *h = cls; | 116 | struct GNUNET_NSE_Handle *h = cls; |
121 | 117 | ||
@@ -123,7 +119,7 @@ handle_estimate (void *cls, | |||
123 | h->recv_cb (h->recv_cb_cls, | 119 | h->recv_cb (h->recv_cb_cls, |
124 | GNUNET_TIME_absolute_ntoh (client_msg->timestamp), | 120 | GNUNET_TIME_absolute_ntoh (client_msg->timestamp), |
125 | GNUNET_ntoh_double (client_msg->size_estimate), | 121 | GNUNET_ntoh_double (client_msg->size_estimate), |
126 | GNUNET_ntoh_double (client_msg->std_deviation)); | 122 | GNUNET_ntoh_double (client_msg->std_deviation)); |
127 | } | 123 | } |
128 | 124 | ||
129 | 125 | ||
@@ -136,13 +132,12 @@ static void | |||
136 | reconnect (void *cls) | 132 | reconnect (void *cls) |
137 | { | 133 | { |
138 | struct GNUNET_NSE_Handle *h = cls; | 134 | struct GNUNET_NSE_Handle *h = cls; |
139 | struct GNUNET_MQ_MessageHandler handlers[] = { | 135 | struct GNUNET_MQ_MessageHandler handlers[] = |
140 | GNUNET_MQ_hd_fixed_size (estimate, | 136 | {GNUNET_MQ_hd_fixed_size (estimate, |
141 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, | 137 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, |
142 | struct GNUNET_NSE_ClientMessage, | 138 | struct GNUNET_NSE_ClientMessage, |
143 | h), | 139 | h), |
144 | GNUNET_MQ_handler_end () | 140 | GNUNET_MQ_handler_end ()}; |
145 | }; | ||
146 | struct GNUNET_MessageHeader *msg; | 141 | struct GNUNET_MessageHeader *msg; |
147 | struct GNUNET_MQ_Envelope *env; | 142 | struct GNUNET_MQ_Envelope *env; |
148 | 143 | ||
@@ -150,17 +145,11 @@ reconnect (void *cls) | |||
150 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 145 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
151 | "Connecting to network size estimation service.\n"); | 146 | "Connecting to network size estimation service.\n"); |
152 | GNUNET_assert (NULL == h->mq); | 147 | GNUNET_assert (NULL == h->mq); |
153 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 148 | h->mq = GNUNET_CLIENT_connect (h->cfg, "nse", handlers, &mq_error_handler, h); |
154 | "nse", | ||
155 | handlers, | ||
156 | &mq_error_handler, | ||
157 | h); | ||
158 | if (NULL == h->mq) | 149 | if (NULL == h->mq) |
159 | return; | 150 | return; |
160 | env = GNUNET_MQ_msg (msg, | 151 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NSE_START); |
161 | GNUNET_MESSAGE_TYPE_NSE_START); | 152 | GNUNET_MQ_send (h->mq, env); |
162 | GNUNET_MQ_send (h->mq, | ||
163 | env); | ||
164 | } | 153 | } |
165 | 154 | ||
166 | 155 | ||
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 @@ | |||
28 | #include "gnunet_crypto_lib.h" | 28 | #include "gnunet_crypto_lib.h" |
29 | #include <gcrypt.h> | 29 | #include <gcrypt.h> |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__) |
32 | 32 | ||
33 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-random", syscall) | 33 | #define LOG_STRERROR(kind, syscall) \ |
34 | GNUNET_log_from_strerror (kind, "util-crypto-random", syscall) | ||
34 | 35 | ||
35 | 36 | ||
36 | /* TODO: ndurner, move this to plibc? */ | 37 | /* TODO: ndurner, move this to plibc? */ |
37 | /* The code is derived from glibc, obviously */ | 38 | /* The code is derived from glibc, obviously */ |
38 | #if !HAVE_RANDOM || !HAVE_SRANDOM | 39 | #if ! HAVE_RANDOM || ! HAVE_SRANDOM |
39 | #ifdef RANDOM | 40 | #ifdef RANDOM |
40 | #undef RANDOM | 41 | #undef RANDOM |
41 | #endif | 42 | #endif |
42 | #ifdef SRANDOM | 43 | #ifdef SRANDOM |
43 | #undef SRANDOM | 44 | #undef SRANDOM |
44 | #endif | 45 | #endif |
45 | #define RANDOM() glibc_weak_rand32() | 46 | #define RANDOM() glibc_weak_rand32 () |
46 | #define SRANDOM(s) glibc_weak_srand32(s) | 47 | #define SRANDOM(s) glibc_weak_srand32 (s) |
47 | #if defined(RAND_MAX) | 48 | #if defined(RAND_MAX) |
48 | #undef RAND_MAX | 49 | #undef RAND_MAX |
49 | #endif | 50 | #endif |
@@ -105,17 +106,12 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed) | |||
105 | * @param length buffer length | 106 | * @param length buffer length |
106 | */ | 107 | */ |
107 | void | 108 | void |
108 | GNUNET_CRYPTO_zero_keys (void *buffer, | 109 | GNUNET_CRYPTO_zero_keys (void *buffer, size_t length) |
109 | size_t length) | ||
110 | { | 110 | { |
111 | #if HAVE_MEMSET_S | 111 | #if HAVE_MEMSET_S |
112 | memset_s (buffer, | 112 | memset_s (buffer, length, 0, length); |
113 | length, | ||
114 | 0, | ||
115 | length); | ||
116 | #elif HAVE_EXPLICIT_BZERO | 113 | #elif HAVE_EXPLICIT_BZERO |
117 | explicit_bzero (buffer, | 114 | explicit_bzero (buffer, length); |
118 | length); | ||
119 | #else | 115 | #else |
120 | volatile unsigned char *p = buffer; | 116 | volatile unsigned char *p = buffer; |
121 | while (length--) | 117 | while (length--) |
@@ -175,8 +171,7 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, | |||
175 | * @return a random value in the interval [0,i[. | 171 | * @return a random value in the interval [0,i[. |
176 | */ | 172 | */ |
177 | uint32_t | 173 | uint32_t |
178 | GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, | 174 | GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i) |
179 | uint32_t i) | ||
180 | { | 175 | { |
181 | #ifdef gcry_fast_random_poll | 176 | #ifdef gcry_fast_random_poll |
182 | static unsigned int invokeCount; | 177 | static unsigned int invokeCount; |
@@ -197,18 +192,17 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, | |||
197 | ul = UINT32_MAX - (UINT32_MAX % i); | 192 | ul = UINT32_MAX - (UINT32_MAX % i); |
198 | do | 193 | do |
199 | { | 194 | { |
200 | gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t), | 195 | gcry_randomize ((unsigned char *) &ret, |
196 | sizeof (uint32_t), | ||
201 | GCRY_STRONG_RANDOM); | 197 | GCRY_STRONG_RANDOM); |
202 | } | 198 | } while (ret >= ul); |
203 | while (ret >= ul); | ||
204 | return ret % i; | 199 | return ret % i; |
205 | case GNUNET_CRYPTO_QUALITY_NONCE: | 200 | case GNUNET_CRYPTO_QUALITY_NONCE: |
206 | ul = UINT32_MAX - (UINT32_MAX % i); | 201 | ul = UINT32_MAX - (UINT32_MAX % i); |
207 | do | 202 | do |
208 | { | 203 | { |
209 | gcry_create_nonce (&ret, sizeof (ret)); | 204 | gcry_create_nonce (&ret, sizeof (ret)); |
210 | } | 205 | } while (ret >= ul); |
211 | while (ret >= ul); | ||
212 | return ret % i; | 206 | return ret % i; |
213 | case GNUNET_CRYPTO_QUALITY_WEAK: | 207 | case GNUNET_CRYPTO_QUALITY_WEAK: |
214 | ret = i * get_weak_random (); | 208 | ret = i * get_weak_random (); |
@@ -231,8 +225,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, | |||
231 | * @return the permutation array (allocated from heap) | 225 | * @return the permutation array (allocated from heap) |
232 | */ | 226 | */ |
233 | unsigned int * | 227 | unsigned int * |
234 | GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, | 228 | GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n) |
235 | unsigned int n) | ||
236 | { | 229 | { |
237 | unsigned int *ret; | 230 | unsigned int *ret; |
238 | unsigned int i; | 231 | unsigned int i; |
@@ -262,8 +255,7 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, | |||
262 | * @return random 64-bit number | 255 | * @return random 64-bit number |
263 | */ | 256 | */ |
264 | uint64_t | 257 | uint64_t |
265 | GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | 258 | GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) |
266 | uint64_t max) | ||
267 | { | 259 | { |
268 | uint64_t ret; | 260 | uint64_t ret; |
269 | uint64_t ul; | 261 | uint64_t ul; |
@@ -275,18 +267,17 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | |||
275 | ul = UINT64_MAX - (UINT64_MAX % max); | 267 | ul = UINT64_MAX - (UINT64_MAX % max); |
276 | do | 268 | do |
277 | { | 269 | { |
278 | gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t), | 270 | gcry_randomize ((unsigned char *) &ret, |
271 | sizeof (uint64_t), | ||
279 | GCRY_STRONG_RANDOM); | 272 | GCRY_STRONG_RANDOM); |
280 | } | 273 | } while (ret >= ul); |
281 | while (ret >= ul); | ||
282 | return ret % max; | 274 | return ret % max; |
283 | case GNUNET_CRYPTO_QUALITY_NONCE: | 275 | case GNUNET_CRYPTO_QUALITY_NONCE: |
284 | ul = UINT64_MAX - (UINT64_MAX % max); | 276 | ul = UINT64_MAX - (UINT64_MAX % max); |
285 | do | 277 | do |
286 | { | 278 | { |
287 | gcry_create_nonce (&ret, sizeof (ret)); | 279 | gcry_create_nonce (&ret, sizeof (ret)); |
288 | } | 280 | } while (ret >= ul); |
289 | while (ret >= ul); | ||
290 | 281 | ||
291 | return ret % max; | 282 | return ret % max; |
292 | case GNUNET_CRYPTO_QUALITY_WEAK: | 283 | case GNUNET_CRYPTO_QUALITY_WEAK: |
@@ -319,6 +310,7 @@ w_malloc (size_t n) | |||
319 | static int | 310 | static int |
320 | w_check (const void *p) | 311 | w_check (const void *p) |
321 | { | 312 | { |
313 | (void) p; | ||
322 | return 0; /* not secure memory */ | 314 | return 0; /* not secure memory */ |
323 | } | 315 | } |
324 | 316 | ||
@@ -326,50 +318,45 @@ w_check (const void *p) | |||
326 | /** | 318 | /** |
327 | * Initialize libgcrypt. | 319 | * Initialize libgcrypt. |
328 | */ | 320 | */ |
329 | void __attribute__ ((constructor)) | 321 | void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init () |
330 | GNUNET_CRYPTO_random_init () | ||
331 | { | 322 | { |
332 | gcry_error_t rc; | 323 | gcry_error_t rc; |
333 | 324 | ||
334 | if (! gcry_check_version (NEED_LIBGCRYPT_VERSION)) | 325 | if (! gcry_check_version (NEED_LIBGCRYPT_VERSION)) |
335 | { | 326 | { |
336 | FPRINTF (stderr, | 327 | FPRINTF ( |
337 | _("libgcrypt has not the expected version (version %s is required).\n"), | 328 | stderr, |
338 | NEED_LIBGCRYPT_VERSION); | 329 | _ ("libgcrypt has not the expected version (version %s is required).\n"), |
330 | NEED_LIBGCRYPT_VERSION); | ||
339 | GNUNET_assert (0); | 331 | GNUNET_assert (0); |
340 | } | 332 | } |
341 | /* set custom allocators */ | 333 | /* set custom allocators */ |
342 | gcry_set_allocation_handler (&w_malloc, | 334 | gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free); |
343 | &w_malloc, | ||
344 | &w_check, | ||
345 | &realloc, | ||
346 | &free); | ||
347 | /* Disable use of secure memory */ | 335 | /* Disable use of secure memory */ |
348 | if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) | 336 | if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) |
349 | FPRINTF (stderr, | 337 | FPRINTF (stderr, |
350 | "Failed to set libgcrypt option %s: %s\n", | 338 | "Failed to set libgcrypt option %s: %s\n", |
351 | "DISABLE_SECMEM", | 339 | "DISABLE_SECMEM", |
352 | gcry_strerror (rc)); | 340 | gcry_strerror (rc)); |
353 | /* Otherwise gnunet-ecc takes forever to complete, besides | 341 | /* Otherwise gnunet-ecc takes forever to complete, besides |
354 | we are fine with "just" using GCRY_STRONG_RANDOM */ | 342 | we are fine with "just" using GCRY_STRONG_RANDOM */ |
355 | if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) | 343 | if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) |
356 | FPRINTF (stderr, | 344 | FPRINTF (stderr, |
357 | "Failed to set libgcrypt option %s: %s\n", | 345 | "Failed to set libgcrypt option %s: %s\n", |
358 | "ENABLE_QUICK_RANDOM", | 346 | "ENABLE_QUICK_RANDOM", |
359 | gcry_strerror (rc)); | 347 | gcry_strerror (rc)); |
360 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 348 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
361 | gcry_fast_random_poll (); | 349 | gcry_fast_random_poll (); |
362 | GNUNET_CRYPTO_seed_weak_random (time (NULL) ^ | 350 | GNUNET_CRYPTO_seed_weak_random ( |
363 | GNUNET_CRYPTO_random_u32 | 351 | time (NULL) ^ |
364 | (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | 352 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); |
365 | } | 353 | } |
366 | 354 | ||
367 | 355 | ||
368 | /** | 356 | /** |
369 | * Nicely shut down libgcrypt. | 357 | * Nicely shut down libgcrypt. |
370 | */ | 358 | */ |
371 | void __attribute__ ((destructor)) | 359 | void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini () |
372 | GNUNET_CRYPTO_random_fini () | ||
373 | { | 360 | { |
374 | gcry_set_progress_handler (NULL, NULL); | 361 | gcry_set_progress_handler (NULL, NULL); |
375 | #ifdef GCRYCTL_CLOSE_RANDOM_DEVICE | 362 | #ifdef GCRYCTL_CLOSE_RANDOM_DEVICE |
@@ -378,5 +365,4 @@ GNUNET_CRYPTO_random_fini () | |||
378 | } | 365 | } |
379 | 366 | ||
380 | 367 | ||
381 | |||
382 | /* end of crypto_random.c */ | 368 | /* end of crypto_random.c */ |
diff --git a/src/util/getopt.c b/src/util/getopt.c index 5e8571ee5..048f52ee0 100644 --- a/src/util/getopt.c +++ b/src/util/getopt.c | |||
@@ -47,14 +47,15 @@ Copyright (C) 2006, 2017 Christian Grothoff | |||
47 | #endif | 47 | #endif |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | #define LOG(kind,...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__) | 50 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__) |
51 | 51 | ||
52 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-getopt", syscall) | 52 | #define LOG_STRERROR(kind, syscall) \ |
53 | GNUNET_log_from_strerror (kind, "util-getopt", syscall) | ||
53 | 54 | ||
54 | #if defined (WIN32) && !defined (__CYGWIN32__) | 55 | #if defined(WIN32) && ! defined(__CYGWIN32__) |
55 | /* It's not Unix, really. See? Capital letters. */ | 56 | /* It's not Unix, really. See? Capital letters. */ |
56 | #include <windows.h> | 57 | #include <windows.h> |
57 | #define getpid() GetCurrentProcessId() | 58 | #define getpid() GetCurrentProcessId () |
58 | #endif | 59 | #endif |
59 | 60 | ||
60 | #ifndef _ | 61 | #ifndef _ |
@@ -62,9 +63,9 @@ Copyright (C) 2006, 2017 Christian Grothoff | |||
62 | When compiling libc, the _ macro is predefined. */ | 63 | When compiling libc, the _ macro is predefined. */ |
63 | #ifdef HAVE_LIBINTL_H | 64 | #ifdef HAVE_LIBINTL_H |
64 | #include <libintl.h> | 65 | #include <libintl.h> |
65 | #define _(msgid) gettext (msgid) | 66 | #define _(msgid) gettext (msgid) |
66 | #else | 67 | #else |
67 | #define _(msgid) (msgid) | 68 | #define _(msgid) (msgid) |
68 | #endif | 69 | #endif |
69 | #endif | 70 | #endif |
70 | 71 | ||
@@ -176,21 +177,18 @@ static char *nextchar; | |||
176 | of the value of `ordering'. In the case of RETURN_IN_ORDER, only | 177 | of the value of `ordering'. In the case of RETURN_IN_ORDER, only |
177 | `--' can cause `getopt' to return -1 with `GNoptind' != ARGC. */ | 178 | `--' can cause `getopt' to return -1 with `GNoptind' != ARGC. */ |
178 | 179 | ||
179 | static enum | 180 | static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; |
180 | { | ||
181 | REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER | ||
182 | } ordering; | ||
183 | 181 | ||
184 | /* Value of POSIXLY_CORRECT environment variable. */ | 182 | /* Value of POSIXLY_CORRECT environment variable. */ |
185 | static char *posixly_correct; | 183 | static char *posixly_correct; |
186 | 184 | ||
187 | #ifdef __GNU_LIBRARY__ | 185 | #ifdef __GNU_LIBRARY__ |
188 | /* We want to avoid inclusion of string.h with non-GNU libraries | 186 | /* We want to avoid inclusion of string.h with non-GNU libraries |
189 | because there are many ways it can cause trouble. | 187 | because there are many ways it can cause trouble. |
190 | On some systems, it contains special magic macros that don't work | 188 | On some systems, it contains special magic macros that don't work |
191 | in GCC. */ | 189 | in GCC. */ |
192 | #include <string.h> | 190 | #include <string.h> |
193 | #define my_index strchr | 191 | #define my_index strchr |
194 | #else | 192 | #else |
195 | 193 | ||
196 | /* Avoid depending on library functions or files | 194 | /* Avoid depending on library functions or files |
@@ -200,8 +198,7 @@ char * | |||
200 | getenv (); | 198 | getenv (); |
201 | 199 | ||
202 | static char * | 200 | static char * |
203 | my_index (const char *str, | 201 | my_index (const char *str, int chr) |
204 | int chr) | ||
205 | { | 202 | { |
206 | while (*str) | 203 | while (*str) |
207 | { | 204 | { |
@@ -217,7 +214,7 @@ my_index (const char *str, | |||
217 | #ifdef __GNUC__ | 214 | #ifdef __GNUC__ |
218 | /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. | 215 | /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. |
219 | That was relevant to code that was here before. */ | 216 | That was relevant to code that was here before. */ |
220 | #if !defined (__STDC__) || !__STDC__ | 217 | #if ! defined(__STDC__) || ! __STDC__ |
221 | /* gcc with -traditional declares the built-in strlen to return int, | 218 | /* gcc with -traditional declares the built-in strlen to return int, |
222 | and has done so at least since version 2.4.5. -- rms. */ | 219 | and has done so at least since version 2.4.5. -- rms. */ |
223 | extern int | 220 | extern int |
@@ -247,7 +244,7 @@ static int last_nonopt; | |||
247 | `first_nonopt' and `last_nonopt' are relocated so that they describe | 244 | `first_nonopt' and `last_nonopt' are relocated so that they describe |
248 | the new indices of the non-options in ARGV after they are moved. */ | 245 | the new indices of the non-options in ARGV after they are moved. */ |
249 | 246 | ||
250 | #if defined (__STDC__) && __STDC__ | 247 | #if defined(__STDC__) && __STDC__ |
251 | static void | 248 | static void |
252 | exchange (char **); | 249 | exchange (char **); |
253 | #endif | 250 | #endif |
@@ -311,14 +308,12 @@ exchange (char **argv) | |||
311 | 308 | ||
312 | /* Initialize the internal data when the first call is made. */ | 309 | /* Initialize the internal data when the first call is made. */ |
313 | 310 | ||
314 | #if defined (__STDC__) && __STDC__ | 311 | #if defined(__STDC__) && __STDC__ |
315 | static const char * | 312 | static const char * |
316 | _getopt_initialize (int, char *const *, const char *); | 313 | _getopt_initialize (int, char *const *, const char *); |
317 | #endif | 314 | #endif |
318 | static const char * | 315 | static const char * |
319 | _getopt_initialize (int argc, | 316 | _getopt_initialize (int argc, char *const *argv, const char *optstring) |
320 | char *const *argv, | ||
321 | const char *optstring) | ||
322 | { | 317 | { |
323 | /* Start processing options with ARGV-element 1 (since ARGV-element 0 | 318 | /* Start processing options with ARGV-element 1 (since ARGV-element 0 |
324 | * is the program name); the sequence of previously skipped | 319 | * is the program name); the sequence of previously skipped |
@@ -407,8 +402,11 @@ _getopt_initialize (int argc, | |||
407 | long-named options. */ | 402 | long-named options. */ |
408 | 403 | ||
409 | static int | 404 | static int |
410 | GN_getopt_internal (int argc, char *const *argv, const char *optstring, | 405 | GN_getopt_internal (int argc, |
411 | const struct GNoption *longopts, int *longind, | 406 | char *const *argv, |
407 | const char *optstring, | ||
408 | const struct GNoption *longopts, | ||
409 | int *longind, | ||
412 | int long_only) | 410 | int long_only) |
413 | { | 411 | { |
414 | static int __getopt_initialized = 0; | 412 | static int __getopt_initialized = 0; |
@@ -416,10 +414,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
416 | 414 | ||
417 | GNoptarg = NULL; | 415 | GNoptarg = NULL; |
418 | 416 | ||
419 | if (GNoptind == 0 || !__getopt_initialized) | 417 | if (GNoptind == 0 || ! __getopt_initialized) |
420 | { | 418 | { |
421 | if (GNoptind == 0) | 419 | if (GNoptind == 0) |
422 | GNoptind = 1; /* Don't scan ARGV[0], the program name. */ | 420 | GNoptind = 1; /* Don't scan ARGV[0], the program name. */ |
423 | optstring = _getopt_initialize (argc, argv, optstring); | 421 | optstring = _getopt_initialize (argc, argv, optstring); |
424 | __getopt_initialized = 1; | 422 | __getopt_initialized = 1; |
425 | } | 423 | } |
@@ -463,7 +461,7 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
463 | * Skip it like a null option, | 461 | * Skip it like a null option, |
464 | * then exchange with previous non-options as if it were an option, | 462 | * then exchange with previous non-options as if it were an option, |
465 | * then skip everything else like a non-option. */ | 463 | * then skip everything else like a non-option. */ |
466 | if (GNoptind != argc && !strcmp (argv[GNoptind], "--")) | 464 | if (GNoptind != argc && ! strcmp (argv[GNoptind], "--")) |
467 | { | 465 | { |
468 | GNoptind++; | 466 | GNoptind++; |
469 | 467 | ||
@@ -503,7 +501,7 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
503 | * Skip the initial punctuation. */ | 501 | * Skip the initial punctuation. */ |
504 | 502 | ||
505 | nextchar = | 503 | nextchar = |
506 | (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-')); | 504 | (argv[GNoptind] + 1 + (longopts != NULL && argv[GNoptind][1] == '-')); |
507 | } | 505 | } |
508 | 506 | ||
509 | /* Decode the current option-ARGV-element. */ | 507 | /* Decode the current option-ARGV-element. */ |
@@ -524,7 +522,7 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
524 | if (longopts != NULL && | 522 | if (longopts != NULL && |
525 | (argv[GNoptind][1] == '-' || | 523 | (argv[GNoptind][1] == '-' || |
526 | (long_only && | 524 | (long_only && |
527 | (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1]))))) | 525 | (argv[GNoptind][2] || ! my_index (optstring, argv[GNoptind][1]))))) |
528 | { | 526 | { |
529 | char *nameend; | 527 | char *nameend; |
530 | const struct GNoption *p; | 528 | const struct GNoption *p; |
@@ -535,12 +533,12 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
535 | int option_index; | 533 | int option_index; |
536 | 534 | ||
537 | for (nameend = nextchar; *nameend && *nameend != '='; nameend++) | 535 | for (nameend = nextchar; *nameend && *nameend != '='; nameend++) |
538 | /* Do nothing. */ ; | 536 | /* Do nothing. */; |
539 | 537 | ||
540 | /* Test all long options for either exact match | 538 | /* Test all long options for either exact match |
541 | * or abbreviated matches. */ | 539 | * or abbreviated matches. */ |
542 | for (p = longopts, option_index = 0; p->name; p++, option_index++) | 540 | for (p = longopts, option_index = 0; p->name; p++, option_index++) |
543 | if (!strncmp (p->name, nextchar, nameend - nextchar)) | 541 | if (! strncmp (p->name, nextchar, nameend - nextchar)) |
544 | { | 542 | { |
545 | if ((unsigned int) (nameend - nextchar) == | 543 | if ((unsigned int) (nameend - nextchar) == |
546 | (unsigned int) strlen (p->name)) | 544 | (unsigned int) strlen (p->name)) |
@@ -562,10 +560,12 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
562 | ambig = 1; | 560 | ambig = 1; |
563 | } | 561 | } |
564 | 562 | ||
565 | if (ambig && !exact) | 563 | if (ambig && ! exact) |
566 | { | 564 | { |
567 | if (GNopterr) | 565 | if (GNopterr) |
568 | FPRINTF (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], | 566 | FPRINTF (stderr, |
567 | _ ("%s: option `%s' is ambiguous\n"), | ||
568 | argv[0], | ||
569 | argv[GNoptind]); | 569 | argv[GNoptind]); |
570 | nextchar += strlen (nextchar); | 570 | nextchar += strlen (nextchar); |
571 | GNoptind++; | 571 | GNoptind++; |
@@ -589,13 +589,16 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
589 | if (argv[GNoptind - 1][1] == '-') | 589 | if (argv[GNoptind - 1][1] == '-') |
590 | /* --option */ | 590 | /* --option */ |
591 | FPRINTF (stderr, | 591 | FPRINTF (stderr, |
592 | _("%s: option `--%s' does not allow an argument\n"), | 592 | _ ("%s: option `--%s' does not allow an argument\n"), |
593 | argv[0], pfound->name); | 593 | argv[0], |
594 | pfound->name); | ||
594 | else | 595 | else |
595 | /* +option or -option */ | 596 | /* +option or -option */ |
596 | FPRINTF (stderr, | 597 | FPRINTF (stderr, |
597 | _("%s: option `%c%s' does not allow an argument\n"), | 598 | _ ("%s: option `%c%s' does not allow an argument\n"), |
598 | argv[0], argv[GNoptind - 1][0], pfound->name); | 599 | argv[0], |
600 | argv[GNoptind - 1][0], | ||
601 | pfound->name); | ||
599 | } | 602 | } |
600 | nextchar += strlen (nextchar); | 603 | nextchar += strlen (nextchar); |
601 | return '?'; | 604 | return '?'; |
@@ -611,8 +614,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
611 | { | 614 | { |
612 | if (GNopterr) | 615 | if (GNopterr) |
613 | { | 616 | { |
614 | FPRINTF (stderr, _("%s: option `%s' requires an argument\n"), | 617 | FPRINTF (stderr, |
615 | argv[0], argv[GNoptind - 1]); | 618 | _ ("%s: option `%s' requires an argument\n"), |
619 | argv[0], | ||
620 | argv[GNoptind - 1]); | ||
616 | } | 621 | } |
617 | nextchar += strlen (nextchar); | 622 | nextchar += strlen (nextchar); |
618 | return (optstring[0] == ':') ? ':' : '?'; | 623 | return (optstring[0] == ':') ? ':' : '?'; |
@@ -633,19 +638,24 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
633 | * or the option starts with '--' or is not a valid short | 638 | * or the option starts with '--' or is not a valid short |
634 | * option, then it's an error. | 639 | * option, then it's an error. |
635 | * Otherwise interpret it as a short option. */ | 640 | * Otherwise interpret it as a short option. */ |
636 | if (!long_only || argv[GNoptind][1] == '-' || | 641 | if (! long_only || argv[GNoptind][1] == '-' || |
637 | my_index (optstring, *nextchar) == NULL) | 642 | my_index (optstring, *nextchar) == NULL) |
638 | { | 643 | { |
639 | if (GNopterr) | 644 | if (GNopterr) |
640 | { | 645 | { |
641 | if (argv[GNoptind][1] == '-') | 646 | if (argv[GNoptind][1] == '-') |
642 | /* --option */ | 647 | /* --option */ |
643 | FPRINTF (stderr, _("%s: unrecognized option `--%s'\n"), argv[0], | 648 | FPRINTF (stderr, |
649 | _ ("%s: unrecognized option `--%s'\n"), | ||
650 | argv[0], | ||
644 | nextchar); | 651 | nextchar); |
645 | else | 652 | else |
646 | /* +option or -option */ | 653 | /* +option or -option */ |
647 | FPRINTF (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0], | 654 | FPRINTF (stderr, |
648 | argv[GNoptind][0], nextchar); | 655 | _ ("%s: unrecognized option `%c%s'\n"), |
656 | argv[0], | ||
657 | argv[GNoptind][0], | ||
658 | nextchar); | ||
649 | } | 659 | } |
650 | nextchar = (char *) ""; | 660 | nextchar = (char *) ""; |
651 | GNoptind++; | 661 | GNoptind++; |
@@ -669,9 +679,9 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
669 | { | 679 | { |
670 | if (posixly_correct) | 680 | if (posixly_correct) |
671 | /* 1003.2 specifies the format of this message. */ | 681 | /* 1003.2 specifies the format of this message. */ |
672 | FPRINTF (stderr, _("%s: illegal option -- %c\n"), argv[0], c); | 682 | FPRINTF (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c); |
673 | else | 683 | else |
674 | FPRINTF (stderr, _("%s: invalid option -- %c\n"), argv[0], c); | 684 | FPRINTF (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c); |
675 | } | 685 | } |
676 | return '?'; | 686 | return '?'; |
677 | } | 687 | } |
@@ -699,8 +709,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
699 | if (GNopterr) | 709 | if (GNopterr) |
700 | { | 710 | { |
701 | /* 1003.2 specifies the format of this message. */ | 711 | /* 1003.2 specifies the format of this message. */ |
702 | FPRINTF (stderr, _("%s: option requires an argument -- %c\n"), | 712 | FPRINTF (stderr, |
703 | argv[0], c); | 713 | _ ("%s: option requires an argument -- %c\n"), |
714 | argv[0], | ||
715 | c); | ||
704 | } | 716 | } |
705 | if (optstring[0] == ':') | 717 | if (optstring[0] == ':') |
706 | c = ':'; | 718 | c = ':'; |
@@ -718,13 +730,13 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
718 | 730 | ||
719 | for (nextchar = nameend = GNoptarg; *nameend && *nameend != '='; | 731 | for (nextchar = nameend = GNoptarg; *nameend && *nameend != '='; |
720 | nameend++) | 732 | nameend++) |
721 | /* Do nothing. */ ; | 733 | /* Do nothing. */; |
722 | 734 | ||
723 | /* Test all long options for either exact match | 735 | /* Test all long options for either exact match |
724 | * or abbreviated matches. */ | 736 | * or abbreviated matches. */ |
725 | if (longopts != NULL) | 737 | if (longopts != NULL) |
726 | for (p = longopts, option_index = 0; p->name; p++, option_index++) | 738 | for (p = longopts, option_index = 0; p->name; p++, option_index++) |
727 | if (!strncmp (p->name, nextchar, nameend - nextchar)) | 739 | if (! strncmp (p->name, nextchar, nameend - nextchar)) |
728 | { | 740 | { |
729 | if ((unsigned int) (nameend - nextchar) == strlen (p->name)) | 741 | if ((unsigned int) (nameend - nextchar) == strlen (p->name)) |
730 | { | 742 | { |
@@ -744,10 +756,12 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
744 | /* Second or later nonexact match found. */ | 756 | /* Second or later nonexact match found. */ |
745 | ambig = 1; | 757 | ambig = 1; |
746 | } | 758 | } |
747 | if (ambig && !exact) | 759 | if (ambig && ! exact) |
748 | { | 760 | { |
749 | if (GNopterr) | 761 | if (GNopterr) |
750 | FPRINTF (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0], | 762 | FPRINTF (stderr, |
763 | _ ("%s: option `-W %s' is ambiguous\n"), | ||
764 | argv[0], | ||
751 | argv[GNoptind]); | 765 | argv[GNoptind]); |
752 | nextchar += strlen (nextchar); | 766 | nextchar += strlen (nextchar); |
753 | GNoptind++; | 767 | GNoptind++; |
@@ -765,7 +779,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
765 | else | 779 | else |
766 | { | 780 | { |
767 | if (GNopterr) | 781 | if (GNopterr) |
768 | FPRINTF (stderr, _("%s: option `-W %s' does not allow an argument\n"), argv[0], pfound->name); | 782 | FPRINTF (stderr, |
783 | _ ("%s: option `-W %s' does not allow an argument\n"), | ||
784 | argv[0], | ||
785 | pfound->name); | ||
769 | 786 | ||
770 | nextchar += strlen (nextchar); | 787 | nextchar += strlen (nextchar); |
771 | return '?'; | 788 | return '?'; |
@@ -778,8 +795,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
778 | else | 795 | else |
779 | { | 796 | { |
780 | if (GNopterr) | 797 | if (GNopterr) |
781 | FPRINTF (stderr, _("%s: option `%s' requires an argument\n"), | 798 | FPRINTF (stderr, |
782 | argv[0], argv[GNoptind - 1]); | 799 | _ ("%s: option `%s' requires an argument\n"), |
800 | argv[0], | ||
801 | argv[GNoptind - 1]); | ||
783 | nextchar += strlen (nextchar); | 802 | nextchar += strlen (nextchar); |
784 | return optstring[0] == ':' ? ':' : '?'; | 803 | return optstring[0] == ':' ? ':' : '?'; |
785 | } | 804 | } |
@@ -795,7 +814,7 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
795 | return pfound->val; | 814 | return pfound->val; |
796 | } | 815 | } |
797 | nextchar = NULL; | 816 | nextchar = NULL; |
798 | return 'W'; /* Let the application handle it. */ | 817 | return 'W'; /* Let the application handle it. */ |
799 | } | 818 | } |
800 | if (temp[1] == ':') | 819 | if (temp[1] == ':') |
801 | { | 820 | { |
@@ -826,8 +845,10 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring, | |||
826 | if (GNopterr) | 845 | if (GNopterr) |
827 | { | 846 | { |
828 | /* 1003.2 specifies the format of this message. */ | 847 | /* 1003.2 specifies the format of this message. */ |
829 | FPRINTF (stderr, _("%s: option requires an argument -- %c\n"), | 848 | FPRINTF (stderr, |
830 | argv[0], c); | 849 | _ ("%s: option requires an argument -- %c\n"), |
850 | argv[0], | ||
851 | c); | ||
831 | } | 852 | } |
832 | if (optstring[0] == ':') | 853 | if (optstring[0] == ':') |
833 | c = ':'; | 854 | c = ':'; |
@@ -880,8 +901,9 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
880 | char *shorts; | 901 | char *shorts; |
881 | int spos; | 902 | int spos; |
882 | int cont; | 903 | int cont; |
883 | int c; | ||
884 | uint8_t *seen; | 904 | uint8_t *seen; |
905 | unsigned int optmatch = 0; | ||
906 | const char *have_exclusive = NULL; | ||
885 | 907 | ||
886 | GNUNET_assert (argc > 0); | 908 | GNUNET_assert (argc > 0); |
887 | GNoptind = 0; | 909 | GNoptind = 0; |
@@ -890,12 +912,13 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
890 | clpc.allOptions = allOptions; | 912 | clpc.allOptions = allOptions; |
891 | clpc.argv = argv; | 913 | clpc.argv = argv; |
892 | clpc.argc = argc; | 914 | clpc.argc = argc; |
893 | for (count = 0; NULL != allOptions[count].name; count++) ; | 915 | for (count = 0; NULL != allOptions[count].name; count++) |
916 | ; | ||
894 | 917 | ||
895 | long_options = GNUNET_new_array (count + 1, | 918 | /* transform our option representation into the format |
896 | struct GNoption); | 919 | used by the GNU getopt copylib */ |
897 | seen = GNUNET_new_array (count, | 920 | long_options = GNUNET_new_array (count + 1, struct GNoption); |
898 | uint8_t); | 921 | seen = GNUNET_new_array (count, uint8_t); |
899 | shorts = GNUNET_malloc (count * 2 + 1); | 922 | shorts = GNUNET_malloc (count * 2 + 1); |
900 | spos = 0; | 923 | spos = 0; |
901 | for (unsigned i = 0; i < count; i++) | 924 | for (unsigned i = 0; i < count; i++) |
@@ -916,53 +939,68 @@ GNUNET_GETOPT_run (const char *binaryOptions, | |||
916 | cont = GNUNET_OK; | 939 | cont = GNUNET_OK; |
917 | 940 | ||
918 | /* main getopt loop */ | 941 | /* main getopt loop */ |
919 | while (GNUNET_OK == cont) | 942 | while (1) |
920 | { | 943 | { |
921 | int option_index = 0; | 944 | int option_index = 0; |
922 | unsigned int i; | 945 | unsigned int i; |
946 | int c; | ||
923 | 947 | ||
924 | c = GNgetopt_long (argc, argv, | 948 | c = GNgetopt_long (argc, argv, shorts, long_options, &option_index); |
925 | shorts, | ||
926 | long_options, | ||
927 | &option_index); | ||
928 | if (c == GNUNET_SYSERR) | 949 | if (c == GNUNET_SYSERR) |
929 | break; /* No more flags to process */ | 950 | break; /* No more flags to process */ |
930 | 951 | ||
952 | /* Check which of our program's options was given by the user */ | ||
931 | for (i = 0; i < count; i++) | 953 | for (i = 0; i < count; i++) |
932 | { | 954 | { |
933 | clpc.currentArgument = GNoptind - 1; | 955 | clpc.currentArgument = GNoptind - 1; |
934 | if ((char) c == allOptions[i].shortName) | 956 | if ((char) c == allOptions[i].shortName) |
935 | { | 957 | { |
936 | cont = allOptions[i].processor (&clpc, | 958 | optmatch++; |
937 | allOptions[i].scls, | 959 | if (allOptions[i].option_exclusive) |
938 | allOptions[i].name, | 960 | have_exclusive = allOptions[i].name; |
939 | GNoptarg); | 961 | if (GNUNET_OK == cont) |
962 | { | ||
963 | /* parse the option using the option-specific processor */ | ||
964 | cont = allOptions[i].processor (&clpc, | ||
965 | allOptions[i].scls, | ||
966 | allOptions[i].name, | ||
967 | GNoptarg); | ||
968 | } | ||
940 | seen[i] = 1; | 969 | seen[i] = 1; |
941 | break; | 970 | break; |
942 | } | 971 | } |
943 | } | 972 | } |
944 | if (i == count) | 973 | if (i == count) |
945 | { | 974 | { |
946 | FPRINTF (stderr, | 975 | FPRINTF (stderr, _ ("Use %s to get a list of options.\n"), "--help"); |
947 | _("Use %s to get a list of options.\n"), | ||
948 | "--help"); | ||
949 | cont = GNUNET_SYSERR; | 976 | cont = GNUNET_SYSERR; |
950 | } | 977 | } |
951 | } | 978 | } |
952 | GNUNET_free (shorts); | 979 | GNUNET_free (shorts); |
953 | GNUNET_free (long_options); | 980 | GNUNET_free (long_options); |
954 | 981 | ||
982 | /* check that if any option that was marked as exclusive | ||
983 | is the only option that was provided */ | ||
984 | if ((NULL != have_exclusive) && (optmatch > 1)) | ||
985 | { | ||
986 | FPRINTF (stderr, | ||
987 | _ ("Option `%s' can't be used with other options.\n"), | ||
988 | have_exclusive); | ||
989 | cont = GNUNET_SYSERR; | ||
990 | } | ||
955 | if (GNUNET_YES == cont) | 991 | if (GNUNET_YES == cont) |
956 | { | 992 | { |
993 | /* check that all mandatory options are present */ | ||
957 | for (count = 0; NULL != allOptions[count].name; count++) | 994 | for (count = 0; NULL != allOptions[count].name; count++) |
958 | if ( (0 == seen[count]) && | 995 | { |
959 | (allOptions[count].option_mandatory) ) | 996 | if ((0 == seen[count]) && (allOptions[count].option_mandatory)) |
960 | { | 997 | { |
961 | FPRINTF (stderr, | 998 | FPRINTF (stderr, |
962 | _("Missing mandatory option `%s'.\n"), | 999 | _ ("Missing mandatory option `%s'.\n"), |
963 | allOptions[count].name); | 1000 | allOptions[count].name); |
964 | cont = GNUNET_SYSERR; | 1001 | cont = GNUNET_SYSERR; |
965 | } | 1002 | } |
1003 | } | ||
966 | } | 1004 | } |
967 | GNUNET_free (seen); | 1005 | GNUNET_free (seen); |
968 | 1006 | ||
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c index 77032e501..05856beee 100644 --- a/src/util/getopt_helpers.c +++ b/src/util/getopt_helpers.c | |||
@@ -26,7 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | 28 | ||
29 | #define LOG(kind,...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__) | 29 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-getopt", __VA_ARGS__) |
30 | 30 | ||
31 | 31 | ||
32 | /** | 32 | /** |
@@ -48,9 +48,7 @@ print_version (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
48 | 48 | ||
49 | (void) option; | 49 | (void) option; |
50 | (void) value; | 50 | (void) value; |
51 | printf ("%s v%s\n", | 51 | printf ("%s v%s\n", ctx->binaryName, version); |
52 | ctx->binaryName, | ||
53 | version); | ||
54 | return GNUNET_NO; | 52 | return GNUNET_NO; |
55 | } | 53 | } |
56 | 54 | ||
@@ -64,13 +62,13 @@ print_version (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
64 | struct GNUNET_GETOPT_CommandLineOption | 62 | struct GNUNET_GETOPT_CommandLineOption |
65 | GNUNET_GETOPT_option_version (const char *version) | 63 | GNUNET_GETOPT_option_version (const char *version) |
66 | { | 64 | { |
67 | struct GNUNET_GETOPT_CommandLineOption clo = { | 65 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = 'v', |
68 | .shortName = 'v', | 66 | .name = "version", |
69 | .name = "version", | 67 | .description = gettext_noop ( |
70 | .description = gettext_noop("print the version number"), | 68 | "print the version number"), |
71 | .processor = &print_version, | 69 | .option_exclusive = 1, |
72 | .scls = (void *) version | 70 | .processor = &print_version, |
73 | }; | 71 | .scls = (void *) version}; |
74 | return clo; | 72 | return clo; |
75 | } | 73 | } |
76 | 74 | ||
@@ -110,10 +108,9 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
110 | (void) value; | 108 | (void) value; |
111 | if (NULL != about) | 109 | if (NULL != about) |
112 | { | 110 | { |
113 | printf ("%s\n%s\n", | 111 | printf ("%s\n%s\n", ctx->binaryOptions, gettext (about)); |
114 | ctx->binaryOptions, | 112 | printf (_ ( |
115 | gettext (about)); | 113 | "Arguments mandatory for long options are also mandatory for short options.\n")); |
116 | printf (_("Arguments mandatory for long options are also mandatory for short options.\n")); | ||
117 | } | 114 | } |
118 | i = 0; | 115 | i = 0; |
119 | opt = ctx->allOptions; | 116 | opt = ctx->allOptions; |
@@ -146,7 +143,7 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
146 | trans = ""; | 143 | trans = ""; |
147 | ml = strlen (trans); | 144 | ml = strlen (trans); |
148 | p = 0; | 145 | p = 0; |
149 | OUTER: | 146 | OUTER: |
150 | while (ml - p > 78 - slen) | 147 | while (ml - p > 78 - slen) |
151 | { | 148 | { |
152 | for (j = p + 78 - slen; j > (int) p; j--) | 149 | for (j = p + 78 - slen; j > (int) p; j--) |
@@ -198,13 +195,13 @@ OUTER: | |||
198 | struct GNUNET_GETOPT_CommandLineOption | 195 | struct GNUNET_GETOPT_CommandLineOption |
199 | GNUNET_GETOPT_option_help (const char *about) | 196 | GNUNET_GETOPT_option_help (const char *about) |
200 | { | 197 | { |
201 | struct GNUNET_GETOPT_CommandLineOption clo = { | 198 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = 'h', |
202 | .shortName = 'h', | 199 | .name = "help", |
203 | .name = "help", | 200 | .description = gettext_noop ( |
204 | .description = gettext_noop("print this help"), | 201 | "print this help"), |
205 | .processor = format_help, | 202 | .option_exclusive = 1, |
206 | .scls = (void *) about | 203 | .processor = format_help, |
207 | }; | 204 | .scls = (void *) about}; |
208 | 205 | ||
209 | return clo; | 206 | return clo; |
210 | } | 207 | } |
@@ -251,17 +248,15 @@ increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
251 | */ | 248 | */ |
252 | struct GNUNET_GETOPT_CommandLineOption | 249 | struct GNUNET_GETOPT_CommandLineOption |
253 | GNUNET_GETOPT_option_increment_uint (char shortName, | 250 | GNUNET_GETOPT_option_increment_uint (char shortName, |
254 | const char *name, | 251 | const char *name, |
255 | const char *description, | 252 | const char *description, |
256 | unsigned int *val) | 253 | unsigned int *val) |
257 | { | 254 | { |
258 | struct GNUNET_GETOPT_CommandLineOption clo = { | 255 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
259 | .shortName = shortName, | 256 | .name = name, |
260 | .name = name, | 257 | .description = description, |
261 | .description = description, | 258 | .processor = &increment_value, |
262 | .processor = &increment_value, | 259 | .scls = (void *) val}; |
263 | .scls = (void *) val | ||
264 | }; | ||
265 | 260 | ||
266 | return clo; | 261 | return clo; |
267 | } | 262 | } |
@@ -276,13 +271,12 @@ GNUNET_GETOPT_option_increment_uint (char shortName, | |||
276 | struct GNUNET_GETOPT_CommandLineOption | 271 | struct GNUNET_GETOPT_CommandLineOption |
277 | GNUNET_GETOPT_option_verbose (unsigned int *level) | 272 | GNUNET_GETOPT_option_verbose (unsigned int *level) |
278 | { | 273 | { |
279 | struct GNUNET_GETOPT_CommandLineOption clo = { | 274 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = 'V', |
280 | .shortName = 'V', | 275 | .name = "verbose", |
281 | .name = "verbose", | 276 | .description = |
282 | .description = gettext_noop("be verbose"), | 277 | gettext_noop ("be verbose"), |
283 | .processor = &increment_value, | 278 | .processor = &increment_value, |
284 | .scls = (void *) level | 279 | .scls = (void *) level}; |
285 | }; | ||
286 | 280 | ||
287 | return clo; | 281 | return clo; |
288 | } | 282 | } |
@@ -330,17 +324,15 @@ set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
330 | */ | 324 | */ |
331 | struct GNUNET_GETOPT_CommandLineOption | 325 | struct GNUNET_GETOPT_CommandLineOption |
332 | GNUNET_GETOPT_option_flag (char shortName, | 326 | GNUNET_GETOPT_option_flag (char shortName, |
333 | const char *name, | 327 | const char *name, |
334 | const char *description, | 328 | const char *description, |
335 | int *val) | 329 | int *val) |
336 | { | 330 | { |
337 | struct GNUNET_GETOPT_CommandLineOption clo = { | 331 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
338 | .shortName = shortName, | 332 | .name = name, |
339 | .name = name, | 333 | .description = description, |
340 | .description = description, | 334 | .processor = &set_one, |
341 | .processor = &set_one, | 335 | .scls = (void *) val}; |
342 | .scls = (void *) val | ||
343 | }; | ||
344 | 336 | ||
345 | return clo; | 337 | return clo; |
346 | } | 338 | } |
@@ -393,15 +385,13 @@ GNUNET_GETOPT_option_string (char shortName, | |||
393 | const char *description, | 385 | const char *description, |
394 | char **str) | 386 | char **str) |
395 | { | 387 | { |
396 | struct GNUNET_GETOPT_CommandLineOption clo = { | 388 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
397 | .shortName = shortName, | 389 | .name = name, |
398 | .name = name, | 390 | .argumentHelp = argumentHelp, |
399 | .argumentHelp = argumentHelp, | 391 | .description = description, |
400 | .description = description, | 392 | .require_argument = 1, |
401 | .require_argument = 1, | 393 | .processor = &set_string, |
402 | .processor = &set_string, | 394 | .scls = (void *) str}; |
403 | .scls = (void *) str | ||
404 | }; | ||
405 | 395 | ||
406 | return clo; | 396 | return clo; |
407 | } | 397 | } |
@@ -416,15 +406,14 @@ GNUNET_GETOPT_option_string (char shortName, | |||
416 | struct GNUNET_GETOPT_CommandLineOption | 406 | struct GNUNET_GETOPT_CommandLineOption |
417 | GNUNET_GETOPT_option_loglevel (char **level) | 407 | GNUNET_GETOPT_option_loglevel (char **level) |
418 | { | 408 | { |
419 | struct GNUNET_GETOPT_CommandLineOption clo = { | 409 | struct GNUNET_GETOPT_CommandLineOption clo = |
420 | .shortName = 'L', | 410 | {.shortName = 'L', |
421 | .name = "log", | 411 | .name = "log", |
422 | .argumentHelp = "LOGLEVEL", | 412 | .argumentHelp = "LOGLEVEL", |
423 | .description = gettext_noop("configure logging to use LOGLEVEL"), | 413 | .description = gettext_noop ("configure logging to use LOGLEVEL"), |
424 | .require_argument = 1, | 414 | .require_argument = 1, |
425 | .processor = &set_string, | 415 | .processor = &set_string, |
426 | .scls = (void *) level | 416 | .scls = (void *) level}; |
427 | }; | ||
428 | 417 | ||
429 | return clo; | 418 | return clo; |
430 | } | 419 | } |
@@ -469,20 +458,18 @@ set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
469 | */ | 458 | */ |
470 | struct GNUNET_GETOPT_CommandLineOption | 459 | struct GNUNET_GETOPT_CommandLineOption |
471 | GNUNET_GETOPT_option_filename (char shortName, | 460 | GNUNET_GETOPT_option_filename (char shortName, |
472 | const char *name, | 461 | const char *name, |
473 | const char *argumentHelp, | 462 | const char *argumentHelp, |
474 | const char *description, | 463 | const char *description, |
475 | char **str) | 464 | char **str) |
476 | { | 465 | { |
477 | struct GNUNET_GETOPT_CommandLineOption clo = { | 466 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
478 | .shortName = shortName, | 467 | .name = name, |
479 | .name = name, | 468 | .argumentHelp = argumentHelp, |
480 | .argumentHelp = argumentHelp, | 469 | .description = description, |
481 | .description = description, | 470 | .require_argument = 1, |
482 | .require_argument = 1, | 471 | .processor = &set_filename, |
483 | .processor = &set_filename, | 472 | .scls = (void *) str}; |
484 | .scls = (void *) str | ||
485 | }; | ||
486 | 473 | ||
487 | return clo; | 474 | return clo; |
488 | } | 475 | } |
@@ -496,15 +483,15 @@ GNUNET_GETOPT_option_filename (char shortName, | |||
496 | struct GNUNET_GETOPT_CommandLineOption | 483 | struct GNUNET_GETOPT_CommandLineOption |
497 | GNUNET_GETOPT_option_logfile (char **logfn) | 484 | GNUNET_GETOPT_option_logfile (char **logfn) |
498 | { | 485 | { |
499 | struct GNUNET_GETOPT_CommandLineOption clo = { | 486 | struct GNUNET_GETOPT_CommandLineOption clo = |
500 | .shortName = 'l', | 487 | {.shortName = 'l', |
501 | .name = "logfile", | 488 | .name = "logfile", |
502 | .argumentHelp = "FILENAME", | 489 | .argumentHelp = "FILENAME", |
503 | .description = gettext_noop ("configure logging to write logs to FILENAME"), | 490 | .description = |
504 | .require_argument = 1, | 491 | gettext_noop ("configure logging to write logs to FILENAME"), |
505 | .processor = &set_filename, | 492 | .require_argument = 1, |
506 | .scls = (void *) logfn | 493 | .processor = &set_filename, |
507 | }; | 494 | .scls = (void *) logfn}; |
508 | 495 | ||
509 | return clo; | 496 | return clo; |
510 | } | 497 | } |
@@ -518,15 +505,14 @@ GNUNET_GETOPT_option_logfile (char **logfn) | |||
518 | struct GNUNET_GETOPT_CommandLineOption | 505 | struct GNUNET_GETOPT_CommandLineOption |
519 | GNUNET_GETOPT_option_cfgfile (char **fn) | 506 | GNUNET_GETOPT_option_cfgfile (char **fn) |
520 | { | 507 | { |
521 | struct GNUNET_GETOPT_CommandLineOption clo = { | 508 | struct GNUNET_GETOPT_CommandLineOption clo = |
522 | .shortName = 'c', | 509 | {.shortName = 'c', |
523 | .name = "config", | 510 | .name = "config", |
524 | .argumentHelp = "FILENAME", | 511 | .argumentHelp = "FILENAME", |
525 | .description = gettext_noop("use configuration file FILENAME"), | 512 | .description = gettext_noop ("use configuration file FILENAME"), |
526 | .require_argument = 1, | 513 | .require_argument = 1, |
527 | .processor = &set_filename, | 514 | .processor = &set_filename, |
528 | .scls = (void *) fn | 515 | .scls = (void *) fn}; |
529 | }; | ||
530 | 516 | ||
531 | return clo; | 517 | return clo; |
532 | } | 518 | } |
@@ -555,13 +541,10 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
555 | char dummy[2]; | 541 | char dummy[2]; |
556 | 542 | ||
557 | (void) ctx; | 543 | (void) ctx; |
558 | if (1 != SSCANF (value, | 544 | if (1 != SSCANF (value, "%llu%1s", val, dummy)) |
559 | "%llu%1s", | ||
560 | val, | ||
561 | dummy)) | ||
562 | { | 545 | { |
563 | FPRINTF (stderr, | 546 | FPRINTF (stderr, |
564 | _("You must pass a number to the `%s' option.\n"), | 547 | _ ("You must pass a number to the `%s' option.\n"), |
565 | option); | 548 | option); |
566 | return GNUNET_SYSERR; | 549 | return GNUNET_SYSERR; |
567 | } | 550 | } |
@@ -580,20 +563,18 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
580 | */ | 563 | */ |
581 | struct GNUNET_GETOPT_CommandLineOption | 564 | struct GNUNET_GETOPT_CommandLineOption |
582 | GNUNET_GETOPT_option_ulong (char shortName, | 565 | GNUNET_GETOPT_option_ulong (char shortName, |
583 | const char *name, | 566 | const char *name, |
584 | const char *argumentHelp, | 567 | const char *argumentHelp, |
585 | const char *description, | 568 | const char *description, |
586 | unsigned long long *val) | 569 | unsigned long long *val) |
587 | { | 570 | { |
588 | struct GNUNET_GETOPT_CommandLineOption clo = { | 571 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
589 | .shortName = shortName, | 572 | .name = name, |
590 | .name = name, | 573 | .argumentHelp = argumentHelp, |
591 | .argumentHelp = argumentHelp, | 574 | .description = description, |
592 | .description = description, | 575 | .require_argument = 1, |
593 | .require_argument = 1, | 576 | .processor = &set_ulong, |
594 | .processor = &set_ulong, | 577 | .scls = (void *) val}; |
595 | .scls = (void *) val | ||
596 | }; | ||
597 | 578 | ||
598 | return clo; | 579 | return clo; |
599 | } | 580 | } |
@@ -619,14 +600,12 @@ set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
619 | const char *value) | 600 | const char *value) |
620 | { | 601 | { |
621 | struct GNUNET_TIME_Relative *val = scls; | 602 | struct GNUNET_TIME_Relative *val = scls; |
622 | 603 | ||
623 | (void) ctx; | 604 | (void) ctx; |
624 | if (GNUNET_OK != | 605 | if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (value, val)) |
625 | GNUNET_STRINGS_fancy_time_to_relative (value, | ||
626 | val)) | ||
627 | { | 606 | { |
628 | FPRINTF (stderr, | 607 | FPRINTF (stderr, |
629 | _("You must pass relative time to the `%s' option.\n"), | 608 | _ ("You must pass relative time to the `%s' option.\n"), |
630 | option); | 609 | option); |
631 | return GNUNET_SYSERR; | 610 | return GNUNET_SYSERR; |
632 | } | 611 | } |
@@ -646,20 +625,18 @@ set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
646 | */ | 625 | */ |
647 | struct GNUNET_GETOPT_CommandLineOption | 626 | struct GNUNET_GETOPT_CommandLineOption |
648 | GNUNET_GETOPT_option_relative_time (char shortName, | 627 | GNUNET_GETOPT_option_relative_time (char shortName, |
649 | const char *name, | 628 | const char *name, |
650 | const char *argumentHelp, | 629 | const char *argumentHelp, |
651 | const char *description, | 630 | const char *description, |
652 | struct GNUNET_TIME_Relative *val) | 631 | struct GNUNET_TIME_Relative *val) |
653 | { | 632 | { |
654 | struct GNUNET_GETOPT_CommandLineOption clo = { | 633 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
655 | .shortName = shortName, | 634 | .name = name, |
656 | .name = name, | 635 | .argumentHelp = argumentHelp, |
657 | .argumentHelp = argumentHelp, | 636 | .description = description, |
658 | .description = description, | 637 | .require_argument = 1, |
659 | .require_argument = 1, | 638 | .processor = &set_relative_time, |
660 | .processor = &set_relative_time, | 639 | .scls = (void *) val}; |
661 | .scls = (void *) val | ||
662 | }; | ||
663 | 640 | ||
664 | return clo; | 641 | return clo; |
665 | } | 642 | } |
@@ -687,12 +664,10 @@ set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
687 | struct GNUNET_TIME_Absolute *val = scls; | 664 | struct GNUNET_TIME_Absolute *val = scls; |
688 | 665 | ||
689 | (void) ctx; | 666 | (void) ctx; |
690 | if (GNUNET_OK != | 667 | if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (value, val)) |
691 | GNUNET_STRINGS_fancy_time_to_absolute (value, | ||
692 | val)) | ||
693 | { | 668 | { |
694 | FPRINTF (stderr, | 669 | FPRINTF (stderr, |
695 | _("You must pass absolute time to the `%s' option.\n"), | 670 | _ ("You must pass absolute time to the `%s' option.\n"), |
696 | option); | 671 | option); |
697 | return GNUNET_SYSERR; | 672 | return GNUNET_SYSERR; |
698 | } | 673 | } |
@@ -712,20 +687,18 @@ set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
712 | */ | 687 | */ |
713 | struct GNUNET_GETOPT_CommandLineOption | 688 | struct GNUNET_GETOPT_CommandLineOption |
714 | GNUNET_GETOPT_option_absolute_time (char shortName, | 689 | GNUNET_GETOPT_option_absolute_time (char shortName, |
715 | const char *name, | 690 | const char *name, |
716 | const char *argumentHelp, | 691 | const char *argumentHelp, |
717 | const char *description, | 692 | const char *description, |
718 | struct GNUNET_TIME_Absolute *val) | 693 | struct GNUNET_TIME_Absolute *val) |
719 | { | 694 | { |
720 | struct GNUNET_GETOPT_CommandLineOption clo = { | 695 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
721 | .shortName = shortName, | 696 | .name = name, |
722 | .name = name, | 697 | .argumentHelp = argumentHelp, |
723 | .argumentHelp = argumentHelp, | 698 | .description = description, |
724 | .description = description, | 699 | .require_argument = 1, |
725 | .require_argument = 1, | 700 | .processor = &set_absolute_time, |
726 | .processor = &set_absolute_time, | 701 | .scls = (void *) val}; |
727 | .scls = (void *) val | ||
728 | }; | ||
729 | 702 | ||
730 | return clo; | 703 | return clo; |
731 | } | 704 | } |
@@ -754,20 +727,18 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
754 | char dummy[2]; | 727 | char dummy[2]; |
755 | 728 | ||
756 | (void) ctx; | 729 | (void) ctx; |
757 | if('-' == *value) | 730 | if ('-' == *value) |
758 | { | 731 | { |
759 | FPRINTF (stderr, | 732 | FPRINTF (stderr, |
760 | _("Your input for the '%s' option has to be a non negative number \n"), | 733 | _ ( |
761 | option); | 734 | "Your input for the '%s' option has to be a non negative number \n"), |
762 | return GNUNET_SYSERR; | 735 | option); |
736 | return GNUNET_SYSERR; | ||
763 | } | 737 | } |
764 | if (1 != SSCANF (value, | 738 | if (1 != SSCANF (value, "%u%1s", val, dummy)) |
765 | "%u%1s", | ||
766 | val, | ||
767 | dummy)) | ||
768 | { | 739 | { |
769 | FPRINTF (stderr, | 740 | FPRINTF (stderr, |
770 | _("You must pass a number to the `%s' option.\n"), | 741 | _ ("You must pass a number to the `%s' option.\n"), |
771 | option); | 742 | option); |
772 | return GNUNET_SYSERR; | 743 | return GNUNET_SYSERR; |
773 | } | 744 | } |
@@ -786,26 +757,23 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
786 | */ | 757 | */ |
787 | struct GNUNET_GETOPT_CommandLineOption | 758 | struct GNUNET_GETOPT_CommandLineOption |
788 | GNUNET_GETOPT_option_uint (char shortName, | 759 | GNUNET_GETOPT_option_uint (char shortName, |
789 | const char *name, | 760 | const char *name, |
790 | const char *argumentHelp, | 761 | const char *argumentHelp, |
791 | const char *description, | 762 | const char *description, |
792 | unsigned int *val) | 763 | unsigned int *val) |
793 | { | 764 | { |
794 | struct GNUNET_GETOPT_CommandLineOption clo = { | 765 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
795 | .shortName = shortName, | 766 | .name = name, |
796 | .name = name, | 767 | .argumentHelp = argumentHelp, |
797 | .argumentHelp = argumentHelp, | 768 | .description = description, |
798 | .description = description, | 769 | .require_argument = 1, |
799 | .require_argument = 1, | 770 | .processor = &set_uint, |
800 | .processor = &set_uint, | 771 | .scls = (void *) val}; |
801 | .scls = (void *) val | ||
802 | }; | ||
803 | 772 | ||
804 | return clo; | 773 | return clo; |
805 | } | 774 | } |
806 | 775 | ||
807 | 776 | ||
808 | |||
809 | /** | 777 | /** |
810 | * Set an option of type 'uint16_t' from the command line. | 778 | * Set an option of type 'uint16_t' from the command line. |
811 | * A pointer to this function should be passed as part of the | 779 | * A pointer to this function should be passed as part of the |
@@ -821,30 +789,27 @@ GNUNET_GETOPT_option_uint (char shortName, | |||
821 | */ | 789 | */ |
822 | static int | 790 | static int |
823 | set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | 791 | set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, |
824 | void *scls, | 792 | void *scls, |
825 | const char *option, | 793 | const char *option, |
826 | const char *value) | 794 | const char *value) |
827 | { | 795 | { |
828 | uint16_t *val = scls; | 796 | uint16_t *val = scls; |
829 | unsigned int v; | 797 | unsigned int v; |
830 | char dummy[2]; | 798 | char dummy[2]; |
831 | 799 | ||
832 | (void) ctx; | 800 | (void) ctx; |
833 | if (1 != SSCANF (value, | 801 | if (1 != SSCANF (value, "%u%1s", &v, dummy)) |
834 | "%u%1s", | ||
835 | &v, | ||
836 | dummy)) | ||
837 | { | 802 | { |
838 | FPRINTF (stderr, | 803 | FPRINTF (stderr, |
839 | _("You must pass a number to the `%s' option.\n"), | 804 | _ ("You must pass a number to the `%s' option.\n"), |
840 | option); | 805 | option); |
841 | return GNUNET_SYSERR; | 806 | return GNUNET_SYSERR; |
842 | } | 807 | } |
843 | if (v > UINT16_MAX) | 808 | if (v > UINT16_MAX) |
844 | { | 809 | { |
845 | FPRINTF (stderr, | 810 | FPRINTF (stderr, |
846 | _("You must pass a number below %u to the `%s' option.\n"), | 811 | _ ("You must pass a number below %u to the `%s' option.\n"), |
847 | (unsigned int) UINT16_MAX, | 812 | (unsigned int) UINT16_MAX, |
848 | option); | 813 | option); |
849 | return GNUNET_SYSERR; | 814 | return GNUNET_SYSERR; |
850 | } | 815 | } |
@@ -864,20 +829,18 @@ set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
864 | */ | 829 | */ |
865 | struct GNUNET_GETOPT_CommandLineOption | 830 | struct GNUNET_GETOPT_CommandLineOption |
866 | GNUNET_GETOPT_option_uint16 (char shortName, | 831 | GNUNET_GETOPT_option_uint16 (char shortName, |
867 | const char *name, | 832 | const char *name, |
868 | const char *argumentHelp, | 833 | const char *argumentHelp, |
869 | const char *description, | 834 | const char *description, |
870 | uint16_t *val) | 835 | uint16_t *val) |
871 | { | 836 | { |
872 | struct GNUNET_GETOPT_CommandLineOption clo = { | 837 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
873 | .shortName = shortName, | 838 | .name = name, |
874 | .name = name, | 839 | .argumentHelp = argumentHelp, |
875 | .argumentHelp = argumentHelp, | 840 | .description = description, |
876 | .description = description, | 841 | .require_argument = 1, |
877 | .require_argument = 1, | 842 | .processor = &set_uint16, |
878 | .processor = &set_uint16, | 843 | .scls = (void *) val}; |
879 | .scls = (void *) val | ||
880 | }; | ||
881 | 844 | ||
882 | return clo; | 845 | return clo; |
883 | } | 846 | } |
@@ -922,15 +885,16 @@ set_base32 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, | |||
922 | struct Base32Context *bc = scls; | 885 | struct Base32Context *bc = scls; |
923 | 886 | ||
924 | (void) ctx; | 887 | (void) ctx; |
925 | if (GNUNET_OK != | 888 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (value, |
926 | GNUNET_STRINGS_string_to_data (value, | 889 | strlen (value), |
927 | strlen (value), | 890 | bc->val, |
928 | bc->val, | 891 | bc->val_size)) |
929 | bc->val_size)) | ||
930 | { | 892 | { |
931 | fprintf (stderr, | 893 | fprintf ( |
932 | _("Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"), | 894 | stderr, |
933 | option); | 895 | _ ( |
896 | "Argument `%s' malformed. Expected base32 (Crockford) encoded value.\n"), | ||
897 | option); | ||
934 | return GNUNET_SYSERR; | 898 | return GNUNET_SYSERR; |
935 | } | 899 | } |
936 | return GNUNET_OK; | 900 | return GNUNET_OK; |
@@ -963,23 +927,21 @@ free_bc (void *cls) | |||
963 | */ | 927 | */ |
964 | struct GNUNET_GETOPT_CommandLineOption | 928 | struct GNUNET_GETOPT_CommandLineOption |
965 | GNUNET_GETOPT_option_base32_fixed_size (char shortName, | 929 | GNUNET_GETOPT_option_base32_fixed_size (char shortName, |
966 | const char *name, | 930 | const char *name, |
967 | const char *argumentHelp, | 931 | const char *argumentHelp, |
968 | const char *description, | 932 | const char *description, |
969 | void *val, | 933 | void *val, |
970 | size_t val_size) | 934 | size_t val_size) |
971 | { | 935 | { |
972 | struct Base32Context *bc = GNUNET_new (struct Base32Context); | 936 | struct Base32Context *bc = GNUNET_new (struct Base32Context); |
973 | struct GNUNET_GETOPT_CommandLineOption clo = { | 937 | struct GNUNET_GETOPT_CommandLineOption clo = {.shortName = shortName, |
974 | .shortName = shortName, | 938 | .name = name, |
975 | .name = name, | 939 | .argumentHelp = argumentHelp, |
976 | .argumentHelp = argumentHelp, | 940 | .description = description, |
977 | .description = description, | 941 | .require_argument = 1, |
978 | .require_argument = 1, | 942 | .processor = &set_base32, |
979 | .processor = &set_base32, | 943 | .cleaner = &free_bc, |
980 | .cleaner = &free_bc, | 944 | .scls = (void *) bc}; |
981 | .scls = (void *) bc | ||
982 | }; | ||
983 | 945 | ||
984 | bc->val = val; | 946 | bc->val = val; |
985 | bc->val_size = val_size; | 947 | bc->val_size = val_size; |
@@ -1001,4 +963,18 @@ GNUNET_GETOPT_option_mandatory (struct GNUNET_GETOPT_CommandLineOption opt) | |||
1001 | } | 963 | } |
1002 | 964 | ||
1003 | 965 | ||
966 | /** | ||
967 | * Make the given option mutually exclusive with other options. | ||
968 | * | ||
969 | * @param opt option to modify | ||
970 | * @return @a opt with the exclusive flag set. | ||
971 | */ | ||
972 | struct GNUNET_GETOPT_CommandLineOption | ||
973 | GNUNET_GETOPT_option_exclusive (struct GNUNET_GETOPT_CommandLineOption opt) | ||
974 | { | ||
975 | opt.option_exclusive = 1; | ||
976 | return opt; | ||
977 | } | ||
978 | |||
979 | |||
1004 | /* end of getopt_helpers.c */ | 980 | /* end of getopt_helpers.c */ |
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index f700428a2..3b9b64d4e 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c | |||
@@ -43,6 +43,13 @@ static char *option; | |||
43 | static char *value; | 43 | static char *value; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Backend to check if the respective plugin is | ||
47 | * loadable. NULL if no check is to be performed. | ||
48 | * The value is the "basename" of the plugin to load. | ||
49 | */ | ||
50 | static char *backend_check; | ||
51 | |||
52 | /** | ||
46 | * Treat option as a filename. | 53 | * Treat option as a filename. |
47 | */ | 54 | */ |
48 | static int is_filename; | 55 | static int is_filename; |
@@ -55,7 +62,7 @@ static int list_sections; | |||
55 | /** | 62 | /** |
56 | * Return value from 'main'. | 63 | * Return value from 'main'. |
57 | */ | 64 | */ |
58 | static int ret; | 65 | static int global_ret; |
59 | 66 | ||
60 | /** | 67 | /** |
61 | * Should we generate a configuration file that is clean and | 68 | * Should we generate a configuration file that is clean and |
@@ -63,6 +70,7 @@ static int ret; | |||
63 | */ | 70 | */ |
64 | static int rewrite; | 71 | static int rewrite; |
65 | 72 | ||
73 | |||
66 | /** | 74 | /** |
67 | * Print each option in a given section. | 75 | * Print each option in a given section. |
68 | * | 76 | * |
@@ -95,18 +103,12 @@ print_option (void *cls, | |||
95 | fn = value_fn; | 103 | fn = value_fn; |
96 | else | 104 | else |
97 | GNUNET_free (value_fn); | 105 | GNUNET_free (value_fn); |
98 | fprintf (stdout, | 106 | fprintf (stdout, "%s = %s\n", option, fn); |
99 | "%s = %s\n", | ||
100 | option, | ||
101 | fn); | ||
102 | GNUNET_free (fn); | 107 | GNUNET_free (fn); |
103 | } | 108 | } |
104 | else | 109 | else |
105 | { | 110 | { |
106 | fprintf (stdout, | 111 | fprintf (stdout, "%s = %s\n", option, value); |
107 | "%s = %s\n", | ||
108 | option, | ||
109 | value); | ||
110 | } | 112 | } |
111 | } | 113 | } |
112 | 114 | ||
@@ -118,13 +120,10 @@ print_option (void *cls, | |||
118 | * @param section a section in the configuration file | 120 | * @param section a section in the configuration file |
119 | */ | 121 | */ |
120 | static void | 122 | static void |
121 | print_section_name (void *cls, | 123 | print_section_name (void *cls, const char *section) |
122 | const char *section) | ||
123 | { | 124 | { |
124 | (void) cls; | 125 | (void) cls; |
125 | fprintf (stdout, | 126 | fprintf (stdout, "%s\n", section); |
126 | "%s\n", | ||
127 | section); | ||
128 | } | 127 | } |
129 | 128 | ||
130 | 129 | ||
@@ -149,45 +148,48 @@ run (void *cls, | |||
149 | 148 | ||
150 | (void) cls; | 149 | (void) cls; |
151 | (void) args; | 150 | (void) args; |
151 | if (NULL != backend_check) | ||
152 | { | ||
153 | char *name; | ||
154 | |||
155 | GNUNET_asprintf (&name, "libgnunet_plugin_%s", backend_check); | ||
156 | global_ret = (GNUNET_OK == GNUNET_PLUGIN_test (name)) ? 0 : 77; | ||
157 | GNUNET_free (name); | ||
158 | return; | ||
159 | } | ||
152 | if (rewrite) | 160 | if (rewrite) |
153 | { | 161 | { |
154 | struct GNUNET_CONFIGURATION_Handle *def; | 162 | struct GNUNET_CONFIGURATION_Handle *def; |
155 | 163 | ||
156 | def = GNUNET_CONFIGURATION_create (); | 164 | def = GNUNET_CONFIGURATION_create (); |
157 | if (GNUNET_OK != | 165 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (def, NULL)) |
158 | GNUNET_CONFIGURATION_load (def, NULL)) | ||
159 | { | 166 | { |
160 | fprintf (stderr, | 167 | fprintf (stderr, _ ("failed to load configuration defaults")); |
161 | _("failed to load configuration defaults")); | 168 | global_ret = 1; |
162 | ret = 1; | ||
163 | return; | 169 | return; |
164 | } | 170 | } |
165 | diff = GNUNET_CONFIGURATION_get_diff (def, | 171 | diff = GNUNET_CONFIGURATION_get_diff (def, cfg); |
166 | cfg); | ||
167 | cfg = diff; | 172 | cfg = diff; |
168 | } | 173 | } |
169 | if ( ((! rewrite) && (NULL == section)) || list_sections) | 174 | if (((! rewrite) && (NULL == section)) || list_sections) |
170 | { | 175 | { |
171 | if (! list_sections) | 176 | if (! list_sections) |
172 | { | 177 | { |
173 | fprintf (stderr, | 178 | fprintf (stderr, |
174 | _("%s or %s argument is required\n"), | 179 | _ ("%s or %s argument is required\n"), |
175 | "--section", | 180 | "--section", |
176 | "--list-sections"); | 181 | "--list-sections"); |
177 | ret = 1; | 182 | global_ret = 1; |
178 | } | 183 | } |
179 | else | 184 | else |
180 | { | 185 | { |
181 | fprintf (stderr, | 186 | fprintf (stderr, _ ("The following sections are available:\n")); |
182 | _("The following sections are available:\n")); | 187 | GNUNET_CONFIGURATION_iterate_sections (cfg, &print_section_name, NULL); |
183 | GNUNET_CONFIGURATION_iterate_sections (cfg, | ||
184 | &print_section_name, | ||
185 | NULL); | ||
186 | } | 188 | } |
187 | goto cleanup; | 189 | goto cleanup; |
188 | } | 190 | } |
189 | 191 | ||
190 | if ( (NULL != section) && (NULL == value) ) | 192 | if ((NULL != section) && (NULL == value)) |
191 | { | 193 | { |
192 | if (NULL == option) | 194 | if (NULL == option) |
193 | { | 195 | { |
@@ -200,27 +202,25 @@ run (void *cls, | |||
200 | { | 202 | { |
201 | if (is_filename) | 203 | if (is_filename) |
202 | { | 204 | { |
203 | if (GNUNET_OK != | 205 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
204 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 206 | section, |
205 | section, | 207 | option, |
206 | option, | 208 | &value)) |
207 | &value)) | ||
208 | { | 209 | { |
209 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 210 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, option); |
210 | section, option); | 211 | global_ret = 3; |
211 | ret = 3; | ||
212 | goto cleanup; | 212 | goto cleanup; |
213 | } | 213 | } |
214 | } | 214 | } |
215 | else | 215 | else |
216 | { | 216 | { |
217 | if (GNUNET_OK != | 217 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
218 | GNUNET_CONFIGURATION_get_value_string (cfg, section, | 218 | section, |
219 | option, &value)) | 219 | option, |
220 | &value)) | ||
220 | { | 221 | { |
221 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 222 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, option); |
222 | section, option); | 223 | global_ret = 3; |
223 | ret = 3; | ||
224 | goto cleanup; | 224 | goto cleanup; |
225 | } | 225 | } |
226 | } | 226 | } |
@@ -231,15 +231,12 @@ run (void *cls, | |||
231 | { | 231 | { |
232 | if (NULL == option) | 232 | if (NULL == option) |
233 | { | 233 | { |
234 | fprintf (stderr, _("--option argument required to set value\n")); | 234 | fprintf (stderr, _ ("--option argument required to set value\n")); |
235 | ret = 1; | 235 | global_ret = 1; |
236 | goto cleanup; | 236 | goto cleanup; |
237 | } | 237 | } |
238 | out = GNUNET_CONFIGURATION_dup (cfg); | 238 | out = GNUNET_CONFIGURATION_dup (cfg); |
239 | GNUNET_CONFIGURATION_set_value_string (out, | 239 | GNUNET_CONFIGURATION_set_value_string (out, section, option, value); |
240 | section, | ||
241 | option, | ||
242 | value); | ||
243 | } | 240 | } |
244 | cfg_fn = NULL; | 241 | cfg_fn = NULL; |
245 | if (NULL == cfgfile) | 242 | if (NULL == cfgfile) |
@@ -255,12 +252,11 @@ run (void *cls, | |||
255 | cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); | 252 | cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); |
256 | cfgfile = cfg_fn; | 253 | cfgfile = cfg_fn; |
257 | } | 254 | } |
258 | if ( (NULL != diff) || (NULL != out) ) | 255 | if ((NULL != diff) || (NULL != out)) |
259 | { | 256 | { |
260 | if (GNUNET_OK != | 257 | if (GNUNET_OK != |
261 | GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, | 258 | GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, cfgfile)) |
262 | cfgfile)) | 259 | global_ret = 2; |
263 | ret = 2; | ||
264 | } | 260 | } |
265 | GNUNET_free_non_null (cfg_fn); | 261 | GNUNET_free_non_null (cfg_fn); |
266 | if (NULL != out) | 262 | if (NULL != out) |
@@ -279,52 +275,65 @@ cleanup: | |||
279 | * @return 0 ok, 1 on error | 275 | * @return 0 ok, 1 on error |
280 | */ | 276 | */ |
281 | int | 277 | int |
282 | main (int argc, | 278 | main (int argc, char *const *argv) |
283 | char *const *argv) | ||
284 | { | 279 | { |
285 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 280 | struct GNUNET_GETOPT_CommandLineOption options[] = |
286 | GNUNET_GETOPT_option_flag ('f', | 281 | {GNUNET_GETOPT_option_flag ( |
287 | "filename", | 282 | 'f', |
288 | gettext_noop ("interpret option value as a filename (with $-expansion)"), | 283 | "filename", |
289 | &is_filename), | 284 | gettext_noop ("interpret option value as a filename (with $-expansion)"), |
290 | GNUNET_GETOPT_option_string ('s', | 285 | &is_filename), |
291 | "section", | 286 | GNUNET_GETOPT_option_exclusive (GNUNET_GETOPT_option_string ( |
292 | "SECTION", | 287 | 'b', |
293 | gettext_noop ("name of the section to access"), | 288 | "supported-backend", |
294 | §ion), | 289 | "BACKEND", |
295 | GNUNET_GETOPT_option_string ('o', | 290 | gettext_noop ( |
296 | "option", | 291 | "test if the current installation supports the specified BACKEND"), |
297 | "OPTION", | 292 | &backend_check)), |
298 | gettext_noop ("name of the option to access"), | 293 | GNUNET_GETOPT_option_string ('s', |
299 | &option), | 294 | "section", |
300 | GNUNET_GETOPT_option_string ('V', | 295 | "SECTION", |
301 | "value", | 296 | gettext_noop ( |
302 | "VALUE", | 297 | "name of the section to access"), |
303 | gettext_noop ("value to set"), | 298 | §ion), |
304 | &value), | 299 | GNUNET_GETOPT_option_string ('o', |
305 | GNUNET_GETOPT_option_flag ('S', | 300 | "option", |
306 | "list-sections", | 301 | "OPTION", |
307 | gettext_noop ("print available configuration sections"), | 302 | gettext_noop ("name of the option to access"), |
308 | &list_sections), | 303 | &option), |
309 | GNUNET_GETOPT_option_flag ('w', | 304 | GNUNET_GETOPT_option_string ('V', |
310 | "rewrite", | 305 | "value", |
311 | gettext_noop ("write configuration file that only contains delta to defaults"), | 306 | "VALUE", |
312 | &rewrite), | 307 | gettext_noop ("value to set"), |
313 | GNUNET_GETOPT_OPTION_END | 308 | &value), |
314 | }; | 309 | GNUNET_GETOPT_option_flag ('S', |
315 | if (GNUNET_OK != | 310 | "list-sections", |
316 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 311 | gettext_noop ( |
317 | &argc, &argv)) | 312 | "print available configuration sections"), |
313 | &list_sections), | ||
314 | GNUNET_GETOPT_option_flag ( | ||
315 | 'w', | ||
316 | "rewrite", | ||
317 | gettext_noop ( | ||
318 | "write configuration file that only contains delta to defaults"), | ||
319 | &rewrite), | ||
320 | GNUNET_GETOPT_OPTION_END}; | ||
321 | int ret; | ||
322 | |||
323 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
318 | return 2; | 324 | return 2; |
319 | 325 | ||
320 | ret = (GNUNET_OK == | 326 | ret = |
321 | GNUNET_PROGRAM_run (argc, | 327 | GNUNET_PROGRAM_run (argc, |
322 | argv, | 328 | argv, |
323 | "gnunet-config [OPTIONS]", | 329 | "gnunet-config [OPTIONS]", |
324 | gettext_noop ("Manipulate GNUnet configuration files"), | 330 | gettext_noop ("Manipulate GNUnet configuration files"), |
325 | options, | 331 | options, |
326 | &run, NULL)) ? 0 : ret; | 332 | &run, |
327 | GNUNET_free ((void*) argv); | 333 | NULL); |
334 | GNUNET_free ((void *) argv); | ||
335 | if (GNUNET_OK == ret) | ||
336 | return global_ret; | ||
328 | return ret; | 337 | return ret; |
329 | } | 338 | } |
330 | 339 | ||
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; | |||
57 | static void | 57 | static void |
58 | shutdown_task (void *cls) | 58 | shutdown_task (void *cls) |
59 | { | 59 | { |
60 | if (sizeof (proof) != | 60 | (void) cls; |
61 | GNUNET_DISK_fn_write (pwfn, | 61 | if (sizeof (proof) != GNUNET_DISK_fn_write (pwfn, |
62 | &proof, | 62 | &proof, |
63 | sizeof (proof), | 63 | sizeof (proof), |
64 | GNUNET_DISK_PERM_USER_READ | | 64 | GNUNET_DISK_PERM_USER_READ | |
65 | GNUNET_DISK_PERM_USER_WRITE)) | 65 | GNUNET_DISK_PERM_USER_WRITE)) |
66 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 66 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", pwfn); |
67 | "write", | ||
68 | pwfn); | ||
69 | } | 67 | } |
70 | 68 | ||
71 | 69 | ||
@@ -77,17 +75,18 @@ shutdown_task (void *cls) | |||
77 | * @param result where to write the resulting hash | 75 | * @param result where to write the resulting hash |
78 | */ | 76 | */ |
79 | static void | 77 | static void |
80 | pow_hash (const void *buf, | 78 | pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result) |
81 | size_t buf_len, | ||
82 | struct GNUNET_HashCode *result) | ||
83 | { | 79 | { |
84 | GNUNET_break (0 == | 80 | GNUNET_break ( |
85 | gcry_kdf_derive (buf, buf_len, | 81 | 0 == gcry_kdf_derive (buf, |
86 | GCRY_KDF_SCRYPT, | 82 | buf_len, |
87 | 1 /* subalgo */, | 83 | GCRY_KDF_SCRYPT, |
88 | "gnunet-proof-of-work", strlen ("gnunet-proof-of-work"), | 84 | 1 /* subalgo */, |
89 | 2 /* iterations; keep cost of individual op small */, | 85 | "gnunet-proof-of-work", |
90 | sizeof (struct GNUNET_HashCode), result)); | 86 | strlen ("gnunet-proof-of-work"), |
87 | 2 /* iterations; keep cost of individual op small */, | ||
88 | sizeof (struct GNUNET_HashCode), | ||
89 | result)); | ||
91 | } | 90 | } |
92 | 91 | ||
93 | 92 | ||
@@ -118,7 +117,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
118 | static void | 117 | static void |
119 | find_proof (void *cls) | 118 | find_proof (void *cls) |
120 | { | 119 | { |
121 | #define ROUND_SIZE 10 | 120 | #define ROUND_SIZE 10 |
122 | uint64_t counter; | 121 | uint64_t counter; |
123 | char buf[sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + | 122 | char buf[sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + |
124 | sizeof (uint64_t)] GNUNET_ALIGN; | 123 | sizeof (uint64_t)] GNUNET_ALIGN; |
@@ -127,12 +126,14 @@ find_proof (void *cls) | |||
127 | struct GNUNET_TIME_Absolute timestamp; | 126 | struct GNUNET_TIME_Absolute timestamp; |
128 | struct GNUNET_TIME_Relative elapsed; | 127 | struct GNUNET_TIME_Relative elapsed; |
129 | 128 | ||
129 | (void) cls; | ||
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
131 | "Got Proof of Work %llu\n", | 131 | "Got Proof of Work %llu\n", |
132 | (unsigned long long) proof); | 132 | (unsigned long long) proof); |
133 | proof_task = NULL; | 133 | proof_task = NULL; |
134 | GNUNET_memcpy (&buf[sizeof (uint64_t)], &pub, | 134 | GNUNET_memcpy (&buf[sizeof (uint64_t)], |
135 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | 135 | &pub, |
136 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | ||
136 | i = 0; | 137 | i = 0; |
137 | counter = proof; | 138 | counter = proof; |
138 | timestamp = GNUNET_TIME_absolute_get (); | 139 | timestamp = GNUNET_TIME_absolute_get (); |
@@ -143,7 +144,8 @@ find_proof (void *cls) | |||
143 | if (nse_work_required <= count_leading_zeroes (&result)) | 144 | if (nse_work_required <= count_leading_zeroes (&result)) |
144 | { | 145 | { |
145 | proof = counter; | 146 | proof = counter; |
146 | FPRINTF (stdout, "Proof of work found: %llu!\n", | 147 | FPRINTF (stdout, |
148 | "Proof of work found: %llu!\n", | ||
147 | (unsigned long long) proof); | 149 | (unsigned long long) proof); |
148 | GNUNET_SCHEDULER_shutdown (); | 150 | GNUNET_SCHEDULER_shutdown (); |
149 | return; | 151 | return; |
@@ -159,7 +161,8 @@ find_proof (void *cls) | |||
159 | GNUNET_STRINGS_relative_time_to_string (elapsed, 0)); | 161 | GNUNET_STRINGS_relative_time_to_string (elapsed, 0)); |
160 | if (proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) | 162 | if (proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) |
161 | { | 163 | { |
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing proofs currently at %llu\n", | 164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
165 | "Testing proofs currently at %llu\n", | ||
163 | (unsigned long long) counter); | 166 | (unsigned long long) counter); |
164 | /* remember progress every 100 rounds */ | 167 | /* remember progress every 100 rounds */ |
165 | proof = counter; | 168 | proof = counter; |
@@ -171,8 +174,9 @@ find_proof (void *cls) | |||
171 | } | 174 | } |
172 | proof_task = | 175 | proof_task = |
173 | GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, | 176 | GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, |
174 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 177 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
175 | &find_proof, NULL); | 178 | &find_proof, |
179 | NULL); | ||
176 | } | 180 | } |
177 | 181 | ||
178 | 182 | ||
@@ -193,54 +197,46 @@ run (void *cls, | |||
193 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 197 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
194 | char *pids; | 198 | char *pids; |
195 | 199 | ||
200 | (void) cls; | ||
201 | (void) args; | ||
202 | (void) cfgfile; | ||
196 | cfg = config; | 203 | cfg = config; |
197 | /* load proof of work */ | 204 | /* load proof of work */ |
198 | if (NULL == pwfn) | 205 | if (NULL == pwfn) |
199 | { | 206 | { |
200 | if (GNUNET_OK != | 207 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
201 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 208 | "NSE", |
202 | "NSE", | 209 | "PROOFFILE", |
203 | "PROOFFILE", | 210 | &pwfn)) |
204 | &pwfn)) | ||
205 | { | 211 | { |
206 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 212 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE"); |
207 | "NSE", | ||
208 | "PROOFFILE"); | ||
209 | GNUNET_SCHEDULER_shutdown (); | 213 | GNUNET_SCHEDULER_shutdown (); |
210 | return; | 214 | return; |
211 | } | 215 | } |
212 | } | 216 | } |
213 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 217 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Proof of Work file: %s\n", pwfn); |
214 | "Proof of Work file: %s\n", | 218 | if ((GNUNET_YES != GNUNET_DISK_file_test (pwfn)) || |
215 | pwfn); | 219 | (sizeof (proof) != GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof)))) |
216 | if ( (GNUNET_YES != GNUNET_DISK_file_test (pwfn)) || | ||
217 | (sizeof (proof) != | ||
218 | GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof)))) | ||
219 | proof = 0; | 220 | proof = 0; |
220 | 221 | ||
221 | /* load private key */ | 222 | /* load private key */ |
222 | if (NULL == pkfn) | 223 | if (NULL == pkfn) |
223 | { | 224 | { |
224 | if (GNUNET_OK != | 225 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
225 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 226 | "PEER", |
226 | "PEER", | 227 | "PRIVATE_KEY", |
227 | "PRIVATE_KEY", | 228 | &pkfn)) |
228 | &pkfn)) | ||
229 | { | 229 | { |
230 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 230 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
231 | "PEER", | 231 | "PEER", |
232 | "PRIVATE_KEY"); | 232 | "PRIVATE_KEY"); |
233 | return; | 233 | return; |
234 | } | 234 | } |
235 | } | 235 | } |
236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn); |
237 | "Private Key file: %s\n", | ||
238 | pkfn); | ||
239 | if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn))) | 237 | if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn))) |
240 | { | 238 | { |
241 | FPRINTF (stderr, | 239 | FPRINTF (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn); |
242 | _("Loading hostkey from `%s' failed.\n"), | ||
243 | pkfn); | ||
244 | GNUNET_free (pkfn); | 240 | GNUNET_free (pkfn); |
245 | return; | 241 | return; |
246 | } | 242 | } |
@@ -248,32 +244,27 @@ run (void *cls, | |||
248 | GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub); | 244 | GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub); |
249 | GNUNET_free (pk); | 245 | GNUNET_free (pk); |
250 | pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); | 246 | pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); |
251 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", pids); |
252 | "Peer ID: %s\n", | ||
253 | pids); | ||
254 | GNUNET_free (pids); | 248 | GNUNET_free (pids); |
255 | 249 | ||
256 | /* get target bit amount */ | 250 | /* get target bit amount */ |
257 | if (0 == nse_work_required) | 251 | if (0 == nse_work_required) |
258 | { | 252 | { |
259 | if (GNUNET_OK != | 253 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
260 | GNUNET_CONFIGURATION_get_value_number (cfg, | 254 | "NSE", |
261 | "NSE", | 255 | "WORKBITS", |
262 | "WORKBITS", | 256 | &nse_work_required)) |
263 | &nse_work_required)) | ||
264 | { | 257 | { |
265 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 258 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS"); |
266 | "NSE", | ||
267 | "WORKBITS"); | ||
268 | GNUNET_SCHEDULER_shutdown (); | 259 | GNUNET_SCHEDULER_shutdown (); |
269 | return; | 260 | return; |
270 | } | 261 | } |
271 | if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) | 262 | if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) |
272 | { | 263 | { |
273 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 264 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
274 | "NSE", | 265 | "NSE", |
275 | "WORKBITS", | 266 | "WORKBITS", |
276 | _("Value is too large.\n")); | 267 | _ ("Value is too large.\n")); |
277 | GNUNET_SCHEDULER_shutdown (); | 268 | GNUNET_SCHEDULER_shutdown (); |
278 | return; | 269 | return; |
279 | } | 270 | } |
@@ -283,19 +274,16 @@ run (void *cls, | |||
283 | return; | 274 | return; |
284 | } | 275 | } |
285 | } | 276 | } |
286 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 277 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bits: %llu\n", nse_work_required); |
287 | "Bits: %llu\n", | ||
288 | nse_work_required); | ||
289 | 278 | ||
290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
291 | "Delay between tries: %s\n", | 280 | "Delay between tries: %s\n", |
292 | GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1)); | 281 | GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1)); |
293 | proof_task = | 282 | proof_task = |
294 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 283 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
295 | &find_proof, | 284 | &find_proof, |
296 | NULL); | 285 | NULL); |
297 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 286 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
298 | NULL); | ||
299 | } | 287 | } |
300 | 288 | ||
301 | 289 | ||
@@ -307,46 +295,51 @@ run (void *cls, | |||
307 | * @return 0 ok, 1 on error | 295 | * @return 0 ok, 1 on error |
308 | */ | 296 | */ |
309 | int | 297 | int |
310 | main (int argc, | 298 | main (int argc, char *const *argv) |
311 | char *const *argv) | ||
312 | { | 299 | { |
313 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 300 | struct GNUNET_GETOPT_CommandLineOption options[] = |
314 | GNUNET_GETOPT_option_ulong ('b', | 301 | {GNUNET_GETOPT_option_ulong ( |
315 | "bits", | 302 | 'b', |
316 | "BITS", | 303 | "bits", |
317 | gettext_noop ("number of bits to require for the proof of work"), | 304 | "BITS", |
318 | &nse_work_required), | 305 | gettext_noop ("number of bits to require for the proof of work"), |
319 | GNUNET_GETOPT_option_filename ('k', | 306 | &nse_work_required), |
320 | "keyfile", | 307 | GNUNET_GETOPT_option_filename ( |
321 | "FILE", | 308 | 'k', |
322 | gettext_noop ("file with private key, otherwise default is used"), | 309 | "keyfile", |
323 | &pkfn), | 310 | "FILE", |
324 | GNUNET_GETOPT_option_filename ('o', | 311 | gettext_noop ("file with private key, otherwise default is used"), |
325 | "outfile", | 312 | &pkfn), |
326 | "FILE", | 313 | GNUNET_GETOPT_option_filename ( |
327 | gettext_noop ("file with proof of work, otherwise default is used"), | 314 | 'o', |
328 | &pwfn), | 315 | "outfile", |
329 | GNUNET_GETOPT_option_relative_time ('t', | 316 | "FILE", |
330 | "timeout", | 317 | gettext_noop ("file with proof of work, otherwise default is used"), |
331 | "TIME", | 318 | &pwfn), |
332 | gettext_noop ("time to wait between calculations"), | 319 | GNUNET_GETOPT_option_relative_time ('t', |
333 | &proof_find_delay), | 320 | "timeout", |
334 | GNUNET_GETOPT_OPTION_END | 321 | "TIME", |
335 | }; | 322 | gettext_noop ( |
323 | "time to wait between calculations"), | ||
324 | &proof_find_delay), | ||
325 | GNUNET_GETOPT_OPTION_END}; | ||
336 | int ret; | 326 | int ret; |
337 | 327 | ||
338 | if (GNUNET_OK != | 328 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
339 | GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
340 | return 2; | 329 | return 2; |
341 | 330 | ||
342 | ret = (GNUNET_OK == | 331 | ret = |
343 | GNUNET_PROGRAM_run (argc, argv, | 332 | (GNUNET_OK == |
344 | "gnunet-scrypt [OPTIONS] prooffile", | 333 | GNUNET_PROGRAM_run (argc, |
345 | gettext_noop ("Manipulate GNUnet proof of work files"), | 334 | argv, |
346 | options, | 335 | "gnunet-scrypt [OPTIONS] prooffile", |
347 | &run, | 336 | gettext_noop ("Manipulate GNUnet proof of work files"), |
348 | NULL)) ? 0 : 1; | 337 | options, |
349 | GNUNET_free ((void*) argv); | 338 | &run, |
339 | NULL)) | ||
340 | ? 0 | ||
341 | : 1; | ||
342 | GNUNET_free ((void *) argv); | ||
350 | GNUNET_free_non_null (pwfn); | 343 | GNUNET_free_non_null (pwfn); |
351 | return ret; | 344 | return ret; |
352 | } | 345 | } |
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) | |||
53 | { | 53 | { |
54 | enum GNUNET_OS_ProcessStatusType type; | 54 | enum GNUNET_OS_ProcessStatusType type; |
55 | 55 | ||
56 | if ( (GNUNET_OK != | 56 | (void) cls; |
57 | GNUNET_OS_process_status (p, &type, &exit_code)) || | 57 | if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) || |
58 | (type != GNUNET_OS_PROCESS_EXITED) ) | 58 | (type != GNUNET_OS_PROCESS_EXITED)) |
59 | GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); | 59 | GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); |
60 | GNUNET_OS_process_destroy (p); | 60 | GNUNET_OS_process_destroy (p); |
61 | } | 61 | } |
@@ -70,56 +70,60 @@ maint_child_death (void *cls) | |||
70 | * @param cfg configuration | 70 | * @param cfg configuration |
71 | */ | 71 | */ |
72 | static void | 72 | static void |
73 | run (void *cls, char *const *args, const char *cfgfile, | 73 | run (void *cls, |
74 | char *const *args, | ||
75 | const char *cfgfile, | ||
74 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 76 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
75 | { | 77 | { |
76 | const char *uri; | 78 | const char *uri; |
77 | const char *slash; | 79 | const char *slash; |
78 | char *subsystem; | 80 | char *subsystem; |
79 | char *program; | 81 | char *program; |
80 | struct GNUNET_SCHEDULER_Task * rt; | 82 | struct GNUNET_SCHEDULER_Task *rt; |
81 | 83 | ||
84 | (void) cls; | ||
85 | (void) cfgfile; | ||
82 | if (NULL == (uri = args[0])) | 86 | if (NULL == (uri = args[0])) |
83 | { | 87 | { |
84 | fprintf (stderr, | 88 | fprintf (stderr, _ ("No URI specified on command line\n")); |
85 | _("No URI specified on command line\n")); | ||
86 | return; | 89 | return; |
87 | } | 90 | } |
88 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) | 91 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) |
89 | { | 92 | { |
90 | fprintf (stderr, | 93 | fprintf (stderr, |
91 | _("Invalid URI: does not start with `%s'\n"), | 94 | _ ("Invalid URI: does not start with `%s'\n"), |
92 | "gnunet://"); | 95 | "gnunet://"); |
93 | return; | 96 | return; |
94 | } | 97 | } |
95 | uri += strlen ("gnunet://"); | 98 | uri += strlen ("gnunet://"); |
96 | if (NULL == (slash = strchr (uri, '/'))) | 99 | if (NULL == (slash = strchr (uri, '/'))) |
97 | { | 100 | { |
98 | fprintf (stderr, _("Invalid URI: fails to specify subsystem\n")); | 101 | fprintf (stderr, _ ("Invalid URI: fails to specify subsystem\n")); |
99 | return; | 102 | return; |
100 | } | 103 | } |
101 | subsystem = GNUNET_strndup (uri, slash - uri); | 104 | subsystem = GNUNET_strndup (uri, slash - uri); |
102 | if (GNUNET_OK != | 105 | if (GNUNET_OK != |
103 | GNUNET_CONFIGURATION_get_value_string (cfg, | 106 | GNUNET_CONFIGURATION_get_value_string (cfg, "uri", subsystem, &program)) |
104 | "uri", | ||
105 | subsystem, | ||
106 | &program)) | ||
107 | { | 107 | { |
108 | fprintf (stderr, _("No handler known for subsystem `%s'\n"), subsystem); | 108 | fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem); |
109 | GNUNET_free (subsystem); | 109 | GNUNET_free (subsystem); |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | GNUNET_free (subsystem); | 112 | GNUNET_free (subsystem); |
113 | rt = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 113 | rt = GNUNET_SCHEDULER_add_read_file ( |
114 | GNUNET_DISK_pipe_handle (sigpipe, | 114 | GNUNET_TIME_UNIT_FOREVER_REL, |
115 | GNUNET_DISK_PIPE_END_READ), | 115 | GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), |
116 | &maint_child_death, NULL); | 116 | &maint_child_death, |
117 | p = GNUNET_OS_start_process (GNUNET_NO, 0, | 117 | NULL); |
118 | NULL, NULL, NULL, | 118 | p = GNUNET_OS_start_process (GNUNET_NO, |
119 | program, | 119 | 0, |
120 | program, | 120 | NULL, |
121 | args[0], | 121 | NULL, |
122 | NULL); | 122 | NULL, |
123 | program, | ||
124 | program, | ||
125 | args[0], | ||
126 | NULL); | ||
123 | GNUNET_free (program); | 127 | GNUNET_free (program); |
124 | if (NULL == p) | 128 | if (NULL == p) |
125 | GNUNET_SCHEDULER_cancel (rt); | 129 | GNUNET_SCHEDULER_cancel (rt); |
@@ -134,13 +138,15 @@ static void | |||
134 | sighandler_child_death () | 138 | sighandler_child_death () |
135 | { | 139 | { |
136 | static char c; | 140 | static char c; |
137 | int old_errno = errno; /* back-up errno */ | 141 | int old_errno = errno; /* back-up errno */ |
138 | 142 | ||
139 | GNUNET_break (1 == | 143 | GNUNET_break ( |
140 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle | 144 | 1 == |
141 | (sigpipe, GNUNET_DISK_PIPE_END_WRITE), | 145 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, |
142 | &c, sizeof (c))); | 146 | GNUNET_DISK_PIPE_END_WRITE), |
143 | errno = old_errno; /* restore errno */ | 147 | &c, |
148 | sizeof (c))); | ||
149 | errno = old_errno; /* restore errno */ | ||
144 | } | 150 | } |
145 | 151 | ||
146 | 152 | ||
@@ -155,8 +161,7 @@ int | |||
155 | main (int argc, char *const *argv) | 161 | main (int argc, char *const *argv) |
156 | { | 162 | { |
157 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 163 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
158 | GNUNET_GETOPT_OPTION_END | 164 | GNUNET_GETOPT_OPTION_END}; |
159 | }; | ||
160 | struct GNUNET_SIGNAL_Context *shc_chld; | 165 | struct GNUNET_SIGNAL_Context *shc_chld; |
161 | int ret; | 166 | int ret; |
162 | 167 | ||
@@ -166,9 +171,14 @@ main (int argc, char *const *argv) | |||
166 | GNUNET_assert (sigpipe != NULL); | 171 | GNUNET_assert (sigpipe != NULL); |
167 | shc_chld = | 172 | shc_chld = |
168 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 173 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); |
169 | ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-uri URI", | 174 | ret = GNUNET_PROGRAM_run (argc, |
170 | gettext_noop ("Perform default-actions for GNUnet URIs"), | 175 | argv, |
171 | options, &run, NULL); | 176 | "gnunet-uri URI", |
177 | gettext_noop ( | ||
178 | "Perform default-actions for GNUnet URIs"), | ||
179 | options, | ||
180 | &run, | ||
181 | NULL); | ||
172 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 182 | GNUNET_SIGNAL_handler_uninstall (shc_chld); |
173 | shc_chld = NULL; | 183 | shc_chld = NULL; |
174 | GNUNET_DISK_pipe_close (sigpipe); | 184 | 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 @@ | |||
35 | * This must be long enough for us to not to mistake skipped log call | 35 | * This must be long enough for us to not to mistake skipped log call |
36 | * on a slow machine for a non-skipped one. | 36 | * on a slow machine for a non-skipped one. |
37 | */ | 37 | */ |
38 | #define OUTPUT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000) | 38 | #define OUTPUT_DELAY \ |
39 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000) | ||
39 | 40 | ||
40 | static void | 41 | static void |
41 | my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, | 42 | my_log (void *ctx, |
42 | const char *date, const char *msg) | 43 | enum GNUNET_ErrorType kind, |
44 | const char *component, | ||
45 | const char *date, | ||
46 | const char *msg) | ||
43 | { | 47 | { |
48 | (void) ctx; | ||
49 | (void) kind; | ||
50 | (void) component; | ||
51 | (void) date; | ||
44 | if (strncmp ("test-common-logging-dummy", component, 25) != 0) | 52 | if (strncmp ("test-common-logging-dummy", component, 25) != 0) |
45 | return; | 53 | return; |
46 | FPRINTF (stdout, "%s", msg); | 54 | FPRINTF (stdout, "%s", msg); |
@@ -48,7 +56,7 @@ my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, | |||
48 | } | 56 | } |
49 | 57 | ||
50 | 58 | ||
51 | #if !defined(GNUNET_CULL_LOGGING) | 59 | #if ! defined(GNUNET_CULL_LOGGING) |
52 | static int | 60 | static int |
53 | expensive_func () | 61 | expensive_func () |
54 | { | 62 | { |
@@ -57,27 +65,36 @@ expensive_func () | |||
57 | #endif | 65 | #endif |
58 | 66 | ||
59 | 67 | ||
60 | #define pr(kind,lvl) {\ | 68 | #define pr(kind, lvl) \ |
61 | struct GNUNET_TIME_Absolute t1, t2;\ | 69 | { \ |
62 | t1 = GNUNET_TIME_absolute_get ();\ | 70 | struct GNUNET_TIME_Absolute t1, t2; \ |
63 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\ | 71 | t1 = GNUNET_TIME_absolute_get (); \ |
64 | t2 = GNUNET_TIME_absolute_get ();\ | 72 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \ |
65 | printf ("1%s %llu\n", lvl,\ | 73 | t2 = GNUNET_TIME_absolute_get (); \ |
66 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \ | 74 | printf ("1%s %llu\n", \ |
67 | } | 75 | lvl, \ |
76 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \ | ||
77 | .rel_value_us); \ | ||
78 | } | ||
79 | |||
80 | #define pr2(kind, lvl) \ | ||
81 | { \ | ||
82 | struct GNUNET_TIME_Absolute t1, t2; \ | ||
83 | t1 = GNUNET_TIME_absolute_get (); \ | ||
84 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \ | ||
85 | t2 = GNUNET_TIME_absolute_get (); \ | ||
86 | printf ("2%s %llu\n", \ | ||
87 | lvl, \ | ||
88 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \ | ||
89 | .rel_value_us); \ | ||
90 | } | ||
68 | 91 | ||
69 | #define pr2(kind,lvl) {\ | ||
70 | struct GNUNET_TIME_Absolute t1, t2;\ | ||
71 | t1 = GNUNET_TIME_absolute_get ();\ | ||
72 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\ | ||
73 | t2 = GNUNET_TIME_absolute_get ();\ | ||
74 | printf ("2%s %llu\n", lvl,\ | ||
75 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \ | ||
76 | } | ||
77 | 92 | ||
78 | int | 93 | int |
79 | main (int argc, char *argv[]) | 94 | main (int argc, char *argv[]) |
80 | { | 95 | { |
96 | (void) argc; | ||
97 | (void) argv; | ||
81 | /* We set up logging with NULL level - will be overrided by | 98 | /* We set up logging with NULL level - will be overrided by |
82 | * GNUNET_LOG or GNUNET_FORCE_LOG at runtime. | 99 | * GNUNET_LOG or GNUNET_FORCE_LOG at runtime. |
83 | */ | 100 | */ |
@@ -97,6 +114,6 @@ main (int argc, char *argv[]) | |||
97 | pr2 (GNUNET_ERROR_TYPE_INFO, "INFO"); | 114 | pr2 (GNUNET_ERROR_TYPE_INFO, "INFO"); |
98 | pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG"); | 115 | pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG"); |
99 | return 0; | 116 | return 0; |
100 | } /* end of main */ | 117 | } /* end of main */ |
101 | 118 | ||
102 | /* end of test_common_logging_dummy.c */ | 119 | /* 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 @@ | |||
44 | */ | 44 | */ |
45 | void | 45 | void |
46 | GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, | 46 | GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, |
47 | uint8_t protocol, | 47 | uint8_t protocol, |
48 | uint16_t payload_length, | 48 | uint16_t payload_length, |
49 | const struct in_addr *src, | 49 | const struct in_addr *src, |
50 | const struct in_addr *dst) | 50 | const struct in_addr *dst) |
51 | { | 51 | { |
52 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_IPv4Header)); | 52 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_IPv4Header)); |
53 | GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header)); | 53 | GNUNET_assert (payload_length <= |
54 | UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header)); | ||
54 | memset (ip, 0, sizeof (struct GNUNET_TUN_IPv4Header)); | 55 | memset (ip, 0, sizeof (struct GNUNET_TUN_IPv4Header)); |
55 | ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; | 56 | ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; |
56 | ip->version = 4; | 57 | ip->version = 4; |
57 | ip->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length); | 58 | ip->total_length = |
58 | ip->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 59 | htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length); |
59 | 65536); | 60 | ip->identification = |
61 | (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 65536); | ||
60 | ip->ttl = FRESH_TTL; | 62 | ip->ttl = FRESH_TTL; |
61 | ip->protocol = protocol; | 63 | ip->protocol = protocol; |
62 | ip->source_address = *src; | 64 | ip->source_address = *src; |
63 | ip->destination_address = *dst; | 65 | ip->destination_address = *dst; |
64 | ip->checksum = GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header)); | 66 | ip->checksum = |
67 | GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header)); | ||
65 | } | 68 | } |
66 | 69 | ||
67 | 70 | ||
@@ -76,13 +79,14 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, | |||
76 | */ | 79 | */ |
77 | void | 80 | void |
78 | GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, | 81 | GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, |
79 | uint8_t protocol, | 82 | uint8_t protocol, |
80 | uint16_t payload_length, | 83 | uint16_t payload_length, |
81 | const struct in6_addr *src, | 84 | const struct in6_addr *src, |
82 | const struct in6_addr *dst) | 85 | const struct in6_addr *dst) |
83 | { | 86 | { |
84 | GNUNET_assert (40 == sizeof (struct GNUNET_TUN_IPv6Header)); | 87 | GNUNET_assert (40 == sizeof (struct GNUNET_TUN_IPv6Header)); |
85 | GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header)); | 88 | GNUNET_assert (payload_length <= |
89 | UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header)); | ||
86 | memset (ip, 0, sizeof (struct GNUNET_TUN_IPv6Header)); | 90 | memset (ip, 0, sizeof (struct GNUNET_TUN_IPv6Header)); |
87 | ip->version = 6; | 91 | ip->version = 6; |
88 | ip->next_header = protocol; | 92 | ip->next_header = protocol; |
@@ -103,27 +107,29 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, | |||
103 | */ | 107 | */ |
104 | void | 108 | void |
105 | GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | 109 | GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, |
106 | struct GNUNET_TUN_TcpHeader *tcp, | 110 | struct GNUNET_TUN_TcpHeader *tcp, |
107 | const void *payload, | 111 | const void *payload, |
108 | uint16_t payload_length) | 112 | uint16_t payload_length) |
109 | { | 113 | { |
110 | uint32_t sum; | 114 | uint32_t sum; |
111 | uint16_t tmp; | 115 | uint16_t tmp; |
112 | 116 | ||
113 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); | 117 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); |
114 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_TcpHeader) == | 118 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + |
115 | ntohs (ip->total_length)); | 119 | sizeof (struct GNUNET_TUN_TcpHeader) == |
120 | ntohs (ip->total_length)); | ||
116 | GNUNET_assert (IPPROTO_TCP == ip->protocol); | 121 | GNUNET_assert (IPPROTO_TCP == ip->protocol); |
117 | 122 | ||
118 | tcp->crc = 0; | 123 | tcp->crc = 0; |
119 | sum = GNUNET_CRYPTO_crc16_step (0, | 124 | sum = GNUNET_CRYPTO_crc16_step (0, |
120 | &ip->source_address, | 125 | &ip->source_address, |
121 | sizeof (struct in_addr) * 2); | 126 | sizeof (struct in_addr) * 2); |
122 | tmp = htons (IPPROTO_TCP); | 127 | tmp = htons (IPPROTO_TCP); |
123 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); | 128 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); |
124 | tmp = htons (payload_length + sizeof (struct GNUNET_TUN_TcpHeader)); | 129 | tmp = htons (payload_length + sizeof (struct GNUNET_TUN_TcpHeader)); |
125 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); | 130 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); |
126 | sum = GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader)); | 131 | sum = |
132 | GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader)); | ||
127 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); | 133 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
128 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 134 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
129 | } | 135 | } |
@@ -139,25 +145,27 @@ GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | |||
139 | */ | 145 | */ |
140 | void | 146 | void |
141 | GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | 147 | GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, |
142 | struct GNUNET_TUN_TcpHeader *tcp, | 148 | struct GNUNET_TUN_TcpHeader *tcp, |
143 | const void *payload, | 149 | const void *payload, |
144 | uint16_t payload_length) | 150 | uint16_t payload_length) |
145 | { | 151 | { |
146 | uint32_t sum; | 152 | uint32_t sum; |
147 | uint32_t tmp; | 153 | uint32_t tmp; |
148 | 154 | ||
149 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); | 155 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); |
150 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_TcpHeader) == | 156 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_TcpHeader) == |
151 | ntohs (ip->payload_length)); | 157 | ntohs (ip->payload_length)); |
152 | GNUNET_assert (IPPROTO_TCP == ip->next_header); | 158 | GNUNET_assert (IPPROTO_TCP == ip->next_header); |
153 | tcp->crc = 0; | 159 | tcp->crc = 0; |
154 | sum = GNUNET_CRYPTO_crc16_step (0, &ip->source_address, 2 * sizeof (struct in6_addr)); | 160 | sum = GNUNET_CRYPTO_crc16_step (0, |
161 | &ip->source_address, | ||
162 | 2 * sizeof (struct in6_addr)); | ||
155 | tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length); | 163 | tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length); |
156 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | 164 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); |
157 | tmp = htonl (IPPROTO_TCP); | 165 | tmp = htonl (IPPROTO_TCP); |
158 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | 166 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); |
159 | sum = GNUNET_CRYPTO_crc16_step (sum, tcp, | 167 | sum = |
160 | sizeof (struct GNUNET_TUN_TcpHeader)); | 168 | GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader)); |
161 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); | 169 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
162 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 170 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
163 | } | 171 | } |
@@ -173,36 +181,31 @@ GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | |||
173 | */ | 181 | */ |
174 | void | 182 | void |
175 | GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | 183 | GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, |
176 | struct GNUNET_TUN_UdpHeader *udp, | 184 | struct GNUNET_TUN_UdpHeader *udp, |
177 | const void *payload, | 185 | const void *payload, |
178 | uint16_t payload_length) | 186 | uint16_t payload_length) |
179 | { | 187 | { |
180 | uint32_t sum; | 188 | uint32_t sum; |
181 | uint16_t tmp; | 189 | uint16_t tmp; |
182 | 190 | ||
183 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); | 191 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); |
184 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_UdpHeader) == | 192 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + |
185 | ntohs (ip->total_length)); | 193 | sizeof (struct GNUNET_TUN_UdpHeader) == |
194 | ntohs (ip->total_length)); | ||
186 | GNUNET_assert (IPPROTO_UDP == ip->protocol); | 195 | GNUNET_assert (IPPROTO_UDP == ip->protocol); |
187 | 196 | ||
188 | udp->crc = 0; /* technically optional, but we calculate it anyway, just to be sure */ | 197 | udp->crc = |
198 | 0; /* technically optional, but we calculate it anyway, just to be sure */ | ||
189 | sum = GNUNET_CRYPTO_crc16_step (0, | 199 | sum = GNUNET_CRYPTO_crc16_step (0, |
190 | &ip->source_address, | 200 | &ip->source_address, |
191 | sizeof (struct in_addr) * 2); | 201 | sizeof (struct in_addr) * 2); |
192 | tmp = htons (IPPROTO_UDP); | 202 | tmp = htons (IPPROTO_UDP); |
193 | sum = GNUNET_CRYPTO_crc16_step (sum, | 203 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); |
194 | &tmp, | ||
195 | sizeof (uint16_t)); | ||
196 | tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); | 204 | tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); |
197 | sum = GNUNET_CRYPTO_crc16_step (sum, | 205 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); |
198 | &tmp, | 206 | sum = |
199 | sizeof (uint16_t)); | 207 | GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader)); |
200 | sum = GNUNET_CRYPTO_crc16_step (sum, | 208 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
201 | udp, | ||
202 | sizeof (struct GNUNET_TUN_UdpHeader)); | ||
203 | sum = GNUNET_CRYPTO_crc16_step (sum, | ||
204 | payload, | ||
205 | payload_length); | ||
206 | udp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 209 | udp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
207 | } | 210 | } |
208 | 211 | ||
@@ -217,28 +220,30 @@ GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | |||
217 | */ | 220 | */ |
218 | void | 221 | void |
219 | GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | 222 | GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, |
220 | struct GNUNET_TUN_UdpHeader *udp, | 223 | struct GNUNET_TUN_UdpHeader *udp, |
221 | const void *payload, | 224 | const void *payload, |
222 | uint16_t payload_length) | 225 | uint16_t payload_length) |
223 | { | 226 | { |
224 | uint32_t sum; | 227 | uint32_t sum; |
225 | uint32_t tmp; | 228 | uint32_t tmp; |
226 | 229 | ||
227 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == | 230 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == |
228 | ntohs (ip->payload_length)); | 231 | ntohs (ip->payload_length)); |
229 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == | 232 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == |
230 | ntohs (udp->len)); | 233 | ntohs (udp->len)); |
231 | GNUNET_assert (IPPROTO_UDP == ip->next_header); | 234 | GNUNET_assert (IPPROTO_UDP == ip->next_header); |
232 | 235 | ||
233 | udp->crc = 0; | 236 | udp->crc = 0; |
234 | sum = GNUNET_CRYPTO_crc16_step (0, | 237 | sum = GNUNET_CRYPTO_crc16_step (0, |
235 | &ip->source_address, | 238 | &ip->source_address, |
236 | sizeof (struct in6_addr) * 2); | 239 | sizeof (struct in6_addr) * 2); |
237 | tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); /* aka udp->len */ | 240 | tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + |
241 | payload_length); /* aka udp->len */ | ||
238 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | 242 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); |
239 | tmp = htons (ip->next_header); | 243 | tmp = htons (ip->next_header); |
240 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | 244 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); |
241 | sum = GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader)); | 245 | sum = |
246 | GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader)); | ||
242 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); | 247 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
243 | udp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 248 | udp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
244 | } | 249 | } |
@@ -253,16 +258,15 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | |||
253 | */ | 258 | */ |
254 | void | 259 | void |
255 | GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, | 260 | GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, |
256 | const void *payload, | 261 | const void *payload, |
257 | uint16_t payload_length) | 262 | uint16_t payload_length) |
258 | { | 263 | { |
259 | uint32_t sum; | 264 | uint32_t sum; |
260 | 265 | ||
261 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_IcmpHeader)); | 266 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_IcmpHeader)); |
262 | icmp->crc = 0; | 267 | icmp->crc = 0; |
263 | sum = GNUNET_CRYPTO_crc16_step (0, | 268 | sum = |
264 | icmp, | 269 | GNUNET_CRYPTO_crc16_step (0, icmp, sizeof (struct GNUNET_TUN_IcmpHeader)); |
265 | sizeof (struct GNUNET_TUN_IcmpHeader)); | ||
266 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); | 270 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
267 | icmp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 271 | icmp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
268 | } | 272 | } |
@@ -286,21 +290,22 @@ GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa, | |||
286 | 290 | ||
287 | switch (sa->sa_family) | 291 | switch (sa->sa_family) |
288 | { | 292 | { |
289 | case AF_INET: | 293 | case AF_INET: { |
290 | { | 294 | const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa; |
291 | const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa; | 295 | const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb; |
292 | const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb; | 296 | if ((include_port) && (sa4->sin_port != sb4->sin_port)) |
293 | return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr); | 297 | return GNUNET_NO; |
294 | } | 298 | return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr); |
295 | case AF_INET6: | 299 | } |
296 | { | 300 | case AF_INET6: { |
297 | const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa; | 301 | const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa; |
298 | const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb; | 302 | const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb; |
299 | 303 | ||
300 | return (0 == memcmp(&sa6->sin6_addr, | 304 | if ((include_port) && (sa6->sin6_port != sb6->sin6_port)) |
301 | &sb6->sin6_addr, | 305 | return GNUNET_NO; |
302 | sizeof (struct in6_addr))); | 306 | return ( |
303 | } | 307 | 0 == memcmp (&sa6->sin6_addr, &sb6->sin6_addr, sizeof (struct in6_addr))); |
308 | } | ||
304 | default: | 309 | default: |
305 | GNUNET_break (0); | 310 | GNUNET_break (0); |
306 | return GNUNET_SYSERR; | 311 | return GNUNET_SYSERR; |