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') 79 if (NULL == open_files)
84 "Created map of open files.\n");
102 "Opening file `%s' failed.\n",
180 "Not able to open file %s\n",
186 if (size_buf != size_written)
189 "Unable to write to file! (Size: %llu, size_written: %llu)\n",
190 (
unsigned long long) size_buf,
191 (
unsigned long long) size_written);
195 "Unable to close file\n");
200 "Wrote %llu bytes raw.\n",
201 (
unsigned long long) size_written);
204 "Unable to close file\n");
229 "Was asked to write %u bits\n", bits_needed);
231 char buf_write[size_buf + 1];
232 const unsigned bytes_iter = (0 != bits_needed % 8 ?
233 (bits_needed / 8) + 1 :
236 unsigned size_buf_write = 0;
238 "num_bits_buf_unaligned: %u\n",
241 "ua args: size_buf: %llu, bits_needed: %u -> iter: %u\n",
242 (
unsigned long long) size_buf,
247 for (
unsigned i = 0; i < bytes_iter; i++)
250 unsigned num_bits_needed_iter;
252 unsigned mask_bits_needed_iter;
255 unsigned num_bits_to_align;
257 unsigned num_bits_to_move;
259 char mask_input_to_move;
263 unsigned distance_shift_bits;
269 char mask_input_leftover;
271 char byte_input_leftover;
272 unsigned num_bits_leftover;
274 char byte_unaligned_new;
276 if ((bits_needed - (i * 8)) <= 8)
279 num_bits_needed_iter = bits_needed - (i * 8);
283 num_bits_needed_iter = 8;
286 "number of bits needed in this iteration: %u\n",
287 num_bits_needed_iter);
288 mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1;
290 "mask needed bits (current iter): "B2B_PAT "\n",
291 B2B (mask_bits_needed_iter));
293 "Unaligned byte: "B2B_PAT " (%u bits)\n",
298 "next whole input byte: "B2B_PAT "\n",
300 byte_input &= mask_bits_needed_iter;
303 "input byte, needed bits: "B2B_PAT "\n",
306 "number of bits needed to align unaligned bit: %u\n",
308 num_bits_to_move =
GNUNET_MIN (num_bits_to_align, num_bits_needed_iter);
310 "number of bits of new byte to move: %u\n",
312 mask_input_to_move = ((char) 1 << num_bits_to_move) - 1;
314 "mask of bits of new byte to take for moving: "B2B_PAT "\n",
315 B2B (mask_input_to_move));
316 bits_to_move = byte_input & mask_input_to_move;
318 "masked bits of new byte to take for moving: "B2B_PAT "\n",
322 "distance needed to shift bits to their correct spot: %u\n",
323 distance_shift_bits);
324 bits_moving = bits_to_move << distance_shift_bits;
326 "shifted, masked bits of new byte being moved: "B2B_PAT "\n",
330 "byte being filled: "B2B_PAT "\n",
333 "pending bytes: %u\n",
339 buf_write[i] = byte_to_fill;
343 mask_input_leftover = mask_bits_needed_iter & (~mask_input_to_move);
345 "mask of leftover bits of new byte: "B2B_PAT "\n",
346 B2B (mask_input_leftover));
347 byte_input_leftover = byte_input & mask_input_leftover;
349 "masked, leftover bits of new byte: "B2B_PAT "\n",
350 B2B (byte_input_leftover));
351 num_bits_leftover = num_bits_needed_iter - num_bits_to_move;
353 "number of unaligned bits left: %u\n",
356 byte_unaligned_new = byte_input_leftover >> num_bits_to_move;
358 "new unaligned byte: "B2B_PAT "\n",
359 B2B (byte_unaligned_new));
370 to_file_raw (file_name, buf_write, size_buf_write);
379 size_t name_buf_size;
385 name_buf_size = 512 *
sizeof(char);
389 keylen += 5 - keylen % 5;
408 size =
GNUNET_snprintf (name_buf, name_buf_size,
"sampler_el-%s", buf);
452 "Could not create directory `/tmp/rps'\n");
474 if ((64 < out_size) ||
478 "Failed to write string to buffer (size: %i, out_size: %i)\n",
482 len_file_name = (strlen (prefix)
492 if ((len_file_name < out_size) ||
496 "Failed to write string to buffer (size: %i, out_size: %i)\n",
518 return x *
fac (x - 1);
struct GNUNET_DISK_FileHandle * get_file_handle(const char *name)
Get file handle.
Create file if it doesn't exist.
static int end
Set if we are to shutdown all services (including ARM).
int close_files_iter(void *cls, const struct GNUNET_HashCode *key, void *value)
Closes the file of the current entry.
Some utils faciliating the view into the internals for the sampler needed for evaluation.
void to_file_raw(const char *file_name, const char *buf, size_t size_buf)
char * auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
static struct GNUNET_CONTAINER_MultiHashMap * open_files
static char * file_name
Dump file name.
static int ret
Return value of the commandline.
static unsigned bits_needed
numer of bits required to represent the largest peer id
static unsigned num_bits_buf_unaligned
number of bits in unaligned buffer
void to_file_raw_unaligned(const char *file_name, const char *buf, size_t size_buf, unsigned bits_needed)
Internal representation of the hash map.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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.
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.
static char * value
Value of the record to add/remove.
char * store_prefix_file_name(const unsigned int index, const char *prefix)
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
static char buf_unaligned
buffer for storing the unaligned bits for the next write
unsigned char key[(512/8)]
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
static int fh
Handle to the unique file.
uint32_t binom(uint32_t n, uint32_t k)
Binomial coefficient (n choose k)
int close_all_files()
Close all files that were opened with get_file_handle.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Open the file for writing.
int 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.
uint32_t fac(uint32_t x)
Factorial.
static int ensure_folder_exist(void)
Try to ensure that /tmp/rps exists.
struct GNUNET_CRYPTO_AuthKey string_to_auth_key(const char *str)
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Handle used to access files (and pipes).
type for (message) authentication keys
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
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.
#define GNUNET_free(ptr)
Wrapper around free.