2 This file is part of GNUnet.
3 (C) 2013 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 3, 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.
21 * @file conversation/gnunet-service-conversation.c
22 * @brief conversation service implementation
23 * @author Simon Dieterle
24 * @author Andreas Fuchs
25 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_applications.h"
31 #include "gnunet_constants.h"
32 #include "gnunet_mesh_service.h"
33 #include "gnunet_conversation_service.h"
34 #include "conversation.h"
38 * The possible connection status
43 * We are waiting for incoming calls.
48 * Our phone is ringing, waiting for the client to pick up.
58 * We are waiting for the phone to be picked up.
68 * We're in shutdown, sending hangup messages before cleaning up.
75 * A line connects a local client with a mesh tunnel (or, if it is an
76 * open line, is waiting for a mesh tunnel).
91 * Handle for the reliable tunnel (contol data)
93 struct GNUNET_MESH_Tunnel *tunnel_reliable;
96 * Handle for unreliable tunnel (audio data)
98 struct GNUNET_MESH_Tunnel *tunnel_unreliable;
101 * Transmit handle for pending audio messages
103 struct GNUNET_MESH_TransmitHandle *mth;
111 * Current status of this line.
113 enum LineStatus status;
121 static const struct GNUNET_CONFIGURATION_Handle *cfg;
124 * Notification context containing all connected clients.
126 static struct GNUNET_SERVER_NotificationContext *nc;
131 static struct GNUNET_MESH_Handle *mesh;
134 * Head of DLL of active lines.
136 static struct Line *lines_head;
139 * Tail of DLL of active lines.
141 static struct Line *lines_tail;
145 * Function to register a phone.
147 * @param cls closure, NULL
148 * @param client the client from which the message is
149 * @param message the message from the client
152 handle_client_register_message (void *cls,
153 struct GNUNET_SERVER_Client *client,
154 const struct GNUNET_MessageHeader *message)
156 const struct ClientPhoneRegisterMessage *msg;
158 msg = (struct ClientPhoneRegisterMessage *) message;
159 GNUNET_break (0); // FIXME
160 GNUNET_SERVER_receive_done (client, GNUNET_OK);
165 * Function to handle a pickup request message from the client
167 * @param cls closure, NULL
168 * @param client the client from which the message is
169 * @param message the message from the client
172 handle_client_pickup_message (void *cls,
173 struct GNUNET_SERVER_Client *client,
174 const struct GNUNET_MessageHeader *message)
176 const struct ClientPhonePickupMessage *msg;
178 msg = (struct ClientPhonePickupMessage *) message;
179 GNUNET_break (0); // FIXME
180 GNUNET_SERVER_receive_done (client, GNUNET_OK);
185 * Function to handle a hangup request message from the client
187 * @param cls closure, NULL
188 * @param client the client from which the message is
189 * @param message the message from the client
192 handle_client_hangup_message (void *cls,
193 struct GNUNET_SERVER_Client *client,
194 const struct GNUNET_MessageHeader *message)
196 const struct ClientPhoneHangupMessage *msg;
198 msg = (struct ClientPhoneHangupMessage *) message;
199 GNUNET_break (0); // FIXME
200 GNUNET_SERVER_receive_done (client, GNUNET_OK);
205 * Function to handle call request the client
207 * @param cls closure, NULL
208 * @param client the client from which the message is
209 * @param message the message from the client
212 handle_client_call_message (void *cls,
213 struct GNUNET_SERVER_Client *client,
214 const struct GNUNET_MessageHeader *message)
216 const struct ClientCallMessage *msg;
218 msg = (struct ClientCallMessage *) message;
219 GNUNET_break (0); // FIXME
220 GNUNET_SERVER_receive_done (client, GNUNET_OK);
225 * Function to handle audio data from the client
227 * @param cls closure, NULL
228 * @param client the client from which the message is
229 * @param message the message from the client
232 handle_client_audio_message (void *cls,
233 struct GNUNET_SERVER_Client *client,
234 const struct GNUNET_MessageHeader *message)
236 const struct ClientAudioMessage *msg;
238 msg = (struct ClientAudioMessage *) message;
239 GNUNET_break (0); // FIXME
240 GNUNET_SERVER_receive_done (client, GNUNET_OK);
245 * Function to handle a ring message incoming over mesh
247 * @param cls closure, NULL
248 * @param tunnel the tunnel over which the message arrived
249 * @param tunnel_ctx the tunnel context, can be NULL
250 * @param message the incoming message
254 handle_mesh_ring_message (void *cls,
255 struct GNUNET_MESH_Tunnel *tunnel,
257 const struct GNUNET_MessageHeader *message)
259 const struct MeshPhoneRingMessage *msg;
261 msg = (const struct MeshPhoneRingMessage *) message;
262 GNUNET_break (0); // FIXME
268 * Function to handle a hangup message incoming over mesh
270 * @param cls closure, NULL
271 * @param tunnel the tunnel over which the message arrived
272 * @param tunnel_ctx the tunnel context, can be NULL
273 * @param message the incoming message
277 handle_mesh_hangup_message (void *cls,
278 struct GNUNET_MESH_Tunnel *tunnel,
280 const struct GNUNET_MessageHeader *message)
282 const struct MeshPhoneHangupMessage *msg;
284 msg = (const struct MeshPhoneHangupMessage *) message;
285 GNUNET_break (0); // FIXME
291 * Function to handle a pickup message incoming over mesh
293 * @param cls closure, NULL
294 * @param tunnel the tunnel over which the message arrived
295 * @param tunnel_ctx the tunnel context, can be NULL
296 * @param message the incoming message
300 handle_mesh_pickup_message (void *cls,
301 struct GNUNET_MESH_Tunnel *tunnel,
303 const struct GNUNET_MessageHeader *message)
305 const struct MeshPhonePickupMessage *msg;
307 msg = (const struct MeshPhonePickupMessage *) message;
308 GNUNET_break (0); // FIXME
314 * Function to handle a busy message incoming over mesh
316 * @param cls closure, NULL
317 * @param tunnel the tunnel over which the message arrived
318 * @param tunnel_ctx the tunnel context, can be NULL
319 * @param message the incoming message
323 handle_mesh_busy_message (void *cls,
324 struct GNUNET_MESH_Tunnel *tunnel,
326 const struct GNUNET_MessageHeader *message)
328 const struct MeshPhoneBusyMessage *msg;
330 msg = (const struct MeshPhoneBusyMessage *) message;
331 GNUNET_break (0); // FIXME
337 * Function to handle an audio message incoming over mesh
339 * @param cls closure, NULL
340 * @param tunnel the tunnel over which the message arrived
341 * @param tunnel_ctx the tunnel context, can be NULL
342 * @param message the incoming message
346 handle_mesh_audio_message (void *cls,
347 struct GNUNET_MESH_Tunnel *tunnel,
349 const struct GNUNET_MessageHeader *message)
351 const struct MeshAudioMessage *msg;
353 msg = (const struct MeshAudioMessage *) message;
354 GNUNET_break (0); // FIXME
360 * Method called whenever another peer has added us to a tunnel
361 * the other peer initiated.
364 * @param tunnel new handle to the tunnel
365 * @param initiator peer that started the tunnel
367 * @return initial tunnel context for the tunnel (can be NULL -- that's not an error)
370 inbound_tunnel (void *cls,
371 struct GNUNET_MESH_Tunnel *tunnel,
372 const struct GNUNET_PeerIdentity *initiator,
375 GNUNET_break (0); // FIXME
376 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
377 _("Received incoming tunnel on port %d\n"), port);
383 * Function called whenever an inbound tunnel is destroyed. Should clean up
384 * any associated state.
386 * @param cls closure (set from #GNUNET_MESH_connect)
387 * @param tunnel connection to the other end (henceforth invalid)
388 * @param tunnel_ctx place where local state associated
389 * with the tunnel is stored
392 inbound_end (void *cls,
393 const struct GNUNET_MESH_Tunnel *tunnel,
396 GNUNET_break (0); // FIXME
401 * A client disconnected. Remove all of its data structure entries.
403 * @param cls closure, NULL
404 * @param client identification of the client
407 handle_client_disconnect (void *cls,
408 struct GNUNET_SERVER_Client *cl)
410 GNUNET_break (0); // FIXME
417 * @param cls closure, NULL
418 * @param tc the task context
421 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
423 GNUNET_break (0); // FIXME
426 GNUNET_MESH_disconnect (mesh);
431 GNUNET_SERVER_notification_context_destroy (nc);
438 * Main function that will be run by the scheduler.
441 * @param server server handle
442 * @param c configuration
446 struct GNUNET_SERVER_Handle *server,
447 const struct GNUNET_CONFIGURATION_Handle *c)
449 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
450 {&handle_client_register_message, NULL,
451 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER,
452 sizeof (struct ClientPhoneRegisterMessage)},
453 {&handle_client_pickup_message, NULL,
454 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP,
456 {&handle_client_hangup_message, NULL,
457 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
459 {&handle_client_call_message, NULL,
460 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL,
462 {&handle_client_audio_message, NULL,
463 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
467 static struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
468 {&handle_mesh_ring_message,
469 GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_RING,
470 sizeof (struct MeshPhoneRingMessage)},
471 {&handle_mesh_hangup_message,
472 GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_HANG_UP,
474 {&handle_mesh_pickup_message,
475 GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_PICK_UP,
477 {&handle_mesh_busy_message,
478 GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_BUSY,
479 sizeof (struct MeshPhoneBusyMessage)},
480 {&handle_mesh_audio_message, GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_AUDIO,
484 static uint32_t ports[] = {
485 GNUNET_APPLICATION_TYPE_CONVERSATION_CONTROL,
486 GNUNET_APPLICATION_TYPE_CONVERSATION_AUDIO,
491 mesh = GNUNET_MESH_connect (cfg,
501 GNUNET_SCHEDULER_shutdown ();
504 nc = GNUNET_SERVER_notification_context_create (server, 16);
505 GNUNET_SERVER_add_handlers (server, server_handlers);
506 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
507 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
514 * The main function for the conversation service.
516 * @param argc number of arguments from the command line
517 * @param argv command line arguments
518 * @return 0 ok, 1 on error
525 GNUNET_SERVICE_run (argc, argv,
527 GNUNET_SERVICE_OPTION_NONE,
528 &run, NULL)) ? 0 : 1;
531 /* end of gnunet-service-conversation.c */