aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2020-12-21 23:52:27 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2020-12-21 23:52:27 +0900
commit4a280820ca3ac316e38a62396c4abba7df105063 (patch)
tree8d0ab8ec9229a5ab6a31da1bae1c28eb4f9e0c7c /src
parent309cf872b25749feaa0ca6ba426da39d0b081f9d (diff)
parent589be093eb59a9b72a3d6a04d1ffbbed30615d81 (diff)
downloadgnunet-4a280820ca3ac316e38a62396c4abba7df105063.tar.gz
gnunet-4a280820ca3ac316e38a62396c4abba7df105063.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src')
-rw-r--r--src/fs/gnunet-search.c15
-rw-r--r--src/fs/test_fs_download.c7
-rw-r--r--src/fs/test_fs_file_information.c6
-rw-r--r--src/fs/test_fs_list_indexed.c6
-rw-r--r--src/fs/test_fs_publish.c6
-rw-r--r--src/fs/test_fs_publish_persistence.c6
-rw-r--r--src/fs/test_fs_unindex.c3
-rw-r--r--src/fs/test_fs_unindex_persistence.c3
-rw-r--r--src/identity/gnunet-service-identity.c6
-rw-r--r--src/include/gnunet_common.h2
-rw-r--r--src/include/gnunet_configuration_lib.h59
-rw-r--r--src/include/gnunet_crypto_lib.h30
-rw-r--r--src/include/gnunet_disk_lib.h54
-rw-r--r--src/include/gnunet_scheduler_lib.h12
-rw-r--r--src/nse/gnunet-service-nse.c23
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c15
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c31
-rw-r--r--src/pq/pq_connect.c4
-rw-r--r--src/reclaim/oidc_helper.c2
-rw-r--r--src/revocation/gnunet-revocation.c21
-rw-r--r--src/testbed/gnunet_mpi_test.c3
-rw-r--r--src/topology/friends.c9
-rw-r--r--src/transport/Makefile.am18
-rw-r--r--src/transport/gnunet-communicator-udp.c362
-rw-r--r--src/transport/test_communicator_basic.c307
-rw-r--r--src/transport/test_communicator_tcp_basic_peer1.conf4
-rw-r--r--src/transport/test_communicator_tcp_basic_peer2.conf4
-rw-r--r--src/transport/test_communicator_tcp_rekey_peer1.conf4
-rw-r--r--src/transport/test_communicator_tcp_rekey_peer2.conf4
-rw-r--r--src/transport/test_communicator_udp_backchannel_peer1.conf5
-rw-r--r--src/transport/test_communicator_udp_backchannel_peer2.conf5
-rw-r--r--src/transport/test_communicator_udp_basic_peer1.conf5
-rw-r--r--src/transport/test_communicator_udp_basic_peer2.conf5
-rw-r--r--src/transport/test_communicator_udp_rekey_peer1.conf6
-rw-r--r--src/transport/test_communicator_udp_rekey_peer2.conf6
-rw-r--r--src/transport/test_communicator_unix_basic_peer1.conf4
-rw-r--r--src/transport/test_communicator_unix_basic_peer2.conf4
-rw-r--r--src/transport/transport-testing-communicator.c57
-rw-r--r--src/transport/transport-testing-communicator.h5
-rw-r--r--src/util/Makefile.am2
-rw-r--r--src/util/configuration.c385
-rw-r--r--src/util/crypto_ecc.c251
-rw-r--r--src/util/crypto_ecc_setup.c118
-rw-r--r--src/util/crypto_rsa.c181
-rw-r--r--src/util/disk.c561
-rw-r--r--src/util/gnunet-scrypt.c15
-rw-r--r--src/util/network.c31
-rw-r--r--src/util/test_disk.c4
48 files changed, 1036 insertions, 1640 deletions
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c
index d25ae55e6..e49609b18 100644
--- a/src/fs/gnunet-search.c
+++ b/src/fs/gnunet-search.c
@@ -111,17 +111,20 @@ clean_task (void *cls)
111 ctx = NULL; 111 ctx = NULL;
112 if (output_filename == NULL) 112 if (output_filename == NULL)
113 return; 113 return;
114 if (GNUNET_OK != GNUNET_FS_directory_builder_finish (db, &dsize, &ddata)) 114 if (GNUNET_OK !=
115 GNUNET_FS_directory_builder_finish (db, &dsize, &ddata))
115 { 116 {
116 GNUNET_break (0); 117 GNUNET_break (0);
117 GNUNET_free (output_filename); 118 GNUNET_free (output_filename);
118 return; 119 return;
119 } 120 }
120 if (dsize != GNUNET_DISK_fn_write (output_filename, 121 (void) GNUNET_DISK_directory_remove (output_filename);
121 ddata, 122 if (GNUNET_OK !=
122 dsize, 123 GNUNET_DISK_fn_write (output_filename,
123 GNUNET_DISK_PERM_USER_READ 124 ddata,
124 | GNUNET_DISK_PERM_USER_WRITE)) 125 dsize,
126 GNUNET_DISK_PERM_USER_READ
127 | GNUNET_DISK_PERM_USER_WRITE))
125 { 128 {
126 fprintf (stderr, 129 fprintf (stderr,
127 _ ("Failed to write directory with search results to `%s'\n"), 130 _ ("Failed to write directory with search results to `%s'\n"),
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c
index 2be2e7f6a..2fe0da77c 100644
--- a/src/fs/test_fs_download.c
+++ b/src/fs/test_fs_download.c
@@ -299,8 +299,11 @@ run (void *cls,
299 "USE_INDEX")) 299 "USE_INDEX"))
300 { 300 {
301 fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); 301 fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test");
302 GNUNET_assert (FILESIZE == 302 (void) GNUNET_DISK_directory_remove (fn1);
303 GNUNET_DISK_fn_write (fn1, buf, FILESIZE, 303 GNUNET_assert (GNUNET_OK ==
304 GNUNET_DISK_fn_write (fn1,
305 buf,
306 FILESIZE,
304 GNUNET_DISK_PERM_USER_READ 307 GNUNET_DISK_PERM_USER_READ
305 | GNUNET_DISK_PERM_USER_WRITE)); 308 | GNUNET_DISK_PERM_USER_WRITE));
306 GNUNET_free (buf); 309 GNUNET_free (buf);
diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c
index 9305471d6..9d0978e06 100644
--- a/src/fs/test_fs_file_information.c
+++ b/src/fs/test_fs_file_information.c
@@ -82,7 +82,8 @@ run (void *cls, char *const *args, const char *cfgfile,
82 buf = GNUNET_malloc (FILESIZE); 82 buf = GNUNET_malloc (FILESIZE);
83 for (i = 0; i < FILESIZE; i++) 83 for (i = 0; i < FILESIZE; i++)
84 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 84 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
85 GNUNET_assert (FILESIZE == 85 (void) GNUNET_DISK_directory_remove (fn1);
86 GNUNET_assert (GNUNET_OK ==
86 GNUNET_DISK_fn_write (fn1, buf, FILESIZE, 87 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
87 GNUNET_DISK_PERM_USER_READ 88 GNUNET_DISK_PERM_USER_READ
88 | GNUNET_DISK_PERM_USER_WRITE)); 89 | GNUNET_DISK_PERM_USER_WRITE));
@@ -92,7 +93,8 @@ run (void *cls, char *const *args, const char *cfgfile,
92 buf = GNUNET_malloc (FILESIZE); 93 buf = GNUNET_malloc (FILESIZE);
93 for (i = 0; i < FILESIZE; i++) 94 for (i = 0; i < FILESIZE; i++)
94 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 95 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
95 GNUNET_assert (FILESIZE == 96 (void) GNUNET_DISK_directory_remove (fn2);
97 GNUNET_assert (GNUNET_OK ==
96 GNUNET_DISK_fn_write (fn2, buf, FILESIZE, 98 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
97 GNUNET_DISK_PERM_USER_READ 99 GNUNET_DISK_PERM_USER_READ
98 | GNUNET_DISK_PERM_USER_WRITE)); 100 | GNUNET_DISK_PERM_USER_WRITE));
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c
index 93367883f..2f04a017a 100644
--- a/src/fs/test_fs_list_indexed.c
+++ b/src/fs/test_fs_list_indexed.c
@@ -198,7 +198,8 @@ run (void *cls,
198 buf = GNUNET_malloc (FILESIZE); 198 buf = GNUNET_malloc (FILESIZE);
199 for (i = 0; i < FILESIZE; i++) 199 for (i = 0; i < FILESIZE; i++)
200 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 200 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
201 GNUNET_assert (FILESIZE == 201 (void) GNUNET_DISK_directory_remove (fn1);
202 GNUNET_assert (GNUNET_OK ==
202 GNUNET_DISK_fn_write (fn1, buf, FILESIZE, 203 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
203 GNUNET_DISK_PERM_USER_READ 204 GNUNET_DISK_PERM_USER_READ
204 | GNUNET_DISK_PERM_USER_WRITE)); 205 | GNUNET_DISK_PERM_USER_WRITE));
@@ -208,7 +209,8 @@ run (void *cls,
208 buf = GNUNET_malloc (FILESIZE); 209 buf = GNUNET_malloc (FILESIZE);
209 for (i = 0; i < FILESIZE; i++) 210 for (i = 0; i < FILESIZE; i++)
210 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 211 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
211 GNUNET_assert (FILESIZE == 212 (void) GNUNET_DISK_directory_remove (fn2);
213 GNUNET_assert (GNUNET_OK ==
212 GNUNET_DISK_fn_write (fn2, buf, FILESIZE, 214 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
213 GNUNET_DISK_PERM_USER_READ 215 GNUNET_DISK_PERM_USER_READ
214 | GNUNET_DISK_PERM_USER_WRITE)); 216 | GNUNET_DISK_PERM_USER_WRITE));
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c
index c42e546e3..2ffc722da 100644
--- a/src/fs/test_fs_publish.c
+++ b/src/fs/test_fs_publish.c
@@ -184,7 +184,8 @@ run (void *cls,
184 buf = GNUNET_malloc (FILESIZE); 184 buf = GNUNET_malloc (FILESIZE);
185 for (i = 0; i < FILESIZE; i++) 185 for (i = 0; i < FILESIZE; i++)
186 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 186 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
187 GNUNET_assert (FILESIZE == 187 (void) GNUNET_DISK_directory_remove (fn1);
188 GNUNET_assert (GNUNET_OK ==
188 GNUNET_DISK_fn_write (fn1, buf, FILESIZE, 189 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
189 GNUNET_DISK_PERM_USER_READ 190 GNUNET_DISK_PERM_USER_READ
190 | GNUNET_DISK_PERM_USER_WRITE)); 191 | GNUNET_DISK_PERM_USER_WRITE));
@@ -194,7 +195,8 @@ run (void *cls,
194 buf = GNUNET_malloc (FILESIZE); 195 buf = GNUNET_malloc (FILESIZE);
195 for (i = 0; i < FILESIZE; i++) 196 for (i = 0; i < FILESIZE; i++)
196 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 197 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
197 GNUNET_assert (FILESIZE == 198 (void) GNUNET_DISK_directory_remove (fn2);
199 GNUNET_assert (GNUNET_OK ==
198 GNUNET_DISK_fn_write (fn2, buf, FILESIZE, 200 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
199 GNUNET_DISK_PERM_USER_READ 201 GNUNET_DISK_PERM_USER_READ
200 | GNUNET_DISK_PERM_USER_WRITE)); 202 | GNUNET_DISK_PERM_USER_WRITE));
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c
index 4ec39d06e..da0209793 100644
--- a/src/fs/test_fs_publish_persistence.c
+++ b/src/fs/test_fs_publish_persistence.c
@@ -258,7 +258,8 @@ run (void *cls,
258 buf = GNUNET_malloc (FILESIZE); 258 buf = GNUNET_malloc (FILESIZE);
259 for (i = 0; i < FILESIZE; i++) 259 for (i = 0; i < FILESIZE; i++)
260 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 260 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
261 GNUNET_assert (FILESIZE == 261 (void) GNUNET_DISK_directory_remove (fn1);
262 GNUNET_assert (GNUNET_OK ==
262 GNUNET_DISK_fn_write (fn1, buf, FILESIZE, 263 GNUNET_DISK_fn_write (fn1, buf, FILESIZE,
263 GNUNET_DISK_PERM_USER_READ 264 GNUNET_DISK_PERM_USER_READ
264 | GNUNET_DISK_PERM_USER_WRITE)); 265 | GNUNET_DISK_PERM_USER_WRITE));
@@ -268,7 +269,8 @@ run (void *cls,
268 buf = GNUNET_malloc (FILESIZE); 269 buf = GNUNET_malloc (FILESIZE);
269 for (i = 0; i < FILESIZE; i++) 270 for (i = 0; i < FILESIZE; i++)
270 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 271 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
271 GNUNET_assert (FILESIZE == 272 (void) GNUNET_DISK_directory_remove (fn2);
273 GNUNET_assert (GNUNET_OK ==
272 GNUNET_DISK_fn_write (fn2, buf, FILESIZE, 274 GNUNET_DISK_fn_write (fn2, buf, FILESIZE,
273 GNUNET_DISK_PERM_USER_READ 275 GNUNET_DISK_PERM_USER_READ
274 | GNUNET_DISK_PERM_USER_WRITE)); 276 | GNUNET_DISK_PERM_USER_WRITE));
diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c
index a11c574c1..992672244 100644
--- a/src/fs/test_fs_unindex.c
+++ b/src/fs/test_fs_unindex.c
@@ -197,7 +197,8 @@ run (void *cls,
197 buf = GNUNET_malloc (FILESIZE); 197 buf = GNUNET_malloc (FILESIZE);
198 for (i = 0; i < FILESIZE; i++) 198 for (i = 0; i < FILESIZE; i++)
199 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 199 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
200 GNUNET_assert (FILESIZE == 200 (void) GNUNET_DISK_directory_remove (fn);
201 GNUNET_assert (GNUNET_OK ==
201 GNUNET_DISK_fn_write (fn, buf, FILESIZE, 202 GNUNET_DISK_fn_write (fn, buf, FILESIZE,
202 GNUNET_DISK_PERM_USER_READ 203 GNUNET_DISK_PERM_USER_READ
203 | GNUNET_DISK_PERM_USER_WRITE)); 204 | GNUNET_DISK_PERM_USER_WRITE));
diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c
index c3668f4e0..802aaf7ca 100644
--- a/src/fs/test_fs_unindex_persistence.c
+++ b/src/fs/test_fs_unindex_persistence.c
@@ -267,7 +267,8 @@ run (void *cls,
267 buf = GNUNET_malloc (FILESIZE); 267 buf = GNUNET_malloc (FILESIZE);
268 for (i = 0; i < FILESIZE; i++) 268 for (i = 0; i < FILESIZE; i++)
269 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 269 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256);
270 GNUNET_assert (FILESIZE == 270 (void) GNUNET_DISK_directory_remove (fn);
271 GNUNET_assert (GNUNET_OK ==
271 GNUNET_DISK_fn_write (fn, buf, FILESIZE, 272 GNUNET_DISK_fn_write (fn, buf, FILESIZE,
272 GNUNET_DISK_PERM_USER_READ 273 GNUNET_DISK_PERM_USER_READ
273 | GNUNET_DISK_PERM_USER_WRITE)); 274 | GNUNET_DISK_PERM_USER_WRITE));
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 6cdb1c2f7..2bb4b0897 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -697,8 +697,7 @@ check_create_message (void *cls,
697 697
698 698
699/** 699/**
700 * Handler for CREATE message from client, creates 700 * Handler for CREATE message from client, creates new identity.
701 * new identity.
702 * 701 *
703 * @param cls unused 702 * @param cls unused
704 * @param client who sent the message 703 * @param client who sent the message
@@ -737,8 +736,7 @@ handle_create_message (void *cls,
737 ego); 736 ego);
738 send_result_code (client, 0, NULL); 737 send_result_code (client, 0, NULL);
739 fn = get_ego_filename (ego); 738 fn = get_ego_filename (ego);
740 (void) GNUNET_DISK_directory_create_for_file (fn); 739 if (GNUNET_OK !=
741 if (sizeof(struct GNUNET_IDENTITY_PrivateKey) !=
742 GNUNET_DISK_fn_write (fn, 740 GNUNET_DISK_fn_write (fn,
743 &crm->private_key, 741 &crm->private_key,
744 sizeof(struct GNUNET_IDENTITY_PrivateKey), 742 sizeof(struct GNUNET_IDENTITY_PrivateKey),
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index bc2055709..b5af1146d 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -345,7 +345,7 @@ struct GNUNET_AsyncScopeSave
345 * #GNUNET_NO to stop iteration with no error, 345 * #GNUNET_NO to stop iteration with no error,
346 * #GNUNET_SYSERR to abort iteration with error! 346 * #GNUNET_SYSERR to abort iteration with error!
347 */ 347 */
348typedef int 348typedef enum GNUNET_GenericReturnValue
349(*GNUNET_FileNameCallback) (void *cls, 349(*GNUNET_FileNameCallback) (void *cls,
350 const char *filename); 350 const char *filename);
351 351
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index b4e7f7d8f..ad55c1b9a 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -82,7 +82,7 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
82 * @param filename name of the configuration file, NULL to load defaults 82 * @param filename name of the configuration file, NULL to load defaults
83 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 83 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
84 */ 84 */
85int 85enum GNUNET_GenericReturnValue
86GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, 86GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
87 const char *filename); 87 const char *filename);
88 88
@@ -95,7 +95,7 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
95 * @param defaults_d directory with the defaults 95 * @param defaults_d directory with the defaults
96 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 96 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
97 */ 97 */
98int 98enum GNUNET_GenericReturnValue
99GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, 99GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
100 const char *defaults_d); 100 const char *defaults_d);
101 101
@@ -120,7 +120,7 @@ GNUNET_CONFIGURATION_default (void);
120 * @param filename name of the configuration file 120 * @param filename name of the configuration file
121 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 121 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
122 */ 122 */
123int 123enum GNUNET_GenericReturnValue
124GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, 124GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
125 const char *filename); 125 const char *filename);
126 126
@@ -149,7 +149,7 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
149 * when we come across them 149 * when we come across them
150 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 150 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
151 */ 151 */
152int 152enum GNUNET_GenericReturnValue
153GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, 153GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
154 const char *mem, 154 const char *mem,
155 size_t size, 155 size_t size,
@@ -163,19 +163,20 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
163 * @param filename where to write the configuration 163 * @param filename where to write the configuration
164 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 164 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
165 */ 165 */
166int 166enum GNUNET_GenericReturnValue
167GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, 167GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
168 const char *filename); 168 const char *filename);
169 169
170 170
171/** 171/**
172 * Write only configuration entries that have been changed to configuration file 172 * Write only configuration entries that have been changed to configuration file
173 *
173 * @param cfg_default default configuration 174 * @param cfg_default default configuration
174 * @param cfg_new new configuration 175 * @param cfg_new new configuration
175 * @param filename where to write the configuration diff between default and new 176 * @param filename where to write the configuration diff between default and new
176 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 177 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
177 */ 178 */
178int 179enum GNUNET_GenericReturnValue
179GNUNET_CONFIGURATION_write_diffs (const struct 180GNUNET_CONFIGURATION_write_diffs (const struct
180 GNUNET_CONFIGURATION_Handle *cfg_default, 181 GNUNET_CONFIGURATION_Handle *cfg_default,
181 const struct 182 const struct
@@ -204,7 +205,7 @@ GNUNET_CONFIGURATION_get_diff (const struct
204 * @param cfg configuration to inspect 205 * @param cfg configuration to inspect
205 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) 206 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
206 */ 207 */
207int 208enum GNUNET_GenericReturnValue
208GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); 209GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
209 210
210 211
@@ -215,7 +216,7 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
215 * @param cfg the configuration 216 * @param cfg the configuration
216 * @return status code 217 * @return status code
217 */ 218 */
218typedef int 219typedef enum GNUNET_GenericReturnValue
219(*GNUNET_CONFIGURATION_Callback)(void *cls, 220(*GNUNET_CONFIGURATION_Callback)(void *cls,
220 const struct GNUNET_CONFIGURATION_Handle *cfg); 221 const struct GNUNET_CONFIGURATION_Handle *cfg);
221 222
@@ -231,7 +232,7 @@ typedef int
231 * @return #GNUNET_SYSERR if parsing the configuration failed, 232 * @return #GNUNET_SYSERR if parsing the configuration failed,
232 * otherwise return value from @a cb. 233 * otherwise return value from @a cb.
233 */ 234 */
234int 235enum GNUNET_GenericReturnValue
235GNUNET_CONFIGURATION_parse_and_run (const char *filename, 236GNUNET_CONFIGURATION_parse_and_run (const char *filename,
236 GNUNET_CONFIGURATION_Callback cb, 237 GNUNET_CONFIGURATION_Callback cb,
237 void *cb_cls); 238 void *cb_cls);
@@ -311,7 +312,7 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
311 * @param number where to store the numeric value of the option 312 * @param number where to store the numeric value of the option
312 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 313 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
313 */ 314 */
314int 315enum GNUNET_GenericReturnValue
315GNUNET_CONFIGURATION_get_value_number (const struct 316GNUNET_CONFIGURATION_get_value_number (const struct
316 GNUNET_CONFIGURATION_Handle *cfg, 317 GNUNET_CONFIGURATION_Handle *cfg,
317 const char *section, 318 const char *section,
@@ -328,7 +329,7 @@ GNUNET_CONFIGURATION_get_value_number (const struct
328 * @param number where to store the floating value of the option 329 * @param number where to store the floating value of the option
329 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 330 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
330 */ 331 */
331int 332enum GNUNET_GenericReturnValue
332GNUNET_CONFIGURATION_get_value_float (const struct 333GNUNET_CONFIGURATION_get_value_float (const struct
333 GNUNET_CONFIGURATION_Handle *cfg, 334 GNUNET_CONFIGURATION_Handle *cfg,
334 const char *section, 335 const char *section,
@@ -345,7 +346,7 @@ GNUNET_CONFIGURATION_get_value_float (const struct
345 * @param time set to the time value stored in the configuration 346 * @param time set to the time value stored in the configuration
346 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 347 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
347 */ 348 */
348int 349enum GNUNET_GenericReturnValue
349GNUNET_CONFIGURATION_get_value_time (const struct 350GNUNET_CONFIGURATION_get_value_time (const struct
350 GNUNET_CONFIGURATION_Handle *cfg, 351 GNUNET_CONFIGURATION_Handle *cfg,
351 const char *section, 352 const char *section,
@@ -362,7 +363,7 @@ GNUNET_CONFIGURATION_get_value_time (const struct
362 * @param size set to the size in bytes as stored in the configuration 363 * @param size set to the size in bytes as stored in the configuration
363 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 364 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
364 */ 365 */
365int 366enum GNUNET_GenericReturnValue
366GNUNET_CONFIGURATION_get_value_size (const struct 367GNUNET_CONFIGURATION_get_value_size (const struct
367 GNUNET_CONFIGURATION_Handle *cfg, 368 GNUNET_CONFIGURATION_Handle *cfg,
368 const char *section, 369 const char *section,
@@ -378,7 +379,7 @@ GNUNET_CONFIGURATION_get_value_size (const struct
378 * @param option option of interest 379 * @param option option of interest
379 * @return #GNUNET_YES if so, #GNUNET_NO if not. 380 * @return #GNUNET_YES if so, #GNUNET_NO if not.
380 */ 381 */
381int 382enum GNUNET_GenericReturnValue
382GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, 383GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
383 const char *section, 384 const char *section,
384 const char *option); 385 const char *option);
@@ -394,12 +395,12 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
394 * value, or NULL if option is not specified 395 * value, or NULL if option is not specified
395 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 396 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
396 */ 397 */
397int 398enum GNUNET_GenericReturnValue
398GNUNET_CONFIGURATION_get_value_string (const struct 399GNUNET_CONFIGURATION_get_value_string (
399 GNUNET_CONFIGURATION_Handle *cfg, 400 const struct GNUNET_CONFIGURATION_Handle *cfg,
400 const char *section, 401 const char *section,
401 const char *option, 402 const char *option,
402 char **value); 403 char **value);
403 404
404 405
405/** 406/**
@@ -413,7 +414,7 @@ GNUNET_CONFIGURATION_get_value_string (const struct
413 * value, or NULL if option is not specified 414 * value, or NULL if option is not specified
414 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 415 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
415 */ 416 */
416int 417enum GNUNET_GenericReturnValue
417GNUNET_CONFIGURATION_get_value_filename (const struct 418GNUNET_CONFIGURATION_get_value_filename (const struct
418 GNUNET_CONFIGURATION_Handle *cfg, 419 GNUNET_CONFIGURATION_Handle *cfg,
419 const char *section, 420 const char *section,
@@ -466,7 +467,7 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct
466 * or NULL if option is not specified and no default given 467 * or NULL if option is not specified and no default given
467 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 468 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
468 */ 469 */
469int 470enum GNUNET_GenericReturnValue
470GNUNET_CONFIGURATION_get_value_choice (const struct 471GNUNET_CONFIGURATION_get_value_choice (const struct
471 GNUNET_CONFIGURATION_Handle *cfg, 472 GNUNET_CONFIGURATION_Handle *cfg,
472 const char *section, 473 const char *section,
@@ -483,7 +484,7 @@ GNUNET_CONFIGURATION_get_value_choice (const struct
483 * @param option option of interest 484 * @param option option of interest
484 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR 485 * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR
485 */ 486 */
486int 487enum GNUNET_GenericReturnValue
487GNUNET_CONFIGURATION_get_value_yesno (const struct 488GNUNET_CONFIGURATION_get_value_yesno (const struct
488 GNUNET_CONFIGURATION_Handle *cfg, 489 GNUNET_CONFIGURATION_Handle *cfg,
489 const char *section, 490 const char *section,
@@ -502,7 +503,7 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct
502 * #GNUNET_NO is the value does not exist 503 * #GNUNET_NO is the value does not exist
503 * #GNUNET_SYSERR on decoding error 504 * #GNUNET_SYSERR on decoding error
504 */ 505 */
505int 506enum GNUNET_GenericReturnValue
506GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, 507GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
507 const char *section, 508 const char *section,
508 const char *option, 509 const char *option,
@@ -527,9 +528,9 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
527 * @return $-expanded string 528 * @return $-expanded string
528 */ 529 */
529char * 530char *
530GNUNET_CONFIGURATION_expand_dollar (const struct 531GNUNET_CONFIGURATION_expand_dollar (
531 GNUNET_CONFIGURATION_Handle *cfg, 532 const struct GNUNET_CONFIGURATION_Handle *cfg,
532 char *orig); 533 char *orig);
533 534
534 535
535/** 536/**
@@ -573,7 +574,7 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
573 * @return #GNUNET_OK on success, 574 * @return #GNUNET_OK on success,
574 * #GNUNET_SYSERR if the filename is not in the list 575 * #GNUNET_SYSERR if the filename is not in the list
575 */ 576 */
576int 577enum GNUNET_GenericReturnValue
577GNUNET_CONFIGURATION_remove_value_filename (struct 578GNUNET_CONFIGURATION_remove_value_filename (struct
578 GNUNET_CONFIGURATION_Handle *cfg, 579 GNUNET_CONFIGURATION_Handle *cfg,
579 const char *section, 580 const char *section,
@@ -592,7 +593,7 @@ GNUNET_CONFIGURATION_remove_value_filename (struct
592 * @return #GNUNET_OK on success, 593 * @return #GNUNET_OK on success,
593 * #GNUNET_SYSERR if the filename already in the list 594 * #GNUNET_SYSERR if the filename already in the list
594 */ 595 */
595int 596enum GNUNET_GenericReturnValue
596GNUNET_CONFIGURATION_append_value_filename (struct 597GNUNET_CONFIGURATION_append_value_filename (struct
597 GNUNET_CONFIGURATION_Handle *cfg, 598 GNUNET_CONFIGURATION_Handle *cfg,
598 const char *section, 599 const char *section,
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 6dc56f0e4..5521dad3c 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -1023,7 +1023,7 @@ GNUNET_CRYPTO_hmac_derive_key (
1023 * @param ... pair of void * & size_t for context chunks, terminated by NULL 1023 * @param ... pair of void * & size_t for context chunks, terminated by NULL
1024 * @return #GNUNET_YES on success 1024 * @return #GNUNET_YES on success
1025 */ 1025 */
1026int 1026enum GNUNET_GenericReturnValue
1027GNUNET_CRYPTO_hkdf (void *result, 1027GNUNET_CRYPTO_hkdf (void *result,
1028 size_t out_len, 1028 size_t out_len,
1029 int xtr_algo, 1029 int xtr_algo,
@@ -1049,7 +1049,7 @@ GNUNET_CRYPTO_hkdf (void *result,
1049 * @param argp va_list of void * & size_t pairs for context chunks 1049 * @param argp va_list of void * & size_t pairs for context chunks
1050 * @return #GNUNET_YES on success 1050 * @return #GNUNET_YES on success
1051 */ 1051 */
1052int 1052enum GNUNET_GenericReturnValue
1053GNUNET_CRYPTO_hkdf_v (void *result, 1053GNUNET_CRYPTO_hkdf_v (void *result,
1054 size_t out_len, 1054 size_t out_len,
1055 int xtr_algo, 1055 int xtr_algo,
@@ -1072,7 +1072,7 @@ GNUNET_CRYPTO_hkdf_v (void *result,
1072 * @param argp va_list of void * & size_t pairs for context chunks 1072 * @param argp va_list of void * & size_t pairs for context chunks
1073 * @return #GNUNET_YES on success 1073 * @return #GNUNET_YES on success
1074 */ 1074 */
1075int 1075enum GNUNET_GenericReturnValue
1076GNUNET_CRYPTO_kdf_v (void *result, 1076GNUNET_CRYPTO_kdf_v (void *result,
1077 size_t out_len, 1077 size_t out_len,
1078 const void *xts, 1078 const void *xts,
@@ -1116,7 +1116,7 @@ GNUNET_CRYPTO_kdf_mod_mpi (gcry_mpi_t *r,
1116 * @param ... void * & size_t pairs for context chunks 1116 * @param ... void * & size_t pairs for context chunks
1117 * @return #GNUNET_YES on success 1117 * @return #GNUNET_YES on success
1118 */ 1118 */
1119int 1119enum GNUNET_GenericReturnValue
1120GNUNET_CRYPTO_kdf (void *result, 1120GNUNET_CRYPTO_kdf (void *result,
1121 size_t out_len, 1121 size_t out_len,
1122 const void *xts, 1122 const void *xts,
@@ -1215,7 +1215,7 @@ GNUNET_CRYPTO_eddsa_public_key_to_string (
1215 * @param pub where to store the public key 1215 * @param pub where to store the public key
1216 * @return #GNUNET_OK on success 1216 * @return #GNUNET_OK on success
1217 */ 1217 */
1218int 1218enum GNUNET_GenericReturnValue
1219GNUNET_CRYPTO_ecdsa_public_key_from_string ( 1219GNUNET_CRYPTO_ecdsa_public_key_from_string (
1220 const char *enc, 1220 const char *enc,
1221 size_t enclen, 1221 size_t enclen,
@@ -1245,7 +1245,7 @@ GNUNET_CRYPTO_eddsa_private_key_from_string (
1245 * @param pub where to store the public key 1245 * @param pub where to store the public key
1246 * @return #GNUNET_OK on success 1246 * @return #GNUNET_OK on success
1247 */ 1247 */
1248int 1248enum GNUNET_GenericReturnValue
1249GNUNET_CRYPTO_eddsa_public_key_from_string ( 1249GNUNET_CRYPTO_eddsa_public_key_from_string (
1250 const char *enc, 1250 const char *enc,
1251 size_t enclen, 1251 size_t enclen,
@@ -1267,7 +1267,7 @@ GNUNET_CRYPTO_eddsa_public_key_from_string (
1267 * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but 1267 * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but
1268 * we found an existing file, #GNUNET_SYSERR on failure 1268 * we found an existing file, #GNUNET_SYSERR on failure
1269 */ 1269 */
1270int 1270enum GNUNET_GenericReturnValue
1271GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, 1271GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename,
1272 int do_create, 1272 int do_create,
1273 struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey); 1273 struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey);
@@ -1606,7 +1606,7 @@ GNUNET_CRYPTO_ecc_dlog_release (struct GNUNET_CRYPTO_EccDlogContext *dlc);
1606 * @param key_material where to write the key material (xyG) 1606 * @param key_material where to write the key material (xyG)
1607 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 1607 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1608 */ 1608 */
1609int 1609enum GNUNET_GenericReturnValue
1610GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, 1610GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1611 const struct GNUNET_CRYPTO_EcdhePublicKey *pub, 1611 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1612 struct GNUNET_HashCode *key_material); 1612 struct GNUNET_HashCode *key_material);
@@ -1622,7 +1622,7 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1622 * @param key_material where to write the key material H(h(x)yG) 1622 * @param key_material where to write the key material H(h(x)yG)
1623 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 1623 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1624 */ 1624 */
1625int 1625enum GNUNET_GenericReturnValue
1626GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 1626GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1627 const struct GNUNET_CRYPTO_EcdhePublicKey *pub, 1627 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1628 struct GNUNET_HashCode *key_material); 1628 struct GNUNET_HashCode *key_material);
@@ -1637,7 +1637,7 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1637 * @param key_material where to write the key material H(h(x)yG) 1637 * @param key_material where to write the key material H(h(x)yG)
1638 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 1638 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1639 */ 1639 */
1640int 1640enum GNUNET_GenericReturnValue
1641GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, 1641GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1642 const struct GNUNET_CRYPTO_EcdhePublicKey *pub, 1642 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1643 struct GNUNET_HashCode *key_material); 1643 struct GNUNET_HashCode *key_material);
@@ -1653,7 +1653,7 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1653 * @param key_material where to write the key material H(yX)=H(h(x)yG) 1653 * @param key_material where to write the key material H(yX)=H(h(x)yG)
1654 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 1654 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1655 */ 1655 */
1656int 1656enum GNUNET_GenericReturnValue
1657GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, 1657GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1658 const struct GNUNET_CRYPTO_EddsaPublicKey *pub, 1658 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
1659 struct GNUNET_HashCode *key_material); 1659 struct GNUNET_HashCode *key_material);
@@ -1668,7 +1668,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1668 * @param key_material where to write the key material H(yX)=H(h(x)yG) 1668 * @param key_material where to write the key material H(yX)=H(h(x)yG)
1669 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 1669 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1670 */ 1670 */
1671int 1671enum GNUNET_GenericReturnValue
1672GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, 1672GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1673 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, 1673 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
1674 struct GNUNET_HashCode *key_material); 1674 struct GNUNET_HashCode *key_material);
@@ -1689,7 +1689,7 @@ GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1689 * @param[out] sig where to write the signature 1689 * @param[out] sig where to write the signature
1690 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 1690 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1691 */ 1691 */
1692int 1692enum GNUNET_GenericReturnValue
1693GNUNET_CRYPTO_eddsa_sign_ ( 1693GNUNET_CRYPTO_eddsa_sign_ (
1694 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 1694 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1695 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, 1695 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
@@ -1736,7 +1736,7 @@ GNUNET_CRYPTO_eddsa_sign_ (
1736 * @param[out] sig where to write the signature 1736 * @param[out] sig where to write the signature
1737 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 1737 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1738 */ 1738 */
1739int 1739enum GNUNET_GenericReturnValue
1740GNUNET_CRYPTO_ecdsa_sign_ ( 1740GNUNET_CRYPTO_ecdsa_sign_ (
1741 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, 1741 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1742 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, 1742 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
@@ -2333,7 +2333,7 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig,
2333 * @param public_key public key of the signer 2333 * @param public_key public key of the signer
2334 * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature 2334 * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature
2335 */ 2335 */
2336int 2336enum GNUNET_GenericReturnValue
2337GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, 2337GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash,
2338 const struct GNUNET_CRYPTO_RsaSignature *sig, 2338 const struct GNUNET_CRYPTO_RsaSignature *sig,
2339 const struct GNUNET_CRYPTO_RsaPublicKey *public_key); 2339 const struct GNUNET_CRYPTO_RsaPublicKey *public_key);
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index 3f29dc2e4..e45ab84f4 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -251,7 +251,7 @@ enum GNUNET_DISK_PipeEnd
251 * @param h handle to check 251 * @param h handle to check
252 * @return #GNUNET_YES if invalid, #GNUNET_NO if valid 252 * @return #GNUNET_YES if invalid, #GNUNET_NO if valid
253 */ 253 */
254int 254enum GNUNET_GenericReturnValue
255GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h); 255GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h);
256 256
257 257
@@ -263,7 +263,7 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h);
263 * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something 263 * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something
264 * else (will print an error message in that case, too). 264 * else (will print an error message in that case, too).
265 */ 265 */
266int 266enum GNUNET_GenericReturnValue
267GNUNET_DISK_file_test (const char *fil); 267GNUNET_DISK_file_test (const char *fil);
268 268
269 269
@@ -304,7 +304,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
304 * and return #GNUNET_SYSERR for directories. 304 * and return #GNUNET_SYSERR for directories.
305 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 305 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
306 */ 306 */
307int 307enum GNUNET_GenericReturnValue
308GNUNET_DISK_file_size (const char *filename, 308GNUNET_DISK_file_size (const char *filename,
309 uint64_t *size, 309 uint64_t *size,
310 int include_symbolic_links, 310 int include_symbolic_links,
@@ -326,7 +326,7 @@ GNUNET_DISK_file_size (const char *filename,
326 * @param ino set to the inode ID 326 * @param ino set to the inode ID
327 * @return #GNUNET_OK on success 327 * @return #GNUNET_OK on success
328 */ 328 */
329int 329enum GNUNET_GenericReturnValue
330GNUNET_DISK_file_get_identifiers (const char *filename, 330GNUNET_DISK_file_get_identifiers (const char *filename,
331 uint64_t *dev, 331 uint64_t *dev,
332 uint64_t *ino); 332 uint64_t *ino);
@@ -385,7 +385,7 @@ GNUNET_DISK_file_open (const char *fn,
385 * @param size where to write size of the file 385 * @param size where to write size of the file
386 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 386 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
387 */ 387 */
388int 388enum GNUNET_GenericReturnValue
389GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, 389GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
390 off_t *size); 390 off_t *size);
391 391
@@ -447,7 +447,7 @@ GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf,
447 * @param p pipe 447 * @param p pipe
448 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 448 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
449 */ 449 */
450int 450enum GNUNET_GenericReturnValue
451GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p); 451GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
452 452
453 453
@@ -458,7 +458,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
458 * @param end which end of the pipe to close 458 * @param end which end of the pipe to close
459 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 459 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
460 */ 460 */
461int 461enum GNUNET_GenericReturnValue
462GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, 462GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
463 enum GNUNET_DISK_PipeEnd end); 463 enum GNUNET_DISK_PipeEnd end);
464 464
@@ -485,7 +485,7 @@ GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p,
485 * @param h file handle 485 * @param h file handle
486 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 486 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
487 */ 487 */
488int 488enum GNUNET_GenericReturnValue
489GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h); 489GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h);
490 490
491 491
@@ -609,19 +609,22 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
609 609
610 610
611/** 611/**
612 * Write a buffer to a file. If the file is longer than 612 * Write a buffer to a file atomically. The directory is created if
613 * the given buffer size, it will be truncated. 613 * necessary. Fail if @a filename already exists or if not exactly @a buf
614 * with @a buf_size bytes could be written to @a filename.
614 * 615 *
615 * @param fn file name 616 * @param fn file name
616 * @param buffer the data to write 617 * @param buf the data to write
617 * @param n number of bytes to write 618 * @param buf_size number of bytes to write from @a buf
618 * @param mode file permissions 619 * @param mode file permissions
619 * @return number of bytes written on success, #GNUNET_SYSERR on error 620 * @return #GNUNET_OK on success,
621 * #GNUNET_NO if a file existed under @a filename
622 * #GNUNET_SYSERR on failure
620 */ 623 */
621ssize_t 624enum GNUNET_GenericReturnValue
622GNUNET_DISK_fn_write (const char *fn, 625GNUNET_DISK_fn_write (const char *fn,
623 const void *buffer, 626 const void *buf,
624 size_t n, 627 size_t buf_size,
625 enum GNUNET_DISK_AccessPermissions mode); 628 enum GNUNET_DISK_AccessPermissions mode);
626 629
627 630
@@ -632,7 +635,7 @@ GNUNET_DISK_fn_write (const char *fn,
632 * @param dst destination file name 635 * @param dst destination file name
633 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 636 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
634 */ 637 */
635int 638enum GNUNET_GenericReturnValue
636GNUNET_DISK_file_copy (const char *src, 639GNUNET_DISK_file_copy (const char *src,
637 const char *dst); 640 const char *dst);
638 641
@@ -659,7 +662,7 @@ GNUNET_DISK_directory_scan (const char *dir_name,
659 * @returns #GNUNET_OK on success, #GNUNET_SYSERR on failure, 662 * @returns #GNUNET_OK on success, #GNUNET_SYSERR on failure,
660 * #GNUNET_NO if directory exists but is not writeable 663 * #GNUNET_NO if directory exists but is not writeable
661 */ 664 */
662int 665enum GNUNET_GenericReturnValue
663GNUNET_DISK_directory_create_for_file (const char *filename); 666GNUNET_DISK_directory_create_for_file (const char *filename);
664 667
665 668
@@ -675,8 +678,9 @@ GNUNET_DISK_directory_create_for_file (const char *filename);
675 * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it 678 * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it
676 * does not exist or `stat`ed 679 * does not exist or `stat`ed
677 */ 680 */
678int 681enum GNUNET_GenericReturnValue
679GNUNET_DISK_directory_test (const char *fil, int is_readable); 682GNUNET_DISK_directory_test (const char *fil,
683 int is_readable);
680 684
681 685
682/** 686/**
@@ -685,7 +689,7 @@ GNUNET_DISK_directory_test (const char *fil, int is_readable);
685 * @param filename the file to remove 689 * @param filename the file to remove
686 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 690 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
687 */ 691 */
688int 692enum GNUNET_GenericReturnValue
689GNUNET_DISK_directory_remove (const char *filename); 693GNUNET_DISK_directory_remove (const char *filename);
690 694
691 695
@@ -707,7 +711,7 @@ GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
707 * @param dir the directory to create 711 * @param dir the directory to create
708 * @returns #GNUNET_SYSERR on failure, #GNUNET_OK otherwise 712 * @returns #GNUNET_SYSERR on failure, #GNUNET_OK otherwise
709 */ 713 */
710int 714enum GNUNET_GenericReturnValue
711GNUNET_DISK_directory_create (const char *dir); 715GNUNET_DISK_directory_create (const char *dir);
712 716
713 717
@@ -725,7 +729,7 @@ GNUNET_DISK_filename_canonicalize (char *fn);
725 * @param user new owner of the file 729 * @param user new owner of the file
726 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 730 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
727 */ 731 */
728int 732enum GNUNET_GenericReturnValue
729GNUNET_DISK_file_change_owner (const char *filename, 733GNUNET_DISK_file_change_owner (const char *filename,
730 const char *user); 734 const char *user);
731 735
@@ -758,7 +762,7 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
758 * @param h mapping handle 762 * @param h mapping handle
759 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 763 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
760 */ 764 */
761int 765enum GNUNET_GenericReturnValue
762GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h); 766GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h);
763 767
764 768
@@ -768,7 +772,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h);
768 * @param h handle to an open file 772 * @param h handle to an open file
769 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 773 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
770 */ 774 */
771int 775enum GNUNET_GenericReturnValue
772GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h); 776GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h);
773 777
774 778
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index b828e2db7..158f1d83b 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -497,13 +497,11 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task);
497 * @param priority priority to use for the task 497 * @param priority priority to use for the task
498 */ 498 */
499void 499void
500GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback 500GNUNET_SCHEDULER_add_with_reason_and_priority (
501 task, 501 GNUNET_SCHEDULER_TaskCallback task,
502 void *task_cls, 502 void *task_cls,
503 enum GNUNET_SCHEDULER_Reason 503 enum GNUNET_SCHEDULER_Reason reason,
504 reason, 504 enum GNUNET_SCHEDULER_Priority priority);
505 enum GNUNET_SCHEDULER_Priority
506 priority);
507 505
508 506
509/** 507/**
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index dfd71e57a..8e9cd0c9d 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -824,19 +824,26 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey,
824 * Write our current proof to disk. 824 * Write our current proof to disk.
825 */ 825 */
826static void 826static void
827write_proof () 827write_proof (void)
828{ 828{
829 char *proof; 829 char *proof;
830 830
831 if (GNUNET_OK != 831 if (GNUNET_OK !=
832 GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) 832 GNUNET_CONFIGURATION_get_value_filename (cfg,
833 "NSE",
834 "PROOFFILE",
835 &proof))
833 return; 836 return;
834 if (sizeof(my_proof) != GNUNET_DISK_fn_write (proof, 837 (void) GNUNET_DISK_directory_remove (proof);
835 &my_proof, 838 if (GNUNET_OK !=
836 sizeof(my_proof), 839 GNUNET_DISK_fn_write (proof,
837 GNUNET_DISK_PERM_USER_READ 840 &my_proof,
838 | GNUNET_DISK_PERM_USER_WRITE)) 841 sizeof(my_proof),
839 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); 842 GNUNET_DISK_PERM_USER_READ
843 | GNUNET_DISK_PERM_USER_WRITE))
844 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
845 "write",
846 proof);
840 GNUNET_free (proof); 847 GNUNET_free (proof);
841} 848}
842 849
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index 987c7c3a0..8b149c98e 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -451,13 +451,14 @@ dump_my_hello ()
451 fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO"); 451 fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO");
452 return; 452 return;
453 } 453 }
454 if (GNUNET_SYSERR == GNUNET_DISK_fn_write (dump_hello, 454 if (GNUNET_SYSERR ==
455 my_hello, 455 GNUNET_DISK_fn_write (dump_hello,
456 size, 456 my_hello,
457 GNUNET_DISK_PERM_USER_READ 457 size,
458 | GNUNET_DISK_PERM_USER_WRITE 458 GNUNET_DISK_PERM_USER_READ
459 | GNUNET_DISK_PERM_GROUP_READ 459 | GNUNET_DISK_PERM_USER_WRITE
460 | GNUNET_DISK_PERM_OTHER_READ)) 460 | GNUNET_DISK_PERM_GROUP_READ
461 | GNUNET_DISK_PERM_OTHER_READ))
461 { 462 {
462 fprintf (stderr, 463 fprintf (stderr,
463 _ ("Failed to write HELLO with %u bytes to file `%s'\n"), 464 _ ("Failed to write HELLO with %u bytes to file `%s'\n"),
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 79af90dd4..1b1232ecb 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -807,13 +807,14 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
807 } 807 }
808 GNUNET_assert (pos == size); 808 GNUNET_assert (pos == size);
809 809
810 if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, 810 if (GNUNET_SYSERR ==
811 buffer, 811 GNUNET_DISK_fn_write (fn,
812 size, 812 buffer,
813 GNUNET_DISK_PERM_USER_READ 813 size,
814 | GNUNET_DISK_PERM_USER_WRITE 814 GNUNET_DISK_PERM_USER_READ
815 | GNUNET_DISK_PERM_GROUP_READ 815 | GNUNET_DISK_PERM_USER_WRITE
816 | GNUNET_DISK_PERM_OTHER_READ)) 816 | GNUNET_DISK_PERM_GROUP_READ
817 | GNUNET_DISK_PERM_OTHER_READ))
817 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); 818 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
818 else 819 else
819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -987,13 +988,15 @@ discard_hosts_helper (void *cls, const char *fn)
987 988
988 if (0 < write_pos) 989 if (0 < write_pos)
989 { 990 {
990 GNUNET_DISK_fn_write (fn, 991 (void) GNUNET_DISK_directory_remove (fn);
991 writebuffer, 992 GNUNET_assert (GNUNET_OK ==
992 write_pos, 993 GNUNET_DISK_fn_write (fn,
993 GNUNET_DISK_PERM_USER_READ 994 writebuffer,
994 | GNUNET_DISK_PERM_USER_WRITE 995 write_pos,
995 | GNUNET_DISK_PERM_GROUP_READ 996 GNUNET_DISK_PERM_USER_READ
996 | GNUNET_DISK_PERM_OTHER_READ); 997 | GNUNET_DISK_PERM_USER_WRITE
998 | GNUNET_DISK_PERM_GROUP_READ
999 | GNUNET_DISK_PERM_OTHER_READ));
997 } 1000 }
998 else if (0 != unlink (fn)) 1001 else if (0 != unlink (fn))
999 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING 1002 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c
index 22230cf5c..fd73cf0d8 100644
--- a/src/pq/pq_connect.c
+++ b/src/pq/pq_connect.c
@@ -190,7 +190,7 @@ apply_patch (struct GNUNET_PQ_Context *db,
190 if ( (GNUNET_OS_PROCESS_EXITED != type) || 190 if ( (GNUNET_OS_PROCESS_EXITED != type) ||
191 (0 != code) ) 191 (0 != code) )
192 { 192 {
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 193 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
194 "Could not run PSQL on file %s: %d\n", 194 "Could not run PSQL on file %s: %d\n",
195 buf, 195 buf,
196 (int) code); 196 (int) code);
@@ -419,7 +419,7 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db)
419 GNUNET_PQ_run_sql (db, 419 GNUNET_PQ_run_sql (db,
420 db->load_path)) 420 db->load_path))
421 { 421 {
422 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 422 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
423 "Failed to load SQL statements from `%s*'\n", 423 "Failed to load SQL statements from `%s*'\n",
424 db->load_path); 424 db->load_path);
425 PQfinish (db->conn); 425 PQfinish (db->conn);
diff --git a/src/reclaim/oidc_helper.c b/src/reclaim/oidc_helper.c
index 40cc5751e..a90d02d68 100644
--- a/src/reclaim/oidc_helper.c
+++ b/src/reclaim/oidc_helper.c
@@ -694,7 +694,7 @@ OIDC_parse_authz_code (const struct GNUNET_IDENTITY_PublicKey *audience,
694 // cmp code_challenge code_verifier 694 // cmp code_challenge code_verifier
695 code_challenge_len = ntohl (params->code_challenge_len); 695 code_challenge_len = ntohl (params->code_challenge_len);
696 code_challenge = ((char *) &params[1]); 696 code_challenge = ((char *) &params[1]);
697 if (!(opts & OIDC_VERIFICATION_NO_CODE_VERIFIER)) 697 if (! (opts & OIDC_VERIFICATION_NO_CODE_VERIFIER))
698 { 698 {
699 if (GNUNET_OK != check_code_challenge (code_challenge, 699 if (GNUNET_OK != check_code_challenge (code_challenge,
700 code_challenge_len, 700 code_challenge_len,
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index d59ea7c81..b5737158b 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -230,7 +230,7 @@ sync_pow ()
230{ 230{
231 size_t psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); 231 size_t psize = GNUNET_REVOCATION_proof_get_size (proof_of_work);
232 if ((NULL != filename) && 232 if ((NULL != filename) &&
233 (psize != 233 (GNUNET_OK !=
234 GNUNET_DISK_fn_write (filename, 234 GNUNET_DISK_fn_write (filename,
235 proof_of_work, 235 proof_of_work,
236 psize, 236 psize,
@@ -280,14 +280,17 @@ calculate_pow (void *cls)
280 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) 280 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph))
281 { 281 {
282 psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); 282 psize = GNUNET_REVOCATION_proof_get_size (proof_of_work);
283 if ((NULL != filename) && 283 if (NULL != filename)
284 (psize != 284 {
285 GNUNET_DISK_fn_write (filename, 285 (void) GNUNET_DISK_directory_remove (filename);
286 proof_of_work, 286 if (GNUNET_OK !=
287 psize, 287 GNUNET_DISK_fn_write (filename,
288 GNUNET_DISK_PERM_USER_READ 288 proof_of_work,
289 | GNUNET_DISK_PERM_USER_WRITE))) 289 psize,
290 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); 290 GNUNET_DISK_PERM_USER_READ
291 | GNUNET_DISK_PERM_USER_WRITE))
292 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
293 }
291 if (perform) 294 if (perform)
292 { 295 {
293 perform_revocation (); 296 perform_revocation ();
diff --git a/src/testbed/gnunet_mpi_test.c b/src/testbed/gnunet_mpi_test.c
index e0caf9676..2ee707fe6 100644
--- a/src/testbed/gnunet_mpi_test.c
+++ b/src/testbed/gnunet_mpi_test.c
@@ -49,7 +49,8 @@ main (int argc, char *argv[])
49 (void) GNUNET_asprintf (&filename, "%d-%d.mpiout", (int) pid, rank); 49 (void) GNUNET_asprintf (&filename, "%d-%d.mpiout", (int) pid, rank);
50 msg_size = GNUNET_asprintf (&msg, "My rank is: %d\n", rank); 50 msg_size = GNUNET_asprintf (&msg, "My rank is: %d\n", rank);
51 printf ("%s", msg); 51 printf ("%s", msg);
52 if (msg_size == 52 (void) GNUNET_DISK_directory_remove (filename);
53 if (GNUNET_OK ==
53 GNUNET_DISK_fn_write (filename, msg, msg_size, 54 GNUNET_DISK_fn_write (filename, msg, msg_size,
54 GNUNET_DISK_PERM_USER_READ 55 GNUNET_DISK_PERM_USER_READ
55 | GNUNET_DISK_PERM_GROUP_READ 56 | GNUNET_DISK_PERM_GROUP_READ
diff --git a/src/topology/friends.c b/src/topology/friends.c
index a3b15d8f7..65c7e81d7 100644
--- a/src/topology/friends.c
+++ b/src/topology/friends.c
@@ -59,15 +59,6 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
59 "FRIENDS"); 59 "FRIENDS");
60 return GNUNET_SYSERR; 60 return GNUNET_SYSERR;
61 } 61 }
62 if (GNUNET_SYSERR ==
63 GNUNET_DISK_directory_create_for_file (fn))
64 {
65 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
66 "mkdir",
67 fn);
68 GNUNET_free (fn);
69 return GNUNET_SYSERR;
70 }
71 if ((GNUNET_OK != 62 if ((GNUNET_OK !=
72 GNUNET_DISK_file_test (fn)) && 63 GNUNET_DISK_file_test (fn)) &&
73 (GNUNET_OK != 64 (GNUNET_OK !=
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 800a27aa2..0f9d40e13 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -813,42 +813,48 @@ test_communicator_basic_unix_SOURCES = \
813test_communicator_basic_unix_LDADD = \ 813test_communicator_basic_unix_LDADD = \
814 libgnunettransporttesting2.la \ 814 libgnunettransporttesting2.la \
815 $(top_builddir)/src/testing/libgnunettesting.la \ 815 $(top_builddir)/src/testing/libgnunettesting.la \
816 $(top_builddir)/src/util/libgnunetutil.la 816 $(top_builddir)/src/util/libgnunetutil.la \
817 $(top_builddir)/src/statistics/libgnunetstatistics.la
817 818
818test_communicator_basic_tcp_SOURCES = \ 819test_communicator_basic_tcp_SOURCES = \
819 test_communicator_basic.c 820 test_communicator_basic.c
820test_communicator_basic_tcp_LDADD = \ 821test_communicator_basic_tcp_LDADD = \
821 libgnunettransporttesting2.la \ 822 libgnunettransporttesting2.la \
822 $(top_builddir)/src/testing/libgnunettesting.la \ 823 $(top_builddir)/src/testing/libgnunettesting.la \
823 $(top_builddir)/src/util/libgnunetutil.la 824 $(top_builddir)/src/util/libgnunetutil.la \
825 $(top_builddir)/src/statistics/libgnunetstatistics.la
824 826
825test_communicator_basic_udp_SOURCES = \ 827test_communicator_basic_udp_SOURCES = \
826 test_communicator_basic.c 828 test_communicator_basic.c
827test_communicator_basic_udp_LDADD = \ 829test_communicator_basic_udp_LDADD = \
828 libgnunettransporttesting2.la \ 830 libgnunettransporttesting2.la \
829 $(top_builddir)/src/testing/libgnunettesting.la \ 831 $(top_builddir)/src/testing/libgnunettesting.la \
830 $(top_builddir)/src/util/libgnunetutil.la 832 $(top_builddir)/src/util/libgnunetutil.la \
833 $(top_builddir)/src/statistics/libgnunetstatistics.la
831 834
832test_communicator_rekey_tcp_SOURCES = \ 835test_communicator_rekey_tcp_SOURCES = \
833 test_communicator_basic.c 836 test_communicator_basic.c
834test_communicator_rekey_tcp_LDADD = \ 837test_communicator_rekey_tcp_LDADD = \
835 libgnunettransporttesting2.la \ 838 libgnunettransporttesting2.la \
836 $(top_builddir)/src/testing/libgnunettesting.la \ 839 $(top_builddir)/src/testing/libgnunettesting.la \
837 $(top_builddir)/src/util/libgnunetutil.la 840 $(top_builddir)/src/util/libgnunetutil.la \
841 $(top_builddir)/src/statistics/libgnunetstatistics.la
838 842
839test_communicator_rekey_udp_SOURCES = \ 843test_communicator_rekey_udp_SOURCES = \
840 test_communicator_basic.c 844 test_communicator_basic.c
841test_communicator_rekey_udp_LDADD = \ 845test_communicator_rekey_udp_LDADD = \
842 libgnunettransporttesting2.la \ 846 libgnunettransporttesting2.la \
843 $(top_builddir)/src/testing/libgnunettesting.la \ 847 $(top_builddir)/src/testing/libgnunettesting.la \
844 $(top_builddir)/src/util/libgnunetutil.la 848 $(top_builddir)/src/util/libgnunetutil.la \
849 $(top_builddir)/src/statistics/libgnunetstatistics.la
845 850
846test_communicator_backchannel_udp_SOURCES = \ 851test_communicator_backchannel_udp_SOURCES = \
847 test_communicator_basic.c 852 test_communicator_basic.c
848test_communicator_backchannel_udp_LDADD = \ 853test_communicator_backchannel_udp_LDADD = \
849 libgnunettransporttesting2.la \ 854 libgnunettransporttesting2.la \
850 $(top_builddir)/src/testing/libgnunettesting.la \ 855 $(top_builddir)/src/testing/libgnunettesting.la \
851 $(top_builddir)/src/util/libgnunetutil.la 856 $(top_builddir)/src/util/libgnunetutil.la \
857 $(top_builddir)/src/statistics/libgnunetstatistics.la
852endif 858endif
853 859
854test_plugin_unix_SOURCES = \ 860test_plugin_unix_SOURCES = \
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 073b1ea02..018da8f0e 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -137,10 +137,10 @@
137#define MAX_SECRETS 128000 137#define MAX_SECRETS 128000
138 138
139/** 139/**
140 * How often do we rekey based on number of bytes transmitted? 140 * Default value for how often we do rekey based on number of bytes transmitted?
141 * (additionally randomized). 141 * (additionally randomized).
142 */ 142 */
143#define REKEY_MAX_BYTES (1024LLU * 1024 * 1024 * 4LLU) 143#define DEFAULT_REKEY_MAX_BYTES (1024LLU * 1024 * 1024 * 4LLU)
144 144
145/** 145/**
146 * Address prefix used by the communicator. 146 * Address prefix used by the communicator.
@@ -510,6 +510,11 @@ struct SharedSecret
510struct SenderAddress 510struct SenderAddress
511{ 511{
512 /** 512 /**
513 * Shared secret we use with @e target for rekeying.
514 */
515 struct SharedSecret *ss_rekey;
516
517 /**
513 * Flag indicating sender is initiated rekeying for this receiver. 518 * Flag indicating sender is initiated rekeying for this receiver.
514 */ 519 */
515 int rekeying; 520 int rekeying;
@@ -760,6 +765,10 @@ struct BroadcastInterface
760static struct GNUNET_TIME_Relative rekey_interval; 765static struct GNUNET_TIME_Relative rekey_interval;
761 766
762/** 767/**
768 * How often we do rekey based on number of bytes transmitted
769 */
770static unsigned long long rekey_max_bytes;
771/**
763 * Shared secret we finished the last kce working queue for. 772 * Shared secret we finished the last kce working queue for.
764 */ 773 */
765struct SharedSecret *ss_finished; 774struct SharedSecret *ss_finished;
@@ -1056,14 +1065,14 @@ secret_destroy (struct SharedSecret *ss, int withoutKce)
1056 struct ReceiverAddress *receiver; 1065 struct ReceiverAddress *receiver;
1057 struct KeyCacheEntry *kce; 1066 struct KeyCacheEntry *kce;
1058 1067
1059 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1060 "secret destroy %u %u\n",
1061 withoutKce,
1062 ss->sequence_allowed);
1063
1064 if (withoutKce && (ss->sequence_allowed > 0)) 1068 if (withoutKce && (ss->sequence_allowed > 0))
1065 return GNUNET_NO; 1069 return GNUNET_NO;
1066 1070
1071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1072 "secret %s destroy %u %u\n",
1073 GNUNET_h2s (&ss->master),
1074 withoutKce,
1075 ss->sequence_allowed);
1067 if (NULL != (sender = ss->sender)) 1076 if (NULL != (sender = ss->sender))
1068 { 1077 {
1069 GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss); 1078 GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss);
@@ -1075,6 +1084,9 @@ secret_destroy (struct SharedSecret *ss, int withoutKce)
1075 receiver->num_secrets--; 1084 receiver->num_secrets--;
1076 // Uncomment this for alternativ 1 of backchannel functionality 1085 // Uncomment this for alternativ 1 of backchannel functionality
1077 receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used); 1086 receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
1087 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1088 "%u receiver->acks_available 3\n",
1089 receiver->acks_available);
1078 // Until here for alternativ 1 1090 // Until here for alternativ 1
1079 } 1091 }
1080 while (NULL != (kce = ss->kce_head)) 1092 while (NULL != (kce = ss->kce_head))
@@ -1194,15 +1206,15 @@ check_timeouts (void *cls)
1194 rt = GNUNET_TIME_UNIT_FOREVER_REL; 1206 rt = GNUNET_TIME_UNIT_FOREVER_REL;
1195 while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap))) 1207 while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap)))
1196 { 1208 {
1197 if (GNUNET_YES != receiver->receiver_destroy_called) 1209 /* if (GNUNET_YES != receiver->receiver_destroy_called) */
1198 { 1210 /* { */
1199 rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout); 1211 rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout);
1200 if (0 != rt.rel_value_us) 1212 if (0 != rt.rel_value_us)
1201 break; 1213 break;
1202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1203 "Receiver timed out\n"); 1215 "Receiver timed out\n");
1204 receiver_destroy (receiver); 1216 receiver_destroy (receiver);
1205 } 1217 // }
1206 } 1218 }
1207 st = GNUNET_TIME_UNIT_FOREVER_REL; 1219 st = GNUNET_TIME_UNIT_FOREVER_REL;
1208 while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap))) 1220 while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
@@ -1433,7 +1445,8 @@ destroy_all_secrets (struct SharedSecret *ss, int withoutKce)
1433 int at_least_one_destroyed = GNUNET_NO; 1445 int at_least_one_destroyed = GNUNET_NO;
1434 1446
1435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1436 "Starting destroy all.\n"); 1448 "Starting destroy all withoutKce: %u.\n",
1449 withoutKce);
1437 1450
1438 if (NULL != (sender = ss->sender)) 1451 if (NULL != (sender = ss->sender))
1439 { 1452 {
@@ -1451,7 +1464,7 @@ destroy_all_secrets (struct SharedSecret *ss, int withoutKce)
1451 } 1464 }
1452 1465
1453 pos = ss_start; 1466 pos = ss_start;
1454 while ( NULL != pos) 1467 while (NULL != pos)
1455 { 1468 {
1456 ss_to_destroy = pos; 1469 ss_to_destroy = pos;
1457 pos = pos->next; 1470 pos = pos->next;
@@ -1462,6 +1475,8 @@ destroy_all_secrets (struct SharedSecret *ss, int withoutKce)
1462 1475
1463 if ((ss != ss_start) && ! at_least_one_destroyed) 1476 if ((ss != ss_start) && ! at_least_one_destroyed)
1464 { 1477 {
1478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1479 "Really destroying all.\n");
1465 destroy_all_secrets (ss_start, GNUNET_NO); 1480 destroy_all_secrets (ss_start, GNUNET_NO);
1466 } 1481 }
1467 1482
@@ -1469,8 +1484,9 @@ destroy_all_secrets (struct SharedSecret *ss, int withoutKce)
1469 "Finished destroy all.\n"); 1484 "Finished destroy all.\n");
1470} 1485}
1471 1486
1487
1472static void 1488static void
1473add_acks (struct SharedSecret *ss, int acks_to_add, int remove_from_receiver) 1489add_acks (struct SharedSecret *ss, int acks_to_add)
1474{ 1490{
1475 1491
1476 struct ReceiverAddress *receiver = ss->receiver; 1492 struct ReceiverAddress *receiver = ss->receiver;
@@ -1489,6 +1505,9 @@ add_acks (struct SharedSecret *ss, int acks_to_add, int remove_from_receiver)
1489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1490 "Tell transport we have %u more acks!\n", 1506 "Tell transport we have %u more acks!\n",
1491 acks_to_add); 1507 acks_to_add);
1508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1509 "%u kce for rekeying.\n",
1510 receiver->number_rekeying_kce);
1492 GNUNET_TRANSPORT_communicator_mq_update (ch, 1511 GNUNET_TRANSPORT_communicator_mq_update (ch,
1493 receiver->d_qh, 1512 receiver->d_qh,
1494 acks_to_add, 1513 acks_to_add,
@@ -1496,35 +1515,70 @@ add_acks (struct SharedSecret *ss, int acks_to_add, int remove_from_receiver)
1496 // Until here for alternativ 1 1515 // Until here for alternativ 1
1497 1516
1498 /* move ss to head to avoid discarding it anytime soon! */ 1517 /* move ss to head to avoid discarding it anytime soon! */
1499 if (remove_from_receiver) 1518
1500 GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); 1519 GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1501 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss); 1520 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1502 destroy_all_secrets (ss, GNUNET_YES); 1521 destroy_all_secrets (ss, GNUNET_YES);
1522}
1503 1523
1504 1524
1505 // Uncomment this for alternativ 2 of backchannel functionality 1525static uint32_t
1506 /*if (receiver->acks_available != ack->acks_available) 1526reset_rekey_kces (struct ReceiverAddress *receiver,
1527 uint32_t acks_to_add)
1528{
1529 int needed_for_rekeying;
1530
1531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1532 "%u kce for rekeying and %u acks_to_add\n",
1533 receiver->number_rekeying_kce,
1534 acks_to_add);
1535
1536 needed_for_rekeying = (3 - receiver->number_rekeying_kce);
1537 if (acks_to_add <= needed_for_rekeying)
1507 { 1538 {
1508 receiver->acks_available = ack->acks_available; 1539 receiver->number_rekeying_kce += acks_to_add;
1509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1540 acks_to_add = 0;
1510 "Tell transport we have different number of acks!\n"); 1541 }
1511 GNUNET_TRANSPORT_communicator_mq_update (ch, 1542 else
1512 receiver->d_qh, 1543 {
1513 receiver->acks_available, 1544 acks_to_add -= (3 - receiver->number_rekeying_kce);
1514 1); 1545 receiver->number_rekeying_kce = 3;
1515 }*/ 1546 }
1516 // Until here for alternativ 2 1547
1548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1549 "%u kce for rekeying and %u acks_to_add\n",
1550 receiver->number_rekeying_kce,
1551 acks_to_add);
1552 return acks_to_add;
1517} 1553}
1518 1554
1555
1519static void 1556static void
1520add_acks_rekey (struct ReceiverAddress *receiver) 1557add_acks_rekey (struct ReceiverAddress *receiver)
1521{ 1558{
1522 add_acks (receiver->ss_rekey, receiver->ss_rekey->sequence_allowed - 3, 1559 uint32_t acks_to_add = receiver->ss_rekey->sequence_allowed;
1523 GNUNET_NO); 1560
1561 if (receiver->number_rekeying_kce < 3)
1562 acks_to_add = reset_rekey_kces (receiver, acks_to_add);
1524 receiver->acks_available = receiver->ss_rekey->sequence_allowed; 1563 receiver->acks_available = receiver->ss_rekey->sequence_allowed;
1564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1565 "%u receiver->acks_available 4\n",
1566 receiver->acks_available);
1567 /* add_acks (receiver->ss_rekey, acks_to_add - 3); */
1568 if (0 != acks_to_add)
1569 {
1570 add_acks (receiver->ss_rekey, acks_to_add);
1571 }
1525 receiver->ss_rekey = NULL; 1572 receiver->ss_rekey = NULL;
1573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1574 "# rekeying successful\n");
1575 GNUNET_STATISTICS_update (stats,
1576 "# rekeying successful",
1577 1,
1578 GNUNET_NO);
1526} 1579}
1527 1580
1581
1528/** 1582/**
1529 * We received an ACK for @a pid. Check if it is for 1583 * We received an ACK for @a pid. Check if it is for
1530 * the receiver in @a value and if so, handle it and 1584 * the receiver in @a value and if so, handle it and
@@ -1540,15 +1594,17 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
1540{ 1594{
1541 const struct UDPAck *ack = cls; 1595 const struct UDPAck *ack = cls;
1542 struct ReceiverAddress *receiver = value; 1596 struct ReceiverAddress *receiver = value;
1543 int acks_to_add; 1597 uint32_t acks_to_add;
1544 uint32_t allowed; 1598 uint32_t allowed;
1599 // int needed_for_rekeying;
1545 1600
1546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1547 "in handle ack\n"); 1602 "in handle ack with cmac %s\n",
1603 GNUNET_h2s (&ack->cmac));
1548 1604
1549 if (NULL != receiver->ss_rekey) 1605 if (NULL != receiver->ss_rekey)
1550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1551 "Received secret with cmac %s \n", 1607 "We have rekey secret with cmac %s \n",
1552 GNUNET_h2s (&receiver->ss_rekey->cmac)); 1608 GNUNET_h2s (&receiver->ss_rekey->cmac));
1553 1609
1554 if ((NULL != receiver->ss_rekey) && (0 == memcmp (&ack->cmac, 1610 if ((NULL != receiver->ss_rekey) && (0 == memcmp (&ack->cmac,
@@ -1598,16 +1654,37 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
1598 // Uncomment this for alternativ 1 of backchannel functionality 1654 // Uncomment this for alternativ 1 of backchannel functionality
1599 acks_to_add = (allowed - ss->sequence_allowed); 1655 acks_to_add = (allowed - ss->sequence_allowed);
1600 if ((GNUNET_NO == receiver->rekeying) && 1656 if ((GNUNET_NO == receiver->rekeying) &&
1601 (receiver->number_rekeying_kce < 1657 (receiver->number_rekeying_kce < 3) )
1602 3) ) 1658 acks_to_add = reset_rekey_kces (receiver, acks_to_add);
1659 /* if ((GNUNET_NO == receiver->rekeying) && */
1660 /* (receiver->number_rekeying_kce < */
1661 /* 3) ) */
1662 /* { */
1663 /* needed_for_rekeying = (3 - receiver->number_rekeying_kce); */
1664 /* if (acks_to_add <= needed_for_rekeying) */
1665 /* { */
1666 /* receiver->number_rekeying_kce += acks_to_add; */
1667 /* acks_to_add = 0; */
1668 /* } */
1669 /* else */
1670 /* { */
1671 /* acks_to_add -= (3 - receiver->number_rekeying_kce); */
1672 /* receiver->number_rekeying_kce = 3; */
1673 /* } */
1674 /* } */
1675 /* GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, */
1676 /* "%u kce for rekeying\n", */
1677 /* receiver->number_rekeying_kce); */
1678
1679 if ((0 != acks_to_add) && (GNUNET_NO == receiver->rekeying))
1603 { 1680 {
1604 acks_to_add -= (3 - receiver->number_rekeying_kce); 1681 receiver->acks_available += (allowed - ss->sequence_allowed);
1605 receiver->number_rekeying_kce = 3; 1682 ss->sequence_allowed = allowed;
1683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1684 "%u receiver->acks_available 5\n",
1685 receiver->acks_available);
1686 add_acks (ss, acks_to_add);
1606 } 1687 }
1607 receiver->acks_available += (allowed - ss->sequence_allowed);
1608 ss->sequence_allowed = allowed;
1609
1610 add_acks (ss, acks_to_add, GNUNET_YES);
1611 } 1688 }
1612 return GNUNET_NO; 1689 return GNUNET_NO;
1613 } 1690 }
@@ -1663,18 +1740,21 @@ try_handle_plaintext (struct SenderAddress *sender,
1663} 1740}
1664 1741
1665 1742
1666
1667static void 1743static void
1668kce_generate_cb (void *cls) 1744kce_generate_cb (void *cls)
1669{ 1745{
1670 struct SharedSecret *ss = cls; 1746 struct SharedSecret *ss = cls;
1671 kce_task = NULL; 1747 kce_task = NULL;
1672 1748
1673 if (ss->sender->acks_available < KCN_TARGET) 1749 if (((GNUNET_NO == ss->sender->rekeying) && (ss->sender->acks_available <
1750 KCN_TARGET) ) ||
1751 ((ss->sender->ss_rekey == ss) && (GNUNET_YES == ss->sender->rekeying) &&
1752 (ss->sender->acks_available < 128)))
1674 { 1753 {
1675 1754
1676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1677 "Precomputing keys\n"); 1756 "Precomputing keys for master %s\n",
1757 GNUNET_h2s (&(ss->master)));
1678 1758
1679 for (int i = 0; i < GENERATE_AT_ONCE; i++) 1759 for (int i = 0; i < GENERATE_AT_ONCE; i++)
1680 kce_generate (ss, ++ss->sequence_allowed); 1760 kce_generate (ss, ++ss->sequence_allowed);
@@ -1694,6 +1774,7 @@ kce_generate_cb (void *cls)
1694 1774
1695} 1775}
1696 1776
1777
1697static void 1778static void
1698kce_generate_rekey_cb (void *cls) 1779kce_generate_rekey_cb (void *cls)
1699{ 1780{
@@ -1702,6 +1783,11 @@ kce_generate_rekey_cb (void *cls)
1702 1783
1703 if (NULL == kce_task) 1784 if (NULL == kce_task)
1704 { 1785 {
1786
1787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1788 "Precomputing keys for rekey master %s\n",
1789 GNUNET_h2s (&(ss->master)));
1790
1705 for (int i = 0; i < GENERATE_AT_ONCE; i++) 1791 for (int i = 0; i < GENERATE_AT_ONCE; i++)
1706 kce_generate (ss, ++ss->sequence_allowed); 1792 kce_generate (ss, ++ss->sequence_allowed);
1707 1793
@@ -1760,25 +1846,36 @@ consider_ss_ack (struct SharedSecret *ss, int initial)
1760 if (((NULL != kce_task) && kce_task_finished) || (GNUNET_NO == initial)) 1846 if (((NULL != kce_task) && kce_task_finished) || (GNUNET_NO == initial))
1761 { 1847 {
1762 struct UDPAck ack; 1848 struct UDPAck ack;
1849 struct SharedSecret *ss_tell;
1850
1851 if (GNUNET_NO != initial)
1852 ss_tell = ss_finished;
1853 else
1854 ss_tell = ss;
1763 1855
1764 ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); 1856 ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK);
1765 ack.header.size = htons (sizeof(ack)); 1857 ack.header.size = htons (sizeof(ack));
1766 ack.sequence_max = htonl (ss_finished->sequence_allowed); 1858 ack.sequence_max = htonl (ss_tell->sequence_allowed);
1767 ack.acks_available = ss->sender->acks_available; 1859 ack.acks_available = ss->sender->acks_available;
1768 ack.cmac = ss_finished->cmac; 1860 ack.cmac = ss_tell->cmac;
1769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1770 "Notifying transport of UDPAck %s with intial %u\n", 1862 "Notifying transport of UDPAck %s with intial %u and master %s\n",
1771 GNUNET_i2s_full (&ss_finished->sender->target), 1863 GNUNET_i2s_full (&ss_tell->sender->target),
1772 initial); 1864 initial,
1865 GNUNET_h2s (&(ss_tell->master)));
1773 GNUNET_TRANSPORT_communicator_notify (ch, 1866 GNUNET_TRANSPORT_communicator_notify (ch,
1774 &ss_finished->sender->target, 1867 &ss_tell->sender->target,
1775 COMMUNICATOR_ADDRESS_PREFIX, 1868 COMMUNICATOR_ADDRESS_PREFIX,
1776 &ack.header); 1869 &ack.header);
1777 destroy_all_secrets (ss, GNUNET_YES); 1870 if (GNUNET_NO != initial)
1778 kce_task = NULL; 1871 {
1779 kce_task_finished = GNUNET_NO; 1872 destroy_all_secrets (ss, GNUNET_YES);
1873 kce_task = NULL;
1874 kce_task_finished = GNUNET_NO;
1875 }
1780 } 1876 }
1781 else if ((NULL == kce_task) && ((KCN_THRESHOLD > ss->sender->acks_available)|| 1877 else if ((NULL == kce_task) && ((KCN_THRESHOLD >
1878 ss->sender->acks_available) ||
1782 (GNUNET_YES == ss->sender->rekeying) || 1879 (GNUNET_YES == ss->sender->rekeying) ||
1783 (ss->sender->num_secrets > MAX_SECRETS) )) 1880 (ss->sender->num_secrets > MAX_SECRETS) ))
1784 { 1881 {
@@ -1835,6 +1932,10 @@ decrypt_box (const struct UDPBox *box,
1835 "# bytes decrypted with BOX", 1932 "# bytes decrypted with BOX",
1836 sizeof(out_buf), 1933 sizeof(out_buf),
1837 GNUNET_NO); 1934 GNUNET_NO);
1935 GNUNET_STATISTICS_update (stats,
1936 "# messages decrypted with BOX",
1937 1,
1938 GNUNET_NO);
1838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1839 "decrypted UDPBox with kid %s\n", 1940 "decrypted UDPBox with kid %s\n",
1840 GNUNET_sh2s (&box->kid)); 1941 GNUNET_sh2s (&box->kid));
@@ -1842,19 +1943,22 @@ decrypt_box (const struct UDPBox *box,
1842 if ((GNUNET_NO == box->rekeying) && (GNUNET_YES == ss->sender->rekeying)) 1943 if ((GNUNET_NO == box->rekeying) && (GNUNET_YES == ss->sender->rekeying))
1843 { 1944 {
1844 ss->sender->rekeying = GNUNET_NO; 1945 ss->sender->rekeying = GNUNET_NO;
1946 ss->sender->ss_rekey = NULL;
1845 // destroy_all_secrets (ss, GNUNET_NO); 1947 // destroy_all_secrets (ss, GNUNET_NO);
1846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1847 "Receiver stopped rekeying.\n"); 1949 "Receiver stopped rekeying.\n");
1848 } 1950 }
1849 else if (GNUNET_NO == box->rekeying) 1951 else if (GNUNET_NO == box->rekeying)
1850 consider_ss_ack (ss, GNUNET_YES); 1952 consider_ss_ack (ss, GNUNET_NO);
1851 else{ 1953 else
1954 {
1852 ss->sender->rekeying = GNUNET_YES; 1955 ss->sender->rekeying = GNUNET_YES;
1853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1956 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1854 "Receiver started rekeying.\n"); 1957 "Got Box: Receiver doing rekeying.\n");
1855 } 1958 }
1856} 1959}
1857 1960
1961
1858/** 1962/**
1859 * We received a @a rekey with matching @a kce. Decrypt and process it. 1963 * We received a @a rekey with matching @a kce. Decrypt and process it.
1860 * 1964 *
@@ -1921,6 +2025,7 @@ decrypt_rekey (const struct UDPRekey *rekey,
1921 /* GNUNET_assert (ss_rekey->prev == NULL && sender->ss_head != ss_rekey); */ 2025 /* GNUNET_assert (ss_rekey->prev == NULL && sender->ss_head != ss_rekey); */
1922 /* GNUNET_assert (ss_rekey->next == NULL && sender->ss_tail != ss_rekey); */ 2026 /* GNUNET_assert (ss_rekey->next == NULL && sender->ss_tail != ss_rekey); */
1923 GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss_rekey); 2027 GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss_rekey);
2028 sender->ss_rekey = ss_rekey;
1924 sender->num_secrets++; 2029 sender->num_secrets++;
1925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1926 "Received secret with cmac %s\n", 2031 "Received secret with cmac %s\n",
@@ -1941,6 +2046,7 @@ decrypt_rekey (const struct UDPRekey *rekey,
1941 2046
1942} 2047}
1943 2048
2049
1944/** 2050/**
1945 * Closure for #find_sender_by_address() 2051 * Closure for #find_sender_by_address()
1946 */ 2052 */
@@ -2151,20 +2257,26 @@ sock_read (void *cls)
2151 box = (const struct UDPBox *) buf; 2257 box = (const struct UDPBox *) buf;
2152 kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &rekey->kid); 2258 kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &rekey->kid);
2153 2259
2154 if ((GNUNET_YES == box->rekeying)||(GNUNET_NO == box->rekeying)) 2260 if ((GNUNET_YES == box->rekeying) || (GNUNET_NO == box->rekeying))
2155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2156 "UDPRekey has rekeying %u\n", 2262 "UDPRekey has rekeying %u\n",
2157 box->rekeying); 2263 box->rekeying);
2158 else 2264 else
2159 do_decrypt = GNUNET_YES; 2265 do_decrypt = GNUNET_YES;
2160 if ((GNUNET_YES == do_decrypt)&& (NULL != kce) && (GNUNET_YES == 2266
2161 kce->ss->sender->rekeying)) 2267 if ((GNUNET_YES == do_decrypt) && (NULL != kce) && (GNUNET_YES ==
2268 kce->ss->sender->
2269 rekeying))
2162 { 2270 {
2163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2164 "UDPRekey with kid %s\n", 2272 "UDPRekey with kid %s\n",
2165 GNUNET_sh2s (&rekey->kid)); 2273 GNUNET_sh2s (&rekey->kid));
2166 sender = setup_sender (&rekey->sender, (const struct sockaddr *) &sa, 2274 sender = setup_sender (&rekey->sender, (const struct sockaddr *) &sa,
2167 salen); 2275 salen);
2276
2277 if (NULL != sender->ss_rekey)
2278 return;
2279
2168 decrypt_rekey (rekey, (size_t) rcvd, kce, sender); 2280 decrypt_rekey (rekey, (size_t) rcvd, kce, sender);
2169 return; 2281 return;
2170 } 2282 }
@@ -2290,16 +2402,18 @@ sock_read (void *cls)
2290 if ((GNUNET_NO == kx->rekeying) && (GNUNET_YES == ss->sender->rekeying)) 2402 if ((GNUNET_NO == kx->rekeying) && (GNUNET_YES == ss->sender->rekeying))
2291 { 2403 {
2292 ss->sender->rekeying = GNUNET_NO; 2404 ss->sender->rekeying = GNUNET_NO;
2405 sender->ss_rekey = NULL;
2293 // destroy_all_secrets (ss, GNUNET_NO); 2406 // destroy_all_secrets (ss, GNUNET_NO);
2294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2295 "Receiver stopped rekeying.\n"); 2408 "Receiver stopped rekeying.\n");
2296 } 2409 }
2297 else if (GNUNET_NO == kx->rekeying) 2410 else if (GNUNET_NO == kx->rekeying)
2298 consider_ss_ack (ss, GNUNET_YES); 2411 consider_ss_ack (ss, GNUNET_YES);
2299 else{ 2412 else
2413 {
2300 ss->sender->rekeying = GNUNET_YES; 2414 ss->sender->rekeying = GNUNET_YES;
2301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2302 "Receiver started rekeying.\n"); 2416 "Got KX: Receiver doing rekeying.\n");
2303 } 2417 }
2304 /*if (sender->num_secrets > MAX_SECRETS) 2418 /*if (sender->num_secrets > MAX_SECRETS)
2305 secret_destroy (sender->ss_tail);*/ 2419 secret_destroy (sender->ss_tail);*/
@@ -2560,6 +2674,7 @@ mq_send_kx (struct GNUNET_MQ_Handle *mq,
2560 GNUNET_MQ_impl_send_continue (mq); 2674 GNUNET_MQ_impl_send_continue (mq);
2561} 2675}
2562 2676
2677
2563static void 2678static void
2564check_for_rekeying (struct ReceiverAddress *receiver, struct UDPBox *box) 2679check_for_rekeying (struct ReceiverAddress *receiver, struct UDPBox *box)
2565{ 2680{
@@ -2583,13 +2698,13 @@ check_for_rekeying (struct ReceiverAddress *receiver, struct UDPBox *box)
2583 rt.rel_value_us, 2698 rt.rel_value_us,
2584 receiver->rekey_timeout.abs_value_us); 2699 receiver->rekey_timeout.abs_value_us);
2585 2700
2586 if ((0 == rt.rel_value_us)||(receiver->rekey_send_bytes > 2701 if ((0 == rt.rel_value_us) || (receiver->rekey_send_bytes >
2587 REKEY_MAX_BYTES) ) 2702 rekey_max_bytes) )
2588 { 2703 {
2589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2590 "Bytes send %lu greater than %llu max bytes\n.", 2705 "Bytes send %lu greater than %llu max bytes\n.",
2591 receiver->rekey_send_bytes, 2706 receiver->rekey_send_bytes,
2592 REKEY_MAX_BYTES); 2707 rekey_max_bytes);
2593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2594 "Relative time is %lu and timeout is %lu\n.", 2709 "Relative time is %lu and timeout is %lu\n.",
2595 rt.rel_value_us, 2710 rt.rel_value_us,
@@ -2612,6 +2727,7 @@ check_for_rekeying (struct ReceiverAddress *receiver, struct UDPBox *box)
2612 } 2727 }
2613} 2728}
2614 2729
2730
2615static void 2731static void
2616send_UDPRekey (struct ReceiverAddress *receiver, struct SharedSecret *ss) 2732send_UDPRekey (struct ReceiverAddress *receiver, struct SharedSecret *ss)
2617{ 2733{
@@ -2631,9 +2747,14 @@ send_UDPRekey (struct ReceiverAddress *receiver, struct SharedSecret *ss)
2631 - (receiver->rekey_acks_available % 3)) / 3; 2747 - (receiver->rekey_acks_available % 3)) / 3;
2632 is_ss_rekey_sequence_allowed_zero = (0 == 2748 is_ss_rekey_sequence_allowed_zero = (0 ==
2633 receiver->ss_rekey->sequence_allowed); 2749 receiver->ss_rekey->sequence_allowed);
2634 is_acks_available_below = (receiver->acks_available > not_below); 2750 is_acks_available_below = (receiver->acks_available >= not_below);
2635 send_rekey = (0 == (receiver->acks_available - not_below) % not_below) && 2751 send_rekey = (0 == (receiver->acks_available - not_below) % not_below) &&
2636 is_acks_available_below && is_ss_rekey_sequence_allowed_zero; 2752 is_acks_available_below && is_ss_rekey_sequence_allowed_zero;
2753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2754 "send_rekey: %u, %u, %u\n",
2755 send_rekey,
2756 receiver->rekey_acks_available,
2757 receiver->acks_available);
2637 } 2758 }
2638 else if (NULL == receiver->ss_rekey) 2759 else if (NULL == receiver->ss_rekey)
2639 { 2760 {
@@ -2641,6 +2762,7 @@ send_UDPRekey (struct ReceiverAddress *receiver, struct SharedSecret *ss)
2641 GNUNET_CRYPTO_ecdhe_key_create (&epriv); 2762 GNUNET_CRYPTO_ecdhe_key_create (&epriv);
2642 receiver->ss_rekey = setup_shared_secret_enc (&epriv, receiver, 2763 receiver->ss_rekey = setup_shared_secret_enc (&epriv, receiver,
2643 GNUNET_NO); 2764 GNUNET_NO);
2765 receiver->ss_rekey->sequence_allowed = 0;
2644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2645 "Setup secret with cmac %s\n", 2767 "Setup secret with cmac %s\n",
2646 GNUNET_h2s (&(receiver->ss_rekey->cmac))); 2768 GNUNET_h2s (&(receiver->ss_rekey->cmac)));
@@ -2700,6 +2822,9 @@ send_UDPRekey (struct ReceiverAddress *receiver, struct SharedSecret *ss)
2700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2701 "Sending rekey with cmac %s\n", 2823 "Sending rekey with cmac %s\n",
2702 GNUNET_h2s (&(receiver->ss_rekey->cmac))); 2824 GNUNET_h2s (&(receiver->ss_rekey->cmac)));
2825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2826 "%u rekey kces left.\n",
2827 receiver->number_rekeying_kce);
2703 2828
2704 if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, 2829 if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
2705 rekey_dgram, 2830 rekey_dgram,
@@ -2708,6 +2833,10 @@ send_UDPRekey (struct ReceiverAddress *receiver, struct SharedSecret *ss)
2708 receiver->address_len)) 2833 receiver->address_len))
2709 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 2834 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
2710 2835
2836 receiver->acks_available--;
2837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2838 "%u receiver->acks_available 1\n",
2839 receiver->acks_available);
2711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2712 "Sending UDPRekey to %s\n", GNUNET_a2s (receiver->address, 2841 "Sending UDPRekey to %s\n", GNUNET_a2s (receiver->address,
2713 receiver-> 2842 receiver->
@@ -2737,6 +2866,12 @@ mq_send_d (struct GNUNET_MQ_Handle *mq,
2737 if ((msize > receiver->d_mtu) || 2866 if ((msize > receiver->d_mtu) ||
2738 (0 == receiver->acks_available)) 2867 (0 == receiver->acks_available))
2739 { 2868 {
2869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2870 "msize: %u, mtu: %lu, acks: %u\n",
2871 msize,
2872 receiver->d_mtu,
2873 receiver->acks_available);
2874
2740 GNUNET_break (0); 2875 GNUNET_break (0);
2741 if (GNUNET_YES != receiver->receiver_destroy_called) 2876 if (GNUNET_YES != receiver->receiver_destroy_called)
2742 receiver_destroy (receiver); 2877 receiver_destroy (receiver);
@@ -2789,8 +2924,6 @@ mq_send_d (struct GNUNET_MQ_Handle *mq,
2789 else 2924 else
2790 box->rekeying = GNUNET_YES; 2925 box->rekeying = GNUNET_YES;
2791 2926
2792 check_for_rekeying (receiver, box);
2793
2794 if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, 2927 if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
2795 dgram, 2928 dgram,
2796 sizeof(dgram), 2929 sizeof(dgram),
@@ -2798,11 +2931,15 @@ mq_send_d (struct GNUNET_MQ_Handle *mq,
2798 receiver->address_len)) 2931 receiver->address_len))
2799 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 2932 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
2800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2801 "Sending UDPBox to %s\n", GNUNET_a2s (receiver->address, 2934 "Sending UDPBox %u acks left\n",
2802 receiver->address_len)); 2935 receiver->acks_available);
2803 GNUNET_MQ_impl_send_continue (mq); 2936 GNUNET_MQ_impl_send_continue (mq);
2804 receiver->acks_available--; 2937 receiver->acks_available--;
2805 if (0 == receiver->acks_available) 2938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2939 "%u receiver->acks_available 2\n",
2940 receiver->acks_available);
2941 check_for_rekeying (receiver, box);
2942 if (0 == receiver->acks_available - receiver->number_rekeying_kce)
2806 { 2943 {
2807 /* We have no more ACKs */ 2944 /* We have no more ACKs */
2808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2810,6 +2947,8 @@ mq_send_d (struct GNUNET_MQ_Handle *mq,
2810 if (GNUNET_YES == receiver->rekeying) 2947 if (GNUNET_YES == receiver->rekeying)
2811 { 2948 {
2812 receiver->rekeying = GNUNET_NO; 2949 receiver->rekeying = GNUNET_NO;
2950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2951 "Sender stopped rekeying\n");
2813 2952
2814 if ((NULL != receiver->ss_rekey) && (0 < 2953 if ((NULL != receiver->ss_rekey) && (0 <
2815 receiver->ss_rekey-> 2954 receiver->ss_rekey->
@@ -3120,6 +3259,8 @@ get_sender_delete_it (void *cls,
3120static void 3259static void
3121do_shutdown (void *cls) 3260do_shutdown (void *cls)
3122{ 3261{
3262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3263 "do_shutdown\n");
3123 if (NULL != nat) 3264 if (NULL != nat)
3124 { 3265 {
3125 GNUNET_NAT_unregister (nat); 3266 GNUNET_NAT_unregister (nat);
@@ -3154,18 +3295,26 @@ do_shutdown (void *cls)
3154 } 3295 }
3155 if (NULL != udp_sock) 3296 if (NULL != udp_sock)
3156 { 3297 {
3157 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (udp_sock)); 3298 GNUNET_break (GNUNET_OK ==
3299 GNUNET_NETWORK_socket_close (udp_sock));
3158 udp_sock = NULL; 3300 udp_sock = NULL;
3159 } 3301 }
3160 GNUNET_CONTAINER_multipeermap_iterate (receivers, 3302 GNUNET_CONTAINER_multipeermap_iterate (receivers,
3161 &get_receiver_delete_it, 3303 &get_receiver_delete_it,
3162 NULL); 3304 NULL);
3163 GNUNET_CONTAINER_multipeermap_destroy (receivers); 3305 GNUNET_CONTAINER_multipeermap_destroy (receivers);
3164 GNUNET_CONTAINER_multipeermap_iterate (senders, &get_sender_delete_it, NULL); 3306 GNUNET_CONTAINER_multipeermap_iterate (senders,
3307 &get_sender_delete_it,
3308 NULL);
3165 GNUNET_CONTAINER_multipeermap_destroy (senders); 3309 GNUNET_CONTAINER_multipeermap_destroy (senders);
3166 GNUNET_CONTAINER_multishortmap_destroy (key_cache); 3310 GNUNET_CONTAINER_multishortmap_destroy (key_cache);
3167 GNUNET_CONTAINER_heap_destroy (senders_heap); 3311 GNUNET_CONTAINER_heap_destroy (senders_heap);
3168 GNUNET_CONTAINER_heap_destroy (receivers_heap); 3312 GNUNET_CONTAINER_heap_destroy (receivers_heap);
3313 if (NULL != timeout_task)
3314 {
3315 GNUNET_SCHEDULER_cancel (timeout_task);
3316 timeout_task = NULL;
3317 }
3169 if (NULL != ch) 3318 if (NULL != ch)
3170 { 3319 {
3171 GNUNET_TRANSPORT_communicator_disconnect (ch); 3320 GNUNET_TRANSPORT_communicator_disconnect (ch);
@@ -3191,6 +3340,8 @@ do_shutdown (void *cls)
3191 GNUNET_NT_scanner_done (is); 3340 GNUNET_NT_scanner_done (is);
3192 is = NULL; 3341 is = NULL;
3193 } 3342 }
3343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3344 "do_shutdown finished\n");
3194} 3345}
3195 3346
3196 3347
@@ -3302,25 +3453,29 @@ ifc_broadcast (void *cls)
3302 static int no = 0; 3453 static int no = 0;
3303 ssize_t sent; 3454 ssize_t sent;
3304 3455
3305 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, 3456 if (GNUNET_OK !=
3306 SOL_SOCKET, 3457 GNUNET_NETWORK_socket_setsockopt (udp_sock,
3307 SO_BROADCAST, 3458 SOL_SOCKET,
3308 &yes, 3459 SO_BROADCAST,
3309 sizeof(int))) 3460 &yes,
3310 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 3461 sizeof(int)))
3462 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
3463 "setsockopt");
3311 sent = GNUNET_NETWORK_socket_sendto (udp_sock, 3464 sent = GNUNET_NETWORK_socket_sendto (udp_sock,
3312 &bi->bcm, 3465 &bi->bcm,
3313 sizeof(bi->bcm), 3466 sizeof(bi->bcm),
3314 bi->ba, 3467 bi->ba,
3315 bi->salen); 3468 bi->salen);
3316 if (-1 == sent) 3469 if (-1 == sent)
3317 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); 3470 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
3471 "sendto");
3318 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, 3472 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock,
3319 SOL_SOCKET, 3473 SOL_SOCKET,
3320 SO_BROADCAST, 3474 SO_BROADCAST,
3321 &no, 3475 &no,
3322 sizeof(int))) 3476 sizeof(int)))
3323 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 3477 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
3478 "setsockopt");
3324 break; 3479 break;
3325 } 3480 }
3326 3481
@@ -3402,9 +3557,18 @@ iface_proc (void *cls,
3402 return GNUNET_OK; /* not using IPv6 */ 3557 return GNUNET_OK; /* not using IPv6 */
3403 3558
3404 bi = GNUNET_new (struct BroadcastInterface); 3559 bi = GNUNET_new (struct BroadcastInterface);
3405 bi->sa = GNUNET_memdup (addr, addrlen); 3560 bi->sa = GNUNET_memdup (addr,
3406 if (NULL != broadcast_addr) 3561 addrlen);
3407 bi->ba = GNUNET_memdup (broadcast_addr, addrlen); 3562 if ( (NULL != broadcast_addr) &&
3563 (addrlen == sizeof (struct sockaddr_in)) )
3564 {
3565 struct sockaddr_in *ba;
3566
3567 ba = GNUNET_memdup (broadcast_addr,
3568 addrlen);
3569 ba->sin_port = htons (2086); /* always GNUnet port, ignore configuration! */
3570 bi->ba = (struct sockaddr *) ba;
3571 }
3408 bi->salen = addrlen; 3572 bi->salen = addrlen;
3409 bi->found = GNUNET_YES; 3573 bi->found = GNUNET_YES;
3410 bi->bcm.sender = my_identity; 3574 bi->bcm.sender = my_identity;
@@ -3415,7 +3579,7 @@ iface_proc (void *cls,
3415 GNUNET_CRYPTO_eddsa_sign (my_private_key, 3579 GNUNET_CRYPTO_eddsa_sign (my_private_key,
3416 &ubs, 3580 &ubs,
3417 &bi->bcm.sender_sig); 3581 &bi->bcm.sender_sig);
3418 if (NULL != broadcast_addr) 3582 if (NULL != bi->ba)
3419 { 3583 {
3420 bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, bi); 3584 bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, bi);
3421 GNUNET_CONTAINER_DLL_insert (bi_head, bi_tail, bi); 3585 GNUNET_CONTAINER_DLL_insert (bi_head, bi_tail, bi);
@@ -3522,6 +3686,13 @@ run (void *cls,
3522 &rekey_interval)) 3686 &rekey_interval))
3523 rekey_interval = DEFAULT_REKEY_TIME_INTERVAL; 3687 rekey_interval = DEFAULT_REKEY_TIME_INTERVAL;
3524 3688
3689 if (GNUNET_OK !=
3690 GNUNET_CONFIGURATION_get_value_size (cfg,
3691 COMMUNICATOR_CONFIG_SECTION,
3692 "REKEY_MAX_BYTES",
3693 &rekey_max_bytes))
3694 rekey_max_bytes = DEFAULT_REKEY_MAX_BYTES;
3695
3525 in = udp_address_to_sockaddr (bindto, &in_len); 3696 in = udp_address_to_sockaddr (bindto, &in_len);
3526 if (NULL == in) 3697 if (NULL == in)
3527 { 3698 {
@@ -3532,7 +3703,9 @@ run (void *cls,
3532 return; 3703 return;
3533 } 3704 }
3534 udp_sock = 3705 udp_sock =
3535 GNUNET_NETWORK_socket_create (in->sa_family, SOCK_DGRAM, IPPROTO_UDP); 3706 GNUNET_NETWORK_socket_create (in->sa_family,
3707 SOCK_DGRAM,
3708 IPPROTO_UDP);
3536 if (NULL == udp_sock) 3709 if (NULL == udp_sock)
3537 { 3710 {
3538 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 3711 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
@@ -3542,9 +3715,14 @@ run (void *cls,
3542 } 3715 }
3543 if (AF_INET6 == in->sa_family) 3716 if (AF_INET6 == in->sa_family)
3544 have_v6_socket = GNUNET_YES; 3717 have_v6_socket = GNUNET_YES;
3545 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (udp_sock, in, in_len)) 3718 if (GNUNET_OK !=
3719 GNUNET_NETWORK_socket_bind (udp_sock,
3720 in,
3721 in_len))
3546 { 3722 {
3547 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto); 3723 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
3724 "bind",
3725 bindto);
3548 GNUNET_NETWORK_socket_close (udp_sock); 3726 GNUNET_NETWORK_socket_close (udp_sock);
3549 udp_sock = NULL; 3727 udp_sock = NULL;
3550 GNUNET_free (in); 3728 GNUNET_free (in);
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c
index 7ea04afdb..ea1a7b1fb 100644
--- a/src/transport/test_communicator_basic.c
+++ b/src/transport/test_communicator_basic.c
@@ -73,6 +73,10 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *my_tc;
73 73
74static char *test_name; 74static char *test_name;
75 75
76static struct GNUNET_STATISTICS_GetHandle *box_stats;
77
78static struct GNUNET_STATISTICS_GetHandle *rekey_stats;
79
76#define SHORT_MESSAGE_SIZE 128 80#define SHORT_MESSAGE_SIZE 128
77 81
78#define LONG_MESSAGE_SIZE 32000 /* FIXME */ 82#define LONG_MESSAGE_SIZE 32000 /* FIXME */
@@ -90,7 +94,7 @@ static unsigned int iterations_left = TOTAL_ITERATIONS;
90#define TIMEOUT_MULTIPLIER 1 94#define TIMEOUT_MULTIPLIER 1
91 95
92#define DELAY \ 96#define DELAY \
93 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,50) 97 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,200)
94 98
95#define SHORT_BURST_WINDOW \ 99#define SHORT_BURST_WINDOW \
96 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) 100 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2)
@@ -129,12 +133,12 @@ static struct GNUNET_TIME_Relative duration;
129 133
130 134
131static void 135static void
132communicator_available_cb (void *cls, 136communicator_available_cb (
133 struct 137 void *cls,
134 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 138 struct
135 *tc_h, 139 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
136 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, 140 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
137 char *address_prefix) 141 char *address_prefix)
138{ 142{
139 LOG (GNUNET_ERROR_TYPE_INFO, 143 LOG (GNUNET_ERROR_TYPE_INFO,
140 "Communicator available. (cc: %u, prefix: %s)\n", 144 "Communicator available. (cc: %u, prefix: %s)\n",
@@ -142,10 +146,11 @@ communicator_available_cb (void *cls,
142 address_prefix); 146 address_prefix);
143} 147}
144 148
149
145static void 150static void
146open_queue (void *cls) 151open_queue (void *cls)
147{ 152{
148 char *address = cls; 153 const char *address = cls;
149 154
150 if (NULL != tc_hs[PEER_A]->c_mq) 155 if (NULL != tc_hs[PEER_A]->c_mq)
151 { 156 {
@@ -158,30 +163,32 @@ open_queue (void *cls)
158 { 163 {
159 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 164 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
160 &open_queue, 165 &open_queue,
161 address); 166 (void *) address);
162 } 167 }
163} 168}
164 169
170
165static void 171static void
166add_address_cb (void *cls, 172add_address_cb (
167 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 173 void *cls,
168 tc_h, 174 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
169 const char *address, 175 const char *address,
170 struct GNUNET_TIME_Relative expiration, 176 struct GNUNET_TIME_Relative expiration,
171 uint32_t aid, 177 uint32_t aid,
172 enum GNUNET_NetworkType nt) 178 enum GNUNET_NetworkType nt)
173{ 179{
174 LOG (GNUNET_ERROR_TYPE_DEBUG, 180 LOG (GNUNET_ERROR_TYPE_DEBUG,
175 "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n", 181 "New address. (addr: %s, expir: %s, ID: %" PRIu32 ", nt: %u\n",
176 address, 182 address,
177 expiration.rel_value_us, 183 GNUNET_STRINGS_relative_time_to_string (expiration,
184 GNUNET_NO),
178 aid, 185 aid,
179 nt); 186 (int) nt);
180 // addresses[1] = GNUNET_strdup (address); 187 // addresses[1] = GNUNET_strdup (address);
181 if ((0 == strcmp ((char*) cls, cfg_peers_name[PEER_B])) && 188 if ((0 == strcmp ((char*) cls, cfg_peers_name[PEER_B])) &&
182 (GNUNET_NO == queue_est)) 189 (GNUNET_NO == queue_est))
183 { 190 {
184 open_queue (address); 191 open_queue ((void *) address);
185 } 192 }
186} 193}
187 194
@@ -198,12 +205,13 @@ add_address_cb (void *cls,
198 * #GNUNET_NO if queue will not be established (bogous address) 205 * #GNUNET_NO if queue will not be established (bogous address)
199 */ 206 */
200static void 207static void
201queue_create_reply_cb (void *cls, 208queue_create_reply_cb (
202 struct 209 void *cls,
203 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 210 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
204 tc_h, 211 int will_try)
205 int will_try)
206{ 212{
213 (void) cls;
214 (void) tc_h;
207 if (GNUNET_YES == will_try) 215 if (GNUNET_YES == will_try)
208 LOG (GNUNET_ERROR_TYPE_DEBUG, 216 LOG (GNUNET_ERROR_TYPE_DEBUG,
209 "Queue will be established!\n"); 217 "Queue will be established!\n");
@@ -219,6 +227,9 @@ handle_backchannel_cb (void *cls,
219 struct GNUNET_PeerIdentity *pid) 227 struct GNUNET_PeerIdentity *pid)
220{ 228{
221 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 229 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
230
231 (void) tc_h;
232 (void) msg;
222 LOG (GNUNET_ERROR_TYPE_DEBUG, "Handling BC message...\n"); 233 LOG (GNUNET_ERROR_TYPE_DEBUG, "Handling BC message...\n");
223 if (0 == memcmp (&peer_id[PEER_A], pid, sizeof (*pid))) 234 if (0 == memcmp (&peer_id[PEER_A], pid, sizeof (*pid)))
224 return tc_hs[PEER_A]; 235 return tc_hs[PEER_A];
@@ -260,9 +271,11 @@ latency_timeout (void *cls)
260 NULL); 271 NULL);
261 return; 272 return;
262 } 273 }
263
264 switch (phase) 274 switch (phase)
265 { 275 {
276 case TP_INIT:
277 GNUNET_assert (0);
278 break;
266 case TP_BURST_SHORT: 279 case TP_BURST_SHORT:
267 num_sent = num_sent_short; 280 num_sent = num_sent_short;
268 num_received = num_received_short; 281 num_received = num_received_short;
@@ -283,6 +296,7 @@ latency_timeout (void *cls)
283 GNUNET_SCHEDULER_shutdown (); 296 GNUNET_SCHEDULER_shutdown ();
284} 297}
285 298
299
286/*static void 300/*static void
287 size_test (void *cls);*/ 301 size_test (void *cls);*/
288 302
@@ -294,7 +308,7 @@ size_test (void *cls)
294 308
295 LOG (GNUNET_ERROR_TYPE_DEBUG, 309 LOG (GNUNET_ERROR_TYPE_DEBUG,
296 "size_test_cb %u\n", 310 "size_test_cb %u\n",
297 num_sent_size); 311 (unsigned int) num_sent_size);
298 GNUNET_assert (TP_SIZE_CHECK == phase); 312 GNUNET_assert (TP_SIZE_CHECK == phase);
299 if (LONG_MESSAGE_SIZE != long_message_size) 313 if (LONG_MESSAGE_SIZE != long_message_size)
300 max_size = long_message_size; 314 max_size = long_message_size;
@@ -316,13 +330,6 @@ size_test (void *cls)
316 TIMEOUT_MULTIPLIER)); 330 TIMEOUT_MULTIPLIER));
317} 331}
318 332
319/*static void
320size_test (void *cls)
321{
322 GNUNET_SCHEDULER_add_delayed (DELAY,
323 &size_test_cb,
324 NULL);
325 }*/
326 333
327static void 334static void
328long_test (void *cls); 335long_test (void *cls);
@@ -334,27 +341,27 @@ long_test_cb (void *cls)
334 341
335 LOG (GNUNET_ERROR_TYPE_DEBUG, 342 LOG (GNUNET_ERROR_TYPE_DEBUG,
336 "long_test_cb %u/%u\n", 343 "long_test_cb %u/%u\n",
337 num_sent_long, 344 (unsigned int) num_sent_long,
338 num_received_long); 345 (unsigned int) num_received_long);
339 payload = make_payload (long_message_size); 346 payload = make_payload (long_message_size);
340 num_sent_long++; 347 num_sent_long++;
341 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, 348 GNUNET_TRANSPORT_TESTING_transport_communicator_send (
342 ((BURST_PACKETS 349 my_tc,
343 * 0.91 == 350 ((BURST_PACKETS * 0.91 == num_received_long) ||
344 num_received_long) || 351 (BURST_PACKETS == num_sent_long))
345 (BURST_PACKETS == 352 ? NULL
346 num_sent_long)) 353 : &long_test,
347 ? NULL 354 NULL,
348 : &long_test, 355 payload,
349 NULL, 356 long_message_size);
350 payload,
351 long_message_size);
352 GNUNET_free (payload); 357 GNUNET_free (payload);
353 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( 358 timeout = GNUNET_TIME_relative_to_absolute (
354 GNUNET_TIME_UNIT_SECONDS, 359 GNUNET_TIME_relative_multiply (
355 TIMEOUT_MULTIPLIER)); 360 GNUNET_TIME_UNIT_SECONDS,
361 TIMEOUT_MULTIPLIER));
356} 362}
357 363
364
358static void 365static void
359long_test (void *cls) 366long_test (void *cls)
360{ 367{
@@ -366,9 +373,11 @@ long_test (void *cls)
366 NULL); 373 NULL);
367} 374}
368 375
376
369static void 377static void
370short_test (void *cls); 378short_test (void *cls);
371 379
380
372static void 381static void
373short_test_cb (void *cls) 382short_test_cb (void *cls)
374{ 383{
@@ -376,27 +385,26 @@ short_test_cb (void *cls)
376 385
377 LOG (GNUNET_ERROR_TYPE_DEBUG, 386 LOG (GNUNET_ERROR_TYPE_DEBUG,
378 "short_test_cb %u/%u\n", 387 "short_test_cb %u/%u\n",
379 num_sent_short, 388 (unsigned int) num_sent_short,
380 num_received_short); 389 (unsigned int) num_received_short);
381 payload = make_payload (SHORT_MESSAGE_SIZE); 390 payload = make_payload (SHORT_MESSAGE_SIZE);
382 num_sent_short++; 391 num_sent_short++;
383 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, 392 GNUNET_TRANSPORT_TESTING_transport_communicator_send (
384 ((BURST_PACKETS 393 my_tc,
385 * 0.91 == 394 ( (BURST_PACKETS * 0.91 == num_received_short) ||
386 num_received_short) || 395 (BURST_PACKETS == num_sent_short) )
387 (BURST_PACKETS == 396 ? NULL
388 num_sent_short)) 397 : &short_test,
389 ? NULL 398 NULL,
390 : &short_test, 399 payload,
391 NULL, 400 SHORT_MESSAGE_SIZE);
392 payload,
393 SHORT_MESSAGE_SIZE);
394 GNUNET_free (payload); 401 GNUNET_free (payload);
395 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( 402 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (
396 GNUNET_TIME_UNIT_SECONDS, 403 GNUNET_TIME_UNIT_SECONDS,
397 TIMEOUT_MULTIPLIER)); 404 TIMEOUT_MULTIPLIER));
398} 405}
399 406
407
400static void 408static void
401short_test (void *cls) 409short_test (void *cls)
402{ 410{
@@ -492,10 +500,14 @@ update_avg_latency (const char*payload)
492 ts = GNUNET_TIME_absolute_ntoh (*ts_n); 500 ts = GNUNET_TIME_absolute_ntoh (*ts_n);
493 latency = GNUNET_TIME_absolute_get_duration (ts); 501 latency = GNUNET_TIME_absolute_get_duration (ts);
494 LOG (GNUNET_ERROR_TYPE_DEBUG, 502 LOG (GNUNET_ERROR_TYPE_DEBUG,
495 "Latency of received packet: %u\n", 503 "Latency of received packet: %s\n",
496 latency); 504 GNUNET_STRINGS_relative_time_to_string (latency,
505 GNUNET_YES));
497 switch (phase) 506 switch (phase)
498 { 507 {
508 case TP_INIT:
509 GNUNET_assert (0);
510 break;
499 case TP_BURST_SHORT: 511 case TP_BURST_SHORT:
500 num_received = num_received_short; 512 num_received = num_received_short;
501 break; 513 break;
@@ -514,6 +526,35 @@ update_avg_latency (const char*payload)
514 526
515} 527}
516 528
529
530static void
531process_statistics_box_done (void *cls, int success)
532{
533 if (NULL != box_stats)
534 box_stats = NULL;
535 if (NULL == rekey_stats)
536 {
537 LOG (GNUNET_ERROR_TYPE_DEBUG,
538 "Finished\n");
539 GNUNET_SCHEDULER_shutdown ();
540 }
541}
542
543
544static void
545process_statistics_rekey_done (void *cls, int success)
546{
547 if (NULL != rekey_stats)
548 rekey_stats = NULL;
549 if (NULL == box_stats)
550 {
551 LOG (GNUNET_ERROR_TYPE_DEBUG,
552 "Finished\n");
553 GNUNET_SCHEDULER_shutdown ();
554 }
555}
556
557
517static int 558static int
518process_statistics (void *cls, 559process_statistics (void *cls,
519 const char *subsystem, 560 const char *subsystem,
@@ -521,9 +562,45 @@ process_statistics (void *cls,
521 uint64_t value, 562 uint64_t value,
522 int is_persistent) 563 int is_persistent)
523{ 564{
565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
566 "Statistic: Name %s and value %lu\n",
567 name,
568 value);
569 if ((0 == strcmp ("rekey", test_name)) && (0 == strcmp (
570 "# rekeying successful",
571 name)) && (0 == value))
572 {
573 ret = 2;
574 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
575 "No successful rekeying!\n");
576 GNUNET_SCHEDULER_shutdown ();
577 }
578 if ((0 == strcmp ("backchannel", test_name)) &&
579 (0 == strcmp (
580 "# messages decrypted with BOX",
581 name))
582 && (9000 > value))
583 {
584 ret = 2;
585 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
586 "Not enough BOX messages!\n");
587 GNUNET_SCHEDULER_shutdown ();
588 }
589 if ((0 == strcmp ("rekey", test_name)) &&
590 (0 == strcmp (
591 "# messages decrypted with BOX",
592 name))
593 && (6000 > value))
594 {
595 ret = 2;
596 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
597 "Not enough BOX messages!\n");
598 GNUNET_SCHEDULER_shutdown ();
599 }
524 return GNUNET_OK; 600 return GNUNET_OK;
525} 601}
526 602
603
527/** 604/**
528 * @brief Handle an incoming message 605 * @brief Handle an incoming message
529 * 606 *
@@ -534,14 +611,14 @@ process_statistics (void *cls,
534 * @param msg Received message 611 * @param msg Received message
535 */ 612 */
536static void 613static void
537incoming_message_cb (void *cls, 614incoming_message_cb (
538 struct 615 void *cls,
539 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 616 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
540 *tc_h, 617 const char *payload,
541 const char*payload, 618 size_t payload_len)
542 size_t payload_len)
543{ 619{
544 if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1])) 620 if (0 != strcmp ((char*) cls,
621 cfg_peers_name[NUM_PEERS - 1]))
545 { 622 {
546 LOG (GNUNET_ERROR_TYPE_WARNING, 623 LOG (GNUNET_ERROR_TYPE_WARNING,
547 "unexpected receiver...\n"); 624 "unexpected receiver...\n");
@@ -566,11 +643,9 @@ incoming_message_cb (void *cls,
566 { 643 {
567 LOG (GNUNET_ERROR_TYPE_MESSAGE, 644 LOG (GNUNET_ERROR_TYPE_MESSAGE,
568 "Short size packet test done.\n"); 645 "Short size packet test done.\n");
569 char *goodput = GNUNET_STRINGS_byte_size_fancy ((SHORT_MESSAGE_SIZE 646 char *goodput = GNUNET_STRINGS_byte_size_fancy (
570 * num_received_short 647 (SHORT_MESSAGE_SIZE * num_received_short * 1000 * 1000)
571 * 1000 648 / duration.rel_value_us);
572 * 1000)
573 / duration.rel_value_us);
574 LOG (GNUNET_ERROR_TYPE_MESSAGE, 649 LOG (GNUNET_ERROR_TYPE_MESSAGE,
575 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", 650 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
576 (unsigned long) num_received_short, 651 (unsigned long) num_received_short,
@@ -603,12 +678,10 @@ incoming_message_cb (void *cls,
603 { 678 {
604 LOG (GNUNET_ERROR_TYPE_MESSAGE, 679 LOG (GNUNET_ERROR_TYPE_MESSAGE,
605 "Long size packet test done.\n"); 680 "Long size packet test done.\n");
606 char *goodput = GNUNET_STRINGS_byte_size_fancy ((long_message_size 681 char *goodput = GNUNET_STRINGS_byte_size_fancy (
607 * num_received_long 682 (long_message_size * num_received_long * 1000 * 1000)
608 * 1000 683 / duration.
609 * 1000) 684 rel_value_us);
610 / duration.
611 rel_value_us);
612 685
613 LOG (GNUNET_ERROR_TYPE_MESSAGE, 686 LOG (GNUNET_ERROR_TYPE_MESSAGE,
614 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", 687 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
@@ -660,18 +733,32 @@ incoming_message_cb (void *cls,
660 short_test (NULL); 733 short_test (NULL);
661 break; 734 break;
662 } 735 }
663 /* if (("rekey" == test_name) || ("backchannel" == test_name)) */ 736 if ( (0 == strcmp ("rekey", test_name)) ||
664 /* { */ 737 (0 == strcmp ("backchannel", test_name)) )
665 /* GNUNET_STATISTICS_get (stats[1], */ 738 {
666 /* "C-UDP", */ 739 if (NULL != box_stats)
667 /* "# bytes decrypted with Rekey", */ 740 GNUNET_STATISTICS_get_cancel (box_stats);
668 /* NULL, */ 741 box_stats = GNUNET_STATISTICS_get (stats[1],
669 /* &process_statistics, */ 742 "C-UDP",
670 /* NULL); */ 743 "# messages decrypted with BOX",
671 /* } */ 744 process_statistics_box_done,
672 LOG (GNUNET_ERROR_TYPE_DEBUG, 745 &process_statistics,
673 "Finished\n"); 746 NULL);
674 GNUNET_SCHEDULER_shutdown (); 747 if (NULL != rekey_stats)
748 GNUNET_STATISTICS_get_cancel (rekey_stats);
749 rekey_stats = GNUNET_STATISTICS_get (stats[0],
750 "C-UDP",
751 "# rekeying successful",
752 process_statistics_rekey_done,
753 &process_statistics,
754 NULL);
755 }
756 else
757 {
758 LOG (GNUNET_ERROR_TYPE_DEBUG,
759 "Finished\n");
760 GNUNET_SCHEDULER_shutdown ();
761 }
675 } 762 }
676 break; 763 break;
677 } 764 }
@@ -682,6 +769,19 @@ incoming_message_cb (void *cls,
682static void 769static void
683do_shutdown (void *cls) 770do_shutdown (void *cls)
684{ 771{
772 LOG (GNUNET_ERROR_TYPE_DEBUG,
773 "shuting down test.\n");
774
775 if (NULL != box_stats)
776 {
777 GNUNET_STATISTICS_get_cancel (box_stats);
778 box_stats = NULL;
779 }
780 if (NULL != rekey_stats)
781 {
782 GNUNET_STATISTICS_get_cancel (rekey_stats);
783 rekey_stats = NULL;
784 }
685 if (NULL != to_task) 785 if (NULL != to_task)
686 { 786 {
687 GNUNET_SCHEDULER_cancel (to_task); 787 GNUNET_SCHEDULER_cancel (to_task);
@@ -690,6 +790,7 @@ do_shutdown (void *cls)
690 for (unsigned int i = 0; i < NUM_PEERS; i++) 790 for (unsigned int i = 0; i < NUM_PEERS; i++)
691 { 791 {
692 GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (tc_hs[i]); 792 GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (tc_hs[i]);
793 GNUNET_STATISTICS_destroy (stats[i], GNUNET_NO);
693 } 794 }
694} 795}
695 796
@@ -697,7 +798,7 @@ do_shutdown (void *cls)
697/** 798/**
698 * @brief Main function called by the scheduler 799 * @brief Main function called by the scheduler
699 * 800 *
700 * @param cls Closure - Handle to configuration 801 * @param cls Closure - Handle to confiation
701 */ 802 */
702static void 803static void
703run (void *cls) 804run (void *cls)
@@ -720,11 +821,12 @@ run (void *cls)
720 &handle_backchannel_cb, 821 &handle_backchannel_cb,
721 cfg_peers_name[i]); /* cls */ 822 cfg_peers_name[i]); /* cls */
722 823
723 /* if (("rekey" == test_name) || ("backchannel" == test_name)) */ 824 if ((0 == strcmp ("rekey", test_name)) || (0 == strcmp ("backchannel",
724 /* { */ 825 test_name)) )
725 /* stats[i] = GNUNET_STATISTICS_create ("C-UDP", */ 826 {
726 /* cfg_peers[i]); */ 827 stats[i] = GNUNET_STATISTICS_create ("C-UDP",
727 /* } */ 828 cfg_peers[i]);
829 }
728 } 830 }
729 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 831 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
730 NULL); 832 NULL);
@@ -816,15 +918,12 @@ main (int argc,
816 LOG (GNUNET_ERROR_TYPE_DEBUG, 918 LOG (GNUNET_ERROR_TYPE_DEBUG,
817 "test_name: %s\n", 919 "test_name: %s\n",
818 test_name); 920 test_name);
819
820 LOG (GNUNET_ERROR_TYPE_DEBUG, 921 LOG (GNUNET_ERROR_TYPE_DEBUG,
821 "communicator_name: %s\n", 922 "communicator_name: %s\n",
822 communicator_name); 923 communicator_name);
823
824 LOG (GNUNET_ERROR_TYPE_DEBUG, 924 LOG (GNUNET_ERROR_TYPE_DEBUG,
825 "communicator_binary: %s\n", 925 "communicator_binary: %s\n",
826 communicator_binary); 926 communicator_binary);
827
828 GNUNET_SCHEDULER_run (&run, 927 GNUNET_SCHEDULER_run (&run,
829 NULL); 928 NULL);
830 return ret; 929 return ret;
diff --git a/src/transport/test_communicator_tcp_basic_peer1.conf b/src/transport/test_communicator_tcp_basic_peer1.conf
index c08737b7b..2411f485b 100644
--- a/src/transport/test_communicator_tcp_basic_peer1.conf
+++ b/src/transport/test_communicator_tcp_basic_peer1.conf
@@ -22,6 +22,10 @@ UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/nat.sock
22[peerstore] 22[peerstore]
23UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock 23UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock
24 24
25[statistics]
26PORT = 22461
27UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_1.sock
28
25[communicator-unix] 29[communicator-unix]
26UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock 30UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock
27 31
diff --git a/src/transport/test_communicator_tcp_basic_peer2.conf b/src/transport/test_communicator_tcp_basic_peer2.conf
index 45b7e7844..8005718bf 100644
--- a/src/transport/test_communicator_tcp_basic_peer2.conf
+++ b/src/transport/test_communicator_tcp_basic_peer2.conf
@@ -23,6 +23,10 @@ UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/nat.sock
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock
25 25
26[statistics]
27PORT = 22462
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_2.sock
29
26[communicator-unix] 30[communicator-unix]
27UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_2.sock 31UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_2.sock
28 32
diff --git a/src/transport/test_communicator_tcp_rekey_peer1.conf b/src/transport/test_communicator_tcp_rekey_peer1.conf
index 901f415ef..82fbf353a 100644
--- a/src/transport/test_communicator_tcp_rekey_peer1.conf
+++ b/src/transport/test_communicator_tcp_rekey_peer1.conf
@@ -23,6 +23,10 @@ ENABLE_IPSCAN = YES
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock
25 25
26[statistics]
27PORT = 22461
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_1.sock
29
26[resolver] 30[resolver]
27PORT = 62089 31PORT = 62089
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock 32UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock
diff --git a/src/transport/test_communicator_tcp_rekey_peer2.conf b/src/transport/test_communicator_tcp_rekey_peer2.conf
index 643b037b2..1036039c4 100644
--- a/src/transport/test_communicator_tcp_rekey_peer2.conf
+++ b/src/transport/test_communicator_tcp_rekey_peer2.conf
@@ -23,6 +23,10 @@ UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/nat.sock
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock
25 25
26[statistics]
27PORT = 22462
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_2.sock
29
26[resolver] 30[resolver]
27PORT = 62090 31PORT = 62090
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock 32UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock
diff --git a/src/transport/test_communicator_udp_backchannel_peer1.conf b/src/transport/test_communicator_udp_backchannel_peer1.conf
index b99a76d6c..59e6d68e3 100644
--- a/src/transport/test_communicator_udp_backchannel_peer1.conf
+++ b/src/transport/test_communicator_udp_backchannel_peer1.conf
@@ -23,6 +23,10 @@ ENABLE_IPSCAN = YES
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock
25 25
26[statistics]
27PORT = 22461
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_1.sock
29
26[resolver] 30[resolver]
27PORT = 62089 31PORT = 62089
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock 32UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock
@@ -35,6 +39,7 @@ BINDTO = 60002
35DISABLE_V6 = YES 39DISABLE_V6 = YES
36 40
37[communicator-udp] 41[communicator-udp]
42#PREFIX = valgrind --leak-check=full --track-origins=yes
38BINDTO = 60002 43BINDTO = 60002
39DISABLE_V6 = YES 44DISABLE_V6 = YES
40MAX_QUEUE_LENGTH=5000 45MAX_QUEUE_LENGTH=5000
diff --git a/src/transport/test_communicator_udp_backchannel_peer2.conf b/src/transport/test_communicator_udp_backchannel_peer2.conf
index 48bd54c8b..3abf7999b 100644
--- a/src/transport/test_communicator_udp_backchannel_peer2.conf
+++ b/src/transport/test_communicator_udp_backchannel_peer2.conf
@@ -23,6 +23,10 @@ UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/nat.sock
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock
25 25
26[statistics]
27PORT = 22462
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_2.sock
29
26[resolver] 30[resolver]
27PORT = 62090 31PORT = 62090
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock 32UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock
@@ -35,6 +39,7 @@ BINDTO = 60003
35DISABLE_V6 = YES 39DISABLE_V6 = YES
36 40
37[communicator-udp] 41[communicator-udp]
42#PREFIX = valgrind --leak-check=full --track-origins=yes
38BINDTO = 60003 43BINDTO = 60003
39DISABLE_V6 = YES 44DISABLE_V6 = YES
40MAX_QUEUE_LENGTH=5000 45MAX_QUEUE_LENGTH=5000
diff --git a/src/transport/test_communicator_udp_basic_peer1.conf b/src/transport/test_communicator_udp_basic_peer1.conf
index d53a55210..c6ff024ee 100644
--- a/src/transport/test_communicator_udp_basic_peer1.conf
+++ b/src/transport/test_communicator_udp_basic_peer1.conf
@@ -23,11 +23,16 @@ ENABLE_IPSCAN = YES
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock
25 25
26[statistics]
27PORT = 22461
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_1.sock
29
26[resolver] 30[resolver]
27PORT = 62089 31PORT = 62089
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock 32UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock
29 33
30[communicator-udp] 34[communicator-udp]
35#PREFIX = valgrind --leak-check=full --track-origins=yes
31BINDTO = 60002 36BINDTO = 60002
32DISABLE_V6 = YES 37DISABLE_V6 = YES
33MAX_QUEUE_LENGTH=5000 38MAX_QUEUE_LENGTH=5000
diff --git a/src/transport/test_communicator_udp_basic_peer2.conf b/src/transport/test_communicator_udp_basic_peer2.conf
index f05ebc5cb..b353b03e9 100644
--- a/src/transport/test_communicator_udp_basic_peer2.conf
+++ b/src/transport/test_communicator_udp_basic_peer2.conf
@@ -24,11 +24,16 @@ UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/nat.sock
24[peerstore] 24[peerstore]
25UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock 25UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock
26 26
27[statistics]
28PORT = 22462
29UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_2.sock
30
27[resolver] 31[resolver]
28PORT = 62090 32PORT = 62090
29UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock 33UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock
30 34
31[communicator-udp] 35[communicator-udp]
36#PREFIX = valgrind --leak-check=full --track-origins=yes
32BINDTO = 60003 37BINDTO = 60003
33DISABLE_V6 = YES 38DISABLE_V6 = YES
34MAX_QUEUE_LENGTH=5000 39MAX_QUEUE_LENGTH=5000
diff --git a/src/transport/test_communicator_udp_rekey_peer1.conf b/src/transport/test_communicator_udp_rekey_peer1.conf
index 8fede6f8c..6bfeafe33 100644
--- a/src/transport/test_communicator_udp_rekey_peer1.conf
+++ b/src/transport/test_communicator_udp_rekey_peer1.conf
@@ -23,6 +23,10 @@ ENABLE_IPSCAN = YES
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock
25 25
26[statistics]
27PORT = 22461
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_1.sock
29
26[resolver] 30[resolver]
27PORT = 62089 31PORT = 62089
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock 32UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock
@@ -41,7 +45,7 @@ REKEY_INTERVAL = 100ms
41BINDTO = 60002 45BINDTO = 60002
42DISABLE_V6 = YES 46DISABLE_V6 = YES
43MAX_QUEUE_LENGTH=5000 47MAX_QUEUE_LENGTH=5000
44REKEY_INTERVAL = 1s 48REKEY_MAX_BYTES=9MiB
45 49
46[communicator-test] 50[communicator-test]
47BACKCHANNEL_ENABLED = YES 51BACKCHANNEL_ENABLED = YES
diff --git a/src/transport/test_communicator_udp_rekey_peer2.conf b/src/transport/test_communicator_udp_rekey_peer2.conf
index f545ba07a..474ca0c15 100644
--- a/src/transport/test_communicator_udp_rekey_peer2.conf
+++ b/src/transport/test_communicator_udp_rekey_peer2.conf
@@ -23,6 +23,10 @@ UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/nat.sock
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock
25 25
26[statistics]
27PORT = 22462
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_2.sock
29
26[resolver] 30[resolver]
27PORT = 62090 31PORT = 62090
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock 32UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock
@@ -41,7 +45,7 @@ REKEY_INTERVAL = 100ms
41BINDTO = 60003 45BINDTO = 60003
42DISABLE_V6 = YES 46DISABLE_V6 = YES
43MAX_QUEUE_LENGTH=5000 47MAX_QUEUE_LENGTH=5000
44REKEY_INTERVAL = 1s 48REKEY_MAX_BYTES=9MiB
45 49
46[communicator-test] 50[communicator-test]
47BACKCHANNEL_ENABLED = YES 51BACKCHANNEL_ENABLED = YES
diff --git a/src/transport/test_communicator_unix_basic_peer1.conf b/src/transport/test_communicator_unix_basic_peer1.conf
index 8e9700108..13ba2d16b 100644
--- a/src/transport/test_communicator_unix_basic_peer1.conf
+++ b/src/transport/test_communicator_unix_basic_peer1.conf
@@ -23,6 +23,10 @@ ENABLE_IPSCAN = YES
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-1/peerstore.sock
25 25
26[statistics]
27PORT = 22461
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_1.sock
29
26[resolver] 30[resolver]
27PORT = 62089 31PORT = 62089
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock 32UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_1.sock
diff --git a/src/transport/test_communicator_unix_basic_peer2.conf b/src/transport/test_communicator_unix_basic_peer2.conf
index c12cc9111..727e844a7 100644
--- a/src/transport/test_communicator_unix_basic_peer2.conf
+++ b/src/transport/test_communicator_unix_basic_peer2.conf
@@ -23,6 +23,10 @@ UNIXPATH = $GNUNET_TMP/communicator-unix-2/nat.sock
23[peerstore] 23[peerstore]
24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock 24UNIXPATH = $GNUNET_TMP/test-communicator-unix-2/peerstore.sock
25 25
26[statistics]
27PORT = 22462
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-statistics_test_2.sock
29
26[resolver] 30[resolver]
27PORT = 62090 31PORT = 62090
28UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock 32UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-resolver_test_2.sock
diff --git a/src/transport/transport-testing-communicator.c b/src/transport/transport-testing-communicator.c
index 6d74b12e8..56240864c 100644
--- a/src/transport/transport-testing-communicator.c
+++ b/src/transport/transport-testing-communicator.c
@@ -766,6 +766,23 @@ shutdown_process (struct GNUNET_OS_Process *proc)
766 GNUNET_OS_process_destroy (proc); 766 GNUNET_OS_process_destroy (proc);
767} 767}
768 768
769/**
770 * @brief Task run at shutdown to kill the statistics process
771 *
772 * @param cls Closure - Process of communicator
773 */
774static void
775shutdown_statistics (void *cls)
776{
777 struct GNUNET_OS_Process *proc = cls;
778 shutdown_process (proc);
779}
780
781/**
782 * @brief Task run at shutdown to kill the peerstore process
783 *
784 * @param cls Closure - Process of communicator
785 */
769static void 786static void
770shutdown_peerstore (void *cls) 787shutdown_peerstore (void *cls)
771{ 788{
@@ -773,6 +790,11 @@ shutdown_peerstore (void *cls)
773 shutdown_process (proc); 790 shutdown_process (proc);
774} 791}
775 792
793/**
794 * @brief Task run at shutdown to kill a communicator process
795 *
796 * @param cls Closure - Process of communicator
797 */
776static void 798static void
777shutdown_communicator (void *cls) 799shutdown_communicator (void *cls)
778{ 800{
@@ -852,6 +874,10 @@ shutdown_resolver (void *cls)
852} 874}
853 875
854 876
877/**
878 * @brief Start Resolver
879 *
880 */
855static void 881static void
856resolver_start (struct 882resolver_start (struct
857 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) 883 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
@@ -881,6 +907,34 @@ resolver_start (struct
881 907
882} 908}
883 909
910/**
911 * @brief Start Statistics
912 *
913 */
914static void
915statistics_start (
916 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
917{
918 char *binary;
919
920 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
921 tc_h->stat_proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
922 NULL,
923 NULL,
924 NULL,
925 binary,
926 "gnunet-service-statistics",
927 "-c",
928 tc_h->cfg_filename,
929 NULL);
930 if (NULL == tc_h->stat_proc)
931 {
932 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start Statistics!");
933 return;
934 }
935 LOG (GNUNET_ERROR_TYPE_INFO, "started Statistics\n");
936 GNUNET_free (binary);
937}
884 938
885/** 939/**
886 * @brief Start Peerstore 940 * @brief Start Peerstore
@@ -1009,6 +1063,8 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
1009 resolver_start (tc_h); 1063 resolver_start (tc_h);
1010 /* Start peerstore service */ 1064 /* Start peerstore service */
1011 peerstore_start (tc_h); 1065 peerstore_start (tc_h);
1066 /* Start statistic service */
1067 statistics_start (tc_h);
1012 /* Schedule start communicator */ 1068 /* Schedule start communicator */
1013 communicator_start (tc_h, 1069 communicator_start (tc_h,
1014 binary_name); 1070 binary_name);
@@ -1025,6 +1081,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (
1025 shutdown_nat (tc_h->nat_proc); 1081 shutdown_nat (tc_h->nat_proc);
1026 shutdown_resolver (tc_h->resolver_proc); 1082 shutdown_resolver (tc_h->resolver_proc);
1027 shutdown_peerstore (tc_h->ps_proc); 1083 shutdown_peerstore (tc_h->ps_proc);
1084 shutdown_statistics (tc_h->stat_proc);
1028 GNUNET_CONFIGURATION_destroy (tc_h->cfg); 1085 GNUNET_CONFIGURATION_destroy (tc_h->cfg);
1029 GNUNET_free (tc_h); 1086 GNUNET_free (tc_h);
1030} 1087}
diff --git a/src/transport/transport-testing-communicator.h b/src/transport/transport-testing-communicator.h
index 693e61515..1875258b4 100644
--- a/src/transport/transport-testing-communicator.h
+++ b/src/transport/transport-testing-communicator.h
@@ -200,6 +200,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
200 struct GNUNET_OS_Process *resolver_proc; 200 struct GNUNET_OS_Process *resolver_proc;
201 201
202 /** 202 /**
203 * statistics service process
204 */
205 struct GNUNET_OS_Process *stat_proc;
206
207 /**
203 * peerstore service process 208 * peerstore service process
204 */ 209 */
205 struct GNUNET_OS_Process *ps_proc; 210 struct GNUNET_OS_Process *ps_proc;
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index d2e4b4d1a..33fe26e34 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -138,7 +138,7 @@ libgnunetutil_la_LIBADD = \
138 138
139libgnunetutil_la_LDFLAGS = \ 139libgnunetutil_la_LDFLAGS = \
140 $(GN_LIB_LDFLAGS) \ 140 $(GN_LIB_LDFLAGS) \
141 -version-info 13:2:1 141 -version-info 14:0:0
142 142
143if HAVE_TESTING 143if HAVE_TESTING
144 GNUNET_ECC = gnunet-ecc 144 GNUNET_ECC = gnunet-ecc
diff --git a/src/util/configuration.c b/src/util/configuration.c
index e5c01f81f..ecdcb3d53 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -93,7 +93,7 @@ struct GNUNET_CONFIGURATION_Handle
93 * #GNUNET_NO if clean, #GNUNET_YES if dirty, 93 * #GNUNET_NO if clean, #GNUNET_YES if dirty,
94 * #GNUNET_SYSERR on error (i.e. last save failed) 94 * #GNUNET_SYSERR on error (i.e. last save failed)
95 */ 95 */
96 int dirty; 96 enum GNUNET_GenericReturnValue dirty;
97}; 97};
98 98
99 99
@@ -109,11 +109,6 @@ struct DiffHandle
109}; 109};
110 110
111 111
112/**
113 * Create a GNUNET_CONFIGURATION_Handle.
114 *
115 * @return fresh configuration object
116 */
117struct GNUNET_CONFIGURATION_Handle * 112struct GNUNET_CONFIGURATION_Handle *
118GNUNET_CONFIGURATION_create () 113GNUNET_CONFIGURATION_create ()
119{ 114{
@@ -199,11 +194,6 @@ GNUNET_CONFIGURATION_create ()
199} 194}
200 195
201 196
202/**
203 * Destroy configuration object.
204 *
205 * @param cfg configuration to destroy
206 */
207void 197void
208GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) 198GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
209{ 199{
@@ -215,24 +205,13 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
215} 205}
216 206
217 207
218/** 208enum GNUNET_GenericReturnValue
219 * Parse a configuration file @a filename and run the function
220 * @a cb with the resulting configuration object. Then free the
221 * configuration object and return the status value from @a cb.
222 *
223 * @param filename configuration to parse, NULL for "default"
224 * @param cb function to run
225 * @param cb_cls closure for @a cb
226 * @return #GNUNET_SYSERR if parsing the configuration failed,
227 * otherwise return value from @a cb.
228 */
229int
230GNUNET_CONFIGURATION_parse_and_run (const char *filename, 209GNUNET_CONFIGURATION_parse_and_run (const char *filename,
231 GNUNET_CONFIGURATION_Callback cb, 210 GNUNET_CONFIGURATION_Callback cb,
232 void *cb_cls) 211 void *cb_cls)
233{ 212{
234 struct GNUNET_CONFIGURATION_Handle *cfg; 213 struct GNUNET_CONFIGURATION_Handle *cfg;
235 int ret; 214 enum GNUNET_GenericReturnValue ret;
236 215
237 cfg = GNUNET_CONFIGURATION_create (); 216 cfg = GNUNET_CONFIGURATION_create ();
238 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename)) 217 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename))
@@ -247,18 +226,7 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename,
247} 226}
248 227
249 228
250/** 229enum GNUNET_GenericReturnValue
251 * De-serializes configuration
252 *
253 * @param cfg configuration to update
254 * @param mem the memory block of serialized configuration
255 * @param size the size of the memory block
256 * @param basedir set to path from which we recursively load configuration
257 * from inlined configurations; NULL if not and raise warnings
258 * when we come across them
259 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
260 */
261int
262GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, 230GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
263 const char *mem, 231 const char *mem,
264 size_t size, 232 size_t size,
@@ -273,7 +241,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
273 size_t to_read; 241 size_t to_read;
274 size_t i; 242 size_t i;
275 int emptyline; 243 int emptyline;
276 int ret; 244 enum GNUNET_GenericReturnValue ret;
277 char *section; 245 char *section;
278 char *eq; 246 char *eq;
279 char *tag; 247 char *tag;
@@ -411,15 +379,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
411} 379}
412 380
413 381
414/** 382enum GNUNET_GenericReturnValue
415 * Parse a configuration file, add all of the options in the
416 * file to the configuration environment.
417 *
418 * @param cfg configuration to update
419 * @param filename name of the configuration file
420 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
421 */
422int
423GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, 383GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
424 const char *filename) 384 const char *filename)
425{ 385{
@@ -429,7 +389,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
429 char *mem; 389 char *mem;
430 char *endsep; 390 char *endsep;
431 int dirty; 391 int dirty;
432 int ret; 392 enum GNUNET_GenericReturnValue ret;
433 ssize_t sret; 393 ssize_t sret;
434 394
435 fn = GNUNET_STRINGS_filename_expand (filename); 395 fn = GNUNET_STRINGS_filename_expand (filename);
@@ -476,28 +436,13 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
476} 436}
477 437
478 438
479/** 439enum GNUNET_GenericReturnValue
480 * Test if there are configuration options that were
481 * changed since the last save.
482 *
483 * @param cfg configuration to inspect
484 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
485 */
486int
487GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) 440GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
488{ 441{
489 return cfg->dirty; 442 return cfg->dirty;
490} 443}
491 444
492 445
493/**
494 * Serializes the given configuration.
495 *
496 * @param cfg configuration to serialize
497 * @param size will be set to the size of the serialized memory block
498 * @return the memory block where the serialized configuration is
499 * present. This memory should be freed by the caller
500 */
501char * 446char *
502GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, 447GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
503 size_t *size) 448 size_t *size)
@@ -580,21 +525,13 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
580} 525}
581 526
582 527
583/** 528enum GNUNET_GenericReturnValue
584 * Write configuration file.
585 *
586 * @param cfg configuration to write
587 * @param filename where to write the configuration
588 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
589 */
590int
591GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, 529GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
592 const char *filename) 530 const char *filename)
593{ 531{
594 char *fn; 532 char *fn;
595 char *cfg_buf; 533 char *cfg_buf;
596 size_t size; 534 size_t size;
597 ssize_t sret;
598 535
599 fn = GNUNET_STRINGS_filename_expand (filename); 536 fn = GNUNET_STRINGS_filename_expand (filename);
600 if (fn == NULL) 537 if (fn == NULL)
@@ -604,15 +541,17 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
604 GNUNET_free (fn); 541 GNUNET_free (fn);
605 return GNUNET_SYSERR; 542 return GNUNET_SYSERR;
606 } 543 }
607 cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size); 544 cfg_buf = GNUNET_CONFIGURATION_serialize (cfg,
608 sret = GNUNET_DISK_fn_write (fn, 545 &size);
609 cfg_buf, 546 (void) GNUNET_DISK_directory_remove (fn);
610 size, 547 if (GNUNET_OK !=
611 GNUNET_DISK_PERM_USER_READ 548 GNUNET_DISK_fn_write (fn,
612 | GNUNET_DISK_PERM_USER_WRITE 549 cfg_buf,
613 | GNUNET_DISK_PERM_GROUP_READ 550 size,
614 | GNUNET_DISK_PERM_GROUP_WRITE); 551 GNUNET_DISK_PERM_USER_READ
615 if ((sret < 0) || (size != (size_t) sret)) 552 | GNUNET_DISK_PERM_USER_WRITE
553 | GNUNET_DISK_PERM_GROUP_READ
554 | GNUNET_DISK_PERM_GROUP_WRITE))
616 { 555 {
617 GNUNET_free (fn); 556 GNUNET_free (fn);
618 GNUNET_free (cfg_buf); 557 GNUNET_free (cfg_buf);
@@ -629,36 +568,25 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
629} 568}
630 569
631 570
632/**
633 * Iterate over all options in the configuration.
634 *
635 * @param cfg configuration to inspect
636 * @param iter function to call on each option
637 * @param iter_cls closure for @a iter
638 */
639void 571void
640GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 572GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
641 GNUNET_CONFIGURATION_Iterator iter, 573 GNUNET_CONFIGURATION_Iterator iter,
642 void *iter_cls) 574 void *iter_cls)
643{ 575{
644 struct ConfigSection *spos; 576 for (struct ConfigSection *spos = cfg->sections;
645 struct ConfigEntry *epos; 577 NULL != spos;
646 578 spos = spos->next)
647 for (spos = cfg->sections; NULL != spos; spos = spos->next) 579 for (struct ConfigEntry *epos = spos->entries;
648 for (epos = spos->entries; NULL != epos; epos = epos->next) 580 NULL != epos;
581 epos = epos->next)
649 if (NULL != epos->val) 582 if (NULL != epos->val)
650 iter (iter_cls, spos->name, epos->key, epos->val); 583 iter (iter_cls,
584 spos->name,
585 epos->key,
586 epos->val);
651} 587}
652 588
653 589
654/**
655 * Iterate over values of a section in the configuration.
656 *
657 * @param cfg configuration to inspect
658 * @param section the section
659 * @param iter function to call on each option
660 * @param iter_cls closure for @a iter
661 */
662void 590void
663GNUNET_CONFIGURATION_iterate_section_values ( 591GNUNET_CONFIGURATION_iterate_section_values (
664 const struct GNUNET_CONFIGURATION_Handle *cfg, 592 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -680,13 +608,6 @@ GNUNET_CONFIGURATION_iterate_section_values (
680} 608}
681 609
682 610
683/**
684 * Iterate over all sections in the configuration.
685 *
686 * @param cfg configuration to inspect
687 * @param iter function to call on each section
688 * @param iter_cls closure for @a iter
689 */
690void 611void
691GNUNET_CONFIGURATION_iterate_sections ( 612GNUNET_CONFIGURATION_iterate_sections (
692 const struct GNUNET_CONFIGURATION_Handle *cfg, 613 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -706,12 +627,6 @@ GNUNET_CONFIGURATION_iterate_sections (
706} 627}
707 628
708 629
709/**
710 * Remove the given section and all options in it.
711 *
712 * @param cfg configuration to inspect
713 * @param section name of the section to remove
714 */
715void 630void
716GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, 631GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
717 const char *section) 632 const char *section)
@@ -769,12 +684,6 @@ copy_entry (void *cls,
769} 684}
770 685
771 686
772/**
773 * Duplicate an existing configuration object.
774 *
775 * @param cfg configuration to duplicate
776 * @return duplicate configuration
777 */
778struct GNUNET_CONFIGURATION_Handle * 687struct GNUNET_CONFIGURATION_Handle *
779GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) 688GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
780{ 689{
@@ -858,13 +767,6 @@ compare_entries (void *cls,
858} 767}
859 768
860 769
861/**
862 * Compute configuration with only entries that have been changed
863 *
864 * @param cfg_default original configuration
865 * @param cfg_new new configuration
866 * @return configuration with only the differences, never NULL
867 */
868struct GNUNET_CONFIGURATION_Handle * 770struct GNUNET_CONFIGURATION_Handle *
869GNUNET_CONFIGURATION_get_diff ( 771GNUNET_CONFIGURATION_get_diff (
870 const struct GNUNET_CONFIGURATION_Handle *cfg_default, 772 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
@@ -879,15 +781,7 @@ GNUNET_CONFIGURATION_get_diff (
879} 781}
880 782
881 783
882/** 784enum GNUNET_GenericReturnValue
883 * Write only configuration entries that have been changed to configuration file
884 *
885 * @param cfg_default default configuration
886 * @param cfg_new new configuration
887 * @param filename where to write the configuration diff between default and new
888 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
889 */
890int
891GNUNET_CONFIGURATION_write_diffs ( 785GNUNET_CONFIGURATION_write_diffs (
892 const struct GNUNET_CONFIGURATION_Handle *cfg_default, 786 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
893 const struct GNUNET_CONFIGURATION_Handle *cfg_new, 787 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
@@ -903,14 +797,6 @@ GNUNET_CONFIGURATION_write_diffs (
903} 797}
904 798
905 799
906/**
907 * Set a configuration value that should be a string.
908 *
909 * @param cfg configuration to update
910 * @param section section of interest
911 * @param option option of interest
912 * @param value value to set
913 */
914void 800void
915GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, 801GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
916 const char *section, 802 const char *section,
@@ -953,14 +839,6 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
953} 839}
954 840
955 841
956/**
957 * Set a configuration value that should be a number.
958 *
959 * @param cfg configuration to update
960 * @param section section of interest
961 * @param option option of interest
962 * @param number value to set
963 */
964void 842void
965GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, 843GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
966 const char *section, 844 const char *section,
@@ -974,16 +852,7 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
974} 852}
975 853
976 854
977/** 855enum GNUNET_GenericReturnValue
978 * Get a configuration value that should be a number.
979 *
980 * @param cfg configuration to inspect
981 * @param section section of interest
982 * @param option option of interest
983 * @param number where to store the numeric value of the option
984 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
985 */
986int
987GNUNET_CONFIGURATION_get_value_number ( 856GNUNET_CONFIGURATION_get_value_number (
988 const struct GNUNET_CONFIGURATION_Handle *cfg, 857 const struct GNUNET_CONFIGURATION_Handle *cfg,
989 const char *section, 858 const char *section,
@@ -1003,16 +872,7 @@ GNUNET_CONFIGURATION_get_value_number (
1003} 872}
1004 873
1005 874
1006/** 875enum GNUNET_GenericReturnValue
1007 * Get a configuration value that should be a floating point number.
1008 *
1009 * @param cfg configuration to inspect
1010 * @param section section of interest
1011 * @param option option of interest
1012 * @param number where to store the floating value of the option
1013 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1014 */
1015int
1016GNUNET_CONFIGURATION_get_value_float ( 876GNUNET_CONFIGURATION_get_value_float (
1017 const struct GNUNET_CONFIGURATION_Handle *cfg, 877 const struct GNUNET_CONFIGURATION_Handle *cfg,
1018 const char *section, 878 const char *section,
@@ -1032,16 +892,7 @@ GNUNET_CONFIGURATION_get_value_float (
1032} 892}
1033 893
1034 894
1035/** 895enum GNUNET_GenericReturnValue
1036 * Get a configuration value that should be a relative time.
1037 *
1038 * @param cfg configuration to inspect
1039 * @param section section of interest
1040 * @param option option of interest
1041 * @param time set to the time value stored in the configuration
1042 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1043 */
1044int
1045GNUNET_CONFIGURATION_get_value_time ( 896GNUNET_CONFIGURATION_get_value_time (
1046 const struct GNUNET_CONFIGURATION_Handle *cfg, 897 const struct GNUNET_CONFIGURATION_Handle *cfg,
1047 const char *section, 898 const char *section,
@@ -1065,16 +916,7 @@ GNUNET_CONFIGURATION_get_value_time (
1065} 916}
1066 917
1067 918
1068/** 919enum GNUNET_GenericReturnValue
1069 * Get a configuration value that should be a size in bytes.
1070 *
1071 * @param cfg configuration to inspect
1072 * @param section section of interest
1073 * @param option option of interest
1074 * @param size set to the size in bytes as stored in the configuration
1075 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1076 */
1077int
1078GNUNET_CONFIGURATION_get_value_size ( 920GNUNET_CONFIGURATION_get_value_size (
1079 const struct GNUNET_CONFIGURATION_Handle *cfg, 921 const struct GNUNET_CONFIGURATION_Handle *cfg,
1080 const char *section, 922 const char *section,
@@ -1101,7 +943,7 @@ GNUNET_CONFIGURATION_get_value_size (
1101 * value, or NULL if option is not specified 943 * value, or NULL if option is not specified
1102 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 944 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1103 */ 945 */
1104int 946enum GNUNET_GenericReturnValue
1105GNUNET_CONFIGURATION_get_value_string ( 947GNUNET_CONFIGURATION_get_value_string (
1106 const struct GNUNET_CONFIGURATION_Handle *cfg, 948 const struct GNUNET_CONFIGURATION_Handle *cfg,
1107 const char *section, 949 const char *section,
@@ -1120,19 +962,7 @@ GNUNET_CONFIGURATION_get_value_string (
1120} 962}
1121 963
1122 964
1123/** 965enum GNUNET_GenericReturnValue
1124 * Get a configuration value that should be in a set of
1125 * predefined strings
1126 *
1127 * @param cfg configuration to inspect
1128 * @param section section of interest
1129 * @param option option of interest
1130 * @param choices NULL-terminated list of legal values
1131 * @param value will be set to an entry in the legal list,
1132 * or NULL if option is not specified and no default given
1133 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1134 */
1135int
1136GNUNET_CONFIGURATION_get_value_choice ( 966GNUNET_CONFIGURATION_get_value_choice (
1137 const struct GNUNET_CONFIGURATION_Handle *cfg, 967 const struct GNUNET_CONFIGURATION_Handle *cfg,
1138 const char *section, 968 const char *section,
@@ -1163,19 +993,7 @@ GNUNET_CONFIGURATION_get_value_choice (
1163} 993}
1164 994
1165 995
1166/** 996enum GNUNET_GenericReturnValue
1167 * Get crockford32-encoded fixed-size binary data from a configuration.
1168 *
1169 * @param cfg configuration to access
1170 * @param section section to access
1171 * @param option option to access
1172 * @param buf where to store the decoded binary result
1173 * @param buf_size exact number of bytes to store in @a buf
1174 * @return #GNUNET_OK on success
1175 * #GNUNET_NO is the value does not exist
1176 * #GNUNET_SYSERR on decoding error
1177 */
1178int
1179GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, 997GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
1180 const char *section, 998 const char *section,
1181 const char *option, 999 const char *option,
@@ -1207,15 +1025,7 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
1207} 1025}
1208 1026
1209 1027
1210/** 1028enum GNUNET_GenericReturnValue
1211 * Test if we have a value for a particular option
1212 *
1213 * @param cfg configuration to inspect
1214 * @param section section of interest
1215 * @param option option of interest
1216 * @return #GNUNET_YES if so, #GNUNET_NO if not.
1217 */
1218int
1219GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, 1029GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
1220 const char *section, 1030 const char *section,
1221 const char *option) 1031 const char *option)
@@ -1390,22 +1200,6 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1390} 1200}
1391 1201
1392 1202
1393/**
1394 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
1395 * where either in the "PATHS" section or the environment "FOO" is
1396 * set to "DIRECTORY". We also support default expansion,
1397 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
1398 * set in PATHS or the environment, and otherwise to "default". Note
1399 * that "default" itself can also be a $-expression, thus
1400 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
1401 * to VAR2.
1402 *
1403 * @param cfg configuration to use for path expansion
1404 * @param orig string to $-expand (will be freed!). Note that multiple
1405 * $-expressions can be present in this string. They will all be
1406 * $-expanded.
1407 * @return $-expanded string
1408 */
1409char * 1203char *
1410GNUNET_CONFIGURATION_expand_dollar ( 1204GNUNET_CONFIGURATION_expand_dollar (
1411 const struct GNUNET_CONFIGURATION_Handle *cfg, 1205 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -1431,17 +1225,7 @@ GNUNET_CONFIGURATION_expand_dollar (
1431} 1225}
1432 1226
1433 1227
1434/** 1228enum GNUNET_GenericReturnValue
1435 * Get a configuration value that should be a string.
1436 *
1437 * @param cfg configuration to inspect
1438 * @param section section of interest
1439 * @param option option of interest
1440 * @param value will be set to a freshly allocated configuration
1441 * value, or NULL if option is not specified
1442 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1443 */
1444int
1445GNUNET_CONFIGURATION_get_value_filename ( 1229GNUNET_CONFIGURATION_get_value_filename (
1446 const struct GNUNET_CONFIGURATION_Handle *cfg, 1230 const struct GNUNET_CONFIGURATION_Handle *cfg,
1447 const char *section, 1231 const char *section,
@@ -1466,16 +1250,7 @@ GNUNET_CONFIGURATION_get_value_filename (
1466} 1250}
1467 1251
1468 1252
1469/** 1253enum GNUNET_GenericReturnValue
1470 * Get a configuration value that should be in a set of
1471 * "YES" or "NO".
1472 *
1473 * @param cfg configuration to inspect
1474 * @param section section of interest
1475 * @param option option of interest
1476 * @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR
1477 */
1478int
1479GNUNET_CONFIGURATION_get_value_yesno ( 1254GNUNET_CONFIGURATION_get_value_yesno (
1480 const struct GNUNET_CONFIGURATION_Handle *cfg, 1255 const struct GNUNET_CONFIGURATION_Handle *cfg,
1481 const char *section, 1256 const char *section,
@@ -1495,16 +1270,6 @@ GNUNET_CONFIGURATION_get_value_yesno (
1495} 1270}
1496 1271
1497 1272
1498/**
1499 * Iterate over the set of filenames stored in a configuration value.
1500 *
1501 * @param cfg configuration to inspect
1502 * @param section section of interest
1503 * @param option option of interest
1504 * @param cb function to call on each filename
1505 * @param cb_cls closure for @a cb
1506 * @return number of filenames iterated over, -1 on error
1507 */
1508int 1273int
1509GNUNET_CONFIGURATION_iterate_value_filenames ( 1274GNUNET_CONFIGURATION_iterate_value_filenames (
1510 const struct GNUNET_CONFIGURATION_Handle *cfg, 1275 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -1618,7 +1383,7 @@ escape_name (const char *value)
1618 * @param fn filename we are currently looking at 1383 * @param fn filename we are currently looking at
1619 * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do 1384 * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do
1620 */ 1385 */
1621static int 1386static enum GNUNET_GenericReturnValue
1622test_match (void *cls, const char *fn) 1387test_match (void *cls, const char *fn)
1623{ 1388{
1624 const char *of = cls; 1389 const char *of = cls;
@@ -1627,19 +1392,7 @@ test_match (void *cls, const char *fn)
1627} 1392}
1628 1393
1629 1394
1630/** 1395enum GNUNET_GenericReturnValue
1631 * Append a filename to a configuration value that
1632 * represents a list of filenames
1633 *
1634 * @param cfg configuration to update
1635 * @param section section of interest
1636 * @param option option of interest
1637 * @param value filename to append
1638 * @return #GNUNET_OK on success,
1639 * #GNUNET_NO if the filename already in the list
1640 * #GNUNET_SYSERR on error
1641 */
1642int
1643GNUNET_CONFIGURATION_append_value_filename ( 1396GNUNET_CONFIGURATION_append_value_filename (
1644 struct GNUNET_CONFIGURATION_Handle *cfg, 1397 struct GNUNET_CONFIGURATION_Handle *cfg,
1645 const char *section, 1398 const char *section,
@@ -1674,19 +1427,7 @@ GNUNET_CONFIGURATION_append_value_filename (
1674} 1427}
1675 1428
1676 1429
1677/** 1430enum GNUNET_GenericReturnValue
1678 * Remove a filename from a configuration value that
1679 * represents a list of filenames
1680 *
1681 * @param cfg configuration to update
1682 * @param section section of interest
1683 * @param option option of interest
1684 * @param value filename to remove
1685 * @return #GNUNET_OK on success,
1686 * #GNUNET_NO if the filename is not in the list,
1687 * #GNUNET_SYSERR on error
1688 */
1689int
1690GNUNET_CONFIGURATION_remove_value_filename ( 1431GNUNET_CONFIGURATION_remove_value_filename (
1691 struct GNUNET_CONFIGURATION_Handle *cfg, 1432 struct GNUNET_CONFIGURATION_Handle *cfg,
1692 const char *section, 1433 const char *section,
@@ -1771,12 +1512,11 @@ GNUNET_CONFIGURATION_remove_value_filename (
1771 * @param filename file to parse 1512 * @param filename file to parse
1772 * @return #GNUNET_OK on success 1513 * @return #GNUNET_OK on success
1773 */ 1514 */
1774static int 1515static enum GNUNET_GenericReturnValue
1775parse_configuration_file (void *cls, const char *filename) 1516parse_configuration_file (void *cls, const char *filename)
1776{ 1517{
1777 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 1518 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1778 char *ext; 1519 char *ext;
1779 int ret;
1780 1520
1781 /* Examine file extension */ 1521 /* Examine file extension */
1782 ext = strrchr (filename, '.'); 1522 ext = strrchr (filename, '.');
@@ -1786,20 +1526,11 @@ parse_configuration_file (void *cls, const char *filename)
1786 return GNUNET_OK; 1526 return GNUNET_OK;
1787 } 1527 }
1788 1528
1789 ret = GNUNET_CONFIGURATION_parse (cfg, filename); 1529 return GNUNET_CONFIGURATION_parse (cfg, filename);
1790 return ret;
1791} 1530}
1792 1531
1793 1532
1794/** 1533enum GNUNET_GenericReturnValue
1795 * Load default configuration. This function will parse the
1796 * defaults from the given defaults_d directory.
1797 *
1798 * @param cfg configuration to update
1799 * @param defaults_d directory with the defaults
1800 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1801 */
1802int
1803GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, 1534GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
1804 const char *defaults_d) 1535 const char *defaults_d)
1805{ 1536{
@@ -1810,43 +1541,31 @@ GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
1810} 1541}
1811 1542
1812 1543
1813/**
1814 * Return GNUnet's default configuration. A new configuration is allocated
1815 * each time and it's up to the caller to destroy it when done. This function
1816 * returns GNUnet's configuration even when #GNUNET_OS_init has been called
1817 * with a value different from #GNUNET_OS_project_data_default.
1818 *
1819 * @return a freshly allocated configuration
1820 */
1821struct GNUNET_CONFIGURATION_Handle * 1544struct GNUNET_CONFIGURATION_Handle *
1822GNUNET_CONFIGURATION_default (void) 1545GNUNET_CONFIGURATION_default (void)
1823{ 1546{
1824 const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); 1547 const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
1825 const struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default (); 1548 const struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default ();
1826
1827 GNUNET_OS_init (dpd);
1828
1829 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
1830 const char *xdg = getenv ("XDG_CONFIG_HOME"); 1549 const char *xdg = getenv ("XDG_CONFIG_HOME");
1831 char *cfgname = NULL; 1550 char *cfgname = NULL;
1551 struct GNUNET_CONFIGURATION_Handle *cfg;
1832 1552
1553 GNUNET_OS_init (dpd);
1554 cfg = GNUNET_CONFIGURATION_create ();
1833 if (NULL != xdg) 1555 if (NULL != xdg)
1834 GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file); 1556 GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
1835 else 1557 else
1836 cfgname = GNUNET_strdup (pd->user_config_file); 1558 cfgname = GNUNET_strdup (pd->user_config_file);
1837 1559 if (GNUNET_OK !=
1838 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgname)) 1560 GNUNET_CONFIGURATION_load (cfg, cfgname))
1839 { 1561 {
1840 GNUNET_OS_init (pd); 1562 GNUNET_OS_init (pd);
1841 GNUNET_CONFIGURATION_destroy (cfg); 1563 GNUNET_CONFIGURATION_destroy (cfg);
1842 GNUNET_free (cfgname); 1564 GNUNET_free (cfgname);
1843 return NULL; 1565 return NULL;
1844 } 1566 }
1845
1846 GNUNET_free (cfgname); 1567 GNUNET_free (cfgname);
1847
1848 GNUNET_OS_init (pd); 1568 GNUNET_OS_init (pd);
1849
1850 return cfg; 1569 return cfg;
1851} 1570}
1852 1571
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index 019dbe94e..bc58142c2 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -166,12 +166,6 @@ decode_private_ecdsa_key (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv)
166} 166}
167 167
168 168
169/**
170 * Extract the public key for the given private key.
171 *
172 * @param priv the private key
173 * @param pub where to write the public key
174 */
175void 169void
176GNUNET_CRYPTO_ecdsa_key_get_public ( 170GNUNET_CRYPTO_ecdsa_key_get_public (
177 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, 171 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
@@ -183,12 +177,6 @@ GNUNET_CRYPTO_ecdsa_key_get_public (
183} 177}
184 178
185 179
186/**
187 * Extract the public key for the given private key.
188 *
189 * @param priv the private key
190 * @param pub where to write the public key
191 */
192void 180void
193GNUNET_CRYPTO_eddsa_key_get_public ( 181GNUNET_CRYPTO_eddsa_key_get_public (
194 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 182 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
@@ -205,12 +193,6 @@ GNUNET_CRYPTO_eddsa_key_get_public (
205} 193}
206 194
207 195
208/**
209 * Extract the public key for the given private key.
210 *
211 * @param priv the private key
212 * @param pub where to write the public key
213 */
214void 196void
215GNUNET_CRYPTO_ecdhe_key_get_public ( 197GNUNET_CRYPTO_ecdhe_key_get_public (
216 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, 198 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
@@ -222,12 +204,6 @@ GNUNET_CRYPTO_ecdhe_key_get_public (
222} 204}
223 205
224 206
225/**
226 * Convert a public key to a string.
227 *
228 * @param pub key to convert
229 * @return string representing @a pub
230 */
231char * 207char *
232GNUNET_CRYPTO_ecdsa_public_key_to_string ( 208GNUNET_CRYPTO_ecdsa_public_key_to_string (
233 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) 209 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
@@ -255,12 +231,6 @@ GNUNET_CRYPTO_ecdsa_public_key_to_string (
255} 231}
256 232
257 233
258/**
259 * Convert a public key to a string.
260 *
261 * @param pub key to convert
262 * @return string representing @a pub
263 */
264char * 234char *
265GNUNET_CRYPTO_eddsa_public_key_to_string ( 235GNUNET_CRYPTO_eddsa_public_key_to_string (
266 const struct GNUNET_CRYPTO_EddsaPublicKey *pub) 236 const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
@@ -288,12 +258,6 @@ GNUNET_CRYPTO_eddsa_public_key_to_string (
288} 258}
289 259
290 260
291/**
292 * Convert a private key to a string.
293 *
294 * @param priv key to convert
295 * @return string representing @a pub
296 */
297char * 261char *
298GNUNET_CRYPTO_eddsa_private_key_to_string ( 262GNUNET_CRYPTO_eddsa_private_key_to_string (
299 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) 263 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
@@ -321,12 +285,6 @@ GNUNET_CRYPTO_eddsa_private_key_to_string (
321} 285}
322 286
323 287
324/**
325 * Convert a private key to a string.
326 *
327 * @param priv key to convert
328 * @return string representing @a priv
329 */
330char * 288char *
331GNUNET_CRYPTO_ecdsa_private_key_to_string ( 289GNUNET_CRYPTO_ecdsa_private_key_to_string (
332 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv) 290 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv)
@@ -354,15 +312,7 @@ GNUNET_CRYPTO_ecdsa_private_key_to_string (
354} 312}
355 313
356 314
357/** 315enum GNUNET_GenericReturnValue
358 * Convert a string representing a public key to a public key.
359 *
360 * @param enc encoded public key
361 * @param enclen number of bytes in @a enc (without 0-terminator)
362 * @param pub where to store the public key
363 * @return #GNUNET_OK on success
364 */
365int
366GNUNET_CRYPTO_ecdsa_public_key_from_string ( 316GNUNET_CRYPTO_ecdsa_public_key_from_string (
367 const char *enc, 317 const char *enc,
368 size_t enclen, 318 size_t enclen,
@@ -387,15 +337,7 @@ GNUNET_CRYPTO_ecdsa_public_key_from_string (
387} 337}
388 338
389 339
390/** 340enum GNUNET_GenericReturnValue
391 * Convert a string representing a public key to a public key.
392 *
393 * @param enc encoded public key
394 * @param enclen number of bytes in @a enc (without 0-terminator)
395 * @param pub where to store the public key
396 * @return #GNUNET_OK on success
397 */
398int
399GNUNET_CRYPTO_eddsa_public_key_from_string ( 341GNUNET_CRYPTO_eddsa_public_key_from_string (
400 const char *enc, 342 const char *enc,
401 size_t enclen, 343 size_t enclen,
@@ -420,15 +362,7 @@ GNUNET_CRYPTO_eddsa_public_key_from_string (
420} 362}
421 363
422 364
423/** 365enum GNUNET_GenericReturnValue
424 * Convert a string representing a private key to a private key.
425 *
426 * @param enc encoded public key
427 * @param enclen number of bytes in @a enc (without 0-terminator)
428 * @param priv where to store the private key
429 * @return #GNUNET_OK on success
430 */
431int
432GNUNET_CRYPTO_eddsa_private_key_from_string ( 366GNUNET_CRYPTO_eddsa_private_key_from_string (
433 const char *enc, 367 const char *enc,
434 size_t enclen, 368 size_t enclen,
@@ -460,12 +394,6 @@ GNUNET_CRYPTO_eddsa_private_key_from_string (
460} 394}
461 395
462 396
463/**
464 * @ingroup crypto
465 * Clear memory that was used to store a private key.
466 *
467 * @param pk location of the key
468 */
469void 397void
470GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) 398GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
471{ 399{
@@ -473,12 +401,6 @@ GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
473} 401}
474 402
475 403
476/**
477 * @ingroup crypto
478 * Clear memory that was used to store a private key.
479 *
480 * @param pk location of the key
481 */
482void 404void
483GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) 405GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
484{ 406{
@@ -486,12 +408,6 @@ GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
486} 408}
487 409
488 410
489/**
490 * @ingroup crypto
491 * Clear memory that was used to store a private key.
492 *
493 * @param pk location of the key
494 */
495void 411void
496GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) 412GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
497{ 413{
@@ -499,11 +415,6 @@ GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
499} 415}
500 416
501 417
502/**
503 * Create a new private key.
504 *
505 * @param[out] pk fresh private key
506 */
507void 418void
508GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) 419GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
509{ 420{
@@ -515,11 +426,6 @@ GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
515} 426}
516 427
517 428
518/**
519 * Create a new private key.
520 *
521 * @param[out] pk private key to initialize
522 */
523void 429void
524GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) 430GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
525{ 431{
@@ -535,11 +441,6 @@ GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
535} 441}
536 442
537 443
538/**
539 * Create a new private key.
540 *
541 * @param[out] pk set to fresh private key
542 */
543void 444void
544GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) 445GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
545{ 446{
@@ -560,11 +461,6 @@ GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
560} 461}
561 462
562 463
563/**
564 * Get the shared private key we use for anonymous users.
565 *
566 * @return "anonymous" private key
567 */
568const struct GNUNET_CRYPTO_EcdsaPrivateKey * 464const struct GNUNET_CRYPTO_EcdsaPrivateKey *
569GNUNET_CRYPTO_ecdsa_key_get_anonymous () 465GNUNET_CRYPTO_ecdsa_key_get_anonymous ()
570{ 466{
@@ -629,19 +525,7 @@ data_to_ecdsa_value (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
629} 525}
630 526
631 527
632/** 528enum GNUNET_GenericReturnValue
633 * Sign a given block. The @a purpose data is the
634 * beginning of the data of which the signature is to be
635 * created. The `size` field in @a purpose must correctly
636 * indicate the number of bytes of the data structure, including
637 * its header.
638 *
639 * @param priv private key to use for the signing
640 * @param purpose what to sign (size, purpose)
641 * @param sig where to write the signature
642 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
643 */
644int
645GNUNET_CRYPTO_ecdsa_sign_ ( 529GNUNET_CRYPTO_ecdsa_sign_ (
646 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, 530 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
647 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, 531 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
@@ -691,19 +575,7 @@ GNUNET_CRYPTO_ecdsa_sign_ (
691} 575}
692 576
693 577
694/** 578enum GNUNET_GenericReturnValue
695 * Sign a given block. The @a purpose data is the
696 * beginning of the data of which the signature is to be
697 * created. The `size` field in @a purpose must correctly
698 * indicate the number of bytes of the data structure, including
699 * its header.
700 *
701 * @param priv private key to use for the signing
702 * @param purpose what to sign (size, purpose)
703 * @param sig where to write the signature
704 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
705 */
706int
707GNUNET_CRYPTO_eddsa_sign_ ( 579GNUNET_CRYPTO_eddsa_sign_ (
708 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 580 const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
709 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, 581 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
@@ -727,21 +599,7 @@ GNUNET_CRYPTO_eddsa_sign_ (
727} 599}
728 600
729 601
730/** 602enum GNUNET_GenericReturnValue
731 * Verify signature. The @a validate data is the
732 * beginning of the data of which the signature is to be
733 * verified. The `size` field in @a validate must correctly
734 * indicate the number of bytes of the data structure, including
735 * its header. If @a purpose does not match the purpose given
736 * in @a validate (the latter
737 *
738 * @param purpose what is the purpose that the signature should have?
739 * @param validate block to validate (size, purpose, data)
740 * @param sig signature that is being validated
741 * @param pub public key of the signer
742 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
743 */
744int
745GNUNET_CRYPTO_ecdsa_verify_ ( 603GNUNET_CRYPTO_ecdsa_verify_ (
746 uint32_t purpose, 604 uint32_t purpose,
747 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, 605 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
@@ -800,22 +658,7 @@ GNUNET_CRYPTO_ecdsa_verify_ (
800} 658}
801 659
802 660
803/** 661enum GNUNET_GenericReturnValue
804 * Verify signature. The @a validate data is the
805 * beginning of the data of which the signature is to be
806 * verified. The `size` field in @a validate must correctly
807 * indicate the number of bytes of the data structure, including
808 * its header. If @a purpose does not match the purpose given
809 * in @a validate (the latter must be in big endian), signature
810 * verification fails.
811 *
812 * @param purpose what is the purpose that the signature should have?
813 * @param validate block to validate (size, purpose, data)
814 * @param sig signature that is being validated
815 * @param pub public key of the signer
816 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
817 */
818int
819GNUNET_CRYPTO_eddsa_verify_ ( 662GNUNET_CRYPTO_eddsa_verify_ (
820 uint32_t purpose, 663 uint32_t purpose,
821 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, 664 const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
@@ -838,15 +681,7 @@ GNUNET_CRYPTO_eddsa_verify_ (
838} 681}
839 682
840 683
841/** 684enum GNUNET_GenericReturnValue
842 * Derive key material from a public and a private ECDHE key.
843 *
844 * @param priv private key to use for the ECDH (x)
845 * @param pub public key to use for the ECDH (yG)
846 * @param key_material where to write the key material (xyG)
847 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
848 */
849int
850GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, 685GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
851 const struct GNUNET_CRYPTO_EcdhePublicKey *pub, 686 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
852 struct GNUNET_HashCode *key_material) 687 struct GNUNET_HashCode *key_material)
@@ -895,18 +730,6 @@ derive_h (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
895} 730}
896 731
897 732
898/**
899 * Derive a private key from a given private key and a label.
900 * Essentially calculates a private key 'd = H(l,P) * x mod n'
901 * where n is the size of the ECC group and P is the public
902 * key associated with the private key 'd'.
903 *
904 * @param priv original private key
905 * @param label label to use for key deriviation
906 * @param context additional context to use for HKDF of 'h';
907 * typically the name of the subsystem/application
908 * @return derived private key
909 */
910struct GNUNET_CRYPTO_EcdsaPrivateKey * 733struct GNUNET_CRYPTO_EcdsaPrivateKey *
911GNUNET_CRYPTO_ecdsa_private_key_derive ( 734GNUNET_CRYPTO_ecdsa_private_key_derive (
912 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, 735 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
@@ -949,16 +772,6 @@ GNUNET_CRYPTO_ecdsa_private_key_derive (
949} 772}
950 773
951 774
952/**
953 * Derive a public key from a given public key and a label.
954 * Essentially calculates a public key 'V = H(l,P) * P'.
955 *
956 * @param pub original public key
957 * @param label label to use for key derivation
958 * @param context additional context to use for HKDF of 'h';
959 * typically the name of the subsystem/application
960 * @param result where to write the derived public key
961 */
962void 775void
963GNUNET_CRYPTO_ecdsa_public_key_derive ( 776GNUNET_CRYPTO_ecdsa_public_key_derive (
964 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, 777 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
@@ -1010,17 +823,7 @@ GNUNET_CRYPTO_ecdsa_public_key_derive (
1010} 823}
1011 824
1012 825
1013/** 826enum GNUNET_GenericReturnValue
1014 * @ingroup crypto
1015 * Derive key material from a ECDH public key and a private EdDSA key.
1016 * Dual to #GNUNET_CRRYPTO_ecdh_eddsa.
1017 *
1018 * @param priv private key from EdDSA to use for the ECDH (x)
1019 * @param pub public key to use for the ECDH (yG)
1020 * @param key_material where to write the key material H(h(x)yG)
1021 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1022 */
1023int
1024GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, 827GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1025 const struct GNUNET_CRYPTO_EcdhePublicKey *pub, 828 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1026 struct GNUNET_HashCode *key_material) 829 struct GNUNET_HashCode *key_material)
@@ -1042,17 +845,7 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1042} 845}
1043 846
1044 847
1045/** 848enum GNUNET_GenericReturnValue
1046 * @ingroup crypto
1047 * Derive key material from a ECDH public key and a private ECDSA key.
1048 * Dual to #GNUNET_CRRYPTO_ecdh_eddsa.
1049 *
1050 * @param priv private key from ECDSA to use for the ECDH (x)
1051 * @param pub public key to use for the ECDH (yG)
1052 * @param key_material where to write the key material H(h(x)yG)
1053 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1054 */
1055int
1056GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, 849GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1057 const struct GNUNET_CRYPTO_EcdhePublicKey *pub, 850 const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1058 struct GNUNET_HashCode *key_material) 851 struct GNUNET_HashCode *key_material)
@@ -1070,17 +863,7 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1070} 863}
1071 864
1072 865
1073/** 866enum GNUNET_GenericReturnValue
1074 * @ingroup crypto
1075 * Derive key material from a EdDSA public key and a private ECDH key.
1076 * Dual to #GNUNET_CRRYPTO_eddsa_ecdh.
1077 *
1078 * @param priv private key to use for the ECDH (y)
1079 * @param pub public key from EdDSA to use for the ECDH (X=h(x)G)
1080 * @param key_material where to write the key material H(yX)=H(h(x)yG)
1081 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1082 */
1083int
1084GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, 867GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1085 const struct GNUNET_CRYPTO_EddsaPublicKey *pub, 868 const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
1086 struct GNUNET_HashCode *key_material) 869 struct GNUNET_HashCode *key_material)
@@ -1097,17 +880,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1097} 880}
1098 881
1099 882
1100/** 883enum GNUNET_GenericReturnValue
1101 * @ingroup crypto
1102 * Derive key material from a ECDSA public key and a private ECDH key.
1103 * Dual to #GNUNET_CRYPTO_ecdsa_ecdh.
1104 *
1105 * @param priv private key to use for the ECDH (y)
1106 * @param pub public key from ECDSA to use for the ECDH (X=h(x)G)
1107 * @param key_material where to write the key material H(yX)=H(h(x)yG)
1108 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1109 */
1110int
1111GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, 884GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1112 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, 885 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
1113 struct GNUNET_HashCode *key_material) 886 struct GNUNET_HashCode *key_material)
diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c
index 6c71030b2..f7cd8c6d9 100644
--- a/src/util/crypto_ecc_setup.c
+++ b/src/util/crypto_ecc_setup.c
@@ -61,7 +61,7 @@
61 * @param buf_size number of bytes in @a buf 61 * @param buf_size number of bytes in @a buf
62 * @return #GNUNET_OK on success 62 * @return #GNUNET_OK on success
63 */ 63 */
64static int 64static enum GNUNET_GenericReturnValue
65read_from_file (const char *filename, 65read_from_file (const char *filename,
66 void *buf, 66 void *buf,
67 size_t buf_size) 67 size_t buf_size)
@@ -123,104 +123,6 @@ read_from_file (const char *filename,
123 123
124 124
125/** 125/**
126 * Write contents of @a buf atomically to @a filename.
127 * Fail if @a filename already exists or if not exactly
128 * @a buf with @a buf_size bytes could be written to
129 * @a filename.
130 *
131 * @param filename where to write
132 * @param buf buffer to write
133 * @param buf_size number of bytes in @a buf to write
134 * @return #GNUNET_OK on success,
135 * #GNUNET_NO if a file existed under @a filename
136 * #GNUNET_SYSERR on failure
137 */
138static int
139atomic_write_to_file (const char *filename,
140 const void *buf,
141 size_t buf_size)
142{
143 char *tmpl;
144 int fd;
145
146 if (GNUNET_OK !=
147 GNUNET_DISK_directory_create_for_file (filename))
148 {
149 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
150 "mkstemp",
151 filename);
152 return GNUNET_SYSERR;
153 }
154 {
155 char *dname;
156
157 dname = GNUNET_strdup (filename);
158 GNUNET_asprintf (&tmpl,
159 "%s/XXXXXX",
160 dirname (dname));
161 GNUNET_free (dname);
162 }
163 fd = mkstemp (tmpl);
164 if (-1 == fd)
165 {
166 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
167 "mkstemp",
168 tmpl);
169 GNUNET_free (tmpl);
170 return GNUNET_SYSERR;
171 }
172 if (0 != fchmod (fd,
173 S_IRUSR))
174 {
175 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
176 "chmod",
177 tmpl);
178 GNUNET_assert (0 == close (fd));
179 if (0 != unlink (tmpl))
180 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
181 "unlink",
182 tmpl);
183 GNUNET_free (tmpl);
184 return GNUNET_SYSERR;
185 }
186 if (buf_size !=
187 write (fd,
188 buf,
189 buf_size))
190 {
191 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
192 "write",
193 tmpl);
194 GNUNET_assert (0 == close (fd));
195 if (0 != unlink (tmpl))
196 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
197 "unlink",
198 tmpl);
199 GNUNET_free (tmpl);
200 return GNUNET_SYSERR;
201 }
202 GNUNET_assert (0 == close (fd));
203
204 if (0 != link (tmpl,
205 filename))
206 {
207 if (0 != unlink (tmpl))
208 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
209 "unlink",
210 tmpl);
211 GNUNET_free (tmpl);
212 return GNUNET_NO;
213 }
214 if (0 != unlink (tmpl))
215 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
216 "unlink",
217 tmpl);
218 GNUNET_free (tmpl);
219 return GNUNET_OK;
220}
221
222
223/**
224 * @ingroup crypto 126 * @ingroup crypto
225 * @brief Create a new private key by reading it from a file. 127 * @brief Create a new private key by reading it from a file.
226 * 128 *
@@ -235,12 +137,12 @@ atomic_write_to_file (const char *filename,
235 * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but 137 * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but
236 * we found an existing file, #GNUNET_SYSERR on failure 138 * we found an existing file, #GNUNET_SYSERR on failure
237 */ 139 */
238int 140enum GNUNET_GenericReturnValue
239GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, 141GNUNET_CRYPTO_eddsa_key_from_file (const char *filename,
240 int do_create, 142 int do_create,
241 struct GNUNET_CRYPTO_EddsaPrivateKey *pkey) 143 struct GNUNET_CRYPTO_EddsaPrivateKey *pkey)
242{ 144{
243 int ret; 145 enum GNUNET_GenericReturnValue ret;
244 146
245 if (GNUNET_OK == 147 if (GNUNET_OK ==
246 read_from_file (filename, 148 read_from_file (filename,
@@ -251,9 +153,10 @@ GNUNET_CRYPTO_eddsa_key_from_file (const char *filename,
251 return (do_create) ? GNUNET_NO : GNUNET_OK; 153 return (do_create) ? GNUNET_NO : GNUNET_OK;
252 } 154 }
253 GNUNET_CRYPTO_eddsa_key_create (pkey); 155 GNUNET_CRYPTO_eddsa_key_create (pkey);
254 ret = atomic_write_to_file (filename, 156 ret = GNUNET_DISK_fn_write (filename,
255 pkey, 157 pkey,
256 sizeof (*pkey)); 158 sizeof (*pkey),
159 GNUNET_DISK_PERM_USER_READ);
257 if ( (GNUNET_OK == ret) || 160 if ( (GNUNET_OK == ret) ||
258 (GNUNET_SYSERR == ret) ) 161 (GNUNET_SYSERR == ret) )
259 return ret; 162 return ret;
@@ -286,7 +189,7 @@ GNUNET_CRYPTO_eddsa_key_from_file (const char *filename,
286 * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but 189 * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but
287 * we found an existing file, #GNUNET_SYSERR on failure 190 * we found an existing file, #GNUNET_SYSERR on failure
288 */ 191 */
289int 192enum GNUNET_GenericReturnValue
290GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, 193GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename,
291 int do_create, 194 int do_create,
292 struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey) 195 struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey)
@@ -301,9 +204,10 @@ GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename,
301 } 204 }
302 GNUNET_CRYPTO_ecdsa_key_create (pkey); 205 GNUNET_CRYPTO_ecdsa_key_create (pkey);
303 if (GNUNET_OK == 206 if (GNUNET_OK ==
304 atomic_write_to_file (filename, 207 GNUNET_DISK_fn_write (filename,
305 pkey, 208 pkey,
306 sizeof (*pkey))) 209 sizeof (*pkey),
210 GNUNET_DISK_PERM_USER_READ))
307 return GNUNET_OK; 211 return GNUNET_OK;
308 /* maybe another process succeeded in the meantime, try reading one more time */ 212 /* maybe another process succeeded in the meantime, try reading one more time */
309 if (GNUNET_OK == 213 if (GNUNET_OK ==
@@ -357,7 +261,7 @@ GNUNET_CRYPTO_eddsa_key_create_from_configuration (
357 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity 261 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity
358 * could not be retrieved 262 * could not be retrieved
359 */ 263 */
360int 264enum GNUNET_GenericReturnValue
361GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, 265GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
362 struct GNUNET_PeerIdentity *dst) 266 struct GNUNET_PeerIdentity *dst)
363{ 267{
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index fec4d13db..63232cab6 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -139,12 +139,6 @@ key_from_sexp (gcry_mpi_t *array,
139} 139}
140 140
141 141
142/**
143 * Create a new private key. Caller must free return value.
144 *
145 * @param len length of the key in bits (i.e. 2048)
146 * @return fresh private key
147 */
148struct GNUNET_CRYPTO_RsaPrivateKey * 142struct GNUNET_CRYPTO_RsaPrivateKey *
149GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) 143GNUNET_CRYPTO_rsa_private_key_create (unsigned int len)
150{ 144{
@@ -174,11 +168,6 @@ GNUNET_CRYPTO_rsa_private_key_create (unsigned int len)
174} 168}
175 169
176 170
177/**
178 * Free memory occupied by the private key.
179 *
180 * @param key pointer to the memory to free
181 */
182void 171void
183GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key) 172GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key)
184{ 173{
@@ -187,14 +176,6 @@ GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key)
187} 176}
188 177
189 178
190/**
191 * Encode the private key in a format suitable for
192 * storing it into a file.
193 *
194 * @param key the private key
195 * @param[out] buffer set to a buffer with the encoded key
196 * @return size of memory allocated in @a buffer
197 */
198size_t 179size_t
199GNUNET_CRYPTO_rsa_private_key_encode (const struct 180GNUNET_CRYPTO_rsa_private_key_encode (const struct
200 GNUNET_CRYPTO_RsaPrivateKey *key, 181 GNUNET_CRYPTO_RsaPrivateKey *key,
@@ -218,14 +199,6 @@ GNUNET_CRYPTO_rsa_private_key_encode (const struct
218} 199}
219 200
220 201
221/**
222 * Decode the private key from the data-format back
223 * to the "normal", internal format.
224 *
225 * @param buf the buffer where the private key data is stored
226 * @param buf_size the size of the data in @a buf
227 * @return NULL on error
228 */
229struct GNUNET_CRYPTO_RsaPrivateKey * 202struct GNUNET_CRYPTO_RsaPrivateKey *
230GNUNET_CRYPTO_rsa_private_key_decode (const void *buf, 203GNUNET_CRYPTO_rsa_private_key_decode (const void *buf,
231 size_t buf_size) 204 size_t buf_size)
@@ -255,12 +228,6 @@ GNUNET_CRYPTO_rsa_private_key_decode (const void *buf,
255} 228}
256 229
257 230
258/**
259 * Extract the public key of the given private key.
260 *
261 * @param priv the private key
262 * @return NULL on error, otherwise the public key
263 */
264struct GNUNET_CRYPTO_RsaPublicKey * 231struct GNUNET_CRYPTO_RsaPublicKey *
265GNUNET_CRYPTO_rsa_private_key_get_public ( 232GNUNET_CRYPTO_rsa_private_key_get_public (
266 const struct GNUNET_CRYPTO_RsaPrivateKey *priv) 233 const struct GNUNET_CRYPTO_RsaPrivateKey *priv)
@@ -296,11 +263,6 @@ GNUNET_CRYPTO_rsa_private_key_get_public (
296} 263}
297 264
298 265
299/**
300 * Free memory occupied by the public key.
301 *
302 * @param key pointer to the memory to free
303 */
304void 266void
305GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_RsaPublicKey *key) 267GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_RsaPublicKey *key)
306{ 268{
@@ -334,14 +296,6 @@ struct GNUNET_CRYPTO_RsaPublicKeyHeaderP
334GNUNET_NETWORK_STRUCT_END 296GNUNET_NETWORK_STRUCT_END
335 297
336 298
337/**
338 * Encode the public key in a format suitable for
339 * storing it into a file.
340 *
341 * @param key the private key
342 * @param[out] buffer set to a buffer with the encoded key
343 * @return size of memory allocated in @a buffer
344 */
345size_t 299size_t
346GNUNET_CRYPTO_rsa_public_key_encode ( 300GNUNET_CRYPTO_rsa_public_key_encode (
347 const struct GNUNET_CRYPTO_RsaPublicKey *key, 301 const struct GNUNET_CRYPTO_RsaPublicKey *key,
@@ -409,12 +363,6 @@ GNUNET_CRYPTO_rsa_public_key_encode (
409} 363}
410 364
411 365
412/**
413 * Compute hash over the public key.
414 *
415 * @param key public key to hash
416 * @param hc where to store the hash code
417 */
418void 366void
419GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, 367GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key,
420 struct GNUNET_HashCode *hc) 368 struct GNUNET_HashCode *hc)
@@ -431,14 +379,6 @@ GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key,
431} 379}
432 380
433 381
434/**
435 * Decode the public key from the data-format back
436 * to the "normal", internal format.
437 *
438 * @param buf the buffer where the public key data is stored
439 * @param len the length of the data in @a buf
440 * @return NULL on error
441 */
442struct GNUNET_CRYPTO_RsaPublicKey * 382struct GNUNET_CRYPTO_RsaPublicKey *
443GNUNET_CRYPTO_rsa_public_key_decode (const char *buf, 383GNUNET_CRYPTO_rsa_public_key_decode (const char *buf,
444 size_t len) 384 size_t len)
@@ -612,13 +552,6 @@ rsa_blinding_key_derive (const struct GNUNET_CRYPTO_RsaPublicKey *pkey,
612 */ 552 */
613 553
614 554
615/**
616 * Compare the values of two signatures.
617 *
618 * @param s1 one signature
619 * @param s2 the other signature
620 * @return 0 if the two are equal
621 */
622int 555int
623GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1, 556GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1,
624 const struct GNUNET_CRYPTO_RsaSignature *s2) 557 const struct GNUNET_CRYPTO_RsaSignature *s2)
@@ -645,13 +578,6 @@ GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1,
645} 578}
646 579
647 580
648/**
649 * Compare the values of two public keys.
650 *
651 * @param p1 one public key
652 * @param p2 the other public key
653 * @return 0 if the two are equal
654 */
655int 581int
656GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1, 582GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1,
657 const struct GNUNET_CRYPTO_RsaPublicKey *p2) 583 const struct GNUNET_CRYPTO_RsaPublicKey *p2)
@@ -678,13 +604,6 @@ GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1,
678} 604}
679 605
680 606
681/**
682 * Compare the values of two private keys.
683 *
684 * @param p1 one private key
685 * @param p2 the other private key
686 * @return 0 if the two are equal
687 */
688int 607int
689GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1, 608GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1,
690 const struct GNUNET_CRYPTO_RsaPrivateKey *p2) 609 const struct GNUNET_CRYPTO_RsaPrivateKey *p2)
@@ -711,12 +630,6 @@ GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1,
711} 630}
712 631
713 632
714/**
715 * Obtain the length of the RSA key in bits.
716 *
717 * @param key the public key to introspect
718 * @return length of the key in bits
719 */
720unsigned int 633unsigned int
721GNUNET_CRYPTO_rsa_public_key_len (const struct GNUNET_CRYPTO_RsaPublicKey *key) 634GNUNET_CRYPTO_rsa_public_key_len (const struct GNUNET_CRYPTO_RsaPublicKey *key)
722{ 635{
@@ -827,17 +740,7 @@ rsa_full_domain_hash (const struct GNUNET_CRYPTO_RsaPublicKey *pkey,
827} 740}
828 741
829 742
830/** 743enum GNUNET_GenericReturnValue
831 * Blinds the given message with the given blinding key
832 *
833 * @param hash hash of the message to sign
834 * @param bkey the blinding key
835 * @param pkey the public key of the signer
836 * @param[out] buf set to a buffer with the blinded message to be signed
837 * @param[out] buf_size number of bytes stored in @a buf
838 * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious
839 */
840int
841GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, 744GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash,
842 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, 745 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks,
843 struct GNUNET_CRYPTO_RsaPublicKey *pkey, 746 struct GNUNET_CRYPTO_RsaPublicKey *pkey,
@@ -863,7 +766,7 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash,
863 GNUNET_break (0); 766 GNUNET_break (0);
864 *buf = NULL; 767 *buf = NULL;
865 *buf_size = 0; 768 *buf_size = 0;
866 return 0; 769 return GNUNET_NO;
867 } 770 }
868 771
869 data = rsa_full_domain_hash (pkey, hash); 772 data = rsa_full_domain_hash (pkey, hash);
@@ -993,14 +896,6 @@ rsa_sign_mpi (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
993} 896}
994 897
995 898
996/**
997 * Sign a blinded value, which must be a full domain hash of a message.
998 *
999 * @param key private key to use for the signing
1000 * @param msg the message to sign
1001 * @param msg_len number of bytes in @a msg to sign
1002 * @return NULL on error, signature on success
1003 */
1004struct GNUNET_CRYPTO_RsaSignature * 899struct GNUNET_CRYPTO_RsaSignature *
1005GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 900GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
1006 const void *msg, 901 const void *msg,
@@ -1025,13 +920,6 @@ GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
1025} 920}
1026 921
1027 922
1028/**
1029 * Create and sign a full domain hash of a message.
1030 *
1031 * @param key private key to use for the signing
1032 * @param hash the hash of the message to sign
1033 * @return NULL on error, including a malicious RSA key, signature on success
1034 */
1035struct GNUNET_CRYPTO_RsaSignature * 923struct GNUNET_CRYPTO_RsaSignature *
1036GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 924GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
1037 const struct GNUNET_HashCode *hash) 925 const struct GNUNET_HashCode *hash)
@@ -1052,11 +940,6 @@ GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
1052} 940}
1053 941
1054 942
1055/**
1056 * Free memory occupied by signature.
1057 *
1058 * @param sig memory to free
1059 */
1060void 943void
1061GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig) 944GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig)
1062{ 945{
@@ -1065,13 +948,6 @@ GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig)
1065} 948}
1066 949
1067 950
1068/**
1069 * Encode the given signature in a format suitable for storing it into a file.
1070 *
1071 * @param sig the signature
1072 * @param[out] buffer set to a buffer with the encoded key
1073 * @return size of memory allocated in @a buffer
1074 */
1075size_t 951size_t
1076GNUNET_CRYPTO_rsa_signature_encode ( 952GNUNET_CRYPTO_rsa_signature_encode (
1077 const struct GNUNET_CRYPTO_RsaSignature *sig, 953 const struct GNUNET_CRYPTO_RsaSignature *sig,
@@ -1112,14 +988,6 @@ GNUNET_CRYPTO_rsa_signature_encode (
1112} 988}
1113 989
1114 990
1115/**
1116 * Decode the signature from the data-format back to the "normal", internal
1117 * format.
1118 *
1119 * @param buf the buffer where the public key data is stored
1120 * @param buf_size the size of the data in @a buf
1121 * @return NULL on error
1122 */
1123struct GNUNET_CRYPTO_RsaSignature * 991struct GNUNET_CRYPTO_RsaSignature *
1124GNUNET_CRYPTO_rsa_signature_decode (const void *buf, 992GNUNET_CRYPTO_rsa_signature_decode (const void *buf,
1125 size_t buf_size) 993 size_t buf_size)
@@ -1156,12 +1024,6 @@ GNUNET_CRYPTO_rsa_signature_decode (const void *buf,
1156} 1024}
1157 1025
1158 1026
1159/**
1160 * Duplicate the given public key
1161 *
1162 * @param key the public key to duplicate
1163 * @return the duplicate key; NULL upon error
1164 */
1165struct GNUNET_CRYPTO_RsaPublicKey * 1027struct GNUNET_CRYPTO_RsaPublicKey *
1166GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key) 1028GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key)
1167{ 1029{
@@ -1181,16 +1043,6 @@ GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key)
1181} 1043}
1182 1044
1183 1045
1184/**
1185 * Unblind a blind-signed signature. The signature should have been generated
1186 * with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with
1187 * #GNUNET_CRYPTO_rsa_blind().
1188 *
1189 * @param sig the signature made on the blinded signature purpose
1190 * @param bks the blinding key secret used to blind the signature purpose
1191 * @param pkey the public key of the signer
1192 * @return unblinded signature on success, NULL if RSA key is bad or malicious.
1193 */
1194struct GNUNET_CRYPTO_RsaSignature * 1046struct GNUNET_CRYPTO_RsaSignature *
1195GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, 1047GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig,
1196 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, 1048 const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks,
@@ -1272,16 +1124,7 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig,
1272} 1124}
1273 1125
1274 1126
1275/** 1127enum GNUNET_GenericReturnValue
1276 * Verify whether the given hash corresponds to the given signature and
1277 * the signature is valid with respect to the given public key.
1278 *
1279 * @param hash hash of the message to verify to match the @a sig
1280 * @param sig signature that is being validated
1281 * @param pkey public key of the signer
1282 * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature is invalid
1283 */
1284int
1285GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, 1128GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash,
1286 const struct GNUNET_CRYPTO_RsaSignature *sig, 1129 const struct GNUNET_CRYPTO_RsaSignature *sig,
1287 const struct GNUNET_CRYPTO_RsaPublicKey *pkey) 1130 const struct GNUNET_CRYPTO_RsaPublicKey *pkey)
@@ -1319,23 +1162,17 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash,
1319 __FILE__, 1162 __FILE__,
1320 __LINE__, 1163 __LINE__,
1321 gcry_strerror (rc)); 1164 gcry_strerror (rc));
1322 return GNUNET_SYSERR;
1323 BENCHMARK_END (rsa_verify); 1165 BENCHMARK_END (rsa_verify);
1166 return GNUNET_SYSERR;
1324 } 1167 }
1325 BENCHMARK_END (rsa_verify); 1168 BENCHMARK_END (rsa_verify);
1326 return GNUNET_OK; 1169 return GNUNET_OK;
1327} 1170}
1328 1171
1329 1172
1330/**
1331 * Duplicate the given private key
1332 *
1333 * @param key the private key to duplicate
1334 * @return the duplicate key; NULL upon error
1335 */
1336struct GNUNET_CRYPTO_RsaPrivateKey * 1173struct GNUNET_CRYPTO_RsaPrivateKey *
1337GNUNET_CRYPTO_rsa_private_key_dup (const struct 1174GNUNET_CRYPTO_rsa_private_key_dup (
1338 GNUNET_CRYPTO_RsaPrivateKey *key) 1175 const struct GNUNET_CRYPTO_RsaPrivateKey *key)
1339{ 1176{
1340 struct GNUNET_CRYPTO_RsaPrivateKey *dup; 1177 struct GNUNET_CRYPTO_RsaPrivateKey *dup;
1341 gcry_sexp_t dup_sexp; 1178 gcry_sexp_t dup_sexp;
@@ -1353,12 +1190,6 @@ GNUNET_CRYPTO_rsa_private_key_dup (const struct
1353} 1190}
1354 1191
1355 1192
1356/**
1357 * Duplicate the given private key
1358 *
1359 * @param key the private key to duplicate
1360 * @return the duplicate key; NULL upon error
1361 */
1362struct GNUNET_CRYPTO_RsaSignature * 1193struct GNUNET_CRYPTO_RsaSignature *
1363GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig) 1194GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig)
1364{ 1195{
diff --git a/src/util/disk.c b/src/util/disk.c
index c95e9753c..3bafe311d 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -92,7 +92,7 @@ struct GetFileSizeData
92 int include_sym_links; 92 int include_sym_links;
93 93
94 /** 94 /**
95 * GNUNET_YES if mode is file-only (return total == -1 for directories). 95 * #GNUNET_YES if mode is file-only (return total == -1 for directories).
96 */ 96 */
97 int single_file_mode; 97 int single_file_mode;
98}; 98};
@@ -142,8 +142,8 @@ translate_unix_perms (enum GNUNET_DISK_AccessPermissions perm)
142 * @param fn current filename we are looking at 142 * @param fn current filename we are looking at
143 * @return #GNUNET_SYSERR on serious errors, otherwise #GNUNET_OK 143 * @return #GNUNET_SYSERR on serious errors, otherwise #GNUNET_OK
144 */ 144 */
145static int 145static enum GNUNET_GenericReturnValue
146getSizeRec (void *cls, const char *fn) 146get_size_rec (void *cls, const char *fn)
147{ 147{
148 struct GetFileSizeData *gfsd = cls; 148 struct GetFileSizeData *gfsd = cls;
149 149
@@ -175,35 +175,23 @@ getSizeRec (void *cls, const char *fn)
175 if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) && 175 if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) &&
176 ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) 176 ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
177 { 177 {
178 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) 178 if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &get_size_rec, gfsd))
179 return GNUNET_SYSERR; 179 return GNUNET_SYSERR;
180 } 180 }
181 return GNUNET_OK; 181 return GNUNET_OK;
182} 182}
183 183
184 184
185/** 185enum GNUNET_GenericReturnValue
186 * Checks whether a handle is invalid
187 *
188 * @param h handle to check
189 * @return #GNUNET_YES if invalid, #GNUNET_NO if valid
190 */
191int
192GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) 186GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
193{ 187{
194 return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO; 188 return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
195} 189}
196 190
197 191
198/** 192enum GNUNET_GenericReturnValue
199 * Get the size of an open file. 193GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
200 * 194 off_t *size)
201 * @param fh open file handle
202 * @param size where to write size of the file
203 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
204 */
205int
206GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size)
207{ 195{
208 struct stat sbuf; 196 struct stat sbuf;
209 197
@@ -214,80 +202,42 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size)
214} 202}
215 203
216 204
217/**
218 * Move the read/write pointer in a file
219 *
220 * @param h handle of an open file
221 * @param offset position to move to
222 * @param whence specification to which position the offset parameter relates to
223 * @return the new position on success, #GNUNET_SYSERR otherwise
224 */
225off_t 205off_t
226GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, 206GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
227 off_t offset, 207 off_t offset,
228 enum GNUNET_DISK_Seek whence) 208 enum GNUNET_DISK_Seek whence)
229{ 209{
210 static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END };
211
230 if (h == NULL) 212 if (h == NULL)
231 { 213 {
232 errno = EINVAL; 214 errno = EINVAL;
233 return GNUNET_SYSERR; 215 return GNUNET_SYSERR;
234 } 216 }
235
236 static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END };
237
238 return lseek (h->fd, offset, t[whence]); 217 return lseek (h->fd, offset, t[whence]);
239} 218}
240 219
241 220
242/** 221enum GNUNET_GenericReturnValue
243 * Get the size of the file (or directory) of the given file (in
244 * bytes).
245 *
246 * @param filename name of the file or directory
247 * @param size set to the size of the file (or,
248 * in the case of directories, the sum
249 * of all sizes of files in the directory)
250 * @param include_symbolic_links should symbolic links be
251 * included?
252 * @param single_file_mode #GNUNET_YES to only get size of one file
253 * and return #GNUNET_SYSERR for directories.
254 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
255 */
256int
257GNUNET_DISK_file_size (const char *filename, 222GNUNET_DISK_file_size (const char *filename,
258 uint64_t *size, 223 uint64_t *size,
259 int include_symbolic_links, 224 int include_symbolic_links,
260 int single_file_mode) 225 int single_file_mode)
261{ 226{
262 struct GetFileSizeData gfsd; 227 struct GetFileSizeData gfsd;
263 int ret; 228 enum GNUNET_GenericReturnValue ret;
264 229
265 GNUNET_assert (size != NULL); 230 GNUNET_assert (size != NULL);
266 gfsd.total = 0; 231 gfsd.total = 0;
267 gfsd.include_sym_links = include_symbolic_links; 232 gfsd.include_sym_links = include_symbolic_links;
268 gfsd.single_file_mode = single_file_mode; 233 gfsd.single_file_mode = single_file_mode;
269 ret = getSizeRec (&gfsd, filename); 234 ret = get_size_rec (&gfsd, filename);
270 *size = gfsd.total; 235 *size = gfsd.total;
271 return ret; 236 return ret;
272} 237}
273 238
274 239
275/** 240enum GNUNET_GenericReturnValue
276 * Obtain some unique identifiers for the given file
277 * that can be used to identify it in the local system.
278 * This function is used between GNUnet processes to
279 * quickly check if two files with the same absolute path
280 * are actually identical. The two processes represent
281 * the same peer but may communicate over the network
282 * (and the file may be on an NFS volume). This function
283 * may not be supported on all operating systems.
284 *
285 * @param filename name of the file
286 * @param dev set to the device ID
287 * @param ino set to the inode ID
288 * @return #GNUNET_OK on success
289 */
290int
291GNUNET_DISK_file_get_identifiers (const char *filename, 241GNUNET_DISK_file_get_identifiers (const char *filename,
292 uint64_t *dev, 242 uint64_t *dev,
293 uint64_t *ino) 243 uint64_t *ino)
@@ -367,14 +317,6 @@ mktemp_name (const char *t)
367} 317}
368 318
369 319
370/**
371 * Update POSIX permissions mask of a file on disk. If both argumets
372 * are #GNUNET_NO, the file is made world-read-write-executable (777).
373 *
374 * @param fn name of the file to update
375 * @param require_uid_match #GNUNET_YES means 700
376 * @param require_gid_match #GNUNET_YES means 770 unless @a require_uid_match is set
377 */
378void 320void
379GNUNET_DISK_fix_permissions (const char *fn, 321GNUNET_DISK_fix_permissions (const char *fn,
380 int require_uid_match, 322 int require_uid_match,
@@ -394,17 +336,6 @@ GNUNET_DISK_fix_permissions (const char *fn,
394} 336}
395 337
396 338
397/**
398 * Create an (empty) temporary directory on disk. If the given name is not
399 * an absolute path, the current 'TMPDIR' will be prepended. In any case,
400 * 6 random characters will be appended to the name to create a unique
401 * filename.
402 *
403 * @param t component to use for the name;
404 * does NOT contain "XXXXXX" or "/tmp/".
405 * @return NULL on error, otherwise name of fresh
406 * file on disk in directory for temporary files
407 */
408char * 339char *
409GNUNET_DISK_mkdtemp (const char *t) 340GNUNET_DISK_mkdtemp (const char *t)
410{ 341{
@@ -425,13 +356,6 @@ GNUNET_DISK_mkdtemp (const char *t)
425} 356}
426 357
427 358
428/**
429 * Move a file out of the way (create a backup) by
430 * renaming it to "orig.NUM~" where NUM is the smallest
431 * number that is not used yet.
432 *
433 * @param fil name of the file to back up
434 */
435void 359void
436GNUNET_DISK_file_backup (const char *fil) 360GNUNET_DISK_file_backup (const char *fil)
437{ 361{
@@ -453,17 +377,6 @@ GNUNET_DISK_file_backup (const char *fil)
453} 377}
454 378
455 379
456/**
457 * Create an (empty) temporary file on disk. If the given name is not
458 * an absolute path, the current 'TMPDIR' will be prepended. In any case,
459 * 6 random characters will be appended to the name to create a unique
460 * filename.
461 *
462 * @param t component to use for the name;
463 * does NOT contain "XXXXXX" or "/tmp/".
464 * @return NULL on error, otherwise name of fresh
465 * file on disk in directory for temporary files
466 */
467char * 380char *
468GNUNET_DISK_mktemp (const char *t) 381GNUNET_DISK_mktemp (const char *t)
469{ 382{
@@ -487,19 +400,7 @@ GNUNET_DISK_mktemp (const char *t)
487} 400}
488 401
489 402
490/** 403enum GNUNET_GenericReturnValue
491 * Test if @a fil is a directory and listable. Optionally, also check if the
492 * directory is readable. Will not print an error message if the directory does
493 * not exist. Will log errors if #GNUNET_SYSERR is returned (i.e., a file exists
494 * with the same name).
495 *
496 * @param fil filename to test
497 * @param is_readable #GNUNET_YES to additionally check if @a fil is readable;
498 * #GNUNET_NO to disable this check
499 * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it
500 * does not exist or stat'ed
501 */
502int
503GNUNET_DISK_directory_test (const char *fil, int is_readable) 404GNUNET_DISK_directory_test (const char *fil, int is_readable)
504{ 405{
505 struct stat filestat; 406 struct stat filestat;
@@ -532,15 +433,7 @@ GNUNET_DISK_directory_test (const char *fil, int is_readable)
532} 433}
533 434
534 435
535/** 436enum GNUNET_GenericReturnValue
536 * Check that fil corresponds to a filename
537 * (of a file that exists and that is not a directory).
538 *
539 * @param fil filename to check
540 * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something
541 * else (will print an error message in that case, too).
542 */
543int
544GNUNET_DISK_file_test (const char *fil) 437GNUNET_DISK_file_test (const char *fil)
545{ 438{
546 struct stat filestat; 439 struct stat filestat;
@@ -552,7 +445,7 @@ GNUNET_DISK_file_test (const char *fil)
552 return GNUNET_SYSERR; 445 return GNUNET_SYSERR;
553 446
554 ret = stat (rdir, &filestat); 447 ret = stat (rdir, &filestat);
555 if (ret != 0) 448 if (0 != ret)
556 { 449 {
557 if (errno != ENOENT) 450 if (errno != ENOENT)
558 { 451 {
@@ -579,13 +472,7 @@ GNUNET_DISK_file_test (const char *fil)
579} 472}
580 473
581 474
582/** 475enum GNUNET_GenericReturnValue
583 * Implementation of "mkdir -p"
584 *
585 * @param dir the directory to create
586 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
587 */
588int
589GNUNET_DISK_directory_create (const char *dir) 476GNUNET_DISK_directory_create (const char *dir)
590{ 477{
591 char *rdir; 478 char *rdir;
@@ -671,22 +558,13 @@ GNUNET_DISK_directory_create (const char *dir)
671} 558}
672 559
673 560
674/** 561enum GNUNET_GenericReturnValue
675 * Create the directory structure for storing a file.
676 *
677 * @param filename name of a file in the directory
678 * @returns #GNUNET_OK on success,
679 * #GNUNET_SYSERR on failure,
680 * #GNUNET_NO if the directory
681 * exists but is not writeable for us
682 */
683int
684GNUNET_DISK_directory_create_for_file (const char *filename) 562GNUNET_DISK_directory_create_for_file (const char *filename)
685{ 563{
686 char *rdir; 564 char *rdir;
687 size_t len; 565 size_t len;
688 int ret;
689 int eno; 566 int eno;
567 enum GNUNET_GenericReturnValue res;
690 568
691 rdir = GNUNET_STRINGS_filename_expand (filename); 569 rdir = GNUNET_STRINGS_filename_expand (filename);
692 if (NULL == rdir) 570 if (NULL == rdir)
@@ -699,7 +577,6 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
699 GNUNET_free (rdir); 577 GNUNET_free (rdir);
700 return GNUNET_OK; 578 return GNUNET_OK;
701 } 579 }
702
703 len = strlen (rdir); 580 len = strlen (rdir);
704 while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) 581 while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
705 len--; 582 len--;
@@ -710,24 +587,17 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
710 GNUNET_free (rdir); 587 GNUNET_free (rdir);
711 rdir = GNUNET_strdup ("/"); 588 rdir = GNUNET_strdup ("/");
712 } 589 }
713 ret = GNUNET_DISK_directory_create (rdir); 590 res = GNUNET_DISK_directory_create (rdir);
714 if ((GNUNET_OK == ret) && (0 != access (rdir, W_OK))) 591 if ( (GNUNET_OK == res) &&
715 ret = GNUNET_NO; 592 (0 != access (rdir, W_OK)) )
593 res = GNUNET_NO;
716 eno = errno; 594 eno = errno;
717 GNUNET_free (rdir); 595 GNUNET_free (rdir);
718 errno = eno; 596 errno = eno;
719 return ret; 597 return res;
720} 598}
721 599
722 600
723/**
724 * Read the contents of a binary file into a buffer.
725 *
726 * @param h handle to an open file
727 * @param result the buffer to write the result to
728 * @param len the maximum number of bytes to read
729 * @return the number of bytes read on success, #GNUNET_SYSERR on failure
730 */
731ssize_t 601ssize_t
732GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, 602GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
733 void *result, 603 void *result,
@@ -738,35 +608,23 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
738 errno = EINVAL; 608 errno = EINVAL;
739 return GNUNET_SYSERR; 609 return GNUNET_SYSERR;
740 } 610 }
741
742 return read (h->fd, result, len); 611 return read (h->fd, result, len);
743} 612}
744 613
745 614
746/**
747 * Read the contents of a binary file into a buffer.
748 * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN
749 * when no data can be read).
750 *
751 * @param h handle to an open file
752 * @param result the buffer to write the result to
753 * @param len the maximum number of bytes to read
754 * @return the number of bytes read on success, #GNUNET_SYSERR on failure
755 */
756ssize_t 615ssize_t
757GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h, 616GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
758 void *result, 617 void *result,
759 size_t len) 618 size_t len)
760{ 619{
620 int flags;
621 ssize_t ret;
622
761 if (NULL == h) 623 if (NULL == h)
762 { 624 {
763 errno = EINVAL; 625 errno = EINVAL;
764 return GNUNET_SYSERR; 626 return GNUNET_SYSERR;
765 } 627 }
766
767 int flags;
768 ssize_t ret;
769
770 /* set to non-blocking, read, then set back */ 628 /* set to non-blocking, read, then set back */
771 flags = fcntl (h->fd, F_GETFL); 629 flags = fcntl (h->fd, F_GETFL);
772 if (0 == (flags & O_NONBLOCK)) 630 if (0 == (flags & O_NONBLOCK))
@@ -782,22 +640,18 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
782} 640}
783 641
784 642
785/**
786 * Read the contents of a binary file into a buffer.
787 *
788 * @param fn file name
789 * @param result the buffer to write the result to
790 * @param len the maximum number of bytes to read
791 * @return number of bytes read, #GNUNET_SYSERR on failure
792 */
793ssize_t 643ssize_t
794GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) 644GNUNET_DISK_fn_read (const char *fn,
645 void *result,
646 size_t len)
795{ 647{
796 struct GNUNET_DISK_FileHandle *fh; 648 struct GNUNET_DISK_FileHandle *fh;
797 ssize_t ret; 649 ssize_t ret;
798 int eno; 650 int eno;
799 651
800 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); 652 fh = GNUNET_DISK_file_open (fn,
653 GNUNET_DISK_OPEN_READ,
654 GNUNET_DISK_PERM_NONE);
801 if (NULL == fh) 655 if (NULL == fh)
802 return GNUNET_SYSERR; 656 return GNUNET_SYSERR;
803 ret = GNUNET_DISK_file_read (fh, result, len); 657 ret = GNUNET_DISK_file_read (fh, result, len);
@@ -808,14 +662,6 @@ GNUNET_DISK_fn_read (const char *fn, void *result, size_t len)
808} 662}
809 663
810 664
811/**
812 * Write a buffer to a file.
813 *
814 * @param h handle to open file
815 * @param buffer the data to write
816 * @param n number of bytes to write
817 * @return number of bytes written on success, #GNUNET_SYSERR on error
818 */
819ssize_t 665ssize_t
820GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, 666GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
821 const void *buffer, 667 const void *buffer,
@@ -831,29 +677,19 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
831} 677}
832 678
833 679
834/**
835 * Write a buffer to a file, blocking, if necessary.
836 *
837 * @param h handle to open file
838 * @param buffer the data to write
839 * @param n number of bytes to write
840 * @return number of bytes written on success, #GNUNET_SYSERR on error
841 */
842ssize_t 680ssize_t
843GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h, 681GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
844 const void *buffer, 682 const void *buffer,
845 size_t n) 683 size_t n)
846{ 684{
685 int flags;
686 ssize_t ret;
687
847 if (NULL == h) 688 if (NULL == h)
848 { 689 {
849 errno = EINVAL; 690 errno = EINVAL;
850 return GNUNET_SYSERR; 691 return GNUNET_SYSERR;
851 } 692 }
852
853
854 int flags;
855 ssize_t ret;
856
857 /* set to blocking, write, then set back */ 693 /* set to blocking, write, then set back */
858 flags = fcntl (h->fd, F_GETFL); 694 flags = fcntl (h->fd, F_GETFL);
859 if (0 != (flags & O_NONBLOCK)) 695 if (0 != (flags & O_NONBLOCK))
@@ -865,48 +701,95 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
865} 701}
866 702
867 703
868/** 704enum GNUNET_GenericReturnValue
869 * Write a buffer to a file. If the file is longer than the
870 * number of bytes that will be written, it will be truncated.
871 *
872 * @param fn file name
873 * @param buffer the data to write
874 * @param n number of bytes to write
875 * @param mode file permissions
876 * @return number of bytes written on success, #GNUNET_SYSERR on error
877 */
878ssize_t
879GNUNET_DISK_fn_write (const char *fn, 705GNUNET_DISK_fn_write (const char *fn,
880 const void *buffer, 706 const void *buf,
881 size_t n, 707 size_t buf_size,
882 enum GNUNET_DISK_AccessPermissions mode) 708 enum GNUNET_DISK_AccessPermissions mode)
883{ 709{
884 struct GNUNET_DISK_FileHandle *fh; 710 char *tmpl;
885 ssize_t ret; 711 int fd;
886 712
887 fh = 713 if (GNUNET_OK !=
888 GNUNET_DISK_file_open (fn, 714 GNUNET_DISK_directory_create_for_file (fn))
889 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE 715 {
890 | GNUNET_DISK_OPEN_CREATE, 716 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
891 mode); 717 "mkstemp",
892 if (! fh) 718 fn);
893 return GNUNET_SYSERR; 719 return GNUNET_SYSERR;
894 ret = GNUNET_DISK_file_write (fh, buffer, n); 720 }
895 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 721 {
896 return ret; 722 char *dname;
723
724 dname = GNUNET_strdup (fn);
725 GNUNET_asprintf (&tmpl,
726 "%s/XXXXXX",
727 dirname (dname));
728 GNUNET_free (dname);
729 }
730 fd = mkstemp (tmpl);
731 if (-1 == fd)
732 {
733 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
734 "mkstemp",
735 tmpl);
736 GNUNET_free (tmpl);
737 return GNUNET_SYSERR;
738 }
739
740 if (0 != fchmod (fd,
741 translate_unix_perms (mode)))
742 {
743 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
744 "chmod",
745 tmpl);
746 GNUNET_assert (0 == close (fd));
747 if (0 != unlink (tmpl))
748 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
749 "unlink",
750 tmpl);
751 GNUNET_free (tmpl);
752 return GNUNET_SYSERR;
753 }
754 if (buf_size !=
755 write (fd,
756 buf,
757 buf_size))
758 {
759 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
760 "write",
761 tmpl);
762 GNUNET_assert (0 == close (fd));
763 if (0 != unlink (tmpl))
764 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
765 "unlink",
766 tmpl);
767 GNUNET_free (tmpl);
768 return GNUNET_SYSERR;
769 }
770 GNUNET_assert (0 == close (fd));
771
772 if (0 != link (tmpl,
773 fn))
774 {
775 if (0 != unlink (tmpl))
776 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
777 "unlink",
778 tmpl);
779 GNUNET_free (tmpl);
780 return GNUNET_NO;
781 }
782 if (0 != unlink (tmpl))
783 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
784 "unlink",
785 tmpl);
786 GNUNET_free (tmpl);
787 return GNUNET_OK;
788
789
897} 790}
898 791
899 792
900/**
901 * Scan a directory for files.
902 *
903 * @param dir_name the name of the directory
904 * @param callback the method to call for each file,
905 * can be NULL, in that case, we only count
906 * @param callback_cls closure for @a callback
907 * @return the number of files found, #GNUNET_SYSERR on error or
908 * ieration aborted by callback returning #GNUNET_SYSERR
909 */
910int 793int
911GNUNET_DISK_directory_scan (const char *dir_name, 794GNUNET_DISK_directory_scan (const char *dir_name,
912 GNUNET_FileNameCallback callback, 795 GNUNET_FileNameCallback callback,
@@ -916,7 +799,7 @@ GNUNET_DISK_directory_scan (const char *dir_name,
916 struct dirent *finfo; 799 struct dirent *finfo;
917 struct stat istat; 800 struct stat istat;
918 int count = 0; 801 int count = 0;
919 int ret; 802 enum GNUNET_GenericReturnValue ret;
920 char *name; 803 char *name;
921 char *dname; 804 char *dname;
922 unsigned int name_len; 805 unsigned int name_len;
@@ -1008,8 +891,9 @@ GNUNET_DISK_directory_scan (const char *dir_name,
1008 * @param fn directory to remove 891 * @param fn directory to remove
1009 * @return #GNUNET_OK 892 * @return #GNUNET_OK
1010 */ 893 */
1011static int 894static enum GNUNET_GenericReturnValue
1012remove_helper (void *unused, const char *fn) 895remove_helper (void *unused,
896 const char *fn)
1013{ 897{
1014 (void) unused; 898 (void) unused;
1015 (void) GNUNET_DISK_directory_remove (fn); 899 (void) GNUNET_DISK_directory_remove (fn);
@@ -1017,14 +901,7 @@ remove_helper (void *unused, const char *fn)
1017} 901}
1018 902
1019 903
1020/** 904enum GNUNET_GenericReturnValue
1021 * Remove all files in a directory (rm -r). Call with
1022 * caution.
1023 *
1024 * @param filename the file to remove
1025 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1026 */
1027int
1028GNUNET_DISK_directory_remove (const char *filename) 905GNUNET_DISK_directory_remove (const char *filename)
1029{ 906{
1030 struct stat istat; 907 struct stat istat;
@@ -1036,14 +913,17 @@ GNUNET_DISK_directory_remove (const char *filename)
1036 } 913 }
1037 if (0 != lstat (filename, &istat)) 914 if (0 != lstat (filename, &istat))
1038 return GNUNET_NO; /* file may not exist... */ 915 return GNUNET_NO; /* file may not exist... */
1039 (void) chmod (filename, S_IWUSR | S_IRUSR | S_IXUSR); 916 (void) chmod (filename,
917 S_IWUSR | S_IRUSR | S_IXUSR);
1040 if (0 == unlink (filename)) 918 if (0 == unlink (filename))
1041 return GNUNET_OK; 919 return GNUNET_OK;
1042 if ((errno != EISDIR) && 920 if ( (errno != EISDIR) &&
1043 /* EISDIR is not sufficient in all cases, e.g. 921 /* EISDIR is not sufficient in all cases, e.g.
1044 * sticky /tmp directory may result in EPERM on BSD. 922 * sticky /tmp directory may result in EPERM on BSD.
1045 * So we also explicitly check "isDirectory" */ 923 * So we also explicitly check "isDirectory" */
1046 (GNUNET_YES != GNUNET_DISK_directory_test (filename, GNUNET_YES))) 924 (GNUNET_YES !=
925 GNUNET_DISK_directory_test (filename,
926 GNUNET_YES)) )
1047 { 927 {
1048 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename); 928 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename);
1049 return GNUNET_SYSERR; 929 return GNUNET_SYSERR;
@@ -1060,15 +940,9 @@ GNUNET_DISK_directory_remove (const char *filename)
1060} 940}
1061 941
1062 942
1063/** 943enum GNUNET_GenericReturnValue
1064 * Copy a file. 944GNUNET_DISK_file_copy (const char *src,
1065 * 945 const char *dst)
1066 * @param src file to copy
1067 * @param dst destination file name
1068 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1069 */
1070int
1071GNUNET_DISK_file_copy (const char *src, const char *dst)
1072{ 946{
1073 char *buf; 947 char *buf;
1074 uint64_t pos; 948 uint64_t pos;
@@ -1131,10 +1005,6 @@ FAIL:
1131} 1005}
1132 1006
1133 1007
1134/**
1135 * @brief Removes special characters as ':' from a filename.
1136 * @param fn the filename to canonicalize
1137 */
1138void 1008void
1139GNUNET_DISK_filename_canonicalize (char *fn) 1009GNUNET_DISK_filename_canonicalize (char *fn)
1140{ 1010{
@@ -1157,15 +1027,9 @@ GNUNET_DISK_filename_canonicalize (char *fn)
1157} 1027}
1158 1028
1159 1029
1160/** 1030enum GNUNET_GenericReturnValue
1161 * @brief Change owner of a file 1031GNUNET_DISK_file_change_owner (const char *filename,
1162 * 1032 const char *user)
1163 * @param filename name of file to change the owner of
1164 * @param user name of the new owner
1165 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1166 */
1167int
1168GNUNET_DISK_file_change_owner (const char *filename, const char *user)
1169{ 1033{
1170 struct passwd *pws; 1034 struct passwd *pws;
1171 1035
@@ -1187,18 +1051,6 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user)
1187} 1051}
1188 1052
1189 1053
1190/**
1191 * Open a file. Note that the access permissions will only be
1192 * used if a new file is created and if the underlying operating
1193 * system supports the given permissions.
1194 *
1195 * @param fn file name to be opened
1196 * @param flags opening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags
1197 * @param perm permissions for the newly created file, use
1198 * #GNUNET_DISK_PERM_NONE if a file could not be created by this
1199 * call (because of flags)
1200 * @return IO handle on success, NULL on error
1201 */
1202struct GNUNET_DISK_FileHandle * 1054struct GNUNET_DISK_FileHandle *
1203GNUNET_DISK_file_open (const char *fn, 1055GNUNET_DISK_file_open (const char *fn,
1204 enum GNUNET_DISK_OpenFlags flags, 1056 enum GNUNET_DISK_OpenFlags flags,
@@ -1270,42 +1122,28 @@ GNUNET_DISK_file_open (const char *fn,
1270} 1122}
1271 1123
1272 1124
1273/** 1125enum GNUNET_GenericReturnValue
1274 * Close an open file.
1275 *
1276 * @param h file handle
1277 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1278 */
1279int
1280GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) 1126GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
1281{ 1127{
1282 int ret; 1128 enum GNUNET_GenericReturnValue ret;
1283 1129
1284 if (h == NULL) 1130 if (NULL == h)
1285 { 1131 {
1286 errno = EINVAL; 1132 errno = EINVAL;
1287 return GNUNET_SYSERR; 1133 return GNUNET_SYSERR;
1288 } 1134 }
1289 1135
1290 ret = GNUNET_OK; 1136 ret = GNUNET_OK;
1291 1137 if (0 != close (h->fd))
1292 if (close (h->fd) != 0)
1293 { 1138 {
1294 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); 1139 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
1295 ret = GNUNET_SYSERR; 1140 ret = GNUNET_SYSERR;
1296 } 1141 }
1297
1298 GNUNET_free (h); 1142 GNUNET_free (h);
1299 return ret; 1143 return ret;
1300} 1144}
1301 1145
1302 1146
1303/**
1304 * Get a handle from a native integer FD.
1305 *
1306 * @param fno native integer file descriptor
1307 * @return file handle corresponding to the descriptor, NULL on error
1308 */
1309struct GNUNET_DISK_FileHandle * 1147struct GNUNET_DISK_FileHandle *
1310GNUNET_DISK_get_handle_from_int_fd (int fno) 1148GNUNET_DISK_get_handle_from_int_fd (int fno)
1311{ 1149{
@@ -1322,12 +1160,6 @@ GNUNET_DISK_get_handle_from_int_fd (int fno)
1322} 1160}
1323 1161
1324 1162
1325/**
1326 * Get a handle from a native streaming FD.
1327 *
1328 * @param fd native streaming file descriptor
1329 * @return file handle corresponding to the descriptor
1330 */
1331struct GNUNET_DISK_FileHandle * 1163struct GNUNET_DISK_FileHandle *
1332GNUNET_DISK_get_handle_from_native (FILE *fd) 1164GNUNET_DISK_get_handle_from_native (FILE *fd)
1333{ 1165{
@@ -1336,7 +1168,6 @@ GNUNET_DISK_get_handle_from_native (FILE *fd)
1336 fno = fileno (fd); 1168 fno = fileno (fd);
1337 if (-1 == fno) 1169 if (-1 == fno)
1338 return NULL; 1170 return NULL;
1339
1340 return GNUNET_DISK_get_handle_from_int_fd (fno); 1171 return GNUNET_DISK_get_handle_from_int_fd (fno);
1341} 1172}
1342 1173
@@ -1362,15 +1193,7 @@ struct GNUNET_DISK_MapHandle
1362#define MAP_FAILED ((void *) -1) 1193#define MAP_FAILED ((void *) -1)
1363#endif 1194#endif
1364 1195
1365/** 1196
1366 * Map a file into memory
1367 *
1368 * @param h open file handle
1369 * @param m handle to the new mapping
1370 * @param access access specification, GNUNET_DISK_MAP_TYPE_xxx
1371 * @param len size of the mapping
1372 * @return pointer to the mapped memory region, NULL on failure
1373 */
1374void * 1197void *
1375GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, 1198GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
1376 struct GNUNET_DISK_MapHandle **m, 1199 struct GNUNET_DISK_MapHandle **m,
@@ -1402,16 +1225,10 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
1402} 1225}
1403 1226
1404 1227
1405/** 1228enum GNUNET_GenericReturnValue
1406 * Unmap a file
1407 *
1408 * @param h mapping handle
1409 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1410 */
1411int
1412GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) 1229GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h)
1413{ 1230{
1414 int ret; 1231 enum GNUNET_GenericReturnValue ret;
1415 1232
1416 if (NULL == h) 1233 if (NULL == h)
1417 { 1234 {
@@ -1424,12 +1241,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h)
1424} 1241}
1425 1242
1426 1243
1427/** 1244enum GNUNET_GenericReturnValue
1428 * Write file changes to disk
1429 * @param h handle to an open file
1430 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1431 */
1432int
1433GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) 1245GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
1434{ 1246{
1435 if (h == NULL) 1247 if (h == NULL)
@@ -1446,12 +1258,6 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
1446} 1258}
1447 1259
1448 1260
1449/**
1450 * Creates an interprocess channel
1451 *
1452 * @param pf how to configure the pipe
1453 * @return handle to the new pipe, NULL on error
1454 */
1455struct GNUNET_DISK_PipeHandle * 1261struct GNUNET_DISK_PipeHandle *
1456GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf) 1262GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf)
1457{ 1263{
@@ -1469,15 +1275,6 @@ GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf)
1469} 1275}
1470 1276
1471 1277
1472/**
1473 * Creates a pipe object from a couple of file descriptors.
1474 * Useful for wrapping existing pipe FDs.
1475 *
1476 * @param pf how to configure the pipe
1477 * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes
1478 *
1479 * @return handle to the new pipe, NULL on error
1480 */
1481struct GNUNET_DISK_PipeHandle * 1278struct GNUNET_DISK_PipeHandle *
1482GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, 1279GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf,
1483 int fd[2]) 1280 int fd[2])
@@ -1551,18 +1348,11 @@ GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf,
1551} 1348}
1552 1349
1553 1350
1554/** 1351enum GNUNET_GenericReturnValue
1555 * Closes an interprocess channel
1556 *
1557 * @param p pipe to close
1558 * @param end which end of the pipe to close
1559 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1560 */
1561int
1562GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, 1352GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
1563 enum GNUNET_DISK_PipeEnd end) 1353 enum GNUNET_DISK_PipeEnd end)
1564{ 1354{
1565 int ret = GNUNET_OK; 1355 enum GNUNET_GenericReturnValue ret = GNUNET_OK;
1566 1356
1567 if (end == GNUNET_DISK_PIPE_END_READ) 1357 if (end == GNUNET_DISK_PIPE_END_READ)
1568 { 1358 {
@@ -1580,23 +1370,10 @@ GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p,
1580 p->fd[1] = NULL; 1370 p->fd[1] = NULL;
1581 } 1371 }
1582 } 1372 }
1583
1584 return ret; 1373 return ret;
1585} 1374}
1586 1375
1587 1376
1588/**
1589 * Detaches one of the ends from the pipe.
1590 * Detached end is a fully-functional FileHandle, it will
1591 * not be affected by anything you do with the pipe afterwards.
1592 * Each end of a pipe can only be detched from it once (i.e.
1593 * it is not duplicated).
1594 *
1595 * @param p pipe to detach an end from
1596 * @param end which end of the pipe to detach
1597 * @return Detached end on success, NULL on failure
1598 * (or if that end is not present or is closed).
1599 */
1600struct GNUNET_DISK_FileHandle * 1377struct GNUNET_DISK_FileHandle *
1601GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, 1378GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p,
1602 enum GNUNET_DISK_PipeEnd end) 1379 enum GNUNET_DISK_PipeEnd end)
@@ -1624,13 +1401,7 @@ GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p,
1624} 1401}
1625 1402
1626 1403
1627/** 1404enum GNUNET_GenericReturnValue
1628 * Closes an interprocess channel
1629 *
1630 * @param p pipe to close
1631 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1632 */
1633int
1634GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) 1405GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
1635{ 1406{
1636 int ret = GNUNET_OK; 1407 int ret = GNUNET_OK;
@@ -1661,13 +1432,6 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
1661} 1432}
1662 1433
1663 1434
1664/**
1665 * Get the handle to a particular pipe end
1666 *
1667 * @param p pipe
1668 * @param n end to access
1669 * @return handle for the respective end
1670 */
1671const struct GNUNET_DISK_FileHandle * 1435const struct GNUNET_DISK_FileHandle *
1672GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, 1436GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
1673 enum GNUNET_DISK_PipeEnd n) 1437 enum GNUNET_DISK_PipeEnd n)
@@ -1685,26 +1449,16 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
1685} 1449}
1686 1450
1687 1451
1688/** 1452enum GNUNET_GenericReturnValue
1689 * Retrieve OS file handle
1690 * @internal
1691 * @param fh GNUnet file descriptor
1692 * @param dst destination buffer
1693 * @param dst_len length of dst
1694 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1695 */
1696int
1697GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, 1453GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
1698 void *dst, 1454 void *dst,
1699 size_t dst_len) 1455 size_t dst_len)
1700{ 1456{
1701 if (NULL == fh) 1457 if (NULL == fh)
1702 return GNUNET_SYSERR; 1458 return GNUNET_SYSERR;
1703
1704 if (dst_len < sizeof(int)) 1459 if (dst_len < sizeof(int))
1705 return GNUNET_SYSERR; 1460 return GNUNET_SYSERR;
1706 *((int *) dst) = fh->fd; 1461 *((int *) dst) = fh->fd;
1707
1708 return GNUNET_OK; 1462 return GNUNET_OK;
1709} 1463}
1710 1464
@@ -1716,8 +1470,9 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
1716 * @param cfg our configuration 1470 * @param cfg our configuration
1717 * @return #GNUNET_OK on success 1471 * @return #GNUNET_OK on success
1718 */ 1472 */
1719static int 1473static enum GNUNET_GenericReturnValue
1720purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 1474purge_cfg_dir (void *cls,
1475 const struct GNUNET_CONFIGURATION_Handle *cfg)
1721{ 1476{
1722 const char *option = cls; 1477 const char *option = cls;
1723 char *tmpname; 1478 char *tmpname;
@@ -1739,15 +1494,9 @@ purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
1739} 1494}
1740 1495
1741 1496
1742/**
1743 * Remove the directory given under @a option in
1744 * section [PATHS] in configuration under @a cfg_filename
1745 *
1746 * @param cfg_filename configuration file to parse
1747 * @param option option with the dir name to purge
1748 */
1749void 1497void
1750GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, const char *option) 1498GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
1499 const char *option)
1751{ 1500{
1752 GNUNET_break (GNUNET_OK == 1501 GNUNET_break (GNUNET_OK ==
1753 GNUNET_CONFIGURATION_parse_and_run (cfg_filename, 1502 GNUNET_CONFIGURATION_parse_and_run (cfg_filename,
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index 136c6debb..5c3dfc12e 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -65,12 +65,15 @@ static void
65shutdown_task (void *cls) 65shutdown_task (void *cls)
66{ 66{
67 (void) cls; 67 (void) cls;
68 if (sizeof(proof) != GNUNET_DISK_fn_write (pwfn, 68 if (GNUNET_OK !=
69 &proof, 69 GNUNET_DISK_fn_write (pwfn,
70 sizeof(proof), 70 &proof,
71 GNUNET_DISK_PERM_USER_READ 71 sizeof(proof),
72 | GNUNET_DISK_PERM_USER_WRITE)) 72 GNUNET_DISK_PERM_USER_READ
73 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", pwfn); 73 | GNUNET_DISK_PERM_USER_WRITE))
74 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
75 "write",
76 pwfn);
74} 77}
75 78
76 79
diff --git a/src/util/network.c b/src/util/network.c
index b18030fcd..c4adefb8f 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -757,21 +757,17 @@ GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle *desc,
757 struct sockaddr *src_addr, 757 struct sockaddr *src_addr,
758 socklen_t *addrlen) 758 socklen_t *addrlen)
759{ 759{
760 int ret; 760 int flags = 0;
761 int flags;
762
763 flags = 0;
764 761
765#ifdef MSG_DONTWAIT 762#ifdef MSG_DONTWAIT
766 flags |= MSG_DONTWAIT; 763 flags |= MSG_DONTWAIT;
767#endif 764#endif
768 ret = recvfrom (desc->fd, 765 return recvfrom (desc->fd,
769 buffer, 766 buffer,
770 length, 767 length,
771 flags, 768 flags,
772 src_addr, 769 src_addr,
773 addrlen); 770 addrlen);
774 return ret;
775} 771}
776 772
777 773
@@ -853,10 +849,7 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc,
853 const struct sockaddr *dest_addr, 849 const struct sockaddr *dest_addr,
854 socklen_t dest_len) 850 socklen_t dest_len)
855{ 851{
856 int ret; 852 int flags = 0;
857 int flags;
858
859 flags = 0;
860 853
861#ifdef MSG_DONTWAIT 854#ifdef MSG_DONTWAIT
862 flags |= MSG_DONTWAIT; 855 flags |= MSG_DONTWAIT;
@@ -864,8 +857,12 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc,
864#ifdef MSG_NOSIGNAL 857#ifdef MSG_NOSIGNAL
865 flags |= MSG_NOSIGNAL; 858 flags |= MSG_NOSIGNAL;
866#endif 859#endif
867 ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len); 860 return sendto (desc->fd,
868 return ret; 861 message,
862 length,
863 flags,
864 dest_addr,
865 dest_len);
869} 866}
870 867
871 868
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 6969e49e6..12bde8107 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -30,12 +30,12 @@
30 30
31 31
32static int 32static int
33testReadWrite () 33testReadWrite (void)
34{ 34{
35 char tmp[100 + 1]; 35 char tmp[100 + 1];
36 int ret; 36 int ret;
37 37
38 if (strlen (TESTSTRING) != 38 if (GNUNET_OK !=
39 GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING), 39 GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING),
40 GNUNET_DISK_PERM_USER_READ 40 GNUNET_DISK_PERM_USER_READ
41 | GNUNET_DISK_PERM_USER_WRITE)) 41 | GNUNET_DISK_PERM_USER_WRITE))