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