glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed_links.h
1 /*
2   This file is part of GNUnet.
3   Copyright (C) 2008--2013 GNUnet e.V.
4
5   GNUnet is free software: you can redistribute it and/or modify it
6   under the terms of the GNU Affero General Public License as published
7   by the Free Software Foundation, either version 3 of the License,
8   or (at your 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   Affero General Public License for more details.
14 */
15
16 /**
17  * @file testbed/gnunet-service-testbed_links.h
18  * @brief TESTBED service components that deals with starting slave controllers
19  *          and establishing lateral links between controllers
20  * @author Sree Harsha Totakura
21  */
22
23
24 /**
25  * A connected controller which is not our child
26  */
27 struct Neighbour;
28
29
30 /**
31  * Structure representing a connected(directly-linked) controller
32  */
33 struct Slave
34 {
35   /**
36    * The controller process handle if we had started the controller
37    */
38   struct GNUNET_TESTBED_ControllerProc *controller_proc;
39
40   /**
41    * The controller handle
42    */
43   struct GNUNET_TESTBED_Controller *controller;
44
45   /**
46    * handle to lcc which is associated with this slave startup. Should be set to
47    * NULL when the slave has successfully started up
48    */
49   struct LinkControllersContext *lcc;
50
51   /**
52    * Head of the host registration DLL
53    */
54   struct HostRegistration *hr_dll_head;
55
56   /**
57    * Tail of the host registration DLL
58    */
59   struct HostRegistration *hr_dll_tail;
60
61   /**
62    * The current host registration handle
63    */
64   struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
65
66   /**
67    * Hashmap to hold Registered host contexts
68    */
69   struct GNUNET_CONTAINER_MultiHashMap *reghost_map;
70
71   /**
72    * The id of the host this controller is running on
73    */
74   uint32_t host_id;
75 };
76
77 /**
78  * A list of directly linked neighbours
79  */
80 extern struct Slave **GST_slave_list;
81
82 /**
83  * The size of directly linked neighbours list
84  */
85 extern unsigned int GST_slave_list_size;
86
87
88 /**
89  * Cleans up the neighbour list
90  */
91 void
92 GST_neighbour_list_clean (void);
93
94
95 /**
96  * Get a neighbour from the neighbour list
97  *
98  * @param id the index of the neighbour in the neighbour list
99  * @return the Neighbour; NULL if the given index in invalid (index greater than
100  *           the list size or neighbour at that index is NULL)
101  */
102 struct Neighbour *
103 GST_get_neighbour (uint32_t id);
104
105
106 /**
107  * Function to cleanup the neighbour connect contexts
108  */
109 void
110 GST_free_nccq (void);
111
112
113 /**
114  * Notification context to be used to notify when connection to the neighbour's
115  * controller is opened
116  */
117 struct NeighbourConnectNotification;
118
119
120 /**
121  * The notification callback to call when we are connect to neighbour
122  *
123  * @param cls the closure given to GST_neighbour_get_connection()
124  * @param controller the controller handle to the neighbour
125  */
126 typedef void
127 (*GST_NeigbourConnectNotifyCallback) (void *cls,
128                                       struct GNUNET_TESTBED_Controller *controller);
129
130
131 /**
132  * Try to open a connection to the given neigbour.  If the connection is open
133  * already, then it is re-used.  If not, the request is queued in the operation
134  * queues responsible for bounding the total number of file descriptors.  The
135  * actual connection will happen when the operation queue marks the
136  * corresponding operation as active.
137  *
138  * @param n the neighbour to open a connection to
139  * @param cb the notification callback to call when the connection is opened
140  * @param cb_cls the closure for the above callback
141  */
142 struct NeighbourConnectNotification *
143 GST_neighbour_get_connection (struct Neighbour *n,
144                               GST_NeigbourConnectNotifyCallback cb,
145                               void *cb_cls);
146
147
148 /**
149  * Cancel the request for opening a connection to the neighbour
150  *
151  * @param h the notification handle
152  */
153 void
154 GST_neighbour_get_connection_cancel (struct NeighbourConnectNotification *h);
155
156
157 /**
158  * Release the connection to the neighbour.  The actual connection will be
159  * closed if connections to other neighbour are waiting (to maintain a bound on
160  * the total number of connections that are open).
161  *
162  * @param n the neighbour whose connection can be closed
163  */
164 void
165 GST_neighbour_release_connection (struct Neighbour *n);
166
167
168 /**
169  * Function to create a neigbour and add it into the neighbour list
170  *
171  * @param host the host of the neighbour
172  */
173 struct Neighbour *
174 GST_create_neighbour (struct GNUNET_TESTBED_Host *host);
175
176
177 /**
178  * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
179  *
180  * @param cls identification of the client
181  * @param msg the actual message
182  */
183 void
184 handle_link_controllers (void *cls,
185                          const struct GNUNET_TESTBED_ControllerLinkRequest *msg);
186
187
188 /**
189  * Clean up @a client handle if we stored any via #handle_link_controllers(),
190  * the given client disconnected.
191  *
192  * @param client the client that is history
193  */
194 void
195 GST_link_notify_disconnect (struct GNUNET_SERVICE_Client *client);
196
197
198 /**
199  * Cleans up the slave list
200  */
201 void
202 GST_slave_list_clear (void);