diff options
Diffstat (limited to 'src/conversation/gnunet-service-conversation.c')
-rw-r--r-- | src/conversation/gnunet-service-conversation.c | 1348 |
1 files changed, 697 insertions, 651 deletions
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c index 3e531e202..e5e225623 100644 --- a/src/conversation/gnunet-service-conversation.c +++ b/src/conversation/gnunet-service-conversation.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013, 2016, 2017 GNUnet e.V. | 3 | Copyright (C) 2013, 2016, 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 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, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet-service-conversation.c | 21 | * @file conversation/gnunet-service-conversation.c |
22 | * @brief conversation service implementation | 22 | * @brief conversation service implementation |
@@ -52,8 +52,7 @@ struct Line; | |||
52 | /** | 52 | /** |
53 | * The possible connection status | 53 | * The possible connection status |
54 | */ | 54 | */ |
55 | enum ChannelStatus | 55 | enum ChannelStatus { |
56 | { | ||
57 | /** | 56 | /** |
58 | * We just got the connection, but no introduction yet. | 57 | * We just got the connection, but no introduction yet. |
59 | */ | 58 | */ |
@@ -88,7 +87,6 @@ enum ChannelStatus | |||
88 | * We're in shutdown, sending hangup messages before cleaning up. | 87 | * We're in shutdown, sending hangup messages before cleaning up. |
89 | */ | 88 | */ |
90 | CS_CALLER_SHUTDOWN | 89 | CS_CALLER_SHUTDOWN |
91 | |||
92 | }; | 90 | }; |
93 | 91 | ||
94 | 92 | ||
@@ -98,9 +96,7 @@ enum ChannelStatus | |||
98 | * be attached the the same `struct Line`, which represents a local | 96 | * be attached the the same `struct Line`, which represents a local |
99 | * client. We keep them in a linked list. | 97 | * client. We keep them in a linked list. |
100 | */ | 98 | */ |
101 | struct Channel | 99 | struct Channel { |
102 | { | ||
103 | |||
104 | /** | 100 | /** |
105 | * This is a DLL. | 101 | * This is a DLL. |
106 | */ | 102 | */ |
@@ -156,8 +152,7 @@ struct Channel | |||
156 | /** | 152 | /** |
157 | * A `struct Line` connects a local client with cadet channels. | 153 | * A `struct Line` connects a local client with cadet channels. |
158 | */ | 154 | */ |
159 | struct Line | 155 | struct Line { |
160 | { | ||
161 | /** | 156 | /** |
162 | * This is a DLL. | 157 | * This is a DLL. |
163 | */ | 158 | */ |
@@ -221,7 +216,7 @@ static struct GNUNET_PeerIdentity my_identity; | |||
221 | * @return NULL for not found | 216 | * @return NULL for not found |
222 | */ | 217 | */ |
223 | static struct Channel * | 218 | static struct Channel * |
224 | find_channel_by_line (struct Line *line, uint32_t cid) | 219 | find_channel_by_line(struct Line *line, uint32_t cid) |
225 | { | 220 | { |
226 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = ch->next) | 221 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = ch->next) |
227 | if (cid == ch->cid) | 222 | if (cid == ch->cid) |
@@ -237,8 +232,8 @@ find_channel_by_line (struct Line *line, uint32_t cid) | |||
237 | * @param msg the message from the client | 232 | * @param msg the message from the client |
238 | */ | 233 | */ |
239 | static void | 234 | static void |
240 | handle_client_pickup_message (void *cls, | 235 | handle_client_pickup_message(void *cls, |
241 | const struct ClientPhonePickupMessage *msg) | 236 | const struct ClientPhonePickupMessage *msg) |
242 | { | 237 | { |
243 | struct Line *line = cls; | 238 | struct Line *line = cls; |
244 | struct CadetPhonePickupMessage *mppm; | 239 | struct CadetPhonePickupMessage *mppm; |
@@ -246,52 +241,56 @@ handle_client_pickup_message (void *cls, | |||
246 | struct Channel *ch; | 241 | struct Channel *ch; |
247 | 242 | ||
248 | if (NULL == line->port) | 243 | if (NULL == line->port) |
249 | { | 244 | { |
250 | /* we never opened the port, bad client! */ | 245 | /* we never opened the port, bad client! */ |
251 | GNUNET_break_op (0); | 246 | GNUNET_break_op(0); |
252 | GNUNET_SERVICE_client_drop (line->client); | 247 | GNUNET_SERVICE_client_drop(line->client); |
253 | return; | 248 | return; |
254 | } | 249 | } |
255 | for (ch = line->channel_head; NULL != ch; ch = ch->next) | 250 | for (ch = line->channel_head; NULL != ch; ch = ch->next) |
256 | if (msg->cid == ch->cid) | 251 | if (msg->cid == ch->cid) |
257 | break; | 252 | break; |
258 | if (NULL == ch) | 253 | if (NULL == ch) |
259 | { | 254 | { |
260 | /* could have been destroyed asynchronously, ignore message */ | 255 | /* could have been destroyed asynchronously, ignore message */ |
261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 256 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
262 | GNUNET_SERVICE_client_continue (line->client); | 257 | GNUNET_SERVICE_client_continue(line->client); |
263 | return; | 258 | return; |
264 | } | 259 | } |
265 | switch (ch->status) | 260 | switch (ch->status) |
266 | { | 261 | { |
267 | case CS_CALLEE_INIT: | 262 | case CS_CALLEE_INIT: |
268 | GNUNET_break (0); | 263 | GNUNET_break(0); |
269 | GNUNET_SERVICE_client_drop (line->client); | 264 | GNUNET_SERVICE_client_drop(line->client); |
270 | return; | 265 | return; |
271 | case CS_CALLEE_RINGING: | 266 | |
272 | ch->status = CS_CALLEE_CONNECTED; | 267 | case CS_CALLEE_RINGING: |
273 | break; | 268 | ch->status = CS_CALLEE_CONNECTED; |
274 | case CS_CALLEE_CONNECTED: | 269 | break; |
275 | GNUNET_break (0); | 270 | |
276 | GNUNET_SERVICE_client_drop (line->client); | 271 | case CS_CALLEE_CONNECTED: |
277 | return; | 272 | GNUNET_break(0); |
278 | case CS_CALLEE_SHUTDOWN: | 273 | GNUNET_SERVICE_client_drop(line->client); |
279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 274 | return; |
280 | "Ignoring client's PICKUP message, line is in SHUTDOWN\n"); | 275 | |
281 | break; | 276 | case CS_CALLEE_SHUTDOWN: |
282 | case CS_CALLER_CALLING: | 277 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
283 | case CS_CALLER_CONNECTED: | 278 | "Ignoring client's PICKUP message, line is in SHUTDOWN\n"); |
284 | case CS_CALLER_SHUTDOWN: | 279 | break; |
285 | GNUNET_break (0); | 280 | |
286 | GNUNET_SERVICE_client_drop (line->client); | 281 | case CS_CALLER_CALLING: |
287 | return; | 282 | case CS_CALLER_CONNECTED: |
288 | } | 283 | case CS_CALLER_SHUTDOWN: |
289 | GNUNET_break (CS_CALLEE_CONNECTED == ch->status); | 284 | GNUNET_break(0); |
290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICK_UP message to cadet\n"); | 285 | GNUNET_SERVICE_client_drop(line->client); |
286 | return; | ||
287 | } | ||
288 | GNUNET_break(CS_CALLEE_CONNECTED == ch->status); | ||
289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending PICK_UP message to cadet\n"); | ||
291 | env = | 290 | env = |
292 | GNUNET_MQ_msg (mppm, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); | 291 | GNUNET_MQ_msg(mppm, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); |
293 | GNUNET_MQ_send (ch->mq, env); | 292 | GNUNET_MQ_send(ch->mq, env); |
294 | GNUNET_SERVICE_client_continue (line->client); | 293 | GNUNET_SERVICE_client_continue(line->client); |
295 | } | 294 | } |
296 | 295 | ||
297 | 296 | ||
@@ -302,34 +301,35 @@ handle_client_pickup_message (void *cls, | |||
302 | * @param ch channel that went down | 301 | * @param ch channel that went down |
303 | */ | 302 | */ |
304 | static void | 303 | static void |
305 | clean_up_channel (struct Channel *ch) | 304 | clean_up_channel(struct Channel *ch) |
306 | { | 305 | { |
307 | struct Line *line = ch->line; | 306 | struct Line *line = ch->line; |
308 | struct GNUNET_MQ_Envelope *env; | 307 | struct GNUNET_MQ_Envelope *env; |
309 | struct ClientPhoneHangupMessage *hup; | 308 | struct ClientPhoneHangupMessage *hup; |
310 | 309 | ||
311 | switch (ch->status) | 310 | switch (ch->status) |
312 | { | ||
313 | case CS_CALLEE_INIT: | ||
314 | case CS_CALLEE_SHUTDOWN: | ||
315 | case CS_CALLER_SHUTDOWN: | ||
316 | break; | ||
317 | case CS_CALLEE_RINGING: | ||
318 | case CS_CALLEE_CONNECTED: | ||
319 | case CS_CALLER_CALLING: | ||
320 | case CS_CALLER_CONNECTED: | ||
321 | if (NULL != line) | ||
322 | { | 311 | { |
323 | env = | 312 | case CS_CALLEE_INIT: |
324 | GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | 313 | case CS_CALLEE_SHUTDOWN: |
325 | hup->cid = ch->cid; | 314 | case CS_CALLER_SHUTDOWN: |
326 | GNUNET_MQ_send (line->mq, env); | 315 | break; |
316 | |||
317 | case CS_CALLEE_RINGING: | ||
318 | case CS_CALLEE_CONNECTED: | ||
319 | case CS_CALLER_CALLING: | ||
320 | case CS_CALLER_CONNECTED: | ||
321 | if (NULL != line) | ||
322 | { | ||
323 | env = | ||
324 | GNUNET_MQ_msg(hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | ||
325 | hup->cid = ch->cid; | ||
326 | GNUNET_MQ_send(line->mq, env); | ||
327 | } | ||
328 | break; | ||
327 | } | 329 | } |
328 | break; | ||
329 | } | ||
330 | if (NULL != line) | 330 | if (NULL != line) |
331 | GNUNET_CONTAINER_DLL_remove (line->channel_head, line->channel_tail, ch); | 331 | GNUNET_CONTAINER_DLL_remove(line->channel_head, line->channel_tail, ch); |
332 | GNUNET_free (ch); | 332 | GNUNET_free(ch); |
333 | } | 333 | } |
334 | 334 | ||
335 | 335 | ||
@@ -339,15 +339,15 @@ clean_up_channel (struct Channel *ch) | |||
339 | * @param ch channel to destroy. | 339 | * @param ch channel to destroy. |
340 | */ | 340 | */ |
341 | static void | 341 | static void |
342 | destroy_line_cadet_channels (struct Channel *ch) | 342 | destroy_line_cadet_channels(struct Channel *ch) |
343 | { | 343 | { |
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying cadet channels\n"); | 344 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying cadet channels\n"); |
345 | if (NULL != ch->channel) | 345 | if (NULL != ch->channel) |
346 | { | 346 | { |
347 | GNUNET_CADET_channel_destroy (ch->channel); | 347 | GNUNET_CADET_channel_destroy(ch->channel); |
348 | ch->channel = NULL; | 348 | ch->channel = NULL; |
349 | } | 349 | } |
350 | clean_up_channel (ch); | 350 | clean_up_channel(ch); |
351 | } | 351 | } |
352 | 352 | ||
353 | 353 | ||
@@ -358,34 +358,40 @@ destroy_line_cadet_channels (struct Channel *ch) | |||
358 | * @param cls the `struct Channel` to reset/terminate | 358 | * @param cls the `struct Channel` to reset/terminate |
359 | */ | 359 | */ |
360 | static void | 360 | static void |
361 | mq_done_finish_caller_shutdown (void *cls) | 361 | mq_done_finish_caller_shutdown(void *cls) |
362 | { | 362 | { |
363 | struct Channel *ch = cls; | 363 | struct Channel *ch = cls; |
364 | 364 | ||
365 | switch (ch->status) | 365 | switch (ch->status) |
366 | { | 366 | { |
367 | case CS_CALLEE_INIT: | 367 | case CS_CALLEE_INIT: |
368 | GNUNET_break (0); | 368 | GNUNET_break(0); |
369 | break; | 369 | break; |
370 | case CS_CALLEE_RINGING: | 370 | |
371 | GNUNET_break (0); | 371 | case CS_CALLEE_RINGING: |
372 | break; | 372 | GNUNET_break(0); |
373 | case CS_CALLEE_CONNECTED: | 373 | break; |
374 | GNUNET_break (0); | 374 | |
375 | break; | 375 | case CS_CALLEE_CONNECTED: |
376 | case CS_CALLEE_SHUTDOWN: | 376 | GNUNET_break(0); |
377 | destroy_line_cadet_channels (ch); | 377 | break; |
378 | break; | 378 | |
379 | case CS_CALLER_CALLING: | 379 | case CS_CALLEE_SHUTDOWN: |
380 | GNUNET_break (0); | 380 | destroy_line_cadet_channels(ch); |
381 | break; | 381 | break; |
382 | case CS_CALLER_CONNECTED: | 382 | |
383 | GNUNET_break (0); | 383 | case CS_CALLER_CALLING: |
384 | break; | 384 | GNUNET_break(0); |
385 | case CS_CALLER_SHUTDOWN: | 385 | break; |
386 | destroy_line_cadet_channels (ch); | 386 | |
387 | break; | 387 | case CS_CALLER_CONNECTED: |
388 | } | 388 | GNUNET_break(0); |
389 | break; | ||
390 | |||
391 | case CS_CALLER_SHUTDOWN: | ||
392 | destroy_line_cadet_channels(ch); | ||
393 | break; | ||
394 | } | ||
389 | } | 395 | } |
390 | 396 | ||
391 | 397 | ||
@@ -396,8 +402,8 @@ mq_done_finish_caller_shutdown (void *cls) | |||
396 | * @param msg the message from the client | 402 | * @param msg the message from the client |
397 | */ | 403 | */ |
398 | static void | 404 | static void |
399 | handle_client_hangup_message (void *cls, | 405 | handle_client_hangup_message(void *cls, |
400 | const struct ClientPhoneHangupMessage *msg) | 406 | const struct ClientPhoneHangupMessage *msg) |
401 | { | 407 | { |
402 | struct Line *line = cls; | 408 | struct Line *line = cls; |
403 | struct GNUNET_MQ_Envelope *e; | 409 | struct GNUNET_MQ_Envelope *e; |
@@ -408,49 +414,55 @@ handle_client_hangup_message (void *cls, | |||
408 | if (msg->cid == ch->cid) | 414 | if (msg->cid == ch->cid) |
409 | break; | 415 | break; |
410 | if (NULL == ch) | 416 | if (NULL == ch) |
411 | { | 417 | { |
412 | /* could have been destroyed asynchronously, ignore message */ | 418 | /* could have been destroyed asynchronously, ignore message */ |
413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
414 | GNUNET_SERVICE_client_continue (line->client); | 420 | GNUNET_SERVICE_client_continue(line->client); |
415 | return; | 421 | return; |
416 | } | 422 | } |
417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 423 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
418 | "Received HANGUP for channel %u which is in state %d\n", | 424 | "Received HANGUP for channel %u which is in state %d\n", |
419 | msg->cid, | 425 | msg->cid, |
420 | ch->status); | 426 | ch->status); |
421 | switch (ch->status) | 427 | switch (ch->status) |
422 | { | 428 | { |
423 | case CS_CALLEE_INIT: | 429 | case CS_CALLEE_INIT: |
424 | GNUNET_break (0); | 430 | GNUNET_break(0); |
425 | GNUNET_SERVICE_client_drop (line->client); | 431 | GNUNET_SERVICE_client_drop(line->client); |
426 | return; | 432 | return; |
427 | case CS_CALLEE_RINGING: | 433 | |
428 | ch->status = CS_CALLEE_SHUTDOWN; | 434 | case CS_CALLEE_RINGING: |
429 | break; | 435 | ch->status = CS_CALLEE_SHUTDOWN; |
430 | case CS_CALLEE_CONNECTED: | 436 | break; |
431 | ch->status = CS_CALLEE_SHUTDOWN; | 437 | |
432 | break; | 438 | case CS_CALLEE_CONNECTED: |
433 | case CS_CALLEE_SHUTDOWN: | 439 | ch->status = CS_CALLEE_SHUTDOWN; |
434 | /* maybe the other peer closed asynchronously... */ | 440 | break; |
435 | GNUNET_SERVICE_client_continue (line->client); | 441 | |
436 | return; | 442 | case CS_CALLEE_SHUTDOWN: |
437 | case CS_CALLER_CALLING: | 443 | /* maybe the other peer closed asynchronously... */ |
438 | ch->status = CS_CALLER_SHUTDOWN; | 444 | GNUNET_SERVICE_client_continue(line->client); |
439 | break; | 445 | return; |
440 | case CS_CALLER_CONNECTED: | 446 | |
441 | ch->status = CS_CALLER_SHUTDOWN; | 447 | case CS_CALLER_CALLING: |
442 | break; | 448 | ch->status = CS_CALLER_SHUTDOWN; |
443 | case CS_CALLER_SHUTDOWN: | 449 | break; |
444 | /* maybe the other peer closed asynchronously... */ | 450 | |
445 | GNUNET_SERVICE_client_continue (line->client); | 451 | case CS_CALLER_CONNECTED: |
446 | return; | 452 | ch->status = CS_CALLER_SHUTDOWN; |
447 | } | 453 | break; |
448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG_UP message via cadet\n"); | 454 | |
455 | case CS_CALLER_SHUTDOWN: | ||
456 | /* maybe the other peer closed asynchronously... */ | ||
457 | GNUNET_SERVICE_client_continue(line->client); | ||
458 | return; | ||
459 | } | ||
460 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending HANG_UP message via cadet\n"); | ||
449 | e = | 461 | e = |
450 | GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); | 462 | GNUNET_MQ_msg(mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); |
451 | GNUNET_MQ_notify_sent (e, &mq_done_finish_caller_shutdown, ch); | 463 | GNUNET_MQ_notify_sent(e, &mq_done_finish_caller_shutdown, ch); |
452 | GNUNET_MQ_send (ch->mq, e); | 464 | GNUNET_MQ_send(ch->mq, e); |
453 | GNUNET_SERVICE_client_continue (line->client); | 465 | GNUNET_SERVICE_client_continue(line->client); |
454 | } | 466 | } |
455 | 467 | ||
456 | 468 | ||
@@ -461,8 +473,8 @@ handle_client_hangup_message (void *cls, | |||
461 | * @param msg the message from the client | 473 | * @param msg the message from the client |
462 | */ | 474 | */ |
463 | static void | 475 | static void |
464 | handle_client_suspend_message (void *cls, | 476 | handle_client_suspend_message(void *cls, |
465 | const struct ClientPhoneSuspendMessage *msg) | 477 | const struct ClientPhoneSuspendMessage *msg) |
466 | { | 478 | { |
467 | struct Line *line = cls; | 479 | struct Line *line = cls; |
468 | struct GNUNET_MQ_Envelope *e; | 480 | struct GNUNET_MQ_Envelope *e; |
@@ -473,56 +485,62 @@ handle_client_suspend_message (void *cls, | |||
473 | if (msg->cid == ch->cid) | 485 | if (msg->cid == ch->cid) |
474 | break; | 486 | break; |
475 | if (NULL == ch) | 487 | if (NULL == ch) |
476 | { | 488 | { |
477 | /* could have been destroyed asynchronously, ignore message */ | 489 | /* could have been destroyed asynchronously, ignore message */ |
478 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 490 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
479 | GNUNET_SERVICE_client_continue (line->client); | 491 | GNUNET_SERVICE_client_continue(line->client); |
480 | return; | 492 | return; |
481 | } | 493 | } |
482 | if (GNUNET_YES == ch->suspended_local) | 494 | if (GNUNET_YES == ch->suspended_local) |
483 | { | 495 | { |
484 | GNUNET_break (0); | 496 | GNUNET_break(0); |
485 | GNUNET_SERVICE_client_drop (line->client); | 497 | GNUNET_SERVICE_client_drop(line->client); |
486 | return; | 498 | return; |
487 | } | 499 | } |
488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 500 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
489 | "Received SUSPEND for channel %u which is in state %d\n", | 501 | "Received SUSPEND for channel %u which is in state %d\n", |
490 | msg->cid, | 502 | msg->cid, |
491 | ch->status); | 503 | ch->status); |
492 | switch (ch->status) | 504 | switch (ch->status) |
493 | { | 505 | { |
494 | case CS_CALLEE_INIT: | 506 | case CS_CALLEE_INIT: |
495 | GNUNET_break (0); | 507 | GNUNET_break(0); |
496 | GNUNET_SERVICE_client_drop (line->client); | 508 | GNUNET_SERVICE_client_drop(line->client); |
497 | return; | 509 | return; |
498 | case CS_CALLEE_RINGING: | 510 | |
499 | GNUNET_break (0); | 511 | case CS_CALLEE_RINGING: |
500 | GNUNET_SERVICE_client_drop (line->client); | 512 | GNUNET_break(0); |
501 | return; | 513 | GNUNET_SERVICE_client_drop(line->client); |
502 | case CS_CALLEE_CONNECTED: | 514 | return; |
503 | ch->suspended_local = GNUNET_YES; | 515 | |
504 | break; | 516 | case CS_CALLEE_CONNECTED: |
505 | case CS_CALLEE_SHUTDOWN: | 517 | ch->suspended_local = GNUNET_YES; |
506 | /* maybe the other peer closed asynchronously... */ | 518 | break; |
507 | GNUNET_SERVICE_client_continue (line->client); | 519 | |
508 | return; | 520 | case CS_CALLEE_SHUTDOWN: |
509 | case CS_CALLER_CALLING: | 521 | /* maybe the other peer closed asynchronously... */ |
510 | GNUNET_break (0); | 522 | GNUNET_SERVICE_client_continue(line->client); |
511 | GNUNET_SERVICE_client_drop (line->client); | 523 | return; |
512 | return; | 524 | |
513 | case CS_CALLER_CONNECTED: | 525 | case CS_CALLER_CALLING: |
514 | ch->suspended_local = GNUNET_YES; | 526 | GNUNET_break(0); |
515 | break; | 527 | GNUNET_SERVICE_client_drop(line->client); |
516 | case CS_CALLER_SHUTDOWN: | 528 | return; |
517 | /* maybe the other peer closed asynchronously... */ | 529 | |
518 | GNUNET_SERVICE_client_continue (line->client); | 530 | case CS_CALLER_CONNECTED: |
519 | return; | 531 | ch->suspended_local = GNUNET_YES; |
520 | } | 532 | break; |
521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUSPEND message via cadet\n"); | 533 | |
534 | case CS_CALLER_SHUTDOWN: | ||
535 | /* maybe the other peer closed asynchronously... */ | ||
536 | GNUNET_SERVICE_client_continue(line->client); | ||
537 | return; | ||
538 | } | ||
539 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending SUSPEND message via cadet\n"); | ||
522 | e = | 540 | e = |
523 | GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); | 541 | GNUNET_MQ_msg(mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); |
524 | GNUNET_MQ_send (ch->mq, e); | 542 | GNUNET_MQ_send(ch->mq, e); |
525 | GNUNET_SERVICE_client_continue (line->client); | 543 | GNUNET_SERVICE_client_continue(line->client); |
526 | } | 544 | } |
527 | 545 | ||
528 | 546 | ||
@@ -533,8 +551,8 @@ handle_client_suspend_message (void *cls, | |||
533 | * @param msg the message from the client | 551 | * @param msg the message from the client |
534 | */ | 552 | */ |
535 | static void | 553 | static void |
536 | handle_client_resume_message (void *cls, | 554 | handle_client_resume_message(void *cls, |
537 | const struct ClientPhoneResumeMessage *msg) | 555 | const struct ClientPhoneResumeMessage *msg) |
538 | { | 556 | { |
539 | struct Line *line = cls; | 557 | struct Line *line = cls; |
540 | struct GNUNET_MQ_Envelope *e; | 558 | struct GNUNET_MQ_Envelope *e; |
@@ -545,55 +563,61 @@ handle_client_resume_message (void *cls, | |||
545 | if (msg->cid == ch->cid) | 563 | if (msg->cid == ch->cid) |
546 | break; | 564 | break; |
547 | if (NULL == ch) | 565 | if (NULL == ch) |
548 | { | 566 | { |
549 | /* could have been destroyed asynchronously, ignore message */ | 567 | /* could have been destroyed asynchronously, ignore message */ |
550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 568 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
551 | GNUNET_SERVICE_client_continue (line->client); | 569 | GNUNET_SERVICE_client_continue(line->client); |
552 | return; | 570 | return; |
553 | } | 571 | } |
554 | if (GNUNET_YES != ch->suspended_local) | 572 | if (GNUNET_YES != ch->suspended_local) |
555 | { | 573 | { |
556 | GNUNET_break (0); | 574 | GNUNET_break(0); |
557 | GNUNET_SERVICE_client_drop (line->client); | 575 | GNUNET_SERVICE_client_drop(line->client); |
558 | return; | 576 | return; |
559 | } | 577 | } |
560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 578 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
561 | "Received RESUME for channel %u which is in state %d\n", | 579 | "Received RESUME for channel %u which is in state %d\n", |
562 | msg->cid, | 580 | msg->cid, |
563 | ch->status); | 581 | ch->status); |
564 | switch (ch->status) | 582 | switch (ch->status) |
565 | { | 583 | { |
566 | case CS_CALLEE_INIT: | 584 | case CS_CALLEE_INIT: |
567 | GNUNET_break (0); | 585 | GNUNET_break(0); |
568 | GNUNET_SERVICE_client_drop (line->client); | 586 | GNUNET_SERVICE_client_drop(line->client); |
569 | return; | 587 | return; |
570 | case CS_CALLEE_RINGING: | 588 | |
571 | GNUNET_break (0); | 589 | case CS_CALLEE_RINGING: |
572 | GNUNET_SERVICE_client_drop (line->client); | 590 | GNUNET_break(0); |
573 | return; | 591 | GNUNET_SERVICE_client_drop(line->client); |
574 | case CS_CALLEE_CONNECTED: | 592 | return; |
575 | ch->suspended_local = GNUNET_NO; | 593 | |
576 | break; | 594 | case CS_CALLEE_CONNECTED: |
577 | case CS_CALLEE_SHUTDOWN: | 595 | ch->suspended_local = GNUNET_NO; |
578 | /* maybe the other peer closed asynchronously... */ | 596 | break; |
579 | GNUNET_SERVICE_client_continue (line->client); | 597 | |
580 | return; | 598 | case CS_CALLEE_SHUTDOWN: |
581 | case CS_CALLER_CALLING: | 599 | /* maybe the other peer closed asynchronously... */ |
582 | GNUNET_break (0); | 600 | GNUNET_SERVICE_client_continue(line->client); |
583 | GNUNET_SERVICE_client_drop (line->client); | 601 | return; |
584 | return; | 602 | |
585 | case CS_CALLER_CONNECTED: | 603 | case CS_CALLER_CALLING: |
586 | ch->suspended_local = GNUNET_NO; | 604 | GNUNET_break(0); |
587 | break; | 605 | GNUNET_SERVICE_client_drop(line->client); |
588 | case CS_CALLER_SHUTDOWN: | 606 | return; |
589 | /* maybe the other peer closed asynchronously... */ | 607 | |
590 | GNUNET_SERVICE_client_drop (line->client); | 608 | case CS_CALLER_CONNECTED: |
591 | return; | 609 | ch->suspended_local = GNUNET_NO; |
592 | } | 610 | break; |
593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RESUME message via cadet\n"); | 611 | |
594 | e = GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME); | 612 | case CS_CALLER_SHUTDOWN: |
595 | GNUNET_MQ_send (ch->mq, e); | 613 | /* maybe the other peer closed asynchronously... */ |
596 | GNUNET_SERVICE_client_continue (line->client); | 614 | GNUNET_SERVICE_client_drop(line->client); |
615 | return; | ||
616 | } | ||
617 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending RESUME message via cadet\n"); | ||
618 | e = GNUNET_MQ_msg(mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME); | ||
619 | GNUNET_MQ_send(ch->mq, e); | ||
620 | GNUNET_SERVICE_client_continue(line->client); | ||
597 | } | 621 | } |
598 | 622 | ||
599 | 623 | ||
@@ -603,7 +627,7 @@ handle_client_resume_message (void *cls, | |||
603 | * @param cls the `struct Channel` we are transmitting for | 627 | * @param cls the `struct Channel` we are transmitting for |
604 | */ | 628 | */ |
605 | static void | 629 | static void |
606 | channel_audio_sent_notify (void *cls) | 630 | channel_audio_sent_notify(void *cls) |
607 | { | 631 | { |
608 | struct Channel *ch = cls; | 632 | struct Channel *ch = cls; |
609 | 633 | ||
@@ -619,10 +643,10 @@ channel_audio_sent_notify (void *cls) | |||
619 | * @return #GNUNET_OK (any data is ok) | 643 | * @return #GNUNET_OK (any data is ok) |
620 | */ | 644 | */ |
621 | static int | 645 | static int |
622 | check_client_audio_message (void *cls, const struct ClientAudioMessage *msg) | 646 | check_client_audio_message(void *cls, const struct ClientAudioMessage *msg) |
623 | { | 647 | { |
624 | (void) cls; | 648 | (void)cls; |
625 | (void) msg; | 649 | (void)msg; |
626 | return GNUNET_OK; | 650 | return GNUNET_OK; |
627 | } | 651 | } |
628 | 652 | ||
@@ -634,70 +658,72 @@ check_client_audio_message (void *cls, const struct ClientAudioMessage *msg) | |||
634 | * @param msg the message from the client | 658 | * @param msg the message from the client |
635 | */ | 659 | */ |
636 | static void | 660 | static void |
637 | handle_client_audio_message (void *cls, const struct ClientAudioMessage *msg) | 661 | handle_client_audio_message(void *cls, const struct ClientAudioMessage *msg) |
638 | { | 662 | { |
639 | struct Line *line = cls; | 663 | struct Line *line = cls; |
640 | struct CadetAudioMessage *mam; | 664 | struct CadetAudioMessage *mam; |
641 | struct Channel *ch; | 665 | struct Channel *ch; |
642 | size_t size; | 666 | size_t size; |
643 | 667 | ||
644 | size = ntohs (msg->header.size) - sizeof (struct ClientAudioMessage); | 668 | size = ntohs(msg->header.size) - sizeof(struct ClientAudioMessage); |
645 | ch = find_channel_by_line (line, msg->cid); | 669 | ch = find_channel_by_line(line, msg->cid); |
646 | if (NULL == ch) | 670 | if (NULL == ch) |
647 | { | 671 | { |
648 | /* could have been destroyed asynchronously, ignore message */ | 672 | /* could have been destroyed asynchronously, ignore message */ |
649 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 673 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
650 | GNUNET_SERVICE_client_continue (line->client); | 674 | GNUNET_SERVICE_client_continue(line->client); |
651 | return; | 675 | return; |
652 | } | 676 | } |
653 | 677 | ||
654 | switch (ch->status) | 678 | switch (ch->status) |
655 | { | 679 | { |
656 | case CS_CALLEE_INIT: | 680 | case CS_CALLEE_INIT: |
657 | case CS_CALLEE_RINGING: | 681 | case CS_CALLEE_RINGING: |
658 | case CS_CALLER_CALLING: | 682 | case CS_CALLER_CALLING: |
659 | GNUNET_break (0); | 683 | GNUNET_break(0); |
660 | GNUNET_SERVICE_client_drop (line->client); | 684 | GNUNET_SERVICE_client_drop(line->client); |
661 | return; | 685 | return; |
662 | case CS_CALLEE_CONNECTED: | 686 | |
663 | case CS_CALLER_CONNECTED: | 687 | case CS_CALLEE_CONNECTED: |
664 | /* common case, handled below */ | 688 | case CS_CALLER_CONNECTED: |
665 | break; | 689 | /* common case, handled below */ |
666 | case CS_CALLEE_SHUTDOWN: | 690 | break; |
667 | case CS_CALLER_SHUTDOWN: | 691 | |
668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 692 | case CS_CALLEE_SHUTDOWN: |
669 | "Cadet audio channel in shutdown; audio data dropped\n"); | 693 | case CS_CALLER_SHUTDOWN: |
670 | GNUNET_SERVICE_client_continue (line->client); | 694 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
671 | return; | 695 | "Cadet audio channel in shutdown; audio data dropped\n"); |
672 | } | 696 | GNUNET_SERVICE_client_continue(line->client); |
697 | return; | ||
698 | } | ||
673 | if (GNUNET_YES == ch->suspended_local) | 699 | if (GNUNET_YES == ch->suspended_local) |
674 | { | 700 | { |
675 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 701 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
676 | "This channel is suspended locally\n"); | 702 | "This channel is suspended locally\n"); |
677 | GNUNET_SERVICE_client_drop (line->client); | 703 | GNUNET_SERVICE_client_drop(line->client); |
678 | return; | 704 | return; |
679 | } | 705 | } |
680 | if (NULL != ch->env) | 706 | if (NULL != ch->env) |
681 | { | 707 | { |
682 | /* NOTE: we may want to not do this and instead combine the data */ | 708 | /* NOTE: we may want to not do this and instead combine the data */ |
683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 709 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
684 | "Bandwidth insufficient; dropping previous audio data segment\n"); | 710 | "Bandwidth insufficient; dropping previous audio data segment\n"); |
685 | GNUNET_MQ_send_cancel (ch->env); | 711 | GNUNET_MQ_send_cancel(ch->env); |
686 | ch->env = NULL; | 712 | ch->env = NULL; |
687 | } | 713 | } |
688 | 714 | ||
689 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 715 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
690 | "Received %u bytes of AUDIO data from client CID %u\n", | 716 | "Received %u bytes of AUDIO data from client CID %u\n", |
691 | (unsigned int) size, | 717 | (unsigned int)size, |
692 | msg->cid); | 718 | msg->cid); |
693 | ch->env = GNUNET_MQ_msg_extra (mam, | 719 | ch->env = GNUNET_MQ_msg_extra(mam, |
694 | size, | 720 | size, |
695 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO); | 721 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO); |
696 | GNUNET_memcpy (&mam[1], &msg[1], size); | 722 | GNUNET_memcpy(&mam[1], &msg[1], size); |
697 | /* FIXME: set options for unreliable transmission */ | 723 | /* FIXME: set options for unreliable transmission */ |
698 | GNUNET_MQ_notify_sent (ch->env, &channel_audio_sent_notify, ch); | 724 | GNUNET_MQ_notify_sent(ch->env, &channel_audio_sent_notify, ch); |
699 | GNUNET_MQ_send (ch->mq, ch->env); | 725 | GNUNET_MQ_send(ch->mq, ch->env); |
700 | GNUNET_SERVICE_client_continue (line->client); | 726 | GNUNET_SERVICE_client_continue(line->client); |
701 | } | 727 | } |
702 | 728 | ||
703 | 729 | ||
@@ -708,7 +734,7 @@ handle_client_audio_message (void *cls, const struct ClientAudioMessage *msg) | |||
708 | * @param msg the incoming message | 734 | * @param msg the incoming message |
709 | */ | 735 | */ |
710 | static void | 736 | static void |
711 | handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg) | 737 | handle_cadet_ring_message(void *cls, const struct CadetPhoneRingMessage *msg) |
712 | { | 738 | { |
713 | struct Channel *ch = cls; | 739 | struct Channel *ch = cls; |
714 | struct Line *line = ch->line; | 740 | struct Line *line = ch->line; |
@@ -716,49 +742,49 @@ handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg) | |||
716 | struct ClientPhoneRingMessage *cring; | 742 | struct ClientPhoneRingMessage *cring; |
717 | struct CadetPhoneRingInfoPS rs; | 743 | struct CadetPhoneRingInfoPS rs; |
718 | 744 | ||
719 | rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); | 745 | rs.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); |
720 | rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS)); | 746 | rs.purpose.size = htonl(sizeof(struct CadetPhoneRingInfoPS)); |
721 | rs.line_port = line->line_port; | 747 | rs.line_port = line->line_port; |
722 | rs.target_peer = my_identity; | 748 | rs.target_peer = my_identity; |
723 | rs.expiration_time = msg->expiration_time; | 749 | rs.expiration_time = msg->expiration_time; |
724 | 750 | ||
725 | if (GNUNET_OK != | 751 | if (GNUNET_OK != |
726 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING, | 752 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING, |
727 | &rs.purpose, | 753 | &rs.purpose, |
728 | &msg->signature, | 754 | &msg->signature, |
729 | &msg->caller_id)) | 755 | &msg->caller_id)) |
730 | { | 756 | { |
731 | GNUNET_break_op (0); | 757 | GNUNET_break_op(0); |
732 | destroy_line_cadet_channels (ch); | 758 | destroy_line_cadet_channels(ch); |
733 | return; | 759 | return; |
734 | } | 760 | } |
735 | if (0 == GNUNET_TIME_absolute_get_remaining ( | 761 | if (0 == GNUNET_TIME_absolute_get_remaining( |
736 | GNUNET_TIME_absolute_ntoh (msg->expiration_time)) | 762 | GNUNET_TIME_absolute_ntoh(msg->expiration_time)) |
737 | .rel_value_us) | 763 | .rel_value_us) |
738 | { | 764 | { |
739 | /* ancient call, replay? */ | 765 | /* ancient call, replay? */ |
740 | GNUNET_break_op (0); | 766 | GNUNET_break_op(0); |
741 | /* Note that our reliance on time here is awkward; better would be | 767 | /* Note that our reliance on time here is awkward; better would be |
742 | to use a more complex challenge-response protocol against | 768 | to use a more complex challenge-response protocol against |
743 | replay attacks. Left for future work ;-). */ | 769 | replay attacks. Left for future work ;-). */ |
744 | destroy_line_cadet_channels (ch); | 770 | destroy_line_cadet_channels(ch); |
745 | return; | 771 | return; |
746 | } | 772 | } |
747 | if (CS_CALLEE_INIT != ch->status) | 773 | if (CS_CALLEE_INIT != ch->status) |
748 | { | 774 | { |
749 | GNUNET_break_op (0); | 775 | GNUNET_break_op(0); |
750 | destroy_line_cadet_channels (ch); | 776 | destroy_line_cadet_channels(ch); |
751 | return; | 777 | return; |
752 | } | 778 | } |
753 | GNUNET_CADET_receive_done (ch->channel); | 779 | GNUNET_CADET_receive_done(ch->channel); |
754 | ch->status = CS_CALLEE_RINGING; | 780 | ch->status = CS_CALLEE_RINGING; |
755 | env = GNUNET_MQ_msg (cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); | 781 | env = GNUNET_MQ_msg(cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); |
756 | cring->cid = ch->cid; | 782 | cring->cid = ch->cid; |
757 | cring->caller_id = msg->caller_id; | 783 | cring->caller_id = msg->caller_id; |
758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 784 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
759 | "Sending RING message to client. CID is %u\n", | 785 | "Sending RING message to client. CID is %u\n", |
760 | (unsigned int) ch->cid); | 786 | (unsigned int)ch->cid); |
761 | GNUNET_MQ_send (line->mq, env); | 787 | GNUNET_MQ_send(line->mq, env); |
762 | } | 788 | } |
763 | 789 | ||
764 | 790 | ||
@@ -769,8 +795,8 @@ handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg) | |||
769 | * @param message the incoming message | 795 | * @param message the incoming message |
770 | */ | 796 | */ |
771 | static void | 797 | static void |
772 | handle_cadet_hangup_message (void *cls, | 798 | handle_cadet_hangup_message(void *cls, |
773 | const struct CadetPhoneHangupMessage *message) | 799 | const struct CadetPhoneHangupMessage *message) |
774 | { | 800 | { |
775 | struct Channel *ch = cls; | 801 | struct Channel *ch = cls; |
776 | struct Line *line = ch->line; | 802 | struct Line *line = ch->line; |
@@ -779,31 +805,35 @@ handle_cadet_hangup_message (void *cls, | |||
779 | enum ChannelStatus status; | 805 | enum ChannelStatus status; |
780 | uint32_t cid; | 806 | uint32_t cid; |
781 | 807 | ||
782 | (void) message; | 808 | (void)message; |
783 | GNUNET_CADET_receive_done (ch->channel); | 809 | GNUNET_CADET_receive_done(ch->channel); |
784 | cid = ch->cid; | 810 | cid = ch->cid; |
785 | status = ch->status; | 811 | status = ch->status; |
786 | destroy_line_cadet_channels (ch); | 812 | destroy_line_cadet_channels(ch); |
787 | switch (status) | 813 | switch (status) |
788 | { | 814 | { |
789 | case CS_CALLEE_INIT: | 815 | case CS_CALLEE_INIT: |
790 | GNUNET_break_op (0); | 816 | GNUNET_break_op(0); |
791 | return; | 817 | return; |
792 | case CS_CALLEE_RINGING: | 818 | |
793 | case CS_CALLEE_CONNECTED: | 819 | case CS_CALLEE_RINGING: |
794 | break; | 820 | case CS_CALLEE_CONNECTED: |
795 | case CS_CALLEE_SHUTDOWN: | 821 | break; |
796 | return; | 822 | |
797 | case CS_CALLER_CALLING: | 823 | case CS_CALLEE_SHUTDOWN: |
798 | case CS_CALLER_CONNECTED: | 824 | return; |
799 | break; | 825 | |
800 | case CS_CALLER_SHUTDOWN: | 826 | case CS_CALLER_CALLING: |
801 | return; | 827 | case CS_CALLER_CONNECTED: |
802 | } | 828 | break; |
803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG UP message to client\n"); | 829 | |
804 | env = GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | 830 | case CS_CALLER_SHUTDOWN: |
831 | return; | ||
832 | } | ||
833 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending HANG UP message to client\n"); | ||
834 | env = GNUNET_MQ_msg(hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | ||
805 | hup->cid = cid; | 835 | hup->cid = cid; |
806 | GNUNET_MQ_send (line->mq, env); | 836 | GNUNET_MQ_send(line->mq, env); |
807 | } | 837 | } |
808 | 838 | ||
809 | 839 | ||
@@ -814,44 +844,48 @@ handle_cadet_hangup_message (void *cls, | |||
814 | * @param message the incoming message | 844 | * @param message the incoming message |
815 | */ | 845 | */ |
816 | static void | 846 | static void |
817 | handle_cadet_pickup_message (void *cls, | 847 | handle_cadet_pickup_message(void *cls, |
818 | const struct CadetPhonePickupMessage *message) | 848 | const struct CadetPhonePickupMessage *message) |
819 | { | 849 | { |
820 | struct Channel *ch = cls; | 850 | struct Channel *ch = cls; |
821 | struct Line *line = ch->line; | 851 | struct Line *line = ch->line; |
822 | struct GNUNET_MQ_Envelope *env; | 852 | struct GNUNET_MQ_Envelope *env; |
823 | struct ClientPhonePickedupMessage *pick; | 853 | struct ClientPhonePickedupMessage *pick; |
824 | 854 | ||
825 | (void) message; | 855 | (void)message; |
826 | GNUNET_CADET_receive_done (ch->channel); | 856 | GNUNET_CADET_receive_done(ch->channel); |
827 | switch (ch->status) | 857 | switch (ch->status) |
828 | { | 858 | { |
829 | case CS_CALLEE_INIT: | 859 | case CS_CALLEE_INIT: |
830 | case CS_CALLEE_RINGING: | 860 | case CS_CALLEE_RINGING: |
831 | case CS_CALLEE_CONNECTED: | 861 | case CS_CALLEE_CONNECTED: |
832 | GNUNET_break_op (0); | 862 | GNUNET_break_op(0); |
833 | destroy_line_cadet_channels (ch); | 863 | destroy_line_cadet_channels(ch); |
834 | return; | 864 | return; |
835 | case CS_CALLEE_SHUTDOWN: | 865 | |
836 | GNUNET_break_op (0); | 866 | case CS_CALLEE_SHUTDOWN: |
837 | destroy_line_cadet_channels (ch); | 867 | GNUNET_break_op(0); |
838 | return; | 868 | destroy_line_cadet_channels(ch); |
839 | case CS_CALLER_CALLING: | 869 | return; |
840 | ch->status = CS_CALLER_CONNECTED; | 870 | |
841 | break; | 871 | case CS_CALLER_CALLING: |
842 | case CS_CALLER_CONNECTED: | 872 | ch->status = CS_CALLER_CONNECTED; |
843 | GNUNET_break_op (0); | 873 | break; |
844 | return; | 874 | |
845 | case CS_CALLER_SHUTDOWN: | 875 | case CS_CALLER_CONNECTED: |
846 | GNUNET_break_op (0); | 876 | GNUNET_break_op(0); |
847 | mq_done_finish_caller_shutdown (ch); | 877 | return; |
848 | return; | 878 | |
849 | } | 879 | case CS_CALLER_SHUTDOWN: |
850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICKED UP message to client\n"); | 880 | GNUNET_break_op(0); |
881 | mq_done_finish_caller_shutdown(ch); | ||
882 | return; | ||
883 | } | ||
884 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending PICKED UP message to client\n"); | ||
851 | env = | 885 | env = |
852 | GNUNET_MQ_msg (pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP); | 886 | GNUNET_MQ_msg(pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP); |
853 | pick->cid = ch->cid; | 887 | pick->cid = ch->cid; |
854 | GNUNET_MQ_send (line->mq, env); | 888 | GNUNET_MQ_send(line->mq, env); |
855 | } | 889 | } |
856 | 890 | ||
857 | 891 | ||
@@ -862,43 +896,49 @@ handle_cadet_pickup_message (void *cls, | |||
862 | * @param message the incoming message | 896 | * @param message the incoming message |
863 | */ | 897 | */ |
864 | static void | 898 | static void |
865 | handle_cadet_suspend_message (void *cls, | 899 | handle_cadet_suspend_message(void *cls, |
866 | const struct CadetPhoneSuspendMessage *message) | 900 | const struct CadetPhoneSuspendMessage *message) |
867 | { | 901 | { |
868 | struct Channel *ch = cls; | 902 | struct Channel *ch = cls; |
869 | struct Line *line = ch->line; | 903 | struct Line *line = ch->line; |
870 | struct GNUNET_MQ_Envelope *env; | 904 | struct GNUNET_MQ_Envelope *env; |
871 | struct ClientPhoneSuspendMessage *suspend; | 905 | struct ClientPhoneSuspendMessage *suspend; |
872 | 906 | ||
873 | (void) message; | 907 | (void)message; |
874 | GNUNET_CADET_receive_done (ch->channel); | 908 | GNUNET_CADET_receive_done(ch->channel); |
875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending channel CID: %u\n", ch->cid); | 909 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Suspending channel CID: %u\n", ch->cid); |
876 | switch (ch->status) | 910 | switch (ch->status) |
877 | { | 911 | { |
878 | case CS_CALLEE_INIT: | 912 | case CS_CALLEE_INIT: |
879 | GNUNET_break_op (0); | 913 | GNUNET_break_op(0); |
880 | break; | 914 | break; |
881 | case CS_CALLEE_RINGING: | 915 | |
882 | GNUNET_break_op (0); | 916 | case CS_CALLEE_RINGING: |
883 | break; | 917 | GNUNET_break_op(0); |
884 | case CS_CALLEE_CONNECTED: | 918 | break; |
885 | ch->suspended_remote = GNUNET_YES; | 919 | |
886 | break; | 920 | case CS_CALLEE_CONNECTED: |
887 | case CS_CALLEE_SHUTDOWN: | 921 | ch->suspended_remote = GNUNET_YES; |
888 | return; | 922 | break; |
889 | case CS_CALLER_CALLING: | 923 | |
890 | GNUNET_break_op (0); | 924 | case CS_CALLEE_SHUTDOWN: |
891 | break; | 925 | return; |
892 | case CS_CALLER_CONNECTED: | 926 | |
893 | ch->suspended_remote = GNUNET_YES; | 927 | case CS_CALLER_CALLING: |
894 | break; | 928 | GNUNET_break_op(0); |
895 | case CS_CALLER_SHUTDOWN: | 929 | break; |
896 | return; | 930 | |
897 | } | 931 | case CS_CALLER_CONNECTED: |
932 | ch->suspended_remote = GNUNET_YES; | ||
933 | break; | ||
934 | |||
935 | case CS_CALLER_SHUTDOWN: | ||
936 | return; | ||
937 | } | ||
898 | env = | 938 | env = |
899 | GNUNET_MQ_msg (suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); | 939 | GNUNET_MQ_msg(suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); |
900 | suspend->cid = ch->cid; | 940 | suspend->cid = ch->cid; |
901 | GNUNET_MQ_send (line->mq, env); | 941 | GNUNET_MQ_send(line->mq, env); |
902 | } | 942 | } |
903 | 943 | ||
904 | 944 | ||
@@ -909,51 +949,57 @@ handle_cadet_suspend_message (void *cls, | |||
909 | * @param msg the incoming message | 949 | * @param msg the incoming message |
910 | */ | 950 | */ |
911 | static void | 951 | static void |
912 | handle_cadet_resume_message (void *cls, | 952 | handle_cadet_resume_message(void *cls, |
913 | const struct CadetPhoneResumeMessage *msg) | 953 | const struct CadetPhoneResumeMessage *msg) |
914 | { | 954 | { |
915 | struct Channel *ch = cls; | 955 | struct Channel *ch = cls; |
916 | struct Line *line; | 956 | struct Line *line; |
917 | struct GNUNET_MQ_Envelope *env; | 957 | struct GNUNET_MQ_Envelope *env; |
918 | struct ClientPhoneResumeMessage *resume; | 958 | struct ClientPhoneResumeMessage *resume; |
919 | 959 | ||
920 | (void) msg; | 960 | (void)msg; |
921 | line = ch->line; | 961 | line = ch->line; |
922 | GNUNET_CADET_receive_done (ch->channel); | 962 | GNUNET_CADET_receive_done(ch->channel); |
923 | if (GNUNET_YES != ch->suspended_remote) | 963 | if (GNUNET_YES != ch->suspended_remote) |
924 | { | 964 | { |
925 | GNUNET_log ( | 965 | GNUNET_log( |
926 | GNUNET_ERROR_TYPE_DEBUG, | 966 | GNUNET_ERROR_TYPE_DEBUG, |
927 | "RESUME message received for non-suspended channel, dropping channel.\n"); | 967 | "RESUME message received for non-suspended channel, dropping channel.\n"); |
928 | destroy_line_cadet_channels (ch); | 968 | destroy_line_cadet_channels(ch); |
929 | return; | 969 | return; |
930 | } | 970 | } |
931 | switch (ch->status) | 971 | switch (ch->status) |
932 | { | 972 | { |
933 | case CS_CALLEE_INIT: | 973 | case CS_CALLEE_INIT: |
934 | GNUNET_break (0); | 974 | GNUNET_break(0); |
935 | break; | 975 | break; |
936 | case CS_CALLEE_RINGING: | 976 | |
937 | GNUNET_break (0); | 977 | case CS_CALLEE_RINGING: |
938 | break; | 978 | GNUNET_break(0); |
939 | case CS_CALLEE_CONNECTED: | 979 | break; |
940 | ch->suspended_remote = GNUNET_NO; | 980 | |
941 | break; | 981 | case CS_CALLEE_CONNECTED: |
942 | case CS_CALLEE_SHUTDOWN: | 982 | ch->suspended_remote = GNUNET_NO; |
943 | return; | 983 | break; |
944 | case CS_CALLER_CALLING: | 984 | |
945 | GNUNET_break (0); | 985 | case CS_CALLEE_SHUTDOWN: |
946 | break; | 986 | return; |
947 | case CS_CALLER_CONNECTED: | 987 | |
948 | ch->suspended_remote = GNUNET_NO; | 988 | case CS_CALLER_CALLING: |
949 | break; | 989 | GNUNET_break(0); |
950 | case CS_CALLER_SHUTDOWN: | 990 | break; |
951 | return; | 991 | |
952 | } | 992 | case CS_CALLER_CONNECTED: |
993 | ch->suspended_remote = GNUNET_NO; | ||
994 | break; | ||
995 | |||
996 | case CS_CALLER_SHUTDOWN: | ||
997 | return; | ||
998 | } | ||
953 | env = | 999 | env = |
954 | GNUNET_MQ_msg (resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); | 1000 | GNUNET_MQ_msg(resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); |
955 | resume->cid = ch->cid; | 1001 | resume->cid = ch->cid; |
956 | GNUNET_MQ_send (line->mq, env); | 1002 | GNUNET_MQ_send(line->mq, env); |
957 | } | 1003 | } |
958 | 1004 | ||
959 | 1005 | ||
@@ -965,10 +1011,10 @@ handle_cadet_resume_message (void *cls, | |||
965 | * @return #GNUNET_OK (always) | 1011 | * @return #GNUNET_OK (always) |
966 | */ | 1012 | */ |
967 | static int | 1013 | static int |
968 | check_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) | 1014 | check_cadet_audio_message(void *cls, const struct CadetAudioMessage *msg) |
969 | { | 1015 | { |
970 | (void) cls; | 1016 | (void)cls; |
971 | (void) msg; | 1017 | (void)msg; |
972 | return GNUNET_OK; /* any payload is fine */ | 1018 | return GNUNET_OK; /* any payload is fine */ |
973 | } | 1019 | } |
974 | 1020 | ||
@@ -980,33 +1026,33 @@ check_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) | |||
980 | * @param msg the incoming message | 1026 | * @param msg the incoming message |
981 | */ | 1027 | */ |
982 | static void | 1028 | static void |
983 | handle_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) | 1029 | handle_cadet_audio_message(void *cls, const struct CadetAudioMessage *msg) |
984 | { | 1030 | { |
985 | struct Channel *ch = cls; | 1031 | struct Channel *ch = cls; |
986 | size_t msize = ntohs (msg->header.size) - sizeof (struct CadetAudioMessage); | 1032 | size_t msize = ntohs(msg->header.size) - sizeof(struct CadetAudioMessage); |
987 | struct GNUNET_MQ_Envelope *env; | 1033 | struct GNUNET_MQ_Envelope *env; |
988 | struct ClientAudioMessage *cam; | 1034 | struct ClientAudioMessage *cam; |
989 | 1035 | ||
990 | GNUNET_CADET_receive_done (ch->channel); | 1036 | GNUNET_CADET_receive_done(ch->channel); |
991 | if ((GNUNET_YES == ch->suspended_local) || | 1037 | if ((GNUNET_YES == ch->suspended_local) || |
992 | (GNUNET_YES == ch->suspended_remote)) | 1038 | (GNUNET_YES == ch->suspended_remote)) |
993 | { | 1039 | { |
994 | GNUNET_log ( | 1040 | GNUNET_log( |
995 | GNUNET_ERROR_TYPE_DEBUG, | 1041 | GNUNET_ERROR_TYPE_DEBUG, |
996 | "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", | 1042 | "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", |
997 | (unsigned int) msize, | 1043 | (unsigned int)msize, |
998 | ch->cid); | 1044 | ch->cid); |
999 | return; | 1045 | return; |
1000 | } | 1046 | } |
1001 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1047 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1002 | "Forwarding %u bytes of AUDIO data to client CID %u\n", | 1048 | "Forwarding %u bytes of AUDIO data to client CID %u\n", |
1003 | (unsigned int) msize, | 1049 | (unsigned int)msize, |
1004 | ch->cid); | 1050 | ch->cid); |
1005 | env = | 1051 | env = |
1006 | GNUNET_MQ_msg_extra (cam, msize, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); | 1052 | GNUNET_MQ_msg_extra(cam, msize, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); |
1007 | cam->cid = ch->cid; | 1053 | cam->cid = ch->cid; |
1008 | GNUNET_memcpy (&cam[1], &msg[1], msize); | 1054 | GNUNET_memcpy(&cam[1], &msg[1], msize); |
1009 | GNUNET_MQ_send (ch->line->mq, env); | 1055 | GNUNET_MQ_send(ch->line->mq, env); |
1010 | } | 1056 | } |
1011 | 1057 | ||
1012 | 1058 | ||
@@ -1018,16 +1064,16 @@ handle_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) | |||
1018 | * @param channel connection to the other end (henceforth invalid) | 1064 | * @param channel connection to the other end (henceforth invalid) |
1019 | */ | 1065 | */ |
1020 | static void | 1066 | static void |
1021 | inbound_end (void *cls, const struct GNUNET_CADET_Channel *channel) | 1067 | inbound_end(void *cls, const struct GNUNET_CADET_Channel *channel) |
1022 | { | 1068 | { |
1023 | struct Channel *ch = cls; | 1069 | struct Channel *ch = cls; |
1024 | 1070 | ||
1025 | GNUNET_assert (channel == ch->channel); | 1071 | GNUNET_assert(channel == ch->channel); |
1026 | ch->channel = NULL; | 1072 | ch->channel = NULL; |
1027 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1073 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1028 | "Channel destroyed by CADET in state %d\n", | 1074 | "Channel destroyed by CADET in state %d\n", |
1029 | ch->status); | 1075 | ch->status); |
1030 | clean_up_channel (ch); | 1076 | clean_up_channel(ch); |
1031 | } | 1077 | } |
1032 | 1078 | ||
1033 | 1079 | ||
@@ -1038,63 +1084,63 @@ inbound_end (void *cls, const struct GNUNET_CADET_Channel *channel) | |||
1038 | * @param msg the message from the client | 1084 | * @param msg the message from the client |
1039 | */ | 1085 | */ |
1040 | static void | 1086 | static void |
1041 | handle_client_call_message (void *cls, const struct ClientCallMessage *msg) | 1087 | handle_client_call_message(void *cls, const struct ClientCallMessage *msg) |
1042 | { | 1088 | { |
1043 | struct Line *line = cls; | 1089 | struct Line *line = cls; |
1044 | struct Channel *ch = GNUNET_new (struct Channel); | 1090 | struct Channel *ch = GNUNET_new(struct Channel); |
1045 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1091 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1046 | {GNUNET_MQ_hd_fixed_size (cadet_hangup_message, | 1092 | { GNUNET_MQ_hd_fixed_size(cadet_hangup_message, |
1047 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, | 1093 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, |
1048 | struct CadetPhoneHangupMessage, | 1094 | struct CadetPhoneHangupMessage, |
1049 | ch), | 1095 | ch), |
1050 | GNUNET_MQ_hd_fixed_size (cadet_pickup_message, | 1096 | GNUNET_MQ_hd_fixed_size(cadet_pickup_message, |
1051 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, | 1097 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, |
1052 | struct CadetPhonePickupMessage, | 1098 | struct CadetPhonePickupMessage, |
1053 | ch), | 1099 | ch), |
1054 | GNUNET_MQ_hd_fixed_size (cadet_suspend_message, | 1100 | GNUNET_MQ_hd_fixed_size(cadet_suspend_message, |
1055 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, | 1101 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, |
1056 | struct CadetPhoneSuspendMessage, | 1102 | struct CadetPhoneSuspendMessage, |
1057 | ch), | 1103 | ch), |
1058 | GNUNET_MQ_hd_fixed_size (cadet_resume_message, | 1104 | GNUNET_MQ_hd_fixed_size(cadet_resume_message, |
1059 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, | 1105 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, |
1060 | struct CadetPhoneResumeMessage, | 1106 | struct CadetPhoneResumeMessage, |
1061 | ch), | ||
1062 | GNUNET_MQ_hd_var_size (cadet_audio_message, | ||
1063 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | ||
1064 | struct CadetAudioMessage, | ||
1065 | ch), | 1107 | ch), |
1066 | GNUNET_MQ_handler_end ()}; | 1108 | GNUNET_MQ_hd_var_size(cadet_audio_message, |
1109 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | ||
1110 | struct CadetAudioMessage, | ||
1111 | ch), | ||
1112 | GNUNET_MQ_handler_end() }; | ||
1067 | struct GNUNET_MQ_Envelope *e; | 1113 | struct GNUNET_MQ_Envelope *e; |
1068 | struct CadetPhoneRingMessage *ring; | 1114 | struct CadetPhoneRingMessage *ring; |
1069 | struct CadetPhoneRingInfoPS rs; | 1115 | struct CadetPhoneRingInfoPS rs; |
1070 | 1116 | ||
1071 | line->line_port = msg->line_port; | 1117 | line->line_port = msg->line_port; |
1072 | rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); | 1118 | rs.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); |
1073 | rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS)); | 1119 | rs.purpose.size = htonl(sizeof(struct CadetPhoneRingInfoPS)); |
1074 | rs.line_port = line->line_port; | 1120 | rs.line_port = line->line_port; |
1075 | rs.target_peer = msg->target; | 1121 | rs.target_peer = msg->target; |
1076 | rs.expiration_time = | 1122 | rs.expiration_time = |
1077 | GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT)); | 1123 | GNUNET_TIME_absolute_hton(GNUNET_TIME_relative_to_absolute(RING_TIMEOUT)); |
1078 | ch->line = line; | 1124 | ch->line = line; |
1079 | GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch); | 1125 | GNUNET_CONTAINER_DLL_insert(line->channel_head, line->channel_tail, ch); |
1080 | ch->status = CS_CALLER_CALLING; | 1126 | ch->status = CS_CALLER_CALLING; |
1081 | ch->channel = GNUNET_CADET_channel_create (cadet, | 1127 | ch->channel = GNUNET_CADET_channel_create(cadet, |
1082 | ch, | 1128 | ch, |
1083 | &msg->target, | 1129 | &msg->target, |
1084 | &msg->line_port, | 1130 | &msg->line_port, |
1085 | NULL, | 1131 | NULL, |
1086 | &inbound_end, | 1132 | &inbound_end, |
1087 | cadet_handlers); | 1133 | cadet_handlers); |
1088 | ch->mq = GNUNET_CADET_get_mq (ch->channel); | 1134 | ch->mq = GNUNET_CADET_get_mq(ch->channel); |
1089 | e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); | 1135 | e = GNUNET_MQ_msg(ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); |
1090 | GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id, &ring->caller_id); | 1136 | GNUNET_CRYPTO_ecdsa_key_get_public(&msg->caller_id, &ring->caller_id); |
1091 | ring->expiration_time = rs.expiration_time; | 1137 | ring->expiration_time = rs.expiration_time; |
1092 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id, | 1138 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_ecdsa_sign(&msg->caller_id, |
1093 | &rs.purpose, | 1139 | &rs.purpose, |
1094 | &ring->signature)); | 1140 | &ring->signature)); |
1095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); | 1141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); |
1096 | GNUNET_MQ_send (ch->mq, e); | 1142 | GNUNET_MQ_send(ch->mq, e); |
1097 | GNUNET_SERVICE_client_continue (line->client); | 1143 | GNUNET_SERVICE_client_continue(line->client); |
1098 | } | 1144 | } |
1099 | 1145 | ||
1100 | 1146 | ||
@@ -1108,24 +1154,24 @@ handle_client_call_message (void *cls, const struct ClientCallMessage *msg) | |||
1108 | * @return initial channel context for the channel | 1154 | * @return initial channel context for the channel |
1109 | */ | 1155 | */ |
1110 | static void * | 1156 | static void * |
1111 | inbound_channel (void *cls, | 1157 | inbound_channel(void *cls, |
1112 | struct GNUNET_CADET_Channel *channel, | 1158 | struct GNUNET_CADET_Channel *channel, |
1113 | const struct GNUNET_PeerIdentity *initiator) | 1159 | const struct GNUNET_PeerIdentity *initiator) |
1114 | { | 1160 | { |
1115 | struct Line *line = cls; | 1161 | struct Line *line = cls; |
1116 | struct Channel *ch; | 1162 | struct Channel *ch; |
1117 | 1163 | ||
1118 | (void) initiator; | 1164 | (void)initiator; |
1119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1165 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1120 | "Received incoming cadet channel on line %p\n", | 1166 | "Received incoming cadet channel on line %p\n", |
1121 | line); | 1167 | line); |
1122 | ch = GNUNET_new (struct Channel); | 1168 | ch = GNUNET_new(struct Channel); |
1123 | ch->status = CS_CALLEE_INIT; | 1169 | ch->status = CS_CALLEE_INIT; |
1124 | ch->line = line; | 1170 | ch->line = line; |
1125 | ch->channel = channel; | 1171 | ch->channel = channel; |
1126 | ch->mq = GNUNET_CADET_get_mq (ch->channel); | 1172 | ch->mq = GNUNET_CADET_get_mq(ch->channel); |
1127 | ch->cid = line->cid_gen++; | 1173 | ch->cid = line->cid_gen++; |
1128 | GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch); | 1174 | GNUNET_CONTAINER_DLL_insert(line->channel_head, line->channel_tail, ch); |
1129 | return ch; | 1175 | return ch; |
1130 | } | 1176 | } |
1131 | 1177 | ||
@@ -1139,14 +1185,14 @@ inbound_channel (void *cls, | |||
1139 | * @return the `struct Line` for the client | 1185 | * @return the `struct Line` for the client |
1140 | */ | 1186 | */ |
1141 | static void * | 1187 | static void * |
1142 | client_connect_cb (void *cls, | 1188 | client_connect_cb(void *cls, |
1143 | struct GNUNET_SERVICE_Client *client, | 1189 | struct GNUNET_SERVICE_Client *client, |
1144 | struct GNUNET_MQ_Handle *mq) | 1190 | struct GNUNET_MQ_Handle *mq) |
1145 | { | 1191 | { |
1146 | struct Line *line; | 1192 | struct Line *line; |
1147 | 1193 | ||
1148 | (void) cls; | 1194 | (void)cls; |
1149 | line = GNUNET_new (struct Line); | 1195 | line = GNUNET_new(struct Line); |
1150 | line->client = client; | 1196 | line->client = client; |
1151 | line->mq = mq; | 1197 | line->mq = mq; |
1152 | return line; | 1198 | return line; |
@@ -1161,28 +1207,28 @@ client_connect_cb (void *cls, | |||
1161 | * @param app_ctx our `struct Line *` for @a client | 1207 | * @param app_ctx our `struct Line *` for @a client |
1162 | */ | 1208 | */ |
1163 | static void | 1209 | static void |
1164 | client_disconnect_cb (void *cls, | 1210 | client_disconnect_cb(void *cls, |
1165 | struct GNUNET_SERVICE_Client *client, | 1211 | struct GNUNET_SERVICE_Client *client, |
1166 | void *app_ctx) | 1212 | void *app_ctx) |
1167 | { | 1213 | { |
1168 | struct Line *line = app_ctx; | 1214 | struct Line *line = app_ctx; |
1169 | struct Channel *chn; | 1215 | struct Channel *chn; |
1170 | 1216 | ||
1171 | (void) cls; | 1217 | (void)cls; |
1172 | (void) client; | 1218 | (void)client; |
1173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, closing line\n"); | 1219 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, closing line\n"); |
1174 | if (NULL != line->port) | 1220 | if (NULL != line->port) |
1175 | { | 1221 | { |
1176 | GNUNET_CADET_close_port (line->port); | 1222 | GNUNET_CADET_close_port(line->port); |
1177 | line->port = NULL; | 1223 | line->port = NULL; |
1178 | } | 1224 | } |
1179 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = chn) | 1225 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = chn) |
1180 | { | 1226 | { |
1181 | chn = ch->next; | 1227 | chn = ch->next; |
1182 | ch->line = NULL; | 1228 | ch->line = NULL; |
1183 | destroy_line_cadet_channels (ch); | 1229 | destroy_line_cadet_channels(ch); |
1184 | } | 1230 | } |
1185 | GNUNET_free (line); | 1231 | GNUNET_free(line); |
1186 | } | 1232 | } |
1187 | 1233 | ||
1188 | 1234 | ||
@@ -1193,54 +1239,54 @@ client_disconnect_cb (void *cls, | |||
1193 | * @param msg the message from the client | 1239 | * @param msg the message from the client |
1194 | */ | 1240 | */ |
1195 | static void | 1241 | static void |
1196 | handle_client_register_message (void *cls, | 1242 | handle_client_register_message(void *cls, |
1197 | const struct ClientPhoneRegisterMessage *msg) | 1243 | const struct ClientPhoneRegisterMessage *msg) |
1198 | { | 1244 | { |
1199 | struct Line *line = cls; | 1245 | struct Line *line = cls; |
1200 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1246 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1201 | {GNUNET_MQ_hd_fixed_size (cadet_ring_message, | 1247 | { GNUNET_MQ_hd_fixed_size(cadet_ring_message, |
1202 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, | 1248 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, |
1203 | struct CadetPhoneRingMessage, | 1249 | struct CadetPhoneRingMessage, |
1204 | NULL), | 1250 | NULL), |
1205 | GNUNET_MQ_hd_fixed_size (cadet_hangup_message, | 1251 | GNUNET_MQ_hd_fixed_size(cadet_hangup_message, |
1206 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, | 1252 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, |
1207 | struct CadetPhoneHangupMessage, | 1253 | struct CadetPhoneHangupMessage, |
1208 | NULL), | ||
1209 | GNUNET_MQ_hd_fixed_size (cadet_pickup_message, | ||
1210 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, | ||
1211 | struct CadetPhonePickupMessage, | ||
1212 | NULL), | ||
1213 | GNUNET_MQ_hd_fixed_size (cadet_suspend_message, | ||
1214 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, | ||
1215 | struct CadetPhoneSuspendMessage, | ||
1216 | NULL), | ||
1217 | GNUNET_MQ_hd_fixed_size (cadet_resume_message, | ||
1218 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, | ||
1219 | struct CadetPhoneResumeMessage, | ||
1220 | NULL), | ||
1221 | GNUNET_MQ_hd_var_size (cadet_audio_message, | ||
1222 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | ||
1223 | struct CadetAudioMessage, | ||
1224 | NULL), | 1254 | NULL), |
1225 | GNUNET_MQ_handler_end ()}; | 1255 | GNUNET_MQ_hd_fixed_size(cadet_pickup_message, |
1256 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, | ||
1257 | struct CadetPhonePickupMessage, | ||
1258 | NULL), | ||
1259 | GNUNET_MQ_hd_fixed_size(cadet_suspend_message, | ||
1260 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, | ||
1261 | struct CadetPhoneSuspendMessage, | ||
1262 | NULL), | ||
1263 | GNUNET_MQ_hd_fixed_size(cadet_resume_message, | ||
1264 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, | ||
1265 | struct CadetPhoneResumeMessage, | ||
1266 | NULL), | ||
1267 | GNUNET_MQ_hd_var_size(cadet_audio_message, | ||
1268 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | ||
1269 | struct CadetAudioMessage, | ||
1270 | NULL), | ||
1271 | GNUNET_MQ_handler_end() }; | ||
1226 | 1272 | ||
1227 | line->line_port = msg->line_port; | 1273 | line->line_port = msg->line_port; |
1228 | line->port = GNUNET_CADET_open_port (cadet, | 1274 | line->port = GNUNET_CADET_open_port(cadet, |
1229 | &msg->line_port, | 1275 | &msg->line_port, |
1230 | &inbound_channel, | 1276 | &inbound_channel, |
1231 | line, | 1277 | line, |
1232 | NULL, | 1278 | NULL, |
1233 | &inbound_end, | 1279 | &inbound_end, |
1234 | cadet_handlers); | 1280 | cadet_handlers); |
1235 | if (NULL == line->port) | 1281 | if (NULL == line->port) |
1236 | { | 1282 | { |
1237 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1283 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1238 | _ ("Could not open line, port %s already in use!\n"), | 1284 | _("Could not open line, port %s already in use!\n"), |
1239 | GNUNET_h2s (&msg->line_port)); | 1285 | GNUNET_h2s(&msg->line_port)); |
1240 | GNUNET_SERVICE_client_drop (line->client); | 1286 | GNUNET_SERVICE_client_drop(line->client); |
1241 | return; | 1287 | return; |
1242 | } | 1288 | } |
1243 | GNUNET_SERVICE_client_continue (line->client); | 1289 | GNUNET_SERVICE_client_continue(line->client); |
1244 | } | 1290 | } |
1245 | 1291 | ||
1246 | 1292 | ||
@@ -1250,14 +1296,14 @@ handle_client_register_message (void *cls, | |||
1250 | * @param cls closure, NULL | 1296 | * @param cls closure, NULL |
1251 | */ | 1297 | */ |
1252 | static void | 1298 | static void |
1253 | do_shutdown (void *cls) | 1299 | do_shutdown(void *cls) |
1254 | { | 1300 | { |
1255 | (void) cls; | 1301 | (void)cls; |
1256 | if (NULL != cadet) | 1302 | if (NULL != cadet) |
1257 | { | 1303 | { |
1258 | GNUNET_CADET_disconnect (cadet); | 1304 | GNUNET_CADET_disconnect(cadet); |
1259 | cadet = NULL; | 1305 | cadet = NULL; |
1260 | } | 1306 | } |
1261 | } | 1307 | } |
1262 | 1308 | ||
1263 | 1309 | ||
@@ -1269,65 +1315,65 @@ do_shutdown (void *cls) | |||
1269 | * @param service service handle | 1315 | * @param service service handle |
1270 | */ | 1316 | */ |
1271 | static void | 1317 | static void |
1272 | run (void *cls, | 1318 | run(void *cls, |
1273 | const struct GNUNET_CONFIGURATION_Handle *c, | 1319 | const struct GNUNET_CONFIGURATION_Handle *c, |
1274 | struct GNUNET_SERVICE_Handle *service) | 1320 | struct GNUNET_SERVICE_Handle *service) |
1275 | { | 1321 | { |
1276 | (void) cls; | 1322 | (void)cls; |
1277 | (void) service; | 1323 | (void)service; |
1278 | cfg = c; | 1324 | cfg = c; |
1279 | GNUNET_assert (GNUNET_OK == | 1325 | GNUNET_assert(GNUNET_OK == |
1280 | GNUNET_CRYPTO_get_peer_identity (cfg, &my_identity)); | 1326 | GNUNET_CRYPTO_get_peer_identity(cfg, &my_identity)); |
1281 | cadet = GNUNET_CADET_connect (cfg); | 1327 | cadet = GNUNET_CADET_connect(cfg); |
1282 | if (NULL == cadet) | 1328 | if (NULL == cadet) |
1283 | { | 1329 | { |
1284 | GNUNET_break (0); | 1330 | GNUNET_break(0); |
1285 | GNUNET_SCHEDULER_shutdown (); | 1331 | GNUNET_SCHEDULER_shutdown(); |
1286 | return; | 1332 | return; |
1287 | } | 1333 | } |
1288 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 1334 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
1289 | } | 1335 | } |
1290 | 1336 | ||
1291 | 1337 | ||
1292 | /** | 1338 | /** |
1293 | * Define "main" method using service macro. | 1339 | * Define "main" method using service macro. |
1294 | */ | 1340 | */ |
1295 | GNUNET_SERVICE_MAIN ( | 1341 | GNUNET_SERVICE_MAIN( |
1296 | "conversation", | 1342 | "conversation", |
1297 | GNUNET_SERVICE_OPTION_NONE, | 1343 | GNUNET_SERVICE_OPTION_NONE, |
1298 | &run, | 1344 | &run, |
1299 | &client_connect_cb, | 1345 | &client_connect_cb, |
1300 | &client_disconnect_cb, | 1346 | &client_disconnect_cb, |
1301 | NULL, | 1347 | NULL, |
1302 | GNUNET_MQ_hd_fixed_size (client_register_message, | 1348 | GNUNET_MQ_hd_fixed_size(client_register_message, |
1303 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, | 1349 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, |
1304 | struct ClientPhoneRegisterMessage, | 1350 | struct ClientPhoneRegisterMessage, |
1305 | NULL), | 1351 | NULL), |
1306 | GNUNET_MQ_hd_fixed_size (client_pickup_message, | 1352 | GNUNET_MQ_hd_fixed_size(client_pickup_message, |
1307 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, | 1353 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, |
1308 | struct ClientPhonePickupMessage, | 1354 | struct ClientPhonePickupMessage, |
1309 | NULL), | 1355 | NULL), |
1310 | GNUNET_MQ_hd_fixed_size (client_suspend_message, | 1356 | GNUNET_MQ_hd_fixed_size(client_suspend_message, |
1311 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, | 1357 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, |
1312 | struct ClientPhoneSuspendMessage, | 1358 | struct ClientPhoneSuspendMessage, |
1313 | NULL), | 1359 | NULL), |
1314 | GNUNET_MQ_hd_fixed_size (client_resume_message, | 1360 | GNUNET_MQ_hd_fixed_size(client_resume_message, |
1315 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, | 1361 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, |
1316 | struct ClientPhoneResumeMessage, | 1362 | struct ClientPhoneResumeMessage, |
1317 | NULL), | 1363 | NULL), |
1318 | GNUNET_MQ_hd_fixed_size (client_hangup_message, | 1364 | GNUNET_MQ_hd_fixed_size(client_hangup_message, |
1319 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, | 1365 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, |
1320 | struct ClientPhoneHangupMessage, | 1366 | struct ClientPhoneHangupMessage, |
1321 | NULL), | 1367 | NULL), |
1322 | GNUNET_MQ_hd_fixed_size (client_call_message, | 1368 | GNUNET_MQ_hd_fixed_size(client_call_message, |
1323 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, | 1369 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, |
1324 | struct ClientCallMessage, | 1370 | struct ClientCallMessage, |
1325 | NULL), | 1371 | NULL), |
1326 | GNUNET_MQ_hd_var_size (client_audio_message, | 1372 | GNUNET_MQ_hd_var_size(client_audio_message, |
1327 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, | 1373 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, |
1328 | struct ClientAudioMessage, | 1374 | struct ClientAudioMessage, |
1329 | NULL), | 1375 | NULL), |
1330 | GNUNET_MQ_handler_end ()); | 1376 | GNUNET_MQ_handler_end()); |
1331 | 1377 | ||
1332 | 1378 | ||
1333 | /* end of gnunet-service-conversation.c */ | 1379 | /* end of gnunet-service-conversation.c */ |