diff options
author | xrs <xrs@mail36.net> | 2020-06-17 22:07:39 +0200 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2020-06-17 22:07:39 +0200 |
commit | 49cf7a8e893eaf7682ac12c7d0ea5ca4a6d1a73d (patch) | |
tree | 71830c1751e291e45795958cad15e9dfa8239e1a | |
parent | b9333fef25b57bdd7f556f5fb73f9abaef9bc5ef (diff) | |
parent | e500e9ec3678dfbb666d173854c134ac3858f8b1 (diff) | |
download | gnunet-49cf7a8e893eaf7682ac12c7d0ea5ca4a6d1a73d.tar.gz gnunet-49cf7a8e893eaf7682ac12c7d0ea5ca4a6d1a73d.zip |
Merge branch 'master' into rewrite_of_cadet_test
102 files changed, 5423 insertions, 1736 deletions
diff --git a/.buildbot/build.sh b/.buildbot/build.sh new file mode 100755 index 000000000..394558ff0 --- /dev/null +++ b/.buildbot/build.sh | |||
@@ -0,0 +1,5 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | ./bootstrap | ||
4 | ./configure --prefix=/tmp/gnunet --enable-experimental | ||
5 | make | ||
diff --git a/.buildbot/firefly-x86_64-amdepyc_deploy.sh b/.buildbot/firefly-x86_64-amdepyc_deploy.sh new file mode 100755 index 000000000..b956a3d92 --- /dev/null +++ b/.buildbot/firefly-x86_64-amdepyc_deploy.sh | |||
@@ -0,0 +1,6 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | # Deploy docs from buildbot | ||
4 | |||
5 | chmod -R ag+rX doc/ | ||
6 | rsync -a --delete doc/ handbook@firefly.gnunet.org:~/doc_deployment/ | ||
diff --git a/.buildbot/firefly-x86_64-amdepyc_test.sh b/.buildbot/firefly-x86_64-amdepyc_test.sh new file mode 100755 index 000000000..db202a112 --- /dev/null +++ b/.buildbot/firefly-x86_64-amdepyc_test.sh | |||
@@ -0,0 +1,3 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | echo "Skipped" | ||
diff --git a/.buildbot/install.sh b/.buildbot/install.sh new file mode 100755 index 000000000..b22f3aae0 --- /dev/null +++ b/.buildbot/install.sh | |||
@@ -0,0 +1,3 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | make install | ||
diff --git a/.buildbot/test.sh b/.buildbot/test.sh new file mode 100644 index 000000000..a057cba05 --- /dev/null +++ b/.buildbot/test.sh | |||
@@ -0,0 +1,3 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | make check | ||
@@ -1,3 +1,361 @@ | |||
1 | Tue, 26 May 2020 11:49:50 +0200 (755cb5c76) | ||
2 | remove argon2 dependency. Use limited libsodium argon2id function for GNS and NSE - Martin Schanzenbach | ||
3 | |||
4 | Tue, 26 May 2020 00:42:24 +0200 (24be68238) | ||
5 | use argon2id - Martin Schanzenbach | ||
6 | |||
7 | Tue, 26 May 2020 03:05:33 +0530 (2a82be115) | ||
8 | add additional test condition for GNS crypto - Florian Dold | ||
9 | |||
10 | Mon, 25 May 2020 21:38:58 +0200 (a32de45ce) | ||
11 | add option to create identity from private key - jospaeth | ||
12 | |||
13 | Fri, 22 May 2020 09:44:22 +0200 (2fbc0f044) | ||
14 | add option to show private key - Martin Schanzenbach | ||
15 | |||
16 | Fri, 22 May 2020 01:16:35 +0200 (9a92bbb51) | ||
17 | fix #6242 - Christian Grothoff | ||
18 | |||
19 | Thu, 14 May 2020 16:03:10 +0200 (f4771fcc1) | ||
20 | Improved BIO API - Christian Grothoff | ||
21 | |||
22 | Sun, 17 May 2020 19:56:12 +0200 (3362a671f) | ||
23 | make mhd and jansson mandatory dependencies - Martin Schanzenbach | ||
24 | |||
25 | Sun, 17 May 2020 19:37:00 +0200 (ac7ba6704) | ||
26 | allow compile against curl-openssl - Martin Schanzenbach | ||
27 | |||
28 | Sun, 10 May 2020 11:28:00 +0200 (63c371cfb) | ||
29 | separate id_token and userinfo claims requests - Martin Schanzenbach | ||
30 | |||
31 | Sun, 10 May 2020 00:23:54 +0200 (44bdb66b4) | ||
32 | fix #5782 - Martin Schanzenbach | ||
33 | |||
34 | Sat, 9 May 2020 22:10:08 +0200 (ada94c274) | ||
35 | fail of LSD0001 is violated for GNS2DNS - Martin Schanzenbach | ||
36 | |||
37 | Sat, 9 May 2020 22:00:01 +0200 (3da4b0d20) | ||
38 | fix #6103; make LEHOs supplemental from CNAMEs and GNS2DNS names - Martin Schanzenbach | ||
39 | |||
40 | Sat, 9 May 2020 20:55:08 +0200 (63c92bbef) | ||
41 | add json response headers to rest plugins - Martin Schanzenbach | ||
42 | |||
43 | Sat, 9 May 2020 19:12:51 +0200 (fbdc2fbb4) | ||
44 | change label processing in namestore REST api for gns records - Martin Schanzenbach | ||
45 | |||
46 | Wed, 6 May 2020 18:42:45 +0200 (1847e1652) | ||
47 | deprecate ill-defined set_nick API - Martin Schanzenbach | ||
48 | |||
49 | Wed, 6 May 2020 21:11:08 +0530 (616af9e62) | ||
50 | add libsodium dep to README - Florian Dold | ||
51 | |||
52 | Wed, 6 May 2020 20:12:05 +0530 (e273b24b9) | ||
53 | Fix #6070 - Florian Dold | ||
54 | |||
55 | Wed, 6 May 2020 18:39:16 +0530 (d7028a584) | ||
56 | move from tweetnacl (+custom hacks) -> only sodium - Florian Dold | ||
57 | |||
58 | Wed, 6 May 2020 10:49:10 +0200 (e7c277845) | ||
59 | remove obsolete framework option - Martin Schanzenbach | ||
60 | |||
61 | Wed, 6 May 2020 10:46:20 +0200 (4d75bfd7e) | ||
62 | add some more useful configuration output wrt transports - Martin Schanzenbach | ||
63 | |||
64 | Wed, 6 May 2020 10:25:00 +0200 (a4fddaa4d) | ||
65 | stop excessive warnings and notifications of information that is displayed later on anyway - Martin Schanzenbach | ||
66 | |||
67 | Wed, 6 May 2020 09:31:11 +0200 (ca168098b) | ||
68 | improve configure messages for rest and reclaim - Martin Schanzenbach | ||
69 | |||
70 | Sat, 2 May 2020 00:08:38 +0200 (f38bc1041) | ||
71 | fix gnunet-identity performance - Christian Grothoff | ||
72 | |||
73 | Fri, 1 May 2020 10:55:51 +0200 (91e407579) | ||
74 | vpn, exit: Add patch from termux for Android in a slightly different way. - nikita | ||
75 | |||
76 | Fri, 24 Apr 2020 13:50:05 +0530 (892bd3c60) | ||
77 | check for integer overflow in buffer lib (fixes #6217) - Florian Dold | ||
78 | |||
79 | Fri, 24 Apr 2020 10:18:16 +0200 (69f8fad56) | ||
80 | fix #6220 - Martin Schanzenbach | ||
81 | |||
82 | Tue, 21 Apr 2020 20:43:18 +0200 (bf99d2243) | ||
83 | fix #6191 - Christian Grothoff | ||
84 | |||
85 | Tue, 21 Apr 2020 18:37:28 +0200 (091f411cc) | ||
86 | purge scrypt; add argon2 - Martin Schanzenbach | ||
87 | |||
88 | Tue, 21 Apr 2020 18:13:05 +0200 (6bda628f7) | ||
89 | update revocation config - Martin Schanzenbach | ||
90 | |||
91 | Tue, 21 Apr 2020 13:47:04 +0200 (13ceb583b) | ||
92 | defining GNUNET_array_concatenate() for #6190 - Christian Grothoff | ||
93 | |||
94 | Tue, 21 Apr 2020 13:33:25 +0200 (3776e3a77) | ||
95 | fix #6189 - Christian Grothoff | ||
96 | |||
97 | Tue, 21 Apr 2020 13:27:04 +0200 (e938b8617) | ||
98 | fix #6186 related bugs - Christian Grothoff | ||
99 | |||
100 | Tue, 21 Apr 2020 13:23:28 +0200 (68615f85c) | ||
101 | use nz - Christian Grothoff | ||
102 | |||
103 | Tue, 21 Apr 2020 12:15:16 +0200 (5f5a1c7b4) | ||
104 | add JSON spec'er for booleans - Christian Grothoff | ||
105 | |||
106 | Tue, 21 Apr 2020 00:54:49 +0200 (30361fe0e) | ||
107 | make GNUNET_freez default, have GNUNET_free_nz for cases where that does not work - Christian Grothoff | ||
108 | |||
109 | Sun, 19 Apr 2020 21:37:35 +0200 (254a9f066) | ||
110 | add i64 deserializer - Christian Grothoff | ||
111 | |||
112 | Sun, 19 Apr 2020 14:07:21 +0200 (87481d240) | ||
113 | mailmap, authors: final sync of my address and name with changes in NetBSD and GNUnet members. - nikita | ||
114 | |||
115 | Fri, 17 Apr 2020 19:58:40 +0200 (2be21d379) | ||
116 | add argon2 for LSD0001 - Martin Schanzenbach | ||
117 | |||
118 | Fri, 17 Apr 2020 19:59:31 +0200 (0c053ecbf) | ||
119 | fix build with clang - Martin Schanzenbach | ||
120 | |||
121 | Fri, 17 Apr 2020 19:13:42 +0200 (3695a510a) | ||
122 | add relative_time specs - Christian Grothoff | ||
123 | |||
124 | Fri, 17 Apr 2020 18:21:17 +0200 (6b89b84d2) | ||
125 | add GNUNET_freez for #6186 - Christian Grothoff | ||
126 | |||
127 | Wed, 15 Apr 2020 20:35:45 +0200 (c894cf82d) | ||
128 | add integer overflow guards and avoid (unlimited) stack allocation - Christian Grothoff | ||
129 | |||
130 | Wed, 15 Apr 2020 20:29:15 +0200 (839badf7c) | ||
131 | take care of odd memset() calls - Christian Grothoff | ||
132 | |||
133 | Wed, 15 Apr 2020 20:26:00 +0200 (b7be5b9f5) | ||
134 | fix #6184 - Christian Grothoff | ||
135 | |||
136 | Sat, 11 Apr 2020 23:11:43 +0200 (7bcd5338f) | ||
137 | fix gnunet-statistics CLI - Christian Grothoff | ||
138 | |||
139 | Sat, 11 Apr 2020 21:55:51 +0200 (f490c0f3f) | ||
140 | do create directory if it doesn't exist - Christian Grothoff | ||
141 | |||
142 | Sat, 11 Apr 2020 21:43:28 +0200 (90ff9edfa) | ||
143 | fixing #6149 - Christian Grothoff | ||
144 | |||
145 | Sat, 11 Apr 2020 20:33:08 +0200 (3bcfe59f1) | ||
146 | fix static assert FTBFS with older gcc - Christian Grothoff | ||
147 | |||
148 | Thu, 9 Apr 2020 01:46:44 +0200 (f3d66d0dc) | ||
149 | mailmap adjust - nikita | ||
150 | |||
151 | Thu, 9 Apr 2020 01:40:49 +0200 (22119c687) | ||
152 | fix interpreter line of gnunet-bugreport - nikita | ||
153 | |||
154 | Thu, 9 Apr 2020 00:29:16 +0200 (8547143da) | ||
155 | adapt code to work with latest MHD API - Christian Grothoff | ||
156 | |||
157 | Thu, 9 Apr 2020 00:21:45 +0200 (6fc0526b4) | ||
158 | fix warnings - Christian Grothoff | ||
159 | |||
160 | Wed, 8 Apr 2020 20:30:05 +0200 (ccfb2c2e6) | ||
161 | introduce enum for generic return values - Christian Grothoff | ||
162 | |||
163 | Wed, 8 Apr 2020 17:34:27 +0200 (ba4da8c3f) | ||
164 | hack around crash on disconnect - Christian Grothoff | ||
165 | |||
166 | Wed, 8 Apr 2020 16:56:33 +0200 (11ae9f030) | ||
167 | fix sign api for to address #6164 - Christian Grothoff | ||
168 | |||
169 | Wed, 8 Apr 2020 14:47:01 +0200 (17113fc2f) | ||
170 | add GNUNET_static_assert() - Christian Grothoff | ||
171 | |||
172 | Wed, 8 Apr 2020 14:44:39 +0200 (8c9600879) | ||
173 | add check to see if CC supports '_Static_assert' - Christian Grothoff | ||
174 | |||
175 | Tue, 7 Apr 2020 17:51:59 +0200 (29bd17729) | ||
176 | improve comments (#6164) - Christian Grothoff | ||
177 | |||
178 | Fri, 3 Apr 2020 18:50:09 +0200 (6d7fd3328) | ||
179 | fix #6157 - Christian Grothoff | ||
180 | |||
181 | Fri, 3 Apr 2020 18:45:46 +0200 (6fd24eef2) | ||
182 | fix #6155 - Christian Grothoff | ||
183 | |||
184 | Fri, 3 Apr 2020 18:43:03 +0200 (bc01117ce) | ||
185 | fix #6158 - Christian Grothoff | ||
186 | |||
187 | Fri, 3 Apr 2020 17:03:35 +0200 (55bff52a2) | ||
188 | fix #6159 and related issues - Christian Grothoff | ||
189 | |||
190 | Fri, 3 Apr 2020 15:18:58 +0200 (0541fd194) | ||
191 | adding a GNUNET_memcmp_priv for constant-time comparing of data; fixes #6152 (modulo actually finding specific places where this SHOULD be used instead of GNUNET_memcmp) - Christian Grothoff | ||
192 | |||
193 | Fri, 3 Apr 2020 15:05:14 +0200 (4e259dbbb) | ||
194 | fix #6153 - Christian Grothoff | ||
195 | |||
196 | Fri, 3 Apr 2020 14:18:58 +0200 (175303b44) | ||
197 | fix #6154 - Christian Grothoff | ||
198 | |||
199 | Fri, 3 Apr 2020 13:46:05 +0200 (a3d4063b7) | ||
200 | added communicator tests to experimental - t3sserakt | ||
201 | |||
202 | Thu, 2 Apr 2020 11:33:53 +0200 (225ddf0a2) | ||
203 | fix #6146 - Christian Grothoff | ||
204 | |||
205 | Sun, 29 Mar 2020 12:51:26 +0200 (73514dd0e) | ||
206 | allow passing of fancy time to timetravel option - Christian Grothoff | ||
207 | |||
208 | Sat, 28 Mar 2020 07:57:04 +0100 (15d926361) | ||
209 | Point to explanatory documentation. - Marcello Stanisci | ||
210 | |||
211 | Fri, 20 Mar 2020 15:35:54 +0100 (19d73a8fa) | ||
212 | Make gnunet-namestore honour expiration dates when importing an URI - Christian Grothoff | ||
213 | |||
214 | Thu, 19 Mar 2020 19:40:34 +0100 (efa84b551) | ||
215 | use strtok_r in code that could plausibly be used from multi-threaded applications - Christian Grothoff | ||
216 | |||
217 | Tue, 17 Mar 2020 01:05:17 +0100 (2fb32626a) | ||
218 | use void * instead of char * for RSA key material to make it more clear that these are not 0-terminated strings - Christian Grothoff | ||
219 | |||
220 | Mon, 16 Mar 2020 19:38:42 +0100 (39c6d488d) | ||
221 | better error handling - Christian Grothoff | ||
222 | |||
223 | Sun, 15 Mar 2020 22:06:28 +0100 (7de26292b) | ||
224 | add function that logically belongs to libgnunetcurl instead of in multiple Taler binaries - Christian Grothoff | ||
225 | |||
226 | Sun, 15 Mar 2020 15:18:53 +0100 (b37cfa2fd) | ||
227 | implement new simplified POW for LSD001 - Martin Schanzenbach | ||
228 | |||
229 | Thu, 12 Mar 2020 12:09:11 +0100 (0c8362ad8) | ||
230 | move literature information to end of paragraph - xrs | ||
231 | |||
232 | Tue, 10 Mar 2020 17:42:04 +0100 (9d5af0464) | ||
233 | import CA into Icecat - Christian Grothoff | ||
234 | |||
235 | Tue, 3 Mar 2020 12:31:23 +0100 (d1bdcb261) | ||
236 | make static analysis happier - Christian Grothoff | ||
237 | |||
238 | Tue, 3 Mar 2020 12:31:12 +0100 (9a6588810) | ||
239 | remove 'illegal' (non-reentrant) log logic from signal handler - Christian Grothoff | ||
240 | |||
241 | Mon, 24 Feb 2020 23:48:47 +0100 (01439e25d) | ||
242 | do not segv if there is no postgres - Christian Grothoff | ||
243 | |||
244 | Mon, 24 Feb 2020 18:19:09 +0100 (dae7d843f) | ||
245 | support versioning schema drop - Christian Grothoff | ||
246 | |||
247 | Wed, 19 Feb 2020 21:52:43 +0100 (ca8202057) | ||
248 | fixing the GNS multirecord multipeer test - Christian Grothoff | ||
249 | |||
250 | Tue, 18 Feb 2020 16:08:43 +0100 (3b2afcd3b) | ||
251 | fix TNG test with NAT - Martin Schanzenbach | ||
252 | |||
253 | Sat, 15 Feb 2020 12:55:24 +0100 (b03978816) | ||
254 | proposed fix for excessive queueing (somehow does not quite work, not sure why) - Christian Grothoff | ||
255 | |||
256 | Sat, 15 Feb 2020 12:25:06 +0100 (e57177325) | ||
257 | better task ordering - Christian Grothoff | ||
258 | |||
259 | Thu, 13 Feb 2020 19:36:37 +0100 (79243b3d2) | ||
260 | add concept of supplemental records - Martin Schanzenbach | ||
261 | |||
262 | Thu, 13 Feb 2020 15:15:18 +0100 (4dc95a504) | ||
263 | always return nick records - Martin Schanzenbach | ||
264 | |||
265 | Wed, 12 Feb 2020 23:09:03 +0100 (206866779) | ||
266 | resolve nick if specifically requested - Martin Schanzenbach | ||
267 | |||
268 | Wed, 12 Feb 2020 22:06:19 +0100 (e021a0f7b) | ||
269 | fix duplicate NICK in record - Martin Schanzenbach | ||
270 | |||
271 | Fri, 7 Feb 2020 15:51:56 +0100 (5f9f9cae1) | ||
272 | consolidate reclaim attribute lib - Martin Schanzenbach | ||
273 | |||
274 | Thu, 6 Feb 2020 22:34:11 +0100 (d06446f14) | ||
275 | add base64url encoding to util (RFC7515) - Martin Schanzenbach | ||
276 | |||
277 | Thu, 6 Feb 2020 20:08:58 +0100 (a80090ffc) | ||
278 | more bugfixes and REST API change - Martin Schanzenbach | ||
279 | |||
280 | Tue, 4 Feb 2020 18:42:04 +0100 (55f6d26b7) | ||
281 | Refactoring reclaim attestations - Martin Schanzenbach | ||
282 | |||
283 | Mon, 3 Feb 2020 21:51:57 +0100 (5b6bb2ce4) | ||
284 | move to 256-bit identifier; some cleanups - Martin Schanzenbach | ||
285 | |||
286 | Sun, 9 Feb 2020 17:31:41 +0100 (99d70615e) | ||
287 | use versioning schema to only load database schema patches if not yet covered according to versioning table - Christian Grothoff | ||
288 | |||
289 | Sun, 9 Feb 2020 15:57:39 +0100 (8f375b3ea) | ||
290 | use NULL value in load_path_suffix to NOT load any files - Christian Grothoff | ||
291 | |||
292 | Tue, 4 Feb 2020 19:18:25 +0100 (1ca805654) | ||
293 | speed up message goodput in perf_mq(client) by 1/3rd - Christian Grothoff | ||
294 | |||
295 | Tue, 4 Feb 2020 19:11:40 +0100 (c656a8218) | ||
296 | adding MQ benchmark - Christian Grothoff | ||
297 | |||
298 | Tue, 4 Feb 2020 18:56:17 +0100 (f40520b09) | ||
299 | speed up running of tasks via GNUNTE_SCHEDULER_add_now() by a factor of at least 5 - Christian Grothoff | ||
300 | |||
301 | Tue, 4 Feb 2020 18:45:19 +0100 (4caa0d290) | ||
302 | add minimal scheduler benchmark - Christian Grothoff | ||
303 | |||
304 | Tue, 4 Feb 2020 15:47:01 +0100 (e14544109) | ||
305 | add timetravel getopt helper - Christian Grothoff | ||
306 | |||
307 | Mon, 3 Feb 2020 23:51:09 +0100 (e3dcec36a) | ||
308 | fix bug *AGAIN*, could swear I fixed this one before... strange - Christian Grothoff | ||
309 | |||
310 | Mon, 3 Feb 2020 18:26:49 +0100 (1bba6bc12) | ||
311 | added a test for DHT lookup between peers - rexxnor | ||
312 | |||
313 | Thu, 30 Jan 2020 10:48:04 +0100 (015cd279b) | ||
314 | added testing scripts for dns2gns - rexxnor | ||
315 | |||
316 | Fri, 24 Jan 2020 16:51:29 +0100 (f4a172abf) | ||
317 | export GNUNET_PQ_run_sql() functonality - Christian Grothoff | ||
318 | |||
319 | Fri, 24 Jan 2020 16:30:45 +0100 (2fd320bc7) | ||
320 | modify GNUNET_PQ_connect_with_cfg to enable flexible loading of .sql files - Christian Grothoff | ||
321 | |||
322 | Sat, 18 Jan 2020 18:47:30 +0100 (bbfde2060) | ||
323 | include mandatory includes - Christian Grothoff | ||
324 | |||
325 | Fri, 17 Jan 2020 12:12:56 +0100 (5422848b4) | ||
326 | do not add '/' to load path - Christian Grothoff | ||
327 | |||
328 | Fri, 17 Jan 2020 03:22:31 +0100 (00bd3376b) | ||
329 | quiet on psql - Christian Grothoff | ||
330 | |||
331 | Fri, 17 Jan 2020 02:51:10 +0100 (8fa757a94) | ||
332 | auto-provide OS_IPK paths in [paths] of config - Christian Grothoff | ||
333 | |||
334 | Fri, 17 Jan 2020 02:35:29 +0100 (3c1f2bdd8) | ||
335 | be more quiet - Christian Grothoff | ||
336 | |||
337 | Fri, 17 Jan 2020 02:26:21 +0100 (4353432b9) | ||
338 | DB load API change - Christian Grothoff | ||
339 | |||
340 | Fri, 17 Jan 2020 00:25:55 +0100 (1126181ab) | ||
341 | include buffer in main util header - Christian Grothoff | ||
342 | |||
343 | Thu, 16 Jan 2020 17:11:58 +0100 (ec7870968) | ||
344 | add new versions of alpine packages (not yet in alpine repo) - xrs | ||
345 | |||
346 | Wed, 15 Jan 2020 19:41:05 +0100 (5177efb74) | ||
347 | remove Taler-specific leftovers, we don't need them anymore - Florian Dold | ||
348 | |||
349 | Wed, 15 Jan 2020 13:29:47 +0100 (9f36b6e9e) | ||
350 | add test vector generation for crypto ops - Florian Dold | ||
351 | |||
352 | Wed, 15 Jan 2020 11:45:20 +0100 (9f3f1753e) | ||
353 | move buffer library from GNU Taler to GNUnet - Florian Dold | ||
354 | |||
355 | Mon, 13 Jan 2020 18:58:13 -0600 (55d610bb3) | ||
356 | Fix copy/paste error checking for explicit_bzero - David Barksdale | ||
357 | |||
358 | |||
1 | Fri Dec 20 09:22:03 2019 +0900 | 359 | Fri Dec 20 09:22:03 2019 +0900 |
2 | Released gnunet 0.12.0 -schanzen | 360 | Released gnunet 0.12.0 -schanzen |
3 | 361 | ||
@@ -63,7 +63,7 @@ These are the direct dependencies for running GNUnet: | |||
63 | - gettext | 63 | - gettext |
64 | - gnutls >= 3.2.12 (highly recommended a gnutls | 64 | - gnutls >= 3.2.12 (highly recommended a gnutls |
65 | linked against libunbound) | 65 | linked against libunbound) |
66 | - A curl build against gnutls, or gnurl: | 66 | - curl (ideally built against gnutls) or gnurl: |
67 | * libgnurl >= 7.35.0 (recommended, available from | 67 | * libgnurl >= 7.35.0 (recommended, available from |
68 | https://gnunet.org/en/gnurl.html) | 68 | https://gnunet.org/en/gnurl.html) |
69 | or | 69 | or |
@@ -74,8 +74,8 @@ These are the direct dependencies for running GNUnet: | |||
74 | * libidn2 (prefered) | 74 | * libidn2 (prefered) |
75 | or | 75 | or |
76 | * libidn >= 1.0 | 76 | * libidn >= 1.0 |
77 | - libmicrohttpd >= 0.9.63 (strongly recommended for | 77 | - libmicrohttpd >= 0.9.63 |
78 | a wide range of features) | 78 | - libjansson |
79 | - makeinfo >= 4.8 | 79 | - makeinfo >= 4.8 |
80 | - make[*3] | 80 | - make[*3] |
81 | - nss (certutil binary, for | 81 | - nss (certutil binary, for |
@@ -96,8 +96,6 @@ These are the direct dependencies for running GNUnet: | |||
96 | - which (contrib/apparmor(?), gnunet-bugreport, | 96 | - which (contrib/apparmor(?), gnunet-bugreport, |
97 | and possibly more) | 97 | and possibly more) |
98 | - zlib | 98 | - zlib |
99 | - argon2 >= 20190702 (for proof-of-work calculations in | ||
100 | revocation) | ||
101 | - libsodium >= 1.0.11 (for elliptic curve cryptography) | 99 | - libsodium >= 1.0.11 (for elliptic curve cryptography) |
102 | 100 | ||
103 | These are the dependencies for GNUnet's testsuite: | 101 | These are the dependencies for GNUnet's testsuite: |
@@ -124,7 +122,6 @@ These are the optional dependencies: | |||
124 | - bluez (for bluetooth support) | 122 | - bluez (for bluetooth support) |
125 | - grof (for linting of man pages) | 123 | - grof (for linting of man pages) |
126 | - libextractor >= 0.6.1 (highly recommended[*5]) | 124 | - libextractor >= 0.6.1 (highly recommended[*5]) |
127 | - libjansson | ||
128 | - libopus >= 1.0.1 (for conversation tool) | 125 | - libopus >= 1.0.1 (for conversation tool) |
129 | - libpulse >= 2.0 (for conversation tool) | 126 | - libpulse >= 2.0 (for conversation tool) |
130 | - libogg >= 1.3.0 (for conversation tool) | 127 | - libogg >= 1.3.0 (for conversation tool) |
diff --git a/configure.ac b/configure.ac index 94c0a7689..6dc914c12 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -786,12 +786,9 @@ AC_ARG_WITH(jansson, | |||
786 | ], | 786 | ], |
787 | [AC_MSG_RESULT([--with-jansson not specified]) | 787 | [AC_MSG_RESULT([--with-jansson not specified]) |
788 | CHECK_LIBHEADER(JANSSON, jansson, json_loads, jansson.h,jansson=1,)]) | 788 | CHECK_LIBHEADER(JANSSON, jansson, json_loads, jansson.h,jansson=1,)]) |
789 | AM_CONDITIONAL(HAVE_JANSSON, [test "$jansson" = 1]) | ||
790 | AM_CONDITIONAL(HAVE_JSON, [test x$jansson = x1]) | ||
791 | AS_IF([test "x$jansson" = x1], | ||
792 | [AC_DEFINE([HAVE_JANSSON],[1],[Have jansson library])], | ||
793 | [AC_DEFINE([HAVE_JANSSON],[0],[Lacking jansson library])]) | ||
794 | 789 | ||
790 | AS_IF([test "x$jansson" != x1], | ||
791 | [AC_MSG_ERROR([GNUnet requires libjansson])]) | ||
795 | 792 | ||
796 | # check for libpulse(audio) library | 793 | # check for libpulse(audio) library |
797 | pulse=0 | 794 | pulse=0 |
@@ -984,8 +981,8 @@ AS_IF([test "x$curl" = xtrue],[ | |||
984 | AC_CHECK_HEADER([curl/curl.h], | 981 | AC_CHECK_HEADER([curl/curl.h], |
985 | AC_CHECK_DECLS(CURLINFO_TLS_SESSION,[curl=true],[curl=false],[[#include <curl/curl.h>]]), | 982 | AC_CHECK_DECLS(CURLINFO_TLS_SESSION,[curl=true],[curl=false],[[#include <curl/curl.h>]]), |
986 | [curl=false]) | 983 | [curl=false]) |
987 | # need libcurl-gnutls.so, everything else is not acceptable | 984 | # need libcurl-gnutls.so for proxy, warn later if not found. |
988 | AC_CHECK_LIB([curl-gnutls],[curl_easy_getinfo],,[curl=false]) | 985 | AC_CHECK_LIB([curl-gnutls],[curl_easy_getinfo],[curl_gnutls=true],[curl_gnutls=false]) |
989 | # cURL must support CURLINFO_TLS_SESSION, version >= 7.34 | 986 | # cURL must support CURLINFO_TLS_SESSION, version >= 7.34 |
990 | ]) | 987 | ]) |
991 | 988 | ||
@@ -1000,7 +997,7 @@ AS_IF([test "$gnurl" = 1], | |||
1000 | AC_DEFINE([HAVE_LIBGNURL],[0],[Lacking libgnurl]) | 997 | AC_DEFINE([HAVE_LIBGNURL],[0],[Lacking libgnurl]) |
1001 | AM_CONDITIONAL(HAVE_LIBCURL, true) | 998 | AM_CONDITIONAL(HAVE_LIBCURL, true) |
1002 | AC_DEFINE([HAVE_LIBCURL],[1],[Have libcurl])], | 999 | AC_DEFINE([HAVE_LIBCURL],[1],[Have libcurl])], |
1003 | [AC_MSG_WARN([ERROR: GNUnet requires libcurl-gnutls or gnurl >= 7.34]) | 1000 | [AC_MSG_ERROR([GNUnet requires libcurl or gnurl >= 7.34]) |
1004 | AM_CONDITIONAL(HAVE_LIBGNURL, false) | 1001 | AM_CONDITIONAL(HAVE_LIBGNURL, false) |
1005 | AC_DEFINE([HAVE_LIBGNURL],[0],[Lacking libgnurl]) | 1002 | AC_DEFINE([HAVE_LIBGNURL],[0],[Lacking libgnurl]) |
1006 | AM_CONDITIONAL(HAVE_LIBCURL, false) | 1003 | AM_CONDITIONAL(HAVE_LIBCURL, false) |
@@ -1036,20 +1033,10 @@ AS_IF([test x$nss = xfalse], | |||
1036 | AC_CHECK_LIB([kvm],[kvm_open]) | 1033 | AC_CHECK_LIB([kvm],[kvm_open]) |
1037 | AC_CHECK_LIB([kstat],[kstat_open]) | 1034 | AC_CHECK_LIB([kstat],[kstat_open]) |
1038 | 1035 | ||
1039 | argon=0 | ||
1040 | # test for argon2 (for POW) | ||
1041 | AC_CHECK_LIB([argon2],[argon2d_hash_raw], argon=1, argon=0) | ||
1042 | AS_IF([test x$argon = x1], | ||
1043 | [ | ||
1044 | AC_MSG_RESULT([argon2 found]) | ||
1045 | ],[ | ||
1046 | AC_MSG_ERROR([GNUnet requires argon2.]) | ||
1047 | ]) | ||
1048 | |||
1049 | libsodium=0 | 1036 | libsodium=0 |
1050 | # test for libsodium | 1037 | # test for libsodium |
1051 | AC_CHECK_HEADER([sodium.h], | 1038 | AC_CHECK_HEADER([sodium.h], |
1052 | [AC_CHECK_LIB([sodium], [sodium_init], | 1039 | [AC_CHECK_LIB([sodium], [crypto_pwhash_argon2id], |
1053 | [libsodium=1])]) | 1040 | [libsodium=1])]) |
1054 | 1041 | ||
1055 | AS_IF([test x$libsodium = x0], | 1042 | AS_IF([test x$libsodium = x0], |
@@ -1472,6 +1459,9 @@ AC_DEFINE_UNQUOTED([HAVE_MHD], $lmhd, [We have libmicrohttpd]) | |||
1472 | 1459 | ||
1473 | AM_CONDITIONAL(HAVE_JSON, [test x$jansson = x1]) | 1460 | AM_CONDITIONAL(HAVE_JSON, [test x$jansson = x1]) |
1474 | AM_CONDITIONAL(HAVE_REST, [test x$jansson = x1 -a x$lmhd = x1]) | 1461 | AM_CONDITIONAL(HAVE_REST, [test x$jansson = x1 -a x$lmhd = x1]) |
1462 | AS_IF([test "x$lmhd" != "x1"], | ||
1463 | [AC_MSG_ERROR([GNUnet requires libmicrohttpd >= 0.9.63.])]) | ||
1464 | |||
1475 | 1465 | ||
1476 | # restore LIBS | 1466 | # restore LIBS |
1477 | LIBS=$SAVE_LIBS | 1467 | LIBS=$SAVE_LIBS |
@@ -2001,7 +1991,7 @@ AS_IF([test "x$enable_java_ports" = "xyes"], | |||
2001 | #### This could be moved to the checks above, | 1991 | #### This could be moved to the checks above, |
2002 | #### but for now let's keep it here. | 1992 | #### but for now let's keep it here. |
2003 | #### | 1993 | #### |
2004 | transport_msg="tcp udp unix" | 1994 | transport_msg="tcp udp unix http" |
2005 | AS_IF([test "x$build_target" = "xlinux" -a "x$enable_experimental" = "xyes"], | 1995 | AS_IF([test "x$build_target" = "xlinux" -a "x$enable_experimental" = "xyes"], |
2006 | [transport_msg="$transport_msg wlan"]) | 1996 | [transport_msg="$transport_msg wlan"]) |
2007 | # -- print message regarding enabled experimental features | 1997 | # -- print message regarding enabled experimental features |
@@ -2047,26 +2037,10 @@ AS_IF([test "x$conversation_backend" = "xnone"], | |||
2047 | [AS_IF([test "x$opus" = x1], | 2037 | [AS_IF([test "x$opus" = x1], |
2048 | [conversation_msg="yes (x$conversation_backend)"], | 2038 | [conversation_msg="yes (x$conversation_backend)"], |
2049 | [AC_MSG_WARN([libopus not found (required to build conversation)])])]) | 2039 | [AC_MSG_WARN([libopus not found (required to build conversation)])])]) |
2050 | # -- rest / oidc | ||
2051 | rest_msg="no" | ||
2052 | AS_IF([test "x$lmhd" = "x1" -a "x$jansson" = "x1"], | ||
2053 | [rest_msg="yes" | ||
2054 | reclaim_msg="yes (with OpenID Connect)"], | ||
2055 | [rest_msg="no" | ||
2056 | reclaim_msg="yes (without OpenID Connect)"]) | ||
2057 | |||
2058 | 2040 | ||
2059 | # -- interface | 2041 | # -- interface |
2060 | interface_msg=`echo $DEFAULT_INTERFACE | tr -d \"` | 2042 | interface_msg=`echo $DEFAULT_INTERFACE | tr -d \"` |
2061 | # -- libmicrohttpd | ||
2062 | AS_IF([test "x$lmhd" = "x0"], | ||
2063 | [libmicrohttpd_msg="no (REST service and HTTP transport will not be built)"], | ||
2064 | [libmicrohttpd_msg="yes" | ||
2065 | transport_msg="$transport_msg http_server"]) | ||
2066 | # -- jansson | 2043 | # -- jansson |
2067 | AS_IF([test "x$jansson" = "x0"], | ||
2068 | [jansson_msg="no (REST service will not be built)"], | ||
2069 | [jansson_msg="yes"]) | ||
2070 | # -- libextractor | 2044 | # -- libextractor |
2071 | AS_IF([test "$extractor" != 1], | 2045 | AS_IF([test "$extractor" != 1], |
2072 | [AC_MSG_WARN([libextractor not found, but various file-sharing functions require it])], | 2046 | [AC_MSG_WARN([libextractor not found, but various file-sharing functions require it])], |
@@ -2080,11 +2054,15 @@ AS_IF([test "$gnurl" = "0"], | |||
2080 | [AS_IF([test "x$curl" = "xfalse"], | 2054 | [AS_IF([test "x$curl" = "xfalse"], |
2081 | [AC_MSG_WARN([libgnurl not found. http client support will not be compiled.]) | 2055 | [AC_MSG_WARN([libgnurl not found. http client support will not be compiled.]) |
2082 | AC_MSG_WARN([IMPORTANT: No HTTP client library found. HTTP transports and hostlist daemon will not be compiled, and you probably WANT the hostlist daemon]) | 2056 | AC_MSG_WARN([IMPORTANT: No HTTP client library found. HTTP transports and hostlist daemon will not be compiled, and you probably WANT the hostlist daemon]) |
2083 | curl_msg="no"], | 2057 | http_client="none"], |
2084 | [AC_MSG_NOTICE([libgnurl not found, trying to use libcurl-gnutls instead.]) | 2058 | [AC_MSG_NOTICE([Using libcurl as HTTP client library.]) |
2085 | curl_msg="yes"])], | 2059 | http_client="curl"])], |
2086 | [gnurl_msg="yes" | 2060 | [AC_MSG_NOTICE([Using libgnurl as HTTP client library.]) |
2087 | transport_msg="$transport_msg http_client"]) | 2061 | http_client="gnurl"]) |
2062 | AS_IF([test "x$curl" = "xtrue" -a "x$curl_gnutls" != "xtrue"], | ||
2063 | [AC_MSG_WARN([libcurl TLS backend is not gnutls. The GNS Proxy will likely not function properly.]) | ||
2064 | http_client="curl-openssl"], | ||
2065 | [http_client="curl-gnutls"]) | ||
2088 | # -- ifconfig | 2066 | # -- ifconfig |
2089 | AS_IF([test "$VAR_IFCONFIG_BINARY" = "false"], | 2067 | AS_IF([test "$VAR_IFCONFIG_BINARY" = "false"], |
2090 | [ifconfig_msg="no (optional, some features will not work)"], | 2068 | [ifconfig_msg="no (optional, some features will not work)"], |
@@ -2160,17 +2138,14 @@ Default Interface: ${interface_msg} | |||
2160 | MySQL: ${mysql_msg} | 2138 | MySQL: ${mysql_msg} |
2161 | PostgreSQL: ${postgres_msg} | 2139 | PostgreSQL: ${postgres_msg} |
2162 | sqlite3: ${sqlite_msg} | 2140 | sqlite3: ${sqlite_msg} |
2163 | gnurl: ${gnurl_msg} | 2141 | http client: ${http_client} |
2164 | curl: ${curl_msg} | ||
2165 | bluetooth: ${bluetooth_msg} | 2142 | bluetooth: ${bluetooth_msg} |
2166 | jansson: ${jansson_msg} | ||
2167 | iptables: ${iptables_msg} | 2143 | iptables: ${iptables_msg} |
2168 | ifconfig: ${ifconfig_msg} | 2144 | ifconfig: ${ifconfig_msg} |
2169 | upnpc: ${upnpc_msg} | 2145 | upnpc: ${upnpc_msg} |
2170 | gnutls: ${gnutls_msg} | 2146 | gnutls: ${gnutls_msg} |
2171 | libzbar: ${libzbar_msg} | 2147 | libzbar: ${libzbar_msg} |
2172 | java: ${java_msg} | 2148 | java: ${java_msg} |
2173 | libmicrohttpd: ${libmicrohttpd_msg} | ||
2174 | libidn: ${libidn1_msg}${libidn2_msg} | 2149 | libidn: ${libidn1_msg}${libidn2_msg} |
2175 | libopus: ${libopus_msg} | 2150 | libopus: ${libopus_msg} |
2176 | gstreamer: ${gstreamer_msg} | 2151 | gstreamer: ${gstreamer_msg} |
@@ -2182,9 +2157,7 @@ mandoc: ${mandoc_msg} | |||
2182 | GNUnet configuration: | 2157 | GNUnet configuration: |
2183 | ===================== | 2158 | ===================== |
2184 | transports: ${transport_msg} | 2159 | transports: ${transport_msg} |
2185 | reclaimID: ${reclaim_msg} | ||
2186 | conversation: ${conversation_msg} | 2160 | conversation: ${conversation_msg} |
2187 | rest: ${rest_msg} | ||
2188 | database backends: ${features_msg} | 2161 | database backends: ${features_msg} |
2189 | experimental: ${experimental_msg} | 2162 | experimental: ${experimental_msg} |
2190 | 2163 | ||
diff --git a/contrib/scripts/changelog_delta.sh b/contrib/scripts/changelog_delta.sh new file mode 100644 index 000000000..1c14d69e2 --- /dev/null +++ b/contrib/scripts/changelog_delta.sh | |||
@@ -0,0 +1,3 @@ | |||
1 | #!/bin/bash | ||
2 | LASTHASH=$(head -n1 ChangeLog | cut -d " " -f 7 | tr -d \( | tr -d \)) | ||
3 | git log --invert-grep --grep="^- " --no-merges --no-color --format="%aD (%h)%n%s - %cN%n" $LASTHASH..HEAD | ||
diff --git a/doc/handbook/chapters/developer.texi b/doc/handbook/chapters/developer.texi index de5166226..ca76a5f2b 100644 --- a/doc/handbook/chapters/developer.texi +++ b/doc/handbook/chapters/developer.texi | |||
@@ -848,8 +848,9 @@ libgnunet_plugin_transport_tcp) | |||
848 | @c XXX: Adjust examples to GNU Standards! | 848 | @c XXX: Adjust examples to GNU Standards! |
849 | @itemize @bullet | 849 | @itemize @bullet |
850 | @item We follow the GNU Coding Standards (@pxref{Top, The GNU Coding Standards,, standards, The GNU Coding Standards}); | 850 | @item We follow the GNU Coding Standards (@pxref{Top, The GNU Coding Standards,, standards, The GNU Coding Standards}); |
851 | @item Indentation is done with spaces, two per level, no tabs; | 851 | @item Indentation is done with spaces, two per level, no tabs; specific (incomplete!) indentation rules are provided in an @code{uncrustify} configuration file (in ``contrib/``) and enforced by Git hooks; |
852 | @item C99 struct initialization is fine; | 852 | @item C99 struct initialization is fine and generally encouraged (but not required); |
853 | @item As in all good C code, we care about symbol space pollution and thus use @code{static} to limit the scope where possible, even in the compilation unit that contains @code{main}; | ||
853 | @item declare only one variable per line, for example: | 854 | @item declare only one variable per line, for example: |
854 | 855 | ||
855 | @noindent | 856 | @noindent |
@@ -1063,6 +1064,32 @@ separated by an empty line (possibly followed by a comment describing the | |||
1063 | following step). The code should not contain empty lines in arbitrary | 1064 | following step). The code should not contain empty lines in arbitrary |
1064 | places; if in doubt, it is likely better to NOT have an empty line (this | 1065 | places; if in doubt, it is likely better to NOT have an empty line (this |
1065 | way, more code will fit on the screen). | 1066 | way, more code will fit on the screen). |
1067 | |||
1068 | |||
1069 | @item When command-line arguments become too long (and would result in | ||
1070 | some particularly ugly @code{uncrustify} wrapping), we start all arguments | ||
1071 | on a new line. As a result, there must never be a new line within an | ||
1072 | argument declaration (i.e. between @code{struct} and the struct's name) or | ||
1073 | between the type and the variable). Example: | ||
1074 | |||
1075 | @example | ||
1076 | struct GNUNET_TRANSPORT_CommunicatorHandle * | ||
1077 | GNUNET_TRANSPORT_communicator_connect ( | ||
1078 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
1079 | const char *config_section_name, | ||
1080 | const char *addr_prefix, | ||
1081 | ...); | ||
1082 | @end example | ||
1083 | |||
1084 | Note that for short function names and arguments, the first argument | ||
1085 | does remain on the same line. Example: | ||
1086 | |||
1087 | @example | ||
1088 | void | ||
1089 | fun (short i, | ||
1090 | short j); | ||
1091 | @end example | ||
1092 | |||
1066 | @end itemize | 1093 | @end itemize |
1067 | 1094 | ||
1068 | @c *********************************************************************** | 1095 | @c *********************************************************************** |
@@ -8941,4 +8968,3 @@ view are sampled through the sampler from the random stream of peer IDs. | |||
8941 | 8968 | ||
8942 | According to the theoretical analysis of Bortnikov et al. this suffices | 8969 | According to the theoretical analysis of Bortnikov et al. this suffices |
8943 | to keep the network connected and having random peers in the view. | 8970 | to keep the network connected and having random peers in the view. |
8944 | |||
diff --git a/doc/handbook/chapters/preface.texi b/doc/handbook/chapters/preface.texi index 800b7c7cd..443fb2600 100644 --- a/doc/handbook/chapters/preface.texi +++ b/doc/handbook/chapters/preface.texi | |||
@@ -181,14 +181,11 @@ GNUnet maintainer can overrule any decisions made by individual | |||
181 | developers. Still, in practice neither has happened in the last 20 | 181 | developers. Still, in practice neither has happened in the last 20 |
182 | years for GNUnet, and we hope to keep it that way. | 182 | years for GNUnet, and we hope to keep it that way. |
183 | 183 | ||
184 | @c TODO: Actually we are a Swiss association, or just a German association | ||
185 | @c TODO: with Swiss bylaws/Satzung? | ||
186 | @c TODO: Rewrite one of the 'GNUnet eV may also' sentences? | ||
187 | The GNUnet project is supported by GNUnet e.V., a German association | 184 | The GNUnet project is supported by GNUnet e.V., a German association |
188 | where any developer can become a member. GNUnet e.V. serves as a | 185 | where any developer can become a member. GNUnet e.V. serves as a |
189 | legal entity to hold the copyrights to GNUnet. GNUnet e.V. may also | 186 | legal entity to hold the copyrights to GNUnet. GNUnet e.V. may also |
190 | choose to pay for project resources, and can collect donations. | 187 | choose to pay for project resources, and can collect donations as |
191 | GNUnet e.V. may also choose to adjust the license of the | 188 | well as choose to adjust the license of the |
192 | software (with the constraint that it has to remain free software). | 189 | software (with the constraint that it has to remain free software). |
193 | In 2018 we switched from GPL3 to AGPL3, in practice these changes do | 190 | In 2018 we switched from GPL3 to AGPL3, in practice these changes do |
194 | not happen very often. | 191 | not happen very often. |
diff --git a/po/POTFILES.in b/po/POTFILES.in index f38c81f49..533b2dda9 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in | |||
@@ -10,13 +10,21 @@ src/arm/arm_monitor_api.c | |||
10 | src/arm/gnunet-arm.c | 10 | src/arm/gnunet-arm.c |
11 | src/arm/gnunet-service-arm.c | 11 | src/arm/gnunet-service-arm.c |
12 | src/arm/mockup-service.c | 12 | src/arm/mockup-service.c |
13 | src/ats-tests/ats-testing-experiment.c | ||
14 | src/ats-tests/ats-testing-log.c | ||
15 | src/ats-tests/ats-testing-preferences.c | ||
16 | src/ats-tests/ats-testing-traffic.c | ||
17 | src/ats-tests/ats-testing.c | ||
18 | src/ats-tests/gnunet-ats-sim.c | ||
19 | src/ats-tests/gnunet-solver-eval.c | ||
20 | src/ats-tool/gnunet-ats.c | ||
13 | src/ats/ats_api_connectivity.c | 21 | src/ats/ats_api_connectivity.c |
14 | src/ats/ats_api_performance.c | 22 | src/ats/ats_api_performance.c |
15 | src/ats/ats_api_scanner.c | 23 | src/ats/ats_api_scanner.c |
16 | src/ats/ats_api_scheduling.c | 24 | src/ats/ats_api_scheduling.c |
17 | src/ats/gnunet-ats-solver-eval.c | 25 | src/ats/gnunet-ats-solver-eval.c |
18 | src/ats/gnunet-service-ats_addresses.c | ||
19 | src/ats/gnunet-service-ats.c | 26 | src/ats/gnunet-service-ats.c |
27 | src/ats/gnunet-service-ats_addresses.c | ||
20 | src/ats/gnunet-service-ats_connectivity.c | 28 | src/ats/gnunet-service-ats_connectivity.c |
21 | src/ats/gnunet-service-ats_normalization.c | 29 | src/ats/gnunet-service-ats_normalization.c |
22 | src/ats/gnunet-service-ats_performance.c | 30 | src/ats/gnunet-service-ats_performance.c |
@@ -25,14 +33,6 @@ src/ats/gnunet-service-ats_preferences.c | |||
25 | src/ats/gnunet-service-ats_reservations.c | 33 | src/ats/gnunet-service-ats_reservations.c |
26 | src/ats/gnunet-service-ats_scheduling.c | 34 | src/ats/gnunet-service-ats_scheduling.c |
27 | src/ats/plugin_ats_proportional.c | 35 | src/ats/plugin_ats_proportional.c |
28 | src/ats-tests/ats-testing.c | ||
29 | src/ats-tests/ats-testing-experiment.c | ||
30 | src/ats-tests/ats-testing-log.c | ||
31 | src/ats-tests/ats-testing-preferences.c | ||
32 | src/ats-tests/ats-testing-traffic.c | ||
33 | src/ats-tests/gnunet-ats-sim.c | ||
34 | src/ats-tests/gnunet-solver-eval.c | ||
35 | src/ats-tool/gnunet-ats.c | ||
36 | src/auction/gnunet-auction-create.c | 36 | src/auction/gnunet-auction-create.c |
37 | src/auction/gnunet-auction-info.c | 37 | src/auction/gnunet-auction-info.c |
38 | src/auction/gnunet-auction-join.c | 38 | src/auction/gnunet-auction-join.c |
@@ -49,8 +49,8 @@ src/cadet/cadet_api_list_peers.c | |||
49 | src/cadet/cadet_api_list_tunnels.c | 49 | src/cadet/cadet_api_list_tunnels.c |
50 | src/cadet/cadet_test_lib.c | 50 | src/cadet/cadet_test_lib.c |
51 | src/cadet/desirability_table.c | 51 | src/cadet/desirability_table.c |
52 | src/cadet/gnunet-cadet.c | ||
53 | src/cadet/gnunet-cadet-profiler.c | 52 | src/cadet/gnunet-cadet-profiler.c |
53 | src/cadet/gnunet-cadet.c | ||
54 | src/cadet/gnunet-service-cadet.c | 54 | src/cadet/gnunet-service-cadet.c |
55 | src/cadet/gnunet-service-cadet_channel.c | 55 | src/cadet/gnunet-service-cadet_channel.c |
56 | src/cadet/gnunet-service-cadet_connection.c | 56 | src/cadet/gnunet-service-cadet_connection.c |
@@ -66,15 +66,15 @@ src/consensus/gnunet-service-consensus.c | |||
66 | src/consensus/plugin_block_consensus.c | 66 | src/consensus/plugin_block_consensus.c |
67 | src/conversation/conversation_api.c | 67 | src/conversation/conversation_api.c |
68 | src/conversation/conversation_api_call.c | 68 | src/conversation/conversation_api_call.c |
69 | src/conversation/gnunet-conversation.c | ||
70 | src/conversation/gnunet-conversation-test.c | 69 | src/conversation/gnunet-conversation-test.c |
71 | src/conversation/gnunet_gst.c | 70 | src/conversation/gnunet-conversation.c |
72 | src/conversation/gnunet_gst_test.c | ||
73 | src/conversation/gnunet-helper-audio-playback.c | ||
74 | src/conversation/gnunet-helper-audio-playback-gst.c | 71 | src/conversation/gnunet-helper-audio-playback-gst.c |
75 | src/conversation/gnunet-helper-audio-record.c | 72 | src/conversation/gnunet-helper-audio-playback.c |
76 | src/conversation/gnunet-helper-audio-record-gst.c | 73 | src/conversation/gnunet-helper-audio-record-gst.c |
74 | src/conversation/gnunet-helper-audio-record.c | ||
77 | src/conversation/gnunet-service-conversation.c | 75 | src/conversation/gnunet-service-conversation.c |
76 | src/conversation/gnunet_gst.c | ||
77 | src/conversation/gnunet_gst_test.c | ||
78 | src/conversation/microphone.c | 78 | src/conversation/microphone.c |
79 | src/conversation/plugin_gnsrecord_conversation.c | 79 | src/conversation/plugin_gnsrecord_conversation.c |
80 | src/conversation/speaker.c | 80 | src/conversation/speaker.c |
@@ -104,7 +104,6 @@ src/dht/dht_api.c | |||
104 | src/dht/dht_test_lib.c | 104 | src/dht/dht_test_lib.c |
105 | src/dht/gnunet-dht-get.c | 105 | src/dht/gnunet-dht-get.c |
106 | src/dht/gnunet-dht-monitor.c | 106 | src/dht/gnunet-dht-monitor.c |
107 | src/dht/gnunet_dht_profiler.c | ||
108 | src/dht/gnunet-dht-put.c | 107 | src/dht/gnunet-dht-put.c |
109 | src/dht/gnunet-service-dht.c | 108 | src/dht/gnunet-service-dht.c |
110 | src/dht/gnunet-service-dht_clients.c | 109 | src/dht/gnunet-service-dht_clients.c |
@@ -113,6 +112,7 @@ src/dht/gnunet-service-dht_hello.c | |||
113 | src/dht/gnunet-service-dht_neighbours.c | 112 | src/dht/gnunet-service-dht_neighbours.c |
114 | src/dht/gnunet-service-dht_nse.c | 113 | src/dht/gnunet-service-dht_nse.c |
115 | src/dht/gnunet-service-dht_routing.c | 114 | src/dht/gnunet-service-dht_routing.c |
115 | src/dht/gnunet_dht_profiler.c | ||
116 | src/dht/plugin_block_dht.c | 116 | src/dht/plugin_block_dht.c |
117 | src/dns/dns_api.c | 117 | src/dns/dns_api.c |
118 | src/dns/gnunet-dns-monitor.c | 118 | src/dns/gnunet-dns-monitor.c |
@@ -147,8 +147,8 @@ src/fs/gnunet-auto-share.c | |||
147 | src/fs/gnunet-daemon-fsprofiler.c | 147 | src/fs/gnunet-daemon-fsprofiler.c |
148 | src/fs/gnunet-directory.c | 148 | src/fs/gnunet-directory.c |
149 | src/fs/gnunet-download.c | 149 | src/fs/gnunet-download.c |
150 | src/fs/gnunet-fs.c | ||
151 | src/fs/gnunet-fs-profiler.c | 150 | src/fs/gnunet-fs-profiler.c |
151 | src/fs/gnunet-fs.c | ||
152 | src/fs/gnunet-helper-fs-publish.c | 152 | src/fs/gnunet-helper-fs-publish.c |
153 | src/fs/gnunet-publish.c | 153 | src/fs/gnunet-publish.c |
154 | src/fs/gnunet-search.c | 154 | src/fs/gnunet-search.c |
@@ -168,9 +168,9 @@ src/gns/gns_tld_api.c | |||
168 | src/gns/gnunet-bcd.c | 168 | src/gns/gnunet-bcd.c |
169 | src/gns/gnunet-dns2gns.c | 169 | src/gns/gnunet-dns2gns.c |
170 | src/gns/gnunet-gns-benchmark.c | 170 | src/gns/gnunet-gns-benchmark.c |
171 | src/gns/gnunet-gns.c | ||
172 | src/gns/gnunet-gns-import.c | 171 | src/gns/gnunet-gns-import.c |
173 | src/gns/gnunet-gns-proxy.c | 172 | src/gns/gnunet-gns-proxy.c |
173 | src/gns/gnunet-gns.c | ||
174 | src/gns/gnunet-service-gns.c | 174 | src/gns/gnunet-service-gns.c |
175 | src/gns/gnunet-service-gns_interceptor.c | 175 | src/gns/gnunet-service-gns_interceptor.c |
176 | src/gns/gnunet-service-gns_resolver.c | 176 | src/gns/gnunet-service-gns_resolver.c |
@@ -183,11 +183,12 @@ src/gnsrecord/gnsrecord.c | |||
183 | src/gnsrecord/gnsrecord_crypto.c | 183 | src/gnsrecord/gnsrecord_crypto.c |
184 | src/gnsrecord/gnsrecord_misc.c | 184 | src/gnsrecord/gnsrecord_misc.c |
185 | src/gnsrecord/gnsrecord_serialization.c | 185 | src/gnsrecord/gnsrecord_serialization.c |
186 | src/gnsrecord/gnunet-gnsrecord-tvg.c | ||
186 | src/gnsrecord/plugin_gnsrecord_dns.c | 187 | src/gnsrecord/plugin_gnsrecord_dns.c |
187 | src/hello/address.c | 188 | src/hello/address.c |
188 | src/hello/gnunet-hello.c | 189 | src/hello/gnunet-hello.c |
189 | src/hello/hello.c | ||
190 | src/hello/hello-ng.c | 190 | src/hello/hello-ng.c |
191 | src/hello/hello.c | ||
191 | src/hostlist/gnunet-daemon-hostlist.c | 192 | src/hostlist/gnunet-daemon-hostlist.c |
192 | src/hostlist/gnunet-daemon-hostlist_client.c | 193 | src/hostlist/gnunet-daemon-hostlist_client.c |
193 | src/hostlist/gnunet-daemon-hostlist_server.c | 194 | src/hostlist/gnunet-daemon-hostlist_server.c |
@@ -212,8 +213,8 @@ src/namecache/namecache_api.c | |||
212 | src/namecache/plugin_namecache_flat.c | 213 | src/namecache/plugin_namecache_flat.c |
213 | src/namecache/plugin_namecache_postgres.c | 214 | src/namecache/plugin_namecache_postgres.c |
214 | src/namecache/plugin_namecache_sqlite.c | 215 | src/namecache/plugin_namecache_sqlite.c |
215 | src/namestore/gnunet-namestore.c | ||
216 | src/namestore/gnunet-namestore-fcfsd.c | 216 | src/namestore/gnunet-namestore-fcfsd.c |
217 | src/namestore/gnunet-namestore.c | ||
217 | src/namestore/gnunet-service-namestore.c | 218 | src/namestore/gnunet-service-namestore.c |
218 | src/namestore/gnunet-zoneimport.c | 219 | src/namestore/gnunet-zoneimport.c |
219 | src/namestore/namestore_api.c | 220 | src/namestore/namestore_api.c |
@@ -239,17 +240,17 @@ src/nat/gnunet-service-nat_mini.c | |||
239 | src/nat/gnunet-service-nat_stun.c | 240 | src/nat/gnunet-service-nat_stun.c |
240 | src/nat/nat_api.c | 241 | src/nat/nat_api.c |
241 | src/nat/nat_api_stun.c | 242 | src/nat/nat_api_stun.c |
242 | src/nse/gnunet-nse.c | ||
243 | src/nse/gnunet-nse-profiler.c | 243 | src/nse/gnunet-nse-profiler.c |
244 | src/nse/gnunet-nse.c | ||
244 | src/nse/gnunet-service-nse.c | 245 | src/nse/gnunet-service-nse.c |
245 | src/nse/nse_api.c | 246 | src/nse/nse_api.c |
246 | src/nt/nt.c | 247 | src/nt/nt.c |
247 | src/peerinfo/gnunet-service-peerinfo.c | ||
248 | src/peerinfo/peerinfo_api.c | ||
249 | src/peerinfo/peerinfo_api_notify.c | ||
250 | src/peerinfo-tool/gnunet-peerinfo.c | 248 | src/peerinfo-tool/gnunet-peerinfo.c |
251 | src/peerinfo-tool/gnunet-peerinfo_plugins.c | 249 | src/peerinfo-tool/gnunet-peerinfo_plugins.c |
252 | src/peerinfo-tool/plugin_rest_peerinfo.c | 250 | src/peerinfo-tool/plugin_rest_peerinfo.c |
251 | src/peerinfo/gnunet-service-peerinfo.c | ||
252 | src/peerinfo/peerinfo_api.c | ||
253 | src/peerinfo/peerinfo_api_notify.c | ||
253 | src/peerstore/gnunet-peerstore.c | 254 | src/peerstore/gnunet-peerstore.c |
254 | src/peerstore/gnunet-service-peerstore.c | 255 | src/peerstore/gnunet-service-peerstore.c |
255 | src/peerstore/peerstore_api.c | 256 | src/peerstore/peerstore_api.c |
@@ -295,26 +296,27 @@ src/rest/gnunet-rest-server.c | |||
295 | src/rest/plugin_rest_config.c | 296 | src/rest/plugin_rest_config.c |
296 | src/rest/plugin_rest_copying.c | 297 | src/rest/plugin_rest_copying.c |
297 | src/rest/rest.c | 298 | src/rest/rest.c |
299 | src/revocation/gnunet-revocation-tvg.c | ||
298 | src/revocation/gnunet-revocation.c | 300 | src/revocation/gnunet-revocation.c |
299 | src/revocation/gnunet-service-revocation.c | 301 | src/revocation/gnunet-service-revocation.c |
300 | src/revocation/plugin_block_revocation.c | 302 | src/revocation/plugin_block_revocation.c |
301 | src/revocation/revocation_api.c | 303 | src/revocation/revocation_api.c |
302 | src/rps/gnunet-rps.c | ||
303 | src/rps/gnunet-rps-profiler.c | 304 | src/rps/gnunet-rps-profiler.c |
305 | src/rps/gnunet-rps.c | ||
304 | src/rps/gnunet-service-rps.c | 306 | src/rps/gnunet-service-rps.c |
305 | src/rps/gnunet-service-rps_custommap.c | 307 | src/rps/gnunet-service-rps_custommap.c |
306 | src/rps/gnunet-service-rps_sampler.c | 308 | src/rps/gnunet-service-rps_sampler.c |
307 | src/rps/gnunet-service-rps_sampler_elem.c | 309 | src/rps/gnunet-service-rps_sampler_elem.c |
308 | src/rps/gnunet-service-rps_view.c | 310 | src/rps/gnunet-service-rps_view.c |
309 | src/rps/rps_api.c | ||
310 | src/rps/rps-sampler_client.c | 311 | src/rps/rps-sampler_client.c |
311 | src/rps/rps-sampler_common.c | 312 | src/rps/rps-sampler_common.c |
312 | src/rps/rps-test_util.c | 313 | src/rps/rps-test_util.c |
314 | src/rps/rps_api.c | ||
313 | src/scalarproduct/gnunet-scalarproduct.c | 315 | src/scalarproduct/gnunet-scalarproduct.c |
314 | src/scalarproduct/gnunet-service-scalarproduct_alice.c | ||
315 | src/scalarproduct/gnunet-service-scalarproduct_bob.c | ||
316 | src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | 316 | src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c |
317 | src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | 317 | src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c |
318 | src/scalarproduct/gnunet-service-scalarproduct_alice.c | ||
319 | src/scalarproduct/gnunet-service-scalarproduct_bob.c | ||
318 | src/scalarproduct/scalarproduct_api.c | 320 | src/scalarproduct/scalarproduct_api.c |
319 | src/secretsharing/gnunet-secretsharing-profiler.c | 321 | src/secretsharing/gnunet-secretsharing-profiler.c |
320 | src/secretsharing/gnunet-service-secretsharing.c | 322 | src/secretsharing/gnunet-service-secretsharing.c |
@@ -340,15 +342,16 @@ src/statistics/gnunet-statistics.c | |||
340 | src/statistics/statistics_api.c | 342 | src/statistics/statistics_api.c |
341 | src/template/gnunet-service-template.c | 343 | src/template/gnunet-service-template.c |
342 | src/template/gnunet-template.c | 344 | src/template/gnunet-template.c |
345 | src/testbed-logger/gnunet-service-testbed-logger.c | ||
346 | src/testbed-logger/testbed_logger_api.c | ||
343 | src/testbed/generate-underlay-topology.c | 347 | src/testbed/generate-underlay-topology.c |
344 | src/testbed/gnunet-daemon-latency-logger.c | 348 | src/testbed/gnunet-daemon-latency-logger.c |
345 | src/testbed/gnunet-daemon-testbed-blacklist.c | 349 | src/testbed/gnunet-daemon-testbed-blacklist.c |
346 | src/testbed/gnunet-daemon-testbed-underlay.c | 350 | src/testbed/gnunet-daemon-testbed-underlay.c |
347 | src/testbed/gnunet-helper-testbed.c | 351 | src/testbed/gnunet-helper-testbed.c |
348 | src/testbed/gnunet_mpi_test.c | ||
349 | src/testbed/gnunet-service-test-barriers.c | 352 | src/testbed/gnunet-service-test-barriers.c |
350 | src/testbed/gnunet-service-testbed_barriers.c | ||
351 | src/testbed/gnunet-service-testbed.c | 353 | src/testbed/gnunet-service-testbed.c |
354 | src/testbed/gnunet-service-testbed_barriers.c | ||
352 | src/testbed/gnunet-service-testbed_cache.c | 355 | src/testbed/gnunet-service-testbed_cache.c |
353 | src/testbed/gnunet-service-testbed_connectionpool.c | 356 | src/testbed/gnunet-service-testbed_connectionpool.c |
354 | src/testbed/gnunet-service-testbed_cpustatus.c | 357 | src/testbed/gnunet-service-testbed_cpustatus.c |
@@ -356,20 +359,19 @@ src/testbed/gnunet-service-testbed_links.c | |||
356 | src/testbed/gnunet-service-testbed_meminfo.c | 359 | src/testbed/gnunet-service-testbed_meminfo.c |
357 | src/testbed/gnunet-service-testbed_oc.c | 360 | src/testbed/gnunet-service-testbed_oc.c |
358 | src/testbed/gnunet-service-testbed_peers.c | 361 | src/testbed/gnunet-service-testbed_peers.c |
359 | src/testbed/gnunet_testbed_mpi_spawn.c | ||
360 | src/testbed/gnunet-testbed-profiler.c | 362 | src/testbed/gnunet-testbed-profiler.c |
361 | src/testbed-logger/gnunet-service-testbed-logger.c | 363 | src/testbed/gnunet_mpi_test.c |
362 | src/testbed-logger/testbed_logger_api.c | 364 | src/testbed/gnunet_testbed_mpi_spawn.c |
363 | src/testbed/testbed_api_barriers.c | ||
364 | src/testbed/testbed_api.c | 365 | src/testbed/testbed_api.c |
366 | src/testbed/testbed_api_barriers.c | ||
365 | src/testbed/testbed_api_hosts.c | 367 | src/testbed/testbed_api_hosts.c |
366 | src/testbed/testbed_api_operations.c | 368 | src/testbed/testbed_api_operations.c |
367 | src/testbed/testbed_api_peers.c | 369 | src/testbed/testbed_api_peers.c |
368 | src/testbed/testbed_api_sd.c | 370 | src/testbed/testbed_api_sd.c |
369 | src/testbed/testbed_api_services.c | 371 | src/testbed/testbed_api_services.c |
370 | src/testbed/testbed_api_statistics.c | 372 | src/testbed/testbed_api_statistics.c |
371 | src/testbed/testbed_api_testbed.c | ||
372 | src/testbed/testbed_api_test.c | 373 | src/testbed/testbed_api_test.c |
374 | src/testbed/testbed_api_testbed.c | ||
373 | src/testbed/testbed_api_topology.c | 375 | src/testbed/testbed_api_topology.c |
374 | src/testbed/testbed_api_underlay.c | 376 | src/testbed/testbed_api_underlay.c |
375 | src/testing/gnunet-testing.c | 377 | src/testing/gnunet-testing.c |
@@ -381,34 +383,40 @@ src/transport/gnunet-communicator-tcp.c | |||
381 | src/transport/gnunet-communicator-udp.c | 383 | src/transport/gnunet-communicator-udp.c |
382 | src/transport/gnunet-communicator-unix.c | 384 | src/transport/gnunet-communicator-unix.c |
383 | src/transport/gnunet-helper-transport-bluetooth.c | 385 | src/transport/gnunet-helper-transport-bluetooth.c |
384 | src/transport/gnunet-helper-transport-wlan.c | ||
385 | src/transport/gnunet-helper-transport-wlan-dummy.c | 386 | src/transport/gnunet-helper-transport-wlan-dummy.c |
387 | src/transport/gnunet-helper-transport-wlan.c | ||
386 | src/transport/gnunet-service-tng.c | 388 | src/transport/gnunet-service-tng.c |
387 | src/transport/gnunet-service-transport_ats.c | ||
388 | src/transport/gnunet-service-transport.c | 389 | src/transport/gnunet-service-transport.c |
390 | src/transport/gnunet-service-transport_ats.c | ||
389 | src/transport/gnunet-service-transport_hello.c | 391 | src/transport/gnunet-service-transport_hello.c |
390 | src/transport/gnunet-service-transport_manipulation.c | 392 | src/transport/gnunet-service-transport_manipulation.c |
391 | src/transport/gnunet-service-transport_neighbours.c | 393 | src/transport/gnunet-service-transport_neighbours.c |
392 | src/transport/gnunet-service-transport_plugins.c | 394 | src/transport/gnunet-service-transport_plugins.c |
393 | src/transport/gnunet-service-transport_validation.c | 395 | src/transport/gnunet-service-transport_validation.c |
394 | src/transport/gnunet-transport.c | ||
395 | src/transport/gnunet-transport-profiler.c | 396 | src/transport/gnunet-transport-profiler.c |
396 | src/transport/gnunet-transport-wlan-receiver.c | 397 | src/transport/gnunet-transport-wlan-receiver.c |
397 | src/transport/gnunet-transport-wlan-sender.c | 398 | src/transport/gnunet-transport-wlan-sender.c |
399 | src/transport/gnunet-transport.c | ||
398 | src/transport/plugin_transport_http_client.c | 400 | src/transport/plugin_transport_http_client.c |
399 | src/transport/plugin_transport_http_common.c | 401 | src/transport/plugin_transport_http_common.c |
400 | src/transport/plugin_transport_http_server.c | 402 | src/transport/plugin_transport_http_server.c |
401 | src/transport/plugin_transport_smtp.c | 403 | src/transport/plugin_transport_smtp.c |
402 | src/transport/plugin_transport_tcp.c | 404 | src/transport/plugin_transport_tcp.c |
403 | src/transport/plugin_transport_template.c | 405 | src/transport/plugin_transport_template.c |
404 | src/transport/plugin_transport_udp_broadcasting.c | ||
405 | src/transport/plugin_transport_udp.c | 406 | src/transport/plugin_transport_udp.c |
407 | src/transport/plugin_transport_udp_broadcasting.c | ||
406 | src/transport/plugin_transport_unix.c | 408 | src/transport/plugin_transport_unix.c |
407 | src/transport/plugin_transport_wlan.c | 409 | src/transport/plugin_transport_wlan.c |
408 | src/transport/tcp_connection_legacy.c | 410 | src/transport/tcp_connection_legacy.c |
409 | src/transport/tcp_server_legacy.c | 411 | src/transport/tcp_server_legacy.c |
410 | src/transport/tcp_server_mst_legacy.c | 412 | src/transport/tcp_server_mst_legacy.c |
411 | src/transport/tcp_service_legacy.c | 413 | src/transport/tcp_service_legacy.c |
414 | src/transport/transport-testing-filenames.c | ||
415 | src/transport/transport-testing-loggers.c | ||
416 | src/transport/transport-testing-main.c | ||
417 | src/transport/transport-testing-send.c | ||
418 | src/transport/transport-testing.c | ||
419 | src/transport/transport-testing2.c | ||
412 | src/transport/transport_api2_application.c | 420 | src/transport/transport_api2_application.c |
413 | src/transport/transport_api2_communication.c | 421 | src/transport/transport_api2_communication.c |
414 | src/transport/transport_api2_core.c | 422 | src/transport/transport_api2_core.c |
@@ -421,12 +429,6 @@ src/transport/transport_api_manipulation.c | |||
421 | src/transport/transport_api_monitor_peers.c | 429 | src/transport/transport_api_monitor_peers.c |
422 | src/transport/transport_api_monitor_plugins.c | 430 | src/transport/transport_api_monitor_plugins.c |
423 | src/transport/transport_api_offer_hello.c | 431 | src/transport/transport_api_offer_hello.c |
424 | src/transport/transport-testing2.c | ||
425 | src/transport/transport-testing.c | ||
426 | src/transport/transport-testing-filenames.c | ||
427 | src/transport/transport-testing-loggers.c | ||
428 | src/transport/transport-testing-main.c | ||
429 | src/transport/transport-testing-send.c | ||
430 | src/util/bandwidth.c | 432 | src/util/bandwidth.c |
431 | src/util/benchmark.c | 433 | src/util/benchmark.c |
432 | src/util/bio.c | 434 | src/util/bio.c |
@@ -441,8 +443,8 @@ src/util/consttime_memcmp.c | |||
441 | src/util/container_bloomfilter.c | 443 | src/util/container_bloomfilter.c |
442 | src/util/container_heap.c | 444 | src/util/container_heap.c |
443 | src/util/container_meta_data.c | 445 | src/util/container_meta_data.c |
444 | src/util/container_multihashmap32.c | ||
445 | src/util/container_multihashmap.c | 446 | src/util/container_multihashmap.c |
447 | src/util/container_multihashmap32.c | ||
446 | src/util/container_multipeermap.c | 448 | src/util/container_multipeermap.c |
447 | src/util/container_multishortmap.c | 449 | src/util/container_multishortmap.c |
448 | src/util/container_multiuuidmap.c | 450 | src/util/container_multiuuidmap.c |
@@ -466,8 +468,8 @@ src/util/dnsparser.c | |||
466 | src/util/dnsstub.c | 468 | src/util/dnsstub.c |
467 | src/util/getopt.c | 469 | src/util/getopt.c |
468 | src/util/getopt_helpers.c | 470 | src/util/getopt_helpers.c |
469 | src/util/gnunet-config.c | ||
470 | src/util/gnunet-config-diff.c | 471 | src/util/gnunet-config-diff.c |
472 | src/util/gnunet-config.c | ||
471 | src/util/gnunet-crypto-tvg.c | 473 | src/util/gnunet-crypto-tvg.c |
472 | src/util/gnunet-ecc.c | 474 | src/util/gnunet-ecc.c |
473 | src/util/gnunet-qr.c | 475 | src/util/gnunet-qr.c |
@@ -504,8 +506,8 @@ src/vpn/gnunet-helper-vpn.c | |||
504 | src/vpn/gnunet-service-vpn.c | 506 | src/vpn/gnunet-service-vpn.c |
505 | src/vpn/gnunet-vpn.c | 507 | src/vpn/gnunet-vpn.c |
506 | src/vpn/vpn_api.c | 508 | src/vpn/vpn_api.c |
507 | src/zonemaster/gnunet-service-zonemaster.c | ||
508 | src/zonemaster/gnunet-service-zonemaster-monitor.c | 509 | src/zonemaster/gnunet-service-zonemaster-monitor.c |
510 | src/zonemaster/gnunet-service-zonemaster.c | ||
509 | src/fs/fs_api.h | 511 | src/fs/fs_api.h |
510 | src/testbed/testbed_api.h | 512 | src/testbed/testbed_api.h |
511 | src/testbed/testbed_api_operations.h | 513 | src/testbed/testbed_api_operations.h |
diff --git a/src/Makefile.am b/src/Makefile.am index 4642b6215..446b1aa2a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -17,26 +17,12 @@ if HAVE_ABE | |||
17 | EXP_DIR += \ | 17 | EXP_DIR += \ |
18 | abe | 18 | abe |
19 | endif | 19 | endif |
20 | if HAVE_JSON | ||
21 | EXP_DIR += \ | 20 | EXP_DIR += \ |
22 | auction | 21 | auction |
23 | endif | 22 | endif |
24 | endif | ||
25 | 23 | ||
26 | if HAVE_JSON | 24 | JSON_DIR = json |
27 | if HAVE_MHD | 25 | CURL_DIR = curl |
28 | JSON_DIR = json | ||
29 | endif | ||
30 | endif | ||
31 | if HAVE_MHD | ||
32 | if HAVE_LIBGNURL | ||
33 | CURL_DIR = curl | ||
34 | else | ||
35 | if HAVE_LIBCURL | ||
36 | CURL_DIR = curl | ||
37 | endif | ||
38 | endif | ||
39 | endif | ||
40 | 26 | ||
41 | if BUILD_PULSE_HELPERS | 27 | if BUILD_PULSE_HELPERS |
42 | CONVERSATION_DIR = conversation | 28 | CONVERSATION_DIR = conversation |
@@ -58,9 +44,7 @@ if HAVE_POSTGRESQL | |||
58 | POSTGRES_DIR = pq | 44 | POSTGRES_DIR = pq |
59 | endif | 45 | endif |
60 | 46 | ||
61 | if HAVE_REST | 47 | REST_DIR = rest |
62 | REST_DIR = rest | ||
63 | endif | ||
64 | 48 | ||
65 | 49 | ||
66 | SUBDIRS = \ | 50 | SUBDIRS = \ |
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index 80294a785..80a2d113d 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am | |||
@@ -30,6 +30,7 @@ lib_LTLIBRARIES = \ | |||
30 | 30 | ||
31 | libgnunetcadet_la_SOURCES = \ | 31 | libgnunetcadet_la_SOURCES = \ |
32 | cadet_api.c \ | 32 | cadet_api.c \ |
33 | cadet_api_drop_message.c \ | ||
33 | cadet_api_get_channel.c \ | 34 | cadet_api_get_channel.c \ |
34 | cadet_api_get_path.c \ | 35 | cadet_api_get_path.c \ |
35 | cadet_api_list_peers.c \ | 36 | cadet_api_list_peers.c \ |
@@ -96,6 +97,7 @@ check_PROGRAMS = \ | |||
96 | test_cadet_2_speed_reliable \ | 97 | test_cadet_2_speed_reliable \ |
97 | test_cadet_2_speed_reliable_backwards \ | 98 | test_cadet_2_speed_reliable_backwards \ |
98 | test_cadet_2_reopen \ | 99 | test_cadet_2_reopen \ |
100 | test_cadet_2_destroy \ | ||
99 | test_cadet_5_forward \ | 101 | test_cadet_5_forward \ |
100 | test_cadet_5_signal \ | 102 | test_cadet_5_signal \ |
101 | test_cadet_5_keepalive \ | 103 | test_cadet_5_keepalive \ |
@@ -217,6 +219,9 @@ test_cadet_5_reopen_SOURCES = \ | |||
217 | test_cadet.c | 219 | test_cadet.c |
218 | test_cadet_5_reopen_LDADD = $(ld_cadet_test_lib) | 220 | test_cadet_5_reopen_LDADD = $(ld_cadet_test_lib) |
219 | 221 | ||
222 | test_cadet_2_destroy_SOURCES = \ | ||
223 | test_cadet.c | ||
224 | test_cadet_2_destroy_LDADD = $(ld_cadet_test_lib) | ||
220 | 225 | ||
221 | if ENABLE_TEST_RUN | 226 | if ENABLE_TEST_RUN |
222 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 227 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h index 29400e39f..d17eab1d6 100644 --- a/src/cadet/cadet.h +++ b/src/cadet/cadet.h | |||
@@ -95,7 +95,6 @@ extern "C" { | |||
95 | 95 | ||
96 | GNUNET_NETWORK_STRUCT_BEGIN | 96 | GNUNET_NETWORK_STRUCT_BEGIN |
97 | 97 | ||
98 | |||
99 | /** | 98 | /** |
100 | * Number uniquely identifying a channel of a client. | 99 | * Number uniquely identifying a channel of a client. |
101 | */ | 100 | */ |
@@ -111,6 +110,70 @@ struct GNUNET_CADET_ClientChannelNumber | |||
111 | uint32_t channel_of_client GNUNET_PACKED; | 110 | uint32_t channel_of_client GNUNET_PACKED; |
112 | }; | 111 | }; |
113 | 112 | ||
113 | /** | ||
114 | * Opaque handle to a channel. | ||
115 | */ | ||
116 | struct GNUNET_CADET_Channel | ||
117 | { | ||
118 | |||
119 | /** | ||
120 | * Other end of the channel. | ||
121 | */ | ||
122 | struct GNUNET_PeerIdentity peer; | ||
123 | |||
124 | /** | ||
125 | * Handle to the cadet this channel belongs to | ||
126 | */ | ||
127 | struct GNUNET_CADET_Handle *cadet; | ||
128 | |||
129 | /** | ||
130 | * Channel's port, if incoming. | ||
131 | */ | ||
132 | struct GNUNET_CADET_Port *incoming_port; | ||
133 | |||
134 | /** | ||
135 | * Any data the caller wants to put in here, used for the | ||
136 | * various callbacks (@e disconnects, @e window_changes, handlers). | ||
137 | */ | ||
138 | void *ctx; | ||
139 | |||
140 | /** | ||
141 | * Message Queue for the channel (which we are implementing). | ||
142 | */ | ||
143 | struct GNUNET_MQ_Handle *mq; | ||
144 | |||
145 | /** | ||
146 | * Task to allow mq to send more traffic. | ||
147 | */ | ||
148 | struct GNUNET_SCHEDULER_Task *mq_cont; | ||
149 | |||
150 | /** | ||
151 | * Pending envelope with a message to be transmitted to the | ||
152 | * service as soon as we are allowed to. Should only be | ||
153 | * non-NULL if @e allow_send is 0. | ||
154 | */ | ||
155 | struct GNUNET_MQ_Envelope *pending_env; | ||
156 | |||
157 | /** | ||
158 | * Window change handler. | ||
159 | */ | ||
160 | GNUNET_CADET_WindowSizeEventHandler window_changes; | ||
161 | |||
162 | /** | ||
163 | * Disconnect handler. | ||
164 | */ | ||
165 | GNUNET_CADET_DisconnectEventHandler disconnects; | ||
166 | |||
167 | /** | ||
168 | * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound. | ||
169 | */ | ||
170 | struct GNUNET_CADET_ClientChannelNumber ccn; | ||
171 | |||
172 | /** | ||
173 | * How many messages are we allowed to send to the service right now? | ||
174 | */ | ||
175 | unsigned int allow_send; | ||
176 | }; | ||
114 | 177 | ||
115 | /** | 178 | /** |
116 | * Message for a client to create and destroy channels. | 179 | * Message for a client to create and destroy channels. |
@@ -252,7 +315,29 @@ struct GNUNET_CADET_LocalInfo | |||
252 | struct GNUNET_PeerIdentity peer; | 315 | struct GNUNET_PeerIdentity peer; |
253 | }; | 316 | }; |
254 | 317 | ||
318 | /** | ||
319 | * Message to drop another message of specific type. Used in test context | ||
320 | */ | ||
321 | struct GNUNET_CADET_RequestDropCadetMessage | ||
322 | { | ||
255 | 323 | ||
324 | /** | ||
325 | * Type: #GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE | ||
326 | */ | ||
327 | struct GNUNET_MessageHeader header; | ||
328 | |||
329 | /** | ||
330 | * Type of the message this handler covers, in host byte order. | ||
331 | */ | ||
332 | uint16_t type; | ||
333 | |||
334 | /** | ||
335 | * ID of the channel we want to drop a message for. | ||
336 | */ | ||
337 | struct GNUNET_CADET_ClientChannelNumber ccn; | ||
338 | |||
339 | }; | ||
340 | |||
256 | /** | 341 | /** |
257 | * Message to inform the client about channels in the service. | 342 | * Message to inform the client about channels in the service. |
258 | */ | 343 | */ |
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 68bd4c290..45cb66c1d 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -73,72 +73,6 @@ struct GNUNET_CADET_Handle | |||
73 | struct GNUNET_TIME_Relative reconnect_time; | 73 | struct GNUNET_TIME_Relative reconnect_time; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | |||
77 | /** | ||
78 | * Opaque handle to a channel. | ||
79 | */ | ||
80 | struct GNUNET_CADET_Channel | ||
81 | { | ||
82 | /** | ||
83 | * Other end of the channel. | ||
84 | */ | ||
85 | struct GNUNET_PeerIdentity peer; | ||
86 | |||
87 | /** | ||
88 | * Handle to the cadet this channel belongs to | ||
89 | */ | ||
90 | struct GNUNET_CADET_Handle *cadet; | ||
91 | |||
92 | /** | ||
93 | * Channel's port, if incoming. | ||
94 | */ | ||
95 | struct GNUNET_CADET_Port *incoming_port; | ||
96 | |||
97 | /** | ||
98 | * Any data the caller wants to put in here, used for the | ||
99 | * various callbacks (@e disconnects, @e window_changes, handlers). | ||
100 | */ | ||
101 | void *ctx; | ||
102 | |||
103 | /** | ||
104 | * Message Queue for the channel (which we are implementing). | ||
105 | */ | ||
106 | struct GNUNET_MQ_Handle *mq; | ||
107 | |||
108 | /** | ||
109 | * Task to allow mq to send more traffic. | ||
110 | */ | ||
111 | struct GNUNET_SCHEDULER_Task *mq_cont; | ||
112 | |||
113 | /** | ||
114 | * Pending envelope with a message to be transmitted to the | ||
115 | * service as soon as we are allowed to. Should only be | ||
116 | * non-NULL if @e allow_send is 0. | ||
117 | */ | ||
118 | struct GNUNET_MQ_Envelope *pending_env; | ||
119 | |||
120 | /** | ||
121 | * Window change handler. | ||
122 | */ | ||
123 | GNUNET_CADET_WindowSizeEventHandler window_changes; | ||
124 | |||
125 | /** | ||
126 | * Disconnect handler. | ||
127 | */ | ||
128 | GNUNET_CADET_DisconnectEventHandler disconnects; | ||
129 | |||
130 | /** | ||
131 | * Local ID of the channel, #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound. | ||
132 | */ | ||
133 | struct GNUNET_CADET_ClientChannelNumber ccn; | ||
134 | |||
135 | /** | ||
136 | * How many messages are we allowed to send to the service right now? | ||
137 | */ | ||
138 | unsigned int allow_send; | ||
139 | }; | ||
140 | |||
141 | |||
142 | /** | 76 | /** |
143 | * Opaque handle to a port. | 77 | * Opaque handle to a port. |
144 | */ | 78 | */ |
@@ -995,6 +929,32 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
995 | 929 | ||
996 | 930 | ||
997 | /** | 931 | /** |
932 | * Function to return link to AGPL source upon request. | ||
933 | * | ||
934 | * @param cls closure with the identification of the client | ||
935 | * @param msg AGPL request | ||
936 | */ | ||
937 | static void | ||
938 | return_agpl (void *cls, const struct GNUNET_MessageHeader *msg) | ||
939 | { | ||
940 | struct GNUNET_SERVICE_Client *client = cls; | ||
941 | struct GNUNET_MQ_Handle *mq; | ||
942 | struct GNUNET_MQ_Envelope *env; | ||
943 | struct GNUNET_MessageHeader *res; | ||
944 | size_t slen; | ||
945 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); | ||
946 | |||
947 | (void) msg; | ||
948 | slen = strlen (pd->agpl_url) + 1; | ||
949 | env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen); | ||
950 | memcpy (&res[1], GNUNET_AGPL_URL, slen); | ||
951 | mq = GNUNET_SERVICE_client_get_mq (client); | ||
952 | GNUNET_MQ_send (mq, env); | ||
953 | GNUNET_SERVICE_client_continue (client); | ||
954 | } | ||
955 | |||
956 | |||
957 | /** | ||
998 | * Open a port to receive incomming MQ-based channels. | 958 | * Open a port to receive incomming MQ-based channels. |
999 | * | 959 | * |
1000 | * @param h CADET handle. | 960 | * @param h CADET handle. |
@@ -1016,6 +976,7 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, | |||
1016 | const struct GNUNET_MQ_MessageHandler *handlers) | 976 | const struct GNUNET_MQ_MessageHandler *handlers) |
1017 | { | 977 | { |
1018 | struct GNUNET_CADET_Port *p; | 978 | struct GNUNET_CADET_Port *p; |
979 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); | ||
1019 | 980 | ||
1020 | GNUNET_assert (NULL != connects); | 981 | GNUNET_assert (NULL != connects); |
1021 | GNUNET_assert (NULL != disconnects); | 982 | GNUNET_assert (NULL != disconnects); |
@@ -1039,7 +1000,9 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, | |||
1039 | p->cls = connects_cls; | 1000 | p->cls = connects_cls; |
1040 | p->window_changes = window_changes; | 1001 | p->window_changes = window_changes; |
1041 | p->disconnects = disconnects; | 1002 | p->disconnects = disconnects; |
1042 | p->handlers = GNUNET_MQ_copy_handlers (handlers); | 1003 | p->handlers = (NULL == pd->agpl_url) |
1004 | ? GNUNET_MQ_copy_handlers (handlers) | ||
1005 | : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL); | ||
1043 | 1006 | ||
1044 | GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p)); | 1007 | GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p)); |
1045 | return p; | 1008 | return p; |
diff --git a/src/cadet/cadet_api_drop_message.c b/src/cadet/cadet_api_drop_message.c new file mode 100644 index 000000000..d9f7e003e --- /dev/null +++ b/src/cadet/cadet_api_drop_message.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2011, 2017, 2019 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file cadet/cadet_api_drop_message.c | ||
22 | * @brief cadet api: client implementation of cadet service | ||
23 | * @author t3sserakt | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "cadet.h" | ||
27 | |||
28 | |||
29 | /** | ||
30 | * Drop the next cadet message of a given type.. | ||
31 | * | ||
32 | * @param mq message queue | ||
33 | * @param ccn client channel number. | ||
34 | * @param type of cadet message to be dropped. | ||
35 | */ | ||
36 | void | ||
37 | GNUNET_CADET_drop_message (struct GNUNET_MQ_Handle *mq, | ||
38 | struct GNUNET_CADET_ClientChannelNumber ccn, | ||
39 | uint16_t type) | ||
40 | { | ||
41 | struct GNUNET_CADET_RequestDropCadetMessage *message; | ||
42 | struct GNUNET_MQ_Envelope *env; | ||
43 | |||
44 | env = GNUNET_MQ_msg (message, GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE); | ||
45 | |||
46 | message->ccn = ccn; | ||
47 | message->type = type; | ||
48 | |||
49 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
50 | "Dropping message for channel of type %s (%d)\n", type == GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY ? "GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY" : "UNKNOWN", type); | ||
51 | |||
52 | GNUNET_MQ_send (mq, env); | ||
53 | |||
54 | } | ||
55 | |||
56 | |||
57 | |||
58 | |||
59 | /* end of cadet_api_drop_message.c */ | ||
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h index e3417f8c4..08298e224 100644 --- a/src/cadet/cadet_protocol.h +++ b/src/cadet/cadet_protocol.h | |||
@@ -85,6 +85,24 @@ struct GNUNET_CADET_ConnectionCreateMessage | |||
85 | uint32_t options GNUNET_PACKED; | 85 | uint32_t options GNUNET_PACKED; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * This flag indicates the peer sending the connection create | ||
89 | * meassage likes to trigger a KX handshake. | ||
90 | */ | ||
91 | int has_monotime; | ||
92 | |||
93 | /** | ||
94 | * This monotonic time is set, if a peer likes to trigger a KX, but is not | ||
95 | * the peer that should start the KX. (xrs,t3ss) | ||
96 | */ | ||
97 | struct GNUNET_TIME_AbsoluteNBO monotime; | ||
98 | |||
99 | /** | ||
100 | * We sign the monotime. The receiving peer can check the signature, to verify | ||
101 | * the sending peer. | ||
102 | */ | ||
103 | struct GNUNET_CRYPTO_EddsaSignature monotime_sig; | ||
104 | |||
105 | /** | ||
88 | * ID of the connection | 106 | * ID of the connection |
89 | */ | 107 | */ |
90 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; | 108 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; |
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index ba83fe0fc..03af3d5c0 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c | |||
@@ -580,6 +580,7 @@ handle_channel_create (void *cls, | |||
580 | if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) | 580 | if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) |
581 | { | 581 | { |
582 | /* Channel ID not in allowed range. */ | 582 | /* Channel ID not in allowed range. */ |
583 | LOG (GNUNET_ERROR_TYPE_DEBUG,"Channel ID not in allowed range."); | ||
583 | GNUNET_break (0); | 584 | GNUNET_break (0); |
584 | GNUNET_SERVICE_client_drop (c->client); | 585 | GNUNET_SERVICE_client_drop (c->client); |
585 | return; | 586 | return; |
@@ -589,6 +590,7 @@ handle_channel_create (void *cls, | |||
589 | if (NULL != ch) | 590 | if (NULL != ch) |
590 | { | 591 | { |
591 | /* Channel ID already in use. Not allowed. */ | 592 | /* Channel ID already in use. Not allowed. */ |
593 | LOG (GNUNET_ERROR_TYPE_DEBUG,"Channel ID already in use. Not allowed."); | ||
592 | GNUNET_break (0); | 594 | GNUNET_break (0); |
593 | GNUNET_SERVICE_client_drop (c->client); | 595 | GNUNET_SERVICE_client_drop (c->client); |
594 | return; | 596 | return; |
@@ -1008,6 +1010,26 @@ handle_info_tunnels (void *cls, | |||
1008 | GNUNET_SERVICE_client_continue (c->client); | 1010 | GNUNET_SERVICE_client_continue (c->client); |
1009 | } | 1011 | } |
1010 | 1012 | ||
1013 | /** | ||
1014 | * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE request. | ||
1015 | * | ||
1016 | * @param cls client Identification of the client. | ||
1017 | * @param message The actual message. | ||
1018 | */ | ||
1019 | static void | ||
1020 | handle_drop_message (void *cls, | ||
1021 | const struct GNUNET_CADET_RequestDropCadetMessage *message) | ||
1022 | { | ||
1023 | struct CadetClient *c = cls; | ||
1024 | struct CadetChannel *ch; | ||
1025 | |||
1026 | ch = lookup_channel (c, | ||
1027 | message->ccn); | ||
1028 | |||
1029 | GCCH_assign_type_to_drop(ch, message); | ||
1030 | |||
1031 | GNUNET_SERVICE_client_continue (c->client); | ||
1032 | } | ||
1011 | 1033 | ||
1012 | /** | 1034 | /** |
1013 | * Callback called when a client connects to the service. | 1035 | * Callback called when a client connects to the service. |
@@ -1305,48 +1327,52 @@ run (void *cls, | |||
1305 | * Define "main" method using service macro. | 1327 | * Define "main" method using service macro. |
1306 | */ | 1328 | */ |
1307 | GNUNET_SERVICE_MAIN | 1329 | GNUNET_SERVICE_MAIN |
1308 | ("cadet", | 1330 | ("cadet", |
1309 | GNUNET_SERVICE_OPTION_NONE, | 1331 | GNUNET_SERVICE_OPTION_NONE, |
1310 | &run, | 1332 | &run, |
1311 | &client_connect_cb, | 1333 | &client_connect_cb, |
1312 | &client_disconnect_cb, | 1334 | &client_disconnect_cb, |
1313 | NULL, | 1335 | NULL, |
1314 | GNUNET_MQ_hd_fixed_size (port_open, | 1336 | GNUNET_MQ_hd_fixed_size (port_open, |
1315 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN, | 1337 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN, |
1316 | struct GNUNET_CADET_PortMessage, | 1338 | struct GNUNET_CADET_PortMessage, |
1317 | NULL), | 1339 | NULL), |
1318 | GNUNET_MQ_hd_fixed_size (port_close, | 1340 | GNUNET_MQ_hd_fixed_size (port_close, |
1319 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE, | 1341 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE, |
1320 | struct GNUNET_CADET_PortMessage, | 1342 | struct GNUNET_CADET_PortMessage, |
1321 | NULL), | 1343 | NULL), |
1322 | GNUNET_MQ_hd_fixed_size (channel_create, | 1344 | GNUNET_MQ_hd_fixed_size (channel_create, |
1323 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, | 1345 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, |
1324 | struct GNUNET_CADET_LocalChannelCreateMessage, | 1346 | struct GNUNET_CADET_LocalChannelCreateMessage, |
1325 | NULL), | 1347 | NULL), |
1326 | GNUNET_MQ_hd_fixed_size (channel_destroy, | 1348 | GNUNET_MQ_hd_fixed_size (channel_destroy, |
1327 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, | 1349 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, |
1328 | struct GNUNET_CADET_LocalChannelDestroyMessage, | 1350 | struct GNUNET_CADET_LocalChannelDestroyMessage, |
1329 | NULL), | 1351 | NULL), |
1330 | GNUNET_MQ_hd_var_size (local_data, | 1352 | GNUNET_MQ_hd_var_size (local_data, |
1331 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, | 1353 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, |
1332 | struct GNUNET_CADET_LocalData, | 1354 | struct GNUNET_CADET_LocalData, |
1333 | NULL), | 1355 | NULL), |
1334 | GNUNET_MQ_hd_fixed_size (local_ack, | 1356 | GNUNET_MQ_hd_fixed_size (local_ack, |
1335 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, | 1357 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, |
1336 | struct GNUNET_CADET_LocalAck, | 1358 | struct GNUNET_CADET_LocalAck, |
1337 | NULL), | 1359 | NULL), |
1338 | GNUNET_MQ_hd_fixed_size (get_peers, | 1360 | GNUNET_MQ_hd_fixed_size (get_peers, |
1339 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS, | 1361 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS, |
1340 | struct GNUNET_MessageHeader, | 1362 | struct GNUNET_MessageHeader, |
1341 | NULL), | 1363 | NULL), |
1342 | GNUNET_MQ_hd_fixed_size (show_path, | 1364 | GNUNET_MQ_hd_fixed_size (show_path, |
1343 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH, | 1365 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH, |
1344 | struct GNUNET_CADET_RequestPathInfoMessage, | 1366 | struct GNUNET_CADET_RequestPathInfoMessage, |
1345 | NULL), | 1367 | NULL), |
1346 | GNUNET_MQ_hd_fixed_size (info_tunnels, | 1368 | GNUNET_MQ_hd_fixed_size (info_tunnels, |
1347 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS, | 1369 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS, |
1348 | struct GNUNET_MessageHeader, | 1370 | struct GNUNET_MessageHeader, |
1349 | NULL), | 1371 | NULL), |
1350 | GNUNET_MQ_handler_end ()); | 1372 | GNUNET_MQ_hd_fixed_size (drop_message, |
1373 | GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE, | ||
1374 | struct GNUNET_CADET_RequestDropCadetMessage, | ||
1375 | NULL), | ||
1376 | GNUNET_MQ_handler_end ()); | ||
1351 | 1377 | ||
1352 | /* end of gnunet-service-cadet-new.c */ | 1378 | /* end of gnunet-service-cadet-new.c */ |
diff --git a/src/cadet/gnunet-service-cadet.h b/src/cadet/gnunet-service-cadet.h index 6da0950f1..ff216f8c3 100644 --- a/src/cadet/gnunet-service-cadet.h +++ b/src/cadet/gnunet-service-cadet.h | |||
@@ -325,4 +325,5 @@ const char * | |||
325 | GSC_2s (struct CadetClient *c); | 325 | GSC_2s (struct CadetClient *c); |
326 | 326 | ||
327 | 327 | ||
328 | |||
328 | #endif | 329 | #endif |
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index 5c8103c5e..e6fce562f 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c | |||
@@ -380,8 +380,44 @@ struct CadetChannel | |||
380 | * empty. | 380 | * empty. |
381 | */ | 381 | */ |
382 | int destroy; | 382 | int destroy; |
383 | |||
384 | /** | ||
385 | * Type of message to be droped. See GCT_send. | ||
386 | */ | ||
387 | uint16_t type GNUNET_PACKED; | ||
388 | |||
383 | }; | 389 | }; |
384 | 390 | ||
391 | /** | ||
392 | * Assign type of message to drop. | ||
393 | * @param ch CadetChannel to assign type to drop. | ||
394 | * @param message GNUNET_CADET_RequestDropCadetMessage to get the type from. | ||
395 | */ | ||
396 | void | ||
397 | GCCH_assign_type_to_drop(struct CadetChannel *ch, const struct GNUNET_CADET_RequestDropCadetMessage *message) | ||
398 | { | ||
399 | |||
400 | ch->type = message->type; | ||
401 | |||
402 | } | ||
403 | |||
404 | /** | ||
405 | * Check if type of message is the one to drop. | ||
406 | * @param ch CadetChannel to check for message type to drop. | ||
407 | * @param message GNUNET_MessageHeader to compare the type with. | ||
408 | */ | ||
409 | int | ||
410 | GCCH_is_type_to_drop(struct CadetChannel *ch, const struct GNUNET_MessageHeader *message) | ||
411 | { | ||
412 | |||
413 | if (ch->type == message->type) | ||
414 | { | ||
415 | ch->type = 0; | ||
416 | return GNUNET_YES; | ||
417 | } | ||
418 | else | ||
419 | return GNUNET_NO; | ||
420 | } | ||
385 | 421 | ||
386 | /** | 422 | /** |
387 | * Get the static string for identification of the channel. | 423 | * Get the static string for identification of the channel. |
@@ -594,7 +630,7 @@ send_channel_open (void *cls) | |||
594 | if (NULL != ch->last_control_qe) | 630 | if (NULL != ch->last_control_qe) |
595 | GCT_send_cancel (ch->last_control_qe); | 631 | GCT_send_cancel (ch->last_control_qe); |
596 | ch->last_control_qe = | 632 | ch->last_control_qe = |
597 | GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch); | 633 | GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch, &msgcc.ctn); |
598 | GNUNET_assert (NULL == ch->retry_control_task); | 634 | GNUNET_assert (NULL == ch->retry_control_task); |
599 | } | 635 | } |
600 | 636 | ||
@@ -818,7 +854,7 @@ send_channel_data_ack (struct CadetChannel *ch) | |||
818 | GCCH_2s (ch)); | 854 | GCCH_2s (ch)); |
819 | if (NULL != ch->last_control_qe) | 855 | if (NULL != ch->last_control_qe) |
820 | GCT_send_cancel (ch->last_control_qe); | 856 | GCT_send_cancel (ch->last_control_qe); |
821 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); | 857 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch, &msg.ctn); |
822 | } | 858 | } |
823 | 859 | ||
824 | 860 | ||
@@ -845,7 +881,7 @@ send_open_ack (void *cls) | |||
845 | msg.port = ch->port; | 881 | msg.port = ch->port; |
846 | if (NULL != ch->last_control_qe) | 882 | if (NULL != ch->last_control_qe) |
847 | GCT_send_cancel (ch->last_control_qe); | 883 | GCT_send_cancel (ch->last_control_qe); |
848 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); | 884 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch, &msg.ctn); |
849 | } | 885 | } |
850 | 886 | ||
851 | 887 | ||
@@ -1477,7 +1513,7 @@ retry_transmission (void *cls) | |||
1477 | "Retrying transmission on %s of message %u\n", | 1513 | "Retrying transmission on %s of message %u\n", |
1478 | GCCH_2s (ch), | 1514 | GCCH_2s (ch), |
1479 | (unsigned int) ntohl (crm->data_message->mid.mid)); | 1515 | (unsigned int) ntohl (crm->data_message->mid.mid)); |
1480 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); | 1516 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm, &crm->data_message->ctn); |
1481 | GNUNET_assert (NULL == ch->retry_data_task); | 1517 | GNUNET_assert (NULL == ch->retry_data_task); |
1482 | } | 1518 | } |
1483 | 1519 | ||
@@ -1865,7 +1901,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1865 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1901 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1866 | ch->retry_data_task = NULL; | 1902 | ch->retry_data_task = NULL; |
1867 | } | 1903 | } |
1868 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); | 1904 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm, &crm->data_message->ctn); |
1869 | GNUNET_assert (NULL == ch->retry_data_task); | 1905 | GNUNET_assert (NULL == ch->retry_data_task); |
1870 | return GNUNET_OK; | 1906 | return GNUNET_OK; |
1871 | } | 1907 | } |
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h index 0a6c97329..7a072f128 100644 --- a/src/cadet/gnunet-service-cadet_channel.h +++ b/src/cadet/gnunet-service-cadet_channel.h | |||
@@ -57,6 +57,23 @@ GCCH_hash_port (struct GNUNET_HashCode *h_port, | |||
57 | const struct GNUNET_HashCode *port, | 57 | const struct GNUNET_HashCode *port, |
58 | const struct GNUNET_PeerIdentity *listener); | 58 | const struct GNUNET_PeerIdentity *listener); |
59 | 59 | ||
60 | /** | ||
61 | * Check if type of message is the one to drop. | ||
62 | * @param ch CadetChannel to check for message type to drop. | ||
63 | * @param message GNUNET_MessageHeader to compare the type with. | ||
64 | */ | ||
65 | int | ||
66 | GCCH_is_type_to_drop (struct CadetChannel *ch, const struct | ||
67 | GNUNET_MessageHeader *message); | ||
68 | |||
69 | /** | ||
70 | * Check if type of message is the one to drop. | ||
71 | * @param ch CadetChannel to assign type to drop. | ||
72 | * @param message GNUNET_CADET_RequestDropCadetMessage to get the type from. | ||
73 | */ | ||
74 | void | ||
75 | GCCH_assign_type_to_drop (struct CadetChannel *ch, const struct | ||
76 | GNUNET_CADET_RequestDropCadetMessage *message); | ||
60 | 77 | ||
61 | /** | 78 | /** |
62 | * Get the static string for identification of the channel. | 79 | * Get the static string for identification of the channel. |
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index c07339ebc..a7c1d9fb0 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -26,6 +26,7 @@ | |||
26 | * @author Christian Grothoff | 26 | * @author Christian Grothoff |
27 | */ | 27 | */ |
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_signatures.h" | ||
29 | #include "gnunet-service-cadet_connection.h" | 30 | #include "gnunet-service-cadet_connection.h" |
30 | #include "gnunet-service-cadet_channel.h" | 31 | #include "gnunet-service-cadet_channel.h" |
31 | #include "gnunet-service-cadet_paths.h" | 32 | #include "gnunet-service-cadet_paths.h" |
@@ -78,7 +79,6 @@ enum CadetConnectionState | |||
78 | CADET_CONNECTION_READY | 79 | CADET_CONNECTION_READY |
79 | }; | 80 | }; |
80 | 81 | ||
81 | |||
82 | /** | 82 | /** |
83 | * Low-level connection to a destination. | 83 | * Low-level connection to a destination. |
84 | */ | 84 | */ |
@@ -206,6 +206,14 @@ update_state (struct CadetConnection *cc, | |||
206 | int old_ready; | 206 | int old_ready; |
207 | int new_ready; | 207 | int new_ready; |
208 | 208 | ||
209 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
210 | "Trying to update connection state for %s having old state %d to new %d and mqm_ready old %d to mqm_ready new %d\n", | ||
211 | GCT_2s (cc->ct->t), | ||
212 | cc->state, | ||
213 | new_state, | ||
214 | cc->mqm_ready, | ||
215 | new_mqm_ready); | ||
216 | |||
209 | if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready)) | 217 | if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready)) |
210 | return; /* no change, nothing to do */ | 218 | return; /* no change, nothing to do */ |
211 | old_ready = | 219 | old_ready = |
@@ -214,6 +222,13 @@ update_state (struct CadetConnection *cc, | |||
214 | ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready)); | 222 | ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready)); |
215 | cc->state = new_state; | 223 | cc->state = new_state; |
216 | cc->mqm_ready = new_mqm_ready; | 224 | cc->mqm_ready = new_mqm_ready; |
225 | |||
226 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
227 | "Updating connection state for %s having old_ready %d and new_rady %d\n", | ||
228 | GCT_2s (cc->ct->t), | ||
229 | old_ready, | ||
230 | new_ready); | ||
231 | |||
217 | if (old_ready != new_ready) | 232 | if (old_ready != new_ready) |
218 | cc->ready_cb (cc->ready_cb_cls, new_ready); | 233 | cc->ready_cb (cc->ready_cb_cls, new_ready); |
219 | } | 234 | } |
@@ -392,7 +407,7 @@ send_keepalive (void *cls) | |||
392 | msg.size = htons (sizeof(msg)); | 407 | msg.size = htons (sizeof(msg)); |
393 | msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); | 408 | msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); |
394 | 409 | ||
395 | cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc); | 410 | cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc, NULL); |
396 | } | 411 | } |
397 | 412 | ||
398 | 413 | ||
@@ -581,6 +596,25 @@ GCC_handle_encrypted (struct CadetConnection *cc, | |||
581 | 596 | ||
582 | 597 | ||
583 | /** | 598 | /** |
599 | * Set the signature for a monotime value on a GNUNET_CADET_ConnectionCreateMessage. | ||
600 | * | ||
601 | * @param msg The GNUNET_CADET_ConnectionCreateMessage. | ||
602 | */ | ||
603 | void | ||
604 | set_monotime_sig (struct GNUNET_CADET_ConnectionCreateMessage *msg) | ||
605 | { | ||
606 | |||
607 | struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl ( | ||
608 | GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR), | ||
609 | .purpose.size = htonl (sizeof(cp)), | ||
610 | .monotonic_time = msg->monotime}; | ||
611 | |||
612 | GNUNET_CRYPTO_eddsa_sign (my_private_key, &cp, | ||
613 | &msg->monotime_sig); | ||
614 | |||
615 | } | ||
616 | |||
617 | /** | ||
584 | * Send a #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the | 618 | * Send a #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE message to the |
585 | * first hop. | 619 | * first hop. |
586 | * | 620 | * |
@@ -593,6 +627,7 @@ send_create (void *cls) | |||
593 | struct GNUNET_CADET_ConnectionCreateMessage *create_msg; | 627 | struct GNUNET_CADET_ConnectionCreateMessage *create_msg; |
594 | struct GNUNET_PeerIdentity *pids; | 628 | struct GNUNET_PeerIdentity *pids; |
595 | struct GNUNET_MQ_Envelope *env; | 629 | struct GNUNET_MQ_Envelope *env; |
630 | struct CadetTunnel *t; | ||
596 | 631 | ||
597 | cc->task = NULL; | 632 | cc->task = NULL; |
598 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 633 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); |
@@ -603,6 +638,18 @@ send_create (void *cls) | |||
603 | // TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed. | 638 | // TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed. |
604 | create_msg->options = 2; | 639 | create_msg->options = 2; |
605 | create_msg->cid = cc->cid; | 640 | create_msg->cid = cc->cid; |
641 | |||
642 | // check for tunnel state and set signed monotime (xrs,t3ss) | ||
643 | t = GCP_get_tunnel (cc->destination, GNUNET_YES); | ||
644 | if ((NULL != t)&& (GCT_get_estate (t) == CADET_TUNNEL_KEY_UNINITIALIZED) && | ||
645 | (GCT_alice_or_betty (GCP_get_id (cc->destination)) == GNUNET_NO)) | ||
646 | { | ||
647 | create_msg->has_monotime = GNUNET_YES; | ||
648 | create_msg->monotime = GNUNET_TIME_absolute_hton ( | ||
649 | GNUNET_TIME_absolute_get_monotonic (cfg)); | ||
650 | set_monotime_sig (create_msg); | ||
651 | } | ||
652 | |||
606 | pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; | 653 | pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; |
607 | pids[0] = my_full_id; | 654 | pids[0] = my_full_id; |
608 | for (unsigned int i = 0; i <= cc->off; i++) | 655 | for (unsigned int i = 0; i <= cc->off; i++) |
@@ -792,6 +839,7 @@ connection_create (struct CadetPeer *destination, | |||
792 | cc = GNUNET_new (struct CadetConnection); | 839 | cc = GNUNET_new (struct CadetConnection); |
793 | cc->state = init_state; | 840 | cc->state = init_state; |
794 | cc->ct = ct; | 841 | cc->ct = ct; |
842 | cc->destination = destination; /* xrs,t3ss,lurchi*/ | ||
795 | cc->cid = *cid; | 843 | cc->cid = *cid; |
796 | cc->retry_delay = | 844 | cc->retry_delay = |
797 | GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off); | 845 | GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off); |
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h index b05c3b72c..ed0e909fb 100644 --- a/src/cadet/gnunet-service-cadet_connection.h +++ b/src/cadet/gnunet-service-cadet_connection.h | |||
@@ -183,6 +183,32 @@ GCC_handle_kx_auth (struct CadetConnection *cc, | |||
183 | const struct | 183 | const struct |
184 | GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg); | 184 | GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg); |
185 | 185 | ||
186 | /** | ||
187 | * Purpose for the signature of a monotime. | ||
188 | */ | ||
189 | struct CadetConnectionCreatePS | ||
190 | { | ||
191 | |||
192 | /** | ||
193 | * Purpose is #GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR | ||
194 | */ | ||
195 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
196 | |||
197 | /** | ||
198 | * Time at the initiator when generating the signature. | ||
199 | * | ||
200 | * Note that the receiver MUST IGNORE the absolute time, and only interpret | ||
201 | * the value as a mononic time and reject "older" values than the last one | ||
202 | * observed. This is necessary as we do not want to require synchronized | ||
203 | * clocks and may not have a bidirectional communication channel. | ||
204 | * | ||
205 | * Even with this, there is no real guarantee against replay achieved here, | ||
206 | * unless the latest timestamp is persisted. Persistence should be | ||
207 | * provided via PEERSTORE if possible. | ||
208 | */ | ||
209 | struct GNUNET_TIME_AbsoluteNBO monotonic_time; | ||
210 | |||
211 | }; | ||
186 | 212 | ||
187 | /** | 213 | /** |
188 | * Performance metrics for a connection. | 214 | * Performance metrics for a connection. |
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c index d54022896..04847f906 100644 --- a/src/cadet/gnunet-service-cadet_core.c +++ b/src/cadet/gnunet-service-cadet_core.c | |||
@@ -227,7 +227,6 @@ static unsigned long long cur_buffers; | |||
227 | */ | 227 | */ |
228 | static struct GNUNET_SCHEDULER_Task *timeout_task; | 228 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
229 | 229 | ||
230 | |||
231 | /** | 230 | /** |
232 | * Get the route corresponding to a hash. | 231 | * Get the route corresponding to a hash. |
233 | * | 232 | * |
@@ -724,6 +723,7 @@ handle_connection_create ( | |||
724 | uint16_t size = ntohs (msg->header.size) - sizeof(*msg); | 723 | uint16_t size = ntohs (msg->header.size) - sizeof(*msg); |
725 | unsigned int path_length; | 724 | unsigned int path_length; |
726 | unsigned int off; | 725 | unsigned int off; |
726 | struct CadetTunnel *t; | ||
727 | 727 | ||
728 | path_length = size / sizeof(struct GNUNET_PeerIdentity); | 728 | path_length = size / sizeof(struct GNUNET_PeerIdentity); |
729 | if (0 == path_length) | 729 | if (0 == path_length) |
@@ -822,8 +822,19 @@ handle_connection_create ( | |||
822 | GCP_2s (origin), | 822 | GCP_2s (origin), |
823 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | 823 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
824 | path = GCPP_get_path_from_route (path_length - 1, pids); | 824 | path = GCPP_get_path_from_route (path_length - 1, pids); |
825 | t = GCP_get_tunnel (sender, GNUNET_YES); | ||
826 | |||
827 | // Check for CADET state in case the other side has lost the tunnel (xrs,t3ss) | ||
828 | if ((GNUNET_YES == msg->has_monotime) && | ||
829 | (GNUNET_YES == GCP_check_and_update_monotime(origin, msg->monotime)) && | ||
830 | ( GNUNET_OK == GCP_check_monotime_sig(origin, msg)) && | ||
831 | (CADET_TUNNEL_KEY_OK == GCT_get_estate(t))) | ||
832 | { | ||
833 | GCT_change_estate (t, CADET_TUNNEL_KEY_UNINITIALIZED); | ||
834 | } | ||
835 | |||
825 | if (GNUNET_OK != | 836 | if (GNUNET_OK != |
826 | GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES), | 837 | GCT_add_inbound_connection (t, |
827 | &msg->cid, | 838 | &msg->cid, |
828 | path)) | 839 | path)) |
829 | { | 840 | { |
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index 8258881d0..55800b88c 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * to take a break if we have some connections and have searched a lot (?)) | 31 | * to take a break if we have some connections and have searched a lot (?)) |
32 | */ | 32 | */ |
33 | #include "platform.h" | 33 | #include "platform.h" |
34 | #include "gnunet_time_lib.h" | ||
34 | #include "gnunet_util_lib.h" | 35 | #include "gnunet_util_lib.h" |
35 | #include "gnunet_hello_lib.h" | 36 | #include "gnunet_hello_lib.h" |
36 | #include "gnunet_signatures.h" | 37 | #include "gnunet_signatures.h" |
@@ -38,10 +39,10 @@ | |||
38 | #include "gnunet_ats_service.h" | 39 | #include "gnunet_ats_service.h" |
39 | #include "gnunet_core_service.h" | 40 | #include "gnunet_core_service.h" |
40 | #include "gnunet_statistics_service.h" | 41 | #include "gnunet_statistics_service.h" |
41 | #include "cadet_protocol.h" | 42 | #include "gnunet-service-cadet_peer.h" |
43 | #include "gnunet-service-cadet.h" | ||
42 | #include "gnunet-service-cadet_connection.h" | 44 | #include "gnunet-service-cadet_connection.h" |
43 | #include "gnunet-service-cadet_dht.h" | 45 | #include "gnunet-service-cadet_dht.h" |
44 | #include "gnunet-service-cadet_peer.h" | ||
45 | #include "gnunet-service-cadet_paths.h" | 46 | #include "gnunet-service-cadet_paths.h" |
46 | #include "gnunet-service-cadet_tunnels.h" | 47 | #include "gnunet-service-cadet_tunnels.h" |
47 | 48 | ||
@@ -66,7 +67,6 @@ | |||
66 | */ | 67 | */ |
67 | #define MAX_OOO_QUEUE_SIZE 100 | 68 | #define MAX_OOO_QUEUE_SIZE 100 |
68 | 69 | ||
69 | |||
70 | /** | 70 | /** |
71 | * Data structure used to track whom we have to notify about changes | 71 | * Data structure used to track whom we have to notify about changes |
72 | * to our message queue. | 72 | * to our message queue. |
@@ -118,7 +118,7 @@ struct CadetPeer | |||
118 | /** | 118 | /** |
119 | * Last time we heard from this peer (currently not used!) | 119 | * Last time we heard from this peer (currently not used!) |
120 | */ | 120 | */ |
121 | struct GNUNET_TIME_Absolute last_contactXXX; | 121 | struct GNUNET_TIME_Absolute last_connection_create; |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Array of DLLs of paths traversing the peer, organized by the | 124 | * Array of DLLs of paths traversing the peer, organized by the |
@@ -1552,5 +1552,56 @@ GCP_send_ooo (struct CadetPeer *cp, | |||
1552 | env); | 1552 | env); |
1553 | } | 1553 | } |
1554 | 1554 | ||
1555 | /** | ||
1556 | * Checking if a monotime value is newer than the last monotime value received from a peer. If the time value is newer it will be stored at the peer. | ||
1557 | * | ||
1558 | * @param peer The peer we received a new time value from. | ||
1559 | * @param monotime Time value we check against the last time value we received from a peer. | ||
1560 | * @return GNUNET_YES if monotime is newer than the last received time value, GNUNET_NO if monotime is not newer. | ||
1561 | */ | ||
1562 | int | ||
1563 | GCP_check_and_update_monotime (struct CadetPeer *peer, | ||
1564 | struct GNUNET_TIME_AbsoluteNBO monotime) | ||
1565 | { | ||
1566 | |||
1567 | struct GNUNET_TIME_Absolute mt = GNUNET_TIME_absolute_ntoh (monotime); | ||
1568 | |||
1569 | if (mt.abs_value_us > *(&peer->last_connection_create.abs_value_us)) | ||
1570 | { | ||
1571 | peer->last_connection_create = mt; | ||
1572 | return GNUNET_YES; | ||
1573 | } | ||
1574 | return GNUNET_NO; | ||
1575 | } | ||
1576 | |||
1577 | /** | ||
1578 | * Checking the signature for a monotime of a GNUNET_CADET_ConnectionCreateMessage. | ||
1579 | * | ||
1580 | * @param peer The peer that signed the monotime value. | ||
1581 | * @param msg The GNUNET_CADET_ConnectionCreateMessage with the monotime value. | ||
1582 | * @return GNUNET_OK if the signature is good, GNUNET_SYSERR if not. | ||
1583 | */ | ||
1584 | int | ||
1585 | GCP_check_monotime_sig (struct CadetPeer *peer, | ||
1586 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) | ||
1587 | { | ||
1588 | struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl ( | ||
1589 | GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR), | ||
1590 | .purpose.size = htonl (sizeof(cp)), | ||
1591 | .monotonic_time = msg->monotime}; | ||
1592 | |||
1593 | if (GNUNET_OK != | ||
1594 | GNUNET_CRYPTO_eddsa_verify ( | ||
1595 | GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR, | ||
1596 | &cp, | ||
1597 | &msg->monotime_sig, | ||
1598 | &peer->pid.public_key)) | ||
1599 | { | ||
1600 | GNUNET_break_op (0); | ||
1601 | return GNUNET_SYSERR; | ||
1602 | } | ||
1603 | return GNUNET_OK; | ||
1604 | } | ||
1605 | |||
1555 | 1606 | ||
1556 | /* end of gnunet-service-cadet-new_peer.c */ | 1607 | /* end of gnunet-service-cadet-new_peer.c */ |
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h index bec0606a0..5782b8bff 100644 --- a/src/cadet/gnunet-service-cadet_peer.h +++ b/src/cadet/gnunet-service-cadet_peer.h | |||
@@ -402,5 +402,26 @@ void | |||
402 | GCP_set_mq (struct CadetPeer *cp, | 402 | GCP_set_mq (struct CadetPeer *cp, |
403 | struct GNUNET_MQ_Handle *mq); | 403 | struct GNUNET_MQ_Handle *mq); |
404 | 404 | ||
405 | /** | ||
406 | * Checking the signature for a monotime of a GNUNET_CADET_ConnectionCreateMessage. | ||
407 | * | ||
408 | * @param peer The peer that signed the monotime value. | ||
409 | * @param msg The GNUNET_CADET_ConnectionCreateMessage with the monotime value. | ||
410 | * @return GNUNET_OK if the signature is good, GNUNET_SYSERR if not. | ||
411 | */ | ||
412 | int | ||
413 | GCP_check_monotime_sig (struct CadetPeer *peer, const struct | ||
414 | GNUNET_CADET_ConnectionCreateMessage *msg); | ||
415 | |||
416 | /** | ||
417 | * Checking if a monotime value is newer than the last monotime value received from a peer. If the time value is newer it will be stored at the peer. | ||
418 | * | ||
419 | * @param peer The peer we received a new time value from. | ||
420 | * @param monotime Time value we check against the last time value we received from a peer. | ||
421 | * @return GNUNET_YES if monotime is newer than the last received time value, GNUNET_NO if monotime is not newer. | ||
422 | */ | ||
423 | int | ||
424 | GCP_check_and_update_monotime (struct CadetPeer *peer, | ||
425 | struct GNUNET_TIME_AbsoluteNBO monotime); | ||
405 | 426 | ||
406 | #endif | 427 | #endif |
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c index f1f2ec81f..66e7d5b1e 100644 --- a/src/cadet/gnunet-service-cadet_tunnels.c +++ b/src/cadet/gnunet-service-cadet_tunnels.c | |||
@@ -464,8 +464,8 @@ struct CadetTunnel | |||
464 | * @param other the other peer | 464 | * @param other the other peer |
465 | * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself | 465 | * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself |
466 | */ | 466 | */ |
467 | static int | 467 | int |
468 | alice_or_betty (const struct GNUNET_PeerIdentity *other) | 468 | GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other) |
469 | { | 469 | { |
470 | if (0 > GNUNET_memcmp (&my_full_id, | 470 | if (0 > GNUNET_memcmp (&my_full_id, |
471 | other)) | 471 | other)) |
@@ -1345,7 +1345,7 @@ send_kx (struct CadetTunnel *t, | |||
1345 | struct GNUNET_CADET_TunnelKeyExchangeMessage *msg; | 1345 | struct GNUNET_CADET_TunnelKeyExchangeMessage *msg; |
1346 | enum GNUNET_CADET_KX_Flags flags; | 1346 | enum GNUNET_CADET_KX_Flags flags; |
1347 | 1347 | ||
1348 | if (GNUNET_YES != alice_or_betty (GCP_get_id (t->destination))) | 1348 | if (GNUNET_YES != GCT_alice_or_betty (GCP_get_id (t->destination))) |
1349 | return; /* only Alice may send KX */ | 1349 | return; /* only Alice may send KX */ |
1350 | if ((NULL == ct) || | 1350 | if ((NULL == ct) || |
1351 | (GNUNET_NO == ct->is_ready)) | 1351 | (GNUNET_NO == ct->is_ready)) |
@@ -1521,7 +1521,7 @@ update_ax_by_kx (struct CadetTunnelAxolotl *ax, | |||
1521 | const char salt[] = "CADET Axolotl salt"; | 1521 | const char salt[] = "CADET Axolotl salt"; |
1522 | int am_I_alice; | 1522 | int am_I_alice; |
1523 | 1523 | ||
1524 | if (GNUNET_SYSERR == (am_I_alice = alice_or_betty (pid))) | 1524 | if (GNUNET_SYSERR == (am_I_alice = GCT_alice_or_betty (pid))) |
1525 | { | 1525 | { |
1526 | GNUNET_break_op (0); | 1526 | GNUNET_break_op (0); |
1527 | return GNUNET_SYSERR; | 1527 | return GNUNET_SYSERR; |
@@ -1726,7 +1726,7 @@ GCT_handle_kx (struct CadetTConnection *ct, | |||
1726 | 1, | 1726 | 1, |
1727 | GNUNET_NO); | 1727 | GNUNET_NO); |
1728 | if (GNUNET_YES == | 1728 | if (GNUNET_YES == |
1729 | alice_or_betty (GCP_get_id (t->destination))) | 1729 | GCT_alice_or_betty (GCP_get_id (t->destination))) |
1730 | { | 1730 | { |
1731 | /* Betty/Bob is not allowed to send KX! */ | 1731 | /* Betty/Bob is not allowed to send KX! */ |
1732 | GNUNET_break_op (0); | 1732 | GNUNET_break_op (0); |
@@ -2123,9 +2123,10 @@ GCT_add_channel (struct CadetTunnel *t, | |||
2123 | ch, | 2123 | ch, |
2124 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2124 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
2125 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2125 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2126 | "Adding %s to %s\n", | 2126 | "Adding %s to %s with state %d\n", |
2127 | GCCH_2s (ch), | 2127 | GCCH_2s (ch), |
2128 | GCT_2s (t)); | 2128 | GCT_2s (t), |
2129 | t->estate); | ||
2129 | switch (t->estate) | 2130 | switch (t->estate) |
2130 | { | 2131 | { |
2131 | case CADET_TUNNEL_KEY_UNINITIALIZED: | 2132 | case CADET_TUNNEL_KEY_UNINITIALIZED: |
@@ -2429,12 +2430,21 @@ connection_ready_cb (void *cls, | |||
2429 | switch (t->estate) | 2430 | switch (t->estate) |
2430 | { | 2431 | { |
2431 | case CADET_TUNNEL_KEY_UNINITIALIZED: | 2432 | case CADET_TUNNEL_KEY_UNINITIALIZED: |
2433 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2434 | "Do not begin KX for %s if WE have no channels waiting. Retrying after %d\n", | ||
2435 | GCT_2s (t), | ||
2436 | GNUNET_TIME_absolute_get_remaining (t->next_kx_attempt).rel_value_us); | ||
2432 | /* Do not begin KX if WE have no channels waiting! */ | 2437 | /* Do not begin KX if WE have no channels waiting! */ |
2433 | if (0 != GNUNET_TIME_absolute_get_remaining ( | 2438 | if (0 != GNUNET_TIME_absolute_get_remaining ( |
2434 | t->next_kx_attempt).rel_value_us) | 2439 | t->next_kx_attempt).rel_value_us) |
2435 | return; /* wait for timeout before retrying */ | 2440 | return; /* wait for timeout before retrying */ |
2436 | /* We are uninitialized, just transmit immediately, | 2441 | /* We are uninitialized, just transmit immediately, |
2437 | without undue delay. */ | 2442 | without undue delay. */ |
2443 | |||
2444 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2445 | "Why for %s \n", | ||
2446 | GCT_2s (t)); | ||
2447 | |||
2438 | if (NULL != t->kx_task) | 2448 | if (NULL != t->kx_task) |
2439 | { | 2449 | { |
2440 | GNUNET_SCHEDULER_cancel (t->kx_task); | 2450 | GNUNET_SCHEDULER_cancel (t->kx_task); |
@@ -3028,7 +3038,8 @@ GCT_send_channel_destroy (struct CadetTunnel *t, | |||
3028 | GCT_send (t, | 3038 | GCT_send (t, |
3029 | &msg.header, | 3039 | &msg.header, |
3030 | NULL, | 3040 | NULL, |
3031 | NULL); | 3041 | NULL, |
3042 | &ctn); | ||
3032 | } | 3043 | } |
3033 | 3044 | ||
3034 | 3045 | ||
@@ -3445,18 +3456,32 @@ GCT_handle_encrypted (struct CadetTConnection *ct, | |||
3445 | * @param t Tunnel on which this message is transmitted. | 3456 | * @param t Tunnel on which this message is transmitted. |
3446 | * @param cont Continuation to call once message is really sent. | 3457 | * @param cont Continuation to call once message is really sent. |
3447 | * @param cont_cls Closure for @c cont. | 3458 | * @param cont_cls Closure for @c cont. |
3459 | * @param The ID of the channel we are using for sending. | ||
3448 | * @return Handle to cancel message | 3460 | * @return Handle to cancel message |
3449 | */ | 3461 | */ |
3450 | struct CadetTunnelQueueEntry * | 3462 | struct CadetTunnelQueueEntry * |
3451 | GCT_send (struct CadetTunnel *t, | 3463 | GCT_send (struct CadetTunnel *t, |
3452 | const struct GNUNET_MessageHeader *message, | 3464 | const struct GNUNET_MessageHeader *message, |
3453 | GCT_SendContinuation cont, | 3465 | GCT_SendContinuation cont, |
3454 | void *cont_cls) | 3466 | void *cont_cls, |
3467 | struct GNUNET_CADET_ChannelTunnelNumber *ctn) | ||
3455 | { | 3468 | { |
3456 | struct CadetTunnelQueueEntry *tq; | 3469 | struct CadetTunnelQueueEntry *tq; |
3457 | uint16_t payload_size; | 3470 | uint16_t payload_size; |
3458 | struct GNUNET_MQ_Envelope *env; | 3471 | struct GNUNET_MQ_Envelope *env; |
3459 | struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg; | 3472 | struct GNUNET_CADET_TunnelEncryptedMessage *ax_msg; |
3473 | struct CadetChannel *ch; | ||
3474 | |||
3475 | if (NULL != ctn) | ||
3476 | { | ||
3477 | ch = lookup_channel (t, | ||
3478 | *ctn); | ||
3479 | if ((NULL != ch)&& GCCH_is_type_to_drop (ch, message)) | ||
3480 | { | ||
3481 | GNUNET_break (0); | ||
3482 | return NULL; | ||
3483 | } | ||
3484 | } | ||
3460 | 3485 | ||
3461 | if (CADET_TUNNEL_KEY_OK != t->estate) | 3486 | if (CADET_TUNNEL_KEY_OK != t->estate) |
3462 | { | 3487 | { |
diff --git a/src/cadet/gnunet-service-cadet_tunnels.h b/src/cadet/gnunet-service-cadet_tunnels.h index ef07badea..147f2e56f 100644 --- a/src/cadet/gnunet-service-cadet_tunnels.h +++ b/src/cadet/gnunet-service-cadet_tunnels.h | |||
@@ -80,6 +80,14 @@ enum CadetTunnelEState | |||
80 | CADET_TUNNEL_KEY_OK | 80 | CADET_TUNNEL_KEY_OK |
81 | }; | 81 | }; |
82 | 82 | ||
83 | /** | ||
84 | * Am I Alice or Betty (some call her Bob), or talking to myself? | ||
85 | * | ||
86 | * @param other the other peer | ||
87 | * @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself | ||
88 | */ | ||
89 | int | ||
90 | GCT_alice_or_betty (const struct GNUNET_PeerIdentity *other); | ||
83 | 91 | ||
84 | /** | 92 | /** |
85 | * Get the static string for the peer this tunnel is directed. | 93 | * Get the static string for the peer this tunnel is directed. |
@@ -226,7 +234,8 @@ struct CadetTunnelQueueEntry * | |||
226 | GCT_send (struct CadetTunnel *t, | 234 | GCT_send (struct CadetTunnel *t, |
227 | const struct GNUNET_MessageHeader *message, | 235 | const struct GNUNET_MessageHeader *message, |
228 | GCT_SendContinuation cont, | 236 | GCT_SendContinuation cont, |
229 | void *cont_cls); | 237 | void *cont_cls, |
238 | struct GNUNET_CADET_ChannelTunnelNumber *ctn); | ||
230 | 239 | ||
231 | 240 | ||
232 | /** | 241 | /** |
@@ -320,6 +329,16 @@ GCT_iterate_channels (struct CadetTunnel *t, | |||
320 | enum CadetTunnelEState | 329 | enum CadetTunnelEState |
321 | GCT_get_estate (struct CadetTunnel *t); | 330 | GCT_get_estate (struct CadetTunnel *t); |
322 | 331 | ||
332 | /** | ||
333 | * Change the tunnel encryption state. | ||
334 | * If the encryption state changes to OK, stop the rekey task. | ||
335 | * | ||
336 | * @param t Tunnel whose encryption state to change, or NULL. | ||
337 | * @param state New encryption state. | ||
338 | */ | ||
339 | void | ||
340 | GCT_change_estate (struct CadetTunnel *t, | ||
341 | enum CadetTunnelEState state); | ||
323 | 342 | ||
324 | /** | 343 | /** |
325 | * Handle KX message. | 344 | * Handle KX message. |
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index 25713709c..779d3bc9f 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c | |||
@@ -25,6 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include <stdio.h> | 26 | #include <stdio.h> |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "cadet.h" | ||
28 | #include "cadet_test_lib.h" | 29 | #include "cadet_test_lib.h" |
29 | #include "gnunet_cadet_service.h" | 30 | #include "gnunet_cadet_service.h" |
30 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
@@ -74,6 +75,17 @@ struct CadetTestChannelWrapper | |||
74 | #define SPEED_REL 8 | 75 | #define SPEED_REL 8 |
75 | #define P2P_SIGNAL 10 | 76 | #define P2P_SIGNAL 10 |
76 | #define REOPEN 11 | 77 | #define REOPEN 11 |
78 | #define DESTROY 12 | ||
79 | |||
80 | /** | ||
81 | * Active peer listing operation. | ||
82 | */ | ||
83 | static struct GNUNET_CADET_PeersLister *plo; | ||
84 | |||
85 | /* | ||
86 | * Task called to check for existing tunnel and depending on that reopen channel | ||
87 | */ | ||
88 | static struct GNUNET_SCHEDULER_Task *get_peers_task; | ||
77 | 89 | ||
78 | /** | 90 | /** |
79 | * Which test are we running? | 91 | * Which test are we running? |
@@ -123,7 +135,12 @@ static struct GNUNET_TESTBED_Operation *t_op[2]; | |||
123 | /** | 135 | /** |
124 | * Peer ids. | 136 | * Peer ids. |
125 | */ | 137 | */ |
126 | static struct GNUNET_PeerIdentity *p_id[2]; | 138 | static struct GNUNET_PeerIdentity *testpeer_id[2]; |
139 | |||
140 | /** | ||
141 | * Peer ids. | ||
142 | */ | ||
143 | static struct GNUNET_CONFIGURATION_Handle *p_cfg[2]; | ||
127 | 144 | ||
128 | /** | 145 | /** |
129 | * Port ID | 146 | * Port ID |
@@ -133,7 +150,7 @@ static struct GNUNET_HashCode port; | |||
133 | /** | 150 | /** |
134 | * Peer ids counter. | 151 | * Peer ids counter. |
135 | */ | 152 | */ |
136 | static unsigned int p_ids; | 153 | static unsigned int peerinfo_task_cnt; |
137 | 154 | ||
138 | /** | 155 | /** |
139 | * Is the setup initialized? | 156 | * Is the setup initialized? |
@@ -196,16 +213,6 @@ static struct GNUNET_SCHEDULER_Task *test_task; | |||
196 | static struct GNUNET_SCHEDULER_Task *send_next_msg_task; | 213 | static struct GNUNET_SCHEDULER_Task *send_next_msg_task; |
197 | 214 | ||
198 | /** | 215 | /** |
199 | * Cadet handle for the root peer | ||
200 | */ | ||
201 | static struct GNUNET_CADET_Handle *h1; | ||
202 | |||
203 | /** | ||
204 | * Cadet handle for the first leaf peer | ||
205 | */ | ||
206 | static struct GNUNET_CADET_Handle *h2; | ||
207 | |||
208 | /** | ||
209 | * Channel handle for the root peer | 216 | * Channel handle for the root peer |
210 | */ | 217 | */ |
211 | static struct GNUNET_CADET_Channel *outgoing_ch; | 218 | static struct GNUNET_CADET_Channel *outgoing_ch; |
@@ -226,6 +233,9 @@ static struct GNUNET_TIME_Absolute start_time; | |||
226 | */ | 233 | */ |
227 | static struct GNUNET_TESTBED_Peer **testbed_peers; | 234 | static struct GNUNET_TESTBED_Peer **testbed_peers; |
228 | 235 | ||
236 | |||
237 | struct GNUNET_CADET_Handle **cadets_running; | ||
238 | |||
229 | /** | 239 | /** |
230 | * Statistics operation handle. | 240 | * Statistics operation handle. |
231 | */ | 241 | */ |
@@ -246,6 +256,17 @@ static unsigned int ka_received; | |||
246 | */ | 256 | */ |
247 | static unsigned int msg_dropped; | 257 | static unsigned int msg_dropped; |
248 | 258 | ||
259 | /** | ||
260 | * Drop the next cadet message of a given type.. | ||
261 | * | ||
262 | * @param mq message queue | ||
263 | * @param ccn client channel number. | ||
264 | * @param type of cadet message to be dropped. | ||
265 | */ | ||
266 | void | ||
267 | GNUNET_CADET_drop_message (struct GNUNET_MQ_Handle *mq, | ||
268 | struct GNUNET_CADET_ClientChannelNumber ccn, | ||
269 | uint16_t type); | ||
249 | 270 | ||
250 | /******************************************************************************/ | 271 | /******************************************************************************/ |
251 | 272 | ||
@@ -516,6 +537,49 @@ static void | |||
516 | disconnect_handler (void *cls, | 537 | disconnect_handler (void *cls, |
517 | const struct GNUNET_CADET_Channel *channel); | 538 | const struct GNUNET_CADET_Channel *channel); |
518 | 539 | ||
540 | static struct GNUNET_PeerIdentity * | ||
541 | get_from_p_ids () | ||
542 | { | ||
543 | if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1])) | ||
544 | { | ||
545 | return testpeer_id[1]; | ||
546 | } | ||
547 | else | ||
548 | { | ||
549 | return testpeer_id[0]; | ||
550 | } | ||
551 | } | ||
552 | |||
553 | static struct GNUNET_CADET_Handle * | ||
554 | get_from_cadets () | ||
555 | { | ||
556 | |||
557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "1\n"); | ||
558 | if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1])) | ||
559 | { | ||
560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "standard peer\n"); | ||
561 | return cadets_running[0]; | ||
562 | } | ||
563 | else | ||
564 | { | ||
565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "the other peer\n"); | ||
566 | return cadets_running[peers_running - 1]; | ||
567 | } | ||
568 | |||
569 | } | ||
570 | |||
571 | static unsigned int | ||
572 | get_peer_nr (int outgoing) | ||
573 | { | ||
574 | if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1])) | ||
575 | { | ||
576 | return GNUNET_YES == outgoing ? 0 : peers_running - 1; | ||
577 | } | ||
578 | else | ||
579 | { | ||
580 | return GNUNET_YES == outgoing ? peers_running - 1 : 0; | ||
581 | } | ||
582 | } | ||
519 | 583 | ||
520 | /** | 584 | /** |
521 | * Task to reconnect to other peer. | 585 | * Task to reconnect to other peer. |
@@ -534,6 +598,8 @@ reconnect_op (void *cls) | |||
534 | }; | 598 | }; |
535 | long l = (long) cls; | 599 | long l = (long) cls; |
536 | struct CadetTestChannelWrapper *ch; | 600 | struct CadetTestChannelWrapper *ch; |
601 | static struct GNUNET_PeerIdentity *p_id; | ||
602 | static struct GNUNET_CADET_Handle *h1; | ||
537 | 603 | ||
538 | reconnect_task = NULL; | 604 | reconnect_task = NULL; |
539 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 605 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -545,17 +611,127 @@ reconnect_op (void *cls) | |||
545 | outgoing_ch = NULL; | 611 | outgoing_ch = NULL; |
546 | } | 612 | } |
547 | ch = GNUNET_new (struct CadetTestChannelWrapper); | 613 | ch = GNUNET_new (struct CadetTestChannelWrapper); |
614 | |||
615 | p_id = get_from_p_ids (); | ||
616 | h1 = get_from_cadets (); | ||
617 | |||
618 | outgoing_ch = GNUNET_CADET_channel_create (h1, | ||
619 | ch, | ||
620 | p_id, | ||
621 | &port, | ||
622 | NULL, | ||
623 | &disconnect_handler, | ||
624 | handlers); | ||
625 | ch->ch = outgoing_ch; | ||
626 | send_test_message (outgoing_ch); | ||
627 | } | ||
628 | |||
629 | void | ||
630 | reopen_channel () | ||
631 | { | ||
632 | struct CadetTestChannelWrapper *ch; | ||
633 | static struct GNUNET_CADET_Handle *h1; | ||
634 | static struct GNUNET_PeerIdentity *p_id; | ||
635 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
636 | GNUNET_MQ_hd_var_size (data, | ||
637 | GNUNET_MESSAGE_TYPE_DUMMY, | ||
638 | struct GNUNET_MessageHeader, | ||
639 | NULL), | ||
640 | GNUNET_MQ_handler_end () | ||
641 | }; | ||
642 | |||
643 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "creating channel again\n"); | ||
644 | p_id = get_from_p_ids (); | ||
645 | h1 = get_from_cadets (); | ||
646 | |||
647 | ch = GNUNET_new (struct CadetTestChannelWrapper); | ||
548 | outgoing_ch = GNUNET_CADET_channel_create (h1, | 648 | outgoing_ch = GNUNET_CADET_channel_create (h1, |
549 | ch, | 649 | ch, |
550 | p_id[1], | 650 | p_id, |
551 | &port, | 651 | &port, |
552 | NULL, | 652 | NULL, |
553 | &disconnect_handler, | 653 | &disconnect_handler, |
554 | handlers); | 654 | handlers); |
555 | ch->ch = outgoing_ch; | 655 | ch->ch = outgoing_ch; |
656 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
657 | "Sending second test data (after destroying the channel) on channel %p...\n", | ||
658 | outgoing_ch); | ||
556 | send_test_message (outgoing_ch); | 659 | send_test_message (outgoing_ch); |
557 | } | 660 | } |
558 | 661 | ||
662 | static void | ||
663 | peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple); | ||
664 | |||
665 | /** | ||
666 | * We ask the monitoring api for all the peers. | ||
667 | */ | ||
668 | static void | ||
669 | get_peers (void *cls) | ||
670 | { | ||
671 | |||
672 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
673 | "requesting peers info!\n"); | ||
674 | plo = GNUNET_CADET_list_peers (p_cfg[get_peer_nr (GNUNET_YES)], | ||
675 | &peers_callback, NULL); | ||
676 | |||
677 | } | ||
678 | |||
679 | /** | ||
680 | * Method called to retrieve information about all peers in CADET, called | ||
681 | * once per peer. | ||
682 | * | ||
683 | * After last peer has been reported, an additional call with NULL is done. | ||
684 | * | ||
685 | * We check the peer we are interested in, if we have a tunnel. If not, we | ||
686 | * reopen the channel | ||
687 | * | ||
688 | * @param cls Closure. | ||
689 | * @param ple information about peer, or NULL on "EOF". | ||
690 | */ | ||
691 | static void | ||
692 | peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple) | ||
693 | { | ||
694 | |||
695 | const struct GNUNET_PeerIdentity *p_id; | ||
696 | const struct GNUNET_PeerIdentity *peer; | ||
697 | |||
698 | |||
699 | peer = &ple->peer; | ||
700 | |||
701 | if (NULL == ple) | ||
702 | { | ||
703 | plo = NULL; | ||
704 | return; | ||
705 | } | ||
706 | p_id = get_from_p_ids (); | ||
707 | |||
708 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
709 | "ple->peer %s\n", | ||
710 | GNUNET_i2s_full (&ple->peer)); | ||
711 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
712 | "p_id %s\n", | ||
713 | GNUNET_i2s_full (p_id)); | ||
714 | |||
715 | if ((0 == GNUNET_memcmp (&ple->peer, p_id))&& ple->have_tunnel) | ||
716 | { | ||
717 | |||
718 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
719 | "schedule get_peers again?\n"); | ||
720 | get_peers_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | ||
721 | &get_peers, | ||
722 | NULL); | ||
723 | |||
724 | } | ||
725 | else if (0 == GNUNET_memcmp (&ple->peer, p_id) ) | ||
726 | { | ||
727 | |||
728 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
729 | "reopen channel\n"); | ||
730 | |||
731 | reopen_channel (); | ||
732 | |||
733 | } | ||
734 | } | ||
559 | 735 | ||
560 | /** | 736 | /** |
561 | * Function called whenever an MQ-channel is destroyed, unless the destruction | 737 | * Function called whenever an MQ-channel is destroyed, unless the destruction |
@@ -575,9 +751,22 @@ disconnect_handler (void *cls, | |||
575 | struct CadetTestChannelWrapper *ch_w = cls; | 751 | struct CadetTestChannelWrapper *ch_w = cls; |
576 | 752 | ||
577 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 753 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
578 | "Channel disconnected at %d\n", | 754 | "Channel disconnected at ok=%d\n", |
579 | ok); | 755 | ok); |
580 | GNUNET_assert (ch_w->ch == channel); | 756 | GNUNET_assert (ch_w->ch == channel); |
757 | |||
758 | if ((DESTROY == test) && (3 == ok)) | ||
759 | { | ||
760 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
761 | "Reopen channel task!\n"); | ||
762 | if (NULL == get_peers_task) | ||
763 | { | ||
764 | get_peers_task = GNUNET_SCHEDULER_add_now (&get_peers, | ||
765 | NULL); | ||
766 | } | ||
767 | return; | ||
768 | } | ||
769 | |||
581 | if (channel == incoming_ch) | 770 | if (channel == incoming_ch) |
582 | { | 771 | { |
583 | ok++; | 772 | ok++; |
@@ -651,8 +840,8 @@ send_test_message (struct GNUNET_CADET_Channel *channel) | |||
651 | int size; | 840 | int size; |
652 | 841 | ||
653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 842 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
654 | "Sending test message on channel %p\n", | 843 | "Sending test message on channel %u\n", |
655 | channel); | 844 | channel->ccn.channel_of_client); |
656 | size = size_payload; | 845 | size = size_payload; |
657 | if (GNUNET_NO == initialized) | 846 | if (GNUNET_NO == initialized) |
658 | { | 847 | { |
@@ -699,6 +888,10 @@ send_test_message (struct GNUNET_CADET_Channel *channel) | |||
699 | "Sending DATA %u [%d bytes]\n", | 888 | "Sending DATA %u [%d bytes]\n", |
700 | data_sent, size); | 889 | data_sent, size); |
701 | } | 890 | } |
891 | else if (DESTROY == test) | ||
892 | { | ||
893 | payload = data_sent; | ||
894 | } | ||
702 | else | 895 | else |
703 | { | 896 | { |
704 | GNUNET_assert (0); | 897 | GNUNET_assert (0); |
@@ -826,7 +1019,7 @@ handle_data (void *cls, | |||
826 | } | 1019 | } |
827 | 1020 | ||
828 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1021 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
829 | " ok: (%d/%d)\n", | 1022 | "handle_data ok: (%d/%d)\n", |
830 | ok, | 1023 | ok, |
831 | ok_goal); | 1024 | ok_goal); |
832 | data = (uint32_t *) &message[1]; | 1025 | data = (uint32_t *) &message[1]; |
@@ -844,6 +1037,49 @@ handle_data (void *cls, | |||
844 | payload, *counter); | 1037 | payload, *counter); |
845 | } | 1038 | } |
846 | 1039 | ||
1040 | if (DESTROY == test) | ||
1041 | { | ||
1042 | if (2 == ok) | ||
1043 | { | ||
1044 | ok++; | ||
1045 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1046 | "dropping message ok: (%d/%d)\n", | ||
1047 | ok, | ||
1048 | ok_goal); | ||
1049 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1050 | "TEST ID 0: %s\n", | ||
1051 | GNUNET_i2s (testpeer_id[0])); | ||
1052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1053 | "TEST ID 1: %s\n", | ||
1054 | GNUNET_i2s (testpeer_id[1])); | ||
1055 | |||
1056 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "dropping message\n"); | ||
1057 | GNUNET_CADET_drop_message (GNUNET_CADET_get_mq (outgoing_ch), | ||
1058 | outgoing_ch->ccn, | ||
1059 | GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); | ||
1060 | if (NULL != outgoing_ch) | ||
1061 | { | ||
1062 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1063 | "Destroying channel %p...\n", | ||
1064 | outgoing_ch); | ||
1065 | GNUNET_CADET_channel_destroy (outgoing_ch); | ||
1066 | outgoing_ch = NULL; | ||
1067 | } | ||
1068 | } | ||
1069 | else if (5 == ok) | ||
1070 | { | ||
1071 | ok++; | ||
1072 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1073 | "destroy test finished ok: (%d/%d)\n", | ||
1074 | ok, | ||
1075 | ok_goal); | ||
1076 | disconnect_task = | ||
1077 | GNUNET_SCHEDULER_add_now (&gather_stats_and_exit, | ||
1078 | (void *) __LINE__); | ||
1079 | // End of DESTROY test. | ||
1080 | } | ||
1081 | } | ||
1082 | |||
847 | if (GNUNET_NO == initialized) | 1083 | if (GNUNET_NO == initialized) |
848 | { | 1084 | { |
849 | initialized = GNUNET_YES; | 1085 | initialized = GNUNET_YES; |
@@ -861,7 +1097,7 @@ handle_data (void *cls, | |||
861 | if (get_target_channel () == channel) /* Got "data" */ | 1097 | if (get_target_channel () == channel) /* Got "data" */ |
862 | { | 1098 | { |
863 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received); | 1099 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received); |
864 | if ((SPEED != test) || ( (ok_goal - 2) == ok) ) | 1100 | if ((DESTROY != test) && ((SPEED != test) || ( (ok_goal - 2) == ok)) ) |
865 | { | 1101 | { |
866 | /* Send ACK */ | 1102 | /* Send ACK */ |
867 | send_test_message (channel); | 1103 | send_test_message (channel); |
@@ -927,11 +1163,13 @@ connect_handler (void *cls, | |||
927 | channel); | 1163 | channel); |
928 | ok++; | 1164 | ok++; |
929 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1165 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
930 | " ok: %d\n", | 1166 | "connect_handler ok: (%d/%d)\n", |
931 | ok); | 1167 | ok, |
932 | if (peer == peers_requested - 1) | 1168 | ok_goal); |
1169 | |||
1170 | if (peer == get_peer_nr (GNUNET_NO)) | ||
933 | { | 1171 | { |
934 | if (NULL != incoming_ch) | 1172 | if ((DESTROY != test)&&(NULL != incoming_ch)) |
935 | { | 1173 | { |
936 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1174 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
937 | "Duplicate incoming channel for client %lu\n", | 1175 | "Duplicate incoming channel for client %lu\n", |
@@ -947,7 +1185,7 @@ connect_handler (void *cls, | |||
947 | (long) cls); | 1185 | (long) cls); |
948 | GNUNET_assert (0); | 1186 | GNUNET_assert (0); |
949 | } | 1187 | } |
950 | if ((NULL != disconnect_task) && (REOPEN != test)) | 1188 | if ((NULL != disconnect_task) && (REOPEN != test) && (DESTROY != test)) |
951 | { | 1189 | { |
952 | GNUNET_SCHEDULER_cancel (disconnect_task); | 1190 | GNUNET_SCHEDULER_cancel (disconnect_task); |
953 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, | 1191 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
@@ -971,6 +1209,7 @@ connect_handler (void *cls, | |||
971 | (void *) __LINE__); | 1209 | (void *) __LINE__); |
972 | } | 1210 | } |
973 | 1211 | ||
1212 | |||
974 | /* TODO: cannot return channel as-is, in order to unify the data handlers */ | 1213 | /* TODO: cannot return channel as-is, in order to unify the data handlers */ |
975 | ch = GNUNET_new (struct CadetTestChannelWrapper); | 1214 | ch = GNUNET_new (struct CadetTestChannelWrapper); |
976 | ch->ch = channel; | 1215 | ch->ch = channel; |
@@ -998,6 +1237,8 @@ start_test (void *cls) | |||
998 | GNUNET_MQ_handler_end () | 1237 | GNUNET_MQ_handler_end () |
999 | }; | 1238 | }; |
1000 | struct CadetTestChannelWrapper *ch; | 1239 | struct CadetTestChannelWrapper *ch; |
1240 | static struct GNUNET_CADET_Handle *h1; | ||
1241 | static struct GNUNET_PeerIdentity *p_id; | ||
1001 | 1242 | ||
1002 | test_task = NULL; | 1243 | test_task = NULL; |
1003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name); | 1244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name); |
@@ -1012,20 +1253,25 @@ start_test (void *cls) | |||
1012 | test = SPEED; | 1253 | test = SPEED; |
1013 | } | 1254 | } |
1014 | 1255 | ||
1256 | p_id = get_from_p_ids (); | ||
1257 | h1 = get_from_cadets (); | ||
1258 | |||
1015 | ch = GNUNET_new (struct CadetTestChannelWrapper); | 1259 | ch = GNUNET_new (struct CadetTestChannelWrapper); |
1016 | outgoing_ch = GNUNET_CADET_channel_create (h1, | 1260 | outgoing_ch = GNUNET_CADET_channel_create (h1, |
1017 | ch, | 1261 | ch, |
1018 | p_id[1], | 1262 | p_id, |
1019 | &port, | 1263 | &port, |
1020 | NULL, | 1264 | NULL, |
1021 | &disconnect_handler, | 1265 | &disconnect_handler, |
1022 | handlers); | 1266 | handlers); |
1267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel created\n"); | ||
1023 | 1268 | ||
1024 | ch->ch = outgoing_ch; | 1269 | ch->ch = outgoing_ch; |
1025 | 1270 | ||
1026 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, | 1271 | if (DESTROY != test) |
1027 | &gather_stats_and_exit, | 1272 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
1028 | (void *) __LINE__); | 1273 | &gather_stats_and_exit, |
1274 | (void *) __LINE__); | ||
1029 | if (KEEPALIVE == test) | 1275 | if (KEEPALIVE == test) |
1030 | return; /* Don't send any data. */ | 1276 | return; /* Don't send any data. */ |
1031 | 1277 | ||
@@ -1054,7 +1300,7 @@ start_test (void *cls) | |||
1054 | /** | 1300 | /** |
1055 | * Callback to be called when the requested peer information is available | 1301 | * Callback to be called when the requested peer information is available |
1056 | * | 1302 | * |
1057 | * @param cls the closure from GNUNET_TESTBED_peer_get_information() | 1303 | * @param cls the closure from GNUNET_TESTBED_peer_getinformation() |
1058 | * @param op the operation this callback corresponds to | 1304 | * @param op the operation this callback corresponds to |
1059 | * @param pinfo the result; will be NULL if the operation has failed | 1305 | * @param pinfo the result; will be NULL if the operation has failed |
1060 | * @param emsg error message if the operation has failed; | 1306 | * @param emsg error message if the operation has failed; |
@@ -1068,9 +1314,6 @@ pi_cb (void *cls, | |||
1068 | { | 1314 | { |
1069 | long i = (long) cls; | 1315 | long i = (long) cls; |
1070 | 1316 | ||
1071 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1072 | "ID callback for %ld\n", | ||
1073 | i); | ||
1074 | if ((NULL == pinfo) || | 1317 | if ((NULL == pinfo) || |
1075 | (NULL != emsg)) | 1318 | (NULL != emsg)) |
1076 | { | 1319 | { |
@@ -1080,15 +1323,40 @@ pi_cb (void *cls, | |||
1080 | abort_test (__LINE__); | 1323 | abort_test (__LINE__); |
1081 | return; | 1324 | return; |
1082 | } | 1325 | } |
1083 | p_id[i] = pinfo->result.id; | 1326 | |
1084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1327 | if (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit) |
1085 | "id: %s\n", | 1328 | { |
1086 | GNUNET_i2s (p_id[i])); | 1329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1087 | p_ids++; | 1330 | "ID callback for %ld\n", |
1088 | if (p_ids < 2) | 1331 | i); |
1332 | testpeer_id[i] = pinfo->result.id; | ||
1333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1334 | "id: %s\n", | ||
1335 | GNUNET_i2s (testpeer_id[i])); | ||
1336 | } | ||
1337 | else if (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit) | ||
1338 | { | ||
1339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1340 | "CFG callback for %ld\n", | ||
1341 | i); | ||
1342 | p_cfg[i] = pinfo->result.cfg; | ||
1343 | } | ||
1344 | else | ||
1345 | { | ||
1346 | GNUNET_break (0); | ||
1347 | } | ||
1348 | |||
1349 | peerinfo_task_cnt++; | ||
1350 | if (peerinfo_task_cnt < 4) | ||
1089 | return; | 1351 | return; |
1090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1091 | "Got all IDs, starting test\n"); | 1353 | "Got all peer information, starting test\n"); |
1354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1355 | "TEST ID 0: %s\n", | ||
1356 | GNUNET_i2s (testpeer_id[0])); | ||
1357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1358 | "TEST ID 1: %s\n", | ||
1359 | GNUNET_i2s (testpeer_id[1])); | ||
1092 | test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL); | 1360 | test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL); |
1093 | } | 1361 | } |
1094 | 1362 | ||
@@ -1115,8 +1383,8 @@ tmain (void *cls, | |||
1115 | peers_running = num_peers; | 1383 | peers_running = num_peers; |
1116 | GNUNET_assert (peers_running == peers_requested); | 1384 | GNUNET_assert (peers_running == peers_requested); |
1117 | testbed_peers = peers; | 1385 | testbed_peers = peers; |
1118 | h1 = cadets[0]; | 1386 | cadets_running = cadets; |
1119 | h2 = cadets[num_peers - 1]; | 1387 | |
1120 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, | 1388 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
1121 | &disconnect_cadet_peers, | 1389 | &disconnect_cadet_peers, |
1122 | (void *) __LINE__); | 1390 | (void *) __LINE__); |
@@ -1130,6 +1398,14 @@ tmain (void *cls, | |||
1130 | GNUNET_TESTBED_PIT_IDENTITY, | 1398 | GNUNET_TESTBED_PIT_IDENTITY, |
1131 | &pi_cb, | 1399 | &pi_cb, |
1132 | (void *) 1L); | 1400 | (void *) 1L); |
1401 | t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0], | ||
1402 | GNUNET_TESTBED_PIT_CONFIGURATION, | ||
1403 | &pi_cb, | ||
1404 | (void *) 0L); | ||
1405 | t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1], | ||
1406 | GNUNET_TESTBED_PIT_CONFIGURATION, | ||
1407 | &pi_cb, | ||
1408 | (void *) 1L); | ||
1133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n"); | 1409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n"); |
1134 | } | 1410 | } |
1135 | 1411 | ||
@@ -1272,6 +1548,13 @@ main (int argc, char *argv[]) | |||
1272 | // */ | 1548 | // */ |
1273 | ok_goal = 6; | 1549 | ok_goal = 6; |
1274 | } | 1550 | } |
1551 | else if (strstr (argv[0], "_destroy") != NULL) | ||
1552 | { | ||
1553 | test = DESTROY; | ||
1554 | test_name = "destroy"; | ||
1555 | ok_goal = 6; | ||
1556 | short_time = GNUNET_TIME_relative_multiply (short_time, 5); | ||
1557 | } | ||
1275 | else | 1558 | else |
1276 | { | 1559 | { |
1277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); | 1560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); |
@@ -1286,7 +1569,7 @@ main (int argc, char *argv[]) | |||
1286 | GNUNET_asprintf (&test_name, "backwards %s", test_name); | 1569 | GNUNET_asprintf (&test_name, "backwards %s", test_name); |
1287 | } | 1570 | } |
1288 | 1571 | ||
1289 | p_ids = 0; | 1572 | peerinfo_task_cnt = 0; |
1290 | ports[0] = &port; | 1573 | ports[0] = &port; |
1291 | ports[1] = NULL; | 1574 | ports[1] = NULL; |
1292 | GNUNET_CADET_TEST_ruN ("test_cadet_small", | 1575 | GNUNET_CADET_TEST_ruN ("test_cadet_small", |
diff --git a/src/cadet/test_cadet.conf b/src/cadet/test_cadet.conf index 30e496aff..067dd5fb4 100644 --- a/src/cadet/test_cadet.conf +++ b/src/cadet/test_cadet.conf | |||
@@ -27,7 +27,8 @@ QUOTA = 1 MB | |||
27 | DATABASE = heap | 27 | DATABASE = heap |
28 | 28 | ||
29 | [transport] | 29 | [transport] |
30 | PLUGINS = udp | 30 | #PLUGINS = udp |
31 | PLUGINS = tcp | ||
31 | NEIGHBOUR_LIMIT = 50 | 32 | NEIGHBOUR_LIMIT = 50 |
32 | #MANIPULATE_DELAY_IN = 10 ms | 33 | #MANIPULATE_DELAY_IN = 10 ms |
33 | #MANIPULATE_DELAY_OUT = 10 ms | 34 | #MANIPULATE_DELAY_OUT = 10 ms |
@@ -102,3 +103,7 @@ START_ON_DEMAND = NO | |||
102 | [rps] | 103 | [rps] |
103 | IMMEDIATE_START = NO | 104 | IMMEDIATE_START = NO |
104 | START_ON_DEMAND = NO | 105 | START_ON_DEMAND = NO |
106 | |||
107 | [rest] | ||
108 | IMMEDIATE_START = NO | ||
109 | START_ON_DEMAND = NO | ||
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c index 2b717367a..dbb742d91 100644 --- a/src/conversation/test_conversation_api.c +++ b/src/conversation/test_conversation_api.c | |||
@@ -402,7 +402,7 @@ namestore_put_cont (void *cls, int32_t success, const char *emsg) | |||
402 | GNUNET_assert (GNUNET_YES == success); | 402 | GNUNET_assert (GNUNET_YES == success); |
403 | GNUNET_assert (NULL == emsg); | 403 | GNUNET_assert (NULL == emsg); |
404 | GNUNET_assert (NULL == op); | 404 | GNUNET_assert (NULL == op); |
405 | op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); | 405 | op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, &caller_ego_create_cont, NULL); |
406 | } | 406 | } |
407 | 407 | ||
408 | 408 | ||
@@ -483,7 +483,7 @@ run (void *cls, | |||
483 | cfg = c; | 483 | cfg = c; |
484 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); | 484 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); |
485 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); | 485 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); |
486 | op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL); | 486 | op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont, NULL); |
487 | ns = GNUNET_NAMESTORE_connect (cfg); | 487 | ns = GNUNET_NAMESTORE_connect (cfg); |
488 | } | 488 | } |
489 | 489 | ||
diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c index 62e4109b0..855b21fd7 100644 --- a/src/conversation/test_conversation_api_reject.c +++ b/src/conversation/test_conversation_api_reject.c | |||
@@ -255,7 +255,7 @@ namestore_put_cont (void *cls, int32_t success, const char *emsg) | |||
255 | GNUNET_assert (GNUNET_YES == success); | 255 | GNUNET_assert (GNUNET_YES == success); |
256 | GNUNET_assert (NULL == emsg); | 256 | GNUNET_assert (NULL == emsg); |
257 | GNUNET_assert (NULL == op); | 257 | GNUNET_assert (NULL == op); |
258 | op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); | 258 | op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, &caller_ego_create_cont, NULL); |
259 | } | 259 | } |
260 | 260 | ||
261 | 261 | ||
@@ -336,7 +336,7 @@ run (void *cls, | |||
336 | cfg = c; | 336 | cfg = c; |
337 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); | 337 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); |
338 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); | 338 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); |
339 | op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL); | 339 | op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont, NULL); |
340 | ns = GNUNET_NAMESTORE_connect (cfg); | 340 | ns = GNUNET_NAMESTORE_connect (cfg); |
341 | } | 341 | } |
342 | 342 | ||
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c index fab49f7d7..6d434a3e1 100644 --- a/src/conversation/test_conversation_api_twocalls.c +++ b/src/conversation/test_conversation_api_twocalls.c | |||
@@ -524,7 +524,7 @@ namestore_put_cont (void *cls, int32_t success, const char *emsg) | |||
524 | GNUNET_assert (GNUNET_YES == success); | 524 | GNUNET_assert (GNUNET_YES == success); |
525 | GNUNET_assert (NULL == emsg); | 525 | GNUNET_assert (NULL == emsg); |
526 | GNUNET_assert (NULL == op); | 526 | GNUNET_assert (NULL == op); |
527 | op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); | 527 | op = GNUNET_IDENTITY_create (id, "caller-ego", NULL, &caller_ego_create_cont, NULL); |
528 | } | 528 | } |
529 | 529 | ||
530 | 530 | ||
@@ -613,7 +613,7 @@ run (void *cls, | |||
613 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); | 613 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); |
614 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 614 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
615 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); | 615 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); |
616 | op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL); | 616 | op = GNUNET_IDENTITY_create (id, "phone-ego", NULL, &phone_ego_create_cont, NULL); |
617 | ns = GNUNET_NAMESTORE_connect (cfg); | 617 | ns = GNUNET_NAMESTORE_connect (cfg); |
618 | } | 618 | } |
619 | 619 | ||
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index c251dfa12..fce69d3f6 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -927,8 +927,8 @@ get_distance (const struct GNUNET_HashCode *target, | |||
927 | (i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); | 927 | (i < sizeof(struct GNUNET_HashCode) * 8) && (i < bucket + 1 + 32 - 9); |
928 | i++) | 928 | i++) |
929 | { | 929 | { |
930 | if (GNUNET_CRYPTO_hash_get_bit (target, i) != | 930 | if (GNUNET_CRYPTO_hash_get_bit_rtl (target, i) != |
931 | GNUNET_CRYPTO_hash_get_bit (have, i)) | 931 | GNUNET_CRYPTO_hash_get_bit_rtl (have, i)) |
932 | lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, | 932 | lsb |= (1 << (bucket + 32 - 9 - i)); /* first bit set will be 10, |
933 | * last bit set will be 31 -- if | 933 | * last bit set will be 31 -- if |
934 | * i does not reach 512 first... */ | 934 | * i does not reach 512 first... */ |
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index e04a93f9c..3d2ba3e99 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c | |||
@@ -676,7 +676,7 @@ get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | |||
676 | fn = get_serialization_file_name (h, ext, ent); | 676 | fn = get_serialization_file_name (h, ext, ent); |
677 | if (NULL == fn) | 677 | if (NULL == fn) |
678 | return NULL; | 678 | return NULL; |
679 | ret = GNUNET_BIO_read_open (fn); | 679 | ret = GNUNET_BIO_read_open_file (fn); |
680 | GNUNET_free (fn); | 680 | GNUNET_free (fn); |
681 | return ret; | 681 | return ret; |
682 | } | 682 | } |
@@ -699,7 +699,7 @@ get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) | |||
699 | fn = get_serialization_file_name (h, ext, ent); | 699 | fn = get_serialization_file_name (h, ext, ent); |
700 | if (NULL == fn) | 700 | if (NULL == fn) |
701 | return NULL; | 701 | return NULL; |
702 | ret = GNUNET_BIO_write_open (fn); | 702 | ret = GNUNET_BIO_write_open_file (fn); |
703 | GNUNET_break (NULL != ret); | 703 | GNUNET_break (NULL != ret); |
704 | GNUNET_free (fn); | 704 | GNUNET_free (fn); |
705 | return ret; | 705 | return ret; |
@@ -727,7 +727,7 @@ get_write_handle_in_dir (struct GNUNET_FS_Handle *h, | |||
727 | fn = get_serialization_file_name_in_dir (h, ext, uni, ent); | 727 | fn = get_serialization_file_name_in_dir (h, ext, uni, ent); |
728 | if (NULL == fn) | 728 | if (NULL == fn) |
729 | return NULL; | 729 | return NULL; |
730 | ret = GNUNET_BIO_write_open (fn); | 730 | ret = GNUNET_BIO_write_open_file (fn); |
731 | GNUNET_free (fn); | 731 | GNUNET_free (fn); |
732 | return ret; | 732 | return ret; |
733 | } | 733 | } |
@@ -839,7 +839,7 @@ write_start_time (struct GNUNET_BIO_WriteHandle *wh, | |||
839 | struct GNUNET_TIME_Relative dur; | 839 | struct GNUNET_TIME_Relative dur; |
840 | 840 | ||
841 | dur = GNUNET_TIME_absolute_get_duration (timestamp); | 841 | dur = GNUNET_TIME_absolute_get_duration (timestamp); |
842 | return GNUNET_BIO_write_int64 (wh, dur.rel_value_us); | 842 | return GNUNET_BIO_write_int64 (wh, "start time", dur.rel_value_us); |
843 | } | 843 | } |
844 | 844 | ||
845 | 845 | ||
@@ -863,7 +863,8 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh, | |||
863 | { | 863 | { |
864 | struct GNUNET_TIME_Relative dur; | 864 | struct GNUNET_TIME_Relative dur; |
865 | 865 | ||
866 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dur.rel_value_us)) | 866 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "start time", |
867 | (int64_t *) &dur.rel_value_us)) | ||
867 | return GNUNET_SYSERR; | 868 | return GNUNET_SYSERR; |
868 | *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur); | 869 | *timestamp = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), dur); |
869 | return GNUNET_OK; | 870 | return GNUNET_OK; |
@@ -937,10 +938,22 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
937 | (GNUNET_OK != | 938 | (GNUNET_OK != |
938 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || | 939 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || |
939 | (GNUNET_OK != | 940 | (GNUNET_OK != |
940 | GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || | 941 | GNUNET_BIO_read_int64 ( |
941 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || | 942 | rh, |
942 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.content_priority)) || | 943 | "expiration time", |
943 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.replication_level))) | 944 | (int64_t *) &ret->bo.expiration_time.abs_value_us)) || |
945 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
946 | rh, | ||
947 | "anonymity level", | ||
948 | (int32_t *) &ret->bo.anonymity_level)) || | ||
949 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
950 | rh, | ||
951 | "content priority", | ||
952 | (int32_t *) &ret->bo.content_priority)) || | ||
953 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
954 | rh, | ||
955 | "replication level", | ||
956 | (int32_t *) &ret->bo.replication_level))) | ||
944 | { | 957 | { |
945 | GNUNET_break (0); | 958 | GNUNET_break (0); |
946 | goto cleanup; | 959 | goto cleanup; |
@@ -948,7 +961,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
948 | switch (b) | 961 | switch (b) |
949 | { | 962 | { |
950 | case 0: /* file-insert */ | 963 | case 0: /* file-insert */ |
951 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | 964 | if (GNUNET_OK != GNUNET_BIO_read_int64 ( |
965 | rh, | ||
966 | "file size", | ||
967 | (int64_t *) &ret->data.file.file_size)) | ||
952 | { | 968 | { |
953 | GNUNET_break (0); | 969 | GNUNET_break (0); |
954 | goto cleanup; | 970 | goto cleanup; |
@@ -990,7 +1006,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
990 | GNUNET_break (0); | 1006 | GNUNET_break (0); |
991 | goto cleanup; | 1007 | goto cleanup; |
992 | } | 1008 | } |
993 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | 1009 | if (GNUNET_OK != GNUNET_BIO_read_int64 ( |
1010 | rh, | ||
1011 | "file size", | ||
1012 | (int64_t *) &ret->data.file.file_size)) | ||
994 | { | 1013 | { |
995 | GNUNET_break (0); | 1014 | GNUNET_break (0); |
996 | goto cleanup; | 1015 | goto cleanup; |
@@ -1010,7 +1029,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1010 | GNUNET_break (0); | 1029 | GNUNET_break (0); |
1011 | goto cleanup; | 1030 | goto cleanup; |
1012 | } | 1031 | } |
1013 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1032 | if ((GNUNET_OK != GNUNET_BIO_read_int64 ( |
1033 | rh, | ||
1034 | "file size", | ||
1035 | (int64_t *) &ret->data.file.file_size)) || | ||
1014 | (GNUNET_OK != GNUNET_BIO_read (rh, | 1036 | (GNUNET_OK != GNUNET_BIO_read (rh, |
1015 | "fileid", | 1037 | "fileid", |
1016 | &ret->data.file.file_id, | 1038 | &ret->data.file.file_id, |
@@ -1034,7 +1056,10 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1034 | GNUNET_break (0); | 1056 | GNUNET_break (0); |
1035 | goto cleanup; | 1057 | goto cleanup; |
1036 | } | 1058 | } |
1037 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1059 | if ((GNUNET_OK != GNUNET_BIO_read_int64 ( |
1060 | rh, | ||
1061 | "file size", | ||
1062 | (int64_t *) &ret->data.file.file_size)) || | ||
1038 | (GNUNET_OK != GNUNET_BIO_read (rh, | 1063 | (GNUNET_OK != GNUNET_BIO_read (rh, |
1039 | "fileid", | 1064 | "fileid", |
1040 | &ret->data.file.file_id, | 1065 | &ret->data.file.file_id, |
@@ -1054,11 +1079,18 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1054 | 1079 | ||
1055 | case 4: /* directory */ | 1080 | case 4: /* directory */ |
1056 | ret->is_directory = GNUNET_YES; | 1081 | ret->is_directory = GNUNET_YES; |
1057 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || | 1082 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, "dsize", |
1083 | (int32_t *) &dsize)) || | ||
1058 | (GNUNET_OK != | 1084 | (GNUNET_OK != |
1059 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || | 1085 | GNUNET_BIO_read_int64 ( |
1086 | rh, | ||
1087 | "contents completed", | ||
1088 | (int64_t *) &ret->data.dir.contents_completed)) || | ||
1060 | (GNUNET_OK != | 1089 | (GNUNET_OK != |
1061 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || | 1090 | GNUNET_BIO_read_int64 ( |
1091 | rh, | ||
1092 | "contents size", | ||
1093 | (int64_t *) &ret->data.dir.contents_size)) || | ||
1062 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || | 1094 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || |
1063 | (GNUNET_OK != | 1095 | (GNUNET_OK != |
1064 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || | 1096 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || |
@@ -1294,7 +1326,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | |||
1294 | GNUNET_free (emsg); | 1326 | GNUNET_free (emsg); |
1295 | return GNUNET_SYSERR; | 1327 | return GNUNET_SYSERR; |
1296 | } | 1328 | } |
1297 | if (GNUNET_OK != GNUNET_BIO_write (wh, buf, ret)) | 1329 | if (GNUNET_OK != GNUNET_BIO_write (wh, "copied from reader", buf, ret)) |
1298 | return GNUNET_SYSERR; | 1330 | return GNUNET_SYSERR; |
1299 | off += ret; | 1331 | off += ret; |
1300 | } | 1332 | } |
@@ -1353,19 +1385,34 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1353 | skss = GNUNET_FS_uri_to_string (fi->sks_uri); | 1385 | skss = GNUNET_FS_uri_to_string (fi->sks_uri); |
1354 | else | 1386 | else |
1355 | skss = NULL; | 1387 | skss = NULL; |
1356 | if ((GNUNET_OK != GNUNET_BIO_write (wh, &b, sizeof(b))) || | 1388 | struct GNUNET_BIO_WriteSpec ws1[] = { |
1357 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, fi->meta)) || | 1389 | GNUNET_BIO_write_spec_object ("b", &b, sizeof (b)), |
1358 | (GNUNET_OK != GNUNET_BIO_write_string (wh, ksks)) || | 1390 | GNUNET_BIO_write_spec_meta_data ("meta", fi->meta), |
1359 | (GNUNET_OK != GNUNET_BIO_write_string (wh, chks)) || | 1391 | GNUNET_BIO_write_spec_string ("ksks", ksks), |
1360 | (GNUNET_OK != GNUNET_BIO_write_string (wh, skss)) || | 1392 | GNUNET_BIO_write_spec_string ("chks", chks), |
1393 | GNUNET_BIO_write_spec_string ("skss", skss), | ||
1394 | GNUNET_BIO_write_spec_end (), | ||
1395 | }; | ||
1396 | struct GNUNET_BIO_WriteSpec ws2[] = { | ||
1397 | GNUNET_BIO_write_spec_string ("emsg", fi->emsg), | ||
1398 | GNUNET_BIO_write_spec_string ("filename", fi->filename), | ||
1399 | GNUNET_BIO_write_spec_int64 ( | ||
1400 | "expiration time", | ||
1401 | (int64_t *) &fi->bo.expiration_time.abs_value_us), | ||
1402 | GNUNET_BIO_write_spec_int32 ( | ||
1403 | "anonymity level", | ||
1404 | (int32_t *) &fi->bo.anonymity_level), | ||
1405 | GNUNET_BIO_write_spec_int32 ( | ||
1406 | "content priority", | ||
1407 | (int32_t *) &fi->bo.content_priority), | ||
1408 | GNUNET_BIO_write_spec_int32 ( | ||
1409 | "replication level", | ||
1410 | (int32_t *) &fi->bo.replication_level), | ||
1411 | GNUNET_BIO_write_spec_end (), | ||
1412 | }; | ||
1413 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) || | ||
1361 | (GNUNET_OK != write_start_time (wh, fi->start_time)) || | 1414 | (GNUNET_OK != write_start_time (wh, fi->start_time)) || |
1362 | (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->emsg)) || | 1415 | (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2))) |
1363 | (GNUNET_OK != GNUNET_BIO_write_string (wh, fi->filename)) || | ||
1364 | (GNUNET_OK != | ||
1365 | GNUNET_BIO_write_int64 (wh, fi->bo.expiration_time.abs_value_us)) || | ||
1366 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.anonymity_level)) || | ||
1367 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.content_priority)) || | ||
1368 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->bo.replication_level))) | ||
1369 | { | 1416 | { |
1370 | GNUNET_break (0); | 1417 | GNUNET_break (0); |
1371 | goto cleanup; | 1418 | goto cleanup; |
@@ -1380,7 +1427,8 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1380 | switch (b) | 1427 | switch (b) |
1381 | { | 1428 | { |
1382 | case 0: /* file-insert */ | 1429 | case 0: /* file-insert */ |
1383 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | 1430 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size", |
1431 | fi->data.file.file_size)) | ||
1384 | { | 1432 | { |
1385 | GNUNET_break (0); | 1433 | GNUNET_break (0); |
1386 | goto cleanup; | 1434 | goto cleanup; |
@@ -1399,7 +1447,8 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1399 | GNUNET_break (0); | 1447 | GNUNET_break (0); |
1400 | goto cleanup; | 1448 | goto cleanup; |
1401 | } | 1449 | } |
1402 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | 1450 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size", |
1451 | fi->data.file.file_size)) | ||
1403 | { | 1452 | { |
1404 | GNUNET_break (0); | 1453 | GNUNET_break (0); |
1405 | goto cleanup; | 1454 | goto cleanup; |
@@ -1413,8 +1462,10 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1413 | GNUNET_break (0); | 1462 | GNUNET_break (0); |
1414 | goto cleanup; | 1463 | goto cleanup; |
1415 | } | 1464 | } |
1416 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || | 1465 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, "file size", |
1466 | fi->data.file.file_size)) || | ||
1417 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1467 | (GNUNET_OK != GNUNET_BIO_write (wh, |
1468 | "file id", | ||
1418 | &fi->data.file.file_id, | 1469 | &fi->data.file.file_id, |
1419 | sizeof(struct GNUNET_HashCode)))) | 1470 | sizeof(struct GNUNET_HashCode)))) |
1420 | { | 1471 | { |
@@ -1427,19 +1478,24 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1427 | if ((NULL != fi->data.dir.entries) && | 1478 | if ((NULL != fi->data.dir.entries) && |
1428 | (NULL == fi->data.dir.entries->serialization)) | 1479 | (NULL == fi->data.dir.entries->serialization)) |
1429 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); | 1480 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); |
1430 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || | 1481 | struct GNUNET_BIO_WriteSpec ws[] = { |
1431 | (GNUNET_OK != | 1482 | GNUNET_BIO_write_spec_int32 ("dir size", |
1432 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || | 1483 | (int32_t *) &fi->data.dir.dir_size), |
1433 | (GNUNET_OK != | 1484 | GNUNET_BIO_write_spec_int64 ( |
1434 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || | 1485 | "contents completed", |
1435 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1486 | (int64_t *) &fi->data.dir.contents_completed), |
1436 | fi->data.dir.dir_data, | 1487 | GNUNET_BIO_write_spec_int64 ("contents size", |
1437 | (uint32_t) fi->data.dir.dir_size)) || | 1488 | (int64_t *) &fi->data.dir.contents_size), |
1438 | (GNUNET_OK != | 1489 | GNUNET_BIO_write_spec_object ("dir data", |
1439 | GNUNET_BIO_write_string (wh, | 1490 | fi->data.dir.dir_data, |
1440 | (fi->data.dir.entries == NULL) | 1491 | (uint32_t) fi->data.dir.dir_size), |
1441 | ? NULL | 1492 | GNUNET_BIO_write_spec_string ("dir entries", |
1442 | : fi->data.dir.entries->serialization))) | 1493 | (fi->data.dir.entries == NULL) |
1494 | ? NULL | ||
1495 | : fi->data.dir.entries->serialization), | ||
1496 | GNUNET_BIO_write_spec_end (), | ||
1497 | }; | ||
1498 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))) | ||
1443 | { | 1499 | { |
1444 | GNUNET_break (0); | 1500 | GNUNET_break (0); |
1445 | goto cleanup; | 1501 | goto cleanup; |
@@ -1453,6 +1509,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1453 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) | 1509 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) |
1454 | GNUNET_FS_file_information_sync_ (fi->next); | 1510 | GNUNET_FS_file_information_sync_ (fi->next); |
1455 | if (GNUNET_OK != GNUNET_BIO_write_string (wh, | 1511 | if (GNUNET_OK != GNUNET_BIO_write_string (wh, |
1512 | "serialization", | ||
1456 | (fi->next != NULL) | 1513 | (fi->next != NULL) |
1457 | ? fi->next->serialization | 1514 | ? fi->next->serialization |
1458 | : NULL)) | 1515 | : NULL)) |
@@ -1460,7 +1517,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1460 | GNUNET_break (0); | 1517 | GNUNET_break (0); |
1461 | goto cleanup; | 1518 | goto cleanup; |
1462 | } | 1519 | } |
1463 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1520 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
1464 | { | 1521 | { |
1465 | wh = NULL; | 1522 | wh = NULL; |
1466 | GNUNET_break (0); | 1523 | GNUNET_break (0); |
@@ -1469,7 +1526,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1469 | return; /* done! */ | 1526 | return; /* done! */ |
1470 | cleanup: | 1527 | cleanup: |
1471 | if (NULL != wh) | 1528 | if (NULL != wh) |
1472 | (void) GNUNET_BIO_write_close (wh); | 1529 | (void) GNUNET_BIO_write_close (wh, NULL); |
1473 | GNUNET_free_non_null (chks); | 1530 | GNUNET_free_non_null (chks); |
1474 | GNUNET_free_non_null (ksks); | 1531 | GNUNET_free_non_null (ksks); |
1475 | GNUNET_free_non_null (skss); | 1532 | GNUNET_free_non_null (skss); |
@@ -1586,23 +1643,23 @@ deserialize_publish_file (void *cls, const char *filename) | |||
1586 | pc->serialization = get_serialization_short_name (filename); | 1643 | pc->serialization = get_serialization_short_name (filename); |
1587 | fi_root = NULL; | 1644 | fi_root = NULL; |
1588 | fi_pos = NULL; | 1645 | fi_pos = NULL; |
1589 | rh = GNUNET_BIO_read_open (filename); | 1646 | rh = GNUNET_BIO_read_open_file (filename); |
1590 | if (NULL == rh) | 1647 | if (NULL == rh) |
1591 | { | 1648 | { |
1592 | GNUNET_break (0); | 1649 | GNUNET_break (0); |
1593 | goto cleanup; | 1650 | goto cleanup; |
1594 | } | 1651 | } |
1595 | if ((GNUNET_OK != | 1652 | struct GNUNET_BIO_ReadSpec rs[] = { |
1596 | GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || | 1653 | GNUNET_BIO_read_spec_string ("publish-nid", &pc->nid, 1024), |
1597 | (GNUNET_OK != | 1654 | GNUNET_BIO_read_spec_string ("publish-nuid", &pc->nuid, 1024), |
1598 | GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || | 1655 | GNUNET_BIO_read_spec_int32 ("options", &options), |
1599 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 1656 | GNUNET_BIO_read_spec_int32 ("all done", &all_done), |
1600 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || | 1657 | GNUNET_BIO_read_spec_int32 ("have ns", &have_ns), |
1601 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || | 1658 | GNUNET_BIO_read_spec_string ("publish-firoot", &fi_root, 128), |
1602 | (GNUNET_OK != | 1659 | GNUNET_BIO_read_spec_string ("publish-fipos", &fi_pos, 128), |
1603 | GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || | 1660 | GNUNET_BIO_read_spec_end (), |
1604 | (GNUNET_OK != | 1661 | }; |
1605 | GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || | 1662 | if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) || |
1606 | ((GNUNET_YES == have_ns) && | 1663 | ((GNUNET_YES == have_ns) && |
1607 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof(ns))))) | 1664 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof(ns))))) |
1608 | { | 1665 | { |
@@ -1729,26 +1786,30 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1729 | goto cleanup; | 1786 | goto cleanup; |
1730 | } | 1787 | } |
1731 | have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO; | 1788 | have_ns = (NULL != pc->ns) ? GNUNET_YES : GNUNET_NO; |
1732 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nid)) || | 1789 | struct GNUNET_BIO_WriteSpec ws[] = { |
1733 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->nuid)) || | 1790 | GNUNET_BIO_write_spec_string ("nid", pc->nid), |
1734 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->options)) || | 1791 | GNUNET_BIO_write_spec_string ("nuid", pc->nuid), |
1735 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || | 1792 | GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &pc->options), |
1736 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || | 1793 | GNUNET_BIO_write_spec_int32 ("all done", &pc->all_done), |
1737 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || | 1794 | GNUNET_BIO_write_spec_int32 ("have ns", &have_ns), |
1738 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | 1795 | GNUNET_BIO_write_spec_string ("serialization", pc->fi->serialization), |
1739 | (NULL == pc->fi_pos) | 1796 | GNUNET_BIO_write_spec_string ("pos serialization", (NULL == pc->fi_pos) |
1740 | ? NULL | 1797 | ? NULL |
1741 | : pc->fi_pos->serialization)) || | 1798 | : pc->fi_pos->serialization), |
1799 | GNUNET_BIO_read_spec_end () | ||
1800 | }; | ||
1801 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)) || | ||
1742 | ((NULL != pc->ns) && | 1802 | ((NULL != pc->ns) && |
1743 | (GNUNET_OK != | 1803 | (GNUNET_OK != |
1744 | GNUNET_BIO_write (wh, | 1804 | GNUNET_BIO_write (wh, |
1805 | "ns", | ||
1745 | pc->ns, | 1806 | pc->ns, |
1746 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))))) | 1807 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey))))) |
1747 | { | 1808 | { |
1748 | GNUNET_break (0); | 1809 | GNUNET_break (0); |
1749 | goto cleanup; | 1810 | goto cleanup; |
1750 | } | 1811 | } |
1751 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1812 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
1752 | { | 1813 | { |
1753 | wh = NULL; | 1814 | wh = NULL; |
1754 | GNUNET_break (0); | 1815 | GNUNET_break (0); |
@@ -1757,7 +1818,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1757 | return; | 1818 | return; |
1758 | cleanup: | 1819 | cleanup: |
1759 | if (NULL != wh) | 1820 | if (NULL != wh) |
1760 | (void) GNUNET_BIO_write_close (wh); | 1821 | (void) GNUNET_BIO_write_close (wh, NULL); |
1761 | GNUNET_FS_remove_sync_file_ (pc->h, | 1822 | GNUNET_FS_remove_sync_file_ (pc->h, |
1762 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1823 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
1763 | pc->serialization); | 1824 | pc->serialization); |
@@ -1797,25 +1858,34 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1797 | uris = GNUNET_FS_uri_to_string (uc->ksk_uri); | 1858 | uris = GNUNET_FS_uri_to_string (uc->ksk_uri); |
1798 | else | 1859 | else |
1799 | uris = NULL; | 1860 | uris = NULL; |
1800 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uc->filename)) || | 1861 | struct GNUNET_BIO_WriteSpec ws1[] = { |
1801 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, uc->file_size)) || | 1862 | GNUNET_BIO_write_spec_string ("filename", uc->filename), |
1863 | GNUNET_BIO_write_spec_int64 ("file size", (int64_t *) &uc->file_size), | ||
1864 | GNUNET_BIO_write_spec_end (), | ||
1865 | }; | ||
1866 | struct GNUNET_BIO_WriteSpec ws2[] = { | ||
1867 | GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &uc->state), | ||
1868 | GNUNET_BIO_write_spec_object ("hashkey", &uc->chk, | ||
1869 | sizeof (struct ContentHashKey)), | ||
1870 | GNUNET_BIO_write_spec_string ("uris", uris), | ||
1871 | GNUNET_BIO_write_spec_int32 ("ksk offset", (int32_t *) &uc->ksk_offset), | ||
1872 | GNUNET_BIO_write_spec_end (), | ||
1873 | }; | ||
1874 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) || | ||
1802 | (GNUNET_OK != write_start_time (wh, uc->start_time)) || | 1875 | (GNUNET_OK != write_start_time (wh, uc->start_time)) || |
1803 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->state)) || | 1876 | (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2)) || |
1804 | (GNUNET_OK != | ||
1805 | GNUNET_BIO_write (wh, &uc->chk, sizeof(struct ContentHashKey))) || | ||
1806 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | ||
1807 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || | ||
1808 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && | 1877 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && |
1809 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1878 | (GNUNET_OK != GNUNET_BIO_write (wh, |
1879 | "file id", | ||
1810 | &uc->file_id, | 1880 | &uc->file_id, |
1811 | sizeof(struct GNUNET_HashCode)))) || | 1881 | sizeof(struct GNUNET_HashCode)))) || |
1812 | ((uc->state == UNINDEX_STATE_ERROR) && | 1882 | ((uc->state == UNINDEX_STATE_ERROR) && |
1813 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) | 1883 | (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", uc->emsg)))) |
1814 | { | 1884 | { |
1815 | GNUNET_break (0); | 1885 | GNUNET_break (0); |
1816 | goto cleanup; | 1886 | goto cleanup; |
1817 | } | 1887 | } |
1818 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1888 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
1819 | { | 1889 | { |
1820 | wh = NULL; | 1890 | wh = NULL; |
1821 | GNUNET_break (0); | 1891 | GNUNET_break (0); |
@@ -1824,7 +1894,7 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1824 | return; | 1894 | return; |
1825 | cleanup: | 1895 | cleanup: |
1826 | if (NULL != wh) | 1896 | if (NULL != wh) |
1827 | (void) GNUNET_BIO_write_close (wh); | 1897 | (void) GNUNET_BIO_write_close (wh, NULL); |
1828 | GNUNET_FS_remove_sync_file_ (uc->h, | 1898 | GNUNET_FS_remove_sync_file_ (uc->h, |
1829 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1899 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
1830 | uc->serialization); | 1900 | uc->serialization); |
@@ -1845,15 +1915,20 @@ write_download_request (struct GNUNET_BIO_WriteHandle *wh, | |||
1845 | struct DownloadRequest *dr) | 1915 | struct DownloadRequest *dr) |
1846 | { | 1916 | { |
1847 | unsigned int i; | 1917 | unsigned int i; |
1848 | 1918 | struct GNUNET_BIO_WriteSpec ws[] = { | |
1849 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->state)) || | 1919 | GNUNET_BIO_write_spec_int32 ("state", (int32_t *) &dr->state), |
1850 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dr->offset)) || | 1920 | GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dr->offset), |
1851 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->num_children)) || | 1921 | GNUNET_BIO_write_spec_int32 ("num children", (int32_t *) &dr->num_children), |
1852 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dr->depth))) | 1922 | GNUNET_BIO_write_spec_int32 ("depth", (int32_t *) &dr->depth), |
1923 | GNUNET_BIO_write_spec_end (), | ||
1924 | }; | ||
1925 | |||
1926 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))) | ||
1853 | return GNUNET_NO; | 1927 | return GNUNET_NO; |
1854 | if ((BRS_CHK_SET == dr->state) && | 1928 | if ((BRS_CHK_SET == dr->state) && |
1855 | (GNUNET_OK != | 1929 | (GNUNET_OK != |
1856 | GNUNET_BIO_write (wh, &dr->chk, sizeof(struct ContentHashKey)))) | 1930 | GNUNET_BIO_write (wh, "hashkey", |
1931 | &dr->chk, sizeof(struct ContentHashKey)))) | ||
1857 | return GNUNET_NO; | 1932 | return GNUNET_NO; |
1858 | for (i = 0; i < dr->num_children; i++) | 1933 | for (i = 0; i < dr->num_children; i++) |
1859 | if (GNUNET_NO == write_download_request (wh, dr->children[i])) | 1934 | if (GNUNET_NO == write_download_request (wh, dr->children[i])) |
@@ -1875,11 +1950,16 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh) | |||
1875 | unsigned int i; | 1950 | unsigned int i; |
1876 | 1951 | ||
1877 | dr = GNUNET_new (struct DownloadRequest); | 1952 | dr = GNUNET_new (struct DownloadRequest); |
1878 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->state)) || | 1953 | struct GNUNET_BIO_ReadSpec rs[] = { |
1879 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dr->offset)) || | 1954 | GNUNET_BIO_read_spec_int32 ("state", (int32_t *) &dr->state), |
1880 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || | 1955 | GNUNET_BIO_read_spec_int64 ("offset", (int64_t *) &dr->offset), |
1956 | GNUNET_BIO_read_spec_int32 ("num children", (int32_t *) &dr->num_children), | ||
1957 | GNUNET_BIO_read_spec_end (), | ||
1958 | }; | ||
1959 | if ((GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) || | ||
1881 | (dr->num_children > CHK_PER_INODE) || | 1960 | (dr->num_children > CHK_PER_INODE) || |
1882 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || | 1961 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "depth", |
1962 | (int32_t *) &dr->depth)) || | ||
1883 | ((0 == dr->depth) && (dr->num_children > 0)) || | 1963 | ((0 == dr->depth) && (dr->num_children > 0)) || |
1884 | ((dr->depth > 0) && (0 == dr->num_children))) | 1964 | ((dr->depth > 0) && (0 == dr->num_children))) |
1885 | { | 1965 | { |
@@ -2005,7 +2085,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
2005 | return; | 2085 | return; |
2006 | } | 2086 | } |
2007 | } | 2087 | } |
2008 | wh = GNUNET_BIO_write_open (fn); | 2088 | wh = GNUNET_BIO_write_open_file (fn); |
2009 | if (NULL == wh) | 2089 | if (NULL == wh) |
2010 | { | 2090 | { |
2011 | GNUNET_free (dc->serialization); | 2091 | GNUNET_free (dc->serialization); |
@@ -2016,19 +2096,28 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
2016 | GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || | 2096 | GNUNET_assert ((GNUNET_YES == GNUNET_FS_uri_test_chk (dc->uri)) || |
2017 | (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri))); | 2097 | (GNUNET_YES == GNUNET_FS_uri_test_loc (dc->uri))); |
2018 | uris = GNUNET_FS_uri_to_string (dc->uri); | 2098 | uris = GNUNET_FS_uri_to_string (dc->uri); |
2019 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2099 | struct GNUNET_BIO_WriteSpec ws1[] = { |
2020 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, dc->meta)) || | 2100 | GNUNET_BIO_write_spec_string ("uris", uris), |
2021 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->emsg)) || | 2101 | GNUNET_BIO_write_spec_meta_data ("metadata", dc->meta), |
2022 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->filename)) || | 2102 | GNUNET_BIO_write_spec_string ("emsg", dc->emsg), |
2023 | (GNUNET_OK != GNUNET_BIO_write_string (wh, dc->temp_filename)) || | 2103 | GNUNET_BIO_write_spec_string ("filename", dc->filename), |
2024 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->old_file_size)) || | 2104 | GNUNET_BIO_write_spec_string ("temp filename", dc->temp_filename), |
2025 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->offset)) || | 2105 | GNUNET_BIO_write_spec_int64 ("old file size", |
2026 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->length)) || | 2106 | (int64_t *) &dc->old_file_size), |
2027 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, dc->completed)) || | 2107 | GNUNET_BIO_write_spec_int64 ("offset", (int64_t *) &dc->offset), |
2108 | GNUNET_BIO_write_spec_int64 ("length", (int64_t *) &dc->length), | ||
2109 | GNUNET_BIO_write_spec_int64 ("completed", (int64_t *) &dc->completed), | ||
2110 | GNUNET_BIO_write_spec_end (), | ||
2111 | }; | ||
2112 | struct GNUNET_BIO_WriteSpec ws2[] = { | ||
2113 | GNUNET_BIO_write_spec_int32 ("anonymity", (int32_t *) &dc->anonymity), | ||
2114 | GNUNET_BIO_write_spec_int32 ("options", (int32_t *) &dc->options), | ||
2115 | GNUNET_BIO_write_spec_int32 ("has finished", (int32_t *) &dc->has_finished), | ||
2116 | GNUNET_BIO_write_spec_end (), | ||
2117 | }; | ||
2118 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws1)) || | ||
2028 | (GNUNET_OK != write_start_time (wh, dc->start_time)) || | 2119 | (GNUNET_OK != write_start_time (wh, dc->start_time)) || |
2029 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, dc->anonymity)) || | 2120 | (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws2))) |
2030 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->options)) || | ||
2031 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) dc->has_finished))) | ||
2032 | { | 2121 | { |
2033 | GNUNET_break (0); | 2122 | GNUNET_break (0); |
2034 | goto cleanup; | 2123 | goto cleanup; |
@@ -2044,7 +2133,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
2044 | } | 2133 | } |
2045 | GNUNET_free_non_null (uris); | 2134 | GNUNET_free_non_null (uris); |
2046 | uris = NULL; | 2135 | uris = NULL; |
2047 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2136 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
2048 | { | 2137 | { |
2049 | wh = NULL; | 2138 | wh = NULL; |
2050 | GNUNET_break (0); | 2139 | GNUNET_break (0); |
@@ -2054,7 +2143,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) | |||
2054 | return; | 2143 | return; |
2055 | cleanup: | 2144 | cleanup: |
2056 | if (NULL != wh) | 2145 | if (NULL != wh) |
2057 | (void) GNUNET_BIO_write_close (wh); | 2146 | (void) GNUNET_BIO_write_close (wh, NULL); |
2058 | GNUNET_free_non_null (uris); | 2147 | GNUNET_free_non_null (uris); |
2059 | if (0 != unlink (fn)) | 2148 | if (0 != unlink (fn)) |
2060 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 2149 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
@@ -2102,23 +2191,30 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2102 | goto cleanup; | 2191 | goto cleanup; |
2103 | } | 2192 | } |
2104 | uris = GNUNET_FS_uri_to_string (sr->uri); | 2193 | uris = GNUNET_FS_uri_to_string (sr->uri); |
2105 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2194 | struct GNUNET_BIO_WriteSpec ws[] = { |
2106 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | 2195 | GNUNET_BIO_write_spec_string ("uris", uris), |
2107 | (sr->download != NULL) | 2196 | GNUNET_BIO_write_spec_string ("download serialization", |
2108 | ? sr->download->serialization | 2197 | (sr->download != NULL) |
2109 | : NULL)) || | 2198 | ? sr->download->serialization |
2110 | (GNUNET_OK != | 2199 | : NULL), |
2111 | GNUNET_BIO_write_string (wh, | 2200 | GNUNET_BIO_write_spec_string ("update search serialization", |
2112 | (sr->update_search != NULL) | 2201 | (sr->update_search != NULL) |
2113 | ? sr->update_search->serialization | 2202 | ? sr->update_search->serialization |
2114 | : NULL)) || | 2203 | : NULL), |
2115 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || | 2204 | GNUNET_BIO_write_spec_meta_data ("metadata", sr->meta), |
2116 | (GNUNET_OK != | 2205 | GNUNET_BIO_write_spec_object ("key", &sr->key, |
2117 | GNUNET_BIO_write (wh, &sr->key, sizeof(struct GNUNET_HashCode))) || | 2206 | sizeof(struct GNUNET_HashCode)), |
2118 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || | 2207 | GNUNET_BIO_write_spec_int32 ("mandatory missing", |
2119 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || | 2208 | (int32_t *) &sr->mandatory_missing), |
2120 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || | 2209 | GNUNET_BIO_write_spec_int32 ("optional support", |
2121 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials))) | 2210 | (int32_t *) &sr->optional_support), |
2211 | GNUNET_BIO_write_spec_int32 ("availability success", | ||
2212 | (int32_t *) &sr->availability_success), | ||
2213 | GNUNET_BIO_write_spec_int32 ("availability trials", | ||
2214 | (int32_t *) &sr->availability_trials), | ||
2215 | GNUNET_BIO_write_spec_end (), | ||
2216 | }; | ||
2217 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))) | ||
2122 | { | 2218 | { |
2123 | GNUNET_break (0); | 2219 | GNUNET_break (0); |
2124 | goto cleanup; | 2220 | goto cleanup; |
@@ -2126,13 +2222,14 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2126 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && | 2222 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && |
2127 | (GNUNET_OK != | 2223 | (GNUNET_OK != |
2128 | GNUNET_BIO_write (wh, | 2224 | GNUNET_BIO_write (wh, |
2225 | "keyword bitmap", | ||
2129 | sr->keyword_bitmap, | 2226 | sr->keyword_bitmap, |
2130 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) | 2227 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) |
2131 | { | 2228 | { |
2132 | GNUNET_break (0); | 2229 | GNUNET_break (0); |
2133 | goto cleanup; | 2230 | goto cleanup; |
2134 | } | 2231 | } |
2135 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2232 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
2136 | { | 2233 | { |
2137 | wh = NULL; | 2234 | wh = NULL; |
2138 | GNUNET_break (0); | 2235 | GNUNET_break (0); |
@@ -2143,7 +2240,7 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2143 | cleanup: | 2240 | cleanup: |
2144 | GNUNET_free_non_null (uris); | 2241 | GNUNET_free_non_null (uris); |
2145 | if (NULL != wh) | 2242 | if (NULL != wh) |
2146 | (void) GNUNET_BIO_write_close (wh); | 2243 | (void) GNUNET_BIO_write_close (wh, NULL); |
2147 | remove_sync_file_in_dir (sr->h, | 2244 | remove_sync_file_in_dir (sr->h, |
2148 | (NULL == sr->sc->psearch_result) | 2245 | (NULL == sr->sc->psearch_result) |
2149 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2246 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
@@ -2188,19 +2285,21 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | |||
2188 | (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri))); | 2285 | (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri))); |
2189 | uris = GNUNET_FS_uri_to_string (sc->uri); | 2286 | uris = GNUNET_FS_uri_to_string (sc->uri); |
2190 | in_pause = (sc->task != NULL) ? 'r' : '\0'; | 2287 | in_pause = (sc->task != NULL) ? 'r' : '\0'; |
2191 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2288 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, "uris", uris)) || |
2192 | (GNUNET_OK != write_start_time (wh, sc->start_time)) || | 2289 | (GNUNET_OK != write_start_time (wh, sc->start_time)) || |
2193 | (GNUNET_OK != GNUNET_BIO_write_string (wh, sc->emsg)) || | 2290 | (GNUNET_OK != GNUNET_BIO_write_string (wh, "emsg", sc->emsg)) || |
2194 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) || | 2291 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "options", |
2195 | (GNUNET_OK != GNUNET_BIO_write (wh, &in_pause, sizeof(in_pause))) || | 2292 | (uint32_t) sc->options)) || |
2196 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sc->anonymity))) | 2293 | (GNUNET_OK != GNUNET_BIO_write (wh, "in pause", |
2294 | &in_pause, sizeof(in_pause))) || | ||
2295 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "anonymity", sc->anonymity))) | ||
2197 | { | 2296 | { |
2198 | GNUNET_break (0); | 2297 | GNUNET_break (0); |
2199 | goto cleanup; | 2298 | goto cleanup; |
2200 | } | 2299 | } |
2201 | GNUNET_free (uris); | 2300 | GNUNET_free (uris); |
2202 | uris = NULL; | 2301 | uris = NULL; |
2203 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 2302 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
2204 | { | 2303 | { |
2205 | wh = NULL; | 2304 | wh = NULL; |
2206 | GNUNET_break (0); | 2305 | GNUNET_break (0); |
@@ -2209,7 +2308,7 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | |||
2209 | return; | 2308 | return; |
2210 | cleanup: | 2309 | cleanup: |
2211 | if (NULL != wh) | 2310 | if (NULL != wh) |
2212 | (void) GNUNET_BIO_write_close (wh); | 2311 | (void) GNUNET_BIO_write_close (wh, NULL); |
2213 | GNUNET_free_non_null (uris); | 2312 | GNUNET_free_non_null (uris); |
2214 | GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization); | 2313 | GNUNET_FS_remove_sync_file_ (sc->h, category, sc->serialization); |
2215 | GNUNET_free (sc->serialization); | 2314 | GNUNET_free (sc->serialization); |
@@ -2239,7 +2338,7 @@ deserialize_unindex_file (void *cls, const char *filename) | |||
2239 | uc = GNUNET_new (struct GNUNET_FS_UnindexContext); | 2338 | uc = GNUNET_new (struct GNUNET_FS_UnindexContext); |
2240 | uc->h = h; | 2339 | uc->h = h; |
2241 | uc->serialization = get_serialization_short_name (filename); | 2340 | uc->serialization = get_serialization_short_name (filename); |
2242 | rh = GNUNET_BIO_read_open (filename); | 2341 | rh = GNUNET_BIO_read_open_file (filename); |
2243 | if (NULL == rh) | 2342 | if (NULL == rh) |
2244 | { | 2343 | { |
2245 | GNUNET_break (0); | 2344 | GNUNET_break (0); |
@@ -2248,14 +2347,17 @@ deserialize_unindex_file (void *cls, const char *filename) | |||
2248 | uris = NULL; | 2347 | uris = NULL; |
2249 | if ((GNUNET_OK != | 2348 | if ((GNUNET_OK != |
2250 | GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) || | 2349 | GNUNET_BIO_read_string (rh, "unindex-fn", &uc->filename, 10 * 1024)) || |
2251 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || | 2350 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, "file size", |
2351 | (int64_t *) &uc->file_size)) || | ||
2252 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || | 2352 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || |
2253 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || | 2353 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "state", |
2354 | (int32_t *) &state)) || | ||
2254 | (GNUNET_OK != | 2355 | (GNUNET_OK != |
2255 | GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) || | 2356 | GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof(struct ContentHashKey))) || |
2256 | (GNUNET_OK != | 2357 | (GNUNET_OK != |
2257 | GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || | 2358 | GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || |
2258 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset))) | 2359 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "ksk offset", |
2360 | (int32_t *) &uc->ksk_offset))) | ||
2259 | { | 2361 | { |
2260 | GNUNET_free_non_null (uris); | 2362 | GNUNET_free_non_null (uris); |
2261 | GNUNET_break (0); | 2363 | GNUNET_break (0); |
@@ -2443,7 +2545,7 @@ deserialize_search_result (void *cls, const char *filename) | |||
2443 | struct GNUNET_FS_SearchResult *sr; | 2545 | struct GNUNET_FS_SearchResult *sr; |
2444 | 2546 | ||
2445 | ser = get_serialization_short_name (filename); | 2547 | ser = get_serialization_short_name (filename); |
2446 | rh = GNUNET_BIO_read_open (filename); | 2548 | rh = GNUNET_BIO_read_open_file (filename); |
2447 | if (NULL == rh) | 2549 | if (NULL == rh) |
2448 | { | 2550 | { |
2449 | if (NULL != ser) | 2551 | if (NULL != ser) |
@@ -2478,10 +2580,22 @@ deserialize_search_result (void *cls, const char *filename) | |||
2478 | "result-key", | 2580 | "result-key", |
2479 | &sr->key, | 2581 | &sr->key, |
2480 | sizeof(struct GNUNET_HashCode))) || | 2582 | sizeof(struct GNUNET_HashCode))) || |
2481 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || | 2583 | (GNUNET_OK != GNUNET_BIO_read_int32 ( |
2482 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || | 2584 | rh, |
2483 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || | 2585 | "mandatory missing", |
2484 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) | 2586 | (int32_t *) &sr->mandatory_missing)) || |
2587 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
2588 | rh, | ||
2589 | "optional support", | ||
2590 | (int32_t *) &sr->optional_support)) || | ||
2591 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
2592 | rh, | ||
2593 | "availability success", | ||
2594 | (int32_t *) &sr->availability_success)) || | ||
2595 | (GNUNET_OK != GNUNET_BIO_read_int32 ( | ||
2596 | rh, | ||
2597 | "availability trials", | ||
2598 | (int32_t *) &sr->availability_trials))) | ||
2485 | { | 2599 | { |
2486 | GNUNET_break (0); | 2600 | GNUNET_break (0); |
2487 | goto cleanup; | 2601 | goto cleanup; |
@@ -2741,7 +2855,7 @@ deserialize_subdownload (void *cls, const char *filename) | |||
2741 | struct GNUNET_BIO_ReadHandle *rh; | 2855 | struct GNUNET_BIO_ReadHandle *rh; |
2742 | 2856 | ||
2743 | ser = get_serialization_short_name (filename); | 2857 | ser = get_serialization_short_name (filename); |
2744 | rh = GNUNET_BIO_read_open (filename); | 2858 | rh = GNUNET_BIO_read_open_file (filename); |
2745 | if (NULL == rh) | 2859 | if (NULL == rh) |
2746 | { | 2860 | { |
2747 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2861 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -2827,29 +2941,35 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2827 | dc->parent = parent; | 2941 | dc->parent = parent; |
2828 | dc->h = h; | 2942 | dc->h = h; |
2829 | dc->serialization = GNUNET_strdup (serialization); | 2943 | dc->serialization = GNUNET_strdup (serialization); |
2944 | struct GNUNET_BIO_ReadSpec rs[] = { | ||
2945 | GNUNET_BIO_read_spec_meta_data ("download-meta", &dc->meta), | ||
2946 | GNUNET_BIO_read_spec_string ("download-emsg", &dc->emsg, 10 * 1024), | ||
2947 | GNUNET_BIO_read_spec_string ("download-fn", &dc->filename, 10 * 1024), | ||
2948 | GNUNET_BIO_read_spec_string ("download-tfn", | ||
2949 | &dc->temp_filename, 10 * 1024), | ||
2950 | GNUNET_BIO_read_spec_int64 ("old file size", | ||
2951 | (int64_t *) &dc->old_file_size), | ||
2952 | GNUNET_BIO_read_spec_int64 ("offset", | ||
2953 | (int64_t *) &dc->offset), | ||
2954 | GNUNET_BIO_read_spec_int64 ("length", | ||
2955 | (int64_t *) &dc->length), | ||
2956 | GNUNET_BIO_read_spec_int64 ("completed", | ||
2957 | (int64_t *) &dc->completed), | ||
2958 | GNUNET_BIO_read_spec_end (), | ||
2959 | }; | ||
2830 | if ((GNUNET_OK != | 2960 | if ((GNUNET_OK != |
2831 | GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) || | 2961 | GNUNET_BIO_read_string (rh, "download-uri", &uris, 10 * 1024)) || |
2832 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2962 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || |
2833 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && | 2963 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && |
2834 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || | 2964 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || |
2835 | (GNUNET_OK != | 2965 | (GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) || |
2836 | GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || | ||
2837 | (GNUNET_OK != | ||
2838 | GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || | ||
2839 | (GNUNET_OK != | ||
2840 | GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || | ||
2841 | (GNUNET_OK != GNUNET_BIO_read_string (rh, | ||
2842 | "download-tfn", | ||
2843 | &dc->temp_filename, | ||
2844 | 10 * 1024)) || | ||
2845 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || | ||
2846 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || | ||
2847 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || | ||
2848 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->completed)) || | ||
2849 | (GNUNET_OK != read_start_time (rh, &dc->start_time)) || | 2966 | (GNUNET_OK != read_start_time (rh, &dc->start_time)) || |
2850 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dc->anonymity)) || | 2967 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity", |
2851 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 2968 | (int32_t *) &dc->anonymity)) || |
2852 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &status))) | 2969 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options", |
2970 | (int32_t *) &options)) || | ||
2971 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "status", | ||
2972 | (int32_t *) &status))) | ||
2853 | { | 2973 | { |
2854 | GNUNET_break (0); | 2974 | GNUNET_break (0); |
2855 | goto cleanup; | 2975 | goto cleanup; |
@@ -2972,10 +3092,12 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2972 | (GNUNET_OK != read_start_time (rh, &sc->start_time)) || | 3092 | (GNUNET_OK != read_start_time (rh, &sc->start_time)) || |
2973 | (GNUNET_OK != | 3093 | (GNUNET_OK != |
2974 | GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) || | 3094 | GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10 * 1024)) || |
2975 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 3095 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "options", |
3096 | (int32_t *) &options)) || | ||
2976 | (GNUNET_OK != | 3097 | (GNUNET_OK != |
2977 | GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof(in_pause))) || | 3098 | GNUNET_BIO_read (rh, "search-pause", &in_pause, sizeof(in_pause))) || |
2978 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sc->anonymity))) | 3099 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "anonymity", |
3100 | (int32_t *) &sc->anonymity))) | ||
2979 | { | 3101 | { |
2980 | GNUNET_break (0); | 3102 | GNUNET_break (0); |
2981 | goto cleanup; | 3103 | goto cleanup; |
@@ -3038,7 +3160,7 @@ deserialize_search_file (void *cls, const char *filename) | |||
3038 | if (S_ISDIR (buf.st_mode)) | 3160 | if (S_ISDIR (buf.st_mode)) |
3039 | return GNUNET_OK; /* skip directories */ | 3161 | return GNUNET_OK; /* skip directories */ |
3040 | ser = get_serialization_short_name (filename); | 3162 | ser = get_serialization_short_name (filename); |
3041 | rh = GNUNET_BIO_read_open (filename); | 3163 | rh = GNUNET_BIO_read_open_file (filename); |
3042 | if (NULL == rh) | 3164 | if (NULL == rh) |
3043 | { | 3165 | { |
3044 | if (NULL != ser) | 3166 | if (NULL != ser) |
@@ -3081,7 +3203,7 @@ deserialize_download_file (void *cls, const char *filename) | |||
3081 | struct GNUNET_BIO_ReadHandle *rh; | 3203 | struct GNUNET_BIO_ReadHandle *rh; |
3082 | 3204 | ||
3083 | ser = get_serialization_short_name (filename); | 3205 | ser = get_serialization_short_name (filename); |
3084 | rh = GNUNET_BIO_read_open (filename); | 3206 | rh = GNUNET_BIO_read_open_file (filename); |
3085 | if (NULL == rh) | 3207 | if (NULL == rh) |
3086 | { | 3208 | { |
3087 | if (0 != unlink (filename)) | 3209 | if (0 != unlink (filename)) |
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c index 6ede02afd..f098032d7 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c | |||
@@ -195,7 +195,7 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
195 | char *uris; | 195 | char *uris; |
196 | 196 | ||
197 | fn = get_update_information_directory (uig->h, &uig->ns); | 197 | fn = get_update_information_directory (uig->h, &uig->ns); |
198 | wh = GNUNET_BIO_write_open (fn); | 198 | wh = GNUNET_BIO_write_open_file (fn); |
199 | if (NULL == wh) | 199 | if (NULL == wh) |
200 | { | 200 | { |
201 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 201 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -205,16 +205,22 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
205 | GNUNET_free (fn); | 205 | GNUNET_free (fn); |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, uig->update_node_count)) | 208 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, |
209 | "fs-namespace-node-count", | ||
210 | uig->update_node_count)) | ||
209 | goto END; | 211 | goto END; |
210 | for (i = 0; i < uig->update_node_count; i++) | 212 | for (i = 0; i < uig->update_node_count; i++) |
211 | { | 213 | { |
212 | n = uig->update_nodes[i]; | 214 | n = uig->update_nodes[i]; |
213 | uris = GNUNET_FS_uri_to_string (n->uri); | 215 | uris = GNUNET_FS_uri_to_string (n->uri); |
214 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, n->id)) || | 216 | struct GNUNET_BIO_WriteSpec ws[] = { |
215 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, n->md)) || | 217 | GNUNET_BIO_write_spec_string("fs-namespace-node-id", n->id), |
216 | (GNUNET_OK != GNUNET_BIO_write_string (wh, n->update)) || | 218 | GNUNET_BIO_write_spec_meta_data("fs-namespace-node-meta", n->md), |
217 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris))) | 219 | GNUNET_BIO_write_spec_string("fs-namespace-node-update", n->update), |
220 | GNUNET_BIO_write_spec_string("fs-namespace-uris", uris), | ||
221 | GNUNET_BIO_write_spec_end(), | ||
222 | }; | ||
223 | if (GNUNET_OK != GNUNET_BIO_write_spec_commit(wh, ws)) | ||
218 | { | 224 | { |
219 | GNUNET_free (uris); | 225 | GNUNET_free (uris); |
220 | break; | 226 | break; |
@@ -222,7 +228,7 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
222 | GNUNET_free (uris); | 228 | GNUNET_free (uris); |
223 | } | 229 | } |
224 | END: | 230 | END: |
225 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 231 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
226 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
227 | _ ("Failed to write `%s': %s\n"), | 233 | _ ("Failed to write `%s': %s\n"), |
228 | fn, | 234 | fn, |
@@ -260,13 +266,14 @@ read_update_information_graph (struct GNUNET_FS_Handle *h, | |||
260 | GNUNET_free (fn); | 266 | GNUNET_free (fn); |
261 | return uig; | 267 | return uig; |
262 | } | 268 | } |
263 | rh = GNUNET_BIO_read_open (fn); | 269 | rh = GNUNET_BIO_read_open_file (fn); |
264 | if (NULL == rh) | 270 | if (NULL == rh) |
265 | { | 271 | { |
266 | GNUNET_free (fn); | 272 | GNUNET_free (fn); |
267 | return uig; | 273 | return uig; |
268 | } | 274 | } |
269 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &count)) | 275 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "fs-namespace-count", |
276 | (int32_t *) &count)) | ||
270 | { | 277 | { |
271 | GNUNET_break (0); | 278 | GNUNET_break (0); |
272 | goto END; | 279 | goto END; |
@@ -284,12 +291,14 @@ read_update_information_graph (struct GNUNET_FS_Handle *h, | |||
284 | for (i = 0; i < count; i++) | 291 | for (i = 0; i < count; i++) |
285 | { | 292 | { |
286 | n = GNUNET_new (struct NamespaceUpdateNode); | 293 | n = GNUNET_new (struct NamespaceUpdateNode); |
287 | if ((GNUNET_OK != | 294 | struct GNUNET_BIO_ReadSpec rs[] = { |
288 | GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || | 295 | GNUNET_BIO_read_spec_string("identifier", &n->id, 1024), |
289 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || | 296 | GNUNET_BIO_read_spec_meta_data("meta", &n->md), |
290 | (GNUNET_OK != | 297 | GNUNET_BIO_read_spec_string("update-id", &n->update, 1024), |
291 | GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || | 298 | GNUNET_BIO_read_spec_string("uri", &uris, 1024 * 2), |
292 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) | 299 | GNUNET_BIO_read_spec_end(), |
300 | }; | ||
301 | if (GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) | ||
293 | { | 302 | { |
294 | GNUNET_break (0); | 303 | GNUNET_break (0); |
295 | GNUNET_free_non_null (n->id); | 304 | GNUNET_free_non_null (n->id); |
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index 13bc908e8..3aed0268b 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c | |||
@@ -190,18 +190,22 @@ load_state () | |||
190 | 190 | ||
191 | emsg = NULL; | 191 | emsg = NULL; |
192 | fn = get_state_file (); | 192 | fn = get_state_file (); |
193 | rh = GNUNET_BIO_read_open (fn); | 193 | rh = GNUNET_BIO_read_open_file (fn); |
194 | GNUNET_free (fn); | 194 | GNUNET_free (fn); |
195 | if (NULL == rh) | 195 | if (NULL == rh) |
196 | return; | 196 | return; |
197 | fn = NULL; | 197 | fn = NULL; |
198 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &n)) | 198 | if (GNUNET_OK != GNUNET_BIO_read_int32 (rh, "number of files", |
199 | (int32_t *) &n)) | ||
199 | goto error; | 200 | goto error; |
200 | while (n-- > 0) | 201 | while (n-- > 0) |
201 | { | 202 | { |
202 | if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "filename", &fn, 1024)) || | 203 | struct GNUNET_BIO_ReadSpec rs[] = { |
203 | (GNUNET_OK != | 204 | GNUNET_BIO_read_spec_string("filename", &fn, 1024), |
204 | GNUNET_BIO_read (rh, "id", &id, sizeof(struct GNUNET_HashCode)))) | 205 | GNUNET_BIO_read_spec_object("id", &id, sizeof(struct GNUNET_HashCode)), |
206 | GNUNET_BIO_read_spec_end(), | ||
207 | }; | ||
208 | if (GNUNET_OK != GNUNET_BIO_read_spec_commit (rh, rs)) | ||
205 | goto error; | 209 | goto error; |
206 | wi = GNUNET_new (struct WorkItem); | 210 | wi = GNUNET_new (struct WorkItem); |
207 | wi->id = id; | 211 | wi->id = id; |
@@ -251,9 +255,13 @@ write_item (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
251 | "Saving serialization ID of file `%s' with value `%s'\n", | 255 | "Saving serialization ID of file `%s' with value `%s'\n", |
252 | wi->filename, | 256 | wi->filename, |
253 | GNUNET_h2s (&wi->id)); | 257 | GNUNET_h2s (&wi->id)); |
254 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, wi->filename)) || | 258 | struct GNUNET_BIO_WriteSpec ws[] = { |
255 | (GNUNET_OK != | 259 | GNUNET_BIO_write_spec_string ("auto-share-write-item-filename", |
256 | GNUNET_BIO_write (wh, &wi->id, sizeof(struct GNUNET_HashCode)))) | 260 | wi->filename), |
261 | GNUNET_BIO_write_spec_object ("id", &wi->id, sizeof(struct GNUNET_HashCode)), | ||
262 | GNUNET_BIO_write_spec_end (), | ||
263 | }; | ||
264 | if (GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws)) | ||
257 | return GNUNET_SYSERR; /* write error, abort iteration */ | 265 | return GNUNET_SYSERR; /* write error, abort iteration */ |
258 | return GNUNET_OK; | 266 | return GNUNET_OK; |
259 | } | 267 | } |
@@ -271,7 +279,7 @@ save_state () | |||
271 | 279 | ||
272 | n = GNUNET_CONTAINER_multihashmap_size (work_finished); | 280 | n = GNUNET_CONTAINER_multihashmap_size (work_finished); |
273 | fn = get_state_file (); | 281 | fn = get_state_file (); |
274 | wh = GNUNET_BIO_write_open (fn); | 282 | wh = GNUNET_BIO_write_open_file (fn); |
275 | if (NULL == wh) | 283 | if (NULL == wh) |
276 | { | 284 | { |
277 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 285 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -280,9 +288,9 @@ save_state () | |||
280 | GNUNET_free (fn); | 288 | GNUNET_free (fn); |
281 | return; | 289 | return; |
282 | } | 290 | } |
283 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, n)) | 291 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, "size of state", n)) |
284 | { | 292 | { |
285 | (void) GNUNET_BIO_write_close (wh); | 293 | (void) GNUNET_BIO_write_close (wh, NULL); |
286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 294 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
287 | _ ("Failed to save state to file %s\n"), | 295 | _ ("Failed to save state to file %s\n"), |
288 | fn); | 296 | fn); |
@@ -290,7 +298,7 @@ save_state () | |||
290 | return; | 298 | return; |
291 | } | 299 | } |
292 | (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, &write_item, wh); | 300 | (void) GNUNET_CONTAINER_multihashmap_iterate (work_finished, &write_item, wh); |
293 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 301 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
294 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 302 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
295 | _ ("Failed to save state to file %s\n"), | 303 | _ ("Failed to save state to file %s\n"), |
296 | fn); | 304 | fn); |
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index 98fca3ec5..f4d560176 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c | |||
@@ -123,7 +123,7 @@ write_index_list () | |||
123 | "INDEXDB"); | 123 | "INDEXDB"); |
124 | return; | 124 | return; |
125 | } | 125 | } |
126 | wh = GNUNET_BIO_write_open (fn); | 126 | wh = GNUNET_BIO_write_open_file (fn); |
127 | if (NULL == wh) | 127 | if (NULL == wh) |
128 | { | 128 | { |
129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
@@ -134,11 +134,14 @@ write_index_list () | |||
134 | } | 134 | } |
135 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 135 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
136 | if ((GNUNET_OK != GNUNET_BIO_write (wh, | 136 | if ((GNUNET_OK != GNUNET_BIO_write (wh, |
137 | "fs-indexing-file-id", | ||
137 | &pos->file_id, | 138 | &pos->file_id, |
138 | sizeof(struct GNUNET_HashCode))) || | 139 | sizeof(struct GNUNET_HashCode))) || |
139 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) | 140 | (GNUNET_OK != GNUNET_BIO_write_string (wh, |
141 | "fs-indexing-filename", | ||
142 | pos->filename))) | ||
140 | break; | 143 | break; |
141 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 144 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
142 | { | 145 | { |
143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
144 | _ ("Error writing `%s'.\n"), | 147 | _ ("Error writing `%s'.\n"), |
@@ -178,7 +181,7 @@ read_index_list () | |||
178 | GNUNET_free (fn); | 181 | GNUNET_free (fn); |
179 | return; | 182 | return; |
180 | } | 183 | } |
181 | rh = GNUNET_BIO_read_open (fn); | 184 | rh = GNUNET_BIO_read_open_file (fn); |
182 | if (NULL == rh) | 185 | if (NULL == rh) |
183 | { | 186 | { |
184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 187 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 7a5f7cfd8..5a9c70997 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -55,7 +55,6 @@ lib_LTLIBRARIES = \ | |||
55 | libgnunetgns.la | 55 | libgnunetgns.la |
56 | 56 | ||
57 | 57 | ||
58 | if HAVE_MHD | ||
59 | if HAVE_GNUTLS | 58 | if HAVE_GNUTLS |
60 | if HAVE_LIBGNURL | 59 | if HAVE_LIBGNURL |
61 | DO_PROXY=gnunet-gns-proxy | 60 | DO_PROXY=gnunet-gns-proxy |
@@ -69,7 +68,6 @@ CPP_GNURL=@LIBCURL_CPPFLAGS@ | |||
69 | endif | 68 | endif |
70 | endif | 69 | endif |
71 | endif | 70 | endif |
72 | endif | ||
73 | 71 | ||
74 | libexec_PROGRAMS = \ | 72 | libexec_PROGRAMS = \ |
75 | gnunet-service-gns \ | 73 | gnunet-service-gns \ |
@@ -82,15 +80,11 @@ bin_PROGRAMS = \ | |||
82 | noinst_PROGRAMS = \ | 80 | noinst_PROGRAMS = \ |
83 | gnunet-gns-benchmark | 81 | gnunet-gns-benchmark |
84 | 82 | ||
85 | if HAVE_MHD | ||
86 | if LINUX | 83 | if LINUX |
87 | bin_PROGRAMS += gnunet-bcd | 84 | bin_PROGRAMS += gnunet-bcd |
88 | endif | 85 | endif |
89 | endif | ||
90 | 86 | ||
91 | if HAVE_REST | ||
92 | REST_PLUGIN = libgnunet_plugin_rest_gns.la | 87 | REST_PLUGIN = libgnunet_plugin_rest_gns.la |
93 | endif | ||
94 | 88 | ||
95 | plugin_LTLIBRARIES = \ | 89 | plugin_LTLIBRARIES = \ |
96 | libgnunet_plugin_block_gns.la \ | 90 | libgnunet_plugin_block_gns.la \ |
@@ -258,14 +252,12 @@ libgnunet_plugin_block_gns_la_LDFLAGS = \ | |||
258 | $(GN_LIBINTL) \ | 252 | $(GN_LIBINTL) \ |
259 | $(GN_PLUGIN_LDFLAGS) | 253 | $(GN_PLUGIN_LDFLAGS) |
260 | 254 | ||
261 | if HAVE_MHD | ||
262 | if HAVE_GNUTLS | 255 | if HAVE_GNUTLS |
263 | if HAVE_LIBGNURL | 256 | if HAVE_LIBGNURL |
264 | check_PROGRAMS = \ | 257 | check_PROGRAMS = \ |
265 | test_gns_proxy | 258 | test_gns_proxy |
266 | endif | 259 | endif |
267 | endif | 260 | endif |
268 | endif | ||
269 | 261 | ||
270 | check_SCRIPTS = \ | 262 | check_SCRIPTS = \ |
271 | test_gns_lookup.sh \ | 263 | test_gns_lookup.sh \ |
@@ -286,18 +278,14 @@ check_SCRIPTS = \ | |||
286 | test_gns_revocation.sh\ | 278 | test_gns_revocation.sh\ |
287 | test_gns_cname_lookup.sh | 279 | test_gns_cname_lookup.sh |
288 | 280 | ||
289 | if HAVE_MHD | ||
290 | if HAVE_GNUTLS | 281 | if HAVE_GNUTLS |
291 | if HAVE_LIBGNURL | 282 | if HAVE_LIBGNURL |
292 | check_SCRIPTS += \ | 283 | check_SCRIPTS += \ |
293 | test_proxy.sh | 284 | test_proxy.sh |
294 | endif | 285 | endif |
295 | endif | 286 | endif |
296 | if HAVE_JSON | ||
297 | check_SCRIPTS += \ | 287 | check_SCRIPTS += \ |
298 | test_plugin_rest_gns.sh | 288 | test_plugin_rest_gns.sh |
299 | endif | ||
300 | endif | ||
301 | 289 | ||
302 | 290 | ||
303 | if ENABLE_TEST_RUN | 291 | if ENABLE_TEST_RUN |
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c index cf815d629..789ff8aa3 100644 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c | |||
@@ -37,34 +37,41 @@ | |||
37 | #define TEST_RRCOUNT 2 | 37 | #define TEST_RRCOUNT 2 |
38 | 38 | ||
39 | static void | 39 | static void |
40 | print_record(const struct GNUNET_GNSRECORD_Data *rd) | 40 | print_bytes (void *buf, |
41 | size_t buf_len, | ||
42 | int fold) | ||
41 | { | 43 | { |
42 | char *data_enc; | 44 | int i; |
43 | char *string_v; | 45 | |
44 | string_v = GNUNET_GNSRECORD_value_to_string (rd->record_type, | 46 | for (i = 0; i < buf_len; i++) |
45 | rd->data, | 47 | { |
46 | rd->data_size); | 48 | if ((0 != i) && (0 != fold) && (i % fold == 0)) |
47 | fprintf (stdout, | 49 | printf ("\n"); |
48 | "EXPIRATION: %"PRIu64"\n", rd->expiration_time); | 50 | printf ("%02x", ((unsigned char*) buf)[i]); |
51 | } | ||
52 | printf ("\n"); | ||
53 | } | ||
54 | |||
55 | |||
56 | static void | ||
57 | print_record (const struct GNUNET_GNSRECORD_Data *rd) | ||
58 | { | ||
59 | |||
49 | fprintf (stdout, | 60 | fprintf (stdout, |
50 | "DATA_SIZE: %"PRIu64"\n", rd->data_size); | 61 | "EXPIRATION: %" PRIu64 "\n", rd->expiration_time); |
62 | fprintf (stdout, | ||
63 | "DATA_SIZE: %zu\n", rd->data_size); | ||
51 | fprintf (stdout, | 64 | fprintf (stdout, |
52 | "TYPE: %d\n", rd->record_type); | 65 | "TYPE: %d\n", rd->record_type); |
53 | fprintf (stdout, | 66 | fprintf (stdout, |
54 | "FLAGS: %d\n", rd->flags); | 67 | "FLAGS: %d\n", rd->flags); |
55 | GNUNET_STRINGS_base64_encode (rd->data, | ||
56 | rd->data_size, | ||
57 | &data_enc); | ||
58 | fprintf (stdout, | ||
59 | "DATA (base64):\n%s\n", | ||
60 | data_enc); | ||
61 | fprintf (stdout, | 68 | fprintf (stdout, |
62 | "DATA (Human readable):\n%s\n\n", string_v); | 69 | "DATA:\n"); |
63 | GNUNET_free (string_v); | 70 | print_bytes ((char*) rd->data, rd->data_size, 8); |
64 | 71 | fprintf (stdout, "\n"); | |
65 | GNUNET_free (data_enc); | ||
66 | } | 72 | } |
67 | 73 | ||
74 | |||
68 | /** | 75 | /** |
69 | * Main function that will be run. | 76 | * Main function that will be run. |
70 | * | 77 | * |
@@ -80,7 +87,7 @@ run (void *cls, | |||
80 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 87 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
81 | { | 88 | { |
82 | struct GNUNET_GNSRECORD_Data rd[2]; | 89 | struct GNUNET_GNSRECORD_Data rd[2]; |
83 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get(); | 90 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get (); |
84 | struct GNUNET_GNSRECORD_Block *rrblock; | 91 | struct GNUNET_GNSRECORD_Block *rrblock; |
85 | char *bdata; | 92 | char *bdata; |
86 | struct GNUNET_CRYPTO_EcdsaPrivateKey id_priv; | 93 | struct GNUNET_CRYPTO_EcdsaPrivateKey id_priv; |
@@ -91,22 +98,16 @@ run (void *cls, | |||
91 | size_t data_size; | 98 | size_t data_size; |
92 | char *rdata; | 99 | char *rdata; |
93 | size_t rdata_size; | 100 | size_t rdata_size; |
94 | char* data_enc; | ||
95 | 101 | ||
96 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv); | 102 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv); |
97 | GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv, | 103 | GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv, |
98 | &id_pub); | 104 | &id_pub); |
99 | GNUNET_STRINGS_base64_encode (&id_priv, | 105 | fprintf (stdout, "Zone private key (d, little-endian scalar):\n"); |
100 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 106 | print_bytes (&id_priv, sizeof(id_priv), 0); |
101 | &data_enc); | 107 | fprintf (stdout, "\n"); |
102 | fprintf(stdout, "Zone private key (d):\n%s\n", data_enc); | 108 | fprintf (stdout, "Zone public key (zk):\n"); |
103 | GNUNET_free (data_enc); | 109 | print_bytes (&id_pub, sizeof(id_pub), 0); |
104 | GNUNET_STRINGS_base64_encode (&id_pub, | 110 | fprintf (stdout, "\n"); |
105 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | ||
106 | &data_enc); | ||
107 | fprintf(stdout, "Zone public key (zk):\n%s\n", data_enc); | ||
108 | GNUNET_free (data_enc); | ||
109 | |||
110 | 111 | ||
111 | GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p); | 112 | GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p); |
112 | GNUNET_CRYPTO_ecdsa_key_get_public (&pkey_data_p, | 113 | GNUNET_CRYPTO_ecdsa_key_get_public (&pkey_data_p, |
@@ -114,7 +115,8 @@ run (void *cls, | |||
114 | fprintf (stdout, | 115 | fprintf (stdout, |
115 | "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT); | 116 | "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT); |
116 | memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2); | 117 | memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2); |
117 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size)); | 118 | GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value ( |
119 | GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size)); | ||
118 | rd[0].data = data; | 120 | rd[0].data = data; |
119 | rd[0].data_size = data_size; | 121 | rd[0].data_size = data_size; |
120 | rd[0].expiration_time = exp_abs.abs_value_us; | 122 | rd[0].expiration_time = exp_abs.abs_value_us; |
@@ -137,34 +139,28 @@ run (void *cls, | |||
137 | rd, | 139 | rd, |
138 | rdata_size, | 140 | rdata_size, |
139 | rdata); | 141 | rdata); |
140 | GNUNET_STRINGS_base64_encode (rdata, | 142 | fprintf (stdout, "RDATA:\n"); |
141 | rdata_size, | 143 | print_bytes (rdata, rdata_size, 8); |
142 | &data_enc); | 144 | fprintf (stdout, "\n"); |
143 | fprintf(stdout, "RDATA:\n%s\n\n", data_enc); | ||
144 | GNUNET_free (data_enc); | ||
145 | rrblock = GNUNET_GNSRECORD_block_create (&id_priv, | 145 | rrblock = GNUNET_GNSRECORD_block_create (&id_priv, |
146 | exp_abs, | 146 | exp_abs, |
147 | TEST_RECORD_LABEL, | 147 | TEST_RECORD_LABEL, |
148 | rd, | 148 | rd, |
149 | TEST_RRCOUNT); | 149 | TEST_RRCOUNT); |
150 | size_t bdata_size = ntohl (rrblock->purpose.size) - | 150 | size_t bdata_size = ntohl (rrblock->purpose.size) |
151 | sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) - | 151 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
152 | sizeof(struct GNUNET_TIME_AbsoluteNBO); | 152 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); |
153 | size_t rrblock_size = ntohl (rrblock->purpose.size) + | 153 | size_t rrblock_size = ntohl (rrblock->purpose.size) |
154 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) + | 154 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) |
155 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | 155 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); |
156 | 156 | ||
157 | bdata = (char*)&rrblock[1]; | 157 | bdata = (char*) &rrblock[1]; |
158 | GNUNET_STRINGS_base64_encode (bdata, | 158 | fprintf (stdout, "BDATA:\n"); |
159 | bdata_size, | 159 | print_bytes (bdata, bdata_size, 8); |
160 | &data_enc); | 160 | fprintf (stdout, "\n"); |
161 | fprintf(stdout, "BDATA:\n%s\n\n", data_enc); | 161 | fprintf (stdout, "RRBLOCK:\n"); |
162 | GNUNET_free (data_enc); | 162 | print_bytes (rrblock, rrblock_size, 8); |
163 | GNUNET_STRINGS_base64_encode (rrblock, | 163 | fprintf (stdout, "\n"); |
164 | rrblock_size, | ||
165 | &data_enc); | ||
166 | fprintf(stdout, "RRBLOCK:\n%s\n", data_enc); | ||
167 | GNUNET_free (data_enc); | ||
168 | 164 | ||
169 | } | 165 | } |
170 | 166 | ||
diff --git a/src/hostlist/Makefile.am b/src/hostlist/Makefile.am index a8621a2b0..3b534de70 100644 --- a/src/hostlist/Makefile.am +++ b/src/hostlist/Makefile.am | |||
@@ -10,12 +10,10 @@ if USE_COVERAGE | |||
10 | AM_CFLAGS = --coverage -O0 | 10 | AM_CFLAGS = --coverage -O0 |
11 | endif | 11 | endif |
12 | 12 | ||
13 | if HAVE_MHD | ||
14 | HOSTLIST_SERVER_SOURCES = \ | 13 | HOSTLIST_SERVER_SOURCES = \ |
15 | gnunet-daemon-hostlist_server.c gnunet-daemon-hostlist_server.h | 14 | gnunet-daemon-hostlist_server.c gnunet-daemon-hostlist_server.h |
16 | GN_LIBMHD = $(MHD_LIBS) | 15 | GN_LIBMHD = $(MHD_LIBS) |
17 | GN_CPPMHD = $(MHD_CFLAGS) | 16 | GN_CPPMHD = $(MHD_CFLAGS) |
18 | endif | ||
19 | 17 | ||
20 | if HAVE_LIBGNURL | 18 | if HAVE_LIBGNURL |
21 | libexec_PROGRAMS = \ | 19 | libexec_PROGRAMS = \ |
@@ -70,13 +68,11 @@ check_PROGRAMS = \ | |||
70 | endif | 68 | endif |
71 | endif | 69 | endif |
72 | 70 | ||
73 | if HAVE_MHD | ||
74 | if ENABLE_TEST_RUN | 71 | if ENABLE_TEST_RUN |
75 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 72 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
76 | TESTS = \ | 73 | TESTS = \ |
77 | $(check_PROGRAMS) | 74 | $(check_PROGRAMS) |
78 | endif | 75 | endif |
79 | endif | ||
80 | 76 | ||
81 | test_gnunet_daemon_hostlist_SOURCES = \ | 77 | test_gnunet_daemon_hostlist_SOURCES = \ |
82 | test_gnunet_daemon_hostlist.c | 78 | test_gnunet_daemon_hostlist.c |
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 704c796b4..54e070f89 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -30,8 +30,6 @@ | |||
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
32 | 32 | ||
33 | #if HAVE_MHD | ||
34 | |||
35 | #include "gnunet-daemon-hostlist_server.h" | 33 | #include "gnunet-daemon-hostlist_server.h" |
36 | 34 | ||
37 | /** | 35 | /** |
@@ -49,8 +47,6 @@ static int provide_hostlist; | |||
49 | */ | 47 | */ |
50 | static GNUNET_CORE_ConnectEventHandler server_ch; | 48 | static GNUNET_CORE_ConnectEventHandler server_ch; |
51 | 49 | ||
52 | #endif | ||
53 | |||
54 | /** | 50 | /** |
55 | * Set if we are allowed to learn about peers by accessing | 51 | * Set if we are allowed to learn about peers by accessing |
56 | * hostlist servers. | 52 | * hostlist servers. |
@@ -211,13 +207,11 @@ connect_handler (void *cls, | |||
211 | (*client_ch)(cls, | 207 | (*client_ch)(cls, |
212 | peer, | 208 | peer, |
213 | mq)); | 209 | mq)); |
214 | #if HAVE_MHD | ||
215 | if (NULL != server_ch) | 210 | if (NULL != server_ch) |
216 | GNUNET_assert (NULL == | 211 | GNUNET_assert (NULL == |
217 | (*server_ch)(cls, | 212 | (*server_ch)(cls, |
218 | peer, | 213 | peer, |
219 | mq)); | 214 | mq)); |
220 | #endif | ||
221 | return (void *) peer; | 215 | return (void *) peer; |
222 | } | 216 | } |
223 | 217 | ||
@@ -265,12 +259,10 @@ cleaning_task (void *cls) | |||
265 | { | 259 | { |
266 | GNUNET_HOSTLIST_client_stop (); | 260 | GNUNET_HOSTLIST_client_stop (); |
267 | } | 261 | } |
268 | #if HAVE_MHD | ||
269 | if (provide_hostlist) | 262 | if (provide_hostlist) |
270 | { | 263 | { |
271 | GNUNET_HOSTLIST_server_stop (); | 264 | GNUNET_HOSTLIST_server_stop (); |
272 | } | 265 | } |
273 | #endif | ||
274 | if (NULL != stats) | 266 | if (NULL != stats) |
275 | { | 267 | { |
276 | GNUNET_STATISTICS_destroy (stats, | 268 | GNUNET_STATISTICS_destroy (stats, |
@@ -306,9 +298,7 @@ run (void *cls, | |||
306 | }; | 298 | }; |
307 | 299 | ||
308 | if ((! bootstrapping) && (! learning) | 300 | if ((! bootstrapping) && (! learning) |
309 | #if HAVE_MHD | ||
310 | && (! provide_hostlist) | 301 | && (! provide_hostlist) |
311 | #endif | ||
312 | ) | 302 | ) |
313 | { | 303 | { |
314 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 304 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -338,14 +328,12 @@ run (void *cls, | |||
338 | learning ? learn_handlers : no_learn_handlers); | 328 | learning ? learn_handlers : no_learn_handlers); |
339 | 329 | ||
340 | 330 | ||
341 | #if HAVE_MHD | ||
342 | if (provide_hostlist) | 331 | if (provide_hostlist) |
343 | GNUNET_HOSTLIST_server_start (cfg, | 332 | GNUNET_HOSTLIST_server_start (cfg, |
344 | stats, | 333 | stats, |
345 | core, | 334 | core, |
346 | &server_ch, | 335 | &server_ch, |
347 | advertising); | 336 | advertising); |
348 | #endif | ||
349 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, | 337 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, |
350 | NULL); | 338 | NULL); |
351 | 339 | ||
@@ -370,13 +358,11 @@ int | |||
370 | main (int argc, char *const *argv) | 358 | main (int argc, char *const *argv) |
371 | { | 359 | { |
372 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 360 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
373 | #if HAVE_MHD | ||
374 | GNUNET_GETOPT_option_flag ('a', | 361 | GNUNET_GETOPT_option_flag ('a', |
375 | "advertise", | 362 | "advertise", |
376 | gettext_noop ( | 363 | gettext_noop ( |
377 | "advertise our hostlist to other peers"), | 364 | "advertise our hostlist to other peers"), |
378 | &advertising), | 365 | &advertising), |
379 | #endif | ||
380 | GNUNET_GETOPT_option_flag ('b', | 366 | GNUNET_GETOPT_option_flag ('b', |
381 | "bootstrap", | 367 | "bootstrap", |
382 | gettext_noop ( | 368 | gettext_noop ( |
@@ -387,12 +373,10 @@ main (int argc, char *const *argv) | |||
387 | gettext_noop ( | 373 | gettext_noop ( |
388 | "enable learning about hostlist servers from other peers"), | 374 | "enable learning about hostlist servers from other peers"), |
389 | &learning), | 375 | &learning), |
390 | #if HAVE_MHD | ||
391 | GNUNET_GETOPT_option_flag ('p', | 376 | GNUNET_GETOPT_option_flag ('p', |
392 | "provide-hostlist", | 377 | "provide-hostlist", |
393 | gettext_noop ("provide a hostlist server"), | 378 | gettext_noop ("provide a hostlist server"), |
394 | &provide_hostlist), | 379 | &provide_hostlist), |
395 | #endif | ||
396 | GNUNET_GETOPT_OPTION_END | 380 | GNUNET_GETOPT_OPTION_END |
397 | }; | 381 | }; |
398 | 382 | ||
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index a5ff9f9fa..c2e8f5d88 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.c +++ b/src/hostlist/gnunet-daemon-hostlist_client.c | |||
@@ -1404,7 +1404,7 @@ load_hostlist_file () | |||
1404 | return; | 1404 | return; |
1405 | } | 1405 | } |
1406 | 1406 | ||
1407 | rh = GNUNET_BIO_read_open (filename); | 1407 | rh = GNUNET_BIO_read_open_file (filename); |
1408 | if (NULL == rh) | 1408 | if (NULL == rh) |
1409 | { | 1409 | { |
1410 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1410 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -1417,13 +1417,17 @@ load_hostlist_file () | |||
1417 | } | 1417 | } |
1418 | 1418 | ||
1419 | counter = 0; | 1419 | counter = 0; |
1420 | struct GNUNET_BIO_ReadSpec rs[] = { | ||
1421 | GNUNET_BIO_read_spec_int32 ("times used", (int32_t *)×_used), | ||
1422 | GNUNET_BIO_read_spec_int64 ("quality", (int64_t *) &quality), | ||
1423 | GNUNET_BIO_read_spec_int64 ("last used", (int64_t *) &last_used), | ||
1424 | GNUNET_BIO_read_spec_int64 ("created", (int64_t *) &created), | ||
1425 | GNUNET_BIO_read_spec_int32 ("hellos returned", (int32_t *) &hellos_returned), | ||
1426 | GNUNET_BIO_read_spec_end (), | ||
1427 | }; | ||
1420 | while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && | 1428 | while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && |
1421 | (NULL != uri) && | 1429 | (NULL != uri) && |
1422 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && | 1430 | (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs))) |
1423 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && | ||
1424 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && | ||
1425 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && | ||
1426 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) | ||
1427 | { | 1431 | { |
1428 | hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1); | 1432 | hostlist = GNUNET_malloc (sizeof(struct Hostlist) + strlen (uri) + 1); |
1429 | hostlist->hello_count = hellos_returned; | 1433 | hostlist->hello_count = hellos_returned; |
@@ -1494,7 +1498,7 @@ save_hostlist_file (int shutdown) | |||
1494 | GNUNET_free (filename); | 1498 | GNUNET_free (filename); |
1495 | return; | 1499 | return; |
1496 | } | 1500 | } |
1497 | wh = GNUNET_BIO_write_open (filename); | 1501 | wh = GNUNET_BIO_write_open_file (filename); |
1498 | if (NULL == wh) | 1502 | if (NULL == wh) |
1499 | { | 1503 | { |
1500 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1504 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -1521,14 +1525,21 @@ save_hostlist_file (int shutdown) | |||
1521 | } | 1525 | } |
1522 | if (GNUNET_YES == ok) | 1526 | if (GNUNET_YES == ok) |
1523 | { | 1527 | { |
1524 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || | 1528 | struct GNUNET_BIO_WriteSpec ws[] = { |
1525 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->times_used)) || | 1529 | GNUNET_BIO_write_spec_string ("hostlist uri", pos->hostlist_uri), |
1526 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, pos->quality)) || | 1530 | GNUNET_BIO_write_spec_int32 ("times used", (int32_t *) &pos->times_used), |
1527 | (GNUNET_OK != | 1531 | GNUNET_BIO_write_spec_int64 ("quality", (int64_t *) &pos->quality), |
1528 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value_us)) || | 1532 | GNUNET_BIO_write_spec_int64 ( |
1529 | (GNUNET_OK != | 1533 | "last usage", |
1530 | GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value_us)) || | 1534 | (int64_t *) &pos->time_last_usage.abs_value_us), |
1531 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count))) | 1535 | GNUNET_BIO_write_spec_int64 ( |
1536 | "creation time", | ||
1537 | (int64_t *) &pos->time_creation.abs_value_us), | ||
1538 | GNUNET_BIO_write_spec_int32 ("hellos count", | ||
1539 | (int32_t *) &pos->hello_count), | ||
1540 | GNUNET_BIO_write_spec_end (), | ||
1541 | }; | ||
1542 | if ((GNUNET_OK != GNUNET_BIO_write_spec_commit (wh, ws))) | ||
1532 | { | 1543 | { |
1533 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1544 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1534 | _ ("Error writing hostlist URIs to file `%s'\n"), | 1545 | _ ("Error writing hostlist URIs to file `%s'\n"), |
@@ -1548,7 +1559,7 @@ save_hostlist_file (int shutdown) | |||
1548 | counter, | 1559 | counter, |
1549 | GNUNET_YES); | 1560 | GNUNET_YES); |
1550 | 1561 | ||
1551 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 1562 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
1552 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1563 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1553 | _ ("Error writing hostlist URIs to file `%s'\n"), | 1564 | _ ("Error writing hostlist URIs to file `%s'\n"), |
1554 | filename); | 1565 | filename); |
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am index 17e72c784..e806f0059 100644 --- a/src/identity/Makefile.am +++ b/src/identity/Makefile.am | |||
@@ -8,9 +8,7 @@ if USE_COVERAGE | |||
8 | XLIB = -lgcov | 8 | XLIB = -lgcov |
9 | endif | 9 | endif |
10 | 10 | ||
11 | if HAVE_REST | ||
12 | plugin_LTLIBRARIES = libgnunet_plugin_rest_identity.la | 11 | plugin_LTLIBRARIES = libgnunet_plugin_rest_identity.la |
13 | endif | ||
14 | 12 | ||
15 | pkgcfgdir= $(pkgdatadir)/config.d/ | 13 | pkgcfgdir= $(pkgdatadir)/config.d/ |
16 | 14 | ||
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index fd73048c4..cf44afd1f 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c | |||
@@ -76,6 +76,11 @@ static char *create_ego; | |||
76 | static char *delete_ego; | 76 | static char *delete_ego; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * -P option | ||
80 | */ | ||
81 | static char *privkey_ego; | ||
82 | |||
83 | /** | ||
79 | * -s option. | 84 | * -s option. |
80 | */ | 85 | */ |
81 | static char *set_ego; | 86 | static char *set_ego; |
@@ -101,6 +106,11 @@ static struct GNUNET_IDENTITY_Operation *create_op; | |||
101 | static struct GNUNET_IDENTITY_Operation *delete_op; | 106 | static struct GNUNET_IDENTITY_Operation *delete_op; |
102 | 107 | ||
103 | /** | 108 | /** |
109 | * Private key from command line option, or NULL. | ||
110 | */ | ||
111 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | ||
112 | |||
113 | /** | ||
104 | * Value to return from #main(). | 114 | * Value to return from #main(). |
105 | */ | 115 | */ |
106 | static int global_ret; | 116 | static int global_ret; |
@@ -390,11 +400,28 @@ run (void *cls, | |||
390 | &delete_finished, | 400 | &delete_finished, |
391 | &delete_op); | 401 | &delete_op); |
392 | if (NULL != create_ego) | 402 | if (NULL != create_ego) |
393 | create_op = | 403 | { |
394 | GNUNET_IDENTITY_create (sh, | 404 | if (NULL != privkey_ego) |
395 | create_ego, | 405 | { |
396 | &create_finished, | 406 | GNUNET_STRINGS_string_to_data (privkey_ego, |
397 | &create_op); | 407 | strlen (privkey_ego), |
408 | &pk, | ||
409 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
410 | create_op = | ||
411 | GNUNET_IDENTITY_create (sh, | ||
412 | create_ego, | ||
413 | &pk, | ||
414 | &create_finished, | ||
415 | &create_op); | ||
416 | } | ||
417 | else | ||
418 | create_op = | ||
419 | GNUNET_IDENTITY_create (sh, | ||
420 | create_ego, | ||
421 | NULL, | ||
422 | &create_finished, | ||
423 | &create_op); | ||
424 | } | ||
398 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 425 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
399 | NULL); | 426 | NULL); |
400 | test_finished (); | 427 | test_finished (); |
@@ -422,6 +449,11 @@ main (int argc, char *const *argv) | |||
422 | "NAME", | 449 | "NAME", |
423 | gettext_noop ("delete ego NAME "), | 450 | gettext_noop ("delete ego NAME "), |
424 | &delete_ego), | 451 | &delete_ego), |
452 | GNUNET_GETOPT_option_string ('P', | ||
453 | "privkey", | ||
454 | "PRIVATE_KEY", | ||
455 | gettext_noop ("set the private key for the identity to PRIVATE_KEY (use together with -C)"), | ||
456 | &privkey_ego), | ||
425 | GNUNET_GETOPT_option_flag ('d', | 457 | GNUNET_GETOPT_option_flag ('d', |
426 | "display", | 458 | "display", |
427 | gettext_noop ("display all egos"), | 459 | gettext_noop ("display all egos"), |
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index 693d4392e..5d17ac5d5 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c | |||
@@ -392,6 +392,7 @@ handle_identity_update (void *cls, | |||
392 | return; | 392 | return; |
393 | } | 393 | } |
394 | ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); | 394 | ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); |
395 | ego->pub_initialized = GNUNET_NO; | ||
395 | ego->pk = um->private_key; | 396 | ego->pk = um->private_key; |
396 | ego->name = GNUNET_strdup (str); | 397 | ego->name = GNUNET_strdup (str); |
397 | ego->id = id; | 398 | ego->id = id; |
@@ -607,11 +608,11 @@ void | |||
607 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, | 608 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, |
608 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk) | 609 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk) |
609 | { | 610 | { |
610 | if (! ego->pub_initialized) | 611 | if (GNUNET_NO == ego->pub_initialized) |
611 | { | 612 | { |
612 | GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk, | 613 | GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk, |
613 | &ego->pub); | 614 | &ego->pub); |
614 | ego->pub_initialized = true; | 615 | ego->pub_initialized = GNUNET_YES; |
615 | } | 616 | } |
616 | *pk = ego->pub; | 617 | *pk = ego->pub; |
617 | } | 618 | } |
@@ -714,6 +715,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | |||
714 | * | 715 | * |
715 | * @param h identity service to use | 716 | * @param h identity service to use |
716 | * @param name desired name | 717 | * @param name desired name |
718 | * @param privkey desired private key or NULL to create one | ||
717 | * @param cont function to call with the result (will only be called once) | 719 | * @param cont function to call with the result (will only be called once) |
718 | * @param cont_cls closure for @a cont | 720 | * @param cont_cls closure for @a cont |
719 | * @return handle to abort the operation | 721 | * @return handle to abort the operation |
@@ -721,6 +723,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | |||
721 | struct GNUNET_IDENTITY_Operation * | 723 | struct GNUNET_IDENTITY_Operation * |
722 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | 724 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, |
723 | const char *name, | 725 | const char *name, |
726 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey, | ||
724 | GNUNET_IDENTITY_CreateContinuation cont, | 727 | GNUNET_IDENTITY_CreateContinuation cont, |
725 | void *cont_cls) | 728 | void *cont_cls) |
726 | { | 729 | { |
@@ -745,7 +748,10 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
745 | env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); | 748 | env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); |
746 | crm->name_len = htons (slen); | 749 | crm->name_len = htons (slen); |
747 | crm->reserved = htons (0); | 750 | crm->reserved = htons (0); |
748 | GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key); | 751 | if (NULL == privkey) |
752 | GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key); | ||
753 | else | ||
754 | crm->private_key = *privkey; | ||
749 | op->pk = crm->private_key; | 755 | op->pk = crm->private_key; |
750 | GNUNET_memcpy (&crm[1], name, slen); | 756 | GNUNET_memcpy (&crm[1], name, slen); |
751 | GNUNET_MQ_send (h->mq, env); | 757 | GNUNET_MQ_send (h->mq, env); |
diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c index 6c61d3977..26b1eacd7 100644 --- a/src/identity/identity_api_lookup.c +++ b/src/identity/identity_api_lookup.c | |||
@@ -130,6 +130,7 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
130 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 130 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
131 | struct GNUNET_HashCode id; | 131 | struct GNUNET_HashCode id; |
132 | struct GNUNET_IDENTITY_Ego ego; | 132 | struct GNUNET_IDENTITY_Ego ego; |
133 | memset (&ego, 0, sizeof (ego)); | ||
133 | 134 | ||
134 | GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); | 135 | GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); |
135 | GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); | 136 | GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); |
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 97a7bf513..009a01f16 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -57,6 +57,11 @@ | |||
57 | #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" | 57 | #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Parameter private key | ||
61 | */ | ||
62 | #define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" | ||
63 | |||
64 | /** | ||
60 | * Parameter subsystem | 65 | * Parameter subsystem |
61 | */ | 66 | */ |
62 | #define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM "subsystem" | 67 | #define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM "subsystem" |
@@ -463,9 +468,11 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
463 | struct RequestHandle *handle = cls; | 468 | struct RequestHandle *handle = cls; |
464 | struct EgoEntry *ego_entry; | 469 | struct EgoEntry *ego_entry; |
465 | struct MHD_Response *resp; | 470 | struct MHD_Response *resp; |
471 | struct GNUNET_HashCode key; | ||
466 | json_t *json_root; | 472 | json_t *json_root; |
467 | json_t *json_ego; | 473 | json_t *json_ego; |
468 | char *result_str; | 474 | char *result_str; |
475 | char *privkey_str; | ||
469 | 476 | ||
470 | json_root = json_array (); | 477 | json_root = json_array (); |
471 | // Return ego/egos | 478 | // Return ego/egos |
@@ -476,6 +483,19 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
476 | json_object_set_new (json_ego, | 483 | json_object_set_new (json_ego, |
477 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, | 484 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, |
478 | json_string (ego_entry->keystring)); | 485 | json_string (ego_entry->keystring)); |
486 | GNUNET_CRYPTO_hash ("private", strlen ("private"), &key); | ||
487 | if (GNUNET_YES == | ||
488 | GNUNET_CONTAINER_multihashmap_contains ( | ||
489 | handle->rest_handle->url_param_map, &key)) | ||
490 | { | ||
491 | privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string ( | ||
492 | GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); | ||
493 | json_object_set_new (json_ego, | ||
494 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, | ||
495 | json_string (privkey_str)); | ||
496 | GNUNET_free (privkey_str); | ||
497 | } | ||
498 | |||
479 | json_object_set_new (json_ego, | 499 | json_object_set_new (json_ego, |
480 | GNUNET_REST_IDENTITY_PARAM_NAME, | 500 | GNUNET_REST_IDENTITY_PARAM_NAME, |
481 | json_string (ego_entry->identifier)); | 501 | json_string (ego_entry->identifier)); |
@@ -504,8 +524,10 @@ void | |||
504 | ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) | 524 | ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) |
505 | { | 525 | { |
506 | struct MHD_Response *resp; | 526 | struct MHD_Response *resp; |
527 | struct GNUNET_HashCode key; | ||
507 | json_t *json_ego; | 528 | json_t *json_ego; |
508 | char *result_str; | 529 | char *result_str; |
530 | char *privkey_str; | ||
509 | 531 | ||
510 | json_ego = json_object (); | 532 | json_ego = json_object (); |
511 | json_object_set_new (json_ego, | 533 | json_object_set_new (json_ego, |
@@ -514,6 +536,18 @@ ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
514 | json_object_set_new (json_ego, | 536 | json_object_set_new (json_ego, |
515 | GNUNET_REST_IDENTITY_PARAM_NAME, | 537 | GNUNET_REST_IDENTITY_PARAM_NAME, |
516 | json_string (ego_entry->identifier)); | 538 | json_string (ego_entry->identifier)); |
539 | GNUNET_CRYPTO_hash ("private", strlen ("private"), &key); | ||
540 | if (GNUNET_YES == | ||
541 | GNUNET_CONTAINER_multihashmap_contains ( | ||
542 | handle->rest_handle->url_param_map, &key)) | ||
543 | { | ||
544 | privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string ( | ||
545 | GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); | ||
546 | json_object_set_new (json_ego, | ||
547 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, | ||
548 | json_string (privkey_str)); | ||
549 | GNUNET_free (privkey_str); | ||
550 | } | ||
517 | 551 | ||
518 | result_str = json_dumps (json_ego, 0); | 552 | result_str = json_dumps (json_ego, 0); |
519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 553 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
@@ -956,6 +990,9 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
956 | json_t *data_js; | 990 | json_t *data_js; |
957 | json_error_t err; | 991 | json_error_t err; |
958 | char *egoname; | 992 | char *egoname; |
993 | char *privkey; | ||
994 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | ||
995 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk_ptr; | ||
959 | int json_unpack_state; | 996 | int json_unpack_state; |
960 | char term_data[handle->data_size + 1]; | 997 | char term_data[handle->data_size + 1]; |
961 | 998 | ||
@@ -982,8 +1019,11 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
982 | return; | 1019 | return; |
983 | } | 1020 | } |
984 | json_unpack_state = 0; | 1021 | json_unpack_state = 0; |
1022 | privkey = NULL; | ||
985 | json_unpack_state = | 1023 | json_unpack_state = |
986 | json_unpack (data_js, "{s:s!}", GNUNET_REST_IDENTITY_PARAM_NAME, &egoname); | 1024 | json_unpack (data_js, "{s:s, s?:s!}", |
1025 | GNUNET_REST_IDENTITY_PARAM_NAME, &egoname, | ||
1026 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, &privkey); | ||
987 | if (0 != json_unpack_state) | 1027 | if (0 != json_unpack_state) |
988 | { | 1028 | { |
989 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 1029 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
@@ -1020,10 +1060,21 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1020 | } | 1060 | } |
1021 | } | 1061 | } |
1022 | handle->name = GNUNET_strdup (egoname); | 1062 | handle->name = GNUNET_strdup (egoname); |
1063 | if (NULL != privkey) | ||
1064 | { | ||
1065 | GNUNET_STRINGS_string_to_data (privkey, | ||
1066 | strlen (privkey), | ||
1067 | &pk, | ||
1068 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
1069 | pk_ptr = &pk; | ||
1070 | } | ||
1071 | else | ||
1072 | pk_ptr = NULL; | ||
1023 | json_decref (data_js); | 1073 | json_decref (data_js); |
1024 | handle->response_code = MHD_HTTP_CREATED; | 1074 | handle->response_code = MHD_HTTP_CREATED; |
1025 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 1075 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, |
1026 | handle->name, | 1076 | handle->name, |
1077 | pk_ptr, | ||
1027 | &do_finished_create, | 1078 | &do_finished_create, |
1028 | handle); | 1079 | handle); |
1029 | } | 1080 | } |
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c index aaa435d4f..37eeab238 100644 --- a/src/identity/test_identity.c +++ b/src/identity/test_identity.c | |||
@@ -279,7 +279,7 @@ run (void *cls, | |||
279 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | 279 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
280 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | 280 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); |
281 | CHECK (NULL != h); | 281 | CHECK (NULL != h); |
282 | op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); | 282 | op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL); |
283 | } | 283 | } |
284 | 284 | ||
285 | 285 | ||
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c index 1dd05f1b9..53eec1252 100644 --- a/src/identity/test_identity_defaults.c +++ b/src/identity/test_identity_defaults.c | |||
@@ -266,7 +266,7 @@ run_set (void *cls, | |||
266 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | 266 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
267 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | 267 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); |
268 | CHECK (NULL != h); | 268 | CHECK (NULL != h); |
269 | op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); | 269 | op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL); |
270 | } | 270 | } |
271 | 271 | ||
272 | 272 | ||
diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h index 2f715ec97..687334c1c 100644 --- a/src/include/gnunet_bio_lib.h +++ b/src/include/gnunet_bio_lib.h | |||
@@ -42,6 +42,8 @@ extern "C" | |||
42 | #endif | 42 | #endif |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | /****************************** READING API *******************************/ | ||
46 | |||
45 | /** | 47 | /** |
46 | * Handle for buffered reading. | 48 | * Handle for buffered reading. |
47 | */ | 49 | */ |
@@ -55,11 +57,22 @@ struct GNUNET_BIO_ReadHandle; | |||
55 | * @return IO handle on success, NULL on error | 57 | * @return IO handle on success, NULL on error |
56 | */ | 58 | */ |
57 | struct GNUNET_BIO_ReadHandle * | 59 | struct GNUNET_BIO_ReadHandle * |
58 | GNUNET_BIO_read_open (const char *fn); | 60 | GNUNET_BIO_read_open_file (const char *fn); |
61 | |||
62 | |||
63 | /** | ||
64 | * Create a handle from an existing allocated buffer. | ||
65 | * | ||
66 | * @param buffer the buffer to use as source | ||
67 | * @param size the total size in bytes of the buffer | ||
68 | * @return IO handle on sucess, NULL on error | ||
69 | */ | ||
70 | struct GNUNET_BIO_ReadHandle * | ||
71 | GNUNET_BIO_read_open_buffer (void *buffer, size_t size); | ||
59 | 72 | ||
60 | 73 | ||
61 | /** | 74 | /** |
62 | * Close an open file. Reports if any errors reading | 75 | * Close an open handle. Reports if any errors reading |
63 | * from the file were encountered. | 76 | * from the file were encountered. |
64 | * | 77 | * |
65 | * @param h file handle | 78 | * @param h file handle |
@@ -71,51 +84,40 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg); | |||
71 | 84 | ||
72 | 85 | ||
73 | /** | 86 | /** |
74 | * Read the contents of a binary file into a buffer. | 87 | * Read some contents into a buffer. |
75 | * | 88 | * |
76 | * @param h handle to an open file | 89 | * @param h the IO handle to read from |
77 | * @param what describes what is being read (for error message creation) | 90 | * @param what describes what is being read (for error message creation) |
78 | * @param result the buffer to write the result to | 91 | * @param result the buffer to write the result to |
79 | * @param len the number of bytes to read | 92 | * @param len the number of bytes to read |
80 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 93 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
81 | */ | 94 | */ |
82 | int | 95 | int |
83 | GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, | 96 | GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, |
84 | void *result, size_t len); | 97 | const char *what, |
98 | void *result, | ||
99 | size_t len); | ||
85 | 100 | ||
86 | 101 | ||
87 | /** | 102 | /** |
88 | * Read the contents of a binary file into a buffer. | 103 | * Read 0-terminated string. |
89 | * | 104 | * |
90 | * @param h handle to an open file | 105 | * @param h the IO handle to read from |
91 | * @param file name of the source file | ||
92 | * @param line line number in the source file | ||
93 | * @param result the buffer to write the result to | ||
94 | * @param len the number of bytes to read | ||
95 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | ||
96 | */ | ||
97 | int | ||
98 | GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, | ||
99 | const char *file, int line, | ||
100 | void *result, size_t len); | ||
101 | |||
102 | /** | ||
103 | * Read 0-terminated string from a file. | ||
104 | * | ||
105 | * @param h handle to an open file | ||
106 | * @param what describes what is being read (for error message creation) | 106 | * @param what describes what is being read (for error message creation) |
107 | * @param result the buffer to store a pointer to the (allocated) string to | 107 | * @param result where to store the pointer to the (allocated) string |
108 | * (note that *result could be set to NULL as well) | 108 | * (note that *result could be set to NULL as well) |
109 | * @param max_length maximum allowed length for the string | 109 | * @param max_length maximum allowed length for the string |
110 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 110 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
111 | */ | 111 | */ |
112 | int | 112 | int |
113 | GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, | 113 | GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, |
114 | char **result, size_t max_length); | 114 | const char *what, |
115 | char **result, | ||
116 | size_t max_length); | ||
115 | 117 | ||
116 | 118 | ||
117 | /** | 119 | /** |
118 | * Read metadata container from a file. | 120 | * Read a metadata container. |
119 | * | 121 | * |
120 | * @param h handle to an open file | 122 | * @param h handle to an open file |
121 | * @param what describes what is being read (for error message creation) | 123 | * @param what describes what is being read (for error message creation) |
@@ -123,79 +125,69 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, | |||
123 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 125 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
124 | */ | 126 | */ |
125 | int | 127 | int |
126 | GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, | 128 | GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, |
129 | const char *what, | ||
127 | struct GNUNET_CONTAINER_MetaData **result); | 130 | struct GNUNET_CONTAINER_MetaData **result); |
128 | 131 | ||
129 | 132 | ||
130 | /** | 133 | /** |
131 | * Read a float. | 134 | * Read a float. |
132 | * | 135 | * |
133 | * @param h hande to open file | 136 | * @param h the IO handle to read from |
137 | * @param what describes what is being read (for error message creation) | ||
134 | * @param f address of float to read | 138 | * @param f address of float to read |
135 | */ | 139 | */ |
136 | #define GNUNET_BIO_read_float(h, f) (GNUNET_BIO_read_fn (h, __FILE__, __LINE__, \ | 140 | int |
137 | f, sizeof(float))) | 141 | GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h, |
142 | const char *what, | ||
143 | float *f); | ||
138 | 144 | ||
139 | 145 | ||
140 | /** | 146 | /** |
141 | * Read a double. | 147 | * Read a double. |
142 | * | 148 | * |
143 | * @param h hande to open file | 149 | * @param h the IO handle to read from |
150 | * @param what describes what is being read (for error message creation) | ||
144 | * @param f address of double to read | 151 | * @param f address of double to read |
145 | */ | 152 | */ |
146 | #define GNUNET_BIO_read_double(h, f) (GNUNET_BIO_read_fn (h, __FILE__, __LINE__, \ | 153 | int |
147 | f, sizeof(double))) | 154 | GNUNET_BIO_read_double(struct GNUNET_BIO_ReadHandle *h, |
155 | const char *what, | ||
156 | double *f); | ||
157 | |||
148 | 158 | ||
149 | 159 | ||
150 | /** | 160 | /** |
151 | * Read an (u)int32_t. | 161 | * Read an (u)int32_t. |
152 | * | 162 | * |
153 | * @param h hande to open file | 163 | * @param h the IO handle to read from |
154 | * @param file name of the source file | 164 | * @param what describes what is being read (for error message creation) |
155 | * @param line line number in the code | 165 | * @param i where to store the data |
156 | * @param i address of 32-bit integer to read | ||
157 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 166 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
158 | */ | 167 | */ |
159 | int | 168 | int |
160 | GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file, | 169 | GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, |
161 | int line, int32_t *i); | 170 | const char *what, |
162 | 171 | int32_t *i); | |
163 | 172 | ||
164 | /** | ||
165 | * Read an (u)int32_t. | ||
166 | * | ||
167 | * @param h hande to open file | ||
168 | * @param i address of 32-bit integer to read | ||
169 | */ | ||
170 | #define GNUNET_BIO_read_int32(h, i) GNUNET_BIO_read_int32__ (h, __FILE__, \ | ||
171 | __LINE__, \ | ||
172 | (int32_t *) i) | ||
173 | 173 | ||
174 | 174 | ||
175 | /** | 175 | /** |
176 | * Read an (u)int64_t. | 176 | * Read an (u)int64_t. |
177 | * | 177 | * |
178 | * @param h hande to open file | 178 | * @param h the IO handle to read from |
179 | * @param file name of the source file | 179 | * @param what describes what is being read (for error message creation) |
180 | * @param line line number in the code | 180 | * @param i where to store the data |
181 | * @param i address of 64-bit integer to read | ||
182 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 181 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
183 | */ | 182 | */ |
184 | int | 183 | int |
185 | GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file, | 184 | GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h, |
186 | int line, int64_t *i); | 185 | const char *what, |
186 | int64_t *i); | ||
187 | 187 | ||
188 | 188 | ||
189 | /** | ||
190 | * Read an (u)int64_t. | ||
191 | * | ||
192 | * @param h hande to open file | ||
193 | * @param i address of 64-bit integer to read | ||
194 | */ | ||
195 | #define GNUNET_BIO_read_int64(h, i) GNUNET_BIO_read_int64__ (h, __FILE__, \ | ||
196 | __LINE__, \ | ||
197 | (int64_t *) i) | ||
198 | 189 | ||
190 | /****************************** WRITING API *******************************/ | ||
199 | 191 | ||
200 | /** | 192 | /** |
201 | * Handle for buffered writing. | 193 | * Handle for buffered writing. |
@@ -205,108 +197,481 @@ struct GNUNET_BIO_WriteHandle; | |||
205 | /** | 197 | /** |
206 | * Open a file for writing. | 198 | * Open a file for writing. |
207 | * | 199 | * |
208 | * @param fn file name to be opened | 200 | * @param fn name of the file to be opened |
209 | * @return IO handle on success, NULL on error | 201 | * @return IO handle on success, NULL on error |
210 | */ | 202 | */ |
211 | struct GNUNET_BIO_WriteHandle * | 203 | struct GNUNET_BIO_WriteHandle * |
212 | GNUNET_BIO_write_open (const char *fn); | 204 | GNUNET_BIO_write_open_file (const char *fn); |
213 | 205 | ||
214 | 206 | ||
215 | /** | 207 | /** |
216 | * Close an open file for writing. | 208 | * Create a handle backed by an in-memory buffer. |
217 | * | 209 | * |
218 | * @param h file handle | 210 | * @return IO handle on success, NULL on error |
219 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | 211 | */ |
212 | struct GNUNET_BIO_WriteHandle * | ||
213 | GNUNET_BIO_write_open_buffer (void); | ||
214 | |||
215 | |||
216 | /** | ||
217 | * Force a file-based buffered writer to flush its buffer. | ||
218 | * If the handle does not use a file, this function returs #GNUNET_OK | ||
219 | * without doing anything. | ||
220 | * | ||
221 | * @param h the IO handle | ||
222 | * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned | ||
223 | * and the file is closed | ||
220 | */ | 224 | */ |
221 | int | 225 | int |
222 | GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h); | 226 | GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h); |
223 | 227 | ||
224 | 228 | ||
225 | /** | 229 | /** |
226 | * Write a buffer to a file. | 230 | * Get the IO handle's contents. |
231 | * If the handle doesn't use an in-memory buffer, this function returns | ||
232 | * #GNUNET_SYSERR. | ||
227 | * | 233 | * |
228 | * @param h handle to open file | 234 | * @param h the IO handle |
229 | * @param buffer the data to write | 235 | * @param emsg set to the (allocated) error message |
230 | * @param n number of bytes to write | 236 | * if the handle has an error message the return value is #GNUNET_SYSERR |
231 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 237 | * @param contents where to store the pointer to the handle's contents |
238 | * @param size where to store the size of @e contents | ||
239 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
232 | */ | 240 | */ |
233 | int | 241 | int |
234 | GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, | 242 | GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, |
235 | size_t n); | 243 | char **emsg, |
244 | void **contents, | ||
245 | size_t *size); | ||
246 | |||
247 | |||
248 | /** | ||
249 | * Close an IO handle. | ||
250 | * If the handle was using a file, the file will be closed. | ||
251 | * | ||
252 | * @param h file handle | ||
253 | * @param emsg set to the (allocated) error message | ||
254 | * if the handle has an error message, the return value is #GNUNET_SYSERR | ||
255 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
256 | */ | ||
257 | int | ||
258 | GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg); | ||
236 | 259 | ||
237 | 260 | ||
238 | /** | 261 | /** |
239 | * Force a buffered writer to flush its buffer | 262 | * Write a buffer to a handle. |
240 | * | 263 | * |
241 | * @param h the writer handle | 264 | * @param h the IO handle to write to |
242 | * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned and | 265 | * @param what what is being written (for error message creation) |
243 | * the file is closed | 266 | * @param buffer the data to write |
267 | * @param n number of bytes to write | ||
268 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
244 | */ | 269 | */ |
245 | int | 270 | int |
246 | GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h); | 271 | GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, |
272 | const char *what, | ||
273 | const void *buffer, | ||
274 | size_t n); | ||
247 | 275 | ||
248 | 276 | ||
249 | /** | 277 | /** |
250 | * Write a string to a file. | 278 | * Write a 0-terminated string. |
251 | * | 279 | * |
252 | * @param h handle to open file | 280 | * @param h the IO handle to write to |
281 | * @param what what is being written (for error message creation) | ||
253 | * @param s string to write (can be NULL) | 282 | * @param s string to write (can be NULL) |
254 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 283 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
255 | */ | 284 | */ |
256 | int | 285 | int |
257 | GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s); | 286 | GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, |
287 | const char *what, | ||
288 | const char *s); | ||
258 | 289 | ||
259 | 290 | ||
260 | /** | 291 | /** |
261 | * Write metadata container to a file. | 292 | * Write a metadata container. |
262 | * | 293 | * |
263 | * @param h handle to open file | 294 | * @param h the IO handle to write to |
295 | * @param what what is being written (for error message creation) | ||
264 | * @param m metadata to write | 296 | * @param m metadata to write |
265 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 297 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
266 | */ | 298 | */ |
267 | int | 299 | int |
268 | GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, | 300 | GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, |
301 | const char *what, | ||
269 | const struct GNUNET_CONTAINER_MetaData *m); | 302 | const struct GNUNET_CONTAINER_MetaData *m); |
270 | 303 | ||
271 | 304 | ||
272 | /** | 305 | /** |
273 | * Write a float. | 306 | * Write a float. |
274 | * | 307 | * |
275 | * @param h hande to open file | 308 | * @param h the IO handle to write to |
309 | * @param what what is being written (for error message creation) | ||
276 | * @param f float to write (must be a variable) | 310 | * @param f float to write (must be a variable) |
277 | */ | 311 | */ |
278 | #define GNUNET_BIO_write_float(h, f) GNUNET_BIO_write (h, &f, sizeof(float)) | 312 | int |
279 | 313 | GNUNET_BIO_write_float(struct GNUNET_BIO_WriteHandle *h, | |
314 | const char *what, | ||
315 | float f); | ||
280 | 316 | ||
281 | /** | 317 | /** |
282 | * Write a double. | 318 | * Write a double. |
283 | * | 319 | * |
284 | * @param h hande to open file | 320 | * @param h the IO handle to write to |
321 | * @param what what is being written (for error message creation) | ||
285 | * @param f double to write (must be a variable) | 322 | * @param f double to write (must be a variable) |
286 | */ | 323 | */ |
287 | #define GNUNET_BIO_write_double(h, f) GNUNET_BIO_write (h, &f, sizeof(double)) | 324 | int |
325 | GNUNET_BIO_write_double(struct GNUNET_BIO_WriteHandle *h, | ||
326 | const char *what, | ||
327 | double f); | ||
288 | 328 | ||
289 | 329 | ||
290 | /** | 330 | /** |
291 | * Write an (u)int32_t. | 331 | * Write an (u)int32_t. |
292 | * | 332 | * |
293 | * @param h hande to open file | 333 | * @param h the IO handle to write to |
334 | * @param what what is being written (for error message creation) | ||
294 | * @param i 32-bit integer to write | 335 | * @param i 32-bit integer to write |
295 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 336 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
296 | */ | 337 | */ |
297 | int | 338 | int |
298 | GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i); | 339 | GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, |
340 | const char *what, | ||
341 | int32_t i); | ||
299 | 342 | ||
300 | 343 | ||
301 | /** | 344 | /** |
302 | * Write an (u)int64_t. | 345 | * Write an (u)int64_t. |
303 | * | 346 | * |
304 | * @param h hande to open file | 347 | * @param h the IO handle to write to |
348 | * @param what what is being written (for error message creation) | ||
305 | * @param i 64-bit integer to write | 349 | * @param i 64-bit integer to write |
306 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 350 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
307 | */ | 351 | */ |
308 | int | 352 | int |
309 | GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i); | 353 | GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, |
354 | const char *what, | ||
355 | int64_t i); | ||
356 | |||
357 | |||
358 | /****************************** READ SPEC API ***************************/ | ||
359 | |||
360 | |||
361 | /** | ||
362 | * Function used to deserialize data read from @a h and store it into @a | ||
363 | * target. | ||
364 | * | ||
365 | * @param cls closure (can be NULL) | ||
366 | * @param h the IO handle to read from | ||
367 | * @param what what is being read (for error message creation) | ||
368 | * @param target where to store the data | ||
369 | * @param target_size how many bytes can be written in @a target | ||
370 | * can be 0 if the size is unknown or is not fixed | ||
371 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
372 | */ | ||
373 | typedef int | ||
374 | (*GNUNET_BIO_ReadHandler)(void *cls, | ||
375 | struct GNUNET_BIO_ReadHandle *h, | ||
376 | const char *what, | ||
377 | void *target, | ||
378 | size_t target_size); | ||
379 | |||
380 | |||
381 | /** | ||
382 | * Structure specifying a reading operation on an IO handle. | ||
383 | */ | ||
384 | struct GNUNET_BIO_ReadSpec | ||
385 | { | ||
386 | /** | ||
387 | * Function performing data deserialization. | ||
388 | */ | ||
389 | GNUNET_BIO_ReadHandler rh; | ||
390 | |||
391 | /** | ||
392 | * Closure for @e rh. Can be NULL. | ||
393 | */ | ||
394 | void *cls; | ||
395 | |||
396 | /** | ||
397 | * What is being read (for error message creation) | ||
398 | */ | ||
399 | const char *what; | ||
400 | |||
401 | /** | ||
402 | * Destination buffer. Can also be a pointer to a pointer, especially for | ||
403 | * dynamically allocated structures. | ||
404 | */ | ||
405 | void *target; | ||
406 | |||
407 | /** | ||
408 | * Size of @e target. Can be 0 if unknown or not fixed. | ||
409 | */ | ||
410 | size_t size; | ||
411 | }; | ||
412 | |||
413 | |||
414 | /** | ||
415 | * End of specifications marker. | ||
416 | */ | ||
417 | #define GNUNET_BIO_read_spec_end() \ | ||
418 | { NULL, NULL, NULL, NULL, 0 } | ||
419 | |||
420 | |||
421 | /** | ||
422 | * Create the specification to read a certain amount of bytes. | ||
423 | * | ||
424 | * @param what describes what is being read (for error message creation) | ||
425 | * @param result the buffer to write the result to | ||
426 | * @param len the number of bytes to read | ||
427 | * @return the read spec | ||
428 | */ | ||
429 | struct GNUNET_BIO_ReadSpec | ||
430 | GNUNET_BIO_read_spec_object (const char *what, | ||
431 | void *result, | ||
432 | size_t size); | ||
433 | |||
434 | |||
435 | /** | ||
436 | * Create the specification to read a 0-terminated string. | ||
437 | * | ||
438 | * @param what describes what is being read (for error message creation) | ||
439 | * @param result where to store the pointer to the (allocated) string | ||
440 | * (note that *result could be set to NULL as well) | ||
441 | * @param max_length maximum allowed length for the string | ||
442 | * @return the read spec | ||
443 | */ | ||
444 | struct GNUNET_BIO_ReadSpec | ||
445 | GNUNET_BIO_read_spec_string (const char *what, | ||
446 | char **result, | ||
447 | size_t max_length); | ||
448 | |||
449 | |||
450 | /** | ||
451 | * Create the specification to read a metadata container. | ||
452 | * | ||
453 | * @param what describes what is being read (for error message creation) | ||
454 | * @param result the buffer to store a pointer to the (allocated) metadata | ||
455 | * @return the read spec | ||
456 | */ | ||
457 | struct GNUNET_BIO_ReadSpec | ||
458 | GNUNET_BIO_read_spec_meta_data (const char *what, | ||
459 | struct GNUNET_CONTAINER_MetaData **result); | ||
460 | |||
461 | |||
462 | /** | ||
463 | * Create the specification to read an (u)int32_t. | ||
464 | * | ||
465 | * @param what describes what is being read (for error message creation) | ||
466 | * @param i where to store the data | ||
467 | * @return the read spec | ||
468 | */ | ||
469 | struct GNUNET_BIO_ReadSpec | ||
470 | GNUNET_BIO_read_spec_int32 (const char *what, | ||
471 | int32_t *i); | ||
472 | |||
473 | |||
474 | /** | ||
475 | * Create the specification to read an (u)int64_t. | ||
476 | * | ||
477 | * @param what describes what is being read (for error message creation) | ||
478 | * @param i where to store the data | ||
479 | * @return the read spec | ||
480 | */ | ||
481 | struct GNUNET_BIO_ReadSpec | ||
482 | GNUNET_BIO_read_spec_int64 (const char *what, | ||
483 | int64_t *i); | ||
484 | |||
485 | |||
486 | /** | ||
487 | * Create the specification to read a float. | ||
488 | * | ||
489 | * @param what describes what is being read (for error message creation) | ||
490 | * @param f address of float to read | ||
491 | */ | ||
492 | struct GNUNET_BIO_ReadSpec | ||
493 | GNUNET_BIO_read_spec_float(const char *what, float *f); | ||
494 | |||
495 | |||
496 | /** | ||
497 | * Create the specification to read a double. | ||
498 | * | ||
499 | * @param what describes what is being read (for error message creation) | ||
500 | * @param f address of double to read | ||
501 | */ | ||
502 | struct GNUNET_BIO_ReadSpec | ||
503 | GNUNET_BIO_read_spec_double(const char *what, double *f); | ||
504 | |||
505 | |||
506 | /** | ||
507 | * Execute the read specifications in order. | ||
508 | * | ||
509 | * @param h the IO handle to read from | ||
510 | * @param rs array of read specs | ||
511 | * the last element must be #GNUNET_BIO_read_spec_end | ||
512 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
513 | */ | ||
514 | int | ||
515 | GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h, | ||
516 | struct GNUNET_BIO_ReadSpec *rs); | ||
517 | |||
518 | |||
519 | /******************************* WRITE SPEC API *****************************/ | ||
520 | |||
521 | |||
522 | /** | ||
523 | * Function used to serialize data from a buffer and write it to @a h. | ||
524 | * | ||
525 | * @param cls closure (can be NULL) | ||
526 | * @param h the IO handle to write to | ||
527 | * @param what what is being written (for error message creation) | ||
528 | * @param source the data to write | ||
529 | * @param source_size how many bytes should be written | ||
530 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
531 | */ | ||
532 | typedef int | ||
533 | (*GNUNET_BIO_WriteHandler) (void *cls, | ||
534 | struct GNUNET_BIO_WriteHandle *h, | ||
535 | const char *what, | ||
536 | void *source, | ||
537 | size_t source_size); | ||
538 | |||
539 | |||
540 | /** | ||
541 | * Structure specifying a writing operation on an IO handle. | ||
542 | */ | ||
543 | struct GNUNET_BIO_WriteSpec | ||
544 | { | ||
545 | /** | ||
546 | * Function performing data serialization. | ||
547 | */ | ||
548 | GNUNET_BIO_WriteHandler wh; | ||
549 | |||
550 | /** | ||
551 | * Closure for @e rh. Can be NULL. | ||
552 | */ | ||
553 | void *cls; | ||
554 | |||
555 | /** | ||
556 | * What is being read (for error message creation) | ||
557 | */ | ||
558 | const char *what; | ||
559 | |||
560 | /** | ||
561 | * Source buffer. The data in this buffer will be written to the handle. | ||
562 | */ | ||
563 | void *source; | ||
564 | |||
565 | /** | ||
566 | * Size of @e source. If it's smaller than the real size of @e source, only | ||
567 | * this many bytes will be written. | ||
568 | */ | ||
569 | size_t source_size; | ||
570 | }; | ||
571 | |||
572 | |||
573 | /** | ||
574 | * End of specifications marker. | ||
575 | */ | ||
576 | #define GNUNET_BIO_write_spec_end() \ | ||
577 | { NULL, NULL, NULL, NULL, 0 } | ||
578 | |||
579 | |||
580 | /** | ||
581 | * Create the specification to read some bytes. | ||
582 | * | ||
583 | * @param what describes what is being written (for error message creation) | ||
584 | * @param source the data to write | ||
585 | * @param size how many bytes should be written | ||
586 | * @return the write spec | ||
587 | */ | ||
588 | struct GNUNET_BIO_WriteSpec | ||
589 | GNUNET_BIO_write_spec_object (const char *what, | ||
590 | void *source, | ||
591 | size_t size); | ||
592 | |||
593 | |||
594 | /** | ||
595 | * Create the specification to write a 0-terminated string. | ||
596 | * | ||
597 | * @param what describes what is being read (for error message creation) | ||
598 | * @param s string to write (can be NULL) | ||
599 | * @return the read spec | ||
600 | */ | ||
601 | struct GNUNET_BIO_WriteSpec | ||
602 | GNUNET_BIO_write_spec_string (const char *what, | ||
603 | const char *s); | ||
604 | |||
605 | |||
606 | /** | ||
607 | * Create the specification to write a metadata container. | ||
608 | * | ||
609 | * @param what what is being written (for error message creation) | ||
610 | * @param m metadata to write | ||
611 | * @return the write spec | ||
612 | */ | ||
613 | struct GNUNET_BIO_WriteSpec | ||
614 | GNUNET_BIO_write_spec_meta_data (const char *what, | ||
615 | const struct GNUNET_CONTAINER_MetaData *m); | ||
616 | |||
617 | |||
618 | /** | ||
619 | * Create the specification to write an (u)int32_t. | ||
620 | * | ||
621 | * @param what describes what is being written (for error message creation) | ||
622 | * @param i pointer to a 32-bit integer | ||
623 | * @return the write spec | ||
624 | */ | ||
625 | struct GNUNET_BIO_WriteSpec | ||
626 | GNUNET_BIO_write_spec_int32 (const char *what, | ||
627 | int32_t *i); | ||
628 | |||
629 | |||
630 | /** | ||
631 | * Create the specification to write an (u)int64_t. | ||
632 | * | ||
633 | * @param what describes what is being written (for error message creation) | ||
634 | * @param i pointer to a 64-bit integer | ||
635 | * @return the write spec | ||
636 | */ | ||
637 | struct GNUNET_BIO_WriteSpec | ||
638 | GNUNET_BIO_write_spec_int64 (const char *what, | ||
639 | int64_t *i); | ||
640 | |||
641 | |||
642 | /** | ||
643 | * Create the specification to write a float. | ||
644 | * | ||
645 | * @param what describes what is being written (for error message creation) | ||
646 | * @param f pointer to a float | ||
647 | * @return the write spec | ||
648 | */ | ||
649 | struct GNUNET_BIO_WriteSpec | ||
650 | GNUNET_BIO_write_spec_float(const char *what, float *f); | ||
651 | |||
652 | |||
653 | /** | ||
654 | * Create the specification to write an double. | ||
655 | * | ||
656 | * @param what describes what is being written (for error message creation) | ||
657 | * @param f pointer to a double | ||
658 | * @return the write spec | ||
659 | */ | ||
660 | struct GNUNET_BIO_WriteSpec | ||
661 | GNUNET_BIO_write_spec_double(const char *what, double *f); | ||
662 | |||
663 | |||
664 | /** | ||
665 | * Execute the write specifications in order. | ||
666 | * | ||
667 | * @param h the IO handle to write to | ||
668 | * @param ws array of write specs | ||
669 | * the last element must be #GNUNET_BIO_write_spec_end | ||
670 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
671 | */ | ||
672 | int | ||
673 | GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h, | ||
674 | struct GNUNET_BIO_WriteSpec *ws); | ||
310 | 675 | ||
311 | 676 | ||
312 | #if 0 /* keep Emacsens' auto-indent happy */ | 677 | #if 0 /* keep Emacsens' auto-indent happy */ |
diff --git a/src/include/gnunet_buffer_lib.h b/src/include/gnunet_buffer_lib.h index c0ae06d77..e23536ab2 100644 --- a/src/include/gnunet_buffer_lib.h +++ b/src/include/gnunet_buffer_lib.h | |||
@@ -165,6 +165,19 @@ GNUNET_buffer_reap_str (struct GNUNET_Buffer *buf); | |||
165 | 165 | ||
166 | 166 | ||
167 | /** | 167 | /** |
168 | * Clear the buffer and return its contents. | ||
169 | * The caller is responsible to eventually #GNUNET_free | ||
170 | * the returned data. | ||
171 | * | ||
172 | * @param buf the buffer to reap the contents from | ||
173 | * @param size where to store the size of the returned data | ||
174 | * @returns the data contained in the string | ||
175 | */ | ||
176 | void * | ||
177 | GNUNET_buffer_reap (struct GNUNET_Buffer *buf, size_t *size); | ||
178 | |||
179 | |||
180 | /** | ||
168 | * Free the backing memory of the given buffer. | 181 | * Free the backing memory of the given buffer. |
169 | * Does not free the memory of the buffer control structure, | 182 | * Does not free the memory of the buffer control structure, |
170 | * which is typically stack-allocated. | 183 | * which is typically stack-allocated. |
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index a5a50e749..d11c6b58c 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -659,7 +659,7 @@ GNUNET_CRYPTO_hash (const void *block, | |||
659 | /** | 659 | /** |
660 | * Calculate the 'proof-of-work' hash (an expensive hash). | 660 | * Calculate the 'proof-of-work' hash (an expensive hash). |
661 | * | 661 | * |
662 | * @param salt salt to use in pow calculation | 662 | * @param salt salt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long. |
663 | * @param buf data to hash | 663 | * @param buf data to hash |
664 | * @param buf_len number of bytes in @a buf | 664 | * @param buf_len number of bytes in @a buf |
665 | * @param result where to write the resulting hash | 665 | * @param result where to write the resulting hash |
@@ -874,12 +874,25 @@ GNUNET_CRYPTO_hash_to_aes_key ( | |||
874 | * Obtain a bit from a hashcode. | 874 | * Obtain a bit from a hashcode. |
875 | * | 875 | * |
876 | * @param code the `struct GNUNET_HashCode` to index bit-wise | 876 | * @param code the `struct GNUNET_HashCode` to index bit-wise |
877 | * @param bit index into the hashcode, [0...159] | 877 | * @param bit index into the hashcode, [0...159] where 0 is the leftmost bit |
878 | * (bytes in code interpreted big endian) | ||
878 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | 879 | * @return Bit \a bit from hashcode \a code, -1 for invalid index |
879 | */ | 880 | */ |
880 | int | 881 | int |
881 | GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, | 882 | GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code, |
882 | unsigned int bit); | 883 | unsigned int bit); |
884 | |||
885 | |||
886 | /** | ||
887 | * Obtain a bit from a hashcode. | ||
888 | * @param code the GNUNET_CRYPTO_hash to index bit-wise | ||
889 | * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit | ||
890 | * (bytes in code interpreted little endian) | ||
891 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | ||
892 | */ | ||
893 | int | ||
894 | GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code, | ||
895 | unsigned int bit); | ||
883 | 896 | ||
884 | 897 | ||
885 | /** | 898 | /** |
@@ -2147,8 +2160,8 @@ GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key); | |||
2147 | * @return 0 if the two are equal | 2160 | * @return 0 if the two are equal |
2148 | */ | 2161 | */ |
2149 | int | 2162 | int |
2150 | GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1, | 2163 | GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1, |
2151 | struct GNUNET_CRYPTO_RsaSignature *s2); | 2164 | const struct GNUNET_CRYPTO_RsaSignature *s2); |
2152 | 2165 | ||
2153 | /** | 2166 | /** |
2154 | * Compare the values of two private keys. | 2167 | * Compare the values of two private keys. |
@@ -2158,8 +2171,8 @@ GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1, | |||
2158 | * @return 0 if the two are equal | 2171 | * @return 0 if the two are equal |
2159 | */ | 2172 | */ |
2160 | int | 2173 | int |
2161 | GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1, | 2174 | GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1, |
2162 | struct GNUNET_CRYPTO_RsaPrivateKey *p2); | 2175 | const struct GNUNET_CRYPTO_RsaPrivateKey *p2); |
2163 | 2176 | ||
2164 | 2177 | ||
2165 | /** | 2178 | /** |
@@ -2170,8 +2183,8 @@ GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1, | |||
2170 | * @return 0 if the two are equal | 2183 | * @return 0 if the two are equal |
2171 | */ | 2184 | */ |
2172 | int | 2185 | int |
2173 | GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1, | 2186 | GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1, |
2174 | struct GNUNET_CRYPTO_RsaPublicKey *p2); | 2187 | const struct GNUNET_CRYPTO_RsaPublicKey *p2); |
2175 | 2188 | ||
2176 | 2189 | ||
2177 | /** | 2190 | /** |
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h index 81af671e2..f4e653598 100644 --- a/src/include/gnunet_identity_service.h +++ b/src/include/gnunet_identity_service.h | |||
@@ -233,6 +233,7 @@ typedef void | |||
233 | * | 233 | * |
234 | * @param id identity service to use | 234 | * @param id identity service to use |
235 | * @param name desired name | 235 | * @param name desired name |
236 | * @param privkey desired private key or NULL to create one | ||
236 | * @param cont function to call with the result (will only be called once) | 237 | * @param cont function to call with the result (will only be called once) |
237 | * @param cont_cls closure for @a cont | 238 | * @param cont_cls closure for @a cont |
238 | * @return handle to abort the operation | 239 | * @return handle to abort the operation |
@@ -240,6 +241,7 @@ typedef void | |||
240 | struct GNUNET_IDENTITY_Operation * | 241 | struct GNUNET_IDENTITY_Operation * |
241 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, | 242 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, |
242 | const char *name, | 243 | const char *name, |
244 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey, | ||
243 | GNUNET_IDENTITY_CreateContinuation cont, | 245 | GNUNET_IDENTITY_CreateContinuation cont, |
244 | void *cont_cls); | 246 | void *cont_cls); |
245 | 247 | ||
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index a6188c1ca..b583cc493 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h | |||
@@ -287,6 +287,14 @@ struct GNUNET_OS_ProjectData | |||
287 | * If this field is NULL, the path is automatically inferred. | 287 | * If this field is NULL, the path is automatically inferred. |
288 | */ | 288 | */ |
289 | char *gettext_path; | 289 | char *gettext_path; |
290 | |||
291 | /** | ||
292 | * URL pointing to the source code of the application. Required for AGPL. | ||
293 | * Setting this to NULL disables the built-in mechanism, but you must | ||
294 | * provide it in some other way. If non-NULL, message type 1 and 2 are | ||
295 | * reserved. | ||
296 | */ | ||
297 | char *agpl_url; | ||
290 | }; | 298 | }; |
291 | 299 | ||
292 | 300 | ||
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index e67e35f38..0db6150aa 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -50,25 +50,29 @@ extern "C" { | |||
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | /******************************************************************************* | 52 | /******************************************************************************* |
53 | * UTIL message types | 53 | * Deprecated |
54 | ******************************************************************************/ | 54 | * *****************************************************************************/ |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Test if service is online. | 57 | * Test if service is online. |
58 | * | 58 | * |
59 | * @deprecated! | 59 | * @deprecated! |
60 | */ | 60 | */ |
61 | #define GNUNET_MESSAGE_TYPE_TEST 1 | 61 | #define GNUNET_MESSAGE_TYPE_TEST 0 |
62 | |||
63 | /******************************************************************************* | ||
64 | * AGPL source code download | ||
65 | * *****************************************************************************/ | ||
62 | 66 | ||
63 | /** | 67 | /** |
64 | * Dummy messages for testing / benchmarking. | 68 | * Message to request source code link. |
65 | */ | 69 | */ |
66 | #define GNUNET_MESSAGE_TYPE_DUMMY 2 | 70 | #define GNUNET_MESSAGE_TYPE_REQUEST_AGPL 1 |
67 | 71 | ||
68 | /** | 72 | /** |
69 | * Another dummy messages for testing / benchmarking. | 73 | * Source code link. |
70 | */ | 74 | */ |
71 | #define GNUNET_MESSAGE_TYPE_DUMMY2 3 | 75 | #define GNUNET_MESSAGE_TYPE_RESPONSE_AGPL 2 |
72 | 76 | ||
73 | /******************************************************************************* | 77 | /******************************************************************************* |
74 | * RESOLVER message types | 78 | * RESOLVER message types |
@@ -85,18 +89,18 @@ extern "C" { | |||
85 | #define GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE 5 | 89 | #define GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE 5 |
86 | 90 | ||
87 | /******************************************************************************* | 91 | /******************************************************************************* |
88 | * AGPL source code download | 92 | * UTIL message types |
89 | * *****************************************************************************/ | 93 | ******************************************************************************/ |
90 | 94 | ||
91 | /** | 95 | /** |
92 | * Message to request source code link. | 96 | * Dummy messages for testing / benchmarking. |
93 | */ | 97 | */ |
94 | #define GNUNET_MESSAGE_TYPE_REQUEST_AGPL 6 | 98 | #define GNUNET_MESSAGE_TYPE_DUMMY 6 |
95 | 99 | ||
96 | /** | 100 | /** |
97 | * Source code link. | 101 | * Another dummy messages for testing / benchmarking. |
98 | */ | 102 | */ |
99 | #define GNUNET_MESSAGE_TYPE_RESPONSE_AGPL 7 | 103 | #define GNUNET_MESSAGE_TYPE_DUMMY2 7 |
100 | 104 | ||
101 | 105 | ||
102 | /******************************************************************************* | 106 | /******************************************************************************* |
@@ -1648,29 +1652,8 @@ extern "C" { | |||
1648 | */ | 1652 | */ |
1649 | #define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ELEMENTS_REPORT 545 | 1653 | #define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ELEMENTS_REPORT 545 |
1650 | 1654 | ||
1651 | /* | ||
1652 | * Initialization message for consensus p2p communication. | ||
1653 | */ | ||
1654 | #define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_HELLO 546 | ||
1655 | |||
1656 | /** | ||
1657 | * Report that the peer is synced with the partner after successfuly decoding | ||
1658 | * the invertible bloom filter. | ||
1659 | */ | ||
1660 | #define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_SYNCED 547 | ||
1661 | |||
1662 | /** | ||
1663 | * Interaction os over, got synched and reported all elements | ||
1664 | */ | ||
1665 | #define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_FIN 548 | ||
1666 | |||
1667 | /** | 1655 | /** |
1668 | * Abort a round, don't send requested elements anymore | 1656 | * Provide context for a consensus round. |
1669 | */ | ||
1670 | #define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ABORT 548 | ||
1671 | |||
1672 | /** | ||
1673 | * Abort a round, don't send requested elements anymore | ||
1674 | */ | 1657 | */ |
1675 | #define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT 547 | 1658 | #define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT 547 |
1676 | 1659 | ||
@@ -2751,9 +2734,8 @@ extern "C" { | |||
2751 | * 1000-1009 Connection-level Messages | 2734 | * 1000-1009 Connection-level Messages |
2752 | * 1010-1019 Channel-level Messages | 2735 | * 1010-1019 Channel-level Messages |
2753 | * 1020-1029 Local Client-Service | 2736 | * 1020-1029 Local Client-Service |
2754 | * 1030-1039 Local Service Monitoring | 2737 | * 1030-1049 Local Service Monitoring |
2755 | * 1040-1049 Application Data | 2738 | * 1050-1059 Application Data |
2756 | * 1050-1059 Reserved | ||
2757 | */ | 2739 | */ |
2758 | 2740 | ||
2759 | /******************************** Connection ********************************/ | 2741 | /******************************** Connection ********************************/ |
@@ -2949,6 +2931,11 @@ extern "C" { | |||
2949 | */ | 2931 | */ |
2950 | #define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END 1041 | 2932 | #define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END 1041 |
2951 | 2933 | ||
2934 | /** | ||
2935 | * Request to drop a message of type X to peer y. | ||
2936 | */ | ||
2937 | #define GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE 1042 | ||
2938 | |||
2952 | 2939 | ||
2953 | /******************************** Application *******************************/ | 2940 | /******************************** Application *******************************/ |
2954 | 2941 | ||
@@ -3178,6 +3165,10 @@ extern "C" { | |||
3178 | */ | 3165 | */ |
3179 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL 1221 | 3166 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL 1221 |
3180 | 3167 | ||
3168 | /** | ||
3169 | * @brief inform transport that a queue was updated | ||
3170 | */ | ||
3171 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE 1222 | ||
3181 | 3172 | ||
3182 | /** | 3173 | /** |
3183 | * Message sent to indicate to the transport that a monitor | 3174 | * Message sent to indicate to the transport that a monitor |
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h index a00e0372d..503113770 100644 --- a/src/include/gnunet_signatures.h +++ b/src/include/gnunet_signatures.h | |||
@@ -241,6 +241,10 @@ extern "C" | |||
241 | */ | 241 | */ |
242 | #define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37 | 242 | #define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 37 |
243 | 243 | ||
244 | /** | ||
245 | * Signature by a peer that like to create a connection. | ||
246 | */ | ||
247 | #define GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR 38 | ||
244 | 248 | ||
245 | #if 0 /* keep Emacsens' auto-indent happy */ | 249 | #if 0 /* keep Emacsens' auto-indent happy */ |
246 | { | 250 | { |
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h index f4dfc8745..ea6b95e2d 100644 --- a/src/include/gnunet_transport_communication_service.h +++ b/src/include/gnunet_transport_communication_service.h | |||
@@ -50,6 +50,10 @@ extern "C" { | |||
50 | */ | 50 | */ |
51 | #define GNUNET_TRANSPORT_COMMUNICATION_VERSION 0x00000000 | 51 | #define GNUNET_TRANSPORT_COMMUNICATION_VERSION 0x00000000 |
52 | 52 | ||
53 | /** | ||
54 | * Queue length | ||
55 | */ | ||
56 | #define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED UINT64_MAX | ||
53 | 57 | ||
54 | /** | 58 | /** |
55 | * Function called by the transport service to initialize a | 59 | * Function called by the transport service to initialize a |
@@ -176,8 +180,9 @@ GNUNET_TRANSPORT_communicator_disconnect ( | |||
176 | * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection) | 180 | * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection) |
177 | * #GNUNET_OK on success | 181 | * #GNUNET_OK on success |
178 | */ | 182 | */ |
179 | typedef void (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls, | 183 | typedef void |
180 | int success); | 184 | (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls, |
185 | int success); | ||
181 | 186 | ||
182 | 187 | ||
183 | /** | 188 | /** |
@@ -251,6 +256,9 @@ enum GNUNET_TRANSPORT_ConnectionStatus | |||
251 | * @param address address in human-readable format, 0-terminated, UTF-8 | 256 | * @param address address in human-readable format, 0-terminated, UTF-8 |
252 | * @param mtu maximum message size supported by queue, 0 if | 257 | * @param mtu maximum message size supported by queue, 0 if |
253 | * sending is not supported, SIZE_MAX for no MTU | 258 | * sending is not supported, SIZE_MAX for no MTU |
259 | * @param q_len number of messages that can be send through this queue | ||
260 | * @param priority queue priority. Queues with highest priority should be | ||
261 | * used | ||
254 | * @param nt which network type does the @a address belong to? | 262 | * @param nt which network type does the @a address belong to? |
255 | * @param cs what is the connection status of the queue? | 263 | * @param cs what is the connection status of the queue? |
256 | * @param mq message queue of the @a peer | 264 | * @param mq message queue of the @a peer |
@@ -262,10 +270,27 @@ GNUNET_TRANSPORT_communicator_mq_add ( | |||
262 | const struct GNUNET_PeerIdentity *peer, | 270 | const struct GNUNET_PeerIdentity *peer, |
263 | const char *address, | 271 | const char *address, |
264 | uint32_t mtu, | 272 | uint32_t mtu, |
273 | uint64_t q_len, | ||
274 | uint32_t priority, | ||
265 | enum GNUNET_NetworkType nt, | 275 | enum GNUNET_NetworkType nt, |
266 | enum GNUNET_TRANSPORT_ConnectionStatus cs, | 276 | enum GNUNET_TRANSPORT_ConnectionStatus cs, |
267 | struct GNUNET_MQ_Handle *mq); | 277 | struct GNUNET_MQ_Handle *mq); |
268 | 278 | ||
279 | /** | ||
280 | * Notify transport service that an MQ was updated | ||
281 | * | ||
282 | * @param ch connection to transport service | ||
283 | * @param qh the queue to update | ||
284 | * @param q_len number of messages that can be send through this queue | ||
285 | * @param priority queue priority. Queues with highest priority should be | ||
286 | * used | ||
287 | */ | ||
288 | void | ||
289 | GNUNET_TRANSPORT_communicator_mq_update ( | ||
290 | struct GNUNET_TRANSPORT_CommunicatorHandle *ch, | ||
291 | const struct GNUNET_TRANSPORT_QueueHandle *u_qh, | ||
292 | uint64_t q_len, | ||
293 | uint32_t priority); | ||
269 | 294 | ||
270 | /** | 295 | /** |
271 | * Notify transport service that an MQ became unavailable due to a | 296 | * Notify transport service that an MQ became unavailable due to a |
diff --git a/src/integration-tests/Makefile.am b/src/integration-tests/Makefile.am index f456544db..b3adc3a0f 100644 --- a/src/integration-tests/Makefile.am +++ b/src/integration-tests/Makefile.am | |||
@@ -21,7 +21,6 @@ check_SCRIPTS = \ | |||
21 | endif | 21 | endif |
22 | 22 | ||
23 | 23 | ||
24 | if HAVE_MHD | ||
25 | if ENABLE_TEST_RUN | 24 | if ENABLE_TEST_RUN |
26 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 25 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
27 | if HAVE_LIBGNURL | 26 | if HAVE_LIBGNURL |
@@ -34,7 +33,6 @@ TESTS = \ | |||
34 | endif | 33 | endif |
35 | endif | 34 | endif |
36 | endif | 35 | endif |
37 | endif | ||
38 | 36 | ||
39 | SUFFIXES = .py.in .py | 37 | SUFFIXES = .py.in .py |
40 | .py.in.py: | 38 | .py.in.py: |
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 94861b478..f4b846065 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -99,9 +99,7 @@ TESTS = \ | |||
99 | $(check_SCRIPTS) | 99 | $(check_SCRIPTS) |
100 | endif | 100 | endif |
101 | 101 | ||
102 | if HAVE_REST | ||
103 | REST_PLUGIN = libgnunet_plugin_rest_namestore.la | 102 | REST_PLUGIN = libgnunet_plugin_rest_namestore.la |
104 | endif | ||
105 | 103 | ||
106 | lib_LTLIBRARIES = \ | 104 | lib_LTLIBRARIES = \ |
107 | libgnunetnamestore.la | 105 | libgnunetnamestore.la |
@@ -114,10 +112,8 @@ bin_PROGRAMS = \ | |||
114 | gnunet-namestore \ | 112 | gnunet-namestore \ |
115 | gnunet-zoneimport | 113 | gnunet-zoneimport |
116 | 114 | ||
117 | if HAVE_MHD | ||
118 | libexec_PROGRAMS += \ | 115 | libexec_PROGRAMS += \ |
119 | gnunet-namestore-fcfsd | 116 | gnunet-namestore-fcfsd |
120 | endif | ||
121 | 117 | ||
122 | 118 | ||
123 | plugin_LTLIBRARIES = \ | 119 | plugin_LTLIBRARIES = \ |
@@ -679,12 +675,8 @@ check_SCRIPTS = \ | |||
679 | test_namestore_lookup.sh \ | 675 | test_namestore_lookup.sh \ |
680 | test_namestore_delete.sh | 676 | test_namestore_delete.sh |
681 | 677 | ||
682 | if HAVE_MHD | ||
683 | if HAVE_JSON | ||
684 | check_SCRIPTS += \ | 678 | check_SCRIPTS += \ |
685 | test_plugin_rest_namestore.sh | 679 | test_plugin_rest_namestore.sh |
686 | endif | ||
687 | endif | ||
688 | 680 | ||
689 | EXTRA_DIST = \ | 681 | EXTRA_DIST = \ |
690 | test_common.c \ | 682 | test_common.c \ |
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 793f60694..ebf39585e 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -780,7 +780,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
780 | unsigned int hash_count; | 780 | unsigned int hash_count; |
781 | 781 | ||
782 | hash_count = 0; | 782 | hash_count = 0; |
783 | while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)) | 783 | while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count)) |
784 | hash_count++; | 784 | hash_count++; |
785 | return hash_count; | 785 | return hash_count; |
786 | } | 786 | } |
@@ -806,7 +806,7 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, | |||
806 | GNUNET_memcpy (&buf[sizeof(val)], | 806 | GNUNET_memcpy (&buf[sizeof(val)], |
807 | pkey, | 807 | pkey, |
808 | sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)); | 808 | sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)); |
809 | GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work", | 809 | GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof", |
810 | buf, | 810 | buf, |
811 | sizeof(buf), | 811 | sizeof(buf), |
812 | &result); | 812 | &result); |
@@ -861,7 +861,7 @@ find_proof (void *cls) | |||
861 | while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) | 861 | while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) |
862 | { | 862 | { |
863 | GNUNET_memcpy (buf, &counter, sizeof(uint64_t)); | 863 | GNUNET_memcpy (buf, &counter, sizeof(uint64_t)); |
864 | GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work", | 864 | GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof", |
865 | buf, | 865 | buf, |
866 | sizeof(buf), | 866 | sizeof(buf), |
867 | &result); | 867 | &result); |
@@ -1001,7 +1001,7 @@ handle_p2p_estimate (void *cls, | |||
1001 | if (NULL != lh) | 1001 | if (NULL != lh) |
1002 | GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof(uint64_t)); | 1002 | GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof(uint64_t)); |
1003 | if (NULL != histogram) | 1003 | if (NULL != histogram) |
1004 | GNUNET_BIO_write_int64 (histogram, t); | 1004 | GNUNET_BIO_write_int64 (histogram, "histogram-time", t); |
1005 | } | 1005 | } |
1006 | #endif | 1006 | #endif |
1007 | GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO); | 1007 | GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO); |
@@ -1299,7 +1299,7 @@ shutdown_task (void *cls) | |||
1299 | } | 1299 | } |
1300 | if (NULL != histogram) | 1300 | if (NULL != histogram) |
1301 | { | 1301 | { |
1302 | GNUNET_BIO_write_close (histogram); | 1302 | GNUNET_BIO_write_close (histogram, NULL); |
1303 | histogram = NULL; | 1303 | histogram = NULL; |
1304 | } | 1304 | } |
1305 | #endif | 1305 | #endif |
@@ -1453,7 +1453,7 @@ run (void *cls, | |||
1453 | GNUNET_assert ( | 1453 | GNUNET_assert ( |
1454 | 0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir)); | 1454 | 0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir)); |
1455 | GNUNET_free (histogram_dir); | 1455 | GNUNET_free (histogram_dir); |
1456 | histogram = GNUNET_BIO_write_open (histogram_fn); | 1456 | histogram = GNUNET_BIO_write_open_file (histogram_fn); |
1457 | if (NULL == histogram) | 1457 | if (NULL == histogram) |
1458 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1458 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1459 | "Unable to open histogram file `%s'\n", | 1459 | "Unable to open histogram file `%s'\n", |
diff --git a/src/nse/nse.conf.in b/src/nse/nse.conf.in index d3c9a64b1..6330254e9 100644 --- a/src/nse/nse.conf.in +++ b/src/nse/nse.conf.in | |||
@@ -35,4 +35,4 @@ INTERVAL = 1 h | |||
35 | # for SCRYPT; with 2ms/op and 5ms workdelay, we can expect | 35 | # for SCRYPT; with 2ms/op and 5ms workdelay, we can expect |
36 | # the POW calculation to be done by a high-end peer in about 6h | 36 | # the POW calculation to be done by a high-end peer in about 6h |
37 | # DO NOT CHANGE THIS VALUE, doing so will break the protocol! | 37 | # DO NOT CHANGE THIS VALUE, doing so will break the protocol! |
38 | WORKBITS = 22 | 38 | WORKBITS = 15 |
diff --git a/src/nse/perf_kdf.c b/src/nse/perf_kdf.c index c5975aaf2..89b70903a 100644 --- a/src/nse/perf_kdf.c +++ b/src/nse/perf_kdf.c | |||
@@ -37,7 +37,7 @@ perfHash () | |||
37 | 37 | ||
38 | memset (buf, 1, sizeof(buf)); | 38 | memset (buf, 1, sizeof(buf)); |
39 | for (unsigned int i = 0; i < 1024; i++) | 39 | for (unsigned int i = 0; i < 1024; i++) |
40 | GNUNET_CRYPTO_pow_hash ("gnunet-proof-of-work", | 40 | GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof", |
41 | buf, | 41 | buf, |
42 | sizeof(buf), | 42 | sizeof(buf), |
43 | &hc); | 43 | &hc); |
diff --git a/src/peerinfo-tool/Makefile.am b/src/peerinfo-tool/Makefile.am index 93252570c..dfcdcd3da 100644 --- a/src/peerinfo-tool/Makefile.am +++ b/src/peerinfo-tool/Makefile.am | |||
@@ -6,9 +6,7 @@ if USE_COVERAGE | |||
6 | XLIB = -lgcov | 6 | XLIB = -lgcov |
7 | endif | 7 | endif |
8 | 8 | ||
9 | if HAVE_REST | ||
10 | REST_PLUGIN = libgnunet_plugin_rest_peerinfo.la | 9 | REST_PLUGIN = libgnunet_plugin_rest_peerinfo.la |
11 | endif | ||
12 | 10 | ||
13 | plugindir = $(libdir)/gnunet | 11 | plugindir = $(libdir)/gnunet |
14 | 12 | ||
diff --git a/src/pt/Makefile.am b/src/pt/Makefile.am index 09a68b779..10ae04931 100644 --- a/src/pt/Makefile.am +++ b/src/pt/Makefile.am | |||
@@ -29,7 +29,6 @@ gnunet_daemon_pt_LDADD = \ | |||
29 | $(GN_LIBINTL) | 29 | $(GN_LIBINTL) |
30 | 30 | ||
31 | if HAVE_TESTING | 31 | if HAVE_TESTING |
32 | if HAVE_MHD | ||
33 | 32 | ||
34 | if HAVE_LIBGNURL | 33 | if HAVE_LIBGNURL |
35 | LIB_GNURL=@LIBGNURL@ | 34 | LIB_GNURL=@LIBGNURL@ |
@@ -58,7 +57,6 @@ endif | |||
58 | endif | 57 | endif |
59 | 58 | ||
60 | endif | 59 | endif |
61 | endif | ||
62 | 60 | ||
63 | check_PROGRAMS = $(VPN_TEST) | 61 | check_PROGRAMS = $(VPN_TEST) |
64 | 62 | ||
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am index 6d448cc3c..b6d73bdf7 100644 --- a/src/reclaim/Makefile.am +++ b/src/reclaim/Makefile.am | |||
@@ -9,16 +9,12 @@ if USE_COVERAGE | |||
9 | endif | 9 | endif |
10 | 10 | ||
11 | 11 | ||
12 | if HAVE_REST | ||
13 | REST_PLUGIN = \ | 12 | REST_PLUGIN = \ |
14 | libgnunet_plugin_rest_openid_connect.la \ | 13 | libgnunet_plugin_rest_openid_connect.la \ |
15 | libgnunet_plugin_rest_reclaim.la | 14 | libgnunet_plugin_rest_reclaim.la |
16 | endif | ||
17 | 15 | ||
18 | if HAVE_JSON | ||
19 | ATTESTATION_PLUGIN = \ | 16 | ATTESTATION_PLUGIN = \ |
20 | libgnunet_plugin_reclaim_attestation_jwt.la | 17 | libgnunet_plugin_reclaim_attestation_jwt.la |
21 | endif | ||
22 | 18 | ||
23 | EXTRA_DIST = \ | 19 | EXTRA_DIST = \ |
24 | reclaim.conf \ | 20 | reclaim.conf \ |
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index d52d15ed4..c470ea567 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -332,7 +332,7 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
332 | (void **) &data, | 332 | (void **) &data, |
333 | &data_size))) | 333 | &data_size))) |
334 | { | 334 | { |
335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attestation value invalid!\n"); | 335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attestation value invalid!\n"); |
336 | return GNUNET_SYSERR; | 336 | return GNUNET_SYSERR; |
337 | } | 337 | } |
338 | attr = GNUNET_RECLAIM_attestation_new (name_str, type, data, data_size); | 338 | attr = GNUNET_RECLAIM_attestation_new (name_str, type, data, data_size); |
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 0800e5b20..863dd0450 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -508,8 +508,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
508 | handle->rest_handle->data, | 508 | handle->rest_handle->data, |
509 | handle->rest_handle->data_size); | 509 | handle->rest_handle->data_size); |
510 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); | 510 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); |
511 | GNUNET_assert (GNUNET_OK == | 511 | GNUNET_JSON_parse (data_json, attrspec, NULL, NULL); |
512 | GNUNET_JSON_parse (data_json, attrspec, NULL, NULL)); | ||
513 | json_decref (data_json); | 512 | json_decref (data_json); |
514 | if (NULL == attribute) | 513 | if (NULL == attribute) |
515 | { | 514 | { |
diff --git a/src/revocation/gnunet-revocation-tvg.c b/src/revocation/gnunet-revocation-tvg.c index 23a4bf020..b8f462b28 100644 --- a/src/revocation/gnunet-revocation-tvg.c +++ b/src/revocation/gnunet-revocation-tvg.c | |||
@@ -34,6 +34,22 @@ | |||
34 | #define TEST_EPOCHS 2 | 34 | #define TEST_EPOCHS 2 |
35 | #define TEST_DIFFICULTY 5 | 35 | #define TEST_DIFFICULTY 5 |
36 | 36 | ||
37 | static void | ||
38 | print_bytes (void *buf, | ||
39 | size_t buf_len, | ||
40 | int fold) | ||
41 | { | ||
42 | int i; | ||
43 | |||
44 | for (i = 0; i < buf_len; i++) | ||
45 | { | ||
46 | if ((0 != i) && (0 != fold) && (i%fold == 0)) | ||
47 | printf("\n"); | ||
48 | printf("%02x", ((unsigned char*)buf)[i]); | ||
49 | } | ||
50 | printf("\n"); | ||
51 | } | ||
52 | |||
37 | /** | 53 | /** |
38 | * Main function that will be run. | 54 | * Main function that will be run. |
39 | * | 55 | * |
@@ -52,22 +68,18 @@ run (void *cls, | |||
52 | struct GNUNET_CRYPTO_EcdsaPublicKey id_pub; | 68 | struct GNUNET_CRYPTO_EcdsaPublicKey id_pub; |
53 | struct GNUNET_REVOCATION_PowP pow; | 69 | struct GNUNET_REVOCATION_PowP pow; |
54 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; | 70 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; |
55 | char* data_enc; | 71 | struct GNUNET_TIME_Relative exp; |
56 | 72 | ||
57 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv); | 73 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv); |
58 | GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv, | 74 | GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv, |
59 | &id_pub); | 75 | &id_pub); |
60 | GNUNET_STRINGS_base64_encode (&id_priv, | 76 | fprintf(stdout, "Zone private key (d, little-endian scalar):\n"); |
61 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 77 | print_bytes (&id_priv, sizeof(id_priv), 0); |
62 | &data_enc); | 78 | fprintf(stdout, "\n"); |
63 | fprintf(stdout, "Zone private key (d):\n%s\n\n", data_enc); | 79 | fprintf(stdout, "Zone public key (zk):\n"); |
64 | GNUNET_free (data_enc); | 80 | print_bytes (&id_pub, sizeof(id_pub), 0); |
65 | GNUNET_STRINGS_base64_encode (&id_pub, | 81 | fprintf(stdout, "\n"); |
66 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 82 | memset (&pow, 0, sizeof (pow)); |
67 | &data_enc); | ||
68 | fprintf(stdout, "Zone public key (zk):\n%s\n\n", data_enc); | ||
69 | GNUNET_free (data_enc); | ||
70 | |||
71 | GNUNET_REVOCATION_pow_init (&id_priv, | 83 | GNUNET_REVOCATION_pow_init (&id_priv, |
72 | &pow); | 84 | &pow); |
73 | ph = GNUNET_REVOCATION_pow_start (&pow, | 85 | ph = GNUNET_REVOCATION_pow_start (&pow, |
@@ -82,11 +94,15 @@ run (void *cls, | |||
82 | { | 94 | { |
83 | pow_passes++; | 95 | pow_passes++; |
84 | } | 96 | } |
85 | GNUNET_STRINGS_base64_encode (&pow, | 97 | exp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, |
86 | sizeof (struct GNUNET_REVOCATION_PowP), | 98 | TEST_EPOCHS); |
87 | &data_enc); | 99 | GNUNET_assert (GNUNET_OK == GNUNET_REVOCATION_check_pow (&pow, |
88 | fprintf(stdout, "Proof:\n%s\n", data_enc); | 100 | TEST_DIFFICULTY, |
89 | GNUNET_free (data_enc); | 101 | exp)); |
102 | fprintf(stdout, "Proof:\n"); | ||
103 | print_bytes (&pow, | ||
104 | sizeof (pow), | ||
105 | 8); | ||
90 | } | 106 | } |
91 | 107 | ||
92 | 108 | ||
diff --git a/src/revocation/revocation.conf.in b/src/revocation/revocation.conf.in index 346168785..04393ea9f 100644 --- a/src/revocation/revocation.conf.in +++ b/src/revocation/revocation.conf.in | |||
@@ -13,7 +13,7 @@ UNIX_MATCH_GID = YES | |||
13 | # 2^25 hash operations take about 16-24h on a first-generation i7 | 13 | # 2^25 hash operations take about 16-24h on a first-generation i7 |
14 | # (using only a single-core) with SCRYPT. | 14 | # (using only a single-core) with SCRYPT. |
15 | # DO NOT CHANGE THIS VALUE, doing so will break the protocol! | 15 | # DO NOT CHANGE THIS VALUE, doing so will break the protocol! |
16 | WORKBITS = 25 | 16 | WORKBITS = 22 |
17 | EPOCH_DURATION = 356 d | 17 | EPOCH_DURATION = 356 d |
18 | 18 | ||
19 | DATABASE = $GNUNET_DATA_HOME/revocation.dat | 19 | DATABASE = $GNUNET_DATA_HOME/revocation.dat |
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c index 12cb63c57..3815e47b0 100644 --- a/src/revocation/revocation_api.c +++ b/src/revocation/revocation_api.c | |||
@@ -394,9 +394,8 @@ static unsigned int | |||
394 | count_leading_zeroes (const struct GNUNET_HashCode *hash) | 394 | count_leading_zeroes (const struct GNUNET_HashCode *hash) |
395 | { | 395 | { |
396 | unsigned int hash_count; | 396 | unsigned int hash_count; |
397 | |||
398 | hash_count = 0; | 397 | hash_count = 0; |
399 | while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))) | 398 | while ((0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count))) |
400 | hash_count++; | 399 | hash_count++; |
401 | return hash_count; | 400 | return hash_count; |
402 | } | 401 | } |
@@ -467,15 +466,12 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
467 | } | 466 | } |
468 | 467 | ||
469 | /** | 468 | /** |
470 | * First, check if any duplicates are in the PoW set | 469 | * First, check if PoW set is strictly monotically increasing |
471 | */ | 470 | */ |
472 | for (unsigned int i = 0; i < POW_COUNT; i++) | 471 | for (unsigned int i = 0; i < POW_COUNT-1; i++) |
473 | { | 472 | { |
474 | for (unsigned int j = i + 1; j < POW_COUNT; j++) | 473 | if (GNUNET_ntohll (pow->pow[i]) >= GNUNET_ntohll (pow->pow[i+1])) |
475 | { | 474 | return GNUNET_NO; |
476 | if (pow->pow[i] == pow->pow[j]) | ||
477 | return GNUNET_NO; | ||
478 | } | ||
479 | } | 475 | } |
480 | GNUNET_memcpy (&buf[sizeof(uint64_t)], | 476 | GNUNET_memcpy (&buf[sizeof(uint64_t)], |
481 | &pow->timestamp, | 477 | &pow->timestamp, |
@@ -486,8 +482,8 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
486 | for (unsigned int i = 0; i < POW_COUNT; i++) | 482 | for (unsigned int i = 0; i < POW_COUNT; i++) |
487 | { | 483 | { |
488 | pow_val = GNUNET_ntohll (pow->pow[i]); | 484 | pow_val = GNUNET_ntohll (pow->pow[i]); |
489 | GNUNET_memcpy (buf, &pow_val, sizeof(uint64_t)); | 485 | GNUNET_memcpy (buf, &pow->pow[i], sizeof(uint64_t)); |
490 | GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work", | 486 | GNUNET_CRYPTO_pow_hash ("GnsRevocationPow", |
491 | buf, | 487 | buf, |
492 | sizeof(buf), | 488 | sizeof(buf), |
493 | &result); | 489 | &result); |
@@ -495,6 +491,7 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 491 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
496 | "Score %u with %" PRIu64 " (#%u)\n", | 492 | "Score %u with %" PRIu64 " (#%u)\n", |
497 | tmp_score, pow_val, i); | 493 | tmp_score, pow_val, i); |
494 | |||
498 | score += tmp_score; | 495 | score += tmp_score; |
499 | 496 | ||
500 | } | 497 | } |
@@ -580,9 +577,14 @@ GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow, | |||
580 | unsigned int difficulty) | 577 | unsigned int difficulty) |
581 | { | 578 | { |
582 | struct GNUNET_REVOCATION_PowCalculationHandle *pc; | 579 | struct GNUNET_REVOCATION_PowCalculationHandle *pc; |
580 | struct GNUNET_TIME_Relative ttl; | ||
581 | |||
583 | 582 | ||
584 | pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); | 583 | pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); |
585 | pc->pow = pow; | 584 | pc->pow = pow; |
585 | ttl = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | ||
586 | epochs); | ||
587 | pc->pow->ttl = GNUNET_TIME_relative_hton (ttl); | ||
586 | pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 588 | pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
587 | UINT64_MAX); | 589 | UINT64_MAX); |
588 | pc->difficulty = difficulty; | 590 | pc->difficulty = difficulty; |
@@ -590,6 +592,18 @@ GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow, | |||
590 | return pc; | 592 | return pc; |
591 | } | 593 | } |
592 | 594 | ||
595 | /** | ||
596 | * Comparison function for quicksort | ||
597 | * | ||
598 | * @param a left element | ||
599 | * @param b right element | ||
600 | * @return a-b | ||
601 | */ | ||
602 | static int | ||
603 | cmp_pow_value (const void *a, const void *b) | ||
604 | { | ||
605 | return ( GNUNET_ntohll(*(uint64_t*)a) - GNUNET_ntohll(*(uint64_t*)b)); | ||
606 | } | ||
593 | 607 | ||
594 | /** | 608 | /** |
595 | * Calculate a key revocation valid for broadcasting for a number | 609 | * Calculate a key revocation valid for broadcasting for a number |
@@ -609,6 +623,8 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc) | |||
609 | + sizeof (uint64_t)] GNUNET_ALIGN; | 623 | + sizeof (uint64_t)] GNUNET_ALIGN; |
610 | struct GNUNET_HashCode result; | 624 | struct GNUNET_HashCode result; |
611 | unsigned int zeros; | 625 | unsigned int zeros; |
626 | int ret; | ||
627 | uint64_t pow_nbo; | ||
612 | 628 | ||
613 | pc->current_pow++; | 629 | pc->current_pow++; |
614 | 630 | ||
@@ -618,15 +634,15 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc) | |||
618 | for (unsigned int i = 0; i < POW_COUNT; i++) | 634 | for (unsigned int i = 0; i < POW_COUNT; i++) |
619 | if (pc->current_pow == pc->best[i].pow) | 635 | if (pc->current_pow == pc->best[i].pow) |
620 | return GNUNET_NO; | 636 | return GNUNET_NO; |
621 | 637 | pow_nbo = GNUNET_htonll (pc->current_pow); | |
622 | GNUNET_memcpy (buf, &pc->current_pow, sizeof(uint64_t)); | 638 | GNUNET_memcpy (buf, &pow_nbo, sizeof(uint64_t)); |
623 | GNUNET_memcpy (&buf[sizeof(uint64_t)], | 639 | GNUNET_memcpy (&buf[sizeof(uint64_t)], |
624 | &pc->pow->timestamp, | 640 | &pc->pow->timestamp, |
625 | sizeof (uint64_t)); | 641 | sizeof (uint64_t)); |
626 | GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], | 642 | GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], |
627 | &pc->pow->key, | 643 | &pc->pow->key, |
628 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | 644 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); |
629 | GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work", | 645 | GNUNET_CRYPTO_pow_hash ("GnsRevocationPow", |
630 | buf, | 646 | buf, |
631 | sizeof(buf), | 647 | sizeof(buf), |
632 | &result); | 648 | &result); |
@@ -637,15 +653,22 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc) | |||
637 | { | 653 | { |
638 | pc->best[i].bits = zeros; | 654 | pc->best[i].bits = zeros; |
639 | pc->best[i].pow = pc->current_pow; | 655 | pc->best[i].pow = pc->current_pow; |
640 | pc->pow->pow[i] = GNUNET_htonll (pc->current_pow); | 656 | pc->pow->pow[i] = pow_nbo; |
641 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 657 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
642 | "New best score %u with %" PRIu64 " (#%u)\n", | 658 | "New best score %u with %" PRIu64 " (#%u)\n", |
643 | zeros, pc->current_pow, i); | 659 | zeros, pc->current_pow, i); |
660 | |||
644 | break; | 661 | break; |
645 | } | 662 | } |
646 | } | 663 | } |
647 | return calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES : | 664 | ret = calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES : |
648 | GNUNET_NO; | 665 | GNUNET_NO; |
666 | if (GNUNET_YES == ret) | ||
667 | { | ||
668 | /* Sort POWs) */ | ||
669 | qsort (pc->pow->pow, POW_COUNT, sizeof (uint64_t), &cmp_pow_value); | ||
670 | } | ||
671 | return ret; | ||
649 | } | 672 | } |
650 | 673 | ||
651 | 674 | ||
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c index f193d5f6c..1c2efa60f 100644 --- a/src/revocation/test_revocation.c +++ b/src/revocation/test_revocation.c | |||
@@ -237,10 +237,12 @@ identity_completion_cb (void *cls, | |||
237 | fprintf (stderr, "All peers connected @ IDENTITY ...\n"); | 237 | fprintf (stderr, "All peers connected @ IDENTITY ...\n"); |
238 | testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh, | 238 | testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh, |
239 | "client", | 239 | "client", |
240 | NULL, | ||
240 | &identity_create_cb, | 241 | &identity_create_cb, |
241 | &testpeers[0]); | 242 | &testpeers[0]); |
242 | testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh, | 243 | testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh, |
243 | "toberevoked", | 244 | "toberevoked", |
245 | NULL, | ||
244 | &identity_create_cb, | 246 | &identity_create_cb, |
245 | &testpeers[1]); | 247 | &testpeers[1]); |
246 | } | 248 | } |
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 5d58c3743..d40f74aaf 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -263,7 +263,7 @@ save () | |||
263 | return; | 263 | return; |
264 | } | 264 | } |
265 | (void) GNUNET_DISK_directory_create_for_file (fn); | 265 | (void) GNUNET_DISK_directory_create_for_file (fn); |
266 | wh = GNUNET_BIO_write_open (fn); | 266 | wh = GNUNET_BIO_write_open_file (fn); |
267 | total = 0; | 267 | total = 0; |
268 | while (NULL != (se = sub_head)) | 268 | while (NULL != (se = sub_head)) |
269 | { | 269 | { |
@@ -290,10 +290,10 @@ save () | |||
290 | msg->flags = | 290 | msg->flags = |
291 | htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); | 291 | htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); |
292 | msg->value = GNUNET_htonll (pos->value); | 292 | msg->value = GNUNET_htonll (pos->value); |
293 | if (GNUNET_OK != GNUNET_BIO_write (wh, msg, size)) | 293 | if (GNUNET_OK != GNUNET_BIO_write (wh, "statistics-save-msg", msg, size)) |
294 | { | 294 | { |
295 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | 295 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); |
296 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 296 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
297 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); | 297 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); |
298 | wh = NULL; | 298 | wh = NULL; |
299 | } | 299 | } |
@@ -309,7 +309,7 @@ save () | |||
309 | } | 309 | } |
310 | if (NULL != wh) | 310 | if (NULL != wh) |
311 | { | 311 | { |
312 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 312 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
313 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); | 313 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); |
314 | if (0 == total) | 314 | if (0 == total) |
315 | GNUNET_break (0 == unlink (fn)); | 315 | GNUNET_break (0 == unlink (fn)); |
@@ -964,7 +964,7 @@ load () | |||
964 | return; | 964 | return; |
965 | } | 965 | } |
966 | buf = GNUNET_malloc (fsize); | 966 | buf = GNUNET_malloc (fsize); |
967 | rh = GNUNET_BIO_read_open (fn); | 967 | rh = GNUNET_BIO_read_open_file (fn); |
968 | if (! rh) | 968 | if (! rh) |
969 | { | 969 | { |
970 | GNUNET_free (buf); | 970 | GNUNET_free (buf); |
diff --git a/src/testbed-logger/gnunet-service-testbed-logger.c b/src/testbed-logger/gnunet-service-testbed-logger.c index 4e0a3cd34..81652fa4f 100644 --- a/src/testbed-logger/gnunet-service-testbed-logger.c +++ b/src/testbed-logger/gnunet-service-testbed-logger.c | |||
@@ -85,6 +85,7 @@ handle_log_msg (void *cls, | |||
85 | 85 | ||
86 | ms = ntohs (msg->size) - sizeof(struct GNUNET_MessageHeader); | 86 | ms = ntohs (msg->size) - sizeof(struct GNUNET_MessageHeader); |
87 | GNUNET_BIO_write (bio, | 87 | GNUNET_BIO_write (bio, |
88 | "testbed-logger-handle-log-msg", | ||
88 | &msg[1], | 89 | &msg[1], |
89 | ms); | 90 | ms); |
90 | GNUNET_SERVICE_client_continue (client); | 91 | GNUNET_SERVICE_client_continue (client); |
@@ -108,7 +109,7 @@ shutdown_task (void *cls) | |||
108 | return; | 109 | return; |
109 | } | 110 | } |
110 | GNUNET_break (GNUNET_OK == | 111 | GNUNET_break (GNUNET_OK == |
111 | GNUNET_BIO_write_close (bio)); | 112 | GNUNET_BIO_write_close (bio, NULL)); |
112 | } | 113 | } |
113 | 114 | ||
114 | 115 | ||
@@ -202,7 +203,7 @@ logger_run (void *cls, | |||
202 | (intmax_t) pid); | 203 | (intmax_t) pid); |
203 | GNUNET_free (hname); | 204 | GNUNET_free (hname); |
204 | GNUNET_free (dir); | 205 | GNUNET_free (dir); |
205 | if (NULL == (bio = GNUNET_BIO_write_open (fn))) | 206 | if (NULL == (bio = GNUNET_BIO_write_open_file (fn))) |
206 | { | 207 | { |
207 | GNUNET_free (fn); | 208 | GNUNET_free (fn); |
208 | GNUNET_SCHEDULER_shutdown (); | 209 | GNUNET_SCHEDULER_shutdown (); |
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c index e96449def..2d490ba8c 100644 --- a/src/testbed/gnunet-service-testbed_cpustatus.c +++ b/src/testbed/gnunet-service-testbed_cpustatus.c | |||
@@ -568,7 +568,7 @@ sample_load_task (void *cls) | |||
568 | ld_cpu, ld_disk, mem_usage, nproc); | 568 | ld_cpu, ld_disk, mem_usage, nproc); |
569 | if (0 < nbs) | 569 | if (0 < nbs) |
570 | { | 570 | { |
571 | GNUNET_BIO_write (bw, str, nbs); | 571 | GNUNET_BIO_write (bw, "sample load task", str, nbs); |
572 | } | 572 | } |
573 | else | 573 | else |
574 | GNUNET_break (0); | 574 | GNUNET_break (0); |
@@ -612,7 +612,7 @@ GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
612 | hostname, (intmax_t) getpid ()); | 612 | hostname, (intmax_t) getpid ()); |
613 | GNUNET_free (stats_dir); | 613 | GNUNET_free (stats_dir); |
614 | GNUNET_free (hostname); | 614 | GNUNET_free (hostname); |
615 | if (NULL == (bw = GNUNET_BIO_write_open (fn))) | 615 | if (NULL == (bw = GNUNET_BIO_write_open_file (fn))) |
616 | { | 616 | { |
617 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 617 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
618 | _ ("Cannot open %s for writing load statistics. " | 618 | _ ("Cannot open %s for writing load statistics. " |
@@ -656,7 +656,7 @@ GST_stats_destroy () | |||
656 | GNUNET_SCHEDULER_cancel (sample_load_task_id); | 656 | GNUNET_SCHEDULER_cancel (sample_load_task_id); |
657 | sample_load_task_id = NULL; | 657 | sample_load_task_id = NULL; |
658 | } | 658 | } |
659 | GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bw)); | 659 | GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bw, NULL)); |
660 | bw = NULL; | 660 | bw = NULL; |
661 | } | 661 | } |
662 | 662 | ||
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 3028b29b4..eadb601ef 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -11,12 +11,10 @@ pkgcfg_DATA = \ | |||
11 | transport.conf \ | 11 | transport.conf \ |
12 | communicator-unix.conf | 12 | communicator-unix.conf |
13 | 13 | ||
14 | if HAVE_MHD | 14 | HTTP_SERVER_PLUGIN_LA = libgnunet_plugin_transport_http_server.la |
15 | HTTP_SERVER_PLUGIN_LA = libgnunet_plugin_transport_http_server.la | 15 | HTTPS_SERVER_PLUGIN_LA = libgnunet_plugin_transport_https_server.la |
16 | HTTPS_SERVER_PLUGIN_LA = libgnunet_plugin_transport_https_server.la | 16 | HTTP_SERVER_PLUGIN_TEST = test_plugin_http_server |
17 | HTTP_SERVER_PLUGIN_TEST = test_plugin_http_server | 17 | HTTPS_SERVER_PLUGIN_TEST = test_plugin_https_server |
18 | HTTPS_SERVER_PLUGIN_TEST = test_plugin_https_server | ||
19 | endif | ||
20 | 18 | ||
21 | if HAVE_LIBGNURL | 19 | if HAVE_LIBGNURL |
22 | HTTP_CLIENT_PLUGIN_TEST = test_plugin_http_client | 20 | HTTP_CLIENT_PLUGIN_TEST = test_plugin_http_client |
@@ -36,7 +34,6 @@ CPP_GNURL=@LIBCURL_CPPFLAGS@ | |||
36 | endif | 34 | endif |
37 | endif | 35 | endif |
38 | 36 | ||
39 | if HAVE_MHD | ||
40 | if HAVE_LIBGNURL | 37 | if HAVE_LIBGNURL |
41 | HTTP_API_TEST = test_transport_api_http | 38 | HTTP_API_TEST = test_transport_api_http |
42 | HTTP_REVERSE_API_TEST = test_transport_api_http_reverse | 39 | HTTP_REVERSE_API_TEST = test_transport_api_http_reverse |
@@ -76,7 +73,6 @@ endif | |||
76 | HTTPS_SWITCH = test_transport_address_switch_https | 73 | HTTPS_SWITCH = test_transport_address_switch_https |
77 | endif | 74 | endif |
78 | endif | 75 | endif |
79 | endif | ||
80 | 76 | ||
81 | if USE_COVERAGE | 77 | if USE_COVERAGE |
82 | AM_CFLAGS = --coverage -O0 | 78 | AM_CFLAGS = --coverage -O0 |
@@ -673,13 +669,13 @@ TESTS += \ | |||
673 | test_transport_api_timeout_udp \ | 669 | test_transport_api_timeout_udp \ |
674 | test_transport_api_udp_nat \ | 670 | test_transport_api_udp_nat \ |
675 | test_transport_api_reliability_udp \ | 671 | test_transport_api_reliability_udp \ |
676 | test_quota_compliance_udp \ | 672 | test_quota_compliance_udp \ |
677 | test_communicator_basic-unix \ | 673 | test_communicator_basic-unix \ |
678 | test_communicator_basic-tcp \ | 674 | test_communicator_basic-tcp \ |
679 | test_communicator_basic-udp \ | 675 | test_communicator_basic-udp \ |
680 | test_communicator_rekey-tcp \ | 676 | test_communicator_rekey-tcp \ |
681 | test_communicator_rekey-udp \ | 677 | test_communicator_rekey-udp \ |
682 | test_communicator_backchannel-udp | 678 | test_communicator_backchannel-udp |
683 | endif | 679 | endif |
684 | endif | 680 | endif |
685 | 681 | ||
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index bbfacbffd..e25cdf139 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c | |||
@@ -40,8 +40,10 @@ | |||
40 | #include "gnunet_nt_lib.h" | 40 | #include "gnunet_nt_lib.h" |
41 | #include "gnunet_nat_service.h" | 41 | #include "gnunet_nat_service.h" |
42 | #include "gnunet_statistics_service.h" | 42 | #include "gnunet_statistics_service.h" |
43 | #include "gnunet_ats_transport_service.h" | ||
44 | #include "transport.h" | ||
43 | #include "gnunet_transport_communication_service.h" | 45 | #include "gnunet_transport_communication_service.h" |
44 | 46 | #include "gnunet_resolver_service.h" | |
45 | /** | 47 | /** |
46 | * How long do we believe our addresses to remain up (before | 48 | * How long do we believe our addresses to remain up (before |
47 | * the other peer should revalidate). | 49 | * the other peer should revalidate). |
@@ -253,6 +255,21 @@ struct TCPFinish | |||
253 | 255 | ||
254 | GNUNET_NETWORK_STRUCT_END | 256 | GNUNET_NETWORK_STRUCT_END |
255 | 257 | ||
258 | /** | ||
259 | * Struct to use as closure. | ||
260 | */ | ||
261 | struct ListenTask | ||
262 | { | ||
263 | /** | ||
264 | * ID of listen task | ||
265 | */ | ||
266 | struct GNUNET_SCHEDULER_Task *listen_task; | ||
267 | |||
268 | /** | ||
269 | * Listen socket. | ||
270 | */ | ||
271 | struct GNUNET_NETWORK_Handle *listen_sock; | ||
272 | }; | ||
256 | 273 | ||
257 | /** | 274 | /** |
258 | * Handle for a queue. | 275 | * Handle for a queue. |
@@ -265,6 +282,16 @@ struct Queue | |||
265 | struct GNUNET_PeerIdentity target; | 282 | struct GNUNET_PeerIdentity target; |
266 | 283 | ||
267 | /** | 284 | /** |
285 | * ID of listen task | ||
286 | */ | ||
287 | struct GNUNET_SCHEDULER_Task *listen_task; | ||
288 | |||
289 | /** | ||
290 | * Listen socket. | ||
291 | */ | ||
292 | struct GNUNET_NETWORK_Handle *listen_sock; | ||
293 | |||
294 | /** | ||
268 | * socket that we transmit all data with on this queue | 295 | * socket that we transmit all data with on this queue |
269 | */ | 296 | */ |
270 | struct GNUNET_NETWORK_Handle *sock; | 297 | struct GNUNET_NETWORK_Handle *sock; |
@@ -449,6 +476,16 @@ struct ProtoQueue | |||
449 | struct ProtoQueue *prev; | 476 | struct ProtoQueue *prev; |
450 | 477 | ||
451 | /** | 478 | /** |
479 | * ID of listen task | ||
480 | */ | ||
481 | struct GNUNET_SCHEDULER_Task *listen_task; | ||
482 | |||
483 | /** | ||
484 | * Listen socket. | ||
485 | */ | ||
486 | struct GNUNET_NETWORK_Handle *listen_sock; | ||
487 | |||
488 | /** | ||
452 | * socket that we transmit all data with on this queue | 489 | * socket that we transmit all data with on this queue |
453 | */ | 490 | */ |
454 | struct GNUNET_NETWORK_Handle *sock; | 491 | struct GNUNET_NETWORK_Handle *sock; |
@@ -485,11 +522,61 @@ struct ProtoQueue | |||
485 | size_t ibuf_off; | 522 | size_t ibuf_off; |
486 | }; | 523 | }; |
487 | 524 | ||
525 | /** | ||
526 | * In case of port only configuration we like to bind to ipv4 and ipv6 addresses. | ||
527 | */ | ||
528 | struct PortOnlyIpv4Ipv6 | ||
529 | { | ||
530 | /** | ||
531 | * Ipv4 address we like to bind to. | ||
532 | */ | ||
533 | struct sockaddr *addr_ipv4; | ||
534 | |||
535 | /** | ||
536 | * Length of ipv4 address. | ||
537 | */ | ||
538 | socklen_t *addr_len_ipv4; | ||
539 | |||
540 | /** | ||
541 | * Ipv6 address we like to bind to. | ||
542 | */ | ||
543 | struct sockaddr *addr_ipv6; | ||
544 | |||
545 | /** | ||
546 | * Length of ipv6 address. | ||
547 | */ | ||
548 | socklen_t *addr_len_ipv6; | ||
549 | |||
550 | }; | ||
488 | 551 | ||
489 | /** | 552 | /** |
490 | * ID of listen task | 553 | * DLL to store the addresses we like to register at NAT service. |
491 | */ | 554 | */ |
492 | static struct GNUNET_SCHEDULER_Task *listen_task; | 555 | struct Addresses |
556 | { | ||
557 | /** | ||
558 | * Kept in a DLL. | ||
559 | */ | ||
560 | struct Addresses *next; | ||
561 | |||
562 | /** | ||
563 | * Kept in a DLL. | ||
564 | */ | ||
565 | struct Addresses *prev; | ||
566 | |||
567 | /** | ||
568 | * Address we like to register at NAT service. | ||
569 | */ | ||
570 | struct sockaddr *addr; | ||
571 | |||
572 | /** | ||
573 | * Length of address we like to register at NAT service. | ||
574 | */ | ||
575 | socklen_t addr_len; | ||
576 | |||
577 | }; | ||
578 | |||
579 | |||
493 | 580 | ||
494 | /** | 581 | /** |
495 | * Maximum queue length before we stop reading towards the transport service. | 582 | * Maximum queue length before we stop reading towards the transport service. |
@@ -512,11 +599,6 @@ static struct GNUNET_TRANSPORT_CommunicatorHandle *ch; | |||
512 | static struct GNUNET_CONTAINER_MultiPeerMap *queue_map; | 599 | static struct GNUNET_CONTAINER_MultiPeerMap *queue_map; |
513 | 600 | ||
514 | /** | 601 | /** |
515 | * Listen socket. | ||
516 | */ | ||
517 | static struct GNUNET_NETWORK_Handle *listen_sock; | ||
518 | |||
519 | /** | ||
520 | * Our public key. | 602 | * Our public key. |
521 | */ | 603 | */ |
522 | static struct GNUNET_PeerIdentity my_identity; | 604 | static struct GNUNET_PeerIdentity my_identity; |
@@ -556,6 +638,25 @@ static struct ProtoQueue *proto_head; | |||
556 | */ | 638 | */ |
557 | static struct ProtoQueue *proto_tail; | 639 | static struct ProtoQueue *proto_tail; |
558 | 640 | ||
641 | /** | ||
642 | * Handle for DNS lookup of bindto address | ||
643 | */ | ||
644 | struct GNUNET_RESOLVER_RequestHandle *resolve_request_handle; | ||
645 | |||
646 | /** | ||
647 | * Head of DLL with addresses we like to register at NAT servcie. | ||
648 | */ | ||
649 | struct Addresses *addrs_head; | ||
650 | |||
651 | /** | ||
652 | * Head of DLL with addresses we like to register at NAT servcie. | ||
653 | */ | ||
654 | struct Addresses *addrs_tail; | ||
655 | |||
656 | /** | ||
657 | * Number of addresses in the DLL for register at NAT service. | ||
658 | */ | ||
659 | int addrs_lens; | ||
559 | 660 | ||
560 | /** | 661 | /** |
561 | * We have been notified that our listen socket has something to | 662 | * We have been notified that our listen socket has something to |
@@ -579,6 +680,10 @@ static void | |||
579 | queue_destroy (struct Queue *queue) | 680 | queue_destroy (struct Queue *queue) |
580 | { | 681 | { |
581 | struct GNUNET_MQ_Handle *mq; | 682 | struct GNUNET_MQ_Handle *mq; |
683 | struct ListenTask *lt; | ||
684 | lt = GNUNET_new (struct ListenTask); | ||
685 | lt->listen_sock = queue->listen_sock; | ||
686 | lt->listen_task = queue->listen_task; | ||
582 | 687 | ||
583 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 688 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
584 | "Disconnecting queue for peer `%s'\n", | 689 | "Disconnecting queue for peer `%s'\n", |
@@ -618,11 +723,13 @@ queue_destroy (struct Queue *queue) | |||
618 | queue->destroyed = GNUNET_YES; | 723 | queue->destroyed = GNUNET_YES; |
619 | else | 724 | else |
620 | GNUNET_free (queue); | 725 | GNUNET_free (queue); |
621 | if (NULL == listen_task) | 726 | |
622 | listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 727 | if (NULL == lt->listen_task) |
623 | listen_sock, | 728 | lt->listen_task = GNUNET_SCHEDULER_add_read_net ( |
624 | &listen_cb, | 729 | GNUNET_TIME_UNIT_FOREVER_REL, |
625 | NULL); | 730 | lt->listen_sock, |
731 | &listen_cb, | ||
732 | lt); | ||
626 | } | 733 | } |
627 | 734 | ||
628 | 735 | ||
@@ -1063,7 +1170,8 @@ queue_read (void *cls) | |||
1063 | However, we have to take into account that the plaintext buffer may have | 1170 | However, we have to take into account that the plaintext buffer may have |
1064 | already contained data and not jumpt too far ahead in the ciphertext. | 1171 | already contained data and not jumpt too far ahead in the ciphertext. |
1065 | If there is no rekey and the last message is incomplete (max > total), | 1172 | If there is no rekey and the last message is incomplete (max > total), |
1066 | it is safe to keep the decryption so we shift by 'max' */if (GNUNET_YES == queue->rekeyed) | 1173 | it is safe to keep the decryption so we shift by 'max' */ |
1174 | if (GNUNET_YES == queue->rekeyed) | ||
1067 | { | 1175 | { |
1068 | max = total - old_pread_off; | 1176 | max = total - old_pread_off; |
1069 | queue->rekeyed = GNUNET_NO; | 1177 | queue->rekeyed = GNUNET_NO; |
@@ -1095,143 +1203,276 @@ queue_read (void *cls) | |||
1095 | queue_finish (queue); | 1203 | queue_finish (queue); |
1096 | } | 1204 | } |
1097 | 1205 | ||
1206 | /** | ||
1207 | * Convert a `struct sockaddr_in6 to a `struct sockaddr *` | ||
1208 | * | ||
1209 | * @param[out] sock_len set to the length of the address. | ||
1210 | * @param v6 The sockaddr_in6 to be converted. | ||
1211 | * @return The struct sockaddr *. | ||
1212 | */ | ||
1213 | static struct sockaddr * | ||
1214 | tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6, | ||
1215 | unsigned int port) | ||
1216 | { | ||
1217 | struct sockaddr *in; | ||
1218 | |||
1219 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1220 | "1 address %s\n", | ||
1221 | GNUNET_a2s (in, *sock_len)); | ||
1222 | |||
1223 | v6.sin6_family = AF_INET6; | ||
1224 | v6.sin6_port = htons ((uint16_t) port); | ||
1225 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1226 | v6.sin6_len = sizeof(sizeof(struct sockaddr_in6)); | ||
1227 | #endif | ||
1228 | in = GNUNET_memdup (&v6, sizeof(v6)); | ||
1229 | *sock_len = sizeof(struct sockaddr_in6); | ||
1230 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1231 | "address %s\n", | ||
1232 | GNUNET_a2s (in, *sock_len)); | ||
1233 | |||
1234 | return in; | ||
1235 | } | ||
1098 | 1236 | ||
1099 | /** | 1237 | /** |
1100 | * Convert TCP bind specification to a `struct sockaddr *` | 1238 | * Convert a `struct sockaddr_in4 to a `struct sockaddr *` |
1101 | * | 1239 | * |
1102 | * @param bindto bind specification to convert | 1240 | * @param[out] sock_len set to the length of the address. |
1103 | * @param[out] sock_len set to the length of the address | 1241 | * @param v4 The sockaddr_in4 to be converted. |
1104 | * @return converted bindto specification | 1242 | * @return The struct sockaddr *. |
1105 | */ | 1243 | */ |
1106 | static struct sockaddr * | 1244 | static struct sockaddr * |
1107 | tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) | 1245 | tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4, |
1246 | unsigned int port) | ||
1108 | { | 1247 | { |
1109 | struct sockaddr *in; | 1248 | struct sockaddr *in; |
1110 | unsigned int port; | 1249 | |
1111 | char dummy[2]; | 1250 | v4.sin_family = AF_INET; |
1112 | char *colon; | 1251 | v4.sin_port = htons ((uint16_t) port); |
1252 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1253 | v4.sin_len = sizeof(struct sockaddr_in); | ||
1254 | #endif | ||
1255 | in = GNUNET_memdup (&v4, sizeof(v4)); | ||
1256 | *sock_len = sizeof(struct sockaddr_in); | ||
1257 | return in; | ||
1258 | } | ||
1259 | |||
1260 | /** | ||
1261 | * Convert TCP bind specification to a `struct PortOnlyIpv4Ipv6 *` | ||
1262 | * | ||
1263 | * @param bindto bind specification to convert. | ||
1264 | * @return The converted bindto specification. | ||
1265 | */ | ||
1266 | static struct PortOnlyIpv4Ipv6 * | ||
1267 | tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port) | ||
1268 | { | ||
1269 | struct PortOnlyIpv4Ipv6 *po; | ||
1270 | struct sockaddr_in *i4; | ||
1271 | struct sockaddr_in6 *i6; | ||
1272 | socklen_t sock_len_ipv4; | ||
1273 | socklen_t sock_len_ipv6; | ||
1274 | |||
1275 | /* interpreting value as just a PORT number */ | ||
1276 | if (*port > UINT16_MAX) | ||
1277 | { | ||
1278 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1279 | "BINDTO specification `%s' invalid: value too large for port\n", | ||
1280 | bindto); | ||
1281 | return NULL; | ||
1282 | } | ||
1283 | |||
1284 | po = GNUNET_new (struct PortOnlyIpv4Ipv6); | ||
1285 | |||
1286 | if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) || | ||
1287 | (GNUNET_YES == | ||
1288 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | ||
1289 | COMMUNICATOR_CONFIG_SECTION, | ||
1290 | "DISABLE_V6"))) | ||
1291 | { | ||
1292 | i4 = GNUNET_malloc (sizeof(struct sockaddr_in)); | ||
1293 | po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4, | ||
1294 | *port); | ||
1295 | po->addr_len_ipv4 = &sock_len_ipv4; | ||
1296 | } | ||
1297 | else | ||
1298 | { | ||
1299 | |||
1300 | i4 = GNUNET_malloc (sizeof(struct sockaddr_in)); | ||
1301 | po->addr_ipv4 = tcp_address_to_sockaddr_numeric_v4 (&sock_len_ipv4, *i4, | ||
1302 | *port); | ||
1303 | po->addr_len_ipv4 = &sock_len_ipv4; | ||
1304 | |||
1305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1306 | "3.5 address %s\n", | ||
1307 | GNUNET_a2s (po->addr_ipv4, sock_len_ipv4)); | ||
1308 | |||
1309 | i6 = GNUNET_malloc (sizeof(struct sockaddr_in6)); | ||
1310 | po->addr_ipv6 = tcp_address_to_sockaddr_numeric_v6 (&sock_len_ipv6, *i6, | ||
1311 | *port); | ||
1312 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1313 | "3 address %s\n", | ||
1314 | GNUNET_a2s (po->addr_ipv6, sock_len_ipv6)); | ||
1315 | |||
1316 | po->addr_len_ipv6 = &sock_len_ipv6; | ||
1317 | } | ||
1318 | return po; | ||
1319 | } | ||
1320 | |||
1321 | /** | ||
1322 | * This Method extracts the address part of the BINDTO string. | ||
1323 | * | ||
1324 | * @param bindto String we extract the address part from. | ||
1325 | * @return The extracted address string. | ||
1326 | */ | ||
1327 | static char * | ||
1328 | extract_address (const char *bindto) | ||
1329 | { | ||
1330 | |||
1331 | char *start; | ||
1332 | char *token; | ||
1113 | char *cp; | 1333 | char *cp; |
1334 | char *rest = NULL; | ||
1114 | 1335 | ||
1115 | if (1 == sscanf (bindto, "%u%1s", &port, dummy)) | 1336 | if (NULL == bindto) |
1337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1338 | "bindto is NULL\n"); | ||
1339 | |||
1340 | cp = GNUNET_strdup (bindto); | ||
1341 | start = cp; | ||
1342 | if (('[' == *cp) && (']' == cp[strlen (cp) - 1])) | ||
1116 | { | 1343 | { |
1117 | /* interpreting value as just a PORT number */ | 1344 | start++; /* skip over '['*/ |
1118 | if (port > UINT16_MAX) | 1345 | cp[strlen (cp) - 1] = '\0'; /* eat ']'*/ |
1346 | } | ||
1347 | else { | ||
1348 | token = strtok_r (cp, "]", &rest); | ||
1349 | if (strlen (bindto) == strlen (token)) | ||
1119 | { | 1350 | { |
1120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1351 | token = strtok_r (cp, ":", &rest); |
1121 | "BINDTO specification `%s' invalid: value too large for port\n", | ||
1122 | bindto); | ||
1123 | return NULL; | ||
1124 | } | 1352 | } |
1125 | if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) || | 1353 | else |
1126 | (GNUNET_YES == | ||
1127 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | ||
1128 | COMMUNICATOR_CONFIG_SECTION, | ||
1129 | "DISABLE_V6"))) | ||
1130 | { | 1354 | { |
1131 | struct sockaddr_in *i4; | 1355 | token++; |
1356 | return token; | ||
1357 | } | ||
1358 | } | ||
1132 | 1359 | ||
1133 | i4 = GNUNET_malloc (sizeof(struct sockaddr_in)); | 1360 | // GNUNET_free(cp); |
1134 | i4->sin_family = AF_INET; | 1361 | |
1135 | i4->sin_port = htons ((uint16_t) port); | 1362 | return start; |
1136 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1363 | } |
1137 | i4->sin_len = sizeof(sizeof(struct sockaddr_in)); | 1364 | |
1138 | #endif | 1365 | /** |
1139 | *sock_len = sizeof(struct sockaddr_in); | 1366 | * This Method extracts the port part of the BINDTO string. |
1140 | in = (struct sockaddr *) i4; | 1367 | * |
1368 | * @param addr_and_port String we extract the port from. | ||
1369 | * @return The extracted port as unsigned int. | ||
1370 | */ | ||
1371 | static unsigned int | ||
1372 | extract_port (const char *addr_and_port) | ||
1373 | { | ||
1374 | unsigned int port; | ||
1375 | char dummy[2]; | ||
1376 | char *token; | ||
1377 | char *addr; | ||
1378 | char *colon; | ||
1379 | char *cp; | ||
1380 | char *rest = NULL; | ||
1381 | |||
1382 | if (NULL != addr_and_port) | ||
1383 | { | ||
1384 | cp = GNUNET_strdup (addr_and_port); | ||
1385 | token = strtok_r (cp, "]", &rest); | ||
1386 | if (strlen (addr_and_port) == strlen (token)) | ||
1387 | { | ||
1388 | colon = strrchr (cp, ':'); | ||
1389 | if (NULL == colon) | ||
1390 | { | ||
1391 | return 0; | ||
1392 | } | ||
1393 | addr = colon; | ||
1394 | addr++; | ||
1141 | } | 1395 | } |
1142 | else | 1396 | else |
1143 | { | 1397 | { |
1144 | struct sockaddr_in6 *i6; | 1398 | token = strtok_r (NULL, "]", &rest); |
1145 | 1399 | if (NULL == token) | |
1146 | i6 = GNUNET_malloc (sizeof(struct sockaddr_in6)); | 1400 | { |
1147 | i6->sin6_family = AF_INET6; | 1401 | return 0; |
1148 | i6->sin6_port = htons ((uint16_t) port); | 1402 | } |
1149 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1403 | else |
1150 | i6->sin6_len = sizeof(sizeof(struct sockaddr_in6)); | 1404 | { |
1151 | #endif | 1405 | addr = token; |
1152 | *sock_len = sizeof(struct sockaddr_in6); | 1406 | addr++; |
1153 | in = (struct sockaddr *) i6; | 1407 | } |
1154 | } | 1408 | } |
1155 | return in; | 1409 | |
1156 | } | 1410 | |
1157 | cp = GNUNET_strdup (bindto); | 1411 | if (1 == sscanf (addr, "%u%1s", &port, dummy)) |
1158 | colon = strrchr (cp, ':'); | ||
1159 | if (NULL != colon) | ||
1160 | { | ||
1161 | /* interpet value after colon as port */ | ||
1162 | *colon = '\0'; | ||
1163 | colon++; | ||
1164 | if (1 == sscanf (colon, "%u%1s", &port, dummy)) | ||
1165 | { | 1412 | { |
1166 | /* interpreting value as just a PORT number */ | 1413 | /* interpreting value as just a PORT number */ |
1167 | if (port > UINT16_MAX) | 1414 | if (port > UINT16_MAX) |
1168 | { | 1415 | { |
1169 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1416 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1170 | "BINDTO specification `%s' invalid: value too large for port\n", | 1417 | "Port `%u' invalid: value too large for port\n", |
1171 | bindto); | 1418 | port); |
1172 | GNUNET_free (cp); | 1419 | // GNUNET_free (cp); |
1173 | return NULL; | 1420 | return 0; |
1174 | } | 1421 | } |
1175 | } | 1422 | } |
1176 | else | 1423 | else |
1177 | { | 1424 | { |
1178 | GNUNET_log ( | 1425 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1179 | GNUNET_ERROR_TYPE_ERROR, | 1426 | "BINDTO specification invalid: last ':' not followed by number\n"); |
1180 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", | 1427 | // GNUNET_free (cp); |
1181 | bindto); | 1428 | return 0; |
1182 | GNUNET_free (cp); | ||
1183 | return NULL; | ||
1184 | } | 1429 | } |
1185 | } | 1430 | } |
1186 | else | 1431 | else |
1187 | { | 1432 | { |
1433 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1434 | "return 0\n"); | ||
1188 | /* interpret missing port as 0, aka pick any free one */ | 1435 | /* interpret missing port as 0, aka pick any free one */ |
1189 | port = 0; | 1436 | port = 0; |
1190 | } | 1437 | } |
1191 | { | ||
1192 | /* try IPv4 */ | ||
1193 | struct sockaddr_in v4; | ||
1194 | 1438 | ||
1195 | if (1 == inet_pton (AF_INET, cp, &v4.sin_addr)) | 1439 | |
1196 | { | 1440 | return port; |
1197 | v4.sin_family = AF_INET; | 1441 | } |
1198 | v4.sin_port = htons ((uint16_t) port); | 1442 | |
1199 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1443 | /** |
1200 | v4.sin_len = sizeof(struct sockaddr_in); | 1444 | * Convert TCP bind specification to a `struct sockaddr *` |
1201 | #endif | 1445 | * |
1202 | in = GNUNET_memdup (&v4, sizeof(v4)); | 1446 | * @param bindto bind specification to convert |
1203 | *sock_len = sizeof(v4); | 1447 | * @param[out] sock_len set to the length of the address |
1204 | GNUNET_free (cp); | 1448 | * @return converted bindto specification |
1205 | return in; | 1449 | */ |
1206 | } | 1450 | static struct sockaddr * |
1451 | tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) | ||
1452 | { | ||
1453 | struct sockaddr *in; | ||
1454 | unsigned int port; | ||
1455 | struct sockaddr_in v4; | ||
1456 | struct sockaddr_in6 v6; | ||
1457 | const char *start; | ||
1458 | |||
1459 | // cp = GNUNET_strdup (bindto); | ||
1460 | start = extract_address (bindto); | ||
1461 | |||
1462 | if (1 == inet_pton (AF_INET, start, &v4.sin_addr)) | ||
1463 | { | ||
1464 | // colon = strrchr (cp, ':'); | ||
1465 | port = extract_port (bindto); | ||
1466 | in = tcp_address_to_sockaddr_numeric_v4 (sock_len, v4, port); | ||
1207 | } | 1467 | } |
1468 | else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr)) | ||
1208 | { | 1469 | { |
1209 | /* try IPv6 */ | 1470 | // colon = strrchr (cp, ':'); |
1210 | struct sockaddr_in6 v6; | 1471 | port = extract_port (bindto); |
1211 | const char *start; | 1472 | in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port); |
1212 | |||
1213 | start = cp; | ||
1214 | if (('[' == *cp) && (']' == cp[strlen (cp) - 1])) | ||
1215 | { | ||
1216 | start++; /* skip over '[' */ | ||
1217 | cp[strlen (cp) - 1] = '\0'; /* eat ']' */ | ||
1218 | } | ||
1219 | if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr)) | ||
1220 | { | ||
1221 | v6.sin6_family = AF_INET6; | ||
1222 | v6.sin6_port = htons ((uint16_t) port); | ||
1223 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1224 | v6.sin6_len = sizeof(sizeof(struct sockaddr_in6)); | ||
1225 | #endif | ||
1226 | in = GNUNET_memdup (&v6, sizeof(v6)); | ||
1227 | *sock_len = sizeof(v6); | ||
1228 | GNUNET_free (cp); | ||
1229 | return in; | ||
1230 | } | ||
1231 | } | 1473 | } |
1232 | /* #5528 FIXME (feature!): maybe also try getnameinfo()? */ | 1474 | |
1233 | GNUNET_free (cp); | 1475 | return in; |
1234 | return NULL; | ||
1235 | } | 1476 | } |
1236 | 1477 | ||
1237 | 1478 | ||
@@ -1547,6 +1788,8 @@ boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs) | |||
1547 | &queue->target, | 1788 | &queue->target, |
1548 | foreign_addr, | 1789 | foreign_addr, |
1549 | 0 /* no MTU */, | 1790 | 0 /* no MTU */, |
1791 | GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, | ||
1792 | 0, /* Priority */ | ||
1550 | queue->nt, | 1793 | queue->nt, |
1551 | cs, | 1794 | cs, |
1552 | queue->mq); | 1795 | queue->mq); |
@@ -1665,6 +1908,16 @@ decrypt_and_check_tc (struct Queue *queue, | |||
1665 | static void | 1908 | static void |
1666 | free_proto_queue (struct ProtoQueue *pq) | 1909 | free_proto_queue (struct ProtoQueue *pq) |
1667 | { | 1910 | { |
1911 | if (NULL != pq->listen_task) | ||
1912 | { | ||
1913 | GNUNET_SCHEDULER_cancel (pq->listen_task); | ||
1914 | pq->listen_task = NULL; | ||
1915 | } | ||
1916 | if (NULL != pq->listen_sock) | ||
1917 | { | ||
1918 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pq->listen_sock)); | ||
1919 | pq->listen_sock = NULL; | ||
1920 | } | ||
1668 | GNUNET_NETWORK_socket_close (pq->sock); | 1921 | GNUNET_NETWORK_socket_close (pq->sock); |
1669 | GNUNET_free (pq->address); | 1922 | GNUNET_free (pq->address); |
1670 | GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq); | 1923 | GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq); |
@@ -1737,6 +1990,8 @@ proto_read_kx (void *cls) | |||
1737 | queue->address = pq->address; /* steals reference */ | 1990 | queue->address = pq->address; /* steals reference */ |
1738 | queue->address_len = pq->address_len; | 1991 | queue->address_len = pq->address_len; |
1739 | queue->target = tc.sender; | 1992 | queue->target = tc.sender; |
1993 | queue->listen_task = pq->listen_task; | ||
1994 | queue->listen_sock = pq->listen_sock; | ||
1740 | queue->sock = pq->sock; | 1995 | queue->sock = pq->sock; |
1741 | start_initial_kx_out (queue); | 1996 | start_initial_kx_out (queue); |
1742 | boot_queue (queue, GNUNET_TRANSPORT_CS_INBOUND); | 1997 | boot_queue (queue, GNUNET_TRANSPORT_CS_INBOUND); |
@@ -1760,7 +2015,7 @@ proto_read_kx (void *cls) | |||
1760 | * read. Do the read and reschedule this function to be called again | 2015 | * read. Do the read and reschedule this function to be called again |
1761 | * once more is available. | 2016 | * once more is available. |
1762 | * | 2017 | * |
1763 | * @param cls NULL | 2018 | * @param cls ListenTask with listening socket and task |
1764 | */ | 2019 | */ |
1765 | static void | 2020 | static void |
1766 | listen_cb (void *cls) | 2021 | listen_cb (void *cls) |
@@ -1769,20 +2024,23 @@ listen_cb (void *cls) | |||
1769 | socklen_t addrlen; | 2024 | socklen_t addrlen; |
1770 | struct GNUNET_NETWORK_Handle *sock; | 2025 | struct GNUNET_NETWORK_Handle *sock; |
1771 | struct ProtoQueue *pq; | 2026 | struct ProtoQueue *pq; |
2027 | struct ListenTask *lt; | ||
1772 | 2028 | ||
1773 | listen_task = NULL; | 2029 | lt = cls; |
1774 | GNUNET_assert (NULL != listen_sock); | 2030 | |
2031 | lt->listen_task = NULL; | ||
2032 | GNUNET_assert (NULL != lt->listen_sock); | ||
1775 | addrlen = sizeof(in); | 2033 | addrlen = sizeof(in); |
1776 | memset (&in, 0, sizeof(in)); | 2034 | memset (&in, 0, sizeof(in)); |
1777 | sock = GNUNET_NETWORK_socket_accept (listen_sock, | 2035 | sock = GNUNET_NETWORK_socket_accept (lt->listen_sock, |
1778 | (struct sockaddr*) &in, | 2036 | (struct sockaddr*) &in, |
1779 | &addrlen); | 2037 | &addrlen); |
1780 | if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno))) | 2038 | if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno))) |
1781 | return; /* system limit reached, wait until connection goes down */ | 2039 | return; /* system limit reached, wait until connection goes down */ |
1782 | listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 2040 | lt->listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1783 | listen_sock, | 2041 | lt->listen_sock, |
1784 | &listen_cb, | 2042 | &listen_cb, |
1785 | NULL); | 2043 | lt); |
1786 | if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno))) | 2044 | if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno))) |
1787 | return; | 2045 | return; |
1788 | if (NULL == sock) | 2046 | if (NULL == sock) |
@@ -1882,7 +2140,6 @@ queue_read_kx (void *cls) | |||
1882 | queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue); | 2140 | queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue); |
1883 | } | 2141 | } |
1884 | 2142 | ||
1885 | |||
1886 | /** | 2143 | /** |
1887 | * Function called by the transport service to initialize a | 2144 | * Function called by the transport service to initialize a |
1888 | * message queue given address information about another peer. | 2145 | * message queue given address information about another peer. |
@@ -1922,6 +2179,13 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
1922 | path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; | 2179 | path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; |
1923 | in = tcp_address_to_sockaddr (path, &in_len); | 2180 | in = tcp_address_to_sockaddr (path, &in_len); |
1924 | 2181 | ||
2182 | if (NULL == in) | ||
2183 | { | ||
2184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2185 | "Failed to setup TCP socket address\n"); | ||
2186 | return GNUNET_SYSERR; | ||
2187 | } | ||
2188 | |||
1925 | sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP); | 2189 | sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP); |
1926 | if (NULL == sock) | 2190 | if (NULL == sock) |
1927 | { | 2191 | { |
@@ -1965,7 +2229,6 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
1965 | return GNUNET_OK; | 2229 | return GNUNET_OK; |
1966 | } | 2230 | } |
1967 | 2231 | ||
1968 | |||
1969 | /** | 2232 | /** |
1970 | * Iterator over all message queues to clean up. | 2233 | * Iterator over all message queues to clean up. |
1971 | * | 2234 | * |
@@ -2003,16 +2266,6 @@ do_shutdown (void *cls) | |||
2003 | GNUNET_NAT_unregister (nat); | 2266 | GNUNET_NAT_unregister (nat); |
2004 | nat = NULL; | 2267 | nat = NULL; |
2005 | } | 2268 | } |
2006 | if (NULL != listen_task) | ||
2007 | { | ||
2008 | GNUNET_SCHEDULER_cancel (listen_task); | ||
2009 | listen_task = NULL; | ||
2010 | } | ||
2011 | if (NULL != listen_sock) | ||
2012 | { | ||
2013 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (listen_sock)); | ||
2014 | listen_sock = NULL; | ||
2015 | } | ||
2016 | GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); | 2269 | GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); |
2017 | GNUNET_CONTAINER_multipeermap_destroy (queue_map); | 2270 | GNUNET_CONTAINER_multipeermap_destroy (queue_map); |
2018 | if (NULL != ch) | 2271 | if (NULL != ch) |
@@ -2085,6 +2338,10 @@ nat_address_cb (void *cls, | |||
2085 | char *my_addr; | 2338 | char *my_addr; |
2086 | struct GNUNET_TRANSPORT_AddressIdentifier *ai; | 2339 | struct GNUNET_TRANSPORT_AddressIdentifier *ai; |
2087 | 2340 | ||
2341 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2342 | "1 nat_address %s\n", | ||
2343 | GNUNET_a2s (addr, addrlen)); | ||
2344 | |||
2088 | if (GNUNET_YES == add_remove) | 2345 | if (GNUNET_YES == add_remove) |
2089 | { | 2346 | { |
2090 | enum GNUNET_NetworkType nt; | 2347 | enum GNUNET_NetworkType nt; |
@@ -2110,80 +2367,53 @@ nat_address_cb (void *cls, | |||
2110 | } | 2367 | } |
2111 | } | 2368 | } |
2112 | 2369 | ||
2113 | |||
2114 | /** | 2370 | /** |
2115 | * Setup communicator and launch network interactions. | 2371 | * This method launch network interactions for each address we like to bind to. |
2116 | * | 2372 | * |
2117 | * @param cls NULL (always) | 2373 | * @param addr The address we will listen to. |
2118 | * @param args remaining command-line arguments | 2374 | * @param in_len The length of the address we will listen to. |
2119 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | 2375 | * @return GNUNET_SYSERR in case of error. GNUNET_OK in case we are successfully listen to the address. |
2120 | * @param c configuration | ||
2121 | */ | 2376 | */ |
2122 | static void | 2377 | static int |
2123 | run (void *cls, | 2378 | init_socket (const struct sockaddr *addr, |
2124 | char *const *args, | 2379 | socklen_t in_len) |
2125 | const char *cfgfile, | ||
2126 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
2127 | { | 2380 | { |
2128 | char *bindto; | ||
2129 | struct sockaddr *in; | ||
2130 | socklen_t in_len; | ||
2131 | struct sockaddr_storage in_sto; | 2381 | struct sockaddr_storage in_sto; |
2132 | socklen_t sto_len; | 2382 | socklen_t sto_len; |
2383 | struct GNUNET_NETWORK_Handle *listen_sock; | ||
2384 | struct ListenTask *lt; | ||
2133 | 2385 | ||
2134 | (void) cls; | 2386 | if (NULL == addr) |
2135 | cfg = c; | ||
2136 | if (GNUNET_OK != | ||
2137 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
2138 | COMMUNICATOR_CONFIG_SECTION, | ||
2139 | "BINDTO", | ||
2140 | &bindto)) | ||
2141 | { | ||
2142 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
2143 | COMMUNICATOR_CONFIG_SECTION, | ||
2144 | "BINDTO"); | ||
2145 | return; | ||
2146 | } | ||
2147 | if (GNUNET_OK != | ||
2148 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
2149 | COMMUNICATOR_CONFIG_SECTION, | ||
2150 | "MAX_QUEUE_LENGTH", | ||
2151 | &max_queue_length)) | ||
2152 | max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; | ||
2153 | if (GNUNET_OK != | ||
2154 | GNUNET_CONFIGURATION_get_value_time (cfg, | ||
2155 | COMMUNICATOR_CONFIG_SECTION, | ||
2156 | "REKEY_INTERVAL", | ||
2157 | &rekey_interval)) | ||
2158 | rekey_interval = DEFAULT_REKEY_INTERVAL; | ||
2159 | |||
2160 | in = tcp_address_to_sockaddr (bindto, &in_len); | ||
2161 | if (NULL == in) | ||
2162 | { | 2387 | { |
2163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2164 | "Failed to setup TCP socket address with path `%s'\n", | 2389 | "Address is NULL.\n"); |
2165 | bindto); | 2390 | return GNUNET_SYSERR; |
2166 | GNUNET_free (bindto); | ||
2167 | return; | ||
2168 | } | 2391 | } |
2392 | |||
2393 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2394 | "4 address %s\n", | ||
2395 | GNUNET_a2s (addr, in_len)); | ||
2396 | |||
2397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2398 | "address %s\n", | ||
2399 | GNUNET_a2s (addr, in_len)); | ||
2400 | |||
2169 | listen_sock = | 2401 | listen_sock = |
2170 | GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP); | 2402 | GNUNET_NETWORK_socket_create (addr->sa_family, SOCK_STREAM, IPPROTO_TCP); |
2171 | if (NULL == listen_sock) | 2403 | if (NULL == listen_sock) |
2172 | { | 2404 | { |
2173 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 2405 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
2174 | GNUNET_free (in); | 2406 | return GNUNET_SYSERR; |
2175 | GNUNET_free (bindto); | ||
2176 | return; | ||
2177 | } | 2407 | } |
2178 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, in, in_len)) | 2408 | |
2409 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, addr, in_len)) | ||
2179 | { | 2410 | { |
2180 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto); | 2411 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); |
2181 | GNUNET_NETWORK_socket_close (listen_sock); | 2412 | GNUNET_NETWORK_socket_close (listen_sock); |
2182 | listen_sock = NULL; | 2413 | listen_sock = NULL; |
2183 | GNUNET_free (in); | 2414 | return GNUNET_SYSERR; |
2184 | GNUNET_free (bindto); | ||
2185 | return; | ||
2186 | } | 2415 | } |
2416 | |||
2187 | if (GNUNET_OK != | 2417 | if (GNUNET_OK != |
2188 | GNUNET_NETWORK_socket_listen (listen_sock, | 2418 | GNUNET_NETWORK_socket_listen (listen_sock, |
2189 | 5)) | 2419 | 5)) |
@@ -2192,69 +2422,311 @@ run (void *cls, | |||
2192 | "listen"); | 2422 | "listen"); |
2193 | GNUNET_NETWORK_socket_close (listen_sock); | 2423 | GNUNET_NETWORK_socket_close (listen_sock); |
2194 | listen_sock = NULL; | 2424 | listen_sock = NULL; |
2195 | GNUNET_free (in); | 2425 | return GNUNET_SYSERR; |
2196 | GNUNET_free (bindto); | ||
2197 | } | 2426 | } |
2427 | |||
2198 | /* We might have bound to port 0, allowing the OS to figure it out; | 2428 | /* We might have bound to port 0, allowing the OS to figure it out; |
2199 | thus, get the real IN-address from the socket */ | 2429 | thus, get the real IN-address from the socket */ |
2200 | sto_len = sizeof(in_sto); | 2430 | sto_len = sizeof(in_sto); |
2431 | |||
2201 | if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock), | 2432 | if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock), |
2202 | (struct sockaddr *) &in_sto, | 2433 | (struct sockaddr *) &in_sto, |
2203 | &sto_len)) | 2434 | &sto_len)) |
2204 | { | 2435 | { |
2205 | memcpy (&in_sto, in, in_len); | 2436 | memcpy (&in_sto, addr, in_len); |
2206 | sto_len = in_len; | 2437 | sto_len = in_len; |
2207 | } | 2438 | } |
2208 | GNUNET_free (in); | 2439 | |
2209 | GNUNET_free (bindto); | 2440 | addr = (struct sockaddr *) &in_sto; |
2210 | in = (struct sockaddr *) &in_sto; | ||
2211 | in_len = sto_len; | 2441 | in_len = sto_len; |
2212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2213 | "Bound to `%s'\n", | 2443 | "Bound to `%s'\n", |
2214 | GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); | 2444 | GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); |
2215 | stats = GNUNET_STATISTICS_create ("C-TCP", cfg); | 2445 | stats = GNUNET_STATISTICS_create ("C-TCP", cfg); |
2216 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 2446 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
2217 | is = GNUNET_NT_scanner_init (); | 2447 | |
2218 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); | 2448 | if (NULL == is) |
2449 | is = GNUNET_NT_scanner_init (); | ||
2450 | |||
2451 | if (NULL == my_private_key) | ||
2452 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); | ||
2219 | if (NULL == my_private_key) | 2453 | if (NULL == my_private_key) |
2220 | { | 2454 | { |
2221 | GNUNET_log ( | 2455 | GNUNET_log ( |
2222 | GNUNET_ERROR_TYPE_ERROR, | 2456 | GNUNET_ERROR_TYPE_ERROR, |
2223 | _ ( | 2457 | _ ( |
2224 | "Transport service is lacking key configuration settings. Exiting.\n")); | 2458 | "Transport service is lacking key configuration settings. Exiting.\n")); |
2459 | GNUNET_RESOLVER_request_cancel (resolve_request_handle); | ||
2225 | GNUNET_SCHEDULER_shutdown (); | 2460 | GNUNET_SCHEDULER_shutdown (); |
2226 | return; | 2461 | return GNUNET_SYSERR; |
2227 | } | 2462 | } |
2228 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); | 2463 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); |
2229 | /* start listening */ | 2464 | /* start listening */ |
2230 | listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 2465 | |
2231 | listen_sock, | 2466 | lt = GNUNET_new (struct ListenTask); |
2232 | &listen_cb, | 2467 | lt->listen_sock = listen_sock; |
2233 | NULL); | 2468 | |
2234 | queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 2469 | lt->listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
2235 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, | 2470 | listen_sock, |
2236 | COMMUNICATOR_CONFIG_SECTION, | 2471 | &listen_cb, |
2237 | COMMUNICATOR_ADDRESS_PREFIX, | 2472 | lt); |
2238 | GNUNET_TRANSPORT_CC_RELIABLE, | 2473 | |
2239 | &mq_init, | 2474 | if (NULL == queue_map) |
2240 | NULL, | 2475 | queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
2241 | &enc_notify_cb, | 2476 | |
2242 | NULL); | 2477 | if (NULL == ch ) |
2478 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, | ||
2479 | COMMUNICATOR_CONFIG_SECTION, | ||
2480 | COMMUNICATOR_ADDRESS_PREFIX, | ||
2481 | GNUNET_TRANSPORT_CC_RELIABLE, | ||
2482 | &mq_init, | ||
2483 | NULL, | ||
2484 | &enc_notify_cb, | ||
2485 | NULL); | ||
2486 | |||
2243 | if (NULL == ch) | 2487 | if (NULL == ch) |
2244 | { | 2488 | { |
2245 | GNUNET_break (0); | 2489 | GNUNET_break (0); |
2490 | GNUNET_RESOLVER_request_cancel (resolve_request_handle); | ||
2246 | GNUNET_SCHEDULER_shutdown (); | 2491 | GNUNET_SCHEDULER_shutdown (); |
2247 | return; | 2492 | return GNUNET_SYSERR; |
2493 | } | ||
2494 | |||
2495 | return GNUNET_OK; | ||
2496 | |||
2497 | } | ||
2498 | |||
2499 | /** | ||
2500 | * This method reads from the DLL addrs_head to register them at the NAT service. | ||
2501 | */ | ||
2502 | static void | ||
2503 | nat_register () | ||
2504 | { | ||
2505 | |||
2506 | struct sockaddr **saddrs; | ||
2507 | socklen_t *saddr_lens; | ||
2508 | int i; | ||
2509 | struct Addresses *pos; | ||
2510 | |||
2511 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2512 | "nat here\n"); | ||
2513 | |||
2514 | i = 0; | ||
2515 | saddrs = GNUNET_malloc ((addrs_lens + 1) * sizeof(struct sockaddr *)); | ||
2516 | |||
2517 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2518 | "2 nat here\n"); | ||
2519 | |||
2520 | saddr_lens = GNUNET_malloc ((addrs_lens + 1) * sizeof(socklen_t)); | ||
2521 | |||
2522 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2523 | "3 nat here\n"); | ||
2524 | |||
2525 | for (pos = addrs_head; NULL != pos; pos = pos->next) | ||
2526 | { | ||
2527 | |||
2528 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2529 | "5 nat here\n"); | ||
2530 | |||
2531 | saddr_lens[i] = addrs_head->addr_len; | ||
2532 | saddrs[i] = GNUNET_malloc (saddr_lens[i]); | ||
2533 | saddrs[i] = addrs_head->addr; | ||
2534 | |||
2535 | i++; | ||
2536 | |||
2537 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2538 | "6 nat here\n"); | ||
2539 | |||
2248 | } | 2540 | } |
2541 | |||
2249 | nat = GNUNET_NAT_register (cfg, | 2542 | nat = GNUNET_NAT_register (cfg, |
2250 | COMMUNICATOR_CONFIG_SECTION, | 2543 | COMMUNICATOR_CONFIG_SECTION, |
2251 | IPPROTO_TCP, | 2544 | IPPROTO_TCP, |
2252 | 1 /* one address */, | 2545 | addrs_lens, |
2253 | (const struct sockaddr **) &in, | 2546 | (const struct sockaddr **) saddrs, |
2254 | &in_len, | 2547 | saddr_lens, |
2255 | &nat_address_cb, | 2548 | &nat_address_cb, |
2256 | NULL /* FIXME: support reversal: #5529 */, | 2549 | NULL /* FIXME: support reversal: #5529 */, |
2257 | NULL /* closure */); | 2550 | NULL /* closure */); |
2551 | |||
2552 | if (NULL == nat) | ||
2553 | { | ||
2554 | GNUNET_break (0); | ||
2555 | GNUNET_RESOLVER_request_cancel (resolve_request_handle); | ||
2556 | GNUNET_SCHEDULER_shutdown (); | ||
2557 | } | ||
2558 | } | ||
2559 | |||
2560 | /** | ||
2561 | * This method adds addresses to the DLL, that are later register at the NAT service. | ||
2562 | */ | ||
2563 | static void | ||
2564 | add_addr (struct sockaddr *in, socklen_t in_len) | ||
2565 | { | ||
2566 | |||
2567 | struct Addresses *saddrs; | ||
2568 | |||
2569 | saddrs = GNUNET_new (struct Addresses); | ||
2570 | saddrs->addr = in; | ||
2571 | saddrs->addr_len = in_len; | ||
2572 | GNUNET_CONTAINER_DLL_insert (addrs_head, addrs_tail, saddrs); | ||
2573 | addrs_lens++; | ||
2574 | } | ||
2575 | |||
2576 | /** | ||
2577 | * This method is the callback called by the resolver API, and wraps method init_socket. | ||
2578 | * | ||
2579 | * @param cls The port we will bind to. | ||
2580 | * @param addr The address we will bind to. | ||
2581 | * @param in_len The length of the address we will bind to. | ||
2582 | */ | ||
2583 | static void | ||
2584 | init_socket_resolv (void *cls, | ||
2585 | const struct sockaddr *addr, | ||
2586 | socklen_t in_len) | ||
2587 | { | ||
2588 | struct sockaddr_in *v4; | ||
2589 | struct sockaddr_in6 *v6; | ||
2590 | struct sockaddr *in; | ||
2591 | unsigned int *port; | ||
2592 | |||
2593 | port = cls; | ||
2594 | if (NULL != addr) | ||
2595 | { | ||
2596 | if (AF_INET == addr->sa_family) | ||
2597 | { | ||
2598 | v4 = (struct sockaddr_in *) addr; | ||
2599 | in = tcp_address_to_sockaddr_numeric_v4 (&in_len, *v4, *port);// _global); | ||
2600 | add_addr (in, in_len); | ||
2601 | } | ||
2602 | else if (AF_INET6 == addr->sa_family) | ||
2603 | { | ||
2604 | v6 = (struct sockaddr_in6 *) addr; | ||
2605 | in = tcp_address_to_sockaddr_numeric_v6 (&in_len, *v6, *port);// _global); | ||
2606 | add_addr (in, in_len); | ||
2607 | } | ||
2608 | else | ||
2609 | { | ||
2610 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2611 | "Address family %u not suitable (not AF_INET %u nor AF_INET6 %u \n", | ||
2612 | addr->sa_family, | ||
2613 | AF_INET, | ||
2614 | AF_INET6); | ||
2615 | return; | ||
2616 | } | ||
2617 | init_socket (in, | ||
2618 | in_len); | ||
2619 | } | ||
2620 | else | ||
2621 | { | ||
2622 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
2623 | "Address is NULL. This might be an error or the resolver finished resolving.\n"); | ||
2624 | nat_register (); | ||
2625 | } | ||
2626 | } | ||
2627 | |||
2628 | /** | ||
2629 | * Setup communicator and launch network interactions. | ||
2630 | * | ||
2631 | * @param cls NULL (always) | ||
2632 | * @param args remaining command-line arguments | ||
2633 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
2634 | * @param c configuration | ||
2635 | */ | ||
2636 | static void | ||
2637 | run (void *cls, | ||
2638 | char *const *args, | ||
2639 | const char *cfgfile, | ||
2640 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
2641 | { | ||
2642 | char *bindto; | ||
2643 | struct sockaddr *in; | ||
2644 | socklen_t in_len; | ||
2645 | struct sockaddr_in v4; | ||
2646 | struct sockaddr_in6 v6; | ||
2647 | char *start; | ||
2648 | unsigned int port; | ||
2649 | char dummy[2]; | ||
2650 | char *rest = NULL; | ||
2651 | struct PortOnlyIpv4Ipv6 *po; | ||
2652 | |||
2653 | (void) cls; | ||
2654 | cfg = c; | ||
2655 | if (GNUNET_OK != | ||
2656 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
2657 | COMMUNICATOR_CONFIG_SECTION, | ||
2658 | "BINDTO", | ||
2659 | &bindto)) | ||
2660 | { | ||
2661 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
2662 | COMMUNICATOR_CONFIG_SECTION, | ||
2663 | "BINDTO"); | ||
2664 | return; | ||
2665 | } | ||
2666 | if (GNUNET_OK != | ||
2667 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
2668 | COMMUNICATOR_CONFIG_SECTION, | ||
2669 | "MAX_QUEUE_LENGTH", | ||
2670 | &max_queue_length)) | ||
2671 | max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; | ||
2672 | if (GNUNET_OK != | ||
2673 | GNUNET_CONFIGURATION_get_value_time (cfg, | ||
2674 | COMMUNICATOR_CONFIG_SECTION, | ||
2675 | "REKEY_INTERVAL", | ||
2676 | &rekey_interval)) | ||
2677 | rekey_interval = DEFAULT_REKEY_INTERVAL; | ||
2678 | |||
2679 | |||
2680 | // cp = GNUNET_strdup (bindto); | ||
2681 | start = extract_address (bindto); | ||
2682 | |||
2683 | if (1 == sscanf (bindto, "%u%1s", &port, dummy)) | ||
2684 | { | ||
2685 | po = tcp_address_to_sockaddr_port_only (bindto, &port); | ||
2686 | |||
2687 | if (NULL != &po->addr_ipv4) | ||
2688 | { | ||
2689 | init_socket (po->addr_ipv4, *po->addr_len_ipv4); | ||
2690 | add_addr (po->addr_ipv4, *po->addr_len_ipv4); | ||
2691 | } | ||
2692 | |||
2693 | if (NULL != &po->addr_ipv6) | ||
2694 | { | ||
2695 | init_socket (po->addr_ipv6, *po->addr_len_ipv6); | ||
2696 | add_addr (po->addr_ipv6, *po->addr_len_ipv6); | ||
2697 | } | ||
2698 | |||
2699 | nat_register (); | ||
2700 | } | ||
2701 | else if (1 == inet_pton (AF_INET, start, &v4.sin_addr)) | ||
2702 | { | ||
2703 | port = extract_port (bindto); | ||
2704 | |||
2705 | in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, port); | ||
2706 | init_socket (in, in_len); | ||
2707 | add_addr (in, in_len); | ||
2708 | nat_register (); | ||
2709 | } | ||
2710 | else if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr)) | ||
2711 | { | ||
2712 | port = extract_port (bindto); | ||
2713 | in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, port); | ||
2714 | init_socket (in, in_len); | ||
2715 | add_addr (in, in_len); | ||
2716 | nat_register (); | ||
2717 | } | ||
2718 | else | ||
2719 | { | ||
2720 | port = extract_port (bindto); | ||
2721 | |||
2722 | resolve_request_handle = GNUNET_RESOLVER_ip_get (strtok_r (bindto, ":", | ||
2723 | &rest), | ||
2724 | AF_UNSPEC, | ||
2725 | GNUNET_TIME_UNIT_MINUTES, | ||
2726 | &init_socket_resolv, | ||
2727 | &port); | ||
2728 | } | ||
2729 | GNUNET_free (bindto); | ||
2258 | } | 2730 | } |
2259 | 2731 | ||
2260 | 2732 | ||
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index 72e84567a..585b29c2d 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -549,14 +549,24 @@ struct ReceiverAddress | |||
549 | struct GNUNET_CONTAINER_HeapNode *hn; | 549 | struct GNUNET_CONTAINER_HeapNode *hn; |
550 | 550 | ||
551 | /** | 551 | /** |
552 | * Message queue we are providing for the #ch. | 552 | * KX message queue we are providing for the #ch. |
553 | */ | 553 | */ |
554 | struct GNUNET_MQ_Handle *mq; | 554 | struct GNUNET_MQ_Handle *kx_mq; |
555 | |||
556 | /** | ||
557 | * Default message queue we are providing for the #ch. | ||
558 | */ | ||
559 | struct GNUNET_MQ_Handle *d_mq; | ||
555 | 560 | ||
556 | /** | 561 | /** |
557 | * handle for this queue with the #ch. | 562 | * handle for KX queue with the #ch. |
558 | */ | 563 | */ |
559 | struct GNUNET_TRANSPORT_QueueHandle *qh; | 564 | struct GNUNET_TRANSPORT_QueueHandle *kx_qh; |
565 | |||
566 | /** | ||
567 | * handle for default queue with the #ch. | ||
568 | */ | ||
569 | struct GNUNET_TRANSPORT_QueueHandle *d_qh; | ||
560 | 570 | ||
561 | /** | 571 | /** |
562 | * Timeout for this receiver address. | 572 | * Timeout for this receiver address. |
@@ -564,9 +574,14 @@ struct ReceiverAddress | |||
564 | struct GNUNET_TIME_Absolute timeout; | 574 | struct GNUNET_TIME_Absolute timeout; |
565 | 575 | ||
566 | /** | 576 | /** |
567 | * MTU we allowed transport for this receiver right now. | 577 | * MTU we allowed transport for this receiver's KX queue. |
568 | */ | 578 | */ |
569 | size_t mtu; | 579 | size_t kx_mtu; |
580 | |||
581 | /** | ||
582 | * MTU we allowed transport for this receiver's default queue. | ||
583 | */ | ||
584 | size_t d_mtu; | ||
570 | 585 | ||
571 | /** | 586 | /** |
572 | * Length of the DLL at @a ss_head. | 587 | * Length of the DLL at @a ss_head. |
@@ -786,15 +801,25 @@ receiver_destroy (struct ReceiverAddress *receiver) | |||
786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
787 | "Disconnecting receiver for peer `%s'\n", | 802 | "Disconnecting receiver for peer `%s'\n", |
788 | GNUNET_i2s (&receiver->target)); | 803 | GNUNET_i2s (&receiver->target)); |
789 | if (NULL != (mq = receiver->mq)) | 804 | if (NULL != (mq = receiver->kx_mq)) |
805 | { | ||
806 | receiver->kx_mq = NULL; | ||
807 | GNUNET_MQ_destroy (mq); | ||
808 | } | ||
809 | if (NULL != receiver->kx_qh) | ||
810 | { | ||
811 | GNUNET_TRANSPORT_communicator_mq_del (receiver->kx_qh); | ||
812 | receiver->kx_qh = NULL; | ||
813 | } | ||
814 | if (NULL != (mq = receiver->d_mq)) | ||
790 | { | 815 | { |
791 | receiver->mq = NULL; | 816 | receiver->d_mq = NULL; |
792 | GNUNET_MQ_destroy (mq); | 817 | GNUNET_MQ_destroy (mq); |
793 | } | 818 | } |
794 | if (NULL != receiver->qh) | 819 | if (NULL != receiver->d_qh) |
795 | { | 820 | { |
796 | GNUNET_TRANSPORT_communicator_mq_del (receiver->qh); | 821 | GNUNET_TRANSPORT_communicator_mq_del (receiver->d_qh); |
797 | receiver->qh = NULL; | 822 | receiver->d_qh = NULL; |
798 | } | 823 | } |
799 | GNUNET_assert (GNUNET_YES == | 824 | GNUNET_assert (GNUNET_YES == |
800 | GNUNET_CONTAINER_multipeermap_remove (receivers, | 825 | GNUNET_CONTAINER_multipeermap_remove (receivers, |
@@ -1030,6 +1055,8 @@ check_timeouts (void *cls) | |||
1030 | rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout); | 1055 | rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout); |
1031 | if (0 != rt.rel_value_us) | 1056 | if (0 != rt.rel_value_us) |
1032 | break; | 1057 | break; |
1058 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1059 | "Receiver timed out\n"); | ||
1033 | receiver_destroy (receiver); | 1060 | receiver_destroy (receiver); |
1034 | } | 1061 | } |
1035 | st = GNUNET_TIME_UNIT_FOREVER_REL; | 1062 | st = GNUNET_TIME_UNIT_FOREVER_REL; |
@@ -1257,6 +1284,8 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
1257 | { | 1284 | { |
1258 | const struct UDPAck *ack = cls; | 1285 | const struct UDPAck *ack = cls; |
1259 | struct ReceiverAddress *receiver = value; | 1286 | struct ReceiverAddress *receiver = value; |
1287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1288 | "in handle ack\n"); | ||
1260 | 1289 | ||
1261 | (void) pid; | 1290 | (void) pid; |
1262 | for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next) | 1291 | for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next) |
@@ -1264,17 +1293,24 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
1264 | if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode))) | 1293 | if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode))) |
1265 | { | 1294 | { |
1266 | uint32_t allowed; | 1295 | uint32_t allowed; |
1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1297 | "Found matching mac\n"); | ||
1267 | 1298 | ||
1268 | allowed = ntohl (ack->sequence_max); | 1299 | allowed = ntohl (ack->sequence_max); |
1269 | 1300 | ||
1270 | if (allowed > ss->sequence_allowed) | 1301 | if (allowed > ss->sequence_allowed) |
1271 | { | 1302 | { |
1303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1304 | "%u > %u (%u)\n", allowed, ss->sequence_allowed, | ||
1305 | receiver->acks_available); | ||
1306 | |||
1272 | receiver->acks_available += (allowed - ss->sequence_allowed); | 1307 | receiver->acks_available += (allowed - ss->sequence_allowed); |
1273 | if ((allowed - ss->sequence_allowed) == receiver->acks_available) | 1308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1274 | { | 1309 | "Tell transport we have more acks!\n"); |
1275 | /* we just incremented from zero => MTU change! */ | 1310 | GNUNET_TRANSPORT_communicator_mq_update (ch, |
1276 | setup_receiver_mq (receiver); | 1311 | receiver->d_qh, |
1277 | } | 1312 | (allowed - ss->sequence_allowed), |
1313 | 1); | ||
1278 | ss->sequence_allowed = allowed; | 1314 | ss->sequence_allowed = allowed; |
1279 | /* move ss to head to avoid discarding it anytime soon! */ | 1315 | /* move ss to head to avoid discarding it anytime soon! */ |
1280 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); | 1316 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); |
@@ -1361,6 +1397,9 @@ consider_ss_ack (struct SharedSecret *ss) | |||
1361 | ack.header.size = htons (sizeof(ack)); | 1397 | ack.header.size = htons (sizeof(ack)); |
1362 | ack.sequence_max = htonl (ss->sequence_allowed); | 1398 | ack.sequence_max = htonl (ss->sequence_allowed); |
1363 | ack.cmac = ss->cmac; | 1399 | ack.cmac = ss->cmac; |
1400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1401 | "Notifying transport of UDPAck %s\n", | ||
1402 | GNUNET_i2s_full (&ss->sender->target)); | ||
1364 | GNUNET_TRANSPORT_communicator_notify (ch, | 1403 | GNUNET_TRANSPORT_communicator_notify (ch, |
1365 | &ss->sender->target, | 1404 | &ss->sender->target, |
1366 | COMMUNICATOR_ADDRESS_PREFIX, | 1405 | COMMUNICATOR_ADDRESS_PREFIX, |
@@ -1889,15 +1928,24 @@ do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) | |||
1889 | * @param impl_state our `struct ReceiverAddress` | 1928 | * @param impl_state our `struct ReceiverAddress` |
1890 | */ | 1929 | */ |
1891 | static void | 1930 | static void |
1892 | mq_send (struct GNUNET_MQ_Handle *mq, | 1931 | mq_send_kx (struct GNUNET_MQ_Handle *mq, |
1893 | const struct GNUNET_MessageHeader *msg, | 1932 | const struct GNUNET_MessageHeader *msg, |
1894 | void *impl_state) | 1933 | void *impl_state) |
1895 | { | 1934 | { |
1896 | struct ReceiverAddress *receiver = impl_state; | 1935 | struct ReceiverAddress *receiver = impl_state; |
1897 | uint16_t msize = ntohs (msg->size); | 1936 | uint16_t msize = ntohs (msg->size); |
1937 | struct UdpHandshakeSignature uhs; | ||
1938 | struct UDPConfirmation uc; | ||
1939 | struct InitialKX kx; | ||
1940 | struct GNUNET_CRYPTO_EcdhePrivateKey epriv; | ||
1941 | char dgram[receiver->kx_mtu + sizeof(uc) + sizeof(kx)]; | ||
1942 | size_t dpos; | ||
1943 | gcry_cipher_hd_t out_cipher; | ||
1944 | struct SharedSecret *ss; | ||
1898 | 1945 | ||
1899 | GNUNET_assert (mq == receiver->mq); | 1946 | |
1900 | if (msize > receiver->mtu) | 1947 | GNUNET_assert (mq == receiver->kx_mq); |
1948 | if (msize > receiver->kx_mtu) | ||
1901 | { | 1949 | { |
1902 | GNUNET_break (0); | 1950 | GNUNET_break (0); |
1903 | receiver_destroy (receiver); | 1951 | receiver_destroy (receiver); |
@@ -1905,117 +1953,125 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
1905 | } | 1953 | } |
1906 | reschedule_receiver_timeout (receiver); | 1954 | reschedule_receiver_timeout (receiver); |
1907 | 1955 | ||
1908 | if (0 == receiver->acks_available) | 1956 | /* setup key material */ |
1957 | GNUNET_CRYPTO_ecdhe_key_create (&epriv); | ||
1958 | |||
1959 | ss = setup_shared_secret_enc (&epriv, receiver); | ||
1960 | setup_cipher (&ss->master, 0, &out_cipher); | ||
1961 | /* compute 'uc' */ | ||
1962 | uc.sender = my_identity; | ||
1963 | uc.monotonic_time = | ||
1964 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); | ||
1965 | uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); | ||
1966 | uhs.purpose.size = htonl (sizeof(uhs)); | ||
1967 | uhs.sender = my_identity; | ||
1968 | uhs.receiver = receiver->target; | ||
1969 | GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral); | ||
1970 | uhs.monotonic_time = uc.monotonic_time; | ||
1971 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | ||
1972 | &uhs, | ||
1973 | &uc.sender_sig); | ||
1974 | /* Leave space for kx */ | ||
1975 | dpos = sizeof(kx); | ||
1976 | /* Append encrypted uc to dgram */ | ||
1977 | GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher, | ||
1978 | &dgram[dpos], | ||
1979 | sizeof(uc), | ||
1980 | &uc, | ||
1981 | sizeof(uc))); | ||
1982 | dpos += sizeof(uc); | ||
1983 | /* Append encrypted payload to dgram */ | ||
1984 | GNUNET_assert ( | ||
1985 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); | ||
1986 | dpos += msize; | ||
1987 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); | ||
1988 | /* Datagram starts with kx */ | ||
1989 | kx.ephemeral = uhs.ephemeral; | ||
1990 | GNUNET_assert ( | ||
1991 | 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag))); | ||
1992 | gcry_cipher_close (out_cipher); | ||
1993 | memcpy (dgram, &kx, sizeof(kx)); | ||
1994 | if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, | ||
1995 | dgram, | ||
1996 | sizeof(dgram), | ||
1997 | receiver->address, | ||
1998 | receiver->address_len)) | ||
1999 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); | ||
2000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2001 | "Sending KX to %s\n", GNUNET_a2s (receiver->address, | ||
2002 | receiver->address_len)); | ||
2003 | GNUNET_MQ_impl_send_continue (mq); | ||
2004 | } | ||
2005 | |||
2006 | |||
2007 | /** | ||
2008 | * Signature of functions implementing the sending functionality of a | ||
2009 | * message queue. | ||
2010 | * | ||
2011 | * @param mq the message queue | ||
2012 | * @param msg the message to send | ||
2013 | * @param impl_state our `struct ReceiverAddress` | ||
2014 | */ | ||
2015 | static void | ||
2016 | mq_send_d (struct GNUNET_MQ_Handle *mq, | ||
2017 | const struct GNUNET_MessageHeader *msg, | ||
2018 | void *impl_state) | ||
2019 | { | ||
2020 | struct ReceiverAddress *receiver = impl_state; | ||
2021 | uint16_t msize = ntohs (msg->size); | ||
2022 | |||
2023 | GNUNET_assert (mq == receiver->d_mq); | ||
2024 | if ((msize > receiver->d_mtu) || | ||
2025 | (0 == receiver->acks_available)) | ||
1909 | { | 2026 | { |
1910 | /* use KX encryption method */ | 2027 | GNUNET_break (0); |
1911 | struct UdpHandshakeSignature uhs; | 2028 | receiver_destroy (receiver); |
1912 | struct UDPConfirmation uc; | 2029 | return; |
1913 | struct InitialKX kx; | 2030 | } |
1914 | struct GNUNET_CRYPTO_EcdhePrivateKey epriv; | 2031 | reschedule_receiver_timeout (receiver); |
1915 | char dgram[receiver->mtu + sizeof(uc) + sizeof(kx)]; | ||
1916 | size_t dpos; | ||
1917 | gcry_cipher_hd_t out_cipher; | ||
1918 | struct SharedSecret *ss; | ||
1919 | 2032 | ||
1920 | /* setup key material */ | 2033 | /* begin "BOX" encryption method, scan for ACKs from tail! */ |
1921 | GNUNET_CRYPTO_ecdhe_key_create (&epriv); | 2034 | for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev) |
2035 | { | ||
2036 | if (ss->sequence_used >= ss->sequence_allowed) | ||
2037 | { | ||
2038 | continue; | ||
2039 | } | ||
2040 | char dgram[sizeof(struct UDPBox) + receiver->d_mtu]; | ||
2041 | struct UDPBox *box; | ||
2042 | gcry_cipher_hd_t out_cipher; | ||
2043 | size_t dpos; | ||
1922 | 2044 | ||
1923 | ss = setup_shared_secret_enc (&epriv, receiver); | 2045 | box = (struct UDPBox *) dgram; |
1924 | setup_cipher (&ss->master, 0, &out_cipher); | 2046 | ss->sequence_used++; |
1925 | /* compute 'uc' */ | 2047 | get_kid (&ss->master, ss->sequence_used, &box->kid); |
1926 | uc.sender = my_identity; | 2048 | setup_cipher (&ss->master, ss->sequence_used, &out_cipher); |
1927 | uc.monotonic_time = | ||
1928 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); | ||
1929 | uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); | ||
1930 | uhs.purpose.size = htonl (sizeof(uhs)); | ||
1931 | uhs.sender = my_identity; | ||
1932 | uhs.receiver = receiver->target; | ||
1933 | GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral); | ||
1934 | uhs.monotonic_time = uc.monotonic_time; | ||
1935 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | ||
1936 | &uhs, | ||
1937 | &uc.sender_sig); | ||
1938 | /* Leave space for kx */ | ||
1939 | dpos = sizeof(kx); | ||
1940 | /* Append encrypted uc to dgram */ | ||
1941 | GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher, | ||
1942 | &dgram[dpos], | ||
1943 | sizeof(uc), | ||
1944 | &uc, | ||
1945 | sizeof(uc))); | ||
1946 | dpos += sizeof(uc); | ||
1947 | /* Append encrypted payload to dgram */ | 2049 | /* Append encrypted payload to dgram */ |
2050 | dpos = sizeof(struct UDPBox); | ||
1948 | GNUNET_assert ( | 2051 | GNUNET_assert ( |
1949 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); | 2052 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); |
1950 | dpos += msize; | 2053 | dpos += msize; |
1951 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); | 2054 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); |
1952 | /* Datagram starts with kx */ | 2055 | GNUNET_assert (0 == gcry_cipher_gettag (out_cipher, |
1953 | kx.ephemeral = uhs.ephemeral; | 2056 | box->gcm_tag, |
1954 | GNUNET_assert ( | 2057 | sizeof(box->gcm_tag))); |
1955 | 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag))); | ||
1956 | gcry_cipher_close (out_cipher); | 2058 | gcry_cipher_close (out_cipher); |
1957 | memcpy (dgram, &kx, sizeof(kx)); | ||
1958 | if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, | 2059 | if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, |
1959 | dgram, | 2060 | dgram, |
1960 | sizeof(dgram), | 2061 | sizeof(dgram), |
1961 | receiver->address, | 2062 | receiver->address, |
1962 | receiver->address_len)) | 2063 | receiver->address_len)) |
1963 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); | 2064 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); |
1964 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1965 | "Sending KX to %s\n", GNUNET_a2s (receiver->address, | ||
1966 | receiver->address_len)); | ||
1967 | GNUNET_MQ_impl_send_continue (mq); | 2065 | GNUNET_MQ_impl_send_continue (mq); |
1968 | return; | 2066 | receiver->acks_available--; |
1969 | } /* End of KX encryption method */ | 2067 | if (0 == receiver->acks_available) |
1970 | |||
1971 | /* begin "BOX" encryption method, scan for ACKs from tail! */ | ||
1972 | for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev) | ||
1973 | { | ||
1974 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1975 | "In non-kx mode...\n"); | ||
1976 | if (ss->sequence_used < ss->sequence_allowed) | ||
1977 | { | 2068 | { |
1978 | char dgram[sizeof(struct UDPBox) + receiver->mtu]; | 2069 | /* We have no more ACKs */ |
1979 | struct UDPBox *box; | ||
1980 | gcry_cipher_hd_t out_cipher; | ||
1981 | size_t dpos; | ||
1982 | |||
1983 | box = (struct UDPBox *) dgram; | ||
1984 | ss->sequence_used++; | ||
1985 | get_kid (&ss->master, ss->sequence_used, &box->kid); | ||
1986 | setup_cipher (&ss->master, ss->sequence_used, &out_cipher); | ||
1987 | /* Append encrypted payload to dgram */ | ||
1988 | dpos = sizeof(struct UDPBox); | ||
1989 | GNUNET_assert ( | ||
1990 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); | ||
1991 | dpos += msize; | ||
1992 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); | ||
1993 | GNUNET_assert (0 == gcry_cipher_gettag (out_cipher, | ||
1994 | box->gcm_tag, | ||
1995 | sizeof(box->gcm_tag))); | ||
1996 | gcry_cipher_close (out_cipher); | ||
1997 | if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, | ||
1998 | dgram, | ||
1999 | sizeof(dgram), | ||
2000 | receiver->address, | ||
2001 | receiver->address_len)) | ||
2002 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); | ||
2003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2070 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2004 | "Sending data\n"); | 2071 | "No more acks\n"); |
2005 | |||
2006 | GNUNET_MQ_impl_send_continue (mq); | ||
2007 | receiver->acks_available--; | ||
2008 | if (0 == receiver->acks_available) | ||
2009 | { | ||
2010 | /* We have no more ACKs => MTU change! */ | ||
2011 | setup_receiver_mq (receiver); | ||
2012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2013 | "No more acks, MTU changed\n"); | ||
2014 | } | ||
2015 | return; | ||
2016 | } | 2072 | } |
2073 | return; | ||
2017 | } | 2074 | } |
2018 | GNUNET_assert (0); | ||
2019 | } | 2075 | } |
2020 | 2076 | ||
2021 | 2077 | ||
@@ -2028,13 +2084,36 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
2028 | * @param impl_state our `struct ReceiverAddress` | 2084 | * @param impl_state our `struct ReceiverAddress` |
2029 | */ | 2085 | */ |
2030 | static void | 2086 | static void |
2031 | mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) | 2087 | mq_destroy_d (struct GNUNET_MQ_Handle *mq, void *impl_state) |
2032 | { | 2088 | { |
2033 | struct ReceiverAddress *receiver = impl_state; | 2089 | struct ReceiverAddress *receiver = impl_state; |
2090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2091 | "Default MQ destroyed\n"); | ||
2092 | if (mq == receiver->d_mq) | ||
2093 | { | ||
2094 | receiver->d_mq = NULL; | ||
2095 | receiver_destroy (receiver); | ||
2096 | } | ||
2097 | } | ||
2098 | |||
2034 | 2099 | ||
2035 | if (mq == receiver->mq) | 2100 | /** |
2101 | * Signature of functions implementing the destruction of a message | ||
2102 | * queue. Implementations must not free @a mq, but should take care | ||
2103 | * of @a impl_state. | ||
2104 | * | ||
2105 | * @param mq the message queue to destroy | ||
2106 | * @param impl_state our `struct ReceiverAddress` | ||
2107 | */ | ||
2108 | static void | ||
2109 | mq_destroy_kx (struct GNUNET_MQ_Handle *mq, void *impl_state) | ||
2110 | { | ||
2111 | struct ReceiverAddress *receiver = impl_state; | ||
2112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2113 | "KX MQ destroyed\n"); | ||
2114 | if (mq == receiver->kx_mq) | ||
2036 | { | 2115 | { |
2037 | receiver->mq = NULL; | 2116 | receiver->kx_mq = NULL; |
2038 | receiver_destroy (receiver); | 2117 | receiver_destroy (receiver); |
2039 | } | 2118 | } |
2040 | } | 2119 | } |
@@ -2088,12 +2167,17 @@ setup_receiver_mq (struct ReceiverAddress *receiver) | |||
2088 | { | 2167 | { |
2089 | size_t base_mtu; | 2168 | size_t base_mtu; |
2090 | 2169 | ||
2091 | if (NULL != receiver->qh) | 2170 | /*if (NULL != receiver->kx_qh) |
2092 | { | 2171 | { |
2093 | GNUNET_TRANSPORT_communicator_mq_del (receiver->qh); | 2172 | GNUNET_TRANSPORT_communicator_mq_del (receiver->kx_qh); |
2094 | receiver->qh = NULL; | 2173 | receiver->kx_qh = NULL; |
2095 | } | 2174 | } |
2096 | GNUNET_assert (NULL == receiver->mq); | 2175 | if (NULL != receiver->d_qh) |
2176 | { | ||
2177 | GNUNET_TRANSPORT_communicator_mq_del (receiver->d_qh); | ||
2178 | receiver->d_qh = NULL; | ||
2179 | }*/ | ||
2180 | // GNUNET_assert (NULL == receiver->mq); | ||
2097 | switch (receiver->address->sa_family) | 2181 | switch (receiver->address->sa_family) |
2098 | { | 2182 | { |
2099 | case AF_INET: | 2183 | case AF_INET: |
@@ -2112,35 +2196,54 @@ setup_receiver_mq (struct ReceiverAddress *receiver) | |||
2112 | GNUNET_assert (0); | 2196 | GNUNET_assert (0); |
2113 | break; | 2197 | break; |
2114 | } | 2198 | } |
2115 | if (0 == receiver->acks_available) | 2199 | /* MTU based on full KX messages */ |
2116 | { | 2200 | receiver->kx_mtu = base_mtu - sizeof(struct InitialKX) /* 48 */ |
2117 | /* MTU based on full KX messages */ | 2201 | - sizeof(struct UDPConfirmation); /* 104 */ |
2118 | receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */ | 2202 | /* MTU based on BOXed messages */ |
2119 | - sizeof(struct UDPConfirmation); /* 104 */ | 2203 | receiver->d_mtu = base_mtu - sizeof(struct UDPBox); |
2120 | } | 2204 | |
2121 | else | 2205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2122 | { | 2206 | "Setting up MQs and QHs\n"); |
2123 | /* MTU based on BOXed messages */ | ||
2124 | receiver->mtu = base_mtu - sizeof(struct UDPBox); | ||
2125 | } | ||
2126 | /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to | 2207 | /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to |
2127 | 1404 (IPv4 + Box) bytes, depending on circumstances... */ | 2208 | 1404 (IPv4 + Box) bytes, depending on circumstances... */ |
2128 | if (NULL == receiver->mq) | 2209 | if (NULL == receiver->kx_mq) |
2129 | receiver->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, | 2210 | receiver->kx_mq = GNUNET_MQ_queue_for_callbacks (&mq_send_kx, |
2130 | &mq_destroy, | 2211 | &mq_destroy_kx, |
2131 | &mq_cancel, | 2212 | &mq_cancel, |
2132 | receiver, | 2213 | receiver, |
2133 | NULL, | 2214 | NULL, |
2134 | &mq_error, | 2215 | &mq_error, |
2135 | receiver); | 2216 | receiver); |
2136 | receiver->qh = | 2217 | if (NULL == receiver->d_mq) |
2218 | receiver->d_mq = GNUNET_MQ_queue_for_callbacks (&mq_send_d, | ||
2219 | &mq_destroy_d, | ||
2220 | &mq_cancel, | ||
2221 | receiver, | ||
2222 | NULL, | ||
2223 | &mq_error, | ||
2224 | receiver); | ||
2225 | |||
2226 | receiver->kx_qh = | ||
2227 | GNUNET_TRANSPORT_communicator_mq_add (ch, | ||
2228 | &receiver->target, | ||
2229 | receiver->foreign_addr, | ||
2230 | receiver->kx_mtu, | ||
2231 | GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, | ||
2232 | 0, /* Priority */ | ||
2233 | receiver->nt, | ||
2234 | GNUNET_TRANSPORT_CS_OUTBOUND, | ||
2235 | receiver->kx_mq); | ||
2236 | receiver->d_qh = | ||
2137 | GNUNET_TRANSPORT_communicator_mq_add (ch, | 2237 | GNUNET_TRANSPORT_communicator_mq_add (ch, |
2138 | &receiver->target, | 2238 | &receiver->target, |
2139 | receiver->foreign_addr, | 2239 | receiver->foreign_addr, |
2140 | receiver->mtu, | 2240 | receiver->d_mtu, |
2241 | 0, /* Initialize with 0 acks */ | ||
2242 | 1, /* Priority */ | ||
2141 | receiver->nt, | 2243 | receiver->nt, |
2142 | GNUNET_TRANSPORT_CS_OUTBOUND, | 2244 | GNUNET_TRANSPORT_CS_OUTBOUND, |
2143 | receiver->mq); | 2245 | receiver->d_mq); |
2246 | |||
2144 | } | 2247 | } |
2145 | 2248 | ||
2146 | 2249 | ||
@@ -2190,6 +2293,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
2190 | &receiver->target, | 2293 | &receiver->target, |
2191 | receiver, | 2294 | receiver, |
2192 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2295 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2297 | "Added %s to receivers\n", | ||
2298 | GNUNET_i2s_full (&receiver->target)); | ||
2193 | receiver->timeout = | 2299 | receiver->timeout = |
2194 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 2300 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
2195 | receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap, | 2301 | receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap, |
@@ -2336,6 +2442,9 @@ enc_notify_cb (void *cls, | |||
2336 | const struct UDPAck *ack; | 2442 | const struct UDPAck *ack; |
2337 | 2443 | ||
2338 | (void) cls; | 2444 | (void) cls; |
2445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2446 | "Storing UDPAck received from backchannel from %s\n", | ||
2447 | GNUNET_i2s_full (sender)); | ||
2339 | if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) || | 2448 | if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) || |
2340 | (ntohs (msg->size) != sizeof(struct UDPAck))) | 2449 | (ntohs (msg->size) != sizeof(struct UDPAck))) |
2341 | { | 2450 | { |
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c index 31d2e4ed3..6ea0ea360 100644 --- a/src/transport/gnunet-communicator-unix.c +++ b/src/transport/gnunet-communicator-unix.c | |||
@@ -57,7 +57,11 @@ | |||
57 | /** | 57 | /** |
58 | * Our MTU. | 58 | * Our MTU. |
59 | */ | 59 | */ |
60 | #ifndef DARWIN | ||
60 | #define UNIX_MTU UINT16_MAX | 61 | #define UNIX_MTU UINT16_MAX |
62 | #else | ||
63 | #define UNIX_MTU 2048 | ||
64 | #endif | ||
61 | 65 | ||
62 | GNUNET_NETWORK_STRUCT_BEGIN | 66 | GNUNET_NETWORK_STRUCT_BEGIN |
63 | 67 | ||
@@ -669,7 +673,9 @@ setup_queue (const struct GNUNET_PeerIdentity *target, | |||
669 | queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, | 673 | queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, |
670 | &queue->target, | 674 | &queue->target, |
671 | foreign_addr, | 675 | foreign_addr, |
672 | UNIX_MTU, | 676 | UNIX_MTU - sizeof (struct UNIXMessage), |
677 | GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, | ||
678 | 0, | ||
673 | GNUNET_NT_LOOPBACK, | 679 | GNUNET_NT_LOOPBACK, |
674 | cs, | 680 | cs, |
675 | queue->mq); | 681 | queue->mq); |
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c index e99db7cfb..290167960 100644 --- a/src/transport/test_communicator_basic.c +++ b/src/transport/test_communicator_basic.c | |||
@@ -58,21 +58,23 @@ static char *cfg_peers_name[NUM_PEERS]; | |||
58 | 58 | ||
59 | static int ret; | 59 | static int ret; |
60 | 60 | ||
61 | static size_t long_message_size; | ||
62 | |||
61 | static struct GNUNET_TIME_Absolute start_short; | 63 | static struct GNUNET_TIME_Absolute start_short; |
62 | 64 | ||
63 | static struct GNUNET_TIME_Absolute start_long; | 65 | static struct GNUNET_TIME_Absolute start_long; |
64 | 66 | ||
65 | static struct GNUNET_TIME_Absolute timeout; | 67 | static struct GNUNET_TIME_Absolute timeout; |
66 | 68 | ||
67 | static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc; | 69 | static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *my_tc; |
68 | 70 | ||
69 | #define SHORT_MESSAGE_SIZE 128 | 71 | #define SHORT_MESSAGE_SIZE 128 |
70 | 72 | ||
71 | #define LONG_MESSAGE_SIZE 32000 | 73 | #define LONG_MESSAGE_SIZE 32000 /* FIXME */ |
72 | 74 | ||
73 | #define BURST_PACKETS 5000 | 75 | #define BURST_PACKETS 5000 |
74 | 76 | ||
75 | #define TOTAL_ITERATIONS 5 | 77 | #define TOTAL_ITERATIONS 1 |
76 | 78 | ||
77 | #define PEER_A 0 | 79 | #define PEER_A 0 |
78 | 80 | ||
@@ -88,6 +90,7 @@ static unsigned int iterations_left = TOTAL_ITERATIONS; | |||
88 | 90 | ||
89 | enum TestPhase | 91 | enum TestPhase |
90 | { | 92 | { |
93 | TP_INIT, | ||
91 | TP_BURST_SHORT, | 94 | TP_BURST_SHORT, |
92 | TP_BURST_LONG, | 95 | TP_BURST_LONG, |
93 | TP_SIZE_CHECK | 96 | TP_SIZE_CHECK |
@@ -182,7 +185,7 @@ handle_backchannel_cb (void *cls, | |||
182 | struct GNUNET_PeerIdentity *pid) | 185 | struct GNUNET_PeerIdentity *pid) |
183 | { | 186 | { |
184 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 187 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handling BC message...\n"); | 188 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Handling BC message...\n"); |
186 | if (0 == memcmp (&peer_id[PEER_A], pid, sizeof (*pid))) | 189 | if (0 == memcmp (&peer_id[PEER_A], pid, sizeof (*pid))) |
187 | return tc_hs[PEER_A]; | 190 | return tc_hs[PEER_A]; |
188 | else | 191 | else |
@@ -197,6 +200,8 @@ make_payload (size_t payload_size) | |||
197 | struct GNUNET_TIME_AbsoluteNBO ts_n; | 200 | struct GNUNET_TIME_AbsoluteNBO ts_n; |
198 | char *payload = GNUNET_malloc (payload_size); | 201 | char *payload = GNUNET_malloc (payload_size); |
199 | 202 | ||
203 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
204 | "Making payload of size %lu\n", payload_size); | ||
200 | GNUNET_assert (payload_size >= 8); // So that out timestamp fits | 205 | GNUNET_assert (payload_size >= 8); // So that out timestamp fits |
201 | ts = GNUNET_TIME_absolute_get (); | 206 | ts = GNUNET_TIME_absolute_get (); |
202 | ts_n = GNUNET_TIME_absolute_hton (ts); | 207 | ts_n = GNUNET_TIME_absolute_hton (ts); |
@@ -218,7 +223,7 @@ latency_timeout (void *cls) | |||
218 | return; | 223 | return; |
219 | } | 224 | } |
220 | 225 | ||
221 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 226 | LOG (GNUNET_ERROR_TYPE_ERROR, |
222 | "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", | 227 | "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", |
223 | phase, num_sent, num_received); | 228 | phase, num_sent, num_received); |
224 | ret = 2; | 229 | ret = 2; |
@@ -230,15 +235,18 @@ static void | |||
230 | size_test (void *cls) | 235 | size_test (void *cls) |
231 | { | 236 | { |
232 | char *payload; | 237 | char *payload; |
238 | size_t max_size = 64000; | ||
233 | 239 | ||
234 | GNUNET_assert (TP_SIZE_CHECK == phase); | 240 | GNUNET_assert (TP_SIZE_CHECK == phase); |
235 | if (ack >= 64000) | 241 | if (LONG_MESSAGE_SIZE != long_message_size) |
242 | max_size = long_message_size; | ||
243 | if (ack + 10 > max_size) | ||
236 | return; /* Leave some room for our protocol, so not 2^16 exactly */ | 244 | return; /* Leave some room for our protocol, so not 2^16 exactly */ |
245 | ack += 10; | ||
237 | payload = make_payload (ack); | 246 | payload = make_payload (ack); |
238 | ack += 5; | ||
239 | num_sent++; | 247 | num_sent++; |
240 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | 248 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, |
241 | (ack < 64000) | 249 | (ack < max_size) |
242 | ? &size_test | 250 | ? &size_test |
243 | : NULL, | 251 | : NULL, |
244 | NULL, | 252 | NULL, |
@@ -254,7 +262,7 @@ long_test (void *cls) | |||
254 | { | 262 | { |
255 | char *payload; | 263 | char *payload; |
256 | 264 | ||
257 | payload = make_payload (LONG_MESSAGE_SIZE); | 265 | payload = make_payload (long_message_size); |
258 | num_sent++; | 266 | num_sent++; |
259 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | 267 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, |
260 | (BURST_PACKETS == | 268 | (BURST_PACKETS == |
@@ -263,7 +271,7 @@ long_test (void *cls) | |||
263 | : &long_test, | 271 | : &long_test, |
264 | NULL, | 272 | NULL, |
265 | payload, | 273 | payload, |
266 | LONG_MESSAGE_SIZE); | 274 | long_message_size); |
267 | GNUNET_free (payload); | 275 | GNUNET_free (payload); |
268 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); | 276 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); |
269 | } | 277 | } |
@@ -289,6 +297,34 @@ short_test (void *cls) | |||
289 | } | 297 | } |
290 | 298 | ||
291 | 299 | ||
300 | static int test_prepared = GNUNET_NO; | ||
301 | |||
302 | /** | ||
303 | * This helps establishing the backchannel | ||
304 | */ | ||
305 | static void | ||
306 | prepare_test (void *cls) | ||
307 | { | ||
308 | char *payload; | ||
309 | |||
310 | if (GNUNET_YES == test_prepared) | ||
311 | { | ||
312 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
313 | &short_test, | ||
314 | NULL); | ||
315 | return; | ||
316 | } | ||
317 | test_prepared = GNUNET_YES; | ||
318 | payload = make_payload (SHORT_MESSAGE_SIZE); | ||
319 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | ||
320 | &prepare_test, | ||
321 | NULL, | ||
322 | payload, | ||
323 | SHORT_MESSAGE_SIZE); | ||
324 | GNUNET_free (payload); | ||
325 | } | ||
326 | |||
327 | |||
292 | /** | 328 | /** |
293 | * @brief Handle opening of queue | 329 | * @brief Handle opening of queue |
294 | * | 330 | * |
@@ -304,21 +340,28 @@ static void | |||
304 | add_queue_cb (void *cls, | 340 | add_queue_cb (void *cls, |
305 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | 341 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, |
306 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * | 342 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * |
307 | tc_queue) | 343 | tc_queue, |
344 | size_t mtu) | ||
308 | { | 345 | { |
346 | if (TP_INIT != phase) | ||
347 | return; | ||
309 | if (0 != strcmp ((char*) cls, cfg_peers_name[0])) | 348 | if (0 != strcmp ((char*) cls, cfg_peers_name[0])) |
310 | return; // TODO? | 349 | return; // TODO? |
311 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 350 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
312 | "Queue established, starting test...\n"); | 351 | "Queue established, starting test...\n"); |
313 | start_short = GNUNET_TIME_absolute_get (); | 352 | start_short = GNUNET_TIME_absolute_get (); |
314 | my_tc = tc_queue; | 353 | my_tc = tc_h; |
354 | if (0 != mtu) | ||
355 | long_message_size = mtu - 4; /* Dummy message header overhead */ | ||
356 | else | ||
357 | long_message_size = LONG_MESSAGE_SIZE; | ||
315 | phase = TP_BURST_SHORT; | 358 | phase = TP_BURST_SHORT; |
316 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); | 359 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
317 | GNUNET_assert (NULL == to_task); | 360 | GNUNET_assert (NULL == to_task); |
318 | to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 361 | to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
319 | &latency_timeout, | 362 | &latency_timeout, |
320 | NULL); | 363 | NULL); |
321 | short_test (NULL); | 364 | prepare_test (NULL); |
322 | } | 365 | } |
323 | 366 | ||
324 | 367 | ||
@@ -359,7 +402,7 @@ incoming_message_cb (void *cls, | |||
359 | { | 402 | { |
360 | if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1])) | 403 | if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1])) |
361 | { | 404 | { |
362 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 405 | LOG (GNUNET_ERROR_TYPE_WARNING, |
363 | "unexpected receiver...\n"); | 406 | "unexpected receiver...\n"); |
364 | return; | 407 | return; |
365 | } | 408 | } |
@@ -367,6 +410,9 @@ incoming_message_cb (void *cls, | |||
367 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); | 410 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); |
368 | switch (phase) | 411 | switch (phase) |
369 | { | 412 | { |
413 | case TP_INIT: | ||
414 | GNUNET_break (0); | ||
415 | break; | ||
370 | case TP_BURST_SHORT: | 416 | case TP_BURST_SHORT: |
371 | { | 417 | { |
372 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); | 418 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); |
@@ -375,13 +421,13 @@ incoming_message_cb (void *cls, | |||
375 | update_avg_latency (payload); | 421 | update_avg_latency (payload); |
376 | if (num_received == BURST_PACKETS) | 422 | if (num_received == BURST_PACKETS) |
377 | { | 423 | { |
378 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 424 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
379 | "Short size packet test done.\n"); | 425 | "Short size packet test done.\n"); |
380 | char *goodput = GNUNET_STRINGS_byte_size_fancy ((SHORT_MESSAGE_SIZE | 426 | char *goodput = GNUNET_STRINGS_byte_size_fancy ((SHORT_MESSAGE_SIZE |
381 | * num_received * 1000 | 427 | * num_received * 1000 |
382 | * 1000) | 428 | * 1000) |
383 | / duration.rel_value_us); | 429 | / duration.rel_value_us); |
384 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 430 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
385 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", | 431 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", |
386 | (unsigned long) num_received, | 432 | (unsigned long) num_received, |
387 | (unsigned long) num_sent, | 433 | (unsigned long) num_sent, |
@@ -400,9 +446,9 @@ incoming_message_cb (void *cls, | |||
400 | } | 446 | } |
401 | case TP_BURST_LONG: | 447 | case TP_BURST_LONG: |
402 | { | 448 | { |
403 | if (LONG_MESSAGE_SIZE != payload_len) | 449 | if (long_message_size != payload_len) |
404 | { | 450 | { |
405 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 451 | LOG (GNUNET_ERROR_TYPE_WARNING, |
406 | "Ignoring packet with wrong length\n"); | 452 | "Ignoring packet with wrong length\n"); |
407 | return; // Ignore | 453 | return; // Ignore |
408 | } | 454 | } |
@@ -411,14 +457,14 @@ incoming_message_cb (void *cls, | |||
411 | update_avg_latency (payload); | 457 | update_avg_latency (payload); |
412 | if (num_received == BURST_PACKETS) | 458 | if (num_received == BURST_PACKETS) |
413 | { | 459 | { |
414 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 460 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
415 | "Long size packet test done.\n"); | 461 | "Long size packet test done.\n"); |
416 | char *goodput = GNUNET_STRINGS_byte_size_fancy ((LONG_MESSAGE_SIZE | 462 | char *goodput = GNUNET_STRINGS_byte_size_fancy ((long_message_size |
417 | * num_received * 1000 | 463 | * num_received * 1000 |
418 | * 1000) | 464 | * 1000) |
419 | / duration.rel_value_us); | 465 | / duration.rel_value_us); |
420 | 466 | ||
421 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 467 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
422 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", | 468 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", |
423 | (unsigned long) num_received, | 469 | (unsigned long) num_received, |
424 | (unsigned long) num_sent, | 470 | (unsigned long) num_sent, |
@@ -426,7 +472,7 @@ incoming_message_cb (void *cls, | |||
426 | goodput, | 472 | goodput, |
427 | (unsigned long long) avg_latency); | 473 | (unsigned long long) avg_latency); |
428 | GNUNET_free (goodput); | 474 | GNUNET_free (goodput); |
429 | ack = 10; | 475 | ack = 0; |
430 | phase = TP_SIZE_CHECK; | 476 | phase = TP_SIZE_CHECK; |
431 | num_received = 0; | 477 | num_received = 0; |
432 | num_sent = 0; | 478 | num_sent = 0; |
@@ -437,13 +483,18 @@ incoming_message_cb (void *cls, | |||
437 | } | 483 | } |
438 | case TP_SIZE_CHECK: | 484 | case TP_SIZE_CHECK: |
439 | { | 485 | { |
486 | size_t max_size = 64000; | ||
487 | |||
488 | GNUNET_assert (TP_SIZE_CHECK == phase); | ||
489 | if (LONG_MESSAGE_SIZE != long_message_size) | ||
490 | max_size = long_message_size; | ||
440 | num_received++; | 491 | num_received++; |
441 | update_avg_latency (payload); | 492 | update_avg_latency (payload); |
442 | if (num_received >= (64000 - 10) / 5) | 493 | if (num_received >= (max_size) / 10) |
443 | { | 494 | { |
444 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 495 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
445 | "Size packet test done.\n"); | 496 | "Size packet test done.\n"); |
446 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 497 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
447 | "%lu/%lu packets -- avg latency: %llu us\n", | 498 | "%lu/%lu packets -- avg latency: %llu us\n", |
448 | (unsigned long) num_received, | 499 | (unsigned long) num_received, |
449 | (unsigned long) num_sent, | 500 | (unsigned long) num_sent, |
@@ -459,7 +510,7 @@ incoming_message_cb (void *cls, | |||
459 | short_test (NULL); | 510 | short_test (NULL); |
460 | break; | 511 | break; |
461 | } | 512 | } |
462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 513 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
463 | "Finished\n"); | 514 | "Finished\n"); |
464 | GNUNET_SCHEDULER_shutdown (); | 515 | GNUNET_SCHEDULER_shutdown (); |
465 | } | 516 | } |
@@ -501,6 +552,7 @@ run (void *cls) | |||
501 | "transport", | 552 | "transport", |
502 | communicator_binary, | 553 | communicator_binary, |
503 | cfg_peers_name[i], | 554 | cfg_peers_name[i], |
555 | &peer_id[i], | ||
504 | &communicator_available_cb, | 556 | &communicator_available_cb, |
505 | &add_address_cb, | 557 | &add_address_cb, |
506 | &queue_create_reply_cb, | 558 | &queue_create_reply_cb, |
@@ -524,6 +576,7 @@ main (int argc, | |||
524 | char *test_name; | 576 | char *test_name; |
525 | char *cfg_peer; | 577 | char *cfg_peer; |
526 | 578 | ||
579 | phase = TP_INIT; | ||
527 | ret = 1; | 580 | ret = 1; |
528 | test_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 581 | test_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
529 | communicator_name = strchr (test_name, '-'); | 582 | communicator_name = strchr (test_name, '-'); |
@@ -586,12 +639,12 @@ main (int argc, | |||
586 | GNUNET_CRYPTO_eddsa_key_get_public (private_key, | 639 | GNUNET_CRYPTO_eddsa_key_get_public (private_key, |
587 | &peer_id[i].public_key); | 640 | &peer_id[i].public_key); |
588 | GNUNET_free (private_key); | 641 | GNUNET_free (private_key); |
589 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 642 | LOG (GNUNET_ERROR_TYPE_INFO, |
590 | "Identity of peer %u is %s\n", | 643 | "Identity of peer %u is %s\n", |
591 | i, | 644 | i, |
592 | GNUNET_i2s_full (&peer_id[i])); | 645 | GNUNET_i2s_full (&peer_id[i])); |
593 | } | 646 | } |
594 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Starting test...\n"); | 647 | LOG (GNUNET_ERROR_TYPE_MESSAGE, "Starting test...\n"); |
595 | GNUNET_SCHEDULER_run (&run, | 648 | GNUNET_SCHEDULER_run (&run, |
596 | NULL); | 649 | NULL); |
597 | return ret; | 650 | return ret; |
diff --git a/src/transport/test_communicator_tcp_basic_peer1.conf b/src/transport/test_communicator_tcp_basic_peer1.conf index fc08af1ee..d0293ff51 100644 --- a/src/transport/test_communicator_tcp_basic_peer1.conf +++ b/src/transport/test_communicator_tcp_basic_peer1.conf | |||
@@ -18,14 +18,17 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-transport_test_1.sock | |||
18 | 18 | ||
19 | [nat] | 19 | [nat] |
20 | UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/nat.sock | 20 | UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/nat.sock |
21 | ENABLE_IPSCAN = YES | ||
22 | 21 | ||
23 | [communicator-unix] | 22 | [communicator-unix] |
24 | UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock | 23 | UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock |
25 | 24 | ||
26 | [communicator-tcp] | 25 | [communicator-tcp] |
27 | BINDTO = 60002 | 26 | BINDTO = 60002 |
28 | DISABLE_V6 = YES | 27 | DISABLE_V6 = NO |
29 | 28 | ||
30 | [communicator-udp] | 29 | [communicator-udp] |
31 | BINDTO = 60002 | 30 | BINDTO = 60002 |
31 | |||
32 | [resolver] | ||
33 | PORT = 62089 | ||
34 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock | ||
diff --git a/src/transport/test_communicator_tcp_basic_peer2.conf b/src/transport/test_communicator_tcp_basic_peer2.conf index 4197df00d..5b9050547 100644 --- a/src/transport/test_communicator_tcp_basic_peer2.conf +++ b/src/transport/test_communicator_tcp_basic_peer2.conf | |||
@@ -25,7 +25,11 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_2.sock | |||
25 | 25 | ||
26 | [communicator-tcp] | 26 | [communicator-tcp] |
27 | BINDTO = 60003 | 27 | BINDTO = 60003 |
28 | DISABLE_V6 = YES | 28 | DISABLE_V6 = NO |
29 | 29 | ||
30 | [communicator-udp] | 30 | [communicator-udp] |
31 | BINDTO = 60003 | 31 | BINDTO = 60003 |
32 | |||
33 | [resolver] | ||
34 | PORT = 62090 | ||
35 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock | ||
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index fe2f28f54..0dc1bb331 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #include "gnunet_hello_lib.h" | 33 | #include "gnunet_hello_lib.h" |
34 | #include "gnunet_signatures.h" | 34 | #include "gnunet_signatures.h" |
35 | #include "transport.h" | 35 | #include "transport.h" |
36 | 36 | #include <inttypes.h> | |
37 | 37 | ||
38 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__) | 38 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__) |
39 | 39 | ||
@@ -84,6 +84,8 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | |||
84 | */ | 84 | */ |
85 | char *cfg_filename; | 85 | char *cfg_filename; |
86 | 86 | ||
87 | struct GNUNET_PeerIdentity peer_id; | ||
88 | |||
87 | /** | 89 | /** |
88 | * @brief Handle to the transport service | 90 | * @brief Handle to the transport service |
89 | */ | 91 | */ |
@@ -107,6 +109,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | |||
107 | struct GNUNET_OS_Process *nat_proc; | 109 | struct GNUNET_OS_Process *nat_proc; |
108 | 110 | ||
109 | /** | 111 | /** |
112 | * resolver service process | ||
113 | */ | ||
114 | struct GNUNET_OS_Process *resolver_proc; | ||
115 | |||
116 | /** | ||
110 | * @brief Task that will be run on shutdown to stop and clean communicator | 117 | * @brief Task that will be run on shutdown to stop and clean communicator |
111 | */ | 118 | */ |
112 | struct GNUNET_SCHEDULER_Task *c_shutdown_task; | 119 | struct GNUNET_SCHEDULER_Task *c_shutdown_task; |
@@ -225,11 +232,21 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue | |||
225 | uint32_t nt; | 232 | uint32_t nt; |
226 | 233 | ||
227 | /** | 234 | /** |
228 | * Maximum transmission unit, in NBO. UINT32_MAX for unlimited. | 235 | * Maximum transmission unit. UINT32_MAX for unlimited. |
229 | */ | 236 | */ |
230 | uint32_t mtu; | 237 | uint32_t mtu; |
231 | 238 | ||
232 | /** | 239 | /** |
240 | * Queue length. UINT64_MAX for unlimited. | ||
241 | */ | ||
242 | uint64_t q_len; | ||
243 | |||
244 | /** | ||
245 | * Queue prio | ||
246 | */ | ||
247 | uint32_t priority; | ||
248 | |||
249 | /** | ||
233 | * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO. | 250 | * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO. |
234 | */ | 251 | */ |
235 | uint32_t cs; | 252 | uint32_t cs; |
@@ -368,7 +385,8 @@ handle_communicator_backchannel (void *cls, | |||
368 | struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *cbi; | 385 | struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *cbi; |
369 | struct GNUNET_MQ_Envelope *env; | 386 | struct GNUNET_MQ_Envelope *env; |
370 | 387 | ||
371 | 388 | LOG (GNUNET_ERROR_TYPE_DEBUG, | |
389 | "Received backchannel message\n"); | ||
372 | if (tc_h->bc_enabled != GNUNET_YES) | 390 | if (tc_h->bc_enabled != GNUNET_YES) |
373 | { | 391 | { |
374 | GNUNET_SERVICE_client_continue (client->client); | 392 | GNUNET_SERVICE_client_continue (client->client); |
@@ -376,17 +394,17 @@ handle_communicator_backchannel (void *cls, | |||
376 | } | 394 | } |
377 | /* Find client providing this communicator */ | 395 | /* Find client providing this communicator */ |
378 | /* Finally, deliver backchannel message to communicator */ | 396 | /* Finally, deliver backchannel message to communicator */ |
379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 397 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
380 | "Delivering backchannel message of type %u to %s\n", | 398 | "Delivering backchannel message of type %u to %s\n", |
381 | ntohs (msg->type), | 399 | ntohs (msg->type), |
382 | target_communicator); | 400 | target_communicator); |
383 | other_tc_h = tc_h->bc_cb (tc_h, msg, (struct | 401 | other_tc_h = tc_h->bc_cb (tc_h, msg, (struct |
384 | GNUNET_PeerIdentity*) &bc_msg->pid); | 402 | GNUNET_PeerIdentity*) &bc_msg->pid); |
385 | env = GNUNET_MQ_msg_extra ( | 403 | env = GNUNET_MQ_msg_extra ( |
386 | cbi, | 404 | cbi, |
387 | isize, | 405 | isize, |
388 | GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING); | 406 | GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING); |
389 | cbi->pid = bc_msg->pid; | 407 | cbi->pid = tc_h->peer_id; |
390 | memcpy (&cbi[1], msg, isize); | 408 | memcpy (&cbi[1], msg, isize); |
391 | 409 | ||
392 | 410 | ||
@@ -493,9 +511,6 @@ handle_incoming_msg (void *cls, | |||
493 | msg = (struct GNUNET_MessageHeader *) &inc_msg[1]; | 511 | msg = (struct GNUNET_MessageHeader *) &inc_msg[1]; |
494 | size_t payload_len = ntohs (msg->size) - sizeof (struct | 512 | size_t payload_len = ntohs (msg->size) - sizeof (struct |
495 | GNUNET_MessageHeader); | 513 | GNUNET_MessageHeader); |
496 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
497 | "Incoming message from communicator!\n"); | ||
498 | |||
499 | if (NULL != tc_h->incoming_msg_cb) | 514 | if (NULL != tc_h->incoming_msg_cb) |
500 | { | 515 | { |
501 | tc_h->incoming_msg_cb (tc_h->cb_cls, | 516 | tc_h->incoming_msg_cb (tc_h->cb_cls, |
@@ -515,6 +530,7 @@ handle_incoming_msg (void *cls, | |||
515 | struct GNUNET_TRANSPORT_IncomingMessageAck *ack; | 530 | struct GNUNET_TRANSPORT_IncomingMessageAck *ack; |
516 | 531 | ||
517 | env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); | 532 | env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); |
533 | GNUNET_assert (NULL != env); | ||
518 | ack->reserved = htonl (0); | 534 | ack->reserved = htonl (0); |
519 | ack->fc_id = inc_msg->fc_id; | 535 | ack->fc_id = inc_msg->fc_id; |
520 | ack->sender = inc_msg->sender; | 536 | ack->sender = inc_msg->sender; |
@@ -605,15 +621,14 @@ handle_add_queue_message (void *cls, | |||
605 | client->tc; | 621 | client->tc; |
606 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; | 622 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; |
607 | 623 | ||
608 | tc_queue = tc_h->queue_head; | 624 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
609 | if (NULL != tc_queue) | 625 | "Got queue with ID %u\n", msg->qid); |
626 | for (tc_queue = tc_h->queue_head; NULL != tc_queue; tc_queue = tc_queue->next) | ||
610 | { | 627 | { |
611 | while (tc_queue->qid != msg->qid) | 628 | if (tc_queue->qid == msg->qid) |
612 | { | 629 | break; |
613 | tc_queue = tc_queue->next; | ||
614 | } | ||
615 | } | 630 | } |
616 | else | 631 | if (NULL == tc_queue) |
617 | { | 632 | { |
618 | tc_queue = | 633 | tc_queue = |
619 | GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); | 634 | GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); |
@@ -625,12 +640,54 @@ handle_add_queue_message (void *cls, | |||
625 | GNUNET_assert (tc_queue->qid == msg->qid); | 640 | GNUNET_assert (tc_queue->qid == msg->qid); |
626 | GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver)); | 641 | GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver)); |
627 | tc_queue->nt = msg->nt; | 642 | tc_queue->nt = msg->nt; |
628 | tc_queue->mtu = msg->mtu; | 643 | tc_queue->mtu = ntohl (msg->mtu); |
629 | tc_queue->cs = msg->cs; | 644 | tc_queue->cs = msg->cs; |
645 | tc_queue->priority = ntohl (msg->priority); | ||
646 | tc_queue->q_len = GNUNET_ntohll (msg->q_len); | ||
630 | if (NULL != tc_h->add_queue_cb) | 647 | if (NULL != tc_h->add_queue_cb) |
631 | { | 648 | { |
632 | tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue); | 649 | tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue, tc_queue->mtu); |
650 | } | ||
651 | GNUNET_SERVICE_client_continue (client->client); | ||
652 | } | ||
653 | |||
654 | |||
655 | /** | ||
656 | * @brief Handle new queue | ||
657 | * | ||
658 | * Store context and call client callback. | ||
659 | * | ||
660 | * @param cls Closure - communicator handle | ||
661 | * @param msg Message struct | ||
662 | */ | ||
663 | static void | ||
664 | handle_update_queue_message (void *cls, | ||
665 | const struct | ||
666 | GNUNET_TRANSPORT_UpdateQueueMessage *msg) | ||
667 | { | ||
668 | struct MyClient *client = cls; | ||
669 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = | ||
670 | client->tc; | ||
671 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; | ||
672 | |||
673 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
674 | "Received queue update message for %u with q_len %"PRIu64"\n", | ||
675 | msg->qid, GNUNET_ntohll(msg->q_len)); | ||
676 | tc_queue = tc_h->queue_head; | ||
677 | if (NULL != tc_queue) | ||
678 | { | ||
679 | while (tc_queue->qid != msg->qid) | ||
680 | { | ||
681 | tc_queue = tc_queue->next; | ||
682 | } | ||
633 | } | 683 | } |
684 | GNUNET_assert (tc_queue->qid == msg->qid); | ||
685 | GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver)); | ||
686 | tc_queue->nt = msg->nt; | ||
687 | tc_queue->mtu = ntohl (msg->mtu); | ||
688 | tc_queue->cs = msg->cs; | ||
689 | tc_queue->priority = ntohl (msg->priority); | ||
690 | tc_queue->q_len += GNUNET_ntohll (msg->q_len); | ||
634 | GNUNET_SERVICE_client_continue (client->client); | 691 | GNUNET_SERVICE_client_continue (client->client); |
635 | } | 692 | } |
636 | 693 | ||
@@ -719,6 +776,8 @@ disconnect_cb (void *cls, | |||
719 | GNUNET_CONTAINER_DLL_remove (tc_h->client_head, | 776 | GNUNET_CONTAINER_DLL_remove (tc_h->client_head, |
720 | tc_h->client_tail, | 777 | tc_h->client_tail, |
721 | cl); | 778 | cl); |
779 | if (cl->c_mq == tc_h->c_mq) | ||
780 | tc_h->c_mq = NULL; | ||
722 | GNUNET_free (cl); | 781 | GNUNET_free (cl); |
723 | break; | 782 | break; |
724 | } | 783 | } |
@@ -786,6 +845,10 @@ transport_communicator_start ( | |||
786 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, | 845 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, |
787 | struct GNUNET_TRANSPORT_AddQueueMessage, | 846 | struct GNUNET_TRANSPORT_AddQueueMessage, |
788 | tc_h), | 847 | tc_h), |
848 | GNUNET_MQ_hd_fixed_size (update_queue_message, | ||
849 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE, | ||
850 | struct GNUNET_TRANSPORT_UpdateQueueMessage, | ||
851 | tc_h), | ||
789 | // GNUNET_MQ_hd_fixed_size (del_queue_message, | 852 | // GNUNET_MQ_hd_fixed_size (del_queue_message, |
790 | // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, | 853 | // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, |
791 | // struct GNUNET_TRANSPORT_DelQueueMessage, | 854 | // struct GNUNET_TRANSPORT_DelQueueMessage, |
@@ -819,11 +882,11 @@ shutdown_process (struct GNUNET_OS_Process *proc) | |||
819 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 882 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
820 | { | 883 | { |
821 | LOG (GNUNET_ERROR_TYPE_WARNING, | 884 | LOG (GNUNET_ERROR_TYPE_WARNING, |
822 | "Error shutting down communicator with SIGERM, trying SIGKILL\n"); | 885 | "Error shutting down process with SIGERM, trying SIGKILL\n"); |
823 | if (0 != GNUNET_OS_process_kill (proc, SIGKILL)) | 886 | if (0 != GNUNET_OS_process_kill (proc, SIGKILL)) |
824 | { | 887 | { |
825 | LOG (GNUNET_ERROR_TYPE_ERROR, | 888 | LOG (GNUNET_ERROR_TYPE_ERROR, |
826 | "Error shutting down communicator with SIGERM and SIGKILL\n"); | 889 | "Error shutting down process with SIGERM and SIGKILL\n"); |
827 | } | 890 | } |
828 | } | 891 | } |
829 | GNUNET_OS_process_destroy (proc); | 892 | GNUNET_OS_process_destroy (proc); |
@@ -884,6 +947,45 @@ shutdown_nat (void *cls) | |||
884 | shutdown_process (proc); | 947 | shutdown_process (proc); |
885 | } | 948 | } |
886 | 949 | ||
950 | /** | ||
951 | * @brief Task run at shutdown to kill the resolver process | ||
952 | * | ||
953 | * @param cls Closure - Process of communicator | ||
954 | */ | ||
955 | static void | ||
956 | shutdown_resolver (void *cls) | ||
957 | { | ||
958 | struct GNUNET_OS_Process *proc = cls; | ||
959 | shutdown_process (proc); | ||
960 | } | ||
961 | |||
962 | static void | ||
963 | resolver_start (struct | ||
964 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) | ||
965 | { | ||
966 | char *binary; | ||
967 | |||
968 | LOG (GNUNET_ERROR_TYPE_DEBUG, "resolver_start\n"); | ||
969 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); | ||
970 | tc_h->resolver_proc = GNUNET_OS_start_process (GNUNET_YES, | ||
971 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
972 | NULL, | ||
973 | NULL, | ||
974 | NULL, | ||
975 | binary, | ||
976 | "gnunet-service-resolver", | ||
977 | "-c", | ||
978 | tc_h->cfg_filename, | ||
979 | NULL); | ||
980 | if (NULL == tc_h->resolver_proc) | ||
981 | { | ||
982 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start resolver service!"); | ||
983 | return; | ||
984 | } | ||
985 | LOG (GNUNET_ERROR_TYPE_INFO, "started resolver service\n"); | ||
986 | GNUNET_free (binary); | ||
987 | |||
988 | } | ||
887 | 989 | ||
888 | /** | 990 | /** |
889 | * @brief Start NAT | 991 | * @brief Start NAT |
@@ -934,6 +1036,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | |||
934 | const char *service_name, | 1036 | const char *service_name, |
935 | const char *binary_name, | 1037 | const char *binary_name, |
936 | const char *cfg_filename, | 1038 | const char *cfg_filename, |
1039 | const struct GNUNET_PeerIdentity *peer_id, | ||
937 | GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback | 1040 | GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback |
938 | communicator_available_cb, | 1041 | communicator_available_cb, |
939 | GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, | 1042 | GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, |
@@ -971,12 +1074,15 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | |||
971 | tc_h->add_queue_cb = add_queue_cb; | 1074 | tc_h->add_queue_cb = add_queue_cb; |
972 | tc_h->incoming_msg_cb = incoming_message_cb; | 1075 | tc_h->incoming_msg_cb = incoming_message_cb; |
973 | tc_h->bc_cb = bc_cb; | 1076 | tc_h->bc_cb = bc_cb; |
1077 | tc_h->peer_id = *peer_id; | ||
974 | tc_h->cb_cls = cb_cls; | 1078 | tc_h->cb_cls = cb_cls; |
975 | 1079 | ||
976 | /* Start communicator part of service */ | 1080 | /* Start communicator part of service */ |
977 | transport_communicator_start (tc_h); | 1081 | transport_communicator_start (tc_h); |
978 | /* Start NAT */ | 1082 | /* Start NAT */ |
979 | nat_start (tc_h); | 1083 | nat_start (tc_h); |
1084 | /* Start resolver service */ | ||
1085 | resolver_start (tc_h); | ||
980 | /* Schedule start communicator */ | 1086 | /* Schedule start communicator */ |
981 | communicator_start (tc_h, | 1087 | communicator_start (tc_h, |
982 | binary_name); | 1088 | binary_name); |
@@ -991,6 +1097,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop ( | |||
991 | shutdown_communicator (tc_h->c_proc); | 1097 | shutdown_communicator (tc_h->c_proc); |
992 | shutdown_service (tc_h->sh); | 1098 | shutdown_service (tc_h->sh); |
993 | shutdown_nat (tc_h->nat_proc); | 1099 | shutdown_nat (tc_h->nat_proc); |
1100 | shutdown_resolver (tc_h->resolver_proc); | ||
994 | GNUNET_CONFIGURATION_destroy (tc_h->cfg); | 1101 | GNUNET_CONFIGURATION_destroy (tc_h->cfg); |
995 | GNUNET_free (tc_h); | 1102 | GNUNET_free (tc_h); |
996 | } | 1103 | } |
@@ -1058,7 +1165,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue ( | |||
1058 | */ | 1165 | */ |
1059 | void | 1166 | void |
1060 | GNUNET_TRANSPORT_TESTING_transport_communicator_send | 1167 | GNUNET_TRANSPORT_TESTING_transport_communicator_send |
1061 | (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, | 1168 | (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, |
1062 | GNUNET_SCHEDULER_TaskCallback cont, | 1169 | GNUNET_SCHEDULER_TaskCallback cont, |
1063 | void *cont_cls, | 1170 | void *cont_cls, |
1064 | const void *payload, | 1171 | const void *payload, |
@@ -1068,11 +1175,46 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send | |||
1068 | struct GNUNET_TRANSPORT_SendMessageTo *msg; | 1175 | struct GNUNET_TRANSPORT_SendMessageTo *msg; |
1069 | struct GNUNET_MQ_Envelope *env; | 1176 | struct GNUNET_MQ_Envelope *env; |
1070 | size_t inbox_size; | 1177 | size_t inbox_size; |
1178 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; | ||
1179 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_tmp; | ||
1071 | 1180 | ||
1181 | tc_queue = NULL; | ||
1182 | for (tc_queue_tmp = tc_h->queue_head; | ||
1183 | NULL != tc_queue_tmp; | ||
1184 | tc_queue_tmp = tc_queue_tmp->next) | ||
1185 | { | ||
1186 | if (tc_queue_tmp->q_len <= 0) | ||
1187 | continue; | ||
1188 | if (NULL == tc_queue) | ||
1189 | { | ||
1190 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1191 | "Selecting queue with prio %u, len %" PRIu64 " and MTU %u\n", | ||
1192 | tc_queue_tmp->priority, | ||
1193 | tc_queue_tmp->q_len, | ||
1194 | tc_queue_tmp->mtu); | ||
1195 | tc_queue = tc_queue_tmp; | ||
1196 | continue; | ||
1197 | } | ||
1198 | if (tc_queue->priority < tc_queue_tmp->priority) | ||
1199 | { | ||
1200 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1201 | "Selecting queue with prio %u, len %" PRIu64 " and MTU %u\n", | ||
1202 | tc_queue_tmp->priority, | ||
1203 | tc_queue_tmp->q_len, | ||
1204 | tc_queue_tmp->mtu); | ||
1205 | tc_queue = tc_queue_tmp; | ||
1206 | } | ||
1207 | } | ||
1208 | GNUNET_assert (NULL != tc_queue); | ||
1209 | if (tc_queue->q_len != GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED) | ||
1210 | tc_queue->q_len--; | ||
1211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1212 | "Sending message\n"); | ||
1072 | inbox_size = sizeof (struct GNUNET_MessageHeader) + payload_size; | 1213 | inbox_size = sizeof (struct GNUNET_MessageHeader) + payload_size; |
1073 | env = GNUNET_MQ_msg_extra (msg, | 1214 | env = GNUNET_MQ_msg_extra (msg, |
1074 | inbox_size, | 1215 | inbox_size, |
1075 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); | 1216 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); |
1217 | GNUNET_assert (NULL != env); | ||
1076 | msg->qid = htonl (tc_queue->qid); | 1218 | msg->qid = htonl (tc_queue->qid); |
1077 | msg->mid = tc_queue->mid++; | 1219 | msg->mid = tc_queue->mid++; |
1078 | msg->receiver = tc_queue->peer_id; | 1220 | msg->receiver = tc_queue->peer_id; |
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h index 96a08a193..b77125e82 100644 --- a/src/transport/transport-testing2.h +++ b/src/transport/transport-testing2.h | |||
@@ -132,7 +132,8 @@ typedef void | |||
132 | *tc_h, | 132 | *tc_h, |
133 | struct | 133 | struct |
134 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue | 134 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue |
135 | *tc_queue); | 135 | *tc_queue, |
136 | size_t mtu); | ||
136 | 137 | ||
137 | 138 | ||
138 | /** | 139 | /** |
@@ -171,6 +172,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | |||
171 | const char *service_name, | 172 | const char *service_name, |
172 | const char *binary_name, | 173 | const char *binary_name, |
173 | const char *cfg_filename, | 174 | const char *cfg_filename, |
175 | const struct GNUNET_PeerIdentity *peer_id, | ||
174 | GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback | 176 | GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback |
175 | communicator_available_cb, | 177 | communicator_available_cb, |
176 | GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, | 178 | GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, |
@@ -214,8 +216,8 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (struct | |||
214 | */ | 216 | */ |
215 | void | 217 | void |
216 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct | 218 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct |
217 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue | 219 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle |
218 | *tc_queue, | 220 | *tc_h, |
219 | GNUNET_SCHEDULER_TaskCallback | 221 | GNUNET_SCHEDULER_TaskCallback |
220 | cont, | 222 | cont, |
221 | void *cont_cls, | 223 | void *cont_cls, |
diff --git a/src/transport/transport.h b/src/transport/transport.h index 36182d8d7..a64ffd5c6 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -836,6 +836,17 @@ struct GNUNET_TRANSPORT_AddQueueMessage | |||
836 | uint32_t mtu; | 836 | uint32_t mtu; |
837 | 837 | ||
838 | /** | 838 | /** |
839 | * Queue length, in NBO. Defines how many messages may be | ||
840 | * send through this queue. UINT64_MAX for unlimited. | ||
841 | */ | ||
842 | uint64_t q_len; | ||
843 | |||
844 | /** | ||
845 | * Priority of the queue in relation to other queues. | ||
846 | */ | ||
847 | uint32_t priority; | ||
848 | |||
849 | /** | ||
839 | * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO. | 850 | * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO. |
840 | */ | 851 | */ |
841 | uint32_t cs; | 852 | uint32_t cs; |
@@ -845,6 +856,55 @@ struct GNUNET_TRANSPORT_AddQueueMessage | |||
845 | 856 | ||
846 | 857 | ||
847 | /** | 858 | /** |
859 | * Update queue | ||
860 | */ | ||
861 | struct GNUNET_TRANSPORT_UpdateQueueMessage | ||
862 | { | ||
863 | /** | ||
864 | * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP. | ||
865 | */ | ||
866 | struct GNUNET_MessageHeader header; | ||
867 | |||
868 | /** | ||
869 | * Queue identifier (used to identify the queue). | ||
870 | */ | ||
871 | uint32_t qid GNUNET_PACKED; | ||
872 | |||
873 | /** | ||
874 | * Receiver that can be addressed via the queue. | ||
875 | */ | ||
876 | struct GNUNET_PeerIdentity receiver; | ||
877 | |||
878 | /** | ||
879 | * An `enum GNUNET_NetworkType` in NBO. | ||
880 | */ | ||
881 | uint32_t nt; | ||
882 | |||
883 | /** | ||
884 | * Maximum transmission unit, in NBO. UINT32_MAX for unlimited. | ||
885 | */ | ||
886 | uint32_t mtu; | ||
887 | |||
888 | /** | ||
889 | * Queue length, in NBO. Defines how many messages may be | ||
890 | * send through this queue. UINT64_MAX for unlimited. | ||
891 | */ | ||
892 | uint64_t q_len; | ||
893 | |||
894 | /** | ||
895 | * Priority of the queue in relation to other queues. | ||
896 | */ | ||
897 | uint32_t priority; | ||
898 | |||
899 | /** | ||
900 | * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO. | ||
901 | */ | ||
902 | uint32_t cs; | ||
903 | }; | ||
904 | |||
905 | |||
906 | |||
907 | /** | ||
848 | * Remove queue, it is no longer available. | 908 | * Remove queue, it is no longer available. |
849 | */ | 909 | */ |
850 | struct GNUNET_TRANSPORT_DelQueueMessage | 910 | struct GNUNET_TRANSPORT_DelQueueMessage |
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c index e80cd5c03..cfa144415 100644 --- a/src/transport/transport_api2_communication.c +++ b/src/transport/transport_api2_communication.c | |||
@@ -280,6 +280,15 @@ struct GNUNET_TRANSPORT_QueueHandle | |||
280 | * Maximum transmission unit for the queue. | 280 | * Maximum transmission unit for the queue. |
281 | */ | 281 | */ |
282 | uint32_t mtu; | 282 | uint32_t mtu; |
283 | |||
284 | /** | ||
285 | * Queue length. | ||
286 | */ | ||
287 | uint64_t q_len; | ||
288 | /** | ||
289 | * Queue priority. | ||
290 | */ | ||
291 | uint32_t priority; | ||
283 | }; | 292 | }; |
284 | 293 | ||
285 | 294 | ||
@@ -395,6 +404,8 @@ send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh) | |||
395 | 404 | ||
396 | if (NULL == qh->ch->mq) | 405 | if (NULL == qh->ch->mq) |
397 | return; | 406 | return; |
407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
408 | "Sending `GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP` message\n"); | ||
398 | env = GNUNET_MQ_msg_extra (aqm, | 409 | env = GNUNET_MQ_msg_extra (aqm, |
399 | strlen (qh->address) + 1, | 410 | strlen (qh->address) + 1, |
400 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP); | 411 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP); |
@@ -402,11 +413,39 @@ send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh) | |||
402 | aqm->receiver = qh->peer; | 413 | aqm->receiver = qh->peer; |
403 | aqm->nt = htonl ((uint32_t) qh->nt); | 414 | aqm->nt = htonl ((uint32_t) qh->nt); |
404 | aqm->mtu = htonl (qh->mtu); | 415 | aqm->mtu = htonl (qh->mtu); |
416 | aqm->q_len = GNUNET_htonll (qh->q_len); | ||
417 | aqm->priority = htonl (qh->priority); | ||
405 | aqm->cs = htonl ((uint32_t) qh->cs); | 418 | aqm->cs = htonl ((uint32_t) qh->cs); |
406 | memcpy (&aqm[1], qh->address, strlen (qh->address) + 1); | 419 | memcpy (&aqm[1], qh->address, strlen (qh->address) + 1); |
407 | GNUNET_MQ_send (qh->ch->mq, env); | 420 | GNUNET_MQ_send (qh->ch->mq, env); |
408 | } | 421 | } |
409 | 422 | ||
423 | /** | ||
424 | * Send message to the transport service about queue @a qh | ||
425 | * updated. | ||
426 | * | ||
427 | * @param qh queue to add | ||
428 | */ | ||
429 | static void | ||
430 | send_update_queue (struct GNUNET_TRANSPORT_QueueHandle *qh) | ||
431 | { | ||
432 | struct GNUNET_MQ_Envelope *env; | ||
433 | struct GNUNET_TRANSPORT_UpdateQueueMessage *uqm; | ||
434 | |||
435 | if (NULL == qh->ch->mq) | ||
436 | return; | ||
437 | env = GNUNET_MQ_msg (uqm, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE); | ||
438 | uqm->qid = htonl (qh->queue_id); | ||
439 | uqm->receiver = qh->peer; | ||
440 | uqm->nt = htonl ((uint32_t) qh->nt); | ||
441 | uqm->mtu = htonl (qh->mtu); | ||
442 | uqm->q_len = GNUNET_htonll (qh->q_len); | ||
443 | uqm->priority = htonl (qh->priority); | ||
444 | uqm->cs = htonl ((uint32_t) qh->cs); | ||
445 | GNUNET_MQ_send (qh->ch->mq, env); | ||
446 | } | ||
447 | |||
448 | |||
410 | 449 | ||
411 | /** | 450 | /** |
412 | * Send message to the transport service about queue @a qh | 451 | * Send message to the transport service about queue @a qh |
@@ -924,6 +963,9 @@ GNUNET_TRANSPORT_communicator_receive ( | |||
924 | * @param address address in human-readable format, 0-terminated, UTF-8 | 963 | * @param address address in human-readable format, 0-terminated, UTF-8 |
925 | * @param mtu maximum message size supported by queue, 0 if | 964 | * @param mtu maximum message size supported by queue, 0 if |
926 | * sending is not supported, SIZE_MAX for no MTU | 965 | * sending is not supported, SIZE_MAX for no MTU |
966 | * @param q_len number of messages that can be send through this queue | ||
967 | * @param priority queue priority. Queues with highest priority should be | ||
968 | * used | ||
927 | * @param nt which network type does the @a address belong to? | 969 | * @param nt which network type does the @a address belong to? |
928 | * @param cc what characteristics does the communicator have? | 970 | * @param cc what characteristics does the communicator have? |
929 | * @param cs what is the connection status of the queue? | 971 | * @param cs what is the connection status of the queue? |
@@ -936,6 +978,8 @@ GNUNET_TRANSPORT_communicator_mq_add ( | |||
936 | const struct GNUNET_PeerIdentity *peer, | 978 | const struct GNUNET_PeerIdentity *peer, |
937 | const char *address, | 979 | const char *address, |
938 | uint32_t mtu, | 980 | uint32_t mtu, |
981 | uint64_t q_len, | ||
982 | uint32_t priority, | ||
939 | enum GNUNET_NetworkType nt, | 983 | enum GNUNET_NetworkType nt, |
940 | enum GNUNET_TRANSPORT_ConnectionStatus cs, | 984 | enum GNUNET_TRANSPORT_ConnectionStatus cs, |
941 | struct GNUNET_MQ_Handle *mq) | 985 | struct GNUNET_MQ_Handle *mq) |
@@ -948,6 +992,8 @@ GNUNET_TRANSPORT_communicator_mq_add ( | |||
948 | qh->address = GNUNET_strdup (address); | 992 | qh->address = GNUNET_strdup (address); |
949 | qh->nt = nt; | 993 | qh->nt = nt; |
950 | qh->mtu = mtu; | 994 | qh->mtu = mtu; |
995 | qh->q_len = q_len; | ||
996 | qh->priority = priority; | ||
951 | qh->cs = cs; | 997 | qh->cs = cs; |
952 | qh->mq = mq; | 998 | qh->mq = mq; |
953 | qh->queue_id = ch->queue_gen++; | 999 | qh->queue_id = ch->queue_gen++; |
@@ -958,6 +1004,37 @@ GNUNET_TRANSPORT_communicator_mq_add ( | |||
958 | 1004 | ||
959 | 1005 | ||
960 | /** | 1006 | /** |
1007 | * Notify transport service that an MQ was updated | ||
1008 | * | ||
1009 | * @param ch connection to transport service | ||
1010 | * @param qh the queue to update | ||
1011 | * @param q_len number of messages that can be send through this queue | ||
1012 | * @param priority queue priority. Queues with highest priority should be | ||
1013 | * used | ||
1014 | */ | ||
1015 | void | ||
1016 | GNUNET_TRANSPORT_communicator_mq_update ( | ||
1017 | struct GNUNET_TRANSPORT_CommunicatorHandle *ch, | ||
1018 | const struct GNUNET_TRANSPORT_QueueHandle *u_qh, | ||
1019 | uint64_t q_len, | ||
1020 | uint32_t priority) | ||
1021 | { | ||
1022 | struct GNUNET_TRANSPORT_QueueHandle *qh; | ||
1023 | |||
1024 | for (qh = ch->queue_head; NULL != qh; qh = qh->next) | ||
1025 | { | ||
1026 | if (u_qh == qh) | ||
1027 | break; | ||
1028 | } | ||
1029 | GNUNET_assert (NULL != qh); | ||
1030 | qh->q_len = q_len; | ||
1031 | qh->priority = priority; | ||
1032 | send_update_queue (qh); | ||
1033 | } | ||
1034 | |||
1035 | |||
1036 | |||
1037 | /** | ||
961 | * Notify transport service that an MQ became unavailable due to a | 1038 | * Notify transport service that an MQ became unavailable due to a |
962 | * disconnect or timeout. | 1039 | * disconnect or timeout. |
963 | * | 1040 | * |
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index f3373fc38..83b3b9c3d 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -131,7 +131,6 @@ libgnunetutil_la_LIBADD = \ | |||
131 | $(LIBIDN) $(LIBIDN2) \ | 131 | $(LIBIDN) $(LIBIDN2) \ |
132 | $(Z_LIBS) \ | 132 | $(Z_LIBS) \ |
133 | -lunistring \ | 133 | -lunistring \ |
134 | -largon2 \ | ||
135 | -lsodium \ | 134 | -lsodium \ |
136 | $(XLIB) \ | 135 | $(XLIB) \ |
137 | $(PTHREAD) | 136 | $(PTHREAD) |
diff --git a/src/util/bio.c b/src/util/bio.c index e05258f73..ce15f073b 100644 --- a/src/util/bio.c +++ b/src/util/bio.c | |||
@@ -48,12 +48,37 @@ | |||
48 | 48 | ||
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Enum used internally to know how buffering is handled. | ||
52 | * | ||
53 | * The idea is that by using an enum, BIO can be extended to support other | ||
54 | * kinds of "backend" for buffering (or just formatted I/O.) | ||
55 | */ | ||
56 | enum IOType | ||
57 | { | ||
58 | /** | ||
59 | * The handle uses a file to read/write data. | ||
60 | */ | ||
61 | IO_FILE = 0, | ||
62 | |||
63 | /** | ||
64 | * The data is stored entirely in memory. | ||
65 | */ | ||
66 | IO_BUFFER, | ||
67 | }; | ||
68 | |||
69 | |||
70 | /** | ||
51 | * Handle for buffered reading. | 71 | * Handle for buffered reading. |
52 | */ | 72 | */ |
53 | struct GNUNET_BIO_ReadHandle | 73 | struct GNUNET_BIO_ReadHandle |
54 | { | 74 | { |
55 | /** | 75 | /** |
56 | * Underlying file abstraction. | 76 | * The "backend" type. |
77 | */ | ||
78 | enum IOType type; | ||
79 | |||
80 | /** | ||
81 | * Handle to a file on disk, if @e type is #IO_FILE. | ||
57 | */ | 82 | */ |
58 | struct GNUNET_DISK_FileHandle *fd; | 83 | struct GNUNET_DISK_FileHandle *fd; |
59 | 84 | ||
@@ -63,12 +88,12 @@ struct GNUNET_BIO_ReadHandle | |||
63 | char *emsg; | 88 | char *emsg; |
64 | 89 | ||
65 | /** | 90 | /** |
66 | * I/O buffer. Allocated at the end of the struct, do not free! | 91 | * I/O buffer. Do @b not free! |
67 | */ | 92 | */ |
68 | char *buffer; | 93 | char *buffer; |
69 | 94 | ||
70 | /** | 95 | /** |
71 | * Number of bytes available in read @e buffer. | 96 | * Number of bytes available in @e buffer. |
72 | */ | 97 | */ |
73 | size_t have; | 98 | size_t have; |
74 | 99 | ||
@@ -91,7 +116,7 @@ struct GNUNET_BIO_ReadHandle | |||
91 | * @return IO handle on success, NULL on error | 116 | * @return IO handle on success, NULL on error |
92 | */ | 117 | */ |
93 | struct GNUNET_BIO_ReadHandle * | 118 | struct GNUNET_BIO_ReadHandle * |
94 | GNUNET_BIO_read_open (const char *fn) | 119 | GNUNET_BIO_read_open_file (const char *fn) |
95 | { | 120 | { |
96 | struct GNUNET_DISK_FileHandle *fd; | 121 | struct GNUNET_DISK_FileHandle *fd; |
97 | struct GNUNET_BIO_ReadHandle *h; | 122 | struct GNUNET_BIO_ReadHandle *h; |
@@ -100,6 +125,7 @@ GNUNET_BIO_read_open (const char *fn) | |||
100 | if (NULL == fd) | 125 | if (NULL == fd) |
101 | return NULL; | 126 | return NULL; |
102 | h = GNUNET_malloc (sizeof(struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); | 127 | h = GNUNET_malloc (sizeof(struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); |
128 | h->type = IO_FILE; | ||
103 | h->buffer = (char *) &h[1]; | 129 | h->buffer = (char *) &h[1]; |
104 | h->size = BIO_BUFFER_SIZE; | 130 | h->size = BIO_BUFFER_SIZE; |
105 | h->fd = fd; | 131 | h->fd = fd; |
@@ -108,11 +134,32 @@ GNUNET_BIO_read_open (const char *fn) | |||
108 | 134 | ||
109 | 135 | ||
110 | /** | 136 | /** |
111 | * Close an open file. Reports if any errors reading | 137 | * Create a handle from an existing allocated buffer. |
138 | * | ||
139 | * @param buffer the buffer to use as source | ||
140 | * @param size the total size in bytes of the buffer | ||
141 | * @return IO handle on sucess, NULL on error | ||
142 | */ | ||
143 | struct GNUNET_BIO_ReadHandle * | ||
144 | GNUNET_BIO_read_open_buffer (void *buffer, size_t size) | ||
145 | { | ||
146 | struct GNUNET_BIO_ReadHandle *h; | ||
147 | |||
148 | h = GNUNET_new (struct GNUNET_BIO_ReadHandle); | ||
149 | h->type = IO_BUFFER; | ||
150 | h->buffer = buffer; | ||
151 | h->size = size; | ||
152 | return h; | ||
153 | } | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Close an open handle. Reports if any errors reading | ||
112 | * from the file were encountered. | 158 | * from the file were encountered. |
113 | * | 159 | * |
114 | * @param h file handle | 160 | * @param h file handle |
115 | * @param emsg set to the error message | 161 | * @param emsg set to the (allocated) error message |
162 | * if the handle has an error message, the return value is #GNUNET_SYSERR | ||
116 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 163 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
117 | */ | 164 | */ |
118 | int | 165 | int |
@@ -121,60 +168,63 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg) | |||
121 | int err; | 168 | int err; |
122 | 169 | ||
123 | err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR; | 170 | err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR; |
124 | if (emsg != NULL) | 171 | if (NULL != emsg) |
125 | *emsg = h->emsg; | 172 | *emsg = h->emsg; |
126 | else | 173 | else |
127 | GNUNET_free_non_null (h->emsg); | 174 | GNUNET_free_non_null (h->emsg); |
128 | GNUNET_DISK_file_close (h->fd); | 175 | switch (h->type) |
176 | { | ||
177 | case IO_FILE: | ||
178 | GNUNET_DISK_file_close (h->fd); | ||
179 | break; | ||
180 | case IO_BUFFER: | ||
181 | break; | ||
182 | default: | ||
183 | break; | ||
184 | } | ||
129 | GNUNET_free (h); | 185 | GNUNET_free (h); |
130 | return err; | 186 | return err; |
131 | } | 187 | } |
132 | 188 | ||
133 | 189 | ||
134 | /** | 190 | /** |
135 | * Read the contents of a binary file into a buffer. | 191 | * Function used internally to read the contents of a file into a buffer. |
136 | * | 192 | * |
137 | * @param h handle to an open file | 193 | * @param h the IO handle to read from |
138 | * @param what describes what is being read (for error message creation) | 194 | * @param what describes what is being read (for error message creation) |
139 | * @param result the buffer to write the result to | 195 | * @param result the buffer to write the data to |
140 | * @param len the number of bytes to read | 196 | * @param len the number of bytes to read |
141 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 197 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
142 | */ | 198 | */ |
143 | int | 199 | static int |
144 | GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, | 200 | read_from_file (struct GNUNET_BIO_ReadHandle *h, |
145 | const char *what, | 201 | const char *what, |
146 | void *result, | 202 | char *result, |
147 | size_t len) | 203 | size_t len) |
148 | { | 204 | { |
149 | char *dst = result; | 205 | size_t pos = 0; |
150 | size_t min; | 206 | size_t min; |
151 | size_t pos; | ||
152 | ssize_t ret; | 207 | ssize_t ret; |
153 | 208 | ||
154 | if (NULL != h->emsg) | ||
155 | return GNUNET_SYSERR; | ||
156 | pos = 0; | ||
157 | do | 209 | do |
158 | { | 210 | { |
159 | /* first, use buffer */ | ||
160 | min = h->have - h->pos; | 211 | min = h->have - h->pos; |
161 | if (min > 0) | 212 | if (0 < min) |
162 | { | 213 | { |
163 | if (min > len - pos) | 214 | if (len - pos < min) |
164 | min = len - pos; | 215 | min = len - pos; |
165 | GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min); | 216 | GNUNET_memcpy (&result[pos], &h->buffer[h->pos], min); |
166 | h->pos += min; | 217 | h->pos += min; |
167 | pos += min; | 218 | pos += min; |
168 | } | 219 | } |
169 | if (pos == len) | 220 | if (len == pos) |
170 | return GNUNET_OK; /* done! */ | 221 | return GNUNET_OK; |
171 | GNUNET_assert (((off_t) h->have) == h->pos); | 222 | GNUNET_assert (((off_t) h->have) == h->pos); |
172 | /* fill buffer */ | ||
173 | ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); | 223 | ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); |
174 | if (-1 == ret) | 224 | if (-1 == ret) |
175 | { | 225 | { |
176 | GNUNET_asprintf (&h->emsg, | 226 | GNUNET_asprintf (&h->emsg, |
177 | _ ("Error reading `%s': %s"), | 227 | _ ("Error reading `%s' from file: %s"), |
178 | what, | 228 | what, |
179 | strerror (errno)); | 229 | strerror (errno)); |
180 | return GNUNET_SYSERR; | 230 | return GNUNET_SYSERR; |
@@ -182,7 +232,7 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, | |||
182 | if (0 == ret) | 232 | if (0 == ret) |
183 | { | 233 | { |
184 | GNUNET_asprintf (&h->emsg, | 234 | GNUNET_asprintf (&h->emsg, |
185 | _ ("Error reading `%s': %s"), | 235 | _ ("Error reading `%s' from file: %s"), |
186 | what, | 236 | what, |
187 | _ ("End of file")); | 237 | _ ("End of file")); |
188 | return GNUNET_SYSERR; | 238 | return GNUNET_SYSERR; |
@@ -190,41 +240,84 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, | |||
190 | h->pos = 0; | 240 | h->pos = 0; |
191 | h->have = ret; | 241 | h->have = ret; |
192 | } | 242 | } |
193 | while (pos < len); /* should always be true */ | 243 | while (pos < len); |
194 | return GNUNET_OK; | 244 | return GNUNET_OK; |
195 | } | 245 | } |
196 | 246 | ||
197 | 247 | ||
198 | /** | 248 | /** |
199 | * Read the contents of a binary file into a buffer. | 249 | * Function used internally to read the content of a buffer into a buffer. |
200 | * | 250 | * |
201 | * @param h handle to an open file | 251 | * @param h the IO handle to read from |
202 | * @param file name of the source file | 252 | * @param what describes what is being read (for error message creation) |
203 | * @param line line number in the source file | 253 | * @param result the buffer to write the result to |
254 | * @param len the number of bytes to read | ||
255 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
256 | */ | ||
257 | static int | ||
258 | read_from_buffer (struct GNUNET_BIO_ReadHandle *h, | ||
259 | const char *what, | ||
260 | char *result, | ||
261 | size_t len) | ||
262 | { | ||
263 | if (h->size < len || h->size - h->pos < len) | ||
264 | { | ||
265 | GNUNET_asprintf (&h->emsg, | ||
266 | _ ("Error while reading `%s' from buffer: %s"), | ||
267 | what, | ||
268 | _ ("Not enough data left")); | ||
269 | return GNUNET_SYSERR; | ||
270 | } | ||
271 | GNUNET_memcpy (result, h->buffer + h->pos, len); | ||
272 | h->pos += len; | ||
273 | return GNUNET_OK; | ||
274 | } | ||
275 | |||
276 | |||
277 | /** | ||
278 | * Read some contents into a buffer. | ||
279 | * | ||
280 | * @param h the IO handle to read from | ||
281 | * @param what describes what is being read (for error message creation) | ||
204 | * @param result the buffer to write the result to | 282 | * @param result the buffer to write the result to |
205 | * @param len the number of bytes to read | 283 | * @param len the number of bytes to read |
206 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 284 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
207 | */ | 285 | */ |
208 | int | 286 | int |
209 | GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, | 287 | GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, |
210 | const char *file, | 288 | const char *what, |
211 | int line, | 289 | void *result, |
212 | void *result, | 290 | size_t len) |
213 | size_t len) | ||
214 | { | 291 | { |
215 | char what[PATH_MAX + 1024]; | 292 | char *dst = result; |
216 | 293 | ||
217 | GNUNET_snprintf (what, sizeof(what), "%s:%d", file, line); | 294 | if (NULL != h->emsg) |
218 | return GNUNET_BIO_read (h, what, result, len); | 295 | return GNUNET_SYSERR; |
296 | |||
297 | if (0 == len) | ||
298 | return GNUNET_OK; | ||
299 | |||
300 | switch (h->type) | ||
301 | { | ||
302 | case IO_FILE: | ||
303 | return read_from_file (h, what, dst, len); | ||
304 | case IO_BUFFER: | ||
305 | return read_from_buffer (h, what, dst, len); | ||
306 | default: | ||
307 | GNUNET_asprintf (&h->emsg, | ||
308 | _ ("Invalid handle type while reading `%s'"), | ||
309 | what); | ||
310 | return GNUNET_SYSERR; | ||
311 | } | ||
219 | } | 312 | } |
220 | 313 | ||
221 | 314 | ||
222 | /** | 315 | /** |
223 | * Read 0-terminated string from a file. | 316 | * Read 0-terminated string. |
224 | * | 317 | * |
225 | * @param h handle to an open file | 318 | * @param h the IO handle to read from |
226 | * @param what describes what is being read (for error message creation) | 319 | * @param what describes what is being read (for error message creation) |
227 | * @param result the buffer to store a pointer to the (allocated) string to | 320 | * @param result where to store the pointer to the (allocated) string |
228 | * (note that *result could be set to NULL as well) | 321 | * (note that *result could be set to NULL as well) |
229 | * @param max_length maximum allowed length for the string | 322 | * @param max_length maximum allowed length for the string |
230 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 323 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
@@ -238,10 +331,21 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, | |||
238 | char *buf; | 331 | char *buf; |
239 | uint32_t big; | 332 | uint32_t big; |
240 | 333 | ||
241 | if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big)) | 334 | if (GNUNET_OK != GNUNET_BIO_read_int32 (h, |
335 | _ ("string length"), | ||
336 | (int32_t *) &big)) | ||
242 | { | 337 | { |
243 | GNUNET_free_non_null (h->emsg); | 338 | char *tmp = h->emsg; |
244 | GNUNET_asprintf (&h->emsg, _ ("Error reading length of string `%s'"), what); | 339 | if (NULL != tmp) |
340 | GNUNET_asprintf (&h->emsg, | ||
341 | _ ("%s (while reading `%s')"), | ||
342 | tmp, | ||
343 | what); | ||
344 | else | ||
345 | GNUNET_asprintf (&h->emsg, | ||
346 | _ ("Error reading length of string `%s'"), | ||
347 | what); | ||
348 | GNUNET_free_non_null (tmp); | ||
245 | return GNUNET_SYSERR; | 349 | return GNUNET_SYSERR; |
246 | } | 350 | } |
247 | if (0 == big) | 351 | if (0 == big) |
@@ -274,7 +378,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, | |||
274 | 378 | ||
275 | 379 | ||
276 | /** | 380 | /** |
277 | * Read metadata container from a file. | 381 | * Read a metadata container. |
278 | * | 382 | * |
279 | * @param h handle to an open file | 383 | * @param h handle to an open file |
280 | * @param what describes what is being read (for error message creation) | 384 | * @param what describes what is being read (for error message creation) |
@@ -290,20 +394,23 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
290 | char *buf; | 394 | char *buf; |
291 | struct GNUNET_CONTAINER_MetaData *meta; | 395 | struct GNUNET_CONTAINER_MetaData *meta; |
292 | 396 | ||
293 | if (GNUNET_OK != GNUNET_BIO_read_int32 (h, (int32_t *) &size)) | 397 | if (GNUNET_OK != GNUNET_BIO_read_int32 (h, |
398 | _ ("metadata length"), | ||
399 | (int32_t *) &size)) | ||
294 | return GNUNET_SYSERR; | 400 | return GNUNET_SYSERR; |
295 | if (size == 0) | 401 | if (0 == size) |
296 | { | 402 | { |
297 | *result = NULL; | 403 | *result = NULL; |
298 | return GNUNET_OK; | 404 | return GNUNET_OK; |
299 | } | 405 | } |
300 | if (size > MAX_META_DATA) | 406 | if (MAX_META_DATA < size) |
301 | { | 407 | { |
302 | GNUNET_asprintf (&h->emsg, | 408 | GNUNET_asprintf ( |
303 | _ ("Serialized metadata `%s' larger than allowed (%u>%u)"), | 409 | &h->emsg, |
304 | what, | 410 | _ ("Serialized metadata `%s' larger than allowed (%u > %u)"), |
305 | size, | 411 | what, |
306 | MAX_META_DATA); | 412 | size, |
413 | MAX_META_DATA); | ||
307 | return GNUNET_SYSERR; | 414 | return GNUNET_SYSERR; |
308 | } | 415 | } |
309 | buf = GNUNET_malloc (size); | 416 | buf = GNUNET_malloc (size); |
@@ -316,7 +423,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
316 | if (NULL == meta) | 423 | if (NULL == meta) |
317 | { | 424 | { |
318 | GNUNET_free (buf); | 425 | GNUNET_free (buf); |
319 | GNUNET_asprintf (&h->emsg, _ ("Metadata `%s' failed to deserialize"), what); | 426 | GNUNET_asprintf (&h->emsg, _ ("Failed to deserialize metadata `%s'"), what); |
320 | return GNUNET_SYSERR; | 427 | return GNUNET_SYSERR; |
321 | } | 428 | } |
322 | GNUNET_free (buf); | 429 | GNUNET_free (buf); |
@@ -324,25 +431,56 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
324 | return GNUNET_OK; | 431 | return GNUNET_OK; |
325 | } | 432 | } |
326 | 433 | ||
434 | /** | ||
435 | * Read a float. | ||
436 | * | ||
437 | * @param h the IO handle to read from | ||
438 | * @param what describes what is being read (for error message creation) | ||
439 | * @param f address of float to read | ||
440 | */ | ||
441 | int | ||
442 | GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h, | ||
443 | const char *what, | ||
444 | float *f) | ||
445 | { | ||
446 | int32_t *i = (int32_t *) f; | ||
447 | return GNUNET_BIO_read_int32 (h, what, i); | ||
448 | } | ||
449 | |||
450 | |||
451 | /** | ||
452 | * Read a double. | ||
453 | * | ||
454 | * @param h the IO handle to read from | ||
455 | * @param what describes what is being read (for error message creation) | ||
456 | * @param f address of double to read | ||
457 | */ | ||
458 | int | ||
459 | GNUNET_BIO_read_double(struct GNUNET_BIO_ReadHandle *h, | ||
460 | const char *what, | ||
461 | double *f) | ||
462 | { | ||
463 | int64_t *i = (int64_t *) f; | ||
464 | return GNUNET_BIO_read_int64 (h, what, i); | ||
465 | } | ||
466 | |||
327 | 467 | ||
328 | /** | 468 | /** |
329 | * Read an (u)int32_t. | 469 | * Read an (u)int32_t. |
330 | * | 470 | * |
331 | * @param h hande to open file | 471 | * @param h the IO handle to read from |
332 | * @param file name of the source file | 472 | * @param what describes what is being read (for error message creation) |
333 | * @param line line number in the source file | 473 | * @param i where to store the data |
334 | * @param i address of 32-bit integer to read | ||
335 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 474 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
336 | */ | 475 | */ |
337 | int | 476 | int |
338 | GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, | 477 | GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, |
339 | const char *file, | 478 | const char *what, |
340 | int line, | 479 | int32_t *i) |
341 | int32_t *i) | ||
342 | { | 480 | { |
343 | int32_t big; | 481 | int32_t big; |
344 | 482 | ||
345 | if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof(int32_t))) | 483 | if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int32_t))) |
346 | return GNUNET_SYSERR; | 484 | return GNUNET_SYSERR; |
347 | *i = ntohl (big); | 485 | *i = ntohl (big); |
348 | return GNUNET_OK; | 486 | return GNUNET_OK; |
@@ -352,21 +490,19 @@ GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, | |||
352 | /** | 490 | /** |
353 | * Read an (u)int64_t. | 491 | * Read an (u)int64_t. |
354 | * | 492 | * |
355 | * @param h hande to open file | 493 | * @param h the IO handle to read from |
356 | * @param file name of the source file | 494 | * @param what describes what is being read (for error message creation) |
357 | * @param line line number in the source file | 495 | * @param i where to store the data |
358 | * @param i address of 64-bit integer to read | ||
359 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 496 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
360 | */ | 497 | */ |
361 | int | 498 | int |
362 | GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, | 499 | GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h, |
363 | const char *file, | 500 | const char *what, |
364 | int line, | 501 | int64_t *i) |
365 | int64_t *i) | ||
366 | { | 502 | { |
367 | int64_t big; | 503 | int64_t big; |
368 | 504 | ||
369 | if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof(int64_t))) | 505 | if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int64_t))) |
370 | return GNUNET_SYSERR; | 506 | return GNUNET_SYSERR; |
371 | *i = GNUNET_ntohll (big); | 507 | *i = GNUNET_ntohll (big); |
372 | return GNUNET_OK; | 508 | return GNUNET_OK; |
@@ -379,17 +515,29 @@ GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, | |||
379 | struct GNUNET_BIO_WriteHandle | 515 | struct GNUNET_BIO_WriteHandle |
380 | { | 516 | { |
381 | /** | 517 | /** |
382 | * Underlying file handle. | 518 | * The "backend" type. |
519 | */ | ||
520 | enum IOType type; | ||
521 | |||
522 | /** | ||
523 | * Handle to a file on disk, if @e type is #IO_FILE. | ||
383 | */ | 524 | */ |
384 | struct GNUNET_DISK_FileHandle *fd; | 525 | struct GNUNET_DISK_FileHandle *fd; |
385 | 526 | ||
386 | /** | 527 | /** |
387 | * I/O buffer. Do not free, allocated at the end of the struct. | 528 | * Error message, NULL if there were no errors. |
388 | */ | 529 | */ |
389 | char *buffer; | 530 | char *emsg; |
531 | |||
532 | /** | ||
533 | * I/O buffer. | ||
534 | * This field is a void * because it is used to hold pointers to allocated | ||
535 | * structures or arrays and will be casted to the appropriate type. | ||
536 | */ | ||
537 | void *buffer; | ||
390 | 538 | ||
391 | /** | 539 | /** |
392 | * Number of bytes already in @e buffer. | 540 | * Number of bytes available in @e buffer. |
393 | */ | 541 | */ |
394 | size_t have; | 542 | size_t have; |
395 | 543 | ||
@@ -403,25 +551,26 @@ struct GNUNET_BIO_WriteHandle | |||
403 | /** | 551 | /** |
404 | * Open a file for writing. | 552 | * Open a file for writing. |
405 | * | 553 | * |
406 | * @param fn file name to be opened | 554 | * @param fn name of the file to be opened |
407 | * @return IO handle on success, NULL on error | 555 | * @return IO handle on success, NULL on error |
408 | */ | 556 | */ |
409 | struct GNUNET_BIO_WriteHandle * | 557 | struct GNUNET_BIO_WriteHandle * |
410 | GNUNET_BIO_write_open (const char *fn) | 558 | GNUNET_BIO_write_open_file (const char *fn) |
411 | { | 559 | { |
412 | struct GNUNET_DISK_FileHandle *fd; | 560 | struct GNUNET_DISK_FileHandle *fd; |
413 | struct GNUNET_BIO_WriteHandle *h; | 561 | struct GNUNET_BIO_WriteHandle *h; |
414 | 562 | ||
415 | fd = | 563 | fd = |
416 | GNUNET_DISK_file_open (fn, | 564 | GNUNET_DISK_file_open (fn, |
417 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | 565 | GNUNET_DISK_OPEN_WRITE |
566 | | GNUNET_DISK_OPEN_TRUNCATE | ||
418 | | GNUNET_DISK_OPEN_CREATE, | 567 | | GNUNET_DISK_OPEN_CREATE, |
419 | GNUNET_DISK_PERM_USER_READ | 568 | GNUNET_DISK_PERM_USER_READ |
420 | | GNUNET_DISK_PERM_USER_WRITE); | 569 | | GNUNET_DISK_PERM_USER_WRITE); |
421 | if (NULL == fd) | 570 | if (NULL == fd) |
422 | return NULL; | 571 | return NULL; |
423 | h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); | 572 | h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); |
424 | h->buffer = (char *) &h[1]; | 573 | h->buffer = &h[1]; |
425 | h->size = BIO_BUFFER_SIZE; | 574 | h->size = BIO_BUFFER_SIZE; |
426 | h->fd = fd; | 575 | h->fd = fd; |
427 | return h; | 576 | return h; |
@@ -429,42 +578,94 @@ GNUNET_BIO_write_open (const char *fn) | |||
429 | 578 | ||
430 | 579 | ||
431 | /** | 580 | /** |
432 | * Close an open file for writing. | 581 | * Create a handle backed by an in-memory buffer. |
582 | * | ||
583 | * @return IO handle on success, NULL on error | ||
584 | */ | ||
585 | struct GNUNET_BIO_WriteHandle * | ||
586 | GNUNET_BIO_write_open_buffer (void) | ||
587 | { | ||
588 | struct GNUNET_BIO_WriteHandle *h; | ||
589 | |||
590 | h = GNUNET_new (struct GNUNET_BIO_WriteHandle); | ||
591 | h->type = IO_BUFFER; | ||
592 | h->buffer = (void *) GNUNET_malloc (sizeof (struct GNUNET_Buffer)); | ||
593 | return h; | ||
594 | } | ||
595 | |||
596 | |||
597 | /** | ||
598 | * Close an IO handle. | ||
599 | * If the handle was using a file, the file will be closed. | ||
433 | * | 600 | * |
434 | * @param h file handle | 601 | * @param h file handle |
602 | * @param emsg set to the (allocated) error message | ||
603 | * if the handle has an error message, the return value is #GNUNET_SYSERR | ||
435 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 604 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
436 | */ | 605 | */ |
437 | int | 606 | int |
438 | GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) | 607 | GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg) |
439 | { | 608 | { |
440 | int ret; | 609 | int err; |
441 | 610 | ||
442 | ret = GNUNET_SYSERR; | 611 | err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR; |
443 | if ((NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h)))) | 612 | if (NULL != emsg) |
444 | GNUNET_DISK_file_close (h->fd); | 613 | *emsg = h->emsg; |
614 | else | ||
615 | GNUNET_free_non_null (h->emsg); | ||
616 | switch (h->type) | ||
617 | { | ||
618 | case IO_FILE: | ||
619 | if (NULL == h->fd) | ||
620 | return GNUNET_SYSERR; | ||
621 | if (GNUNET_OK != GNUNET_BIO_flush (h)) | ||
622 | { | ||
623 | if (NULL != emsg) | ||
624 | *emsg = h->emsg; | ||
625 | else | ||
626 | GNUNET_free_non_null (h->emsg); | ||
627 | err = GNUNET_SYSERR; | ||
628 | } | ||
629 | else | ||
630 | { | ||
631 | GNUNET_DISK_file_close (h->fd); | ||
632 | } | ||
633 | break; | ||
634 | case IO_BUFFER: | ||
635 | GNUNET_buffer_clear ((struct GNUNET_Buffer *) h->buffer); | ||
636 | GNUNET_free (h->buffer); | ||
637 | break; | ||
638 | } | ||
445 | GNUNET_free (h); | 639 | GNUNET_free (h); |
446 | return ret; | 640 | return err; |
447 | } | 641 | } |
448 | 642 | ||
449 | 643 | ||
450 | /** | 644 | /** |
451 | * Force a buffered writer to flush its buffer | 645 | * Force a file-based buffered writer to flush its buffer. |
646 | * If the handle does not use a file, this function returs #GNUNET_OK | ||
647 | * without doing anything. | ||
452 | * | 648 | * |
453 | * @param h the writer handle | 649 | * @param h the IO handle |
454 | * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned and | 650 | * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned |
455 | * the file is closed | 651 | * and the file is closed |
456 | */ | 652 | */ |
457 | int | 653 | int |
458 | GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) | 654 | GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) |
459 | { | 655 | { |
460 | ssize_t ret; | 656 | ssize_t ret; |
461 | 657 | ||
658 | if (IO_FILE != h->type) | ||
659 | return GNUNET_OK; | ||
660 | |||
462 | ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); | 661 | ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); |
463 | if (ret != (ssize_t) h->have) | 662 | if (ret != (ssize_t) h->have) |
464 | { | 663 | { |
465 | GNUNET_DISK_file_close (h->fd); | 664 | GNUNET_DISK_file_close (h->fd); |
466 | h->fd = NULL; | 665 | h->fd = NULL; |
467 | return GNUNET_SYSERR; /* error */ | 666 | GNUNET_free_non_null (h->emsg); |
667 | GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file")); | ||
668 | return GNUNET_SYSERR; | ||
468 | } | 669 | } |
469 | h->have = 0; | 670 | h->have = 0; |
470 | return GNUNET_OK; | 671 | return GNUNET_OK; |
@@ -472,96 +673,213 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) | |||
472 | 673 | ||
473 | 674 | ||
474 | /** | 675 | /** |
475 | * Write a buffer to a file. | 676 | * Get the IO handle's contents. |
677 | * If the handle doesn't use an in-memory buffer, this function returns | ||
678 | * #GNUNET_SYSERR. | ||
476 | * | 679 | * |
477 | * @param h handle to open file | 680 | * @param h the IO handle |
478 | * @param buffer the data to write | 681 | * @param emsg set to the (allocated) error message |
479 | * @param n number of bytes to write | 682 | * if the handle has an error message the return value is #GNUNET_SYSERR |
480 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 683 | * @param contents where to store the pointer to the handle's contents |
684 | * @param size where to store the size of @e contents | ||
685 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
481 | */ | 686 | */ |
482 | int | 687 | int |
483 | GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, | 688 | GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, |
484 | const void *buffer, | 689 | char **emsg, |
485 | size_t n) | 690 | void **contents, |
691 | size_t *size) | ||
692 | { | ||
693 | if (IO_BUFFER != h->type) | ||
694 | return GNUNET_SYSERR; | ||
695 | if (NULL == contents || NULL == size) | ||
696 | return GNUNET_SYSERR; | ||
697 | int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK; | ||
698 | if (NULL != emsg) | ||
699 | *emsg = h->emsg; | ||
700 | else | ||
701 | GNUNET_free_non_null (h->emsg); | ||
702 | *contents = GNUNET_buffer_reap ((struct GNUNET_Buffer *) h->buffer, size); | ||
703 | return ret; | ||
704 | } | ||
705 | |||
706 | |||
707 | /** | ||
708 | * Function used internally to write the contents of a buffer into a file. | ||
709 | * | ||
710 | * @param h the IO handle to write to | ||
711 | * @param what describes what is being written (for error message creation) | ||
712 | * @param source the buffer to write | ||
713 | * @param len the number of bytes to write | ||
714 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
715 | */ | ||
716 | static int | ||
717 | write_to_file (struct GNUNET_BIO_WriteHandle *h, | ||
718 | const char *what, | ||
719 | const char *source, | ||
720 | size_t len) | ||
486 | { | 721 | { |
487 | const char *src = buffer; | ||
488 | size_t min; | 722 | size_t min; |
489 | size_t pos; | 723 | size_t pos = 0; |
724 | char *buffer = (char *) h->buffer; | ||
490 | 725 | ||
491 | if (NULL == h->fd) | 726 | if (NULL == h->fd) |
727 | { | ||
728 | GNUNET_asprintf (&h->emsg, | ||
729 | _ ("Error while writing `%s' to file: %s"), | ||
730 | what, | ||
731 | _ ("No associated file")); | ||
492 | return GNUNET_SYSERR; | 732 | return GNUNET_SYSERR; |
493 | pos = 0; | 733 | } |
734 | |||
494 | do | 735 | do |
495 | { | 736 | { |
496 | /* first, just use buffer */ | ||
497 | min = h->size - h->have; | 737 | min = h->size - h->have; |
498 | if (min > n - pos) | 738 | if (len - pos < min) |
499 | min = n - pos; | 739 | min = len - pos; |
500 | GNUNET_memcpy (&h->buffer[h->have], &src[pos], min); | 740 | GNUNET_memcpy (&buffer[h->have], &source[pos], min); |
501 | pos += min; | 741 | pos += min; |
502 | h->have += min; | 742 | h->have += min; |
503 | if (pos == n) | 743 | if (len == pos) |
504 | return GNUNET_OK; /* done */ | 744 | return GNUNET_OK; |
505 | GNUNET_assert (h->have == h->size); | 745 | GNUNET_assert (h->have == h->size); |
506 | if (GNUNET_OK != GNUNET_BIO_flush (h)) | 746 | if (GNUNET_OK != GNUNET_BIO_flush (h)) |
507 | return GNUNET_SYSERR; /* error */ | 747 | { |
748 | char *tmp = h->emsg; | ||
749 | GNUNET_asprintf (&h->emsg, | ||
750 | _ ("Error while writing `%s' to file: %s"), | ||
751 | what, | ||
752 | tmp); | ||
753 | GNUNET_free_non_null (tmp); | ||
754 | return GNUNET_SYSERR; | ||
755 | } | ||
508 | } | 756 | } |
509 | while (pos < n); /* should always be true */ | 757 | while (pos < len); |
510 | GNUNET_break (0); | 758 | GNUNET_break (0); |
511 | return GNUNET_OK; | 759 | return GNUNET_OK; |
512 | } | 760 | } |
513 | 761 | ||
514 | 762 | ||
515 | /** | 763 | /** |
516 | * Write a string to a file. | 764 | * Function used internally to write the contents of a buffer to another buffer. |
765 | * | ||
766 | * @param h the IO handle to write to | ||
767 | * @param what describes what is being written (for error message creation) | ||
768 | * @param source the buffer to write | ||
769 | * @param len the number of bytes to write | ||
770 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
771 | */ | ||
772 | static int | ||
773 | write_to_buffer (struct GNUNET_BIO_WriteHandle *h, | ||
774 | const char *what, | ||
775 | const char *source, | ||
776 | size_t len) | ||
777 | { | ||
778 | GNUNET_buffer_write ((struct GNUNET_Buffer *) h->buffer, source, len); | ||
779 | h->have += len; | ||
780 | return GNUNET_OK; | ||
781 | } | ||
782 | |||
783 | |||
784 | /** | ||
785 | * Write a buffer to a handle. | ||
786 | * | ||
787 | * @param h the IO handle to write to | ||
788 | * @param what what is being written (for error message creation) | ||
789 | * @param buffer the data to write | ||
790 | * @param n number of bytes to write | ||
791 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
792 | */ | ||
793 | int | ||
794 | GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, | ||
795 | const char *what, | ||
796 | const void *buffer, | ||
797 | size_t n) | ||
798 | { | ||
799 | const char *src = buffer; | ||
800 | |||
801 | if (NULL != h->emsg) | ||
802 | return GNUNET_SYSERR; | ||
803 | |||
804 | if (0 == n) | ||
805 | return GNUNET_OK; | ||
806 | |||
807 | switch (h->type) | ||
808 | { | ||
809 | case IO_FILE: | ||
810 | return write_to_file (h, what, src, n); | ||
811 | case IO_BUFFER: | ||
812 | return write_to_buffer (h, what, src, n); | ||
813 | default: | ||
814 | GNUNET_asprintf (&h->emsg, | ||
815 | _ ("Invalid handle type while writing `%s'"), | ||
816 | what); | ||
817 | return GNUNET_SYSERR; | ||
818 | } | ||
819 | } | ||
820 | |||
821 | |||
822 | /** | ||
823 | * Write a 0-terminated string. | ||
517 | * | 824 | * |
518 | * @param h handle to open file | 825 | * @param h the IO handle to write to |
826 | * @param what what is being written (for error message creation) | ||
519 | * @param s string to write (can be NULL) | 827 | * @param s string to write (can be NULL) |
520 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 828 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
521 | */ | 829 | */ |
522 | int | 830 | int |
523 | GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s) | 831 | GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, |
832 | const char *what, | ||
833 | const char *s) | ||
524 | { | 834 | { |
525 | uint32_t slen; | 835 | uint32_t slen; |
526 | 836 | ||
527 | slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1); | 837 | slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1); |
528 | if (GNUNET_OK != GNUNET_BIO_write_int32 (h, slen)) | 838 | if (GNUNET_OK != GNUNET_BIO_write_int32 (h, _ ("string length"), slen)) |
529 | return GNUNET_SYSERR; | 839 | return GNUNET_SYSERR; |
530 | if (0 != slen) | 840 | if (0 != slen) |
531 | return GNUNET_BIO_write (h, s, slen - 1); | 841 | return GNUNET_BIO_write (h, what, s, slen - 1); |
532 | return GNUNET_OK; | 842 | return GNUNET_OK; |
533 | } | 843 | } |
534 | 844 | ||
535 | 845 | ||
536 | /** | 846 | /** |
537 | * Write metadata container to a file. | 847 | * Write a metadata container. |
538 | * | 848 | * |
539 | * @param h handle to open file | 849 | * @param h the IO handle to write to |
850 | * @param what what is being written (for error message creation) | ||
540 | * @param m metadata to write | 851 | * @param m metadata to write |
541 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 852 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
542 | */ | 853 | */ |
543 | int | 854 | int |
544 | GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, | 855 | GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, |
856 | const char *what, | ||
545 | const struct GNUNET_CONTAINER_MetaData *m) | 857 | const struct GNUNET_CONTAINER_MetaData *m) |
546 | { | 858 | { |
547 | ssize_t size; | 859 | ssize_t size; |
548 | char *buf; | 860 | char *buf; |
549 | 861 | ||
550 | if (m == NULL) | 862 | if (m == NULL) |
551 | return GNUNET_BIO_write_int32 (h, 0); | 863 | return GNUNET_BIO_write_int32 (h, _ ("metadata length"), 0); |
552 | buf = NULL; | 864 | buf = NULL; |
553 | size = GNUNET_CONTAINER_meta_data_serialize ( | 865 | size = GNUNET_CONTAINER_meta_data_serialize ( |
554 | m, | 866 | m, |
555 | &buf, | 867 | &buf, |
556 | MAX_META_DATA, | 868 | MAX_META_DATA, |
557 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 869 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
558 | if (size == -1) | 870 | if (-1 == size) |
559 | { | 871 | { |
560 | GNUNET_free (buf); | 872 | GNUNET_free (buf); |
873 | GNUNET_free_non_null (h->emsg); | ||
874 | GNUNET_asprintf (&h->emsg, | ||
875 | _ ("Failed to serialize metadata `%s'"), | ||
876 | what); | ||
561 | return GNUNET_SYSERR; | 877 | return GNUNET_SYSERR; |
562 | } | 878 | } |
563 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, (uint32_t) size)) || | 879 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, |
564 | (GNUNET_OK != GNUNET_BIO_write (h, buf, size))) | 880 | _ ("metadata length"), |
881 | (uint32_t) size)) | ||
882 | || (GNUNET_OK != GNUNET_BIO_write (h, what, buf, size))) | ||
565 | { | 883 | { |
566 | GNUNET_free (buf); | 884 | GNUNET_free (buf); |
567 | return GNUNET_SYSERR; | 885 | return GNUNET_SYSERR; |
@@ -572,36 +890,669 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, | |||
572 | 890 | ||
573 | 891 | ||
574 | /** | 892 | /** |
893 | * Write a float. | ||
894 | * | ||
895 | * @param h the IO handle to write to | ||
896 | * @param what what is being written (for error message creation) | ||
897 | * @param f float to write | ||
898 | */ | ||
899 | int | ||
900 | GNUNET_BIO_write_float(struct GNUNET_BIO_WriteHandle *h, | ||
901 | const char *what, | ||
902 | float f) | ||
903 | { | ||
904 | int32_t i = f; | ||
905 | return GNUNET_BIO_write_int32 (h, what, i); | ||
906 | } | ||
907 | |||
908 | |||
909 | /** | ||
910 | * Write a double. | ||
911 | * | ||
912 | * @param h the IO handle to write to | ||
913 | * @param what what is being written (for error message creation) | ||
914 | * @param f double to write | ||
915 | */ | ||
916 | int | ||
917 | GNUNET_BIO_write_double(struct GNUNET_BIO_WriteHandle *h, | ||
918 | const char *what, | ||
919 | double f) | ||
920 | { | ||
921 | int64_t i = f; | ||
922 | return GNUNET_BIO_write_int64 (h, what, i); | ||
923 | } | ||
924 | |||
925 | |||
926 | /** | ||
575 | * Write an (u)int32_t. | 927 | * Write an (u)int32_t. |
576 | * | 928 | * |
577 | * @param h hande to open file | 929 | * @param h the IO handle to write to |
930 | * @param what what is being written (for error message creation) | ||
578 | * @param i 32-bit integer to write | 931 | * @param i 32-bit integer to write |
579 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 932 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
580 | */ | 933 | */ |
581 | int | 934 | int |
582 | GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i) | 935 | GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, |
936 | const char *what, | ||
937 | int32_t i) | ||
583 | { | 938 | { |
584 | int32_t big; | 939 | int32_t big; |
585 | 940 | ||
586 | big = htonl (i); | 941 | big = htonl (i); |
587 | return GNUNET_BIO_write (h, &big, sizeof(int32_t)); | 942 | return GNUNET_BIO_write (h, what, &big, sizeof(int32_t)); |
588 | } | 943 | } |
589 | 944 | ||
590 | 945 | ||
591 | /** | 946 | /** |
592 | * Write an (u)int64_t. | 947 | * Write an (u)int64_t. |
593 | * | 948 | * |
594 | * @param h hande to open file | 949 | * @param h the IO handle to write to |
950 | * @param what what is being written (for error message creation) | ||
595 | * @param i 64-bit integer to write | 951 | * @param i 64-bit integer to write |
596 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 952 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
597 | */ | 953 | */ |
598 | int | 954 | int |
599 | GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i) | 955 | GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, |
956 | const char *what, | ||
957 | int64_t i) | ||
600 | { | 958 | { |
601 | int64_t big; | 959 | int64_t big; |
602 | 960 | ||
603 | big = GNUNET_htonll (i); | 961 | big = GNUNET_htonll (i); |
604 | return GNUNET_BIO_write (h, &big, sizeof(int64_t)); | 962 | return GNUNET_BIO_write (h, what, &big, sizeof(int64_t)); |
963 | } | ||
964 | |||
965 | |||
966 | /** | ||
967 | * Function used internally to read some bytes from within a read spec. | ||
968 | * | ||
969 | * @param cls ignored, always NULL | ||
970 | * @param h the IO handle to read from | ||
971 | * @param what what is being read (for error message creation) | ||
972 | * @param target where to store the data | ||
973 | * @param target_size how many bytes to read | ||
974 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
975 | */ | ||
976 | static int | ||
977 | read_spec_handler_object (void *cls, | ||
978 | struct GNUNET_BIO_ReadHandle *h, | ||
979 | const char *what, | ||
980 | void *target, | ||
981 | size_t target_size) | ||
982 | { | ||
983 | return GNUNET_BIO_read (h, what, target, target_size); | ||
984 | } | ||
985 | |||
986 | |||
987 | /** | ||
988 | * Create the specification to read a certain amount of bytes. | ||
989 | * | ||
990 | * @param what describes what is being read (for error message creation) | ||
991 | * @param result the buffer to write the result to | ||
992 | * @param len the number of bytes to read | ||
993 | * @return the read spec | ||
994 | */ | ||
995 | struct GNUNET_BIO_ReadSpec | ||
996 | GNUNET_BIO_read_spec_object (const char *what, | ||
997 | void *result, | ||
998 | size_t len) | ||
999 | { | ||
1000 | struct GNUNET_BIO_ReadSpec rs = { | ||
1001 | .rh = &read_spec_handler_object, | ||
1002 | .cls = NULL, | ||
1003 | .what = what, | ||
1004 | .target = result, | ||
1005 | .size = len, | ||
1006 | }; | ||
1007 | |||
1008 | return rs; | ||
1009 | } | ||
1010 | |||
1011 | |||
1012 | /** | ||
1013 | * Function used interally to read a string from within a read spec. | ||
1014 | * | ||
1015 | * @param cls ignored, always NULL | ||
1016 | * @param h the IO handle to read from | ||
1017 | * @param what what is being read (for error message creation) | ||
1018 | * @param target where to store the data | ||
1019 | * @param target_size how many bytes to read | ||
1020 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1021 | */ | ||
1022 | static int | ||
1023 | read_spec_handler_string (void *cls, | ||
1024 | struct GNUNET_BIO_ReadHandle *h, | ||
1025 | const char *what, | ||
1026 | void *target, | ||
1027 | size_t target_size) | ||
1028 | { | ||
1029 | char **result = target; | ||
1030 | return GNUNET_BIO_read_string (h, what, result, target_size); | ||
1031 | } | ||
1032 | |||
1033 | |||
1034 | /** | ||
1035 | * Create the specification to read a 0-terminated string. | ||
1036 | * | ||
1037 | * @param what describes what is being read (for error message creation) | ||
1038 | * @param result where to store the pointer to the (allocated) string | ||
1039 | * (note that *result could be set to NULL as well) | ||
1040 | * @param max_length maximum allowed length for the string | ||
1041 | * @return the read spec | ||
1042 | */ | ||
1043 | struct GNUNET_BIO_ReadSpec | ||
1044 | GNUNET_BIO_read_spec_string (const char *what, | ||
1045 | char **result, | ||
1046 | size_t max_length) | ||
1047 | { | ||
1048 | struct GNUNET_BIO_ReadSpec rs = { | ||
1049 | .rh = &read_spec_handler_string, | ||
1050 | .cls = NULL, | ||
1051 | .target = result, | ||
1052 | .size = max_length, | ||
1053 | }; | ||
1054 | |||
1055 | return rs; | ||
1056 | } | ||
1057 | |||
1058 | |||
1059 | /** | ||
1060 | * Function used internally to read a metadata container from within a read | ||
1061 | * spec. | ||
1062 | * | ||
1063 | * @param cls ignored, always NULL | ||
1064 | * @param h the IO handle to read from | ||
1065 | * @param what what is being read (for error message creation) | ||
1066 | * @param target where to store the data | ||
1067 | * @param target_size ignored | ||
1068 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1069 | */ | ||
1070 | static int | ||
1071 | read_spec_handler_meta_data (void *cls, | ||
1072 | struct GNUNET_BIO_ReadHandle *h, | ||
1073 | const char *what, | ||
1074 | void *target, | ||
1075 | size_t target_size) | ||
1076 | { | ||
1077 | struct GNUNET_CONTAINER_MetaData **result = target; | ||
1078 | return GNUNET_BIO_read_meta_data (h, what, result); | ||
1079 | } | ||
1080 | |||
1081 | |||
1082 | /** | ||
1083 | * Create the specification to read a metadata container. | ||
1084 | * | ||
1085 | * @param what describes what is being read (for error message creation) | ||
1086 | * @param result the buffer to store a pointer to the (allocated) metadata | ||
1087 | * @return the read spec | ||
1088 | */ | ||
1089 | struct GNUNET_BIO_ReadSpec | ||
1090 | GNUNET_BIO_read_spec_meta_data (const char *what, | ||
1091 | struct GNUNET_CONTAINER_MetaData **result) | ||
1092 | { | ||
1093 | struct GNUNET_BIO_ReadSpec rs = { | ||
1094 | .rh = &read_spec_handler_meta_data, | ||
1095 | .cls = NULL, | ||
1096 | .target = result, | ||
1097 | .size = 0, | ||
1098 | }; | ||
1099 | |||
1100 | return rs; | ||
1101 | } | ||
1102 | |||
1103 | |||
1104 | /** | ||
1105 | * Function used internally to read an (u)int32_t from within a read spec. | ||
1106 | * | ||
1107 | * @param cls ignored, always NULL | ||
1108 | * @param h the IO handle to read from | ||
1109 | * @param what what is being read (for error message creation) | ||
1110 | * @param target where to store the data | ||
1111 | * @param target_size ignored | ||
1112 | * @retun #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1113 | */ | ||
1114 | static int | ||
1115 | read_spec_handler_int32 (void *cls, | ||
1116 | struct GNUNET_BIO_ReadHandle *h, | ||
1117 | const char *what, | ||
1118 | void *target, | ||
1119 | size_t target_size) | ||
1120 | { | ||
1121 | int32_t *result = target; | ||
1122 | return GNUNET_BIO_read_int32 (h, what, result); | ||
1123 | } | ||
1124 | |||
1125 | |||
1126 | /** | ||
1127 | * Create the specification to read an (u)int32_t. | ||
1128 | * | ||
1129 | * @param what describes what is being read (for error message creation) | ||
1130 | * @param i where to store the data | ||
1131 | * @return the read spec | ||
1132 | */ | ||
1133 | struct GNUNET_BIO_ReadSpec | ||
1134 | GNUNET_BIO_read_spec_int32 (const char *what, | ||
1135 | int32_t *i) | ||
1136 | { | ||
1137 | struct GNUNET_BIO_ReadSpec rs = { | ||
1138 | .rh = &read_spec_handler_int32, | ||
1139 | .cls = NULL, | ||
1140 | .target = i, | ||
1141 | .size = 0, | ||
1142 | }; | ||
1143 | |||
1144 | return rs; | ||
1145 | } | ||
1146 | |||
1147 | |||
1148 | /** | ||
1149 | * Function used internally to read an (u)int64_t from within a read spec. | ||
1150 | * | ||
1151 | * @param cls ignored, always NULL | ||
1152 | * @param h the IO handle to read from | ||
1153 | * @param what what is being read (for error message creation) | ||
1154 | * @param target where to store the data | ||
1155 | * @param target_size ignored | ||
1156 | * @retun #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1157 | */ | ||
1158 | static int | ||
1159 | read_spec_handler_int64 (void *cls, | ||
1160 | struct GNUNET_BIO_ReadHandle *h, | ||
1161 | const char *what, | ||
1162 | void *target, | ||
1163 | size_t target_size) | ||
1164 | { | ||
1165 | int64_t *result = target; | ||
1166 | return GNUNET_BIO_read_int64 (h, what, result); | ||
1167 | } | ||
1168 | |||
1169 | |||
1170 | /** | ||
1171 | * Create the specification to read an (u)int64_t. | ||
1172 | * | ||
1173 | * @param what describes what is being read (for error message creation) | ||
1174 | * @param i where to store the data | ||
1175 | * @return the read spec | ||
1176 | */ | ||
1177 | struct GNUNET_BIO_ReadSpec | ||
1178 | GNUNET_BIO_read_spec_int64 (const char *what, | ||
1179 | int64_t *i) | ||
1180 | { | ||
1181 | struct GNUNET_BIO_ReadSpec rs = { | ||
1182 | .rh = &read_spec_handler_int64, | ||
1183 | .cls = NULL, | ||
1184 | .target = i, | ||
1185 | .size = 0, | ||
1186 | }; | ||
1187 | |||
1188 | return rs; | ||
1189 | } | ||
1190 | |||
1191 | |||
1192 | /** | ||
1193 | * Create the specification to read a float. | ||
1194 | * | ||
1195 | * @param what describes what is being read (for error message creation) | ||
1196 | * @param f address of float to read | ||
1197 | */ | ||
1198 | struct GNUNET_BIO_ReadSpec | ||
1199 | GNUNET_BIO_read_spec_float(const char *what, float *f) | ||
1200 | { | ||
1201 | struct GNUNET_BIO_ReadSpec rs = { | ||
1202 | .rh = &read_spec_handler_int32, | ||
1203 | .cls = NULL, | ||
1204 | .target = (int32_t *) f, | ||
1205 | .size = 0, | ||
1206 | }; | ||
1207 | |||
1208 | return rs; | ||
1209 | } | ||
1210 | |||
1211 | |||
1212 | /** | ||
1213 | * Create the specification to read a double. | ||
1214 | * | ||
1215 | * @param what describes what is being read (for error message creation) | ||
1216 | * @param f address of double to read | ||
1217 | */ | ||
1218 | struct GNUNET_BIO_ReadSpec | ||
1219 | GNUNET_BIO_read_spec_double(const char *what, double *f) | ||
1220 | { | ||
1221 | struct GNUNET_BIO_ReadSpec rs = { | ||
1222 | .rh = &read_spec_handler_int64, | ||
1223 | .cls = NULL, | ||
1224 | .target = (int64_t *) f, | ||
1225 | .size = 0, | ||
1226 | }; | ||
1227 | |||
1228 | return rs; | ||
1229 | } | ||
1230 | |||
1231 | |||
1232 | /** | ||
1233 | * Execute the read specifications in order. | ||
1234 | * | ||
1235 | * @param h the IO handle to read from | ||
1236 | * @param rs array of read specs | ||
1237 | * the last element must be #GNUNET_BIO_read_spec_end | ||
1238 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1239 | */ | ||
1240 | int | ||
1241 | GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h, | ||
1242 | struct GNUNET_BIO_ReadSpec *rs) | ||
1243 | { | ||
1244 | int ret = GNUNET_OK; | ||
1245 | |||
1246 | for (size_t i=0; NULL!=rs[i].rh; ++i) | ||
1247 | { | ||
1248 | ret = rs[i].rh (rs[i].cls, h, rs[i].what, rs[i].target, rs[i].size); | ||
1249 | if (GNUNET_OK != ret) | ||
1250 | return ret; | ||
1251 | } | ||
1252 | |||
1253 | return ret; | ||
1254 | } | ||
1255 | |||
1256 | |||
1257 | /** | ||
1258 | * Function used internally to write some bytes from within a write spec. | ||
1259 | * | ||
1260 | * @param cls ignored, always NULL | ||
1261 | * @param h the IO handle to write to | ||
1262 | * @param what what is being written (for error message creation) | ||
1263 | * @param source the data to write | ||
1264 | * @param source_size how many bytes to write | ||
1265 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1266 | */ | ||
1267 | static int | ||
1268 | write_spec_handler_object (void *cls, | ||
1269 | struct GNUNET_BIO_WriteHandle *h, | ||
1270 | const char *what, | ||
1271 | void *source, | ||
1272 | size_t source_size) | ||
1273 | { | ||
1274 | return GNUNET_BIO_write (h, what, source, source_size); | ||
1275 | } | ||
1276 | |||
1277 | |||
1278 | /** | ||
1279 | * Create the specification to read some bytes. | ||
1280 | * | ||
1281 | * @param what describes what is being written (for error message creation) | ||
1282 | * @param source the data to write | ||
1283 | * @param size how many bytes should be written | ||
1284 | * @return the write spec | ||
1285 | */ | ||
1286 | struct GNUNET_BIO_WriteSpec | ||
1287 | GNUNET_BIO_write_spec_object (const char *what, | ||
1288 | void *source, | ||
1289 | size_t size) | ||
1290 | { | ||
1291 | struct GNUNET_BIO_WriteSpec ws = { | ||
1292 | .wh = &write_spec_handler_object, | ||
1293 | .cls = NULL, | ||
1294 | .what = what, | ||
1295 | .source = source, | ||
1296 | .source_size = size, | ||
1297 | }; | ||
1298 | |||
1299 | return ws; | ||
1300 | } | ||
1301 | |||
1302 | |||
1303 | /** | ||
1304 | * Function used internally to write a 0-terminated string from within a write | ||
1305 | * spec. | ||
1306 | * | ||
1307 | * @param cls ignored, always NULL | ||
1308 | * @param h the IO handle to write to | ||
1309 | * @param what what is being written (for error message creation) | ||
1310 | * @param source the data to write | ||
1311 | * @param source_size ignored | ||
1312 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1313 | */ | ||
1314 | static int | ||
1315 | write_spec_handler_string (void *cls, | ||
1316 | struct GNUNET_BIO_WriteHandle *h, | ||
1317 | const char *what, | ||
1318 | void *source, | ||
1319 | size_t source_size) | ||
1320 | { | ||
1321 | const char *s = source; | ||
1322 | return GNUNET_BIO_write_string (h, what, s); | ||
1323 | } | ||
1324 | |||
1325 | |||
1326 | /** | ||
1327 | * Create the specification to write a 0-terminated string. | ||
1328 | * | ||
1329 | * @param what describes what is being read (for error message creation) | ||
1330 | * @param s string to write (can be NULL) | ||
1331 | * @return the read spec | ||
1332 | */ | ||
1333 | struct GNUNET_BIO_WriteSpec | ||
1334 | GNUNET_BIO_write_spec_string (const char *what, | ||
1335 | const char *s) | ||
1336 | { | ||
1337 | struct GNUNET_BIO_WriteSpec ws = { | ||
1338 | .wh = &write_spec_handler_string, | ||
1339 | .cls = NULL, | ||
1340 | .what = what, | ||
1341 | .source = (void *) s, | ||
1342 | .source_size = 0, | ||
1343 | }; | ||
1344 | |||
1345 | return ws; | ||
1346 | } | ||
1347 | |||
1348 | |||
1349 | /** | ||
1350 | * Function used internally to write a metadata container from within a write | ||
1351 | * spec. | ||
1352 | * | ||
1353 | * @param cls ignored, always NULL | ||
1354 | * @param h the IO handle to write to | ||
1355 | * @param what what is being written (for error message creation) | ||
1356 | * @param source the data to write | ||
1357 | * @param source_size ignored | ||
1358 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1359 | */ | ||
1360 | static int | ||
1361 | write_spec_handler_meta_data (void *cls, | ||
1362 | struct GNUNET_BIO_WriteHandle *h, | ||
1363 | const char *what, | ||
1364 | void *source, | ||
1365 | size_t source_size) | ||
1366 | { | ||
1367 | const struct GNUNET_CONTAINER_MetaData *m = source; | ||
1368 | return GNUNET_BIO_write_meta_data (h, what, m); | ||
1369 | } | ||
1370 | |||
1371 | |||
1372 | /** | ||
1373 | * Create the specification to write a metadata container. | ||
1374 | * | ||
1375 | * @param what what is being written (for error message creation) | ||
1376 | * @param m metadata to write | ||
1377 | * @return the write spec | ||
1378 | */ | ||
1379 | struct GNUNET_BIO_WriteSpec | ||
1380 | GNUNET_BIO_write_spec_meta_data (const char *what, | ||
1381 | const struct GNUNET_CONTAINER_MetaData *m) | ||
1382 | { | ||
1383 | struct GNUNET_BIO_WriteSpec ws = { | ||
1384 | .wh = &write_spec_handler_meta_data, | ||
1385 | .cls = NULL, | ||
1386 | .what = what, | ||
1387 | .source = (void *) m, | ||
1388 | .source_size = 0, | ||
1389 | }; | ||
1390 | |||
1391 | return ws; | ||
1392 | } | ||
1393 | |||
1394 | |||
1395 | /** | ||
1396 | * Function used internally to write an (u)int32_t from within a write spec. | ||
1397 | * | ||
1398 | * @param cls ignored, always NULL | ||
1399 | * @param h the IO handle to write to | ||
1400 | * @param what what is being written (for error message creation) | ||
1401 | * @param source the data to write | ||
1402 | * @param source_size ignored | ||
1403 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1404 | */ | ||
1405 | static int | ||
1406 | write_spec_handler_int32 (void *cls, | ||
1407 | struct GNUNET_BIO_WriteHandle *h, | ||
1408 | const char *what, | ||
1409 | void *source, | ||
1410 | size_t source_size) | ||
1411 | { | ||
1412 | int32_t i = *(int32_t *) source; | ||
1413 | return GNUNET_BIO_write_int32 (h, what, i); | ||
1414 | } | ||
1415 | |||
1416 | |||
1417 | /** | ||
1418 | * Create the specification to write an (u)int32_t. | ||
1419 | * | ||
1420 | * @param what describes what is being written (for error message creation) | ||
1421 | * @param i pointer to a 32-bit integer | ||
1422 | * @return the write spec | ||
1423 | */ | ||
1424 | struct GNUNET_BIO_WriteSpec | ||
1425 | GNUNET_BIO_write_spec_int32 (const char *what, | ||
1426 | int32_t *i) | ||
1427 | { | ||
1428 | struct GNUNET_BIO_WriteSpec ws = { | ||
1429 | .wh = &write_spec_handler_int32, | ||
1430 | .cls = NULL, | ||
1431 | .what = what, | ||
1432 | .source = i, | ||
1433 | .source_size = 0, | ||
1434 | }; | ||
1435 | |||
1436 | return ws; | ||
1437 | } | ||
1438 | |||
1439 | |||
1440 | /** | ||
1441 | * Function used internally to write an (u)int64_t from within a write spec. | ||
1442 | * | ||
1443 | * @param cls ignored, always NULL | ||
1444 | * @param h the IO handle to write to | ||
1445 | * @param what what is being written (for error message creation) | ||
1446 | * @param source the data to write | ||
1447 | * @param source_size ignored | ||
1448 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1449 | */ | ||
1450 | static int | ||
1451 | write_spec_handler_int64 (void *cls, | ||
1452 | struct GNUNET_BIO_WriteHandle *h, | ||
1453 | const char *what, | ||
1454 | void *source, | ||
1455 | size_t source_size) | ||
1456 | { | ||
1457 | int64_t i = *(int64_t *) source; | ||
1458 | return GNUNET_BIO_write_int64 (h, what, i); | ||
1459 | } | ||
1460 | |||
1461 | |||
1462 | /** | ||
1463 | * Create the specification to write an (u)int64_t. | ||
1464 | * | ||
1465 | * @param what describes what is being written (for error message creation) | ||
1466 | * @param i pointer to a 64-bit integer | ||
1467 | * @return the write spec | ||
1468 | */ | ||
1469 | struct GNUNET_BIO_WriteSpec | ||
1470 | GNUNET_BIO_write_spec_int64 (const char *what, | ||
1471 | int64_t *i) | ||
1472 | { | ||
1473 | struct GNUNET_BIO_WriteSpec ws = { | ||
1474 | .wh = &write_spec_handler_int64, | ||
1475 | .cls = NULL, | ||
1476 | .what = what, | ||
1477 | .source = i, | ||
1478 | .source_size = 0, | ||
1479 | }; | ||
1480 | |||
1481 | return ws; | ||
1482 | } | ||
1483 | |||
1484 | |||
1485 | /** | ||
1486 | * Create the specification to write a float. | ||
1487 | * | ||
1488 | * @param what describes what is being written (for error message creation) | ||
1489 | * @param f pointer to a float | ||
1490 | * @return the write spec | ||
1491 | */ | ||
1492 | struct GNUNET_BIO_WriteSpec | ||
1493 | GNUNET_BIO_write_spec_float(const char *what, float *f) | ||
1494 | { | ||
1495 | struct GNUNET_BIO_WriteSpec ws = { | ||
1496 | .wh = &write_spec_handler_int32, | ||
1497 | .cls = NULL, | ||
1498 | .what = what, | ||
1499 | .source = (int32_t *) f, | ||
1500 | .source_size = 0, | ||
1501 | }; | ||
1502 | |||
1503 | return ws; | ||
1504 | } | ||
1505 | |||
1506 | |||
1507 | /** | ||
1508 | * Create the specification to write an double. | ||
1509 | * | ||
1510 | * @param what describes what is being written (for error message creation) | ||
1511 | * @param f pointer to a double | ||
1512 | * @return the write spec | ||
1513 | */ | ||
1514 | struct GNUNET_BIO_WriteSpec | ||
1515 | GNUNET_BIO_write_spec_double(const char *what, double *f) | ||
1516 | { | ||
1517 | struct GNUNET_BIO_WriteSpec ws = { | ||
1518 | .wh = &write_spec_handler_int64, | ||
1519 | .cls = NULL, | ||
1520 | .what = what, | ||
1521 | .source = (int64_t *) f, | ||
1522 | .source_size = 0, | ||
1523 | }; | ||
1524 | |||
1525 | return ws; | ||
1526 | } | ||
1527 | |||
1528 | |||
1529 | /** | ||
1530 | * Execute the write specifications in order. | ||
1531 | * | ||
1532 | * @param h the IO handle to write to | ||
1533 | * @param ws array of write specs | ||
1534 | * the last element must be #GNUNET_BIO_write_spec_end | ||
1535 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1536 | */ | ||
1537 | int | ||
1538 | GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h, | ||
1539 | struct GNUNET_BIO_WriteSpec *ws) | ||
1540 | { | ||
1541 | int ret = GNUNET_OK; | ||
1542 | |||
1543 | for (size_t i=0; NULL!=ws[i].wh; ++i) | ||
1544 | { | ||
1545 | ret = ws[i].wh (ws[i].cls, h, ws[i].what, ws[i].source, ws[i].source_size); | ||
1546 | if (GNUNET_OK != ret) | ||
1547 | return ret; | ||
1548 | } | ||
1549 | |||
1550 | /* If it's a file-based handle, the flush makes sure that the data in the | ||
1551 | buffer is actualy written to the disk. */ | ||
1552 | if (IO_FILE == h->type) | ||
1553 | ret = GNUNET_BIO_flush (h); | ||
1554 | |||
1555 | return ret; | ||
605 | } | 1556 | } |
606 | 1557 | ||
607 | 1558 | ||
diff --git a/src/util/buffer.c b/src/util/buffer.c index dabf630c7..c865f6307 100644 --- a/src/util/buffer.c +++ b/src/util/buffer.c | |||
@@ -130,7 +130,26 @@ GNUNET_buffer_reap_str (struct GNUNET_Buffer *buf) | |||
130 | buf->mem[buf->position++] = '\0'; | 130 | buf->mem[buf->position++] = '\0'; |
131 | } | 131 | } |
132 | res = buf->mem; | 132 | res = buf->mem; |
133 | *buf = (struct GNUNET_Buffer) { 0 }; | 133 | memset (buf, 0, sizeof (struct GNUNET_Buffer)); |
134 | return res; | ||
135 | } | ||
136 | |||
137 | |||
138 | /** | ||
139 | * Clear the buffer and return its contents. | ||
140 | * The caller is responsible to eventually #GNUNET_free | ||
141 | * the returned data. | ||
142 | * | ||
143 | * @param buf the buffer to reap the contents from | ||
144 | * @param size where to store the size of the returned data | ||
145 | * @returns the data contained in the string | ||
146 | */ | ||
147 | void * | ||
148 | GNUNET_buffer_reap (struct GNUNET_Buffer *buf, size_t *size) | ||
149 | { | ||
150 | *size = buf->position; | ||
151 | void *res = buf->mem; | ||
152 | memset (buf, 0, sizeof (struct GNUNET_Buffer)); | ||
134 | return res; | 153 | return res; |
135 | } | 154 | } |
136 | 155 | ||
@@ -144,7 +163,7 @@ void | |||
144 | GNUNET_buffer_clear (struct GNUNET_Buffer *buf) | 163 | GNUNET_buffer_clear (struct GNUNET_Buffer *buf) |
145 | { | 164 | { |
146 | GNUNET_free_non_null (buf->mem); | 165 | GNUNET_free_non_null (buf->mem); |
147 | *buf = (struct GNUNET_Buffer) { 0 }; | 166 | memset (buf, 0, sizeof (struct GNUNET_Buffer)); |
148 | } | 167 | } |
149 | 168 | ||
150 | 169 | ||
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 96d546185..e1608ae55 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -544,10 +544,18 @@ void | |||
544 | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | 544 | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
545 | { | 545 | { |
546 | BENCHMARK_START (eddsa_key_create); | 546 | BENCHMARK_START (eddsa_key_create); |
547 | /* | ||
548 | * We do not clamp for EdDSA, since all functions that use the private key do | ||
549 | * their own clamping (just like in libsodium). What we call "private key" | ||
550 | * here, actually corresponds to the seed in libsodium. | ||
551 | * | ||
552 | * (Contrast this to ECDSA, where functions using the private key can't clamp | ||
553 | * due to properties needed for GNS. That is a worse/unsafer API, but | ||
554 | * required for the GNS constructions to work.) | ||
555 | */ | ||
547 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 556 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, |
548 | pk, | 557 | pk, |
549 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); | 558 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); |
550 | // FIXME: should we not do the clamping here? Or is this done elsewhere? | ||
551 | BENCHMARK_END (eddsa_key_create); | 559 | BENCHMARK_END (eddsa_key_create); |
552 | } | 560 | } |
553 | 561 | ||
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index c41c419ff..622953476 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -244,18 +244,35 @@ GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode *hc, | |||
244 | /** | 244 | /** |
245 | * Obtain a bit from a hashcode. | 245 | * Obtain a bit from a hashcode. |
246 | * @param code the GNUNET_CRYPTO_hash to index bit-wise | 246 | * @param code the GNUNET_CRYPTO_hash to index bit-wise |
247 | * @param bit index into the hashcode, [0...511] | 247 | * @param bit index into the hashcode, [0...511] where 0 is the leftmost bit |
248 | * (bytes in code interpreted big endian) | ||
248 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | 249 | * @return Bit \a bit from hashcode \a code, -1 for invalid index |
249 | */ | 250 | */ |
250 | int | 251 | int |
251 | GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, unsigned int | 252 | GNUNET_CRYPTO_hash_get_bit_ltr (const struct GNUNET_HashCode *code, |
252 | bit) | 253 | unsigned int bit) |
254 | { | ||
255 | GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode)); | ||
256 | return (((unsigned char *) code)[bit >> 3] & (128 >> (bit & 7))) > 0; | ||
257 | } | ||
258 | |||
259 | /** | ||
260 | * Obtain a bit from a hashcode. | ||
261 | * @param code the GNUNET_CRYPTO_hash to index bit-wise | ||
262 | * @param bit index into the hashcode, [0...511] where 0 is the rightmost bit | ||
263 | * (bytes in code interpreted little endian) | ||
264 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | ||
265 | */ | ||
266 | int | ||
267 | GNUNET_CRYPTO_hash_get_bit_rtl (const struct GNUNET_HashCode *code, | ||
268 | unsigned int bit) | ||
253 | { | 269 | { |
254 | GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode)); | 270 | GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode)); |
255 | return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; | 271 | return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; |
256 | } | 272 | } |
257 | 273 | ||
258 | 274 | ||
275 | |||
259 | /** | 276 | /** |
260 | * Determine how many low order bits match in two | 277 | * Determine how many low order bits match in two |
261 | * `struct GNUNET_HashCode`s. i.e. - 010011 and 011111 share | 278 | * `struct GNUNET_HashCode`s. i.e. - 010011 and 011111 share |
@@ -275,8 +292,8 @@ GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first, | |||
275 | unsigned int i; | 292 | unsigned int i; |
276 | 293 | ||
277 | for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++) | 294 | for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++) |
278 | if (GNUNET_CRYPTO_hash_get_bit (first, i) != | 295 | if (GNUNET_CRYPTO_hash_get_bit_rtl (first, i) != |
279 | GNUNET_CRYPTO_hash_get_bit (second, i)) | 296 | GNUNET_CRYPTO_hash_get_bit_rtl (second, i)) |
280 | return i; | 297 | return i; |
281 | return sizeof(struct GNUNET_HashCode) * 8; | 298 | return sizeof(struct GNUNET_HashCode) * 8; |
282 | } | 299 | } |
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c index 35511a130..cfa0676d0 100644 --- a/src/util/crypto_pow.c +++ b/src/util/crypto_pow.c | |||
@@ -25,14 +25,14 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_crypto_lib.h" | 27 | #include "gnunet_crypto_lib.h" |
28 | #include <argon2.h> | 28 | #include <sodium.h> |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Calculate the 'proof-of-work' hash (an expensive hash). | 31 | * Calculate the 'proof-of-work' hash (an expensive hash). |
32 | * We're using a non-standard formula to avoid issues with | 32 | * We're using a non-standard formula to avoid issues with |
33 | * ASICs appearing (see #3795). | 33 | * ASICs appearing (see #3795). |
34 | * | 34 | * |
35 | * @param salt salt for the hash | 35 | * @param salt salt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long. |
36 | * @param buf data to hash | 36 | * @param buf data to hash |
37 | * @param buf_len number of bytes in @a buf | 37 | * @param buf_len number of bytes in @a buf |
38 | * @param result where to write the resulting hash | 38 | * @param result where to write the resulting hash |
@@ -43,17 +43,17 @@ GNUNET_CRYPTO_pow_hash (const char *salt, | |||
43 | size_t buf_len, | 43 | size_t buf_len, |
44 | struct GNUNET_HashCode *result) | 44 | struct GNUNET_HashCode *result) |
45 | { | 45 | { |
46 | GNUNET_break (ARGON2_OK == argon2d_hash_raw (3, /* iterations */ | 46 | GNUNET_assert (strlen (salt) == crypto_pwhash_argon2id_SALTBYTES); |
47 | 1024, /* memory (1 MiB) */ | 47 | /* Threads hardcoded at 1 in libsodium */ |
48 | 1, /* threads */ | 48 | GNUNET_break (0 == |
49 | buf, | 49 | crypto_pwhash_argon2id ((unsigned char *) result, |
50 | buf_len, | 50 | sizeof (struct GNUNET_HashCode), |
51 | salt, | 51 | buf, |
52 | strlen (salt), | 52 | buf_len, |
53 | result, | 53 | (unsigned char*) salt, |
54 | sizeof (struct | 54 | 3, /* iterations */ |
55 | GNUNET_HashCode))); | 55 | 1024 * 1024, /* memory (1 MiB) */ |
56 | 56 | crypto_pwhash_argon2id_ALG_ARGON2ID13)); | |
57 | } | 57 | } |
58 | 58 | ||
59 | 59 | ||
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 2957546a7..cb4640d48 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -620,8 +620,8 @@ rsa_blinding_key_derive (const struct GNUNET_CRYPTO_RsaPublicKey *pkey, | |||
620 | * @return 0 if the two are equal | 620 | * @return 0 if the two are equal |
621 | */ | 621 | */ |
622 | int | 622 | int |
623 | GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1, | 623 | GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1, |
624 | struct GNUNET_CRYPTO_RsaSignature *s2) | 624 | const struct GNUNET_CRYPTO_RsaSignature *s2) |
625 | { | 625 | { |
626 | void *b1; | 626 | void *b1; |
627 | void *b2; | 627 | void *b2; |
@@ -653,8 +653,8 @@ GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1, | |||
653 | * @return 0 if the two are equal | 653 | * @return 0 if the two are equal |
654 | */ | 654 | */ |
655 | int | 655 | int |
656 | GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1, | 656 | GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1, |
657 | struct GNUNET_CRYPTO_RsaPublicKey *p2) | 657 | const struct GNUNET_CRYPTO_RsaPublicKey *p2) |
658 | { | 658 | { |
659 | void *b1; | 659 | void *b1; |
660 | void *b2; | 660 | void *b2; |
@@ -686,8 +686,8 @@ GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1, | |||
686 | * @return 0 if the two are equal | 686 | * @return 0 if the two are equal |
687 | */ | 687 | */ |
688 | int | 688 | int |
689 | GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1, | 689 | GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1, |
690 | struct GNUNET_CRYPTO_RsaPrivateKey *p2) | 690 | const struct GNUNET_CRYPTO_RsaPrivateKey *p2) |
691 | { | 691 | { |
692 | void *b1; | 692 | void *b1; |
693 | void *b2; | 693 | void *b2; |
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index 70ba48d82..7d13ce469 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c | |||
@@ -79,7 +79,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
79 | unsigned int hash_count; | 79 | unsigned int hash_count; |
80 | 80 | ||
81 | hash_count = 0; | 81 | hash_count = 0; |
82 | while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)) | 82 | while (0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count)) |
83 | hash_count++; | 83 | hash_count++; |
84 | return hash_count; | 84 | return hash_count; |
85 | } | 85 | } |
@@ -117,7 +117,7 @@ find_proof (void *cls) | |||
117 | while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) | 117 | while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) |
118 | { | 118 | { |
119 | GNUNET_memcpy (buf, &counter, sizeof(uint64_t)); | 119 | GNUNET_memcpy (buf, &counter, sizeof(uint64_t)); |
120 | GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work", | 120 | GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof", |
121 | buf, | 121 | buf, |
122 | sizeof(buf), | 122 | sizeof(buf), |
123 | &result); | 123 | &result); |
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index dcd31dc2c..714df6957 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -70,6 +70,7 @@ static const struct GNUNET_OS_ProjectData default_pd = { | |||
70 | .is_gnu = 1, | 70 | .is_gnu = 1, |
71 | .gettext_domain = PACKAGE, | 71 | .gettext_domain = PACKAGE, |
72 | .gettext_path = NULL, | 72 | .gettext_path = NULL, |
73 | .agpl_url = GNUNET_AGPL_URL, | ||
73 | }; | 74 | }; |
74 | 75 | ||
75 | /** | 76 | /** |
diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c index 49d9ec644..8533351e1 100644 --- a/src/util/perf_crypto_asymmetric.c +++ b/src/util/perf_crypto_asymmetric.c | |||
@@ -62,9 +62,9 @@ int | |||
62 | main (int argc, char *argv[]) | 62 | main (int argc, char *argv[]) |
63 | { | 63 | { |
64 | int i; | 64 | int i; |
65 | struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l]; | 65 | struct GNUNET_CRYPTO_EcdhePrivateKey ecdhe[l]; |
66 | struct GNUNET_CRYPTO_EcdhePublicKey dhpub[l]; | 66 | struct GNUNET_CRYPTO_EcdhePublicKey dhpub[l]; |
67 | struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa[l]; | 67 | struct GNUNET_CRYPTO_EddsaPrivateKey eddsa[l]; |
68 | struct GNUNET_CRYPTO_EddsaPublicKey dspub[l]; | 68 | struct GNUNET_CRYPTO_EddsaPublicKey dspub[l]; |
69 | struct TestSig sig[l]; | 69 | struct TestSig sig[l]; |
70 | 70 | ||
@@ -82,18 +82,18 @@ main (int argc, char *argv[]) | |||
82 | 82 | ||
83 | start = GNUNET_TIME_absolute_get (); | 83 | start = GNUNET_TIME_absolute_get (); |
84 | for (i = 0; i < l; i++) | 84 | for (i = 0; i < l; i++) |
85 | eddsa[i] = GNUNET_CRYPTO_eddsa_key_create (); | 85 | GNUNET_CRYPTO_eddsa_key_create (&eddsa[i]); |
86 | log_duration ("EdDSA", "create key"); | 86 | log_duration ("EdDSA", "create key"); |
87 | 87 | ||
88 | start = GNUNET_TIME_absolute_get (); | 88 | start = GNUNET_TIME_absolute_get (); |
89 | for (i = 0; i < l; i++) | 89 | for (i = 0; i < l; i++) |
90 | GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]); | 90 | GNUNET_CRYPTO_eddsa_key_get_public (&eddsa[i], &dspub[i]); |
91 | log_duration ("EdDSA", "get public"); | 91 | log_duration ("EdDSA", "get public"); |
92 | 92 | ||
93 | start = GNUNET_TIME_absolute_get (); | 93 | start = GNUNET_TIME_absolute_get (); |
94 | for (i = 0; i < l; i++) | 94 | for (i = 0; i < l; i++) |
95 | GNUNET_assert (GNUNET_OK == | 95 | GNUNET_assert (GNUNET_OK == |
96 | GNUNET_CRYPTO_eddsa_sign_ (eddsa[i], | 96 | GNUNET_CRYPTO_eddsa_sign_ (&eddsa[i], |
97 | &sig[i].purp, | 97 | &sig[i].purp, |
98 | &sig[i].sig)); | 98 | &sig[i].sig)); |
99 | log_duration ("EdDSA", "sign HashCode"); | 99 | log_duration ("EdDSA", "sign HashCode"); |
@@ -109,19 +109,19 @@ main (int argc, char *argv[]) | |||
109 | 109 | ||
110 | start = GNUNET_TIME_absolute_get (); | 110 | start = GNUNET_TIME_absolute_get (); |
111 | for (i = 0; i < l; i++) | 111 | for (i = 0; i < l; i++) |
112 | ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create (); | 112 | GNUNET_CRYPTO_ecdhe_key_create (&ecdhe[i]); |
113 | log_duration ("ECDH", "create key"); | 113 | log_duration ("ECDH", "create key"); |
114 | 114 | ||
115 | start = GNUNET_TIME_absolute_get (); | 115 | start = GNUNET_TIME_absolute_get (); |
116 | for (i = 0; i < l; i++) | 116 | for (i = 0; i < l; i++) |
117 | GNUNET_CRYPTO_ecdhe_key_get_public (ecdhe[i], &dhpub[i]); | 117 | GNUNET_CRYPTO_ecdhe_key_get_public (&ecdhe[i], &dhpub[i]); |
118 | log_duration ("ECDH", "get public"); | 118 | log_duration ("ECDH", "get public"); |
119 | 119 | ||
120 | start = GNUNET_TIME_absolute_get (); | 120 | start = GNUNET_TIME_absolute_get (); |
121 | for (i = 0; i < l - 1; i += 2) | 121 | for (i = 0; i < l - 1; i += 2) |
122 | { | 122 | { |
123 | GNUNET_CRYPTO_ecc_ecdh (ecdhe[i], &dhpub[i + 1], &sig[i].h); | 123 | GNUNET_CRYPTO_ecc_ecdh (&ecdhe[i], &dhpub[i + 1], &sig[i].h); |
124 | GNUNET_CRYPTO_ecc_ecdh (ecdhe[i + 1], &dhpub[i], &sig[i + 1].h); | 124 | GNUNET_CRYPTO_ecc_ecdh (&ecdhe[i + 1], &dhpub[i], &sig[i + 1].h); |
125 | } | 125 | } |
126 | log_duration ("ECDH", "do DH"); | 126 | log_duration ("ECDH", "do DH"); |
127 | 127 | ||
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index a1e30bbd4..d38c700e4 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -152,7 +152,7 @@ struct GNUNET_RESOLVER_RequestHandle | |||
152 | /** | 152 | /** |
153 | * Has this request been transmitted to the service? | 153 | * Has this request been transmitted to the service? |
154 | * #GNUNET_YES if transmitted | 154 | * #GNUNET_YES if transmitted |
155 | * #GNUNET_YES if not transmitted | 155 | * #GNUNET_NO if not transmitted |
156 | * #GNUNET_SYSERR when request was canceled | 156 | * #GNUNET_SYSERR when request was canceled |
157 | */ | 157 | */ |
158 | int was_transmitted; | 158 | int was_transmitted; |
diff --git a/src/util/service.c b/src/util/service.c index 9dc14eba9..ea078b19b 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -1823,9 +1823,10 @@ return_agpl (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1823 | struct GNUNET_MQ_Envelope *env; | 1823 | struct GNUNET_MQ_Envelope *env; |
1824 | struct GNUNET_MessageHeader *res; | 1824 | struct GNUNET_MessageHeader *res; |
1825 | size_t slen; | 1825 | size_t slen; |
1826 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); | ||
1826 | 1827 | ||
1827 | (void) msg; | 1828 | (void) msg; |
1828 | slen = strlen (GNUNET_AGPL_URL) + 1; | 1829 | slen = strlen (pd->agpl_url) + 1; |
1829 | env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen); | 1830 | env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen); |
1830 | memcpy (&res[1], GNUNET_AGPL_URL, slen); | 1831 | memcpy (&res[1], GNUNET_AGPL_URL, slen); |
1831 | mq = GNUNET_SERVICE_client_get_mq (client); | 1832 | mq = GNUNET_SERVICE_client_get_mq (client); |
@@ -2019,7 +2020,9 @@ GNUNET_SERVICE_run_ (int argc, | |||
2019 | sh.connect_cb = connect_cb; | 2020 | sh.connect_cb = connect_cb; |
2020 | sh.disconnect_cb = disconnect_cb; | 2021 | sh.disconnect_cb = disconnect_cb; |
2021 | sh.cb_cls = cls; | 2022 | sh.cb_cls = cls; |
2022 | sh.handlers = GNUNET_MQ_copy_handlers (handlers); | 2023 | sh.handlers = (NULL == pd->agpl_url) |
2024 | ? GNUNET_MQ_copy_handlers (handlers) | ||
2025 | : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL); | ||
2023 | sh.service_name = service_name; | 2026 | sh.service_name = service_name; |
2024 | sh.ret = 0; | 2027 | sh.ret = 0; |
2025 | /* setup subsystems */ | 2028 | /* setup subsystems */ |
diff --git a/src/util/test_bio.c b/src/util/test_bio.c index 53b45c23a..0c8453121 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c | |||
@@ -30,363 +30,406 @@ | |||
30 | #define TESTSTRING "testString" | 30 | #define TESTSTRING "testString" |
31 | #define TESTNUMBER64 ((int64_t) 100000L) | 31 | #define TESTNUMBER64 ((int64_t) 100000L) |
32 | 32 | ||
33 | |||
33 | static int | 34 | static int |
34 | test_normal_rw () | 35 | test_normal_rw (void) |
35 | { | 36 | { |
36 | char *msg; | 37 | struct GNUNET_BIO_WriteHandle *wh; |
37 | int64_t testNum; | 38 | struct GNUNET_BIO_ReadHandle *rh; |
38 | char *readResultString; | 39 | void *buffer; |
39 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 40 | size_t buffer_size = 0; |
40 | struct GNUNET_BIO_WriteHandle *fileW; | 41 | char *filename = GNUNET_DISK_mktemp ("gnunet-bio"); |
41 | struct GNUNET_BIO_ReadHandle *fileR; | 42 | struct GNUNET_CONTAINER_MetaData *mdW; |
42 | struct GNUNET_CONTAINER_MetaData *metaDataW; | 43 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
43 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 44 | char *rString = NULL; |
44 | 45 | int64_t wNum = TESTNUMBER64; | |
45 | metaDataW = GNUNET_CONTAINER_meta_data_create (); | 46 | int64_t rNum = 0; |
46 | metaDataR = NULL; | 47 | |
47 | GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW); | 48 | mdW = GNUNET_CONTAINER_meta_data_create (); |
48 | 49 | GNUNET_CONTAINER_meta_data_add_publication_date (mdW); | |
49 | fileW = GNUNET_BIO_write_open (fileName); | 50 | |
50 | GNUNET_assert (NULL != fileW); | 51 | struct GNUNET_BIO_WriteSpec ws[] = { |
51 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, TESTSTRING)); | 52 | GNUNET_BIO_write_spec_string ("test-normal-rw-string", TESTSTRING), |
52 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_meta_data (fileW, metaDataW)); | 53 | GNUNET_BIO_write_spec_meta_data ("test-normal-rw-metadata", mdW), |
53 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int64 (fileW, TESTNUMBER64)); | 54 | GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64", &wNum), |
54 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 55 | GNUNET_BIO_write_spec_end(), |
55 | 56 | }; | |
56 | fileR = GNUNET_BIO_read_open (fileName); | 57 | |
57 | GNUNET_assert (NULL != fileR); | 58 | struct GNUNET_BIO_ReadSpec rs[] = { |
58 | readResultString = NULL; | 59 | GNUNET_BIO_read_spec_string ("test-normal-rw-string", &rString, 200), |
59 | GNUNET_assert (GNUNET_OK == | 60 | GNUNET_BIO_read_spec_meta_data ("test-normal-rw-metadata", &mdR), |
60 | GNUNET_BIO_read_string (fileR, "Read string error", | 61 | GNUNET_BIO_read_spec_int64 ("test-normal-rw-int64", &rNum), |
61 | &readResultString, 200)); | 62 | GNUNET_BIO_read_spec_end(), |
62 | GNUNET_assert (NULL != readResultString); | 63 | }; |
63 | GNUNET_assert (0 == strcmp (TESTSTRING, readResultString)); | 64 | |
64 | GNUNET_free (readResultString); | 65 | /* I/O on file */ |
66 | wh = GNUNET_BIO_write_open_file (filename); | ||
67 | GNUNET_assert (NULL != wh); | ||
68 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws)); | ||
69 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
70 | |||
71 | rh = GNUNET_BIO_read_open_file (filename); | ||
72 | GNUNET_assert (NULL != rh); | ||
73 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); | ||
74 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); | ||
75 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); | ||
76 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal (mdR, mdW)); | ||
77 | GNUNET_assert (wNum == rNum); | ||
78 | |||
79 | GNUNET_CONTAINER_meta_data_destroy (mdR); | ||
80 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
81 | GNUNET_free(filename); | ||
82 | |||
83 | /* I/O on buffer */ | ||
84 | wh = GNUNET_BIO_write_open_buffer (); | ||
85 | GNUNET_assert (NULL != wh); | ||
86 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws)); | ||
65 | GNUNET_assert (GNUNET_OK == | 87 | GNUNET_assert (GNUNET_OK == |
66 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 88 | GNUNET_BIO_get_buffer_contents (wh, |
67 | &metaDataR)); | 89 | NULL, |
68 | GNUNET_assert (GNUNET_YES == | 90 | &buffer, |
69 | GNUNET_CONTAINER_meta_data_test_equal (metaDataR, metaDataW)); | 91 | &buffer_size)); |
70 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum)); | 92 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); |
71 | GNUNET_BIO_read_close (fileR, &msg); | 93 | |
72 | GNUNET_CONTAINER_meta_data_destroy (metaDataW); | 94 | rh = GNUNET_BIO_read_open_buffer (buffer, buffer_size); |
73 | GNUNET_CONTAINER_meta_data_destroy (metaDataR); | 95 | GNUNET_assert (NULL != rh); |
74 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 96 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); |
75 | GNUNET_free (fileName); | 97 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); |
98 | GNUNET_assert (0 == strcmp (TESTSTRING, rString)); | ||
99 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal (mdR, mdW)); | ||
100 | GNUNET_assert (wNum == rNum); | ||
101 | |||
102 | GNUNET_free (buffer); | ||
103 | |||
104 | GNUNET_CONTAINER_meta_data_destroy (mdW); | ||
105 | GNUNET_CONTAINER_meta_data_destroy (mdR); | ||
76 | return 0; | 106 | return 0; |
77 | } | 107 | } |
78 | 108 | ||
79 | 109 | ||
80 | static int | 110 | static int |
81 | test_nullstring_rw () | 111 | test_nullstring_rw (void) |
82 | { | 112 | { |
83 | char *msg; | 113 | struct GNUNET_BIO_WriteHandle *wh; |
84 | char *readResultString = (char *) "not null"; | 114 | struct GNUNET_BIO_ReadHandle *rh; |
85 | struct GNUNET_BIO_WriteHandle *fileW; | 115 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
86 | struct GNUNET_BIO_ReadHandle *fileR; | 116 | char *rString = "not null"; |
87 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 117 | |
88 | 118 | wh = GNUNET_BIO_write_open_file (filename); | |
89 | fileW = GNUNET_BIO_write_open (fileName); | 119 | GNUNET_assert (NULL != wh); |
90 | GNUNET_assert (NULL != fileW); | 120 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, |
91 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, NULL)); | 121 | "test-nullstring-rw", |
92 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 122 | NULL)); |
93 | 123 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | |
94 | fileR = GNUNET_BIO_read_open (fileName); | 124 | |
95 | GNUNET_assert (NULL != fileR); | 125 | rh = GNUNET_BIO_read_open_file (filename); |
96 | GNUNET_assert (GNUNET_OK == | 126 | GNUNET_assert (NULL != rh); |
97 | GNUNET_BIO_read_string (fileR, "Read string error", | 127 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh, |
98 | &readResultString, 200)); | 128 | "test-nullstring-rw", |
99 | GNUNET_assert (NULL == readResultString); | 129 | &rString, 200)); |
100 | GNUNET_BIO_read_close (fileR, &msg); | 130 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); |
101 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 131 | |
102 | GNUNET_free (fileName); | 132 | GNUNET_assert (NULL == rString); |
103 | 133 | ||
134 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
135 | GNUNET_free (filename); | ||
104 | return 0; | 136 | return 0; |
105 | } | 137 | } |
106 | 138 | ||
107 | 139 | ||
108 | static int | 140 | static int |
109 | test_emptystring_rw () | 141 | test_emptystring_rw (void) |
110 | { | 142 | { |
111 | char *msg; | 143 | struct GNUNET_BIO_WriteHandle *wh; |
112 | char *readResultString; | 144 | struct GNUNET_BIO_ReadHandle *rh; |
113 | struct GNUNET_BIO_WriteHandle *fileW; | 145 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
114 | struct GNUNET_BIO_ReadHandle *fileR; | 146 | char *rString = NULL; |
115 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 147 | |
116 | 148 | wh = GNUNET_BIO_write_open_file (filename); | |
117 | fileW = GNUNET_BIO_write_open (fileName); | 149 | GNUNET_assert (NULL != wh); |
118 | GNUNET_assert (NULL != fileW); | 150 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, |
119 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, "")); | 151 | "test-emptystring-rw", |
120 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 152 | "")); |
121 | 153 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | |
122 | fileR = GNUNET_BIO_read_open (fileName); | 154 | |
123 | GNUNET_assert (NULL != fileR); | 155 | rh = GNUNET_BIO_read_open_file (filename); |
124 | readResultString = NULL; | 156 | GNUNET_assert (NULL != rh); |
125 | GNUNET_assert (GNUNET_OK == | 157 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh, |
126 | GNUNET_BIO_read_string (fileR, "Read string error", | 158 | "test-emptystring-rw", |
127 | &readResultString, 200)); | 159 | &rString, 200)); |
128 | GNUNET_free (readResultString); | 160 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); |
129 | GNUNET_BIO_read_close (fileR, &msg); | 161 | |
130 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 162 | GNUNET_free (rString); |
131 | GNUNET_free (fileName); | 163 | |
164 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
165 | GNUNET_free (filename); | ||
132 | return 0; | 166 | return 0; |
133 | } | 167 | } |
134 | 168 | ||
135 | 169 | ||
136 | static int | 170 | static int |
137 | test_bigstring_rw () | 171 | test_bigstring_rw (void) |
138 | { | 172 | { |
139 | char *msg; | 173 | struct GNUNET_BIO_WriteHandle *wh; |
140 | char *readResultString; | 174 | struct GNUNET_BIO_ReadHandle *rh; |
141 | struct GNUNET_BIO_WriteHandle *fileW; | 175 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
142 | struct GNUNET_BIO_ReadHandle *fileR; | 176 | char *rString = NULL; |
143 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 177 | |
144 | 178 | wh = GNUNET_BIO_write_open_file (filename); | |
145 | fileW = GNUNET_BIO_write_open (fileName); | 179 | GNUNET_assert (NULL != wh); |
146 | GNUNET_assert (NULL != fileW); | 180 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, |
147 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, TESTSTRING)); | 181 | "test-bigstring-rw", |
148 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 182 | TESTSTRING)); |
149 | 183 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | |
150 | fileR = GNUNET_BIO_read_open (fileName); | 184 | |
151 | GNUNET_assert (NULL != fileR); | 185 | rh = GNUNET_BIO_read_open_file (filename); |
152 | readResultString = NULL; | 186 | GNUNET_assert (NULL != rh); |
153 | GNUNET_assert (GNUNET_SYSERR == | 187 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_string (rh, |
154 | GNUNET_BIO_read_string (fileR, "Read string error", | 188 | "test-bigstring-rw", |
155 | &readResultString, 1)); | 189 | &rString, 1)); |
156 | GNUNET_assert (NULL == readResultString); | 190 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
157 | msg = NULL; | 191 | |
158 | GNUNET_BIO_read_close (fileR, &msg); | 192 | GNUNET_assert (NULL == rString); |
159 | GNUNET_free (msg); | 193 | |
160 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 194 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
161 | GNUNET_free (fileName); | 195 | GNUNET_free (filename); |
162 | return 0; | 196 | return 0; |
163 | } | 197 | } |
164 | 198 | ||
165 | 199 | ||
166 | static int | 200 | static int |
167 | test_bigmeta_rw () | 201 | test_bigmeta_rw (void) |
168 | { | 202 | { |
169 | char *msg; | ||
170 | static char meta[1024 * 1024 * 10]; | 203 | static char meta[1024 * 1024 * 10]; |
171 | struct GNUNET_BIO_WriteHandle *fileW; | 204 | struct GNUNET_BIO_WriteHandle *wh; |
172 | struct GNUNET_BIO_ReadHandle *fileR; | 205 | struct GNUNET_BIO_ReadHandle *rh; |
173 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 206 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
174 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 207 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
175 | 208 | ||
176 | memset (meta, 'b', sizeof(meta)); | 209 | memset (meta, 'b', sizeof (meta)); |
177 | meta[sizeof(meta) - 1] = '\0'; | 210 | meta[sizeof (meta) - 1] = '\0'; |
178 | fileW = GNUNET_BIO_write_open (fileName); | 211 | |
179 | GNUNET_assert (NULL != fileW); | 212 | wh = GNUNET_BIO_write_open_file (filename); |
180 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, sizeof(meta))); | 213 | GNUNET_assert (NULL != wh); |
181 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (fileW, meta, sizeof(meta))); | 214 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, |
182 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 215 | "test-bigmeta-rw-int32", |
183 | 216 | sizeof (meta))); | |
184 | fileR = GNUNET_BIO_read_open (fileName); | 217 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write (wh, |
185 | GNUNET_assert (NULL != fileR); | 218 | "test-bigmeta-rw-bytes", |
186 | metaDataR = NULL; | 219 | meta, |
220 | sizeof (meta))); | ||
221 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
222 | |||
223 | rh = GNUNET_BIO_read_open_file (filename); | ||
224 | GNUNET_assert (NULL != rh); | ||
187 | GNUNET_assert (GNUNET_SYSERR == | 225 | GNUNET_assert (GNUNET_SYSERR == |
188 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 226 | GNUNET_BIO_read_meta_data (rh, |
189 | &metaDataR)); | 227 | "test-bigmeta-rw-metadata", |
190 | msg = NULL; | 228 | &mdR)); |
191 | GNUNET_BIO_read_close (fileR, &msg); | 229 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
192 | GNUNET_free (msg); | 230 | |
193 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 231 | GNUNET_assert (NULL == mdR); |
194 | GNUNET_assert (NULL == metaDataR); | 232 | |
195 | GNUNET_free (fileName); | 233 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
234 | GNUNET_free (filename); | ||
196 | return 0; | 235 | return 0; |
197 | } | 236 | } |
198 | 237 | ||
199 | 238 | ||
200 | static int | 239 | static int |
201 | test_directory_r () | 240 | test_directory_r (void) |
202 | { | 241 | { |
203 | #ifdef __linux__ | 242 | #ifdef LINUX |
204 | char *msg; | 243 | struct GNUNET_BIO_ReadHandle *rh; |
205 | char readResult[200]; | 244 | char rString[200]; |
206 | struct GNUNET_BIO_ReadHandle *fileR; | 245 | |
207 | 246 | rh = GNUNET_BIO_read_open_file ("/dev"); | |
208 | fileR = GNUNET_BIO_read_open ("/dev"); | 247 | GNUNET_assert (NULL != rh); |
209 | GNUNET_assert (NULL != fileR); | 248 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read (rh, |
210 | GNUNET_assert (GNUNET_SYSERR == | 249 | "test-directory-r", |
211 | GNUNET_BIO_read (fileR, "Read error", readResult, | 250 | rString, |
212 | sizeof(readResult))); | 251 | sizeof (rString))); |
213 | msg = NULL; | 252 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
214 | GNUNET_BIO_read_close (fileR, &msg); | ||
215 | GNUNET_free (msg); | ||
216 | #endif | 253 | #endif |
217 | return 0; | 254 | return 0; |
218 | } | 255 | } |
219 | 256 | ||
220 | 257 | ||
221 | static int | 258 | static int |
222 | test_nullfile_rw () | 259 | test_nullfile_rw (void) |
223 | { | 260 | { |
224 | static char fileNameNO[102401]; | 261 | static char filename[102401]; |
225 | struct GNUNET_BIO_WriteHandle *fileWNO; | 262 | struct GNUNET_BIO_WriteHandle *wh; |
226 | struct GNUNET_BIO_ReadHandle *fileRNO; | 263 | struct GNUNET_BIO_ReadHandle *rh; |
227 | 264 | ||
228 | memset (fileNameNO, 'a', sizeof(fileNameNO)); | 265 | memset (filename, 'a', sizeof (filename)); |
229 | fileNameNO[sizeof(fileNameNO) - 1] = '\0'; | 266 | filename[sizeof (filename) - 1] = '\0'; |
230 | 267 | ||
231 | GNUNET_log_skip (1, GNUNET_NO); | 268 | GNUNET_log_skip (2, GNUNET_NO); |
232 | fileWNO = GNUNET_BIO_write_open (fileNameNO); | 269 | wh = GNUNET_BIO_write_open_file (filename); |
233 | GNUNET_log_skip (0, GNUNET_YES); | 270 | GNUNET_log_skip (0, GNUNET_YES); |
234 | GNUNET_assert (NULL == fileWNO); | 271 | GNUNET_assert (NULL == wh); |
235 | 272 | ||
236 | GNUNET_log_skip (1, GNUNET_NO); | 273 | GNUNET_log_skip (2, GNUNET_NO); |
237 | fileRNO = GNUNET_BIO_read_open (fileNameNO); | 274 | rh = GNUNET_BIO_read_open_file (filename); |
238 | GNUNET_log_skip (0, GNUNET_YES); | 275 | GNUNET_log_skip (0, GNUNET_YES); |
239 | GNUNET_assert (NULL == fileRNO); | 276 | GNUNET_assert (NULL == rh); |
277 | |||
240 | return 0; | 278 | return 0; |
241 | } | 279 | } |
242 | 280 | ||
243 | 281 | ||
244 | static int | 282 | static int |
245 | test_fullfile_rw () | 283 | test_fullfile_rw (void) |
246 | { | 284 | { |
247 | #ifdef __linux__ | 285 | #ifdef LINUX |
248 | /* /dev/full only seems to exist on Linux */ | 286 | /* /dev/full doesn't exist on every platform */ |
249 | char *msg; | 287 | struct GNUNET_BIO_WriteHandle *wh; |
250 | int64_t testNum; | 288 | struct GNUNET_BIO_ReadHandle *rh; |
251 | char *readResultString; | 289 | char *rString = NULL; |
252 | char readResult[200]; | 290 | char rResult[200]; |
253 | struct GNUNET_BIO_WriteHandle *fileW; | 291 | struct GNUNET_CONTAINER_MetaData *mdW; |
254 | struct GNUNET_BIO_ReadHandle *fileR; | 292 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
255 | struct GNUNET_CONTAINER_MetaData *metaDataW; | 293 | |
256 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 294 | mdW = GNUNET_CONTAINER_meta_data_create (); |
257 | 295 | GNUNET_CONTAINER_meta_data_add_publication_date (mdW); | |
258 | metaDataW = GNUNET_CONTAINER_meta_data_create (); | 296 | |
259 | GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW); | 297 | struct GNUNET_BIO_WriteSpec ws[] = { |
260 | 298 | GNUNET_BIO_write_spec_object ("test-fullfile-rw-bytes", | |
261 | fileW = GNUNET_BIO_write_open ("/dev/full"); | 299 | TESTSTRING, |
262 | GNUNET_assert (NULL != fileW); | 300 | strlen (TESTSTRING)), |
263 | (void) GNUNET_BIO_write (fileW, TESTSTRING, strlen (TESTSTRING)); | 301 | GNUNET_BIO_write_spec_string ("test-fullfile-rw-string", |
264 | (void) GNUNET_BIO_write_string (fileW, TESTSTRING); | 302 | TESTSTRING), |
265 | (void) GNUNET_BIO_write_meta_data (fileW, metaDataW); | 303 | GNUNET_BIO_write_spec_meta_data ("test-fullfile-rw-metadata", |
266 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (fileW)); | 304 | mdW), |
267 | GNUNET_CONTAINER_meta_data_destroy (metaDataW); | 305 | GNUNET_BIO_write_spec_end (), |
268 | 306 | }; | |
269 | fileW = GNUNET_BIO_write_open ("/dev/full"); | 307 | |
270 | GNUNET_assert (NULL != fileW); | 308 | struct GNUNET_BIO_ReadSpec rs[] = { |
271 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (fileW)); | 309 | GNUNET_BIO_read_spec_object ("test-fullfile-rw-bytes", |
272 | 310 | rResult, | |
273 | fileR = GNUNET_BIO_read_open ("/dev/null"); | 311 | sizeof (rResult)), |
274 | GNUNET_assert (NULL != fileR); | 312 | GNUNET_BIO_read_spec_string ("test-fullfile-rw-string", |
275 | GNUNET_assert (GNUNET_SYSERR == | 313 | &rString, |
276 | GNUNET_BIO_read (fileR, "Read error", readResult, | 314 | 200), |
277 | sizeof(readResult))); | 315 | GNUNET_BIO_read_spec_meta_data ("test-fullfile-rw-metadata", |
278 | readResultString = NULL; | 316 | &mdR), |
279 | GNUNET_assert (GNUNET_SYSERR == | 317 | GNUNET_BIO_read_spec_end(), |
280 | GNUNET_BIO_read_string (fileR, "Read string error", | 318 | }; |
281 | &readResultString, 200)); | 319 | |
282 | GNUNET_assert (NULL == readResultString); | 320 | wh = GNUNET_BIO_write_open_file ("/dev/full"); |
283 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_int64 (fileR, &testNum)); | 321 | GNUNET_assert (NULL != wh); |
284 | metaDataR = NULL; | 322 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_spec_commit (wh, ws)); |
285 | GNUNET_assert (GNUNET_SYSERR == | 323 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (wh, NULL)); |
286 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 324 | |
287 | &metaDataR)); | 325 | rh = GNUNET_BIO_read_open_file ("/dev/null"); |
288 | msg = NULL; | 326 | GNUNET_assert (NULL != rh); |
289 | GNUNET_BIO_read_close (fileR, &msg); | 327 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_spec_commit (rh, rs)); |
290 | GNUNET_free (msg); | 328 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
291 | GNUNET_assert (NULL == metaDataR); | 329 | |
330 | GNUNET_assert (NULL == rString); | ||
331 | GNUNET_assert (NULL == mdR); | ||
292 | #endif | 332 | #endif |
293 | return 0; | 333 | return 0; |
294 | } | 334 | } |
295 | 335 | ||
296 | 336 | ||
297 | static int | 337 | static int |
298 | test_fakestring_rw () | 338 | test_fakestring_rw (void) |
299 | { | 339 | { |
300 | char *msg; | 340 | struct GNUNET_BIO_WriteHandle *wh; |
301 | int32_t tmpInt = 2; | 341 | struct GNUNET_BIO_ReadHandle *rh; |
302 | char *readResult; | 342 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
303 | struct GNUNET_BIO_WriteHandle *fileW; | 343 | char *rString = NULL; |
304 | struct GNUNET_BIO_ReadHandle *fileR; | 344 | |
305 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 345 | wh = GNUNET_BIO_write_open_file (filename); |
306 | 346 | GNUNET_assert (NULL != wh); | |
307 | fileW = GNUNET_BIO_write_open (fileName); | 347 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, |
308 | GNUNET_assert (NULL != fileW); | 348 | "test-fakestring-rw-int32", |
309 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, tmpInt)); | 349 | 2)); |
310 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 350 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); |
311 | 351 | ||
312 | fileR = GNUNET_BIO_read_open (fileName); | 352 | rh = GNUNET_BIO_read_open_file (filename); |
313 | GNUNET_assert (NULL != fileR); | 353 | GNUNET_assert (NULL != rh); |
314 | GNUNET_assert (GNUNET_SYSERR == | 354 | GNUNET_assert (GNUNET_SYSERR == |
315 | GNUNET_BIO_read_string (fileR, "Read string error", | 355 | GNUNET_BIO_read_string (rh, |
316 | &readResult, 200)); | 356 | "test-fakestring-rw-string", |
317 | msg = NULL; | 357 | &rString, 200)); |
318 | GNUNET_BIO_read_close (fileR, &msg); | 358 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
319 | GNUNET_free (msg); | 359 | |
320 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 360 | GNUNET_assert (NULL == rString); |
321 | GNUNET_free (fileName); | 361 | |
362 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
363 | GNUNET_free (filename); | ||
322 | return 0; | 364 | return 0; |
323 | } | 365 | } |
324 | 366 | ||
325 | 367 | ||
326 | static int | 368 | static int |
327 | test_fakemeta_rw () | 369 | test_fakemeta_rw (void) |
328 | { | 370 | { |
329 | char *msg; | 371 | struct GNUNET_BIO_WriteHandle *wh; |
330 | int32_t tmpInt = 2; | 372 | struct GNUNET_BIO_ReadHandle *rh; |
331 | struct GNUNET_BIO_WriteHandle *fileW; | 373 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
332 | struct GNUNET_BIO_ReadHandle *fileR; | 374 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
333 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 375 | |
334 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 376 | wh = GNUNET_BIO_write_open_file (filename); |
335 | 377 | GNUNET_assert (NULL != wh); | |
336 | fileW = GNUNET_BIO_write_open (fileName); | 378 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, |
337 | GNUNET_assert (NULL != fileW); | 379 | "test-fakestring-rw-int32", |
338 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, tmpInt)); | 380 | 2)); |
339 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 381 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); |
340 | 382 | ||
341 | fileR = GNUNET_BIO_read_open (fileName); | 383 | rh = GNUNET_BIO_read_open_file (filename); |
342 | GNUNET_assert (NULL != fileR); | 384 | GNUNET_assert (NULL != rh); |
343 | metaDataR = NULL; | ||
344 | GNUNET_assert (GNUNET_SYSERR == | 385 | GNUNET_assert (GNUNET_SYSERR == |
345 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 386 | GNUNET_BIO_read_meta_data (rh, |
346 | &metaDataR)); | 387 | "test-fakestring-rw-metadata", |
347 | GNUNET_assert (NULL == metaDataR); | 388 | &mdR)); |
348 | msg = NULL; | 389 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
349 | GNUNET_BIO_read_close (fileR, &msg); | 390 | |
350 | GNUNET_free (msg); | 391 | GNUNET_assert (NULL == mdR); |
351 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 392 | |
352 | GNUNET_free (fileName); | 393 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
394 | GNUNET_free (filename); | ||
353 | return 0; | 395 | return 0; |
354 | } | 396 | } |
355 | 397 | ||
356 | 398 | ||
357 | static int | 399 | static int |
358 | test_fakebigmeta_rw () | 400 | test_fakebigmeta_rw (void) |
359 | { | 401 | { |
360 | char *msg; | 402 | struct GNUNET_BIO_WriteHandle *wh; |
361 | int32_t tmpInt = 1024 * 1024 * 10; | 403 | struct GNUNET_BIO_ReadHandle *rh; |
362 | struct GNUNET_BIO_WriteHandle *fileW; | 404 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); |
363 | struct GNUNET_BIO_ReadHandle *fileR; | 405 | struct GNUNET_CONTAINER_MetaData *mdR = NULL; |
364 | char *fileName = GNUNET_DISK_mktemp ("gnunet_bio"); | 406 | int32_t wNum = 1024 * 1024 * 10; |
365 | struct GNUNET_CONTAINER_MetaData *metaDataR; | 407 | |
366 | 408 | wh = GNUNET_BIO_write_open_file (filename); | |
367 | fileW = GNUNET_BIO_write_open (fileName); | 409 | GNUNET_assert (NULL != wh); |
368 | GNUNET_assert (NULL != fileW); | 410 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, |
369 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (fileW, tmpInt)); | 411 | "test-fakebigmeta-rw-int32", |
370 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); | 412 | wNum)); |
371 | 413 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | |
372 | fileR = GNUNET_BIO_read_open (fileName); | 414 | |
373 | GNUNET_assert (NULL != fileR); | 415 | rh = GNUNET_BIO_read_open_file (filename); |
374 | metaDataR = NULL; | 416 | GNUNET_assert (NULL != rh); |
375 | GNUNET_assert (GNUNET_SYSERR == | 417 | GNUNET_assert (GNUNET_SYSERR == |
376 | GNUNET_BIO_read_meta_data (fileR, "Read meta error", | 418 | GNUNET_BIO_read_meta_data (rh, |
377 | &metaDataR)); | 419 | "test-fakebigmeta-rw-metadata", |
378 | msg = NULL; | 420 | &mdR)); |
379 | GNUNET_BIO_read_close (fileR, &msg); | 421 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); |
380 | GNUNET_free (msg); | 422 | |
381 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (fileName)); | 423 | GNUNET_assert (NULL == mdR); |
382 | GNUNET_assert (NULL == metaDataR); | 424 | |
383 | GNUNET_free (fileName); | 425 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); |
426 | GNUNET_free (filename); | ||
384 | return 0; | 427 | return 0; |
385 | } | 428 | } |
386 | 429 | ||
387 | 430 | ||
388 | static int | 431 | static int |
389 | check_string_rw () | 432 | check_string_rw (void) |
390 | { | 433 | { |
391 | GNUNET_assert (0 == test_nullstring_rw ()); | 434 | GNUNET_assert (0 == test_nullstring_rw ()); |
392 | GNUNET_assert (0 == test_emptystring_rw ()); | 435 | GNUNET_assert (0 == test_emptystring_rw ()); |
@@ -397,7 +440,7 @@ check_string_rw () | |||
397 | 440 | ||
398 | 441 | ||
399 | static int | 442 | static int |
400 | check_metadata_rw () | 443 | check_metadata_rw (void) |
401 | { | 444 | { |
402 | GNUNET_assert (0 == test_fakebigmeta_rw ()); | 445 | GNUNET_assert (0 == test_fakebigmeta_rw ()); |
403 | GNUNET_assert (0 == test_fakemeta_rw ()); | 446 | GNUNET_assert (0 == test_fakemeta_rw ()); |
@@ -407,7 +450,7 @@ check_metadata_rw () | |||
407 | 450 | ||
408 | 451 | ||
409 | static int | 452 | static int |
410 | check_file_rw () | 453 | check_file_rw (void) |
411 | { | 454 | { |
412 | GNUNET_assert (0 == test_normal_rw ()); | 455 | GNUNET_assert (0 == test_normal_rw ()); |
413 | GNUNET_assert (0 == test_nullfile_rw ()); | 456 | GNUNET_assert (0 == test_nullfile_rw ()); |
diff --git a/src/util/test_crypto_ecdsa.c b/src/util/test_crypto_ecdsa.c index cfa236d6d..7908590a8 100644 --- a/src/util/test_crypto_ecdsa.c +++ b/src/util/test_crypto_ecdsa.c | |||
@@ -107,6 +107,7 @@ testDeriveSignVerify (void) | |||
107 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dpriv; | 107 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dpriv; |
108 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 108 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
109 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; | 109 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; |
110 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub2; | ||
110 | 111 | ||
111 | dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (&key, | 112 | dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (&key, |
112 | "test-derive", | 113 | "test-derive", |
@@ -117,9 +118,17 @@ testDeriveSignVerify (void) | |||
117 | "test-derive", | 118 | "test-derive", |
118 | "test-CTX", | 119 | "test-CTX", |
119 | &dpub); | 120 | &dpub); |
121 | GNUNET_CRYPTO_ecdsa_key_get_public (dpriv, &dpub2); | ||
120 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 122 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
121 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 123 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
122 | 124 | ||
125 | if (0 != GNUNET_memcmp (&dpub.q_y, &dpub2.q_y)) | ||
126 | { | ||
127 | fprintf (stderr, "%s", "key derivation failed\n"); | ||
128 | GNUNET_free (dpriv); | ||
129 | return GNUNET_SYSERR; | ||
130 | } | ||
131 | |||
123 | if (GNUNET_SYSERR == | 132 | if (GNUNET_SYSERR == |
124 | GNUNET_CRYPTO_ecdsa_sign_ (dpriv, | 133 | GNUNET_CRYPTO_ecdsa_sign_ (dpriv, |
125 | &purp, | 134 | &purp, |
diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c index 12e1324dd..d22e1f5d3 100644 --- a/src/util/test_crypto_hash.c +++ b/src/util/test_crypto_hash.c | |||
@@ -91,10 +91,15 @@ testArithmetic () | |||
91 | return 1; | 91 | return 1; |
92 | if (1 != GNUNET_CRYPTO_hash_xorcmp (&h1, &h2, &h2)) | 92 | if (1 != GNUNET_CRYPTO_hash_xorcmp (&h1, &h2, &h2)) |
93 | return 1; | 93 | return 1; |
94 | memset (&d, 0xF0, sizeof(d)); | 94 | memset (&d, 0x40, sizeof(d)); |
95 | if (0 != GNUNET_CRYPTO_hash_get_bit (&d, 3)) | 95 | if (0 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 3)) |
96 | return 1; | 96 | return 1; |
97 | if (1 != GNUNET_CRYPTO_hash_get_bit (&d, 6)) | 97 | if (1 != GNUNET_CRYPTO_hash_get_bit_rtl (&d, 6)) |
98 | return 1; | ||
99 | memset (&d, 0x02, sizeof(d)); | ||
100 | if (0 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 3)) | ||
101 | return 1; | ||
102 | if (1 != GNUNET_CRYPTO_hash_get_bit_ltr (&d, 6)) | ||
98 | return 1; | 103 | return 1; |
99 | memset (&d, 0, sizeof(d)); | 104 | memset (&d, 0, sizeof(d)); |
100 | GNUNET_CRYPTO_hash_to_aes_key (&d, &skey, &iv); | 105 | GNUNET_CRYPTO_hash_to_aes_key (&d, &skey, &iv); |