- restructure
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed.h
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 "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_core_service.h"
32
33 #include "testbed.h"
34 #include "testbed_api.h"
35 #include "testbed_api_operations.h"
36 #include "testbed_api_hosts.h"
37 #include "gnunet_testing_lib.h"
38
39
40 /**
41  * Generic logging
42  */
43 #define LOG(kind,...)                           \
44   GNUNET_log (kind, __VA_ARGS__)
45
46 /**
47  * Debug logging
48  */
49 #define LOG_DEBUG(...)                          \
50   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
51
52 /**
53  * By how much should the arrays lists grow
54  */
55 #define LIST_GROW_STEP 10
56
57
58 /**
59  * A routing entry
60  */
61 struct Route
62 {
63   /**
64    * destination host
65    */
66   uint32_t dest;
67
68   /**
69    * The destination host is reachable thru
70    */
71   uint32_t thru;
72 };
73
74
75 /**
76  * Context information for operations forwarded to subcontrollers
77  */
78 struct ForwardedOperationContext
79 {
80   /**
81    * The next pointer for DLL
82    */
83   struct ForwardedOperationContext *next;
84
85   /**
86    * The prev pointer for DLL
87    */
88   struct ForwardedOperationContext *prev;
89
90   /**
91    * The generated operation context
92    */
93   struct OperationContext *opc;
94
95   /**
96    * The client to which we have to reply
97    */
98   struct GNUNET_SERVER_Client *client;
99
100   /**
101    * Closure pointer
102    */
103   void *cls;
104
105   /**
106    * Task ID for the timeout task
107    */
108   GNUNET_SCHEDULER_TaskIdentifier timeout_task;
109
110   /**
111    * The id of the operation that has been forwarded
112    */
113   uint64_t operation_id;
114
115   /**
116    * The type of the operation which is forwarded
117    */
118   enum OperationType type;
119
120 };
121
122
123 /**
124  * A DLL of host registrations to be made
125  */
126 struct HostRegistration
127 {
128   /**
129    * next registration in the DLL
130    */
131   struct HostRegistration *next;
132
133   /**
134    * previous registration in the DLL
135    */
136   struct HostRegistration *prev;
137
138   /**
139    * The callback to call after this registration's status is available
140    */
141   GNUNET_TESTBED_HostRegistrationCompletion cb;
142
143   /**
144    * The closure for the above callback
145    */
146   void *cb_cls;
147
148   /**
149    * The host that has to be registered
150    */
151   struct GNUNET_TESTBED_Host *host;
152 };
153
154
155 /**
156  * Context information used while linking controllers
157  */
158 struct LinkControllersContext
159 {
160   /**
161    * The client which initiated the link controller operation
162    */
163   struct GNUNET_SERVER_Client *client;
164
165   /**
166    * The ID of the operation
167    */
168   uint64_t operation_id;
169
170 };
171
172
173 /**
174  * Structure representing a connected(directly-linked) controller
175  */
176 struct Slave
177 {
178   /**
179    * The controller process handle if we had started the controller
180    */
181   struct GNUNET_TESTBED_ControllerProc *controller_proc;
182
183   /**
184    * The controller handle
185    */
186   struct GNUNET_TESTBED_Controller *controller;
187
188   /**
189    * handle to lcc which is associated with this slave startup. Should be set to
190    * NULL when the slave has successfully started up
191    */
192   struct LinkControllersContext *lcc;
193
194   /**
195    * Head of the host registration DLL
196    */
197   struct HostRegistration *hr_dll_head;
198
199   /**
200    * Tail of the host registration DLL
201    */
202   struct HostRegistration *hr_dll_tail;
203
204   /**
205    * The current host registration handle
206    */
207   struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
208
209   /**
210    * Hashmap to hold Registered host contexts
211    */
212   struct GNUNET_CONTAINER_MultiHashMap *reghost_map;
213
214   /**
215    * The id of the host this controller is running on
216    */
217   uint32_t host_id;
218
219 };
220
221
222 /**
223  * A peer
224  */
225
226 struct Peer
227 {
228
229   union
230   {
231     struct
232     {
233       /**
234        * The peer handle from testing API
235        */
236       struct GNUNET_TESTING_Peer *peer;
237
238       /**
239        * The modified (by GNUNET_TESTING_peer_configure) configuration this
240        * peer is configured with
241        */
242       struct GNUNET_CONFIGURATION_Handle *cfg;
243
244       /**
245        * Is the peer running
246        */
247       int is_running;
248
249     } local;
250
251     struct
252     {
253       /**
254        * The slave this peer is started through
255        */
256       struct Slave *slave;
257
258       /**
259        * The id of the remote host this peer is running on
260        */
261       uint32_t remote_host_id;
262
263     } remote;
264
265   } details;
266
267   /**
268    * Is this peer locally created?
269    */
270   int is_remote;
271
272   /**
273    * Our local reference id for this peer
274    */
275   uint32_t id;
276
277   /**
278    * References to peers are using in forwarded overlay contexts and remote
279    * overlay connect contexts. A peer can only be destroyed after all such
280    * contexts are destroyed. For this, we maintain a reference counter. When we
281    * use a peer in any such context, we increment this counter. We decrement it
282    * when we are destroying these contexts
283    */
284   uint32_t reference_cnt;
285
286   /**
287    * While destroying a peer, due to the fact that there could be references to
288    * this peer, we delay the peer destroy to a further time. We do this by using
289    * this flag to destroy the peer while destroying a context in which this peer
290    * has been used. When the flag is set to 1 and reference_cnt = 0 we destroy
291    * the peer
292    */
293   uint32_t destroy_flag;
294
295 };
296
297
298 /**
299  * The main context information associated with the client which started us
300  */
301 struct Context
302 {
303   /**
304    * The client handle associated with this context
305    */
306   struct GNUNET_SERVER_Client *client;
307
308   /**
309    * The network address of the master controller
310    */
311   char *master_ip;
312
313   /**
314    * The TESTING system handle for starting peers locally
315    */
316   struct GNUNET_TESTING_System *system;
317
318   /**
319    * Our host id according to this context
320    */
321   uint32_t host_id;
322 };
323
324
325 /**
326  * The structure for identifying a shared service
327  */
328 struct SharedService
329 {
330   /**
331    * The name of the shared service
332    */
333   char *name;
334
335   /**
336    * Number of shared peers per instance of the shared service
337    */
338   uint32_t num_shared;
339
340   /**
341    * Number of peers currently sharing the service
342    */
343   uint32_t num_sharing;
344 };
345
346
347 /**
348  * Context information to used during operations which forward the overlay
349  * connect message
350  */
351 struct ForwardedOverlayConnectContext
352 {
353   /**
354    * next ForwardedOverlayConnectContext in the DLL
355    */
356   struct ForwardedOverlayConnectContext *next;
357
358   /**
359    * previous ForwardedOverlayConnectContext in the DLL
360    */
361   struct ForwardedOverlayConnectContext *prev;
362
363   /**
364    * A copy of the original overlay connect message
365    */
366   struct GNUNET_MessageHeader *orig_msg;
367
368   /**
369    * The id of the operation which created this context information
370    */
371   uint64_t operation_id;
372
373   /**
374    * the id of peer 1
375    */
376   uint32_t peer1;
377
378   /**
379    * The id of peer 2
380    */
381   uint32_t peer2;
382
383   /**
384    * Id of the host where peer2 is running
385    */
386   uint32_t peer2_host_id;
387 };
388
389
390 /**
391  * The type for data structures which commonly arrive at the slave_event_callback
392  */
393 enum ClosureType
394 {
395   /**
396    * Type for RegisteredHostContext closures
397    */
398   CLOSURE_TYPE_RHC = 1,
399
400   /**
401    * Type for LinkControllersForwardingContext closures
402    */
403   CLOSURE_TYPE_LCF
404 };
405
406
407 /**
408  * This context information will be created for each host that is registered at
409  * slave controllers during overlay connects.
410  */
411 struct RegisteredHostContext
412 {
413   /**
414    * The type of this data structure. Set this to CLOSURE_TYPE_RHC
415    */
416   enum ClosureType type;
417
418   /**
419    * The host which is being registered
420    */
421   struct GNUNET_TESTBED_Host *reg_host;
422
423   /**
424    * The host of the controller which has to connect to the above rhost
425    */
426   struct GNUNET_TESTBED_Host *host;
427
428   /**
429    * The gateway to which this operation is forwarded to
430    */
431   struct Slave *gateway;
432
433   /**
434    * The gateway through which peer2's controller can be reached
435    */
436   struct Slave *gateway2;
437
438   /**
439    * Handle for sub-operations
440    */
441   struct GNUNET_TESTBED_Operation *sub_op;
442
443   /**
444    * The client which initiated the link controller operation
445    */
446   struct GNUNET_SERVER_Client *client;
447
448   /**
449    * Head of the ForwardedOverlayConnectContext DLL
450    */
451   struct ForwardedOverlayConnectContext *focc_dll_head;
452
453   /**
454    * Tail of the ForwardedOverlayConnectContext DLL
455    */
456   struct ForwardedOverlayConnectContext *focc_dll_tail;
457
458   /**
459    * Enumeration of states for this context
460    */
461   enum RHCState
462   {
463
464     /**
465      * The initial state
466      */
467     RHC_INIT = 0,
468
469     /**
470      * State where we attempt to get peer2's controller configuration
471      */
472     RHC_GET_CFG,
473
474     /**
475      * State where we attempt to link the controller of peer 1 to the controller
476      * of peer2
477      */
478     RHC_LINK,
479
480     /**
481      * State where we attempt to do the overlay connection again
482      */
483     RHC_OL_CONNECT
484   } state;
485
486 };
487
488
489 /**
490  * States of LCFContext
491  */
492 enum LCFContextState
493 {
494   /**
495    * The Context has been initialized; Nothing has been done on it
496    */
497   INIT,
498
499   /**
500    * Delegated host has been registered at the forwarding controller
501    */
502   DELEGATED_HOST_REGISTERED,
503
504   /**
505    * The slave host has been registred at the forwarding controller
506    */
507   SLAVE_HOST_REGISTERED,
508
509   /**
510    * The context has been finished (may have error)
511    */
512   FINISHED
513 };
514
515
516 /**
517  * Link controllers request forwarding context
518  */
519 struct LCFContext
520 {
521   /**
522    * The type of this data structure. Set this to CLOSURE_TYPE_LCF
523    */
524   enum ClosureType type;
525   
526   /**
527    * The gateway which will pass the link message to delegated host
528    */
529   struct Slave *gateway;
530
531   /**
532    * The client which has asked to perform this operation
533    */
534   struct GNUNET_SERVER_Client *client;
535
536   /**
537    * Handle for operations which are forwarded while linking controllers
538    */
539   struct GNUNET_TESTBED_Operation *op;
540
541   /**
542    * The configuration which has to be either used as a template while starting
543    * the delegated controller or for connecting to the delegated controller
544    */
545   struct GNUNET_CONFIGURATION_Handle *cfg;
546
547   /**
548    * The timeout task
549    */
550   GNUNET_SCHEDULER_TaskIdentifier timeout_task;
551
552   /**
553    * The id of the operation which created this context
554    */
555   uint64_t operation_id;
556   
557   /**
558    * should the slave controller start the delegated controller?
559    */
560   int is_subordinate;
561
562   /**
563    * The state of this context
564    */
565   enum LCFContextState state;
566
567   /**
568    * The delegated host
569    */
570   uint32_t delegated_host_id;
571
572   /**
573    * The slave host
574    */
575   uint32_t slave_host_id;
576
577 };
578
579
580 /**
581  * Structure of a queue entry in LCFContext request queue
582  */
583 struct LCFContextQueue
584 {
585   /**
586    * The LCFContext
587    */
588   struct LCFContext *lcf;
589
590   /**
591    * Head prt for DLL
592    */
593   struct LCFContextQueue *next;
594
595   /**
596    * Tail ptr for DLL
597    */
598   struct LCFContextQueue *prev;
599 };
600
601
602 /**
603  * Context data for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler
604  */
605 struct HandlerContext_ShutdownPeers
606 {
607   /**
608    * The number of slave we expect to hear from since we forwarded the
609    * GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them
610    */
611   unsigned int nslaves;
612
613   /**
614    * Did we observe a timeout with respect to this operation at any of the
615    * slaves
616    */
617   int timeout;
618 };
619
620
621 /**
622  * Our configuration
623  */
624 struct GNUNET_CONFIGURATION_Handle *our_config;
625
626 /**
627  * The master context; generated with the first INIT message
628  */
629 extern struct Context *GST_context;
630
631 /**
632  * DLL head for forwarded operation contexts
633  */
634 extern struct ForwardedOperationContext *fopcq_head;
635
636 /**
637  * DLL tail for forwarded operation contexts
638  */
639 extern struct ForwardedOperationContext *fopcq_tail;
640
641 /**
642  * A list of peers we know about
643  */
644 extern struct Peer **GST_peer_list;
645
646 /**
647  * Array of hosts
648  */
649 extern struct GNUNET_TESTBED_Host **GST_host_list;
650
651 /**
652  * A list of directly linked neighbours
653  */
654 extern struct Slave **GST_slave_list;
655
656 /**
657  * Operation queue for open file descriptors
658  */
659 extern struct OperationQueue *GST_opq_openfds;
660
661 /**
662  * Timeout for operations which may take some time
663  */
664 const extern struct GNUNET_TIME_Relative GST_timeout;
665
666 /**
667  * The size of the peer list
668  */
669 extern unsigned int GST_peer_list_size;
670
671 /**
672  * The size of the host list
673  */
674 extern unsigned int GST_host_list_size;
675
676 /**
677  * The size of directly linked neighbours list
678  */
679 extern unsigned int GST_slave_list_size;
680
681 /**
682  * The directory where to store load statistics data
683  */
684 extern char *GST_stats_dir;
685
686
687 /**
688  * Similar to GNUNET_array_grow(); however instead of calling GNUNET_array_grow()
689  * several times we call it only once. The array is also made to grow in steps
690  * of LIST_GROW_STEP.
691  *
692  * @param ptr the array pointer to grow
693  * @param size the size of array
694  * @param accommodate_size the size which the array has to accommdate; after
695  *          this call the array will be big enough to accommdate sizes upto
696  *          accommodate_size
697  */
698 #define GST_array_grow_large_enough(ptr, size, accommodate_size) \
699   do                                                                    \
700   {                                                                     \
701     unsigned int growth_size;                                           \
702     GNUNET_assert (size <= accommodate_size);                            \
703     growth_size = size;                                                 \
704     while (growth_size <= accommodate_size)                             \
705       growth_size += LIST_GROW_STEP;                                    \
706     GNUNET_array_grow (ptr, size, growth_size);                         \
707     GNUNET_assert (size > accommodate_size);                            \
708   } while (0)
709
710
711 /**
712  * Queues a message in send queue for sending to the service
713  *
714  * @param client the client to whom the queued message has to be sent
715  * @param msg the message to queue
716  */
717 void
718 GST_queue_message (struct GNUNET_SERVER_Client *client,
719                    struct GNUNET_MessageHeader *msg);
720
721
722 /**
723  * Function to destroy a peer
724  *
725  * @param peer the peer structure to destroy
726  */
727 void
728 GST_destroy_peer (struct Peer *peer);
729
730
731 /**
732  * Stops and destroys all peers
733  */
734 void
735 GST_destroy_peers ();
736
737
738 /**
739  * Finds the route with directly connected host as destination through which
740  * the destination host can be reached
741  *
742  * @param host_id the id of the destination host
743  * @return the route with directly connected destination host; NULL if no route
744  *           is found
745  */
746 struct Route *
747 GST_find_dest_route (uint32_t host_id);
748
749
750 /**
751  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
752  *
753  * @param cls NULL
754  * @param client identification of the client
755  * @param message the actual message
756  */
757 void
758 GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
759                             const struct GNUNET_MessageHeader *message);
760
761
762 /**
763  * Adds a host registration's request to a slave's registration queue
764  *
765  * @param slave the slave controller at which the given host has to be
766  *          registered
767  * @param cb the host registration completion callback
768  * @param cb_cls the closure for the host registration completion callback
769  * @param host the host which has to be registered
770  */
771 void
772 GST_queue_host_registration (struct Slave *slave,
773                              GNUNET_TESTBED_HostRegistrationCompletion cb,
774                              void *cb_cls, struct GNUNET_TESTBED_Host *host);
775
776
777 /**
778  * Callback to relay the reply msg of a forwarded operation back to the client
779  *
780  * @param cls ForwardedOperationContext
781  * @param msg the message to relay
782  */
783 void
784 GST_forwarded_operation_reply_relay (void *cls,
785                                      const struct GNUNET_MessageHeader *msg);
786
787
788 /**
789  * Task to free resources when forwarded operation has been timedout
790  *
791  * @param cls the ForwardedOperationContext
792  * @param tc the task context from scheduler
793  */
794 void
795 GST_forwarded_operation_timeout (void *cls,
796                                  const struct GNUNET_SCHEDULER_TaskContext *tc);
797
798
799 /**
800  * Clears the forwarded operations queue
801  */
802 void
803 GST_clear_fopcq ();
804
805
806 /**
807  * Send operation failure message to client
808  *
809  * @param client the client to which the failure message has to be sent to
810  * @param operation_id the id of the failed operation
811  * @param emsg the error message; can be NULL
812  */
813 void
814 GST_send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
815                              uint64_t operation_id, const char *emsg);
816
817
818 /**
819  * Function to send generic operation success message to given client
820  *
821  * @param client the client to send the message to
822  * @param operation_id the id of the operation which was successful
823  */
824 void
825 GST_send_operation_success_msg (struct GNUNET_SERVER_Client *client,
826                                 uint64_t operation_id);
827
828
829 /**
830  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages
831  *
832  * @param cls NULL
833  * @param client identification of the client
834  * @param message the actual message
835  */
836 void
837 GST_handle_remote_overlay_connect (void *cls,
838                                    struct GNUNET_SERVER_Client *client,
839                                    const struct GNUNET_MessageHeader *message);
840
841
842 /**
843  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
844  *
845  * @param cls NULL
846  * @param client identification of the client
847  * @param message the actual message
848  */
849 void
850 GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
851                         const struct GNUNET_MessageHeader *message);
852
853
854 /**
855  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
856  *
857  * @param cls NULL
858  * @param client identification of the client
859  * @param message the actual message
860  */
861 void
862 GST_handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
863                          const struct GNUNET_MessageHeader *message);
864
865
866 /**
867  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
868  *
869  * @param cls NULL
870  * @param client identification of the client
871  * @param message the actual message
872  */
873 void
874 GST_handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
875                        const struct GNUNET_MessageHeader *message);
876
877
878 /**
879  * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
880  *
881  * @param cls NULL
882  * @param client identification of the client
883  * @param message the actual message
884  */
885 void
886 GST_handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
887                       const struct GNUNET_MessageHeader *message);
888
889
890 /**
891  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
892  *
893  * @param cls NULL
894  * @param client identification of the client
895  * @param message the actual message
896  */
897 void
898 GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
899                             const struct GNUNET_MessageHeader *message);
900
901
902 /**
903  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS messages
904  *
905  * @param cls NULL
906  * @param client identification of the client
907  * @param message the actual message
908  */
909 void
910 GST_handle_shutdown_peers (void *cls, struct GNUNET_SERVER_Client *client,
911                            const struct GNUNET_MessageHeader *message);
912
913
914 /**
915  * Handler for GNUNET_TESTBED_ManagePeerServiceMessage message
916  *
917  * @param cls NULL
918  * @param client identification of client
919  * @param message the actual message
920  */
921 void
922 GST_handle_manage_peer_service (void *cls, struct GNUNET_SERVER_Client *client,
923                                 const struct GNUNET_MessageHeader *message);
924
925
926 /**
927  * Frees the ManageServiceContext queue
928  */
929 void
930 GST_free_mctxq ();
931
932
933 /**
934  * Processes a forwarded overlay connect context in the queue of the given RegisteredHostContext
935  *
936  * @param rhc the RegisteredHostContext
937  */
938 void
939 GST_process_next_focc (struct RegisteredHostContext *rhc);
940
941
942 /**
943  * Cleans up ForwardedOverlayConnectContext
944  *
945  * @param focc the ForwardedOverlayConnectContext to cleanup
946  */
947 void
948 GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc);
949
950
951 /**
952  * Clears all pending overlay connect contexts in queue
953  */
954 void
955 GST_free_occq ();
956
957
958 /**
959  * Clears all pending remote overlay connect contexts in queue
960  */
961 void
962 GST_free_roccq ();
963
964
965 /**
966  * Initializes the cache
967  *
968  * @param size the size of the cache
969  */
970 void
971 GST_cache_init (unsigned int size);
972
973
974 /**
975  * Clear cache
976  */
977 void
978 GST_cache_clear ();
979
980
981 /**
982  * Looks up in the hello cache and returns the HELLO of the given peer
983  *
984  * @param peer_id the index of the peer whose HELLO has to be looked up
985  * @return the HELLO message; NULL if not found
986  */
987 const struct GNUNET_MessageHeader *
988 GST_cache_lookup_hello (const unsigned int peer_id);
989
990
991 /**
992  * Caches the HELLO of the given peer. Updates the HELLO if it was already
993  * cached before
994  *
995  * @param peer_id the peer identity of the peer whose HELLO has to be cached
996  * @param hello the HELLO message
997  */
998 void
999 GST_cache_add_hello (const unsigned int peer_id,
1000                      const struct GNUNET_MessageHeader *hello);
1001
1002
1003 /**
1004  * Functions of this type are called when the needed handle is available for
1005  * usage. These functions are to be registered with either of the functions
1006  * GST_cache_get_handle_transport() or GST_cache_get_handle_core(). The
1007  * corresponding handles will be set and if they are not, then it signals an
1008  * error while opening the handles.
1009  *
1010  * @param cls the closure passed to GST_cache_get_handle_transport() or
1011  *          GST_cache_get_handle_core()
1012  * @param ch the handle to CORE. Can be NULL if it is not requested
1013  * @param th the handle to TRANSPORT. Can be NULL if it is not requested
1014  * @param peer_id the identity of the peer. Will be NULL if ch is NULL. In other
1015  *          cases, its value being NULL means that CORE connection has failed.
1016  */
1017 typedef void (*GST_cache_handle_ready_cb) (void *cls,
1018                                            struct GNUNET_CORE_Handle * ch,
1019                                            struct GNUNET_TRANSPORT_Handle * th,
1020                                            const struct GNUNET_PeerIdentity *
1021                                            peer_id);
1022
1023
1024 /**
1025  * Callback to notify when the target peer given to
1026  * GST_cache_get_handle_transport() is connected. Note that this callback may
1027  * not be called if the target peer is already connected. Use
1028  * GNUNET_TRANSPORT_check_neighbour_connected() to check if the target peer is
1029  * already connected or not. This callback will be called only once or never (in
1030  * case the target cannot be connected).
1031  *
1032  * @param cls the closure given to GST_cache_get_handle_done() for this callback
1033  * @param target the peer identity of the target peer. The pointer should be
1034  *          valid until GST_cache_get_handle_done() is called.
1035  */
1036 typedef void (*GST_cache_peer_connect_notify) (void *cls,
1037                                                const struct GNUNET_PeerIdentity
1038                                                * target);
1039
1040
1041 /**
1042  * Get a transport handle with the given configuration. If the handle is already
1043  * cached before, it will be retured in the given callback; the peer_id is used to lookup in the
1044  * cache. If not a new operation is started to open the transport handle and
1045  * will be given in the callback when it is available.
1046  *
1047  * @param peer_id the index of the peer
1048  * @param cfg the configuration with which the transport handle has to be
1049  *          created if it was not present in the cache
1050  * @param cb the callback to notify when the transport handle is available
1051  * @param cb_cls the closure for the above callback
1052  * @param target the peer identify of the peer whose connection to our TRANSPORT
1053  *          subsystem will be notified through the connect_notify_cb. Can be NULL
1054  * @param connect_notify_cb the callback to call when the given target peer is
1055  *          connected. This callback will only be called once or never again (in
1056  *          case the target peer cannot be connected). Can be NULL
1057  * @param connect_notify_cb_cls the closure for the above callback
1058  * @return the handle which can be used cancel or mark that the handle is no
1059  *           longer being used
1060  */
1061 struct GSTCacheGetHandle *
1062 GST_cache_get_handle_transport (unsigned int peer_id,
1063                                 const struct GNUNET_CONFIGURATION_Handle *cfg,
1064                                 GST_cache_handle_ready_cb cb, void *cb_cls,
1065                                 const struct GNUNET_PeerIdentity *target,
1066                                 GST_cache_peer_connect_notify connect_notify_cb,
1067                                 void *connect_notify_cb_cls);
1068
1069
1070 /**
1071  * Get a CORE handle with the given configuration. If the handle is already
1072  * cached before, it will be retured in the given callback; the peer_id is used
1073  * to lookup in the cache. If the handle is not cached before, a new operation
1074  * is started to open the CORE handle and will be given in the callback when it
1075  * is available along with the peer identity
1076  *
1077  * @param peer_id the index of the peer
1078  * @param cfg the configuration with which the transport handle has to be
1079  *          created if it was not present in the cache
1080  * @param cb the callback to notify when the transport handle is available
1081  * @param cb_cls the closure for the above callback
1082  * @param target the peer identify of the peer whose connection to our CORE
1083  *          subsystem will be notified through the connect_notify_cb. Can be NULL
1084  * @param connect_notify_cb the callback to call when the given target peer is
1085  *          connected. This callback will only be called once or never again (in
1086  *          case the target peer cannot be connected). Can be NULL
1087  * @param connect_notify_cb_cls the closure for the above callback
1088  * @return the handle which can be used cancel or mark that the handle is no
1089  *           longer being used
1090  */
1091 struct GSTCacheGetHandle *
1092 GST_cache_get_handle_core (unsigned int peer_id,
1093                            const struct GNUNET_CONFIGURATION_Handle *cfg,
1094                            GST_cache_handle_ready_cb cb, void *cb_cls,
1095                            const struct GNUNET_PeerIdentity *target,
1096                            GST_cache_peer_connect_notify connect_notify_cb,
1097                            void *connect_notify_cb_cls);
1098
1099
1100 /**
1101  * Mark the GetCacheHandle as being done if a handle has been provided already
1102  * or as being cancelled if the callback for the handle hasn't been called.
1103  *
1104  * @param cgh the CacheGetHandle handle
1105  */
1106 void
1107 GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh);
1108
1109
1110 /**
1111  * Initialize logging CPU and IO statisticfs.  Checks the configuration for
1112  * "STATS_DIR" and logs to a file in that directory.  The file is name is
1113  * generated from the hostname and the process's PID.
1114  */
1115 void
1116 GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
1117
1118
1119 /**
1120  * Shutdown the status calls module.
1121  */
1122 void
1123 GST_stats_destroy ();
1124
1125 /* End of gnunet-service-testbed.h */