diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-19 21:20:39 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-19 21:20:39 +0200 |
commit | 33e87eb7680148006b7c9fc8f89040ad104597ea (patch) | |
tree | bee7bf0101ddd39a1fdeaa2e33d88e52be04e288 | |
parent | a31cd73472ac1b4c899a6e1d7e53851c20677f7d (diff) | |
download | gnunet-33e87eb7680148006b7c9fc8f89040ad104597ea.tar.gz gnunet-33e87eb7680148006b7c9fc8f89040ad104597ea.zip |
fix socket cmp, fix compiler warnings about unused args
-rw-r--r-- | src/nse/gnunet-nse.c | 38 | ||||
-rw-r--r-- | src/nse/nse_api.c | 43 | ||||
-rw-r--r-- | src/util/crypto_random.c | 84 | ||||
-rw-r--r-- | src/util/gnunet-scrypt.c | 213 | ||||
-rw-r--r-- | src/util/gnunet-uri.c | 84 | ||||
-rw-r--r-- | src/util/test_common_logging_dummy.c | 59 | ||||
-rw-r--r-- | src/util/tun.c | 163 |
7 files changed, 343 insertions, 341 deletions
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c index bf2fe11c3..c8ffa152e 100644 --- a/src/nse/gnunet-nse.c +++ b/src/nse/gnunet-nse.c | |||
@@ -46,6 +46,7 @@ static int status; | |||
46 | static void | 46 | static void |
47 | do_shutdown (void *cls) | 47 | do_shutdown (void *cls) |
48 | { | 48 | { |
49 | (void) cls; | ||
49 | if (NULL != nse) | 50 | if (NULL != nse) |
50 | { | 51 | { |
51 | GNUNET_NSE_disconnect (nse); | 52 | GNUNET_NSE_disconnect (nse); |
@@ -65,12 +66,14 @@ do_shutdown (void *cls) | |||
65 | */ | 66 | */ |
66 | static void | 67 | static void |
67 | handle_estimate (void *cls, | 68 | handle_estimate (void *cls, |
68 | struct GNUNET_TIME_Absolute timestamp, | 69 | struct GNUNET_TIME_Absolute timestamp, |
69 | double estimate, | 70 | double estimate, |
70 | double std_dev) | 71 | double std_dev) |
71 | { | 72 | { |
73 | (void) cls; | ||
72 | status = 0; | 74 | status = 0; |
73 | FPRINTF (stdout, "%llu %f %f %f\n", | 75 | FPRINTF (stdout, |
76 | "%llu %f %f %f\n", | ||
74 | (unsigned long long) timestamp.abs_value_us, | 77 | (unsigned long long) timestamp.abs_value_us, |
75 | GNUNET_NSE_log_estimate_to_n (estimate), | 78 | GNUNET_NSE_log_estimate_to_n (estimate), |
76 | estimate, | 79 | estimate, |
@@ -92,11 +95,11 @@ run (void *cls, | |||
92 | const char *cfgfile, | 95 | const char *cfgfile, |
93 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 96 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
94 | { | 97 | { |
95 | nse = GNUNET_NSE_connect (cfg, | 98 | (void) cls; |
96 | &handle_estimate, | 99 | (void) args; |
97 | NULL); | 100 | (void) cfgfile; |
98 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 101 | nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL); |
99 | NULL); | 102 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
100 | } | 103 | } |
101 | 104 | ||
102 | 105 | ||
@@ -106,22 +109,21 @@ run (void *cls, | |||
106 | * @return 0 on success | 109 | * @return 0 on success |
107 | */ | 110 | */ |
108 | int | 111 | int |
109 | main (int argc, | 112 | main (int argc, char *const *argv) |
110 | char *const *argv) | ||
111 | { | 113 | { |
112 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 114 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
113 | GNUNET_GETOPT_OPTION_END | 115 | GNUNET_GETOPT_OPTION_END}; |
114 | }; | ||
115 | 116 | ||
116 | status = 1; | 117 | status = 1; |
117 | if (GNUNET_OK != | 118 | if (GNUNET_OK != |
118 | GNUNET_PROGRAM_run (argc, | 119 | GNUNET_PROGRAM_run (argc, |
119 | argv, | 120 | argv, |
120 | "gnunet-nse", | 121 | "gnunet-nse", |
121 | gettext_noop | 122 | gettext_noop ( |
122 | ("Show network size estimates from NSE service."), | 123 | "Show network size estimates from NSE service."), |
123 | options, | 124 | options, |
124 | &run, NULL)) | 125 | &run, |
126 | NULL)) | ||
125 | return 2; | 127 | return 2; |
126 | return status; | 128 | return status; |
127 | } | 129 | } |
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c index e9eaada93..259be75ed 100644 --- a/src/nse/nse_api.c +++ b/src/nse/nse_api.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include "gnunet_nse_service.h" | 32 | #include "gnunet_nse_service.h" |
33 | #include "nse.h" | 33 | #include "nse.h" |
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "nse-api",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "nse-api", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Handle for talking with the NSE service. | 38 | * Handle for talking with the NSE service. |
@@ -68,7 +68,6 @@ struct GNUNET_NSE_Handle | |||
68 | * Closure to pass to @e recv_cb callback. | 68 | * Closure to pass to @e recv_cb callback. |
69 | */ | 69 | */ |
70 | void *recv_cb_cls; | 70 | void *recv_cb_cls; |
71 | |||
72 | }; | 71 | }; |
73 | 72 | ||
74 | 73 | ||
@@ -91,17 +90,15 @@ reconnect (void *cls); | |||
91 | * @param error error code | 90 | * @param error error code |
92 | */ | 91 | */ |
93 | static void | 92 | static void |
94 | mq_error_handler (void *cls, | 93 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
95 | enum GNUNET_MQ_Error error) | ||
96 | { | 94 | { |
97 | struct GNUNET_NSE_Handle *h = cls; | 95 | struct GNUNET_NSE_Handle *h = cls; |
98 | 96 | ||
97 | (void) error; | ||
99 | GNUNET_MQ_destroy (h->mq); | 98 | GNUNET_MQ_destroy (h->mq); |
100 | h->mq = NULL; | 99 | h->mq = NULL; |
101 | h->reconnect_task | 100 | h->reconnect_task = |
102 | = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, | 101 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); |
103 | &reconnect, | ||
104 | h); | ||
105 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 102 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
106 | } | 103 | } |
107 | 104 | ||
@@ -114,8 +111,7 @@ mq_error_handler (void *cls, | |||
114 | * @param client_msg message received | 111 | * @param client_msg message received |
115 | */ | 112 | */ |
116 | static void | 113 | static void |
117 | handle_estimate (void *cls, | 114 | handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg) |
118 | const struct GNUNET_NSE_ClientMessage *client_msg) | ||
119 | { | 115 | { |
120 | struct GNUNET_NSE_Handle *h = cls; | 116 | struct GNUNET_NSE_Handle *h = cls; |
121 | 117 | ||
@@ -123,7 +119,7 @@ handle_estimate (void *cls, | |||
123 | h->recv_cb (h->recv_cb_cls, | 119 | h->recv_cb (h->recv_cb_cls, |
124 | GNUNET_TIME_absolute_ntoh (client_msg->timestamp), | 120 | GNUNET_TIME_absolute_ntoh (client_msg->timestamp), |
125 | GNUNET_ntoh_double (client_msg->size_estimate), | 121 | GNUNET_ntoh_double (client_msg->size_estimate), |
126 | GNUNET_ntoh_double (client_msg->std_deviation)); | 122 | GNUNET_ntoh_double (client_msg->std_deviation)); |
127 | } | 123 | } |
128 | 124 | ||
129 | 125 | ||
@@ -136,13 +132,12 @@ static void | |||
136 | reconnect (void *cls) | 132 | reconnect (void *cls) |
137 | { | 133 | { |
138 | struct GNUNET_NSE_Handle *h = cls; | 134 | struct GNUNET_NSE_Handle *h = cls; |
139 | struct GNUNET_MQ_MessageHandler handlers[] = { | 135 | struct GNUNET_MQ_MessageHandler handlers[] = |
140 | GNUNET_MQ_hd_fixed_size (estimate, | 136 | {GNUNET_MQ_hd_fixed_size (estimate, |
141 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, | 137 | GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, |
142 | struct GNUNET_NSE_ClientMessage, | 138 | struct GNUNET_NSE_ClientMessage, |
143 | h), | 139 | h), |
144 | GNUNET_MQ_handler_end () | 140 | GNUNET_MQ_handler_end ()}; |
145 | }; | ||
146 | struct GNUNET_MessageHeader *msg; | 141 | struct GNUNET_MessageHeader *msg; |
147 | struct GNUNET_MQ_Envelope *env; | 142 | struct GNUNET_MQ_Envelope *env; |
148 | 143 | ||
@@ -150,17 +145,11 @@ reconnect (void *cls) | |||
150 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 145 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
151 | "Connecting to network size estimation service.\n"); | 146 | "Connecting to network size estimation service.\n"); |
152 | GNUNET_assert (NULL == h->mq); | 147 | GNUNET_assert (NULL == h->mq); |
153 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 148 | h->mq = GNUNET_CLIENT_connect (h->cfg, "nse", handlers, &mq_error_handler, h); |
154 | "nse", | ||
155 | handlers, | ||
156 | &mq_error_handler, | ||
157 | h); | ||
158 | if (NULL == h->mq) | 149 | if (NULL == h->mq) |
159 | return; | 150 | return; |
160 | env = GNUNET_MQ_msg (msg, | 151 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NSE_START); |
161 | GNUNET_MESSAGE_TYPE_NSE_START); | 152 | GNUNET_MQ_send (h->mq, env); |
162 | GNUNET_MQ_send (h->mq, | ||
163 | env); | ||
164 | } | 153 | } |
165 | 154 | ||
166 | 155 | ||
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 8bb5f0587..71eaab87a 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c | |||
@@ -28,22 +28,23 @@ | |||
28 | #include "gnunet_crypto_lib.h" | 28 | #include "gnunet_crypto_lib.h" |
29 | #include <gcrypt.h> | 29 | #include <gcrypt.h> |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__) |
32 | 32 | ||
33 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-random", syscall) | 33 | #define LOG_STRERROR(kind, syscall) \ |
34 | GNUNET_log_from_strerror (kind, "util-crypto-random", syscall) | ||
34 | 35 | ||
35 | 36 | ||
36 | /* TODO: ndurner, move this to plibc? */ | 37 | /* TODO: ndurner, move this to plibc? */ |
37 | /* The code is derived from glibc, obviously */ | 38 | /* The code is derived from glibc, obviously */ |
38 | #if !HAVE_RANDOM || !HAVE_SRANDOM | 39 | #if ! HAVE_RANDOM || ! HAVE_SRANDOM |
39 | #ifdef RANDOM | 40 | #ifdef RANDOM |
40 | #undef RANDOM | 41 | #undef RANDOM |
41 | #endif | 42 | #endif |
42 | #ifdef SRANDOM | 43 | #ifdef SRANDOM |
43 | #undef SRANDOM | 44 | #undef SRANDOM |
44 | #endif | 45 | #endif |
45 | #define RANDOM() glibc_weak_rand32() | 46 | #define RANDOM() glibc_weak_rand32 () |
46 | #define SRANDOM(s) glibc_weak_srand32(s) | 47 | #define SRANDOM(s) glibc_weak_srand32 (s) |
47 | #if defined(RAND_MAX) | 48 | #if defined(RAND_MAX) |
48 | #undef RAND_MAX | 49 | #undef RAND_MAX |
49 | #endif | 50 | #endif |
@@ -105,17 +106,12 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed) | |||
105 | * @param length buffer length | 106 | * @param length buffer length |
106 | */ | 107 | */ |
107 | void | 108 | void |
108 | GNUNET_CRYPTO_zero_keys (void *buffer, | 109 | GNUNET_CRYPTO_zero_keys (void *buffer, size_t length) |
109 | size_t length) | ||
110 | { | 110 | { |
111 | #if HAVE_MEMSET_S | 111 | #if HAVE_MEMSET_S |
112 | memset_s (buffer, | 112 | memset_s (buffer, length, 0, length); |
113 | length, | ||
114 | 0, | ||
115 | length); | ||
116 | #elif HAVE_EXPLICIT_BZERO | 113 | #elif HAVE_EXPLICIT_BZERO |
117 | explicit_bzero (buffer, | 114 | explicit_bzero (buffer, length); |
118 | length); | ||
119 | #else | 115 | #else |
120 | volatile unsigned char *p = buffer; | 116 | volatile unsigned char *p = buffer; |
121 | while (length--) | 117 | while (length--) |
@@ -175,8 +171,7 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, | |||
175 | * @return a random value in the interval [0,i[. | 171 | * @return a random value in the interval [0,i[. |
176 | */ | 172 | */ |
177 | uint32_t | 173 | uint32_t |
178 | GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, | 174 | GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i) |
179 | uint32_t i) | ||
180 | { | 175 | { |
181 | #ifdef gcry_fast_random_poll | 176 | #ifdef gcry_fast_random_poll |
182 | static unsigned int invokeCount; | 177 | static unsigned int invokeCount; |
@@ -197,18 +192,17 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, | |||
197 | ul = UINT32_MAX - (UINT32_MAX % i); | 192 | ul = UINT32_MAX - (UINT32_MAX % i); |
198 | do | 193 | do |
199 | { | 194 | { |
200 | gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t), | 195 | gcry_randomize ((unsigned char *) &ret, |
196 | sizeof (uint32_t), | ||
201 | GCRY_STRONG_RANDOM); | 197 | GCRY_STRONG_RANDOM); |
202 | } | 198 | } while (ret >= ul); |
203 | while (ret >= ul); | ||
204 | return ret % i; | 199 | return ret % i; |
205 | case GNUNET_CRYPTO_QUALITY_NONCE: | 200 | case GNUNET_CRYPTO_QUALITY_NONCE: |
206 | ul = UINT32_MAX - (UINT32_MAX % i); | 201 | ul = UINT32_MAX - (UINT32_MAX % i); |
207 | do | 202 | do |
208 | { | 203 | { |
209 | gcry_create_nonce (&ret, sizeof (ret)); | 204 | gcry_create_nonce (&ret, sizeof (ret)); |
210 | } | 205 | } while (ret >= ul); |
211 | while (ret >= ul); | ||
212 | return ret % i; | 206 | return ret % i; |
213 | case GNUNET_CRYPTO_QUALITY_WEAK: | 207 | case GNUNET_CRYPTO_QUALITY_WEAK: |
214 | ret = i * get_weak_random (); | 208 | ret = i * get_weak_random (); |
@@ -231,8 +225,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, | |||
231 | * @return the permutation array (allocated from heap) | 225 | * @return the permutation array (allocated from heap) |
232 | */ | 226 | */ |
233 | unsigned int * | 227 | unsigned int * |
234 | GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, | 228 | GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n) |
235 | unsigned int n) | ||
236 | { | 229 | { |
237 | unsigned int *ret; | 230 | unsigned int *ret; |
238 | unsigned int i; | 231 | unsigned int i; |
@@ -262,8 +255,7 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, | |||
262 | * @return random 64-bit number | 255 | * @return random 64-bit number |
263 | */ | 256 | */ |
264 | uint64_t | 257 | uint64_t |
265 | GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | 258 | GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) |
266 | uint64_t max) | ||
267 | { | 259 | { |
268 | uint64_t ret; | 260 | uint64_t ret; |
269 | uint64_t ul; | 261 | uint64_t ul; |
@@ -275,18 +267,17 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, | |||
275 | ul = UINT64_MAX - (UINT64_MAX % max); | 267 | ul = UINT64_MAX - (UINT64_MAX % max); |
276 | do | 268 | do |
277 | { | 269 | { |
278 | gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t), | 270 | gcry_randomize ((unsigned char *) &ret, |
271 | sizeof (uint64_t), | ||
279 | GCRY_STRONG_RANDOM); | 272 | GCRY_STRONG_RANDOM); |
280 | } | 273 | } while (ret >= ul); |
281 | while (ret >= ul); | ||
282 | return ret % max; | 274 | return ret % max; |
283 | case GNUNET_CRYPTO_QUALITY_NONCE: | 275 | case GNUNET_CRYPTO_QUALITY_NONCE: |
284 | ul = UINT64_MAX - (UINT64_MAX % max); | 276 | ul = UINT64_MAX - (UINT64_MAX % max); |
285 | do | 277 | do |
286 | { | 278 | { |
287 | gcry_create_nonce (&ret, sizeof (ret)); | 279 | gcry_create_nonce (&ret, sizeof (ret)); |
288 | } | 280 | } while (ret >= ul); |
289 | while (ret >= ul); | ||
290 | 281 | ||
291 | return ret % max; | 282 | return ret % max; |
292 | case GNUNET_CRYPTO_QUALITY_WEAK: | 283 | case GNUNET_CRYPTO_QUALITY_WEAK: |
@@ -319,6 +310,7 @@ w_malloc (size_t n) | |||
319 | static int | 310 | static int |
320 | w_check (const void *p) | 311 | w_check (const void *p) |
321 | { | 312 | { |
313 | (void) p; | ||
322 | return 0; /* not secure memory */ | 314 | return 0; /* not secure memory */ |
323 | } | 315 | } |
324 | 316 | ||
@@ -326,50 +318,45 @@ w_check (const void *p) | |||
326 | /** | 318 | /** |
327 | * Initialize libgcrypt. | 319 | * Initialize libgcrypt. |
328 | */ | 320 | */ |
329 | void __attribute__ ((constructor)) | 321 | void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init () |
330 | GNUNET_CRYPTO_random_init () | ||
331 | { | 322 | { |
332 | gcry_error_t rc; | 323 | gcry_error_t rc; |
333 | 324 | ||
334 | if (! gcry_check_version (NEED_LIBGCRYPT_VERSION)) | 325 | if (! gcry_check_version (NEED_LIBGCRYPT_VERSION)) |
335 | { | 326 | { |
336 | FPRINTF (stderr, | 327 | FPRINTF ( |
337 | _("libgcrypt has not the expected version (version %s is required).\n"), | 328 | stderr, |
338 | NEED_LIBGCRYPT_VERSION); | 329 | _ ("libgcrypt has not the expected version (version %s is required).\n"), |
330 | NEED_LIBGCRYPT_VERSION); | ||
339 | GNUNET_assert (0); | 331 | GNUNET_assert (0); |
340 | } | 332 | } |
341 | /* set custom allocators */ | 333 | /* set custom allocators */ |
342 | gcry_set_allocation_handler (&w_malloc, | 334 | gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free); |
343 | &w_malloc, | ||
344 | &w_check, | ||
345 | &realloc, | ||
346 | &free); | ||
347 | /* Disable use of secure memory */ | 335 | /* Disable use of secure memory */ |
348 | if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) | 336 | if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) |
349 | FPRINTF (stderr, | 337 | FPRINTF (stderr, |
350 | "Failed to set libgcrypt option %s: %s\n", | 338 | "Failed to set libgcrypt option %s: %s\n", |
351 | "DISABLE_SECMEM", | 339 | "DISABLE_SECMEM", |
352 | gcry_strerror (rc)); | 340 | gcry_strerror (rc)); |
353 | /* Otherwise gnunet-ecc takes forever to complete, besides | 341 | /* Otherwise gnunet-ecc takes forever to complete, besides |
354 | we are fine with "just" using GCRY_STRONG_RANDOM */ | 342 | we are fine with "just" using GCRY_STRONG_RANDOM */ |
355 | if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) | 343 | if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) |
356 | FPRINTF (stderr, | 344 | FPRINTF (stderr, |
357 | "Failed to set libgcrypt option %s: %s\n", | 345 | "Failed to set libgcrypt option %s: %s\n", |
358 | "ENABLE_QUICK_RANDOM", | 346 | "ENABLE_QUICK_RANDOM", |
359 | gcry_strerror (rc)); | 347 | gcry_strerror (rc)); |
360 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 348 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
361 | gcry_fast_random_poll (); | 349 | gcry_fast_random_poll (); |
362 | GNUNET_CRYPTO_seed_weak_random (time (NULL) ^ | 350 | GNUNET_CRYPTO_seed_weak_random ( |
363 | GNUNET_CRYPTO_random_u32 | 351 | time (NULL) ^ |
364 | (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | 352 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); |
365 | } | 353 | } |
366 | 354 | ||
367 | 355 | ||
368 | /** | 356 | /** |
369 | * Nicely shut down libgcrypt. | 357 | * Nicely shut down libgcrypt. |
370 | */ | 358 | */ |
371 | void __attribute__ ((destructor)) | 359 | void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini () |
372 | GNUNET_CRYPTO_random_fini () | ||
373 | { | 360 | { |
374 | gcry_set_progress_handler (NULL, NULL); | 361 | gcry_set_progress_handler (NULL, NULL); |
375 | #ifdef GCRYCTL_CLOSE_RANDOM_DEVICE | 362 | #ifdef GCRYCTL_CLOSE_RANDOM_DEVICE |
@@ -378,5 +365,4 @@ GNUNET_CRYPTO_random_fini () | |||
378 | } | 365 | } |
379 | 366 | ||
380 | 367 | ||
381 | |||
382 | /* end of crypto_random.c */ | 368 | /* end of crypto_random.c */ |
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index 5e15eb16a..f4149a398 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c | |||
@@ -57,15 +57,13 @@ static char *pwfn; | |||
57 | static void | 57 | static void |
58 | shutdown_task (void *cls) | 58 | shutdown_task (void *cls) |
59 | { | 59 | { |
60 | if (sizeof (proof) != | 60 | (void) cls; |
61 | GNUNET_DISK_fn_write (pwfn, | 61 | if (sizeof (proof) != GNUNET_DISK_fn_write (pwfn, |
62 | &proof, | 62 | &proof, |
63 | sizeof (proof), | 63 | sizeof (proof), |
64 | GNUNET_DISK_PERM_USER_READ | | 64 | GNUNET_DISK_PERM_USER_READ | |
65 | GNUNET_DISK_PERM_USER_WRITE)) | 65 | GNUNET_DISK_PERM_USER_WRITE)) |
66 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 66 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", pwfn); |
67 | "write", | ||
68 | pwfn); | ||
69 | } | 67 | } |
70 | 68 | ||
71 | 69 | ||
@@ -77,17 +75,18 @@ shutdown_task (void *cls) | |||
77 | * @param result where to write the resulting hash | 75 | * @param result where to write the resulting hash |
78 | */ | 76 | */ |
79 | static void | 77 | static void |
80 | pow_hash (const void *buf, | 78 | pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result) |
81 | size_t buf_len, | ||
82 | struct GNUNET_HashCode *result) | ||
83 | { | 79 | { |
84 | GNUNET_break (0 == | 80 | GNUNET_break ( |
85 | gcry_kdf_derive (buf, buf_len, | 81 | 0 == gcry_kdf_derive (buf, |
86 | GCRY_KDF_SCRYPT, | 82 | buf_len, |
87 | 1 /* subalgo */, | 83 | GCRY_KDF_SCRYPT, |
88 | "gnunet-proof-of-work", strlen ("gnunet-proof-of-work"), | 84 | 1 /* subalgo */, |
89 | 2 /* iterations; keep cost of individual op small */, | 85 | "gnunet-proof-of-work", |
90 | sizeof (struct GNUNET_HashCode), result)); | 86 | strlen ("gnunet-proof-of-work"), |
87 | 2 /* iterations; keep cost of individual op small */, | ||
88 | sizeof (struct GNUNET_HashCode), | ||
89 | result)); | ||
91 | } | 90 | } |
92 | 91 | ||
93 | 92 | ||
@@ -118,7 +117,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash) | |||
118 | static void | 117 | static void |
119 | find_proof (void *cls) | 118 | find_proof (void *cls) |
120 | { | 119 | { |
121 | #define ROUND_SIZE 10 | 120 | #define ROUND_SIZE 10 |
122 | uint64_t counter; | 121 | uint64_t counter; |
123 | char buf[sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + | 122 | char buf[sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + |
124 | sizeof (uint64_t)] GNUNET_ALIGN; | 123 | sizeof (uint64_t)] GNUNET_ALIGN; |
@@ -127,12 +126,14 @@ find_proof (void *cls) | |||
127 | struct GNUNET_TIME_Absolute timestamp; | 126 | struct GNUNET_TIME_Absolute timestamp; |
128 | struct GNUNET_TIME_Relative elapsed; | 127 | struct GNUNET_TIME_Relative elapsed; |
129 | 128 | ||
129 | (void) cls; | ||
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
131 | "Got Proof of Work %llu\n", | 131 | "Got Proof of Work %llu\n", |
132 | (unsigned long long) proof); | 132 | (unsigned long long) proof); |
133 | proof_task = NULL; | 133 | proof_task = NULL; |
134 | GNUNET_memcpy (&buf[sizeof (uint64_t)], &pub, | 134 | GNUNET_memcpy (&buf[sizeof (uint64_t)], |
135 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | 135 | &pub, |
136 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); | ||
136 | i = 0; | 137 | i = 0; |
137 | counter = proof; | 138 | counter = proof; |
138 | timestamp = GNUNET_TIME_absolute_get (); | 139 | timestamp = GNUNET_TIME_absolute_get (); |
@@ -143,7 +144,8 @@ find_proof (void *cls) | |||
143 | if (nse_work_required <= count_leading_zeroes (&result)) | 144 | if (nse_work_required <= count_leading_zeroes (&result)) |
144 | { | 145 | { |
145 | proof = counter; | 146 | proof = counter; |
146 | FPRINTF (stdout, "Proof of work found: %llu!\n", | 147 | FPRINTF (stdout, |
148 | "Proof of work found: %llu!\n", | ||
147 | (unsigned long long) proof); | 149 | (unsigned long long) proof); |
148 | GNUNET_SCHEDULER_shutdown (); | 150 | GNUNET_SCHEDULER_shutdown (); |
149 | return; | 151 | return; |
@@ -159,7 +161,8 @@ find_proof (void *cls) | |||
159 | GNUNET_STRINGS_relative_time_to_string (elapsed, 0)); | 161 | GNUNET_STRINGS_relative_time_to_string (elapsed, 0)); |
160 | if (proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) | 162 | if (proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE)) |
161 | { | 163 | { |
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing proofs currently at %llu\n", | 164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
165 | "Testing proofs currently at %llu\n", | ||
163 | (unsigned long long) counter); | 166 | (unsigned long long) counter); |
164 | /* remember progress every 100 rounds */ | 167 | /* remember progress every 100 rounds */ |
165 | proof = counter; | 168 | proof = counter; |
@@ -171,8 +174,9 @@ find_proof (void *cls) | |||
171 | } | 174 | } |
172 | proof_task = | 175 | proof_task = |
173 | GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, | 176 | GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay, |
174 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 177 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
175 | &find_proof, NULL); | 178 | &find_proof, |
179 | NULL); | ||
176 | } | 180 | } |
177 | 181 | ||
178 | 182 | ||
@@ -193,54 +197,46 @@ run (void *cls, | |||
193 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 197 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
194 | char *pids; | 198 | char *pids; |
195 | 199 | ||
200 | (void) cls; | ||
201 | (void) args; | ||
202 | (void) cfgfile; | ||
196 | cfg = config; | 203 | cfg = config; |
197 | /* load proof of work */ | 204 | /* load proof of work */ |
198 | if (NULL == pwfn) | 205 | if (NULL == pwfn) |
199 | { | 206 | { |
200 | if (GNUNET_OK != | 207 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
201 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 208 | "NSE", |
202 | "NSE", | 209 | "PROOFFILE", |
203 | "PROOFFILE", | 210 | &pwfn)) |
204 | &pwfn)) | ||
205 | { | 211 | { |
206 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 212 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE"); |
207 | "NSE", | ||
208 | "PROOFFILE"); | ||
209 | GNUNET_SCHEDULER_shutdown (); | 213 | GNUNET_SCHEDULER_shutdown (); |
210 | return; | 214 | return; |
211 | } | 215 | } |
212 | } | 216 | } |
213 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 217 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Proof of Work file: %s\n", pwfn); |
214 | "Proof of Work file: %s\n", | 218 | if ((GNUNET_YES != GNUNET_DISK_file_test (pwfn)) || |
215 | pwfn); | 219 | (sizeof (proof) != GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof)))) |
216 | if ( (GNUNET_YES != GNUNET_DISK_file_test (pwfn)) || | ||
217 | (sizeof (proof) != | ||
218 | GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof)))) | ||
219 | proof = 0; | 220 | proof = 0; |
220 | 221 | ||
221 | /* load private key */ | 222 | /* load private key */ |
222 | if (NULL == pkfn) | 223 | if (NULL == pkfn) |
223 | { | 224 | { |
224 | if (GNUNET_OK != | 225 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
225 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 226 | "PEER", |
226 | "PEER", | 227 | "PRIVATE_KEY", |
227 | "PRIVATE_KEY", | 228 | &pkfn)) |
228 | &pkfn)) | ||
229 | { | 229 | { |
230 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 230 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
231 | "PEER", | 231 | "PEER", |
232 | "PRIVATE_KEY"); | 232 | "PRIVATE_KEY"); |
233 | return; | 233 | return; |
234 | } | 234 | } |
235 | } | 235 | } |
236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn); |
237 | "Private Key file: %s\n", | ||
238 | pkfn); | ||
239 | if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn))) | 237 | if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn))) |
240 | { | 238 | { |
241 | FPRINTF (stderr, | 239 | FPRINTF (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn); |
242 | _("Loading hostkey from `%s' failed.\n"), | ||
243 | pkfn); | ||
244 | GNUNET_free (pkfn); | 240 | GNUNET_free (pkfn); |
245 | return; | 241 | return; |
246 | } | 242 | } |
@@ -248,32 +244,27 @@ run (void *cls, | |||
248 | GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub); | 244 | GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub); |
249 | GNUNET_free (pk); | 245 | GNUNET_free (pk); |
250 | pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); | 246 | pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); |
251 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", pids); |
252 | "Peer ID: %s\n", | ||
253 | pids); | ||
254 | GNUNET_free (pids); | 248 | GNUNET_free (pids); |
255 | 249 | ||
256 | /* get target bit amount */ | 250 | /* get target bit amount */ |
257 | if (0 == nse_work_required) | 251 | if (0 == nse_work_required) |
258 | { | 252 | { |
259 | if (GNUNET_OK != | 253 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
260 | GNUNET_CONFIGURATION_get_value_number (cfg, | 254 | "NSE", |
261 | "NSE", | 255 | "WORKBITS", |
262 | "WORKBITS", | 256 | &nse_work_required)) |
263 | &nse_work_required)) | ||
264 | { | 257 | { |
265 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 258 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS"); |
266 | "NSE", | ||
267 | "WORKBITS"); | ||
268 | GNUNET_SCHEDULER_shutdown (); | 259 | GNUNET_SCHEDULER_shutdown (); |
269 | return; | 260 | return; |
270 | } | 261 | } |
271 | if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) | 262 | if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) |
272 | { | 263 | { |
273 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 264 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
274 | "NSE", | 265 | "NSE", |
275 | "WORKBITS", | 266 | "WORKBITS", |
276 | _("Value is too large.\n")); | 267 | _ ("Value is too large.\n")); |
277 | GNUNET_SCHEDULER_shutdown (); | 268 | GNUNET_SCHEDULER_shutdown (); |
278 | return; | 269 | return; |
279 | } | 270 | } |
@@ -283,19 +274,16 @@ run (void *cls, | |||
283 | return; | 274 | return; |
284 | } | 275 | } |
285 | } | 276 | } |
286 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 277 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bits: %llu\n", nse_work_required); |
287 | "Bits: %llu\n", | ||
288 | nse_work_required); | ||
289 | 278 | ||
290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
291 | "Delay between tries: %s\n", | 280 | "Delay between tries: %s\n", |
292 | GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1)); | 281 | GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1)); |
293 | proof_task = | 282 | proof_task = |
294 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 283 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
295 | &find_proof, | 284 | &find_proof, |
296 | NULL); | 285 | NULL); |
297 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 286 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
298 | NULL); | ||
299 | } | 287 | } |
300 | 288 | ||
301 | 289 | ||
@@ -307,46 +295,51 @@ run (void *cls, | |||
307 | * @return 0 ok, 1 on error | 295 | * @return 0 ok, 1 on error |
308 | */ | 296 | */ |
309 | int | 297 | int |
310 | main (int argc, | 298 | main (int argc, char *const *argv) |
311 | char *const *argv) | ||
312 | { | 299 | { |
313 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 300 | struct GNUNET_GETOPT_CommandLineOption options[] = |
314 | GNUNET_GETOPT_option_ulong ('b', | 301 | {GNUNET_GETOPT_option_ulong ( |
315 | "bits", | 302 | 'b', |
316 | "BITS", | 303 | "bits", |
317 | gettext_noop ("number of bits to require for the proof of work"), | 304 | "BITS", |
318 | &nse_work_required), | 305 | gettext_noop ("number of bits to require for the proof of work"), |
319 | GNUNET_GETOPT_option_filename ('k', | 306 | &nse_work_required), |
320 | "keyfile", | 307 | GNUNET_GETOPT_option_filename ( |
321 | "FILE", | 308 | 'k', |
322 | gettext_noop ("file with private key, otherwise default is used"), | 309 | "keyfile", |
323 | &pkfn), | 310 | "FILE", |
324 | GNUNET_GETOPT_option_filename ('o', | 311 | gettext_noop ("file with private key, otherwise default is used"), |
325 | "outfile", | 312 | &pkfn), |
326 | "FILE", | 313 | GNUNET_GETOPT_option_filename ( |
327 | gettext_noop ("file with proof of work, otherwise default is used"), | 314 | 'o', |
328 | &pwfn), | 315 | "outfile", |
329 | GNUNET_GETOPT_option_relative_time ('t', | 316 | "FILE", |
330 | "timeout", | 317 | gettext_noop ("file with proof of work, otherwise default is used"), |
331 | "TIME", | 318 | &pwfn), |
332 | gettext_noop ("time to wait between calculations"), | 319 | GNUNET_GETOPT_option_relative_time ('t', |
333 | &proof_find_delay), | 320 | "timeout", |
334 | GNUNET_GETOPT_OPTION_END | 321 | "TIME", |
335 | }; | 322 | gettext_noop ( |
323 | "time to wait between calculations"), | ||
324 | &proof_find_delay), | ||
325 | GNUNET_GETOPT_OPTION_END}; | ||
336 | int ret; | 326 | int ret; |
337 | 327 | ||
338 | if (GNUNET_OK != | 328 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
339 | GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
340 | return 2; | 329 | return 2; |
341 | 330 | ||
342 | ret = (GNUNET_OK == | 331 | ret = |
343 | GNUNET_PROGRAM_run (argc, argv, | 332 | (GNUNET_OK == |
344 | "gnunet-scrypt [OPTIONS] prooffile", | 333 | GNUNET_PROGRAM_run (argc, |
345 | gettext_noop ("Manipulate GNUnet proof of work files"), | 334 | argv, |
346 | options, | 335 | "gnunet-scrypt [OPTIONS] prooffile", |
347 | &run, | 336 | gettext_noop ("Manipulate GNUnet proof of work files"), |
348 | NULL)) ? 0 : 1; | 337 | options, |
349 | GNUNET_free ((void*) argv); | 338 | &run, |
339 | NULL)) | ||
340 | ? 0 | ||
341 | : 1; | ||
342 | GNUNET_free ((void *) argv); | ||
350 | GNUNET_free_non_null (pwfn); | 343 | GNUNET_free_non_null (pwfn); |
351 | return ret; | 344 | return ret; |
352 | } | 345 | } |
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c index 58f9e331c..33ff7b1e6 100644 --- a/src/util/gnunet-uri.c +++ b/src/util/gnunet-uri.c | |||
@@ -53,9 +53,9 @@ maint_child_death (void *cls) | |||
53 | { | 53 | { |
54 | enum GNUNET_OS_ProcessStatusType type; | 54 | enum GNUNET_OS_ProcessStatusType type; |
55 | 55 | ||
56 | if ( (GNUNET_OK != | 56 | (void) cls; |
57 | GNUNET_OS_process_status (p, &type, &exit_code)) || | 57 | if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) || |
58 | (type != GNUNET_OS_PROCESS_EXITED) ) | 58 | (type != GNUNET_OS_PROCESS_EXITED)) |
59 | GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); | 59 | GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); |
60 | GNUNET_OS_process_destroy (p); | 60 | GNUNET_OS_process_destroy (p); |
61 | } | 61 | } |
@@ -70,56 +70,60 @@ maint_child_death (void *cls) | |||
70 | * @param cfg configuration | 70 | * @param cfg configuration |
71 | */ | 71 | */ |
72 | static void | 72 | static void |
73 | run (void *cls, char *const *args, const char *cfgfile, | 73 | run (void *cls, |
74 | char *const *args, | ||
75 | const char *cfgfile, | ||
74 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 76 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
75 | { | 77 | { |
76 | const char *uri; | 78 | const char *uri; |
77 | const char *slash; | 79 | const char *slash; |
78 | char *subsystem; | 80 | char *subsystem; |
79 | char *program; | 81 | char *program; |
80 | struct GNUNET_SCHEDULER_Task * rt; | 82 | struct GNUNET_SCHEDULER_Task *rt; |
81 | 83 | ||
84 | (void) cls; | ||
85 | (void) cfgfile; | ||
82 | if (NULL == (uri = args[0])) | 86 | if (NULL == (uri = args[0])) |
83 | { | 87 | { |
84 | fprintf (stderr, | 88 | fprintf (stderr, _ ("No URI specified on command line\n")); |
85 | _("No URI specified on command line\n")); | ||
86 | return; | 89 | return; |
87 | } | 90 | } |
88 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) | 91 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) |
89 | { | 92 | { |
90 | fprintf (stderr, | 93 | fprintf (stderr, |
91 | _("Invalid URI: does not start with `%s'\n"), | 94 | _ ("Invalid URI: does not start with `%s'\n"), |
92 | "gnunet://"); | 95 | "gnunet://"); |
93 | return; | 96 | return; |
94 | } | 97 | } |
95 | uri += strlen ("gnunet://"); | 98 | uri += strlen ("gnunet://"); |
96 | if (NULL == (slash = strchr (uri, '/'))) | 99 | if (NULL == (slash = strchr (uri, '/'))) |
97 | { | 100 | { |
98 | fprintf (stderr, _("Invalid URI: fails to specify subsystem\n")); | 101 | fprintf (stderr, _ ("Invalid URI: fails to specify subsystem\n")); |
99 | return; | 102 | return; |
100 | } | 103 | } |
101 | subsystem = GNUNET_strndup (uri, slash - uri); | 104 | subsystem = GNUNET_strndup (uri, slash - uri); |
102 | if (GNUNET_OK != | 105 | if (GNUNET_OK != |
103 | GNUNET_CONFIGURATION_get_value_string (cfg, | 106 | GNUNET_CONFIGURATION_get_value_string (cfg, "uri", subsystem, &program)) |
104 | "uri", | ||
105 | subsystem, | ||
106 | &program)) | ||
107 | { | 107 | { |
108 | fprintf (stderr, _("No handler known for subsystem `%s'\n"), subsystem); | 108 | fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem); |
109 | GNUNET_free (subsystem); | 109 | GNUNET_free (subsystem); |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | GNUNET_free (subsystem); | 112 | GNUNET_free (subsystem); |
113 | rt = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 113 | rt = GNUNET_SCHEDULER_add_read_file ( |
114 | GNUNET_DISK_pipe_handle (sigpipe, | 114 | GNUNET_TIME_UNIT_FOREVER_REL, |
115 | GNUNET_DISK_PIPE_END_READ), | 115 | GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), |
116 | &maint_child_death, NULL); | 116 | &maint_child_death, |
117 | p = GNUNET_OS_start_process (GNUNET_NO, 0, | 117 | NULL); |
118 | NULL, NULL, NULL, | 118 | p = GNUNET_OS_start_process (GNUNET_NO, |
119 | program, | 119 | 0, |
120 | program, | 120 | NULL, |
121 | args[0], | 121 | NULL, |
122 | NULL); | 122 | NULL, |
123 | program, | ||
124 | program, | ||
125 | args[0], | ||
126 | NULL); | ||
123 | GNUNET_free (program); | 127 | GNUNET_free (program); |
124 | if (NULL == p) | 128 | if (NULL == p) |
125 | GNUNET_SCHEDULER_cancel (rt); | 129 | GNUNET_SCHEDULER_cancel (rt); |
@@ -134,13 +138,15 @@ static void | |||
134 | sighandler_child_death () | 138 | sighandler_child_death () |
135 | { | 139 | { |
136 | static char c; | 140 | static char c; |
137 | int old_errno = errno; /* back-up errno */ | 141 | int old_errno = errno; /* back-up errno */ |
138 | 142 | ||
139 | GNUNET_break (1 == | 143 | GNUNET_break ( |
140 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle | 144 | 1 == |
141 | (sigpipe, GNUNET_DISK_PIPE_END_WRITE), | 145 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, |
142 | &c, sizeof (c))); | 146 | GNUNET_DISK_PIPE_END_WRITE), |
143 | errno = old_errno; /* restore errno */ | 147 | &c, |
148 | sizeof (c))); | ||
149 | errno = old_errno; /* restore errno */ | ||
144 | } | 150 | } |
145 | 151 | ||
146 | 152 | ||
@@ -155,8 +161,7 @@ int | |||
155 | main (int argc, char *const *argv) | 161 | main (int argc, char *const *argv) |
156 | { | 162 | { |
157 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 163 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
158 | GNUNET_GETOPT_OPTION_END | 164 | GNUNET_GETOPT_OPTION_END}; |
159 | }; | ||
160 | struct GNUNET_SIGNAL_Context *shc_chld; | 165 | struct GNUNET_SIGNAL_Context *shc_chld; |
161 | int ret; | 166 | int ret; |
162 | 167 | ||
@@ -166,9 +171,14 @@ main (int argc, char *const *argv) | |||
166 | GNUNET_assert (sigpipe != NULL); | 171 | GNUNET_assert (sigpipe != NULL); |
167 | shc_chld = | 172 | shc_chld = |
168 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 173 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); |
169 | ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-uri URI", | 174 | ret = GNUNET_PROGRAM_run (argc, |
170 | gettext_noop ("Perform default-actions for GNUnet URIs"), | 175 | argv, |
171 | options, &run, NULL); | 176 | "gnunet-uri URI", |
177 | gettext_noop ( | ||
178 | "Perform default-actions for GNUnet URIs"), | ||
179 | options, | ||
180 | &run, | ||
181 | NULL); | ||
172 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 182 | GNUNET_SIGNAL_handler_uninstall (shc_chld); |
173 | shc_chld = NULL; | 183 | shc_chld = NULL; |
174 | GNUNET_DISK_pipe_close (sigpipe); | 184 | GNUNET_DISK_pipe_close (sigpipe); |
diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c index b8f2bef91..5c3709206 100644 --- a/src/util/test_common_logging_dummy.c +++ b/src/util/test_common_logging_dummy.c | |||
@@ -35,12 +35,20 @@ | |||
35 | * This must be long enough for us to not to mistake skipped log call | 35 | * This must be long enough for us to not to mistake skipped log call |
36 | * on a slow machine for a non-skipped one. | 36 | * on a slow machine for a non-skipped one. |
37 | */ | 37 | */ |
38 | #define OUTPUT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000) | 38 | #define OUTPUT_DELAY \ |
39 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000) | ||
39 | 40 | ||
40 | static void | 41 | static void |
41 | my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, | 42 | my_log (void *ctx, |
42 | const char *date, const char *msg) | 43 | enum GNUNET_ErrorType kind, |
44 | const char *component, | ||
45 | const char *date, | ||
46 | const char *msg) | ||
43 | { | 47 | { |
48 | (void) ctx; | ||
49 | (void) kind; | ||
50 | (void) component; | ||
51 | (void) date; | ||
44 | if (strncmp ("test-common-logging-dummy", component, 25) != 0) | 52 | if (strncmp ("test-common-logging-dummy", component, 25) != 0) |
45 | return; | 53 | return; |
46 | FPRINTF (stdout, "%s", msg); | 54 | FPRINTF (stdout, "%s", msg); |
@@ -48,7 +56,7 @@ my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component, | |||
48 | } | 56 | } |
49 | 57 | ||
50 | 58 | ||
51 | #if !defined(GNUNET_CULL_LOGGING) | 59 | #if ! defined(GNUNET_CULL_LOGGING) |
52 | static int | 60 | static int |
53 | expensive_func () | 61 | expensive_func () |
54 | { | 62 | { |
@@ -57,27 +65,36 @@ expensive_func () | |||
57 | #endif | 65 | #endif |
58 | 66 | ||
59 | 67 | ||
60 | #define pr(kind,lvl) {\ | 68 | #define pr(kind, lvl) \ |
61 | struct GNUNET_TIME_Absolute t1, t2;\ | 69 | { \ |
62 | t1 = GNUNET_TIME_absolute_get ();\ | 70 | struct GNUNET_TIME_Absolute t1, t2; \ |
63 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\ | 71 | t1 = GNUNET_TIME_absolute_get (); \ |
64 | t2 = GNUNET_TIME_absolute_get ();\ | 72 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \ |
65 | printf ("1%s %llu\n", lvl,\ | 73 | t2 = GNUNET_TIME_absolute_get (); \ |
66 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \ | 74 | printf ("1%s %llu\n", \ |
67 | } | 75 | lvl, \ |
76 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \ | ||
77 | .rel_value_us); \ | ||
78 | } | ||
79 | |||
80 | #define pr2(kind, lvl) \ | ||
81 | { \ | ||
82 | struct GNUNET_TIME_Absolute t1, t2; \ | ||
83 | t1 = GNUNET_TIME_absolute_get (); \ | ||
84 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \ | ||
85 | t2 = GNUNET_TIME_absolute_get (); \ | ||
86 | printf ("2%s %llu\n", \ | ||
87 | lvl, \ | ||
88 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \ | ||
89 | .rel_value_us); \ | ||
90 | } | ||
68 | 91 | ||
69 | #define pr2(kind,lvl) {\ | ||
70 | struct GNUNET_TIME_Absolute t1, t2;\ | ||
71 | t1 = GNUNET_TIME_absolute_get ();\ | ||
72 | GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\ | ||
73 | t2 = GNUNET_TIME_absolute_get ();\ | ||
74 | printf ("2%s %llu\n", lvl,\ | ||
75 | (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \ | ||
76 | } | ||
77 | 92 | ||
78 | int | 93 | int |
79 | main (int argc, char *argv[]) | 94 | main (int argc, char *argv[]) |
80 | { | 95 | { |
96 | (void) argc; | ||
97 | (void) argv; | ||
81 | /* We set up logging with NULL level - will be overrided by | 98 | /* We set up logging with NULL level - will be overrided by |
82 | * GNUNET_LOG or GNUNET_FORCE_LOG at runtime. | 99 | * GNUNET_LOG or GNUNET_FORCE_LOG at runtime. |
83 | */ | 100 | */ |
@@ -97,6 +114,6 @@ main (int argc, char *argv[]) | |||
97 | pr2 (GNUNET_ERROR_TYPE_INFO, "INFO"); | 114 | pr2 (GNUNET_ERROR_TYPE_INFO, "INFO"); |
98 | pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG"); | 115 | pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG"); |
99 | return 0; | 116 | return 0; |
100 | } /* end of main */ | 117 | } /* end of main */ |
101 | 118 | ||
102 | /* end of test_common_logging_dummy.c */ | 119 | /* end of test_common_logging_dummy.c */ |
diff --git a/src/util/tun.c b/src/util/tun.c index 97fbaa83b..e3643d0c6 100644 --- a/src/util/tun.c +++ b/src/util/tun.c | |||
@@ -44,24 +44,27 @@ | |||
44 | */ | 44 | */ |
45 | void | 45 | void |
46 | GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, | 46 | GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, |
47 | uint8_t protocol, | 47 | uint8_t protocol, |
48 | uint16_t payload_length, | 48 | uint16_t payload_length, |
49 | const struct in_addr *src, | 49 | const struct in_addr *src, |
50 | const struct in_addr *dst) | 50 | const struct in_addr *dst) |
51 | { | 51 | { |
52 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_IPv4Header)); | 52 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_IPv4Header)); |
53 | GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header)); | 53 | GNUNET_assert (payload_length <= |
54 | UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header)); | ||
54 | memset (ip, 0, sizeof (struct GNUNET_TUN_IPv4Header)); | 55 | memset (ip, 0, sizeof (struct GNUNET_TUN_IPv4Header)); |
55 | ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; | 56 | ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4; |
56 | ip->version = 4; | 57 | ip->version = 4; |
57 | ip->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length); | 58 | ip->total_length = |
58 | ip->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 59 | htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length); |
59 | 65536); | 60 | ip->identification = |
61 | (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 65536); | ||
60 | ip->ttl = FRESH_TTL; | 62 | ip->ttl = FRESH_TTL; |
61 | ip->protocol = protocol; | 63 | ip->protocol = protocol; |
62 | ip->source_address = *src; | 64 | ip->source_address = *src; |
63 | ip->destination_address = *dst; | 65 | ip->destination_address = *dst; |
64 | ip->checksum = GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header)); | 66 | ip->checksum = |
67 | GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header)); | ||
65 | } | 68 | } |
66 | 69 | ||
67 | 70 | ||
@@ -76,13 +79,14 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, | |||
76 | */ | 79 | */ |
77 | void | 80 | void |
78 | GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, | 81 | GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, |
79 | uint8_t protocol, | 82 | uint8_t protocol, |
80 | uint16_t payload_length, | 83 | uint16_t payload_length, |
81 | const struct in6_addr *src, | 84 | const struct in6_addr *src, |
82 | const struct in6_addr *dst) | 85 | const struct in6_addr *dst) |
83 | { | 86 | { |
84 | GNUNET_assert (40 == sizeof (struct GNUNET_TUN_IPv6Header)); | 87 | GNUNET_assert (40 == sizeof (struct GNUNET_TUN_IPv6Header)); |
85 | GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header)); | 88 | GNUNET_assert (payload_length <= |
89 | UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header)); | ||
86 | memset (ip, 0, sizeof (struct GNUNET_TUN_IPv6Header)); | 90 | memset (ip, 0, sizeof (struct GNUNET_TUN_IPv6Header)); |
87 | ip->version = 6; | 91 | ip->version = 6; |
88 | ip->next_header = protocol; | 92 | ip->next_header = protocol; |
@@ -103,27 +107,29 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, | |||
103 | */ | 107 | */ |
104 | void | 108 | void |
105 | GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | 109 | GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, |
106 | struct GNUNET_TUN_TcpHeader *tcp, | 110 | struct GNUNET_TUN_TcpHeader *tcp, |
107 | const void *payload, | 111 | const void *payload, |
108 | uint16_t payload_length) | 112 | uint16_t payload_length) |
109 | { | 113 | { |
110 | uint32_t sum; | 114 | uint32_t sum; |
111 | uint16_t tmp; | 115 | uint16_t tmp; |
112 | 116 | ||
113 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); | 117 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); |
114 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_TcpHeader) == | 118 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + |
115 | ntohs (ip->total_length)); | 119 | sizeof (struct GNUNET_TUN_TcpHeader) == |
120 | ntohs (ip->total_length)); | ||
116 | GNUNET_assert (IPPROTO_TCP == ip->protocol); | 121 | GNUNET_assert (IPPROTO_TCP == ip->protocol); |
117 | 122 | ||
118 | tcp->crc = 0; | 123 | tcp->crc = 0; |
119 | sum = GNUNET_CRYPTO_crc16_step (0, | 124 | sum = GNUNET_CRYPTO_crc16_step (0, |
120 | &ip->source_address, | 125 | &ip->source_address, |
121 | sizeof (struct in_addr) * 2); | 126 | sizeof (struct in_addr) * 2); |
122 | tmp = htons (IPPROTO_TCP); | 127 | tmp = htons (IPPROTO_TCP); |
123 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); | 128 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); |
124 | tmp = htons (payload_length + sizeof (struct GNUNET_TUN_TcpHeader)); | 129 | tmp = htons (payload_length + sizeof (struct GNUNET_TUN_TcpHeader)); |
125 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); | 130 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); |
126 | sum = GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader)); | 131 | sum = |
132 | GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader)); | ||
127 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); | 133 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
128 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 134 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
129 | } | 135 | } |
@@ -139,25 +145,27 @@ GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | |||
139 | */ | 145 | */ |
140 | void | 146 | void |
141 | GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | 147 | GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, |
142 | struct GNUNET_TUN_TcpHeader *tcp, | 148 | struct GNUNET_TUN_TcpHeader *tcp, |
143 | const void *payload, | 149 | const void *payload, |
144 | uint16_t payload_length) | 150 | uint16_t payload_length) |
145 | { | 151 | { |
146 | uint32_t sum; | 152 | uint32_t sum; |
147 | uint32_t tmp; | 153 | uint32_t tmp; |
148 | 154 | ||
149 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); | 155 | GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader)); |
150 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_TcpHeader) == | 156 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_TcpHeader) == |
151 | ntohs (ip->payload_length)); | 157 | ntohs (ip->payload_length)); |
152 | GNUNET_assert (IPPROTO_TCP == ip->next_header); | 158 | GNUNET_assert (IPPROTO_TCP == ip->next_header); |
153 | tcp->crc = 0; | 159 | tcp->crc = 0; |
154 | sum = GNUNET_CRYPTO_crc16_step (0, &ip->source_address, 2 * sizeof (struct in6_addr)); | 160 | sum = GNUNET_CRYPTO_crc16_step (0, |
161 | &ip->source_address, | ||
162 | 2 * sizeof (struct in6_addr)); | ||
155 | tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length); | 163 | tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length); |
156 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | 164 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); |
157 | tmp = htonl (IPPROTO_TCP); | 165 | tmp = htonl (IPPROTO_TCP); |
158 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | 166 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); |
159 | sum = GNUNET_CRYPTO_crc16_step (sum, tcp, | 167 | sum = |
160 | sizeof (struct GNUNET_TUN_TcpHeader)); | 168 | GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader)); |
161 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); | 169 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
162 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 170 | tcp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
163 | } | 171 | } |
@@ -173,36 +181,31 @@ GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | |||
173 | */ | 181 | */ |
174 | void | 182 | void |
175 | GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | 183 | GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, |
176 | struct GNUNET_TUN_UdpHeader *udp, | 184 | struct GNUNET_TUN_UdpHeader *udp, |
177 | const void *payload, | 185 | const void *payload, |
178 | uint16_t payload_length) | 186 | uint16_t payload_length) |
179 | { | 187 | { |
180 | uint32_t sum; | 188 | uint32_t sum; |
181 | uint16_t tmp; | 189 | uint16_t tmp; |
182 | 190 | ||
183 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); | 191 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); |
184 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_UdpHeader) == | 192 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + |
185 | ntohs (ip->total_length)); | 193 | sizeof (struct GNUNET_TUN_UdpHeader) == |
194 | ntohs (ip->total_length)); | ||
186 | GNUNET_assert (IPPROTO_UDP == ip->protocol); | 195 | GNUNET_assert (IPPROTO_UDP == ip->protocol); |
187 | 196 | ||
188 | udp->crc = 0; /* technically optional, but we calculate it anyway, just to be sure */ | 197 | udp->crc = |
198 | 0; /* technically optional, but we calculate it anyway, just to be sure */ | ||
189 | sum = GNUNET_CRYPTO_crc16_step (0, | 199 | sum = GNUNET_CRYPTO_crc16_step (0, |
190 | &ip->source_address, | 200 | &ip->source_address, |
191 | sizeof (struct in_addr) * 2); | 201 | sizeof (struct in_addr) * 2); |
192 | tmp = htons (IPPROTO_UDP); | 202 | tmp = htons (IPPROTO_UDP); |
193 | sum = GNUNET_CRYPTO_crc16_step (sum, | 203 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); |
194 | &tmp, | ||
195 | sizeof (uint16_t)); | ||
196 | tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); | 204 | tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); |
197 | sum = GNUNET_CRYPTO_crc16_step (sum, | 205 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t)); |
198 | &tmp, | 206 | sum = |
199 | sizeof (uint16_t)); | 207 | GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader)); |
200 | sum = GNUNET_CRYPTO_crc16_step (sum, | 208 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
201 | udp, | ||
202 | sizeof (struct GNUNET_TUN_UdpHeader)); | ||
203 | sum = GNUNET_CRYPTO_crc16_step (sum, | ||
204 | payload, | ||
205 | payload_length); | ||
206 | udp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 209 | udp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
207 | } | 210 | } |
208 | 211 | ||
@@ -217,28 +220,30 @@ GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, | |||
217 | */ | 220 | */ |
218 | void | 221 | void |
219 | GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | 222 | GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, |
220 | struct GNUNET_TUN_UdpHeader *udp, | 223 | struct GNUNET_TUN_UdpHeader *udp, |
221 | const void *payload, | 224 | const void *payload, |
222 | uint16_t payload_length) | 225 | uint16_t payload_length) |
223 | { | 226 | { |
224 | uint32_t sum; | 227 | uint32_t sum; |
225 | uint32_t tmp; | 228 | uint32_t tmp; |
226 | 229 | ||
227 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == | 230 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == |
228 | ntohs (ip->payload_length)); | 231 | ntohs (ip->payload_length)); |
229 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == | 232 | GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) == |
230 | ntohs (udp->len)); | 233 | ntohs (udp->len)); |
231 | GNUNET_assert (IPPROTO_UDP == ip->next_header); | 234 | GNUNET_assert (IPPROTO_UDP == ip->next_header); |
232 | 235 | ||
233 | udp->crc = 0; | 236 | udp->crc = 0; |
234 | sum = GNUNET_CRYPTO_crc16_step (0, | 237 | sum = GNUNET_CRYPTO_crc16_step (0, |
235 | &ip->source_address, | 238 | &ip->source_address, |
236 | sizeof (struct in6_addr) * 2); | 239 | sizeof (struct in6_addr) * 2); |
237 | tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); /* aka udp->len */ | 240 | tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + |
241 | payload_length); /* aka udp->len */ | ||
238 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | 242 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); |
239 | tmp = htons (ip->next_header); | 243 | tmp = htons (ip->next_header); |
240 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); | 244 | sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t)); |
241 | sum = GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader)); | 245 | sum = |
246 | GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader)); | ||
242 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); | 247 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
243 | udp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 248 | udp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
244 | } | 249 | } |
@@ -253,16 +258,15 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, | |||
253 | */ | 258 | */ |
254 | void | 259 | void |
255 | GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, | 260 | GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, |
256 | const void *payload, | 261 | const void *payload, |
257 | uint16_t payload_length) | 262 | uint16_t payload_length) |
258 | { | 263 | { |
259 | uint32_t sum; | 264 | uint32_t sum; |
260 | 265 | ||
261 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_IcmpHeader)); | 266 | GNUNET_assert (8 == sizeof (struct GNUNET_TUN_IcmpHeader)); |
262 | icmp->crc = 0; | 267 | icmp->crc = 0; |
263 | sum = GNUNET_CRYPTO_crc16_step (0, | 268 | sum = |
264 | icmp, | 269 | GNUNET_CRYPTO_crc16_step (0, icmp, sizeof (struct GNUNET_TUN_IcmpHeader)); |
265 | sizeof (struct GNUNET_TUN_IcmpHeader)); | ||
266 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); | 270 | sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length); |
267 | icmp->crc = GNUNET_CRYPTO_crc16_finish (sum); | 271 | icmp->crc = GNUNET_CRYPTO_crc16_finish (sum); |
268 | } | 272 | } |
@@ -286,21 +290,22 @@ GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa, | |||
286 | 290 | ||
287 | switch (sa->sa_family) | 291 | switch (sa->sa_family) |
288 | { | 292 | { |
289 | case AF_INET: | 293 | case AF_INET: { |
290 | { | 294 | const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa; |
291 | const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa; | 295 | const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb; |
292 | const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb; | 296 | if ((include_port) && (sa4->sin_port != sb4->sin_port)) |
293 | return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr); | 297 | return GNUNET_NO; |
294 | } | 298 | return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr); |
295 | case AF_INET6: | 299 | } |
296 | { | 300 | case AF_INET6: { |
297 | const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa; | 301 | const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa; |
298 | const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb; | 302 | const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb; |
299 | 303 | ||
300 | return (0 == memcmp(&sa6->sin6_addr, | 304 | if ((include_port) && (sa6->sin6_port != sb6->sin6_port)) |
301 | &sb6->sin6_addr, | 305 | return GNUNET_NO; |
302 | sizeof (struct in6_addr))); | 306 | return ( |
303 | } | 307 | 0 == memcmp (&sa6->sin6_addr, &sb6->sin6_addr, sizeof (struct in6_addr))); |
308 | } | ||
304 | default: | 309 | default: |
305 | GNUNET_break (0); | 310 | GNUNET_break (0); |
306 | return GNUNET_SYSERR; | 311 | return GNUNET_SYSERR; |