aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed.h
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-01-25 10:31:11 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-01-25 10:31:11 +0000
commitf4ac441409d20d314d3733cf454dece1aae42e99 (patch)
tree2e93c5599a584d9483add99707484b488e219975 /src/testbed/gnunet-service-testbed.h
parent8b755173de77add8e4edfe7b7c84d6f17ed9f47a (diff)
downloadgnunet-f4ac441409d20d314d3733cf454dece1aae42e99.tar.gz
gnunet-f4ac441409d20d314d3733cf454dece1aae42e99.zip
- move data structures to shared header
Diffstat (limited to 'src/testbed/gnunet-service-testbed.h')
-rw-r--r--src/testbed/gnunet-service-testbed.h810
1 files changed, 810 insertions, 0 deletions
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h
new file mode 100644
index 000000000..1ddc89540
--- /dev/null
+++ b/src/testbed/gnunet-service-testbed.h
@@ -0,0 +1,810 @@
1/*
2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file testbed/gnunet-service-testbed.h
23 * @brief data structures shared amongst components of TESTBED service
24 * @author Sree Harsha Totakura
25 */
26
27#include "gnunet_util_lib.h"
28#include "gnunet_testbed_service.h"
29#include "gnunet_transport_service.h"
30#include "gnunet_core_service.h"
31
32#include "testbed.h"
33#include "testbed_api.h"
34#include "testbed_api_operations.h"
35#include "testbed_api_hosts.h"
36#include "gnunet_testing_lib.h"
37
38
39/**
40 * Generic logging
41 */
42#define LOG(kind,...) \
43 GNUNET_log (kind, __VA_ARGS__)
44
45/**
46 * Debug logging
47 */
48#define LOG_DEBUG(...) \
49 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
50
51/**
52 * By how much should the arrays lists grow
53 */
54#define LIST_GROW_STEP 10
55
56/**
57 * Default timeout for operations which may take some time
58 */
59#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
60
61
62/**
63 * A routing entry
64 */
65struct Route
66{
67 /**
68 * destination host
69 */
70 uint32_t dest;
71
72 /**
73 * The destination host is reachable thru
74 */
75 uint32_t thru;
76};
77
78
79/**
80 * Context information for operations forwarded to subcontrollers
81 */
82struct ForwardedOperationContext
83{
84 /**
85 * The next pointer for DLL
86 */
87 struct ForwardedOperationContext *next;
88
89 /**
90 * The prev pointer for DLL
91 */
92 struct ForwardedOperationContext *prev;
93
94 /**
95 * The generated operation context
96 */
97 struct OperationContext *opc;
98
99 /**
100 * The client to which we have to reply
101 */
102 struct GNUNET_SERVER_Client *client;
103
104 /**
105 * Closure pointer
106 */
107 void *cls;
108
109 /**
110 * Task ID for the timeout task
111 */
112 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
113
114 /**
115 * The id of the operation that has been forwarded
116 */
117 uint64_t operation_id;
118
119 /**
120 * The type of the operation which is forwarded
121 */
122 enum OperationType type;
123
124};
125
126
127/**
128 * A DLL of host registrations to be made
129 */
130struct HostRegistration
131{
132 /**
133 * next registration in the DLL
134 */
135 struct HostRegistration *next;
136
137 /**
138 * previous registration in the DLL
139 */
140 struct HostRegistration *prev;
141
142 /**
143 * The callback to call after this registration's status is available
144 */
145 GNUNET_TESTBED_HostRegistrationCompletion cb;
146
147 /**
148 * The closure for the above callback
149 */
150 void *cb_cls;
151
152 /**
153 * The host that has to be registered
154 */
155 struct GNUNET_TESTBED_Host *host;
156};
157
158
159/**
160 * Context information used while linking controllers
161 */
162struct LinkControllersContext
163{
164 /**
165 * The client which initiated the link controller operation
166 */
167 struct GNUNET_SERVER_Client *client;
168
169 /**
170 * The ID of the operation
171 */
172 uint64_t operation_id;
173
174};
175
176
177/**
178 * Structure representing a connected(directly-linked) controller
179 */
180struct Slave
181{
182 /**
183 * The controller process handle if we had started the controller
184 */
185 struct GNUNET_TESTBED_ControllerProc *controller_proc;
186
187 /**
188 * The controller handle
189 */
190 struct GNUNET_TESTBED_Controller *controller;
191
192 /**
193 * The configuration of the slave. Cannot be NULL
194 */
195 struct GNUNET_CONFIGURATION_Handle *cfg;
196
197 /**
198 * handle to lcc which is associated with this slave startup. Should be set to
199 * NULL when the slave has successfully started up
200 */
201 struct LinkControllersContext *lcc;
202
203 /**
204 * Head of the host registration DLL
205 */
206 struct HostRegistration *hr_dll_head;
207
208 /**
209 * Tail of the host registration DLL
210 */
211 struct HostRegistration *hr_dll_tail;
212
213 /**
214 * The current host registration handle
215 */
216 struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
217
218 /**
219 * Hashmap to hold Registered host contexts
220 */
221 struct GNUNET_CONTAINER_MultiHashMap *reghost_map;
222
223 /**
224 * The id of the host this controller is running on
225 */
226 uint32_t host_id;
227
228};
229
230
231/**
232 * A peer
233 */
234
235struct Peer
236{
237
238 union
239 {
240 struct
241 {
242 /**
243 * The peer handle from testing API
244 */
245 struct GNUNET_TESTING_Peer *peer;
246
247 /**
248 * The modified (by GNUNET_TESTING_peer_configure) configuration this
249 * peer is configured with
250 */
251 struct GNUNET_CONFIGURATION_Handle *cfg;
252
253 /**
254 * Is the peer running
255 */
256 int is_running;
257
258 } local;
259
260 struct
261 {
262 /**
263 * The slave this peer is started through
264 */
265 struct Slave *slave;
266
267 /**
268 * The id of the remote host this peer is running on
269 */
270 uint32_t remote_host_id;
271
272 } remote;
273
274 } details;
275
276 /**
277 * Is this peer locally created?
278 */
279 int is_remote;
280
281 /**
282 * Our local reference id for this peer
283 */
284 uint32_t id;
285
286 /**
287 * References to peers are using in forwarded overlay contexts and remote
288 * overlay connect contexts. A peer can only be destroyed after all such
289 * contexts are destroyed. For this, we maintain a reference counter. When we
290 * use a peer in any such context, we increment this counter. We decrement it
291 * when we are destroying these contexts
292 */
293 uint32_t reference_cnt;
294
295 /**
296 * While destroying a peer, due to the fact that there could be references to
297 * this peer, we delay the peer destroy to a further time. We do this by using
298 * this flag to destroy the peer while destroying a context in which this peer
299 * has been used. When the flag is set to 1 and reference_cnt = 0 we destroy
300 * the peer
301 */
302 uint32_t destroy_flag;
303
304};
305
306
307/**
308 * Context information for transport try connect
309 */
310struct TryConnectContext
311{
312 /**
313 * The identity of the peer to which the transport has to attempt a connection
314 */
315 struct GNUNET_PeerIdentity *pid;
316
317 /**
318 * The transport handle
319 */
320 struct GNUNET_TRANSPORT_Handle *th;
321
322 /**
323 * the try connect handle
324 */
325 struct GNUNET_TRANSPORT_TryConnectHandle *tch;
326
327 /**
328 * The task handle
329 */
330 GNUNET_SCHEDULER_TaskIdentifier task;
331
332 /**
333 * The id of the operation which is resposible for this context
334 */
335 uint64_t op_id;
336
337 /**
338 * The number of times we attempted to connect
339 */
340 unsigned int retries;
341
342};
343
344
345/**
346 * Context information for connecting 2 peers in overlay
347 */
348struct OverlayConnectContext
349{
350 /**
351 * The next pointer for maintaining a DLL
352 */
353 struct OverlayConnectContext *next;
354
355 /**
356 * The prev pointer for maintaining a DLL
357 */
358 struct OverlayConnectContext *prev;
359
360 /**
361 * The client which has requested for overlay connection
362 */
363 struct GNUNET_SERVER_Client *client;
364
365 /**
366 * the peer which has to connect to the other peer
367 */
368 struct Peer *peer;
369
370 /**
371 * Transport handle of the first peer to get its HELLO
372 */
373 struct GNUNET_TRANSPORT_Handle *p1th;
374
375 /**
376 * Core handles of the first peer; used to notify when second peer connects to it
377 */
378 struct GNUNET_CORE_Handle *ch;
379
380 /**
381 * HELLO of the other peer
382 */
383 struct GNUNET_MessageHeader *hello;
384
385 /**
386 * Get hello handle to acquire HELLO of first peer
387 */
388 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
389
390 /**
391 * The handle for offering HELLO
392 */
393 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
394
395 /**
396 * The error message we send if this overlay connect operation has timed out
397 */
398 char *emsg;
399
400 /**
401 * Operation context for suboperations
402 */
403 struct OperationContext *opc;
404
405 /**
406 * Controller of peer 2; NULL if the peer is local
407 */
408 struct GNUNET_TESTBED_Controller *peer2_controller;
409
410 /**
411 * The transport try connect context
412 */
413 struct TryConnectContext tcc;
414
415 /**
416 * The peer identity of the first peer
417 */
418 struct GNUNET_PeerIdentity peer_identity;
419
420 /**
421 * The peer identity of the other peer
422 */
423 struct GNUNET_PeerIdentity other_peer_identity;
424
425 /**
426 * The id of the operation responsible for creating this context
427 */
428 uint64_t op_id;
429
430 /**
431 * The id of the task for sending HELLO of peer 2 to peer 1 and ask peer 1 to
432 * connect to peer 2
433 */
434 GNUNET_SCHEDULER_TaskIdentifier send_hello_task;
435
436 /**
437 * The id of the overlay connect timeout task
438 */
439 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
440
441 /**
442 * The id of the cleanup task
443 */
444 GNUNET_SCHEDULER_TaskIdentifier cleanup_task;
445
446 /**
447 * The id of peer A
448 */
449 uint32_t peer_id;
450
451 /**
452 * The id of peer B
453 */
454 uint32_t other_peer_id;
455
456};
457
458
459/**
460 * Context information for RequestOverlayConnect
461 * operations. RequestOverlayConnect is used when peers A, B reside on different
462 * hosts and the host controller for peer B is asked by the host controller of
463 * peer A to make peer B connect to peer A
464 */
465struct RequestOverlayConnectContext
466{
467 /**
468 * the next pointer for DLL
469 */
470 struct RequestOverlayConnectContext *next;
471
472 /**
473 * the prev pointer for DLL
474 */
475 struct RequestOverlayConnectContext *prev;
476
477 /**
478 * The peer handle of peer B
479 */
480 struct Peer *peer;
481
482 /**
483 * Peer A's HELLO
484 */
485 struct GNUNET_MessageHeader *hello;
486
487 /**
488 * The handle for offering HELLO
489 */
490 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
491
492 /**
493 * The transport try connect context
494 */
495 struct TryConnectContext tcc;
496
497 /**
498 * The peer identity of peer A
499 */
500 struct GNUNET_PeerIdentity a_id;
501
502 /**
503 * Task for offering HELLO of A to B and doing try_connect
504 */
505 GNUNET_SCHEDULER_TaskIdentifier attempt_connect_task_id;
506
507 /**
508 * Task to timeout RequestOverlayConnect
509 */
510 GNUNET_SCHEDULER_TaskIdentifier timeout_rocc_task_id;
511
512 /**
513 * The id of the operation responsible for creating this context
514 */
515 uint64_t op_id;
516};
517
518
519/**
520 * Context information to used during operations which forward the overlay
521 * connect message
522 */
523struct ForwardedOverlayConnectContext
524{
525 /**
526 * next ForwardedOverlayConnectContext in the DLL
527 */
528 struct ForwardedOverlayConnectContext *next;
529
530 /**
531 * previous ForwardedOverlayConnectContext in the DLL
532 */
533 struct ForwardedOverlayConnectContext *prev;
534
535 /**
536 * A copy of the original overlay connect message
537 */
538 struct GNUNET_MessageHeader *orig_msg;
539
540 /**
541 * The id of the operation which created this context information
542 */
543 uint64_t operation_id;
544
545 /**
546 * the id of peer 1
547 */
548 uint32_t peer1;
549
550 /**
551 * The id of peer 2
552 */
553 uint32_t peer2;
554
555 /**
556 * Id of the host where peer2 is running
557 */
558 uint32_t peer2_host_id;
559};
560
561
562/**
563 * The main context information associated with the client which started us
564 */
565struct Context
566{
567 /**
568 * The client handle associated with this context
569 */
570 struct GNUNET_SERVER_Client *client;
571
572 /**
573 * The network address of the master controller
574 */
575 char *master_ip;
576
577 /**
578 * The TESTING system handle for starting peers locally
579 */
580 struct GNUNET_TESTING_System *system;
581
582 /**
583 * Our host id according to this context
584 */
585 uint32_t host_id;
586};
587
588
589/**
590 * The structure for identifying a shared service
591 */
592struct SharedService
593{
594 /**
595 * The name of the shared service
596 */
597 char *name;
598
599 /**
600 * Number of shared peers per instance of the shared service
601 */
602 uint32_t num_shared;
603
604 /**
605 * Number of peers currently sharing the service
606 */
607 uint32_t num_sharing;
608};
609
610
611/**
612 * This context information will be created for each host that is registered at
613 * slave controllers during overlay connects.
614 */
615struct RegisteredHostContext
616{
617 /**
618 * The host which is being registered
619 */
620 struct GNUNET_TESTBED_Host *reg_host;
621
622 /**
623 * The host of the controller which has to connect to the above rhost
624 */
625 struct GNUNET_TESTBED_Host *host;
626
627 /**
628 * The gateway to which this operation is forwarded to
629 */
630 struct Slave *gateway;
631
632 /**
633 * The gateway through which peer2's controller can be reached
634 */
635 struct Slave *gateway2;
636
637 /**
638 * Handle for sub-operations
639 */
640 struct GNUNET_TESTBED_Operation *sub_op;
641
642 /**
643 * The client which initiated the link controller operation
644 */
645 struct GNUNET_SERVER_Client *client;
646
647 /**
648 * Head of the ForwardedOverlayConnectContext DLL
649 */
650 struct ForwardedOverlayConnectContext *focc_dll_head;
651
652 /**
653 * Tail of the ForwardedOverlayConnectContext DLL
654 */
655 struct ForwardedOverlayConnectContext *focc_dll_tail;
656
657 /**
658 * Enumeration of states for this context
659 */
660 enum RHCState {
661
662 /**
663 * The initial state
664 */
665 RHC_INIT = 0,
666
667 /**
668 * State where we attempt to get peer2's controller configuration
669 */
670 RHC_GET_CFG,
671
672 /**
673 * State where we attempt to link the controller of peer 1 to the controller
674 * of peer2
675 */
676 RHC_LINK,
677
678 /**
679 * State where we attempt to do the overlay connection again
680 */
681 RHC_OL_CONNECT
682
683 } state;
684
685};
686
687
688/**
689 * States of LCFContext
690 */
691enum LCFContextState
692{
693 /**
694 * The Context has been initialized; Nothing has been done on it
695 */
696 INIT,
697
698 /**
699 * Delegated host has been registered at the forwarding controller
700 */
701 DELEGATED_HOST_REGISTERED,
702
703 /**
704 * The slave host has been registred at the forwarding controller
705 */
706 SLAVE_HOST_REGISTERED,
707
708 /**
709 * The context has been finished (may have error)
710 */
711 FINISHED
712};
713
714
715/**
716 * Link controllers request forwarding context
717 */
718struct LCFContext
719{
720 /**
721 * The gateway which will pass the link message to delegated host
722 */
723 struct Slave *gateway;
724
725 /**
726 * The controller link message that has to be forwarded to
727 */
728 struct GNUNET_TESTBED_ControllerLinkMessage *msg;
729
730 /**
731 * The client which has asked to perform this operation
732 */
733 struct GNUNET_SERVER_Client *client;
734
735 /**
736 * Handle for operations which are forwarded while linking controllers
737 */
738 struct ForwardedOperationContext *fopc;
739
740 /**
741 * The id of the operation which created this context
742 */
743 uint64_t operation_id;
744
745 /**
746 * The state of this context
747 */
748 enum LCFContextState state;
749
750 /**
751 * The delegated host
752 */
753 uint32_t delegated_host_id;
754
755 /**
756 * The slave host
757 */
758 uint32_t slave_host_id;
759
760};
761
762
763/**
764 * Structure of a queue entry in LCFContext request queue
765 */
766struct LCFContextQueue
767{
768 /**
769 * The LCFContext
770 */
771 struct LCFContext *lcf;
772
773 /**
774 * Head prt for DLL
775 */
776 struct LCFContextQueue *next;
777
778 /**
779 * Tail ptr for DLL
780 */
781 struct LCFContextQueue *prev;
782};
783
784
785/**
786 * Hello cache entry
787 */
788struct HelloCacheEntry
789{
790 /**
791 * DLL next ptr for least recently used hello cache entries
792 */
793 struct HelloCacheEntry *next;
794
795 /**
796 * DLL prev ptr for least recently used hello cache entries
797 */
798 struct HelloCacheEntry *prev;
799
800 /**
801 * The key for this entry
802 */
803 struct GNUNET_HashCode key;
804
805 /**
806 * The HELLO message
807 */
808 struct GNUNET_MessageHeader *hello;
809};
810