2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file testbed/gnunet-service-testbed.h
23 * @brief data structures shared amongst components of TESTBED service
24 * @author Sree Harsha Totakura
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_core_service.h"
34 #include "testbed_api.h"
35 #include "testbed_api_operations.h"
36 #include "testbed_api_hosts.h"
37 #include "gnunet_testing_lib.h"
43 #define LOG(kind,...) \
44 GNUNET_log (kind, __VA_ARGS__)
49 #define LOG_DEBUG(...) \
50 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
53 * By how much should the arrays lists grow
55 #define LIST_GROW_STEP 10
58 * Default timeout for operations which may take some time
60 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
74 * The destination host is reachable thru
81 * Context information for operations forwarded to subcontrollers
83 struct ForwardedOperationContext
86 * The next pointer for DLL
88 struct ForwardedOperationContext *next;
91 * The prev pointer for DLL
93 struct ForwardedOperationContext *prev;
96 * The generated operation context
98 struct OperationContext *opc;
101 * The client to which we have to reply
103 struct GNUNET_SERVER_Client *client;
111 * Task ID for the timeout task
113 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
116 * The id of the operation that has been forwarded
118 uint64_t operation_id;
121 * The type of the operation which is forwarded
123 enum OperationType type;
129 * A DLL of host registrations to be made
131 struct HostRegistration
134 * next registration in the DLL
136 struct HostRegistration *next;
139 * previous registration in the DLL
141 struct HostRegistration *prev;
144 * The callback to call after this registration's status is available
146 GNUNET_TESTBED_HostRegistrationCompletion cb;
149 * The closure for the above callback
154 * The host that has to be registered
156 struct GNUNET_TESTBED_Host *host;
161 * Context information used while linking controllers
163 struct LinkControllersContext
166 * The client which initiated the link controller operation
168 struct GNUNET_SERVER_Client *client;
171 * The ID of the operation
173 uint64_t operation_id;
179 * Structure representing a connected(directly-linked) controller
184 * The controller process handle if we had started the controller
186 struct GNUNET_TESTBED_ControllerProc *controller_proc;
189 * The controller handle
191 struct GNUNET_TESTBED_Controller *controller;
194 * The configuration of the slave. Cannot be NULL
196 struct GNUNET_CONFIGURATION_Handle *cfg;
199 * handle to lcc which is associated with this slave startup. Should be set to
200 * NULL when the slave has successfully started up
202 struct LinkControllersContext *lcc;
205 * Head of the host registration DLL
207 struct HostRegistration *hr_dll_head;
210 * Tail of the host registration DLL
212 struct HostRegistration *hr_dll_tail;
215 * The current host registration handle
217 struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
220 * Hashmap to hold Registered host contexts
222 struct GNUNET_CONTAINER_MultiHashMap *reghost_map;
225 * The id of the host this controller is running on
244 * The peer handle from testing API
246 struct GNUNET_TESTING_Peer *peer;
249 * The modified (by GNUNET_TESTING_peer_configure) configuration this
250 * peer is configured with
252 struct GNUNET_CONFIGURATION_Handle *cfg;
255 * Is the peer running
264 * The slave this peer is started through
269 * The id of the remote host this peer is running on
271 uint32_t remote_host_id;
278 * Is this peer locally created?
283 * Our local reference id for this peer
288 * References to peers are using in forwarded overlay contexts and remote
289 * overlay connect contexts. A peer can only be destroyed after all such
290 * contexts are destroyed. For this, we maintain a reference counter. When we
291 * use a peer in any such context, we increment this counter. We decrement it
292 * when we are destroying these contexts
294 uint32_t reference_cnt;
297 * While destroying a peer, due to the fact that there could be references to
298 * this peer, we delay the peer destroy to a further time. We do this by using
299 * this flag to destroy the peer while destroying a context in which this peer
300 * has been used. When the flag is set to 1 and reference_cnt = 0 we destroy
303 uint32_t destroy_flag;
309 * The main context information associated with the client which started us
314 * The client handle associated with this context
316 struct GNUNET_SERVER_Client *client;
319 * The network address of the master controller
324 * The TESTING system handle for starting peers locally
326 struct GNUNET_TESTING_System *system;
329 * Our host id according to this context
336 * The structure for identifying a shared service
341 * The name of the shared service
346 * Number of shared peers per instance of the shared service
351 * Number of peers currently sharing the service
353 uint32_t num_sharing;
358 * Context information to used during operations which forward the overlay
361 struct ForwardedOverlayConnectContext
364 * next ForwardedOverlayConnectContext in the DLL
366 struct ForwardedOverlayConnectContext *next;
369 * previous ForwardedOverlayConnectContext in the DLL
371 struct ForwardedOverlayConnectContext *prev;
374 * A copy of the original overlay connect message
376 struct GNUNET_MessageHeader *orig_msg;
379 * The id of the operation which created this context information
381 uint64_t operation_id;
394 * Id of the host where peer2 is running
396 uint32_t peer2_host_id;
401 * This context information will be created for each host that is registered at
402 * slave controllers during overlay connects.
404 struct RegisteredHostContext
407 * The host which is being registered
409 struct GNUNET_TESTBED_Host *reg_host;
412 * The host of the controller which has to connect to the above rhost
414 struct GNUNET_TESTBED_Host *host;
417 * The gateway to which this operation is forwarded to
419 struct Slave *gateway;
422 * The gateway through which peer2's controller can be reached
424 struct Slave *gateway2;
427 * Handle for sub-operations
429 struct GNUNET_TESTBED_Operation *sub_op;
432 * The client which initiated the link controller operation
434 struct GNUNET_SERVER_Client *client;
437 * Head of the ForwardedOverlayConnectContext DLL
439 struct ForwardedOverlayConnectContext *focc_dll_head;
442 * Tail of the ForwardedOverlayConnectContext DLL
444 struct ForwardedOverlayConnectContext *focc_dll_tail;
447 * Enumeration of states for this context
457 * State where we attempt to get peer2's controller configuration
462 * State where we attempt to link the controller of peer 1 to the controller
468 * State where we attempt to do the overlay connection again
478 * States of LCFContext
483 * The Context has been initialized; Nothing has been done on it
488 * Delegated host has been registered at the forwarding controller
490 DELEGATED_HOST_REGISTERED,
493 * The slave host has been registred at the forwarding controller
495 SLAVE_HOST_REGISTERED,
498 * The context has been finished (may have error)
505 * Link controllers request forwarding context
510 * The gateway which will pass the link message to delegated host
512 struct Slave *gateway;
515 * The controller link message that has to be forwarded to
517 struct GNUNET_TESTBED_ControllerLinkMessage *msg;
520 * The client which has asked to perform this operation
522 struct GNUNET_SERVER_Client *client;
525 * Handle for operations which are forwarded while linking controllers
527 struct ForwardedOperationContext *fopc;
530 * The id of the operation which created this context
532 uint64_t operation_id;
535 * The state of this context
537 enum LCFContextState state;
542 uint32_t delegated_host_id;
547 uint32_t slave_host_id;
553 * Structure of a queue entry in LCFContext request queue
555 struct LCFContextQueue
560 struct LCFContext *lcf;
565 struct LCFContextQueue *next;
570 struct LCFContextQueue *prev;
576 struct GNUNET_CONFIGURATION_Handle *our_config;
579 * The master context; generated with the first INIT message
581 extern struct Context *TESTBED_context;
584 * DLL head for forwarded operation contexts
586 extern struct ForwardedOperationContext *fopcq_head;
589 * DLL tail for forwarded operation contexts
591 extern struct ForwardedOperationContext *fopcq_tail;
594 * A list of peers we know about
596 extern struct Peer **TESTBED_peer_list;
601 extern struct GNUNET_TESTBED_Host **TESTBED_host_list;
604 * A list of directly linked neighbours
606 extern struct Slave **TESTBED_slave_list;
609 * The size of the peer list
611 extern unsigned int TESTBED_peer_list_size;
614 * The size of the host list
616 extern unsigned int TESTBED_host_list_size;
619 * The size of directly linked neighbours list
621 extern unsigned int TESTBED_slave_list_size;
625 * Queues a message in send queue for sending to the service
627 * @param client the client to whom the queued message has to be sent
628 * @param msg the message to queue
631 TESTBED_queue_message (struct GNUNET_SERVER_Client *client,
632 struct GNUNET_MessageHeader *msg);
636 * Function to destroy a peer
638 * @param peer the peer structure to destroy
641 TESTBED_destroy_peer (struct Peer *peer);
645 * Looks up in the hello cache and returns the HELLO of the given peer
647 * @param id the peer identity of the peer whose HELLO has to be looked up
648 * @return the HELLO message; NULL if not found
650 const struct GNUNET_MessageHeader *
651 TESTBED_hello_cache_lookup (const struct GNUNET_PeerIdentity *id);
654 * Caches the HELLO of the given peer. Updates the HELLO if it was already
657 * @param id the peer identity of the peer whose HELLO has to be cached
658 * @param hello the HELLO message
661 TESTBED_hello_cache_add (const struct GNUNET_PeerIdentity *id,
662 const struct GNUNET_MessageHeader *hello);
666 * Initializes the cache
668 * @param size the size of the cache
671 TESTBED_cache_init (unsigned int size);
678 TESTBED_cache_clear ();
682 * Finds the route with directly connected host as destination through which
683 * the destination host can be reached
685 * @param host_id the id of the destination host
686 * @return the route with directly connected destination host; NULL if no route
690 TESTBED_find_dest_route (uint32_t host_id);
694 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
697 * @param client identification of the client
698 * @param message the actual message
701 TESTBED_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
702 const struct GNUNET_MessageHeader *message);
706 * Adds a host registration's request to a slave's registration queue
708 * @param slave the slave controller at which the given host has to be
710 * @param cb the host registration completion callback
711 * @param cb_cls the closure for the host registration completion callback
712 * @param host the host which has to be registered
715 TESTBED_queue_host_registration (struct Slave *slave,
716 GNUNET_TESTBED_HostRegistrationCompletion cb,
718 struct GNUNET_TESTBED_Host *host);
722 * Callback to relay the reply msg of a forwarded operation back to the client
724 * @param cls ForwardedOperationContext
725 * @param msg the message to relay
728 TESTBED_forwarded_operation_reply_relay (void *cls,
729 const struct GNUNET_MessageHeader *msg);
733 * Task to free resources when forwarded operation has been timedout
735 * @param cls the ForwardedOperationContext
736 * @param tc the task context from scheduler
739 TESTBED_forwarded_operation_timeout (void *cls,
740 const struct GNUNET_SCHEDULER_TaskContext *tc);
744 * Send operation failure message to client
746 * @param client the client to which the failure message has to be sent to
747 * @param operation_id the id of the failed operation
748 * @param emsg the error message; can be NULL
751 TESTBED_send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
752 uint64_t operation_id, const char *emsg);
756 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages
759 * @param client identification of the client
760 * @param message the actual message
763 TESTBED_handle_overlay_request_connect (void *cls,
764 struct GNUNET_SERVER_Client *client,
765 const struct GNUNET_MessageHeader
770 * Processes a forwarded overlay connect context in the queue of the given RegisteredHostContext
772 * @param rhc the RegisteredHostContext
775 TESTBED_process_next_focc (struct RegisteredHostContext *rhc);
779 * Cleans up ForwardedOverlayConnectContext
781 * @param focc the ForwardedOverlayConnectContext to cleanup
784 TESTBED_cleanup_focc (struct ForwardedOverlayConnectContext *focc);
788 * Clears all pending overlay connect contexts in queue
791 TESTBED_free_occq ();
795 * Clears all pending remote overlay connect contexts in queue
798 TESTBED_free_roccq ();
802 /* End of gnunet-service-testbed.h */