aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-rps-profiler.c21
-rw-r--r--src/rps/rps-test_util.c133
-rw-r--r--src/rps/rps-test_util.h8
3 files changed, 147 insertions, 15 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c
index 5ef42187f..4a7a89b15 100644
--- a/src/rps/gnunet-rps-profiler.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -42,6 +42,11 @@
42static uint32_t num_peers; 42static uint32_t num_peers;
43 43
44/** 44/**
45 * @brief numer of bits required to represent the largest peer id
46 */
47static unsigned bits_needed;
48
49/**
45 * How long do we run the test? 50 * How long do we run the test?
46 * In seconds. 51 * In seconds.
47 */ 52 */
@@ -1698,6 +1703,7 @@ profiler_reply_handle (void *cls,
1698 char *file_name; 1703 char *file_name;
1699 char *file_name_dh; 1704 char *file_name_dh;
1700 char *file_name_dhr; 1705 char *file_name_dhr;
1706 char *file_name_dhru;
1701 unsigned int i; 1707 unsigned int i;
1702 struct PendingReply *pending_rep = (struct PendingReply *) cls; 1708 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1703 1709
@@ -1706,6 +1712,7 @@ profiler_reply_handle (void *cls,
1706 file_name = "/tmp/rps/received_ids"; 1712 file_name = "/tmp/rps/received_ids";
1707 file_name_dh = "/tmp/rps/diehard_input"; 1713 file_name_dh = "/tmp/rps/diehard_input";
1708 file_name_dhr = "/tmp/rps/diehard_input_raw"; 1714 file_name_dhr = "/tmp/rps/diehard_input_raw";
1715 file_name_dhru = "/tmp/rps/diehard_input_raw_aligned";
1709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1710 "[%s] got %" PRIu64 " peers:\n", 1717 "[%s] got %" PRIu64 " peers:\n",
1711 GNUNET_i2s (rps_peer->peer_id), 1718 GNUNET_i2s (rps_peer->peer_id),
@@ -1725,8 +1732,12 @@ profiler_reply_handle (void *cls,
1725 "%" PRIu32 "\n", 1732 "%" PRIu32 "\n",
1726 (uint32_t) rcv_rps_peer->index); 1733 (uint32_t) rcv_rps_peer->index);
1727 to_file_raw (file_name_dhr, 1734 to_file_raw (file_name_dhr,
1728 &rcv_rps_peer->index, 1735 (char *) &rcv_rps_peer->index,
1729 sizeof (uint32_t)); 1736 sizeof (uint32_t));
1737 to_file_raw_unaligned (file_name_dhru,
1738 (char *) &rcv_rps_peer->index,
1739 sizeof (uint32_t),
1740 bits_needed);
1730 } 1741 }
1731 default_reply_handle (cls, n, recv_peers); 1742 default_reply_handle (cls, n, recv_peers);
1732} 1743}
@@ -2626,6 +2637,14 @@ run (void *cls,
2626 GNUNET_DISK_directory_create ("/tmp/rps/"); 2637 GNUNET_DISK_directory_create ("/tmp/rps/");
2627 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s); 2638 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s);
2628 2639
2640 /* Compute number of bits for representing largest peer id */
2641 for (bits_needed = 1; (bits_needed << 1) < num_peers - 1; bits_needed++)
2642 ;
2643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2644 "Need %u bits to represent largest peer id %" PRIu32 "\n",
2645 bits_needed,
2646 num_peers - 1);
2647
2629 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); 2648 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
2630 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); 2649 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
2631 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); 2650 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index ea55deac5..9a1dfe0d8 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -29,13 +29,26 @@
29 29
30#include <inttypes.h> 30#include <inttypes.h>
31 31
32#define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from(kind,"rps-test_util",__VA_ARGS__)
33 33
34#ifndef TO_FILE 34#ifndef TO_FILE
35#define TO_FILE 35#define TO_FILE
36#endif /* TO_FILE */ 36#endif /* TO_FILE */
37 37
38#ifdef TO_FILE 38#ifdef TO_FILE
39
40#define min(x,y) ((x) > (y) ? (y) : (x))
41
42/**
43 * @brief buffer for storing the unaligned bits for the next write
44 */
45static char buf_unaligned;
46
47/**
48 * @brief number of bits in unaligned buffer
49 */
50static unsigned num_bits_buf_unaligned;
51
39void 52void
40to_file_ (const char *file_name, char *line) 53to_file_ (const char *file_name, char *line)
41{ 54{
@@ -108,11 +121,10 @@ to_file_ (const char *file_name, char *line)
108} 121}
109 122
110void 123void
111to_file_raw (const char *file_name, void *buf, size_t size_buf) 124to_file_raw (const char *file_name, const char *buf, size_t size_buf)
112{ 125{
113 struct GNUNET_DISK_FileHandle *f; 126 struct GNUNET_DISK_FileHandle *f;
114 size_t size2; 127 size_t size_written;
115
116 128
117 if (NULL == (f = GNUNET_DISK_file_open (file_name, 129 if (NULL == (f = GNUNET_DISK_file_open (file_name,
118 GNUNET_DISK_OPEN_APPEND | 130 GNUNET_DISK_OPEN_APPEND |
@@ -129,13 +141,13 @@ to_file_raw (const char *file_name, void *buf, size_t size_buf)
129 return; 141 return;
130 } 142 }
131 143
132 size2 = GNUNET_DISK_file_write (f, buf, size_buf); 144 size_written = GNUNET_DISK_file_write (f, buf, size_buf);
133 if (size_buf != size2) 145 if (size_buf != size_written)
134 { 146 {
135 LOG (GNUNET_ERROR_TYPE_WARNING, 147 LOG (GNUNET_ERROR_TYPE_WARNING,
136 "Unable to write to file! (Size: %u, size2: %u)\n", 148 "Unable to write to file! (Size: %u, size_written: %u)\n",
137 size_buf, 149 size_buf,
138 size2); 150 size_written);
139 151
140 if (GNUNET_YES != GNUNET_DISK_file_close (f)) 152 if (GNUNET_YES != GNUNET_DISK_file_close (f))
141 LOG (GNUNET_ERROR_TYPE_WARNING, 153 LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -143,15 +155,110 @@ to_file_raw (const char *file_name, void *buf, size_t size_buf)
143 155
144 return; 156 return;
145 } 157 }
158}
146 159
147 //if (512 < size_buf) 160void
161to_file_raw_unaligned (const char *file_name,
162 const char *buf,
163 size_t size_buf,
164 unsigned bits_needed)
165{
166 // TODO endianness!
167 GNUNET_assert (size_buf >= (bits_needed/8));
168 //if (0 == num_bits_buf_unaligned)
148 //{ 169 //{
149 // GNUNET_free (output_buffer_p); 170 // if (0 == (bits_needed % 8))
171 // {
172 // to_file_raw (file_name, buf, size_buf);
173 // return;
174 // }
175 // to_file_raw (file_name, buf, size_buf - 1);
176 // buf_unaligned = buf[size_buf - 1];
177 // num_bits_buf_unaligned = bits_needed % 8;
178 // return;
150 //} 179 //}
151 180
152 //if (GNUNET_YES != GNUNET_DISK_file_close (f)) 181 char buf_write[size_buf + 1];
153 // LOG (GNUNET_ERROR_TYPE_WARNING, 182 const unsigned bytes_iter = (0 != bits_needed % 8?
154 // "Unable to close file\n"); 183 (bits_needed/8)+1:
184 bits_needed/8);
185 // TODO what if no iteration happens?
186 unsigned size_buf_write = 0;
187 buf_write[0] = buf_unaligned;
188 /* Iterate over input bytes */
189 for (unsigned i = 0; i < bytes_iter; i++)
190 {
191 /* Number of bits needed in this iteration - 8 for all except last iter */
192 unsigned num_bits_needed_iter;
193 /* Mask for bits to actually use */
194 unsigned mask_bits_needed_iter;
195 char byte_input;
196 /* Number of bits needed to align unaligned byte */
197 unsigned num_bits_to_align;
198 /* Number of bits that are to be moved */
199 unsigned num_bits_to_move;
200 /* Mask for bytes to be moved */
201 char mask_input_to_move;
202 /* Masked bits to be moved */
203 char bits_to_move;
204 /* The amount of bits needed to fit the bits to shift to the nearest spot */
205 unsigned distance_shift_bits;
206 /* Shifted bits on the move */
207 char bits_moving;
208 /* (unaligned) byte being filled with bits */
209 char byte_to_fill;
210 /* mask for needed bits of the input byte that have not been moved */
211 char mask_input_leftover;
212 /* needed bits of the input byte that have not been moved */
213 char byte_input_leftover;
214 unsigned num_bits_leftover;
215 unsigned num_bits_discard;
216 char byte_unaligned_new;
217
218 if ( (bits_needed - (i * 8)) <= 8)
219 {
220 /* last iteration */
221 num_bits_needed_iter = bits_needed - (i * 8);
222 }
223 else
224 {
225 num_bits_needed_iter = 8;
226 }
227 mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1;
228 byte_input = buf[i];
229 byte_input &= mask_bits_needed_iter;
230 num_bits_to_align = 8 - num_bits_buf_unaligned;
231 num_bits_to_move = min (num_bits_to_align, num_bits_needed_iter);
232 mask_input_to_move = ((char) 1 << num_bits_to_move) - 1;
233 bits_to_move = byte_input & mask_input_to_move;
234 distance_shift_bits = num_bits_buf_unaligned;
235 bits_moving = bits_to_move << distance_shift_bits;
236 byte_to_fill = buf_unaligned | bits_moving;
237 if (num_bits_buf_unaligned + num_bits_needed_iter > 8)
238 {
239 /* buf_unaligned was aligned by filling
240 * -> can be written to storage */
241 buf_write[i] = byte_to_fill;
242 size_buf_write++;
243
244 /* store the leftover, unaligned bits in buffer */
245 mask_input_leftover = mask_bits_needed_iter & (~ mask_input_to_move);
246 byte_input_leftover = byte_input & mask_input_leftover;
247 num_bits_leftover = num_bits_needed_iter - num_bits_to_move;
248 num_bits_discard = 8 - num_bits_needed_iter;
249 byte_unaligned_new = byte_input_leftover >> num_bits_to_move;
250 buf_unaligned = byte_unaligned_new;
251 num_bits_buf_unaligned = num_bits_leftover % 8;
252 }
253 else
254 {
255 /* unaligned buffer still unaligned but 'fuller' */
256 buf_unaligned = byte_to_fill;
257 num_bits_buf_unaligned = (num_bits_buf_unaligned + bits_needed) % 8;
258 }
259 }
260 to_file_raw (file_name, buf_write, size_buf_write);
261 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
155} 262}
156 263
157char * 264char *
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h
index d42422750..577a2b0a7 100644
--- a/src/rps/rps-test_util.h
+++ b/src/rps/rps-test_util.h
@@ -75,7 +75,13 @@ store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
75 const char *prefix); 75 const char *prefix);
76 76
77void 77void
78to_file_raw (const char *file_name, void *buf, size_t size_buf); 78to_file_raw (const char *file_name, const char *buf, size_t size_buf);
79
80void
81to_file_raw_unaligned (const char *file_name,
82 const char *buf,
83 size_t size_buf,
84 unsigned bits_needed);
79 85
80#endif /* RPS_TEST_UTIL_H */ 86#endif /* RPS_TEST_UTIL_H */
81/* end of gnunet-service-rps.c */ 87/* end of gnunet-service-rps.c */