35#define LOG(kind, ...) GNUNET_log_from (kind, "rps-test_util", __VA_ARGS__)
37#define B2B_PAT "%c%c%c%c%c%c%c%c"
39 (byte & 0x80 ? '1' : '0'), \
40 (byte & 0x40 ? '1' : '0'), \
41 (byte & 0x20 ? '1' : '0'), \
42 (byte & 0x10 ? '1' : '0'), \
43 (byte & 0x08 ? '1' : '0'), \
44 (byte & 0x04 ? '1' : '0'), \
45 (byte & 0x02 ? '1' : '0'), \
46 (byte & 0x01 ? '1' : '0')
84 "Created map of open files.\n");
102 "Opening file `%s' failed.\n",
184 "Not able to open file %s\n",
190 if (size_buf != size_written)
193 "Unable to write to file! (Size: %llu, size_written: %llu)\n",
194 (
unsigned long long) size_buf,
195 (
unsigned long long) size_written);
199 "Unable to close file\n");
204 "Wrote %llu bytes raw.\n",
205 (
unsigned long long) size_written);
208 "Unable to close file\n");
216 unsigned bits_needed)
233 "Was asked to write %u bits\n", bits_needed);
235 char buf_write[size_buf + 1];
236 const unsigned bytes_iter = (0 != bits_needed % 8 ?
237 (bits_needed / 8) + 1 :
240 unsigned size_buf_write = 0;
242 "num_bits_buf_unaligned: %u\n",
245 "ua args: size_buf: %llu, bits_needed: %u -> iter: %u\n",
246 (
unsigned long long) size_buf,
251 for (
unsigned i = 0; i < bytes_iter; i++)
254 unsigned num_bits_needed_iter;
256 unsigned mask_bits_needed_iter;
259 unsigned num_bits_to_align;
261 unsigned num_bits_to_move;
263 char mask_input_to_move;
267 unsigned distance_shift_bits;
273 char mask_input_leftover;
275 char byte_input_leftover;
276 unsigned num_bits_leftover;
278 char byte_unaligned_new;
280 if ((bits_needed - (i * 8)) <= 8)
283 num_bits_needed_iter = bits_needed - (i * 8);
287 num_bits_needed_iter = 8;
290 "number of bits needed in this iteration: %u\n",
291 num_bits_needed_iter);
292 mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1;
294 "mask needed bits (current iter): "B2B_PAT "\n",
295 B2B (mask_bits_needed_iter));
297 "Unaligned byte: "B2B_PAT " (%u bits)\n",
302 "next whole input byte: "B2B_PAT "\n",
304 byte_input &= mask_bits_needed_iter;
307 "input byte, needed bits: "B2B_PAT "\n",
310 "number of bits needed to align unaligned bit: %u\n",
312 num_bits_to_move =
GNUNET_MIN (num_bits_to_align, num_bits_needed_iter);
314 "number of bits of new byte to move: %u\n",
316 mask_input_to_move = ((char) 1 << num_bits_to_move) - 1;
318 "mask of bits of new byte to take for moving: "B2B_PAT "\n",
319 B2B (mask_input_to_move));
320 bits_to_move = byte_input & mask_input_to_move;
322 "masked bits of new byte to take for moving: "B2B_PAT "\n",
326 "distance needed to shift bits to their correct spot: %u\n",
327 distance_shift_bits);
328 bits_moving = bits_to_move << distance_shift_bits;
330 "shifted, masked bits of new byte being moved: "B2B_PAT "\n",
334 "byte being filled: "B2B_PAT "\n",
337 "pending bytes: %u\n",
343 buf_write[i] = byte_to_fill;
347 mask_input_leftover = mask_bits_needed_iter & (~mask_input_to_move);
349 "mask of leftover bits of new byte: "B2B_PAT "\n",
350 B2B (mask_input_leftover));
351 byte_input_leftover = byte_input & mask_input_leftover;
353 "masked, leftover bits of new byte: "B2B_PAT "\n",
354 B2B (byte_input_leftover));
355 num_bits_leftover = num_bits_needed_iter - num_bits_to_move;
357 "number of unaligned bits left: %u\n",
360 byte_unaligned_new = byte_input_leftover >> num_bits_to_move;
362 "new unaligned byte: "B2B_PAT "\n",
363 B2B (byte_unaligned_new));
383 size_t name_buf_size;
389 name_buf_size = 512 *
sizeof(char);
393 keylen += 5 - keylen % 5;
456 "Could not create directory `/tmp/rps'\n");
478 if ((64 < out_size) ||
482 "Failed to write string to buffer (size: %i, out_size: %i)\n",
486 len_file_name = (strlen (
prefix)
496 if ((len_file_name < out_size) ||
500 "Failed to write string to buffer (size: %i, out_size: %i)\n",
522 return x *
fac (x - 1);
static int ret
Final status code.
static int end
Set if we are to shutdown all services (including ARM).
static int prefix
If printing the value of PREFIX has been requested.
static char * file_name
Dump file name.
struct GNUNET_HashCode key
The key used in the DHT.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_OPEN_APPEND
Append to the file.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_PERM_OTHER_READ
Everybody can read.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
static unsigned int size
Size of the "table".
char * auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key)
uint32_t fac(uint32_t x)
Factorial.
static char buf_unaligned
buffer for storing the unaligned bits for the next write
int close_files_iter(void *cls, const struct GNUNET_HashCode *key, void *value)
Closes the file of the current entry.
char * store_prefix_file_name(const unsigned int index, const char *prefix)
static int ensure_folder_exist(void)
Try to ensure that /tmp/rps exists.
void to_file_raw_unaligned(const char *file_name, const char *buf, size_t size_buf, unsigned bits_needed)
static struct GNUNET_CONTAINER_MultiHashMap * open_files
int close_all_files()
Close all files that were opened with get_file_handle.
void to_file_raw(const char *file_name, const char *buf, size_t size_buf)
struct GNUNET_CRYPTO_AuthKey string_to_auth_key(const char *str)
struct GNUNET_DISK_FileHandle * get_file_handle(const char *name)
Get file handle.
static unsigned num_bits_buf_unaligned
number of bits in unaligned buffer
uint32_t binom(uint32_t n, uint32_t k)
Binomial coefficient (n choose k)
Some utils facilitating the view into the internals for the sampler needed for evaluation.
Internal representation of the hash map.
type for (message) authentication keys
unsigned char key[(512/8)]
Handle used to access files (and pipes).