aboutsummaryrefslogtreecommitdiff
path: root/src/conversation
diff options
context:
space:
mode:
Diffstat (limited to 'src/conversation')
-rw-r--r--src/conversation/gnunet-service-conversation.c548
1 files changed, 216 insertions, 332 deletions
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c
index 8937c8f49..08458f278 100644
--- a/src/conversation/gnunet-service-conversation.c
+++ b/src/conversation/gnunet-service-conversation.c
@@ -172,7 +172,12 @@ struct Line
172 /** 172 /**
173 * Handle to the line client. 173 * Handle to the line client.
174 */ 174 */
175 struct GNUNET_SERVER_Client *client; 175 struct GNUNET_SERVICE_Client *client;
176
177 /**
178 * Message queue for @e client.
179 */
180 struct GNUNET_MQ_Handle *mq;
176 181
177 /** 182 /**
178 * Our open port. 183 * Our open port.
@@ -199,11 +204,6 @@ struct Line
199static const struct GNUNET_CONFIGURATION_Handle *cfg; 204static const struct GNUNET_CONFIGURATION_Handle *cfg;
200 205
201/** 206/**
202 * Notification context containing all connected clients.
203 */
204static struct GNUNET_SERVER_NotificationContext *nc;
205
206/**
207 * Handle for cadet 207 * Handle for cadet
208 */ 208 */
209static struct GNUNET_CADET_Handle *cadet; 209static struct GNUNET_CADET_Handle *cadet;
@@ -238,28 +238,23 @@ find_channel_by_line (struct Line *line,
238/** 238/**
239 * Function to handle a pickup request message from the client 239 * Function to handle a pickup request message from the client
240 * 240 *
241 * @param cls closure, NULL 241 * @param cls the `struct Line` of the client from which the message is
242 * @param client the client from which the message is 242 * @param msg the message from the client
243 * @param message the message from the client
244 */ 243 */
245static void 244static void
246handle_client_pickup_message (void *cls, 245handle_client_pickup_message (void *cls,
247 struct GNUNET_SERVER_Client *client, 246 const struct ClientPhonePickupMessage *msg)
248 const struct GNUNET_MessageHeader *message)
249{ 247{
250 const struct ClientPhonePickupMessage *msg; 248 struct Line *line = cls;
251 struct GNUNET_MQ_Envelope *e;
252 struct CadetPhonePickupMessage *mppm; 249 struct CadetPhonePickupMessage *mppm;
253 struct Line *line; 250 struct GNUNET_MQ_Envelope *env;
254 struct Channel *ch; 251 struct Channel *ch;
255 252
256 msg = (const struct ClientPhonePickupMessage *) message; 253 if (NULL == line->port)
257 line = GNUNET_SERVER_client_get_user_context (client,
258 struct Line);
259 if (NULL == line)
260 { 254 {
261 GNUNET_break (0); 255 /* we never opened the port, bad client! */
262 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 256 GNUNET_break_op (0);
257 GNUNET_SERVICE_client_drop (line->client);
263 return; 258 return;
264 } 259 }
265 for (ch = line->channel_head; NULL != ch; ch = ch->next) 260 for (ch = line->channel_head; NULL != ch; ch = ch->next)
@@ -271,24 +266,21 @@ handle_client_pickup_message (void *cls,
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
272 "Channel %u not found\n", 267 "Channel %u not found\n",
273 msg->cid); 268 msg->cid);
274 GNUNET_SERVER_receive_done (client, 269 GNUNET_SERVICE_client_continue (line->client);
275 GNUNET_YES);
276 return; 270 return;
277 } 271 }
278 switch (ch->status) 272 switch (ch->status)
279 { 273 {
280 case CS_CALLEE_INIT: 274 case CS_CALLEE_INIT:
281 GNUNET_break (0); 275 GNUNET_break (0);
282 GNUNET_SERVER_receive_done (client, 276 GNUNET_SERVICE_client_drop (line->client);
283 GNUNET_SYSERR);
284 return; 277 return;
285 case CS_CALLEE_RINGING: 278 case CS_CALLEE_RINGING:
286 ch->status = CS_CALLEE_CONNECTED; 279 ch->status = CS_CALLEE_CONNECTED;
287 break; 280 break;
288 case CS_CALLEE_CONNECTED: 281 case CS_CALLEE_CONNECTED:
289 GNUNET_break (0); 282 GNUNET_break (0);
290 GNUNET_SERVER_receive_done (client, 283 GNUNET_SERVICE_client_drop (line->client);
291 GNUNET_SYSERR);
292 return; 284 return;
293 case CS_CALLEE_SHUTDOWN: 285 case CS_CALLEE_SHUTDOWN:
294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -298,17 +290,17 @@ handle_client_pickup_message (void *cls,
298 case CS_CALLER_CONNECTED: 290 case CS_CALLER_CONNECTED:
299 case CS_CALLER_SHUTDOWN: 291 case CS_CALLER_SHUTDOWN:
300 GNUNET_break (0); 292 GNUNET_break (0);
301 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 293 GNUNET_SERVICE_client_drop (line->client);
302 return; 294 return;
303 } 295 }
304 GNUNET_break (CS_CALLEE_CONNECTED == ch->status); 296 GNUNET_break (CS_CALLEE_CONNECTED == ch->status);
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
306 "Sending PICK_UP message to cadet\n"); 298 "Sending PICK_UP message to cadet\n");
307 e = GNUNET_MQ_msg (mppm, 299 env = GNUNET_MQ_msg (mppm,
308 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); 300 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP);
309 GNUNET_MQ_send (ch->mq, e); 301 GNUNET_MQ_send (ch->mq,
310 GNUNET_SERVER_receive_done (client, 302 env);
311 GNUNET_OK); 303 GNUNET_SERVICE_client_continue (line->client);
312} 304}
313 305
314 306
@@ -373,31 +365,18 @@ mq_done_finish_caller_shutdown (void *cls)
373/** 365/**
374 * Function to handle a hangup request message from the client 366 * Function to handle a hangup request message from the client
375 * 367 *
376 * @param cls closure, NULL 368 * @param cls the `struct Line` the hangup is for
377 * @param client the client from which the message is 369 * @param msg the message from the client
378 * @param message the message from the client
379 */ 370 */
380static void 371static void
381handle_client_hangup_message (void *cls, 372handle_client_hangup_message (void *cls,
382 struct GNUNET_SERVER_Client *client, 373 const struct ClientPhoneHangupMessage *msg)
383 const struct GNUNET_MessageHeader *message)
384{ 374{
385 const struct ClientPhoneHangupMessage *msg; 375 struct Line *line = cls;
386 struct GNUNET_MQ_Envelope *e; 376 struct GNUNET_MQ_Envelope *e;
387 struct CadetPhoneHangupMessage *mhum; 377 struct CadetPhoneHangupMessage *mhum;
388 struct Line *line;
389 struct Channel *ch; 378 struct Channel *ch;
390 379
391 msg = (const struct ClientPhoneHangupMessage *) message;
392 line = GNUNET_SERVER_client_get_user_context (client,
393 struct Line);
394 if (NULL == line)
395 {
396 GNUNET_break (0);
397 GNUNET_SERVER_receive_done (client,
398 GNUNET_SYSERR);
399 return;
400 }
401 for (ch = line->channel_head; NULL != ch; ch = ch->next) 380 for (ch = line->channel_head; NULL != ch; ch = ch->next)
402 if (msg->cid == ch->cid) 381 if (msg->cid == ch->cid)
403 break; 382 break;
@@ -407,8 +386,7 @@ handle_client_hangup_message (void *cls,
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Channel %u not found\n", 387 "Channel %u not found\n",
409 msg->cid); 388 msg->cid);
410 GNUNET_SERVER_receive_done (client, 389 GNUNET_SERVICE_client_continue (line->client);
411 GNUNET_OK);
412 return; 390 return;
413 } 391 }
414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -419,8 +397,7 @@ handle_client_hangup_message (void *cls,
419 { 397 {
420 case CS_CALLEE_INIT: 398 case CS_CALLEE_INIT:
421 GNUNET_break (0); 399 GNUNET_break (0);
422 GNUNET_SERVER_receive_done (client, 400 GNUNET_SERVICE_client_drop (line->client);
423 GNUNET_SYSERR);
424 return; 401 return;
425 case CS_CALLEE_RINGING: 402 case CS_CALLEE_RINGING:
426 ch->status = CS_CALLEE_SHUTDOWN; 403 ch->status = CS_CALLEE_SHUTDOWN;
@@ -430,8 +407,7 @@ handle_client_hangup_message (void *cls,
430 break; 407 break;
431 case CS_CALLEE_SHUTDOWN: 408 case CS_CALLEE_SHUTDOWN:
432 /* maybe the other peer closed asynchronously... */ 409 /* maybe the other peer closed asynchronously... */
433 GNUNET_SERVER_receive_done (client, 410 GNUNET_SERVICE_client_continue (line->client);
434 GNUNET_OK);
435 return; 411 return;
436 case CS_CALLER_CALLING: 412 case CS_CALLER_CALLING:
437 ch->status = CS_CALLER_SHUTDOWN; 413 ch->status = CS_CALLER_SHUTDOWN;
@@ -441,7 +417,7 @@ handle_client_hangup_message (void *cls,
441 break; 417 break;
442 case CS_CALLER_SHUTDOWN: 418 case CS_CALLER_SHUTDOWN:
443 /* maybe the other peer closed asynchronously... */ 419 /* maybe the other peer closed asynchronously... */
444 GNUNET_SERVER_receive_done (client, GNUNET_OK); 420 GNUNET_SERVICE_client_continue (line->client);
445 return; 421 return;
446 } 422 }
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -453,39 +429,25 @@ handle_client_hangup_message (void *cls,
453 ch); 429 ch);
454 GNUNET_MQ_send (ch->mq, 430 GNUNET_MQ_send (ch->mq,
455 e); 431 e);
456 GNUNET_SERVER_receive_done (client, 432 GNUNET_SERVICE_client_continue (line->client);
457 GNUNET_OK);
458} 433}
459 434
460 435
461/** 436/**
462 * Function to handle a suspend request message from the client 437 * Function to handle a suspend request message from the client
463 * 438 *
464 * @param cls closure, NULL 439 * @param cls the `struct Line` the message is about
465 * @param client the client from which the message is 440 * @param msg the message from the client
466 * @param message the message from the client
467 */ 441 */
468static void 442static void
469handle_client_suspend_message (void *cls, 443handle_client_suspend_message (void *cls,
470 struct GNUNET_SERVER_Client *client, 444 const struct ClientPhoneSuspendMessage *msg)
471 const struct GNUNET_MessageHeader *message)
472{ 445{
473 const struct ClientPhoneSuspendMessage *msg; 446 struct Line *line = cls;
474 struct GNUNET_MQ_Envelope *e; 447 struct GNUNET_MQ_Envelope *e;
475 struct CadetPhoneSuspendMessage *mhum; 448 struct CadetPhoneSuspendMessage *mhum;
476 struct Line *line;
477 struct Channel *ch; 449 struct Channel *ch;
478 450
479 msg = (const struct ClientPhoneSuspendMessage *) message;
480 line = GNUNET_SERVER_client_get_user_context (client,
481 struct Line);
482 if (NULL == line)
483 {
484 GNUNET_break (0);
485 GNUNET_SERVER_receive_done (client,
486 GNUNET_SYSERR);
487 return;
488 }
489 for (ch = line->channel_head; NULL != ch; ch = ch->next) 451 for (ch = line->channel_head; NULL != ch; ch = ch->next)
490 if (msg->cid == ch->cid) 452 if (msg->cid == ch->cid)
491 break; 453 break;
@@ -495,15 +457,13 @@ handle_client_suspend_message (void *cls,
495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
496 "Channel %u not found\n", 458 "Channel %u not found\n",
497 msg->cid); 459 msg->cid);
498 GNUNET_SERVER_receive_done (client, 460 GNUNET_SERVICE_client_continue (line->client);
499 GNUNET_OK);
500 return; 461 return;
501 } 462 }
502 if (GNUNET_YES == ch->suspended_local) 463 if (GNUNET_YES == ch->suspended_local)
503 { 464 {
504 GNUNET_break (0); 465 GNUNET_break (0);
505 GNUNET_SERVER_receive_done (client, 466 GNUNET_SERVICE_client_drop (line->client);
506 GNUNET_SYSERR);
507 return; 467 return;
508 } 468 }
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -514,34 +474,29 @@ handle_client_suspend_message (void *cls,
514 { 474 {
515 case CS_CALLEE_INIT: 475 case CS_CALLEE_INIT:
516 GNUNET_break (0); 476 GNUNET_break (0);
517 GNUNET_SERVER_receive_done (client, 477 GNUNET_SERVICE_client_drop (line->client);
518 GNUNET_SYSERR);
519 return; 478 return;
520 case CS_CALLEE_RINGING: 479 case CS_CALLEE_RINGING:
521 GNUNET_break (0); 480 GNUNET_break (0);
522 GNUNET_SERVER_receive_done (client, 481 GNUNET_SERVICE_client_drop (line->client);
523 GNUNET_SYSERR);
524 return; 482 return;
525 case CS_CALLEE_CONNECTED: 483 case CS_CALLEE_CONNECTED:
526 ch->suspended_local = GNUNET_YES; 484 ch->suspended_local = GNUNET_YES;
527 break; 485 break;
528 case CS_CALLEE_SHUTDOWN: 486 case CS_CALLEE_SHUTDOWN:
529 /* maybe the other peer closed asynchronously... */ 487 /* maybe the other peer closed asynchronously... */
530 GNUNET_SERVER_receive_done (client, 488 GNUNET_SERVICE_client_continue (line->client);
531 GNUNET_OK);
532 return; 489 return;
533 case CS_CALLER_CALLING: 490 case CS_CALLER_CALLING:
534 GNUNET_break (0); 491 GNUNET_break (0);
535 GNUNET_SERVER_receive_done (client, 492 GNUNET_SERVICE_client_drop (line->client);
536 GNUNET_SYSERR);
537 return; 493 return;
538 case CS_CALLER_CONNECTED: 494 case CS_CALLER_CONNECTED:
539 ch->suspended_local = GNUNET_YES; 495 ch->suspended_local = GNUNET_YES;
540 break; 496 break;
541 case CS_CALLER_SHUTDOWN: 497 case CS_CALLER_SHUTDOWN:
542 /* maybe the other peer closed asynchronously... */ 498 /* maybe the other peer closed asynchronously... */
543 GNUNET_SERVER_receive_done (client, 499 GNUNET_SERVICE_client_continue (line->client);
544 GNUNET_OK);
545 return; 500 return;
546 } 501 }
547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -550,39 +505,25 @@ handle_client_suspend_message (void *cls,
550 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); 505 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND);
551 GNUNET_MQ_send (ch->mq, 506 GNUNET_MQ_send (ch->mq,
552 e); 507 e);
553 GNUNET_SERVER_receive_done (client, 508 GNUNET_SERVICE_client_continue (line->client);
554 GNUNET_OK);
555} 509}
556 510
557 511
558/** 512/**
559 * Function to handle a resume request message from the client 513 * Function to handle a resume request message from the client
560 * 514 *
561 * @param cls closure, NULL 515 * @param cls the `struct Line` the message is about
562 * @param client the client from which the message is 516 * @param msg the message from the client
563 * @param message the message from the client
564 */ 517 */
565static void 518static void
566handle_client_resume_message (void *cls, 519handle_client_resume_message (void *cls,
567 struct GNUNET_SERVER_Client *client, 520 const struct ClientPhoneResumeMessage *msg)
568 const struct GNUNET_MessageHeader *message)
569{ 521{
570 const struct ClientPhoneResumeMessage *msg; 522 struct Line *line = cls;
571 struct GNUNET_MQ_Envelope *e; 523 struct GNUNET_MQ_Envelope *e;
572 struct CadetPhoneResumeMessage *mhum; 524 struct CadetPhoneResumeMessage *mhum;
573 struct Line *line;
574 struct Channel *ch; 525 struct Channel *ch;
575 526
576 msg = (const struct ClientPhoneResumeMessage *) message;
577 line = GNUNET_SERVER_client_get_user_context (client,
578 struct Line);
579 if (NULL == line)
580 {
581 GNUNET_break (0);
582 GNUNET_SERVER_receive_done (client,
583 GNUNET_SYSERR);
584 return;
585 }
586 for (ch = line->channel_head; NULL != ch; ch = ch->next) 527 for (ch = line->channel_head; NULL != ch; ch = ch->next)
587 if (msg->cid == ch->cid) 528 if (msg->cid == ch->cid)
588 break; 529 break;
@@ -592,14 +533,13 @@ handle_client_resume_message (void *cls,
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
593 "Channel %u not found\n", 534 "Channel %u not found\n",
594 msg->cid); 535 msg->cid);
595 GNUNET_SERVER_receive_done (client, 536 GNUNET_SERVICE_client_continue (line->client);
596 GNUNET_OK);
597 return; 537 return;
598 } 538 }
599 if (GNUNET_YES != ch->suspended_local) 539 if (GNUNET_YES != ch->suspended_local)
600 { 540 {
601 GNUNET_break (0); 541 GNUNET_break (0);
602 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 542 GNUNET_SERVICE_client_drop (line->client);
603 return; 543 return;
604 } 544 }
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -610,34 +550,29 @@ handle_client_resume_message (void *cls,
610 { 550 {
611 case CS_CALLEE_INIT: 551 case CS_CALLEE_INIT:
612 GNUNET_break (0); 552 GNUNET_break (0);
613 GNUNET_SERVER_receive_done (client, 553 GNUNET_SERVICE_client_drop (line->client);
614 GNUNET_SYSERR);
615 return; 554 return;
616 case CS_CALLEE_RINGING: 555 case CS_CALLEE_RINGING:
617 GNUNET_break (0); 556 GNUNET_break (0);
618 GNUNET_SERVER_receive_done (client, 557 GNUNET_SERVICE_client_drop (line->client);
619 GNUNET_SYSERR);
620 return; 558 return;
621 case CS_CALLEE_CONNECTED: 559 case CS_CALLEE_CONNECTED:
622 ch->suspended_local = GNUNET_NO; 560 ch->suspended_local = GNUNET_NO;
623 break; 561 break;
624 case CS_CALLEE_SHUTDOWN: 562 case CS_CALLEE_SHUTDOWN:
625 /* maybe the other peer closed asynchronously... */ 563 /* maybe the other peer closed asynchronously... */
626 GNUNET_SERVER_receive_done (client, 564 GNUNET_SERVICE_client_continue (line->client);
627 GNUNET_OK);
628 return; 565 return;
629 case CS_CALLER_CALLING: 566 case CS_CALLER_CALLING:
630 GNUNET_break (0); 567 GNUNET_break (0);
631 GNUNET_SERVER_receive_done (client, 568 GNUNET_SERVICE_client_drop (line->client);
632 GNUNET_SYSERR);
633 return; 569 return;
634 case CS_CALLER_CONNECTED: 570 case CS_CALLER_CONNECTED:
635 ch->suspended_local = GNUNET_NO; 571 ch->suspended_local = GNUNET_NO;
636 break; 572 break;
637 case CS_CALLER_SHUTDOWN: 573 case CS_CALLER_SHUTDOWN:
638 /* maybe the other peer closed asynchronously... */ 574 /* maybe the other peer closed asynchronously... */
639 GNUNET_SERVER_receive_done (client, 575 GNUNET_SERVICE_client_drop (line->client);
640 GNUNET_SYSERR);
641 return; 576 return;
642 } 577 }
643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -646,46 +581,27 @@ handle_client_resume_message (void *cls,
646 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME); 581 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME);
647 GNUNET_MQ_send (ch->mq, 582 GNUNET_MQ_send (ch->mq,
648 e); 583 e);
649 GNUNET_SERVER_receive_done (client, 584 GNUNET_SERVICE_client_continue (line->client);
650 GNUNET_OK);
651} 585}
652 586
653 587
654/** 588/**
655 * Function to handle call request from the client 589 * Function to handle call request from the client
656 * 590 *
657 * @param cls closure, NULL 591 * @param cls the `struct Line` the message is about
658 * @param client the client from which the message is 592 * @param msg the message from the client
659 * @param message the message from the client
660 */ 593 */
661static void 594static void
662handle_client_call_message (void *cls, 595handle_client_call_message (void *cls,
663 struct GNUNET_SERVER_Client *client, 596 const struct ClientCallMessage *msg)
664 const struct GNUNET_MessageHeader *message)
665{ 597{
666 const struct ClientCallMessage *msg; 598 struct Line *line = cls;
667 struct Line *line;
668 struct Channel *ch; 599 struct Channel *ch;
669 struct GNUNET_MQ_Envelope *e; 600 struct GNUNET_MQ_Envelope *e;
670 struct CadetPhoneRingMessage *ring; 601 struct CadetPhoneRingMessage *ring;
671 struct CadetPhoneRingInfoPS rs; 602 struct CadetPhoneRingInfoPS rs;
672 603
673 msg = (const struct ClientCallMessage *) message;
674 line = GNUNET_SERVER_client_get_user_context (client,
675 struct Line);
676 if (NULL != line)
677 {
678 GNUNET_break (0);
679 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
680 return;
681 }
682 line = GNUNET_new (struct Line);
683 line->client = client;
684 line->line_port = msg->line_port; 604 line->line_port = msg->line_port;
685 GNUNET_SERVER_client_set_user_context (client,
686 line);
687 GNUNET_SERVER_notification_context_add (nc,
688 client);
689 rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); 605 rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING);
690 rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS)); 606 rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS));
691 rs.line_port = line->line_port; 607 rs.line_port = line->line_port;
@@ -718,8 +634,7 @@ handle_client_call_message (void *cls,
718 "Sending RING message via CADET\n"); 634 "Sending RING message via CADET\n");
719 GNUNET_MQ_send (ch->mq, 635 GNUNET_MQ_send (ch->mq,
720 e); 636 e);
721 GNUNET_SERVER_receive_done (client, 637 GNUNET_SERVICE_client_continue (line->client);
722 GNUNET_OK);
723} 638}
724 639
725 640
@@ -738,34 +653,36 @@ channel_audio_sent_notify (void *cls)
738 653
739 654
740/** 655/**
656 * Function to check audio data from the client
657 *
658 * @param cls the `struct Line` the message is about
659 * @param msg the message from the client
660 * @return #GNUNET_OK (any data is ok)
661 */
662static int
663check_client_audio_message (void *cls,
664 const struct ClientAudioMessage *msg)
665{
666 return GNUNET_OK;
667}
668
669
670/**
741 * Function to handle audio data from the client 671 * Function to handle audio data from the client
742 * 672 *
743 * @param cls closure, NULL 673 * @param cls the `struct Line` the message is about
744 * @param client the client from which the message is 674 * @param msg the message from the client
745 * @param message the message from the client
746 */ 675 */
747static void 676static void
748handle_client_audio_message (void *cls, 677handle_client_audio_message (void *cls,
749 struct GNUNET_SERVER_Client *client, 678 const struct ClientAudioMessage *msg)
750 const struct GNUNET_MessageHeader *message)
751{ 679{
752 const struct ClientAudioMessage *msg; 680 struct Line *line = cls;
753 struct ClientAudioMessage *mam; 681 struct ClientAudioMessage *mam;
754 struct Line *line;
755 struct Channel *ch; 682 struct Channel *ch;
756 size_t size; 683 size_t size;
757 684
758 size = ntohs (message->size) - sizeof (struct ClientAudioMessage); 685 size = ntohs (msg->header.size) - sizeof (struct ClientAudioMessage);
759 msg = (const struct ClientAudioMessage *) message;
760 line = GNUNET_SERVER_client_get_user_context (client,
761 struct Line);
762 if (NULL == line)
763 {
764 GNUNET_break (0);
765 GNUNET_SERVER_receive_done (client,
766 GNUNET_SYSERR);
767 return;
768 }
769 ch = find_channel_by_line (line, 686 ch = find_channel_by_line (line,
770 msg->cid); 687 msg->cid);
771 if (NULL == ch) 688 if (NULL == ch)
@@ -774,8 +691,7 @@ handle_client_audio_message (void *cls,
774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
775 "Channel %u not found\n", 692 "Channel %u not found\n",
776 msg->cid); 693 msg->cid);
777 GNUNET_SERVER_receive_done (client, 694 GNUNET_SERVICE_client_continue (line->client);
778 GNUNET_OK);
779 return; 695 return;
780 } 696 }
781 697
@@ -785,8 +701,7 @@ handle_client_audio_message (void *cls,
785 case CS_CALLEE_RINGING: 701 case CS_CALLEE_RINGING:
786 case CS_CALLER_CALLING: 702 case CS_CALLER_CALLING:
787 GNUNET_break (0); 703 GNUNET_break (0);
788 GNUNET_SERVER_receive_done (client, 704 GNUNET_SERVICE_client_drop (line->client);
789 GNUNET_SYSERR);
790 return; 705 return;
791 case CS_CALLEE_CONNECTED: 706 case CS_CALLEE_CONNECTED:
792 case CS_CALLER_CONNECTED: 707 case CS_CALLER_CONNECTED:
@@ -796,16 +711,14 @@ handle_client_audio_message (void *cls,
796 case CS_CALLER_SHUTDOWN: 711 case CS_CALLER_SHUTDOWN:
797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
798 "Cadet audio channel in shutdown; audio data dropped\n"); 713 "Cadet audio channel in shutdown; audio data dropped\n");
799 GNUNET_SERVER_receive_done (client, 714 GNUNET_SERVICE_client_continue (line->client);
800 GNUNET_OK);
801 return; 715 return;
802 } 716 }
803 if (GNUNET_YES == ch->suspended_local) 717 if (GNUNET_YES == ch->suspended_local)
804 { 718 {
805 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 719 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
806 "This channel is suspended locally\n"); 720 "This channel is suspended locally\n");
807 GNUNET_SERVER_receive_done (client, 721 GNUNET_SERVICE_client_drop (line->client);
808 GNUNET_SYSERR);
809 return; 722 return;
810 } 723 }
811 if (NULL != ch->env) 724 if (NULL != ch->env)
@@ -829,8 +742,7 @@ handle_client_audio_message (void *cls,
829 ch); 742 ch);
830 GNUNET_MQ_send (ch->mq, 743 GNUNET_MQ_send (ch->mq,
831 ch->env); 744 ch->env);
832 GNUNET_SERVER_receive_done (client, 745 GNUNET_SERVICE_client_continue (line->client);
833 GNUNET_OK);
834} 746}
835 747
836 748
@@ -853,7 +765,8 @@ handle_cadet_ring_message (void *cls,
853 struct Channel *ch = *channel_ctx; 765 struct Channel *ch = *channel_ctx;
854 struct Line *line = ch->line; 766 struct Line *line = ch->line;
855 const struct CadetPhoneRingMessage *msg; 767 const struct CadetPhoneRingMessage *msg;
856 struct ClientPhoneRingMessage cring; 768 struct GNUNET_MQ_Envelope *env;
769 struct ClientPhoneRingMessage *cring;
857 struct CadetPhoneRingInfoPS rs; 770 struct CadetPhoneRingInfoPS rs;
858 771
859 msg = (const struct CadetPhoneRingMessage *) message; 772 msg = (const struct CadetPhoneRingMessage *) message;
@@ -888,17 +801,15 @@ handle_cadet_ring_message (void *cls,
888 } 801 }
889 GNUNET_CADET_receive_done (channel); 802 GNUNET_CADET_receive_done (channel);
890 ch->status = CS_CALLEE_RINGING; 803 ch->status = CS_CALLEE_RINGING;
891 cring.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); 804 env = GNUNET_MQ_msg (cring,
892 cring.header.size = htons (sizeof (cring)); 805 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING);
893 cring.cid = ch->cid; 806 cring->cid = ch->cid;
894 cring.caller_id = msg->caller_id; 807 cring->caller_id = msg->caller_id;
895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
896 "Sending RING message to client. CID is %u\n", 809 "Sending RING message to client. CID is %u\n",
897 (unsigned int) ch->cid); 810 (unsigned int) ch->cid);
898 GNUNET_SERVER_notification_context_unicast (nc, 811 GNUNET_MQ_send (line->mq,
899 line->client, 812 env);
900 &cring.header,
901 GNUNET_NO);
902 return GNUNET_OK; 813 return GNUNET_OK;
903} 814}
904 815
@@ -921,13 +832,13 @@ handle_cadet_hangup_message (void *cls,
921{ 832{
922 struct Channel *ch = *channel_ctx; 833 struct Channel *ch = *channel_ctx;
923 struct Line *line = ch->line; 834 struct Line *line = ch->line;
924 struct ClientPhoneHangupMessage hup; 835 struct GNUNET_MQ_Envelope *env;
836 struct ClientPhoneHangupMessage *hup;
925 enum ChannelStatus status; 837 enum ChannelStatus status;
838 uint32_t cid;
926 839
927 GNUNET_CADET_receive_done (channel); 840 GNUNET_CADET_receive_done (channel);
928 hup.header.size = htons (sizeof (hup)); 841 cid = ch->cid;
929 hup.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
930 hup.cid = ch->cid;
931 status = ch->status; 842 status = ch->status;
932 destroy_line_cadet_channels (ch); 843 destroy_line_cadet_channels (ch);
933 switch (status) 844 switch (status)
@@ -948,10 +859,11 @@ handle_cadet_hangup_message (void *cls,
948 } 859 }
949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
950 "Sending HANG UP message to client\n"); 861 "Sending HANG UP message to client\n");
951 GNUNET_SERVER_notification_context_unicast (nc, 862 env = GNUNET_MQ_msg (hup,
952 line->client, 863 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
953 &hup.header, 864 hup->cid = cid;
954 GNUNET_NO); 865 GNUNET_MQ_send (line->mq,
866 env);
955 return GNUNET_OK; 867 return GNUNET_OK;
956} 868}
957 869
@@ -975,7 +887,8 @@ handle_cadet_pickup_message (void *cls,
975{ 887{
976 struct Channel *ch = *channel_ctx; 888 struct Channel *ch = *channel_ctx;
977 struct Line *line = ch->line; 889 struct Line *line = ch->line;
978 struct ClientPhonePickedupMessage pick; 890 struct GNUNET_MQ_Envelope *env;
891 struct ClientPhonePickedupMessage *pick;
979 892
980 GNUNET_CADET_receive_done (channel); 893 GNUNET_CADET_receive_done (channel);
981 switch (ch->status) 894 switch (ch->status)
@@ -1001,15 +914,13 @@ handle_cadet_pickup_message (void *cls,
1001 mq_done_finish_caller_shutdown (ch); 914 mq_done_finish_caller_shutdown (ch);
1002 return GNUNET_SYSERR; 915 return GNUNET_SYSERR;
1003 } 916 }
1004 pick.header.size = htons (sizeof (pick));
1005 pick.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP);
1006 pick.cid = ch->cid;
1007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1008 "Sending PICKED UP message to client\n"); 918 "Sending PICKED UP message to client\n");
1009 GNUNET_SERVER_notification_context_unicast (nc, 919 env = GNUNET_MQ_msg (pick,
1010 line->client, 920 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP);
1011 &pick.header, 921 pick->cid = ch->cid;
1012 GNUNET_NO); 922 GNUNET_MQ_send (line->mq,
923 env);
1013 return GNUNET_OK; 924 return GNUNET_OK;
1014} 925}
1015 926
@@ -1032,12 +943,10 @@ handle_cadet_suspend_message (void *cls,
1032{ 943{
1033 struct Channel *ch = *channel_ctx; 944 struct Channel *ch = *channel_ctx;
1034 struct Line *line = ch->line; 945 struct Line *line = ch->line;
1035 struct ClientPhoneSuspendMessage suspend; 946 struct GNUNET_MQ_Envelope *env;
947 struct ClientPhoneSuspendMessage *suspend;
1036 948
1037 GNUNET_CADET_receive_done (channel); 949 GNUNET_CADET_receive_done (channel);
1038 suspend.header.size = htons (sizeof (suspend));
1039 suspend.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND);
1040 suspend.cid = ch->cid;
1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1042 "Suspending channel CID: %u\n", 951 "Suspending channel CID: %u\n",
1043 ch->cid); 952 ch->cid);
@@ -1063,10 +972,11 @@ handle_cadet_suspend_message (void *cls,
1063 case CS_CALLER_SHUTDOWN: 972 case CS_CALLER_SHUTDOWN:
1064 return GNUNET_OK; 973 return GNUNET_OK;
1065 } 974 }
1066 GNUNET_SERVER_notification_context_unicast (nc, 975 env = GNUNET_MQ_msg (suspend,
1067 line->client, 976 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND);
1068 &suspend.header, 977 suspend->cid = ch->cid;
1069 GNUNET_NO); 978 GNUNET_MQ_send (line->mq,
979 env);
1070 return GNUNET_OK; 980 return GNUNET_OK;
1071} 981}
1072 982
@@ -1089,7 +999,8 @@ handle_cadet_resume_message (void *cls,
1089{ 999{
1090 struct Channel *ch = *channel_ctx; 1000 struct Channel *ch = *channel_ctx;
1091 struct Line *line; 1001 struct Line *line;
1092 struct ClientPhoneResumeMessage resume; 1002 struct GNUNET_MQ_Envelope *env;
1003 struct ClientPhoneResumeMessage *resume;
1093 1004
1094 if (NULL == ch) 1005 if (NULL == ch)
1095 { 1006 {
@@ -1098,9 +1009,6 @@ handle_cadet_resume_message (void *cls,
1098 return GNUNET_SYSERR; 1009 return GNUNET_SYSERR;
1099 } 1010 }
1100 line = ch->line; 1011 line = ch->line;
1101 resume.header.size = htons (sizeof (resume));
1102 resume.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME);
1103 resume.cid = ch->cid;
1104 GNUNET_CADET_receive_done (channel); 1012 GNUNET_CADET_receive_done (channel);
1105 if (GNUNET_YES != ch->suspended_remote) 1013 if (GNUNET_YES != ch->suspended_remote)
1106 { 1014 {
@@ -1130,10 +1038,11 @@ handle_cadet_resume_message (void *cls,
1130 case CS_CALLER_SHUTDOWN: 1038 case CS_CALLER_SHUTDOWN:
1131 return GNUNET_OK; 1039 return GNUNET_OK;
1132 } 1040 }
1133 GNUNET_SERVER_notification_context_unicast (nc, 1041 env = GNUNET_MQ_msg (resume,
1134 line->client, 1042 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME);
1135 &resume.header, 1043 resume->cid = ch->cid;
1136 GNUNET_NO); 1044 GNUNET_MQ_send (line->mq,
1045 env);
1137 return GNUNET_OK; 1046 return GNUNET_OK;
1138} 1047}
1139 1048
@@ -1157,7 +1066,7 @@ handle_cadet_audio_message (void *cls,
1157 struct Channel *ch = *channel_ctx; 1066 struct Channel *ch = *channel_ctx;
1158 const struct CadetAudioMessage *msg; 1067 const struct CadetAudioMessage *msg;
1159 size_t msize = ntohs (message->size) - sizeof (struct CadetAudioMessage); 1068 size_t msize = ntohs (message->size) - sizeof (struct CadetAudioMessage);
1160 char buf[msize + sizeof (struct ClientAudioMessage)] GNUNET_ALIGN; 1069 struct GNUNET_MQ_Envelope *env;
1161 struct ClientAudioMessage *cam; 1070 struct ClientAudioMessage *cam;
1162 1071
1163 msg = (const struct CadetAudioMessage *) message; 1072 msg = (const struct CadetAudioMessage *) message;
@@ -1175,17 +1084,15 @@ handle_cadet_audio_message (void *cls,
1175 "Forwarding %u bytes of AUDIO data to client CID %u\n", 1084 "Forwarding %u bytes of AUDIO data to client CID %u\n",
1176 (unsigned int) msize, 1085 (unsigned int) msize,
1177 ch->cid); 1086 ch->cid);
1178 cam = (struct ClientAudioMessage *) buf; 1087 env = GNUNET_MQ_msg_extra (cam,
1179 cam->header.size = htons (sizeof (buf)); 1088 msize,
1180 cam->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); 1089 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
1181 cam->cid = ch->cid; 1090 cam->cid = ch->cid;
1182 GNUNET_memcpy (&cam[1], 1091 GNUNET_memcpy (&cam[1],
1183 &msg[1], 1092 &msg[1],
1184 msize); 1093 msize);
1185 GNUNET_SERVER_notification_context_unicast (nc, 1094 GNUNET_MQ_send (ch->line->mq,
1186 ch->line->client, 1095 env);
1187 &cam->header,
1188 GNUNET_YES);
1189 return GNUNET_OK; 1096 return GNUNET_OK;
1190} 1097}
1191 1098
@@ -1244,7 +1151,8 @@ inbound_end (void *cls,
1244{ 1151{
1245 struct Channel *ch = channel_ctx; 1152 struct Channel *ch = channel_ctx;
1246 struct Line *line; 1153 struct Line *line;
1247 struct ClientPhoneHangupMessage hup; 1154 struct GNUNET_MQ_Envelope *env;
1155 struct ClientPhoneHangupMessage *hup;
1248 1156
1249 if (NULL == ch) 1157 if (NULL == ch)
1250 { 1158 {
@@ -1257,32 +1165,24 @@ inbound_end (void *cls,
1257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1258 "Channel destroyed by CADET in state %d\n", 1166 "Channel destroyed by CADET in state %d\n",
1259 ch->status); 1167 ch->status);
1260 hup.header.size = htons (sizeof (hup));
1261 hup.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
1262 hup.cid = ch->cid;
1263 switch (ch->status) 1168 switch (ch->status)
1264 { 1169 {
1265 case CS_CALLEE_INIT: 1170 case CS_CALLEE_INIT:
1171 case CS_CALLEE_SHUTDOWN:
1172 case CS_CALLER_SHUTDOWN:
1266 break; 1173 break;
1267 case CS_CALLEE_RINGING: 1174 case CS_CALLEE_RINGING:
1268 case CS_CALLEE_CONNECTED: 1175 case CS_CALLEE_CONNECTED:
1269 if (NULL != line)
1270 GNUNET_SERVER_notification_context_unicast (nc,
1271 line->client,
1272 &hup.header,
1273 GNUNET_NO);
1274 break;
1275 case CS_CALLEE_SHUTDOWN:
1276 break;
1277 case CS_CALLER_CALLING: 1176 case CS_CALLER_CALLING:
1278 case CS_CALLER_CONNECTED: 1177 case CS_CALLER_CONNECTED:
1279 if (NULL != line) 1178 if (NULL != line)
1280 GNUNET_SERVER_notification_context_unicast (nc, 1179 {
1281 line->client, 1180 env = GNUNET_MQ_msg (hup,
1282 &hup.header, 1181 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
1283 GNUNET_NO); 1182 hup->cid = ch->cid;
1284 break; 1183 GNUNET_MQ_send (line->mq,
1285 case CS_CALLER_SHUTDOWN: 1184 env);
1185 }
1286 break; 1186 break;
1287 } 1187 }
1288 destroy_line_cadet_channels (ch); 1188 destroy_line_cadet_channels (ch);
@@ -1295,27 +1195,43 @@ inbound_end (void *cls,
1295 1195
1296 1196
1297/** 1197/**
1198 * A client connected. Initialize the `struct Line` data structure.
1199 *
1200 * @param cls closure, NULL
1201 * @param client identification of the client
1202 * @param mq message queue for @a client
1203 * @return the `struct Line` for the client
1204 */
1205static void *
1206client_connect_cb (void *cls,
1207 struct GNUNET_SERVICE_Client *client,
1208 struct GNUNET_MQ_Handle *mq)
1209{
1210 struct Line *line;
1211
1212 line = GNUNET_new (struct Line);
1213 line->client = client;
1214 line->mq = mq;
1215 return line;
1216}
1217
1218
1219/**
1298 * A client disconnected. Remove all of its data structure entries. 1220 * A client disconnected. Remove all of its data structure entries.
1299 * 1221 *
1300 * @param cls closure, NULL 1222 * @param cls closure, NULL
1301 * @param client identification of the client 1223 * @param client identification of the client
1224 * @param app_ctx our `struct Line *` for @a client
1302 */ 1225 */
1303static void 1226static void
1304handle_client_disconnect (void *cls, 1227client_disconnect_cb (void *cls,
1305 struct GNUNET_SERVER_Client *client) 1228 struct GNUNET_SERVICE_Client *client,
1229 void *app_ctx)
1306{ 1230{
1307 struct Line *line; 1231 struct Line *line = app_ctx;
1308 struct Channel *ch; 1232 struct Channel *ch;
1309 struct Channel *chn; 1233 struct Channel *chn;
1310 1234
1311 if (NULL == client)
1312 return;
1313 line = GNUNET_SERVER_client_get_user_context (client,
1314 struct Line);
1315 if (NULL == line)
1316 return;
1317 GNUNET_SERVER_client_set_user_context (client,
1318 NULL);
1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1320 "Client disconnected, closing line\n"); 1236 "Client disconnected, closing line\n");
1321 if (NULL != line->port) 1237 if (NULL != line->port)
@@ -1336,41 +1252,21 @@ handle_client_disconnect (void *cls,
1336/** 1252/**
1337 * Function to register a phone. 1253 * Function to register a phone.
1338 * 1254 *
1339 * @param cls closure, NULL 1255 * @param cls the `struct Line` of the client from which the message is
1340 * @param client the client from which the message is 1256 * @param msg the message from the client
1341 * @param message the message from the client
1342 */ 1257 */
1343static void 1258static void
1344handle_client_register_message (void *cls, 1259handle_client_register_message (void *cls,
1345 struct GNUNET_SERVER_Client *client, 1260 const struct ClientPhoneRegisterMessage *msg)
1346 const struct GNUNET_MessageHeader *message)
1347{ 1261{
1348 const struct ClientPhoneRegisterMessage *msg; 1262 struct Line *line = cls;
1349 struct Line *line;
1350 1263
1351 msg = (const struct ClientPhoneRegisterMessage *) message;
1352 line = GNUNET_SERVER_client_get_user_context (client,
1353 struct Line);
1354 if (NULL != line)
1355 {
1356 GNUNET_break (0);
1357 GNUNET_SERVER_receive_done (client,
1358 GNUNET_SYSERR);
1359 return;
1360 }
1361 line = GNUNET_new (struct Line);
1362 line->client = client;
1363 GNUNET_SERVER_notification_context_add (nc,
1364 client);
1365 GNUNET_SERVER_client_set_user_context (client,
1366 line);
1367 line->line_port = msg->line_port; 1264 line->line_port = msg->line_port;
1368 line->port = GNUNET_CADET_open_port (cadet, 1265 line->port = GNUNET_CADET_open_port (cadet,
1369 &msg->line_port, 1266 &msg->line_port,
1370 &inbound_channel, 1267 &inbound_channel,
1371 line); 1268 line);
1372 GNUNET_SERVER_receive_done (client, 1269 GNUNET_SERVICE_client_continue (line->client);
1373 GNUNET_OK);
1374} 1270}
1375 1271
1376 1272
@@ -1387,11 +1283,6 @@ do_shutdown (void *cls)
1387 GNUNET_CADET_disconnect (cadet); 1283 GNUNET_CADET_disconnect (cadet);
1388 cadet = NULL; 1284 cadet = NULL;
1389 } 1285 }
1390 if (NULL != nc)
1391 {
1392 GNUNET_SERVER_notification_context_destroy (nc);
1393 nc = NULL;
1394 }
1395} 1286}
1396 1287
1397 1288
@@ -1399,38 +1290,14 @@ do_shutdown (void *cls)
1399 * Main function that will be run by the scheduler. 1290 * Main function that will be run by the scheduler.
1400 * 1291 *
1401 * @param cls closure 1292 * @param cls closure
1402 * @param server server handle
1403 * @param c configuration 1293 * @param c configuration
1294 * @param service service handle
1404 */ 1295 */
1405static void 1296static void
1406run (void *cls, 1297run (void *cls,
1407 struct GNUNET_SERVER_Handle *server, 1298 const struct GNUNET_CONFIGURATION_Handle *c,
1408 const struct GNUNET_CONFIGURATION_Handle *c) 1299 struct GNUNET_SERVICE_Handle *service)
1409{ 1300{
1410 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
1411 {&handle_client_register_message, NULL,
1412 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER,
1413 sizeof (struct ClientPhoneRegisterMessage)},
1414 {&handle_client_pickup_message, NULL,
1415 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP,
1416 sizeof (struct ClientPhonePickupMessage) },
1417 {&handle_client_suspend_message, NULL,
1418 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND,
1419 sizeof (struct ClientPhoneSuspendMessage) },
1420 {&handle_client_resume_message, NULL,
1421 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME,
1422 sizeof (struct ClientPhoneResumeMessage) },
1423 {&handle_client_hangup_message, NULL,
1424 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
1425 sizeof (struct ClientPhoneHangupMessage) },
1426 {&handle_client_call_message, NULL,
1427 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL,
1428 sizeof (struct ClientCallMessage) },
1429 {&handle_client_audio_message, NULL,
1430 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
1431 0},
1432 {NULL, NULL, 0, 0}
1433 };
1434 static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { 1301 static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
1435 {&handle_cadet_ring_message, 1302 {&handle_cadet_ring_message,
1436 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, 1303 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING,
@@ -1466,34 +1333,51 @@ run (void *cls,
1466 GNUNET_SCHEDULER_shutdown (); 1333 GNUNET_SCHEDULER_shutdown ();
1467 return; 1334 return;
1468 } 1335 }
1469 nc = GNUNET_SERVER_notification_context_create (server,
1470 16);
1471 GNUNET_SERVER_add_handlers (server,
1472 server_handlers);
1473 GNUNET_SERVER_disconnect_notify (server,
1474 &handle_client_disconnect,
1475 NULL);
1476 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 1336 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
1477 NULL); 1337 NULL);
1478} 1338}
1479 1339
1480 1340
1341
1481/** 1342/**
1482 * The main function for the conversation service. 1343 * Define "main" method using service macro.
1483 *
1484 * @param argc number of arguments from the command line
1485 * @param argv command line arguments
1486 * @return 0 ok, 1 on error
1487 */ 1344 */
1488int 1345GNUNET_SERVICE_MAIN
1489main (int argc, 1346("conversation",
1490 char *const *argv) 1347 GNUNET_SERVICE_OPTION_NONE,
1491{ 1348 &run,
1492 return (GNUNET_OK == 1349 &client_connect_cb,
1493 GNUNET_SERVICE_run (argc, argv, 1350 &client_disconnect_cb,
1494 "conversation", 1351 NULL,
1495 GNUNET_SERVICE_OPTION_NONE, 1352 GNUNET_MQ_hd_fixed_size (client_register_message,
1496 &run, NULL)) ? 0 : 1; 1353 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER,
1497} 1354 struct ClientPhoneRegisterMessage,
1355 NULL),
1356 GNUNET_MQ_hd_fixed_size (client_pickup_message,
1357 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP,
1358 struct ClientPhonePickupMessage,
1359 NULL),
1360 GNUNET_MQ_hd_fixed_size (client_suspend_message,
1361 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND,
1362 struct ClientPhoneSuspendMessage,
1363 NULL),
1364 GNUNET_MQ_hd_fixed_size (client_resume_message,
1365 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME,
1366 struct ClientPhoneResumeMessage,
1367 NULL),
1368 GNUNET_MQ_hd_fixed_size (client_hangup_message,
1369 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
1370 struct ClientPhoneHangupMessage,
1371 NULL),
1372 GNUNET_MQ_hd_fixed_size (client_call_message,
1373 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL,
1374 struct ClientCallMessage,
1375 NULL),
1376 GNUNET_MQ_hd_var_size (client_audio_message,
1377 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
1378 struct ClientAudioMessage,
1379 NULL),
1380 GNUNET_MQ_handler_end ());
1381
1498 1382
1499/* end of gnunet-service-conversation.c */ 1383/* end of gnunet-service-conversation.c */