aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-05-27 08:18:36 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-05-27 08:18:36 +0000
commitb740132d08a1ebbfdd2ecf538f463d5a665b0e6c (patch)
tree3b90a2e827efdc6ded7f298b4027717f20691c11
parent4456c3907fd3b463a204a986245680ce96425c10 (diff)
downloadgnunet-b740132d08a1ebbfdd2ecf538f463d5a665b0e6c.tar.gz
gnunet-b740132d08a1ebbfdd2ecf538f463d5a665b0e6c.zip
docu
-rw-r--r--src/experimentation/gnunet-daemon-experimentation_nodes.c100
1 files changed, 98 insertions, 2 deletions
diff --git a/src/experimentation/gnunet-daemon-experimentation_nodes.c b/src/experimentation/gnunet-daemon-experimentation_nodes.c
index 2ddfb4dcb..266f82ce3 100644
--- a/src/experimentation/gnunet-daemon-experimentation_nodes.c
+++ b/src/experimentation/gnunet-daemon-experimentation_nodes.c
@@ -31,21 +31,31 @@
31#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
32#include "gnunet-daemon-experimentation.h" 32#include "gnunet-daemon-experimentation.h"
33 33
34
35/**
36 * Core handle
37 */
34static struct GNUNET_CORE_Handle *ch; 38static struct GNUNET_CORE_Handle *ch;
35 39
40
41/**
42 * Peer's own identity
43 */
36static struct GNUNET_PeerIdentity me; 44static struct GNUNET_PeerIdentity me;
37 45
46
38/** 47/**
39 * Nodes with a pending request 48 * Nodes with a pending request
40 */ 49 */
41
42struct GNUNET_CONTAINER_MultiHashMap *nodes_requested; 50struct GNUNET_CONTAINER_MultiHashMap *nodes_requested;
43 51
52
44/** 53/**
45 * Active experimentation nodes 54 * Active experimentation nodes
46 */ 55 */
47struct GNUNET_CONTAINER_MultiHashMap *nodes_active; 56struct GNUNET_CONTAINER_MultiHashMap *nodes_active;
48 57
58
49/** 59/**
50 * Inactive experimentation nodes 60 * Inactive experimentation nodes
51 * To be excluded from future requests 61 * To be excluded from future requests
@@ -53,6 +63,11 @@ struct GNUNET_CONTAINER_MultiHashMap *nodes_active;
53struct GNUNET_CONTAINER_MultiHashMap *nodes_inactive; 63struct GNUNET_CONTAINER_MultiHashMap *nodes_inactive;
54 64
55 65
66/**
67 * Update statistics
68 *
69 * @param m hashmap to update values from
70 */
56static void update_stats (struct GNUNET_CONTAINER_MultiHashMap *m) 71static void update_stats (struct GNUNET_CONTAINER_MultiHashMap *m)
57{ 72{
58 GNUNET_assert (NULL != m); 73 GNUNET_assert (NULL != m);
@@ -78,6 +93,15 @@ static void update_stats (struct GNUNET_CONTAINER_MultiHashMap *m)
78 93
79} 94}
80 95
96
97/**
98 * Clean up nodes
99 *
100 * @param cls the hashmap to clean up
101 * @param key key of the current node
102 * @param value related node object
103 * @return always GNUNET_OK
104 */
81static int 105static int
82cleanup_nodes (void *cls, 106cleanup_nodes (void *cls,
83 const struct GNUNET_HashCode * key, 107 const struct GNUNET_HashCode * key,
@@ -105,6 +129,12 @@ cleanup_nodes (void *cls,
105} 129}
106 130
107 131
132/**
133 * Check if id passed is my id
134 *
135 * @param id the id to check
136 * @return GNUNET_YES or GNUNET_NO
137 */
108static int is_me (const struct GNUNET_PeerIdentity *id) 138static int is_me (const struct GNUNET_PeerIdentity *id)
109{ 139{
110 if (0 == memcmp (&me, id, sizeof (me))) 140 if (0 == memcmp (&me, id, sizeof (me)))
@@ -113,14 +143,28 @@ static int is_me (const struct GNUNET_PeerIdentity *id)
113 return GNUNET_NO; 143 return GNUNET_NO;
114} 144}
115 145
146/**
147 * Core startup callback
148 *
149 * @param cls unused
150 * @param server core service's server handle
151 * @param my_identity my id
152 */
116static void 153static void
117core_startup_handler (void *cls, 154core_startup_handler (void *cls,
118 struct GNUNET_CORE_Handle * server, 155 struct GNUNET_CORE_Handle *server,
119 const struct GNUNET_PeerIdentity *my_identity) 156 const struct GNUNET_PeerIdentity *my_identity)
120{ 157{
121 me = *my_identity; 158 me = *my_identity;
122} 159}
123 160
161
162/**
163 * Remove experimentation request due to timeout
164 *
165 * @param cls the related node
166 * @param tc scheduler's task context
167 */
124static void 168static void
125remove_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 169remove_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
126{ 170{
@@ -146,6 +190,15 @@ remove_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
146 } 190 }
147} 191}
148 192
193
194/**
195 * Core's transmit notify callback to send request
196 *
197 * @param cls the related node
198 * @param bufsize buffer size
199 * @param buf the buffer to copy to
200 * @return bytes passed
201 */
149size_t send_request_cb (void *cls, size_t bufsize, void *buf) 202size_t send_request_cb (void *cls, size_t bufsize, void *buf)
150{ 203{
151 struct Node *n = cls; 204 struct Node *n = cls;
@@ -174,6 +227,12 @@ size_t send_request_cb (void *cls, size_t bufsize, void *buf)
174 return size; 227 return size;
175} 228}
176 229
230
231/**
232 * Send request
233 *
234 * @param peer the peer to send to
235 */
177static void send_request (const struct GNUNET_PeerIdentity *peer) 236static void send_request (const struct GNUNET_PeerIdentity *peer)
178{ 237{
179 struct Node *n; 238 struct Node *n;
@@ -194,6 +253,15 @@ static void send_request (const struct GNUNET_PeerIdentity *peer)
194 update_stats (nodes_requested); 253 update_stats (nodes_requested);
195} 254}
196 255
256
257/**
258 * Core's transmit notify callback to send response
259 *
260 * @param cls the related node
261 * @param bufsize buffer size
262 * @param buf the buffer to copy to
263 * @return bytes passed
264 */
197size_t send_response_cb (void *cls, size_t bufsize, void *buf) 265size_t send_response_cb (void *cls, size_t bufsize, void *buf)
198{ 266{
199 struct Node *n = cls; 267 struct Node *n = cls;
@@ -219,6 +287,12 @@ size_t send_response_cb (void *cls, size_t bufsize, void *buf)
219 return size; 287 return size;
220} 288}
221 289
290
291/**
292 * Set a specific node as active
293 *
294 * @param n the node
295 */
222static void node_make_active (struct Node *n) 296static void node_make_active (struct Node *n)
223{ 297{
224 GNUNET_CONTAINER_multihashmap_put (nodes_active, 298 GNUNET_CONTAINER_multihashmap_put (nodes_active,
@@ -229,6 +303,12 @@ static void node_make_active (struct Node *n)
229} 303}
230 304
231 305
306/**
307 * Handle a request and send a response
308 *
309 * @param peer the source
310 * @param message the message
311 */
232static void handle_request (const struct GNUNET_PeerIdentity *peer, 312static void handle_request (const struct GNUNET_PeerIdentity *peer,
233 const struct GNUNET_MessageHeader *message) 313 const struct GNUNET_MessageHeader *message)
234{ 314{
@@ -286,6 +366,13 @@ static void handle_request (const struct GNUNET_PeerIdentity *peer,
286 send_response_cb, n); 366 send_response_cb, n);
287} 367}
288 368
369
370/**
371 * Handle a response
372 *
373 * @param peer the source
374 * @param message the message
375 */
289static void handle_response (const struct GNUNET_PeerIdentity *peer, 376static void handle_response (const struct GNUNET_PeerIdentity *peer,
290 const struct GNUNET_MessageHeader *message) 377 const struct GNUNET_MessageHeader *message)
291{ 378{
@@ -381,6 +468,14 @@ void core_disconnect_handler (void *cls,
381} 468}
382 469
383 470
471/**
472 * Handle a request and send a response
473 *
474 * @param cls unused
475 * @param other the sender
476 * @param message the message
477 * @return GNUNET_OK to keep connection, GNUNET_SYSERR on error
478 */
384static int 479static int
385core_receive_handler (void *cls, 480core_receive_handler (void *cls,
386 const struct GNUNET_PeerIdentity *other, 481 const struct GNUNET_PeerIdentity *other,
@@ -432,6 +527,7 @@ GNUNET_EXPERIMENTATION_nodes_start ()
432 nodes_inactive = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); 527 nodes_inactive = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
433} 528}
434 529
530
435/** 531/**
436 * Stop the nodes management 532 * Stop the nodes management
437 */ 533 */