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