diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-11-14 13:55:12 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-11-14 13:55:12 +0000 |
commit | b7366f3d6a56d38d0269a33039f88de967e8c130 (patch) | |
tree | e299448a28e358c6549670a094b82f247925f7e2 /src | |
parent | 6bde5e0c83d1fd344a26de64172ddce37920bb40 (diff) | |
download | gnunet-b7366f3d6a56d38d0269a33039f88de967e8c130.tar.gz gnunet-b7366f3d6a56d38d0269a33039f88de967e8c130.zip |
Use encrypted MESH by default
Diffstat (limited to 'src')
30 files changed, 1515 insertions, 10455 deletions
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c index 054274e33..8e6e114df 100644 --- a/src/conversation/gnunet-service-conversation.c +++ b/src/conversation/gnunet-service-conversation.c | |||
@@ -86,8 +86,8 @@ enum LineStatus | |||
86 | 86 | ||
87 | 87 | ||
88 | /** | 88 | /** |
89 | * A line connects a local client with a mesh tunnel (or, if it is an | 89 | * A line connects a local client with a mesh channel (or, if it is an |
90 | * open line, is waiting for a mesh tunnel). | 90 | * open line, is waiting for a mesh channel). |
91 | */ | 91 | */ |
92 | struct Line | 92 | struct Line |
93 | { | 93 | { |
@@ -102,14 +102,14 @@ struct Line | |||
102 | struct Line *prev; | 102 | struct Line *prev; |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Handle for the reliable tunnel (contol data) | 105 | * Handle for the reliable channel (contol data) |
106 | */ | 106 | */ |
107 | struct GNUNET_MESH_Tunnel *tunnel_reliable; | 107 | struct GNUNET_MESH_Channel *channel_reliable; |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * Handle for unreliable tunnel (audio data) | 110 | * Handle for unreliable channel (audio data) |
111 | */ | 111 | */ |
112 | struct GNUNET_MESH_Tunnel *tunnel_unreliable; | 112 | struct GNUNET_MESH_Channel *channel_unreliable; |
113 | 113 | ||
114 | /** | 114 | /** |
115 | * Transmit handle for pending audio messages | 115 | * Transmit handle for pending audio messages |
@@ -307,14 +307,14 @@ handle_client_pickup_message (void *cls, | |||
307 | 307 | ||
308 | 308 | ||
309 | /** | 309 | /** |
310 | * Destroy the mesh tunnels of a line. | 310 | * Destroy the mesh channels of a line. |
311 | * | 311 | * |
312 | * @param line line to shutdown tunnels of | 312 | * @param line line to shutdown channels of |
313 | */ | 313 | */ |
314 | static void | 314 | static void |
315 | destroy_line_mesh_tunnels (struct Line *line) | 315 | destroy_line_mesh_channels (struct Line *line) |
316 | { | 316 | { |
317 | struct GNUNET_MESH_Tunnel *t; | 317 | struct GNUNET_MESH_Channel *t; |
318 | 318 | ||
319 | if (NULL != line->reliable_mq) | 319 | if (NULL != line->reliable_mq) |
320 | { | 320 | { |
@@ -326,15 +326,15 @@ destroy_line_mesh_tunnels (struct Line *line) | |||
326 | GNUNET_MESH_notify_transmit_ready_cancel (line->unreliable_mth); | 326 | GNUNET_MESH_notify_transmit_ready_cancel (line->unreliable_mth); |
327 | line->unreliable_mth = NULL; | 327 | line->unreliable_mth = NULL; |
328 | } | 328 | } |
329 | if (NULL != (t = line->tunnel_unreliable)) | 329 | if (NULL != (t = line->channel_unreliable)) |
330 | { | 330 | { |
331 | line->tunnel_unreliable = NULL; | 331 | line->channel_unreliable = NULL; |
332 | GNUNET_MESH_tunnel_destroy (t); | 332 | GNUNET_MESH_channel_destroy (t); |
333 | } | 333 | } |
334 | if (NULL != (t = line->tunnel_reliable)) | 334 | if (NULL != (t = line->channel_reliable)) |
335 | { | 335 | { |
336 | line->tunnel_reliable = NULL; | 336 | line->channel_reliable = NULL; |
337 | GNUNET_MESH_tunnel_destroy (t); | 337 | GNUNET_MESH_channel_destroy (t); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | 340 | ||
@@ -363,7 +363,7 @@ mq_done_finish_caller_shutdown (void *cls) | |||
363 | break; | 363 | break; |
364 | case LS_CALLEE_SHUTDOWN: | 364 | case LS_CALLEE_SHUTDOWN: |
365 | line->status = LS_CALLEE_LISTEN; | 365 | line->status = LS_CALLEE_LISTEN; |
366 | destroy_line_mesh_tunnels (line); | 366 | destroy_line_mesh_channels (line); |
367 | return; | 367 | return; |
368 | case LS_CALLER_CALLING: | 368 | case LS_CALLER_CALLING: |
369 | line->status = LS_CALLER_SHUTDOWN; | 369 | line->status = LS_CALLER_SHUTDOWN; |
@@ -372,7 +372,7 @@ mq_done_finish_caller_shutdown (void *cls) | |||
372 | line->status = LS_CALLER_SHUTDOWN; | 372 | line->status = LS_CALLER_SHUTDOWN; |
373 | break; | 373 | break; |
374 | case LS_CALLER_SHUTDOWN: | 374 | case LS_CALLER_SHUTDOWN: |
375 | destroy_line_mesh_tunnels (line); | 375 | destroy_line_mesh_channels (line); |
376 | break; | 376 | break; |
377 | } | 377 | } |
378 | } | 378 | } |
@@ -490,13 +490,13 @@ handle_client_call_message (void *cls, | |||
490 | line); | 490 | line); |
491 | line->remote_line = ntohl (msg->line); | 491 | line->remote_line = ntohl (msg->line); |
492 | line->status = LS_CALLER_CALLING; | 492 | line->status = LS_CALLER_CALLING; |
493 | line->tunnel_reliable = GNUNET_MESH_tunnel_create (mesh, | 493 | line->channel_reliable = GNUNET_MESH_channel_create (mesh, |
494 | line, | 494 | line, |
495 | &msg->target, | 495 | &msg->target, |
496 | GNUNET_APPLICATION_TYPE_CONVERSATION_CONTROL, | 496 | GNUNET_APPLICATION_TYPE_CONVERSATION_CONTROL, |
497 | GNUNET_NO, | 497 | GNUNET_NO, |
498 | GNUNET_YES); | 498 | GNUNET_YES); |
499 | line->reliable_mq = GNUNET_MESH_mq_create (line->tunnel_reliable); | 499 | line->reliable_mq = GNUNET_MESH_mq_create (line->channel_reliable); |
500 | line->local_line = local_line_cnt++; | 500 | line->local_line = local_line_cnt++; |
501 | e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_RING); | 501 | e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_RING); |
502 | ring->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); | 502 | ring->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); |
@@ -606,7 +606,7 @@ handle_client_audio_message (void *cls, | |||
606 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 606 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
607 | return; | 607 | return; |
608 | } | 608 | } |
609 | if (NULL == line->tunnel_unreliable) | 609 | if (NULL == line->channel_unreliable) |
610 | { | 610 | { |
611 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 611 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
612 | _("Mesh audio channel not ready; audio data dropped\n")); | 612 | _("Mesh audio channel not ready; audio data dropped\n")); |
@@ -629,7 +629,7 @@ handle_client_audio_message (void *cls, | |||
629 | memcpy (line->audio_data, | 629 | memcpy (line->audio_data, |
630 | &msg[1], | 630 | &msg[1], |
631 | size); | 631 | size); |
632 | line->unreliable_mth = GNUNET_MESH_notify_transmit_ready (line->tunnel_unreliable, | 632 | line->unreliable_mth = GNUNET_MESH_notify_transmit_ready (line->channel_unreliable, |
633 | GNUNET_NO, | 633 | GNUNET_NO, |
634 | GNUNET_TIME_UNIT_FOREVER_REL, | 634 | GNUNET_TIME_UNIT_FOREVER_REL, |
635 | sizeof (struct MeshAudioMessage) | 635 | sizeof (struct MeshAudioMessage) |
@@ -642,16 +642,16 @@ handle_client_audio_message (void *cls, | |||
642 | 642 | ||
643 | /** | 643 | /** |
644 | * We are done signalling shutdown to the other peer. | 644 | * We are done signalling shutdown to the other peer. |
645 | * Destroy the tunnel. | 645 | * Destroy the channel. |
646 | * | 646 | * |
647 | * @param cls the `struct GNUNET_MESH_tunnel` to destroy | 647 | * @param cls the `struct GNUNET_MESH_channel` to destroy |
648 | */ | 648 | */ |
649 | static void | 649 | static void |
650 | mq_done_destroy_tunnel (void *cls) | 650 | mq_done_destroy_channel (void *cls) |
651 | { | 651 | { |
652 | struct GNUNET_MESH_Tunnel *tunnel = cls; | 652 | struct GNUNET_MESH_Channel *channel = cls; |
653 | 653 | ||
654 | GNUNET_MESH_tunnel_destroy (tunnel); | 654 | GNUNET_MESH_channel_destroy (channel); |
655 | } | 655 | } |
656 | 656 | ||
657 | 657 | ||
@@ -659,15 +659,15 @@ mq_done_destroy_tunnel (void *cls) | |||
659 | * Function to handle a ring message incoming over mesh | 659 | * Function to handle a ring message incoming over mesh |
660 | * | 660 | * |
661 | * @param cls closure, NULL | 661 | * @param cls closure, NULL |
662 | * @param tunnel the tunnel over which the message arrived | 662 | * @param channel the channel over which the message arrived |
663 | * @param tunnel_ctx the tunnel context, can be NULL | 663 | * @param channel_ctx the channel context, can be NULL |
664 | * @param message the incoming message | 664 | * @param message the incoming message |
665 | * @return #GNUNET_OK | 665 | * @return #GNUNET_OK |
666 | */ | 666 | */ |
667 | static int | 667 | static int |
668 | handle_mesh_ring_message (void *cls, | 668 | handle_mesh_ring_message (void *cls, |
669 | struct GNUNET_MESH_Tunnel *tunnel, | 669 | struct GNUNET_MESH_Channel *channel, |
670 | void **tunnel_ctx, | 670 | void **channel_ctx, |
671 | const struct GNUNET_MessageHeader *message) | 671 | const struct GNUNET_MessageHeader *message) |
672 | { | 672 | { |
673 | const struct MeshPhoneRingMessage *msg; | 673 | const struct MeshPhoneRingMessage *msg; |
@@ -701,17 +701,17 @@ handle_mesh_ring_message (void *cls, | |||
701 | ntohl (msg->remote_line)); | 701 | ntohl (msg->remote_line)); |
702 | e = GNUNET_MQ_msg (busy, GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_BUSY); | 702 | e = GNUNET_MQ_msg (busy, GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_PHONE_BUSY); |
703 | GNUNET_MQ_notify_sent (e, | 703 | GNUNET_MQ_notify_sent (e, |
704 | &mq_done_destroy_tunnel, | 704 | &mq_done_destroy_channel, |
705 | tunnel); | 705 | channel); |
706 | GNUNET_MQ_send (line->reliable_mq, e); | 706 | GNUNET_MQ_send (line->reliable_mq, e); |
707 | GNUNET_MESH_receive_done (tunnel); /* needed? */ | 707 | GNUNET_MESH_receive_done (channel); /* needed? */ |
708 | return GNUNET_OK; | 708 | return GNUNET_OK; |
709 | } | 709 | } |
710 | line->status = LS_CALLEE_RINGING; | 710 | line->status = LS_CALLEE_RINGING; |
711 | line->remote_line = ntohl (msg->source_line); | 711 | line->remote_line = ntohl (msg->source_line); |
712 | line->tunnel_reliable = tunnel; | 712 | line->channel_reliable = channel; |
713 | line->reliable_mq = GNUNET_MESH_mq_create (line->tunnel_reliable); | 713 | line->reliable_mq = GNUNET_MESH_mq_create (line->channel_reliable); |
714 | *tunnel_ctx = line; | 714 | *channel_ctx = line; |
715 | cring.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); | 715 | cring.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); |
716 | cring.header.size = htons (sizeof (cring)); | 716 | cring.header.size = htons (sizeof (cring)); |
717 | cring.reserved = htonl (0); | 717 | cring.reserved = htonl (0); |
@@ -722,7 +722,7 @@ handle_mesh_ring_message (void *cls, | |||
722 | line->client, | 722 | line->client, |
723 | &cring.header, | 723 | &cring.header, |
724 | GNUNET_NO); | 724 | GNUNET_NO); |
725 | GNUNET_MESH_receive_done (tunnel); | 725 | GNUNET_MESH_receive_done (channel); |
726 | return GNUNET_OK; | 726 | return GNUNET_OK; |
727 | } | 727 | } |
728 | 728 | ||
@@ -731,18 +731,18 @@ handle_mesh_ring_message (void *cls, | |||
731 | * Function to handle a hangup message incoming over mesh | 731 | * Function to handle a hangup message incoming over mesh |
732 | * | 732 | * |
733 | * @param cls closure, NULL | 733 | * @param cls closure, NULL |
734 | * @param tunnel the tunnel over which the message arrived | 734 | * @param channel the channel over which the message arrived |
735 | * @param tunnel_ctx the tunnel context, can be NULL | 735 | * @param channel_ctx the channel context, can be NULL |
736 | * @param message the incoming message | 736 | * @param message the incoming message |
737 | * @return #GNUNET_OK | 737 | * @return #GNUNET_OK |
738 | */ | 738 | */ |
739 | static int | 739 | static int |
740 | handle_mesh_hangup_message (void *cls, | 740 | handle_mesh_hangup_message (void *cls, |
741 | struct GNUNET_MESH_Tunnel *tunnel, | 741 | struct GNUNET_MESH_Channel *channel, |
742 | void **tunnel_ctx, | 742 | void **channel_ctx, |
743 | const struct GNUNET_MessageHeader *message) | 743 | const struct GNUNET_MessageHeader *message) |
744 | { | 744 | { |
745 | struct Line *line = *tunnel_ctx; | 745 | struct Line *line = *channel_ctx; |
746 | const struct MeshPhoneHangupMessage *msg; | 746 | const struct MeshPhoneHangupMessage *msg; |
747 | const char *reason; | 747 | const char *reason; |
748 | size_t len = ntohs (message->size) - sizeof (struct MeshPhoneHangupMessage); | 748 | size_t len = ntohs (message->size) - sizeof (struct MeshPhoneHangupMessage); |
@@ -761,10 +761,10 @@ handle_mesh_hangup_message (void *cls, | |||
761 | if (NULL == line) | 761 | if (NULL == line) |
762 | { | 762 | { |
763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
764 | "HANGUP message received for non-existing line, dropping tunnel.\n"); | 764 | "HANGUP message received for non-existing line, dropping channel.\n"); |
765 | return GNUNET_SYSERR; | 765 | return GNUNET_SYSERR; |
766 | } | 766 | } |
767 | *tunnel_ctx = NULL; | 767 | *channel_ctx = NULL; |
768 | switch (line->status) | 768 | switch (line->status) |
769 | { | 769 | { |
770 | case LS_CALLEE_LISTEN: | 770 | case LS_CALLEE_LISTEN: |
@@ -772,15 +772,15 @@ handle_mesh_hangup_message (void *cls, | |||
772 | return GNUNET_SYSERR; | 772 | return GNUNET_SYSERR; |
773 | case LS_CALLEE_RINGING: | 773 | case LS_CALLEE_RINGING: |
774 | line->status = LS_CALLEE_LISTEN; | 774 | line->status = LS_CALLEE_LISTEN; |
775 | destroy_line_mesh_tunnels (line); | 775 | destroy_line_mesh_channels (line); |
776 | break; | 776 | break; |
777 | case LS_CALLEE_CONNECTED: | 777 | case LS_CALLEE_CONNECTED: |
778 | line->status = LS_CALLEE_LISTEN; | 778 | line->status = LS_CALLEE_LISTEN; |
779 | destroy_line_mesh_tunnels (line); | 779 | destroy_line_mesh_channels (line); |
780 | break; | 780 | break; |
781 | case LS_CALLEE_SHUTDOWN: | 781 | case LS_CALLEE_SHUTDOWN: |
782 | line->status = LS_CALLEE_LISTEN; | 782 | line->status = LS_CALLEE_LISTEN; |
783 | destroy_line_mesh_tunnels (line); | 783 | destroy_line_mesh_channels (line); |
784 | return GNUNET_OK; | 784 | return GNUNET_OK; |
785 | case LS_CALLER_CALLING: | 785 | case LS_CALLER_CALLING: |
786 | line->status = LS_CALLER_SHUTDOWN; | 786 | line->status = LS_CALLER_SHUTDOWN; |
@@ -805,7 +805,7 @@ handle_mesh_hangup_message (void *cls, | |||
805 | line->client, | 805 | line->client, |
806 | &hup->header, | 806 | &hup->header, |
807 | GNUNET_NO); | 807 | GNUNET_NO); |
808 | GNUNET_MESH_receive_done (tunnel); | 808 | GNUNET_MESH_receive_done (channel); |
809 | return GNUNET_OK; | 809 | return GNUNET_OK; |
810 | } | 810 | } |
811 | 811 | ||
@@ -814,19 +814,19 @@ handle_mesh_hangup_message (void *cls, | |||
814 | * Function to handle a pickup message incoming over mesh | 814 | * Function to handle a pickup message incoming over mesh |
815 | * | 815 | * |
816 | * @param cls closure, NULL | 816 | * @param cls closure, NULL |
817 | * @param tunnel the tunnel over which the message arrived | 817 | * @param channel the channel over which the message arrived |
818 | * @param tunnel_ctx the tunnel context, can be NULL | 818 | * @param channel_ctx the channel context, can be NULL |
819 | * @param message the incoming message | 819 | * @param message the incoming message |
820 | * @return #GNUNET_OK | 820 | * @return #GNUNET_OK |
821 | */ | 821 | */ |
822 | static int | 822 | static int |
823 | handle_mesh_pickup_message (void *cls, | 823 | handle_mesh_pickup_message (void *cls, |
824 | struct GNUNET_MESH_Tunnel *tunnel, | 824 | struct GNUNET_MESH_Channel *channel, |
825 | void **tunnel_ctx, | 825 | void **channel_ctx, |
826 | const struct GNUNET_MessageHeader *message) | 826 | const struct GNUNET_MessageHeader *message) |
827 | { | 827 | { |
828 | const struct MeshPhonePickupMessage *msg; | 828 | const struct MeshPhonePickupMessage *msg; |
829 | struct Line *line = *tunnel_ctx; | 829 | struct Line *line = *channel_ctx; |
830 | const char *metadata; | 830 | const char *metadata; |
831 | size_t len = ntohs (message->size) - sizeof (struct MeshPhonePickupMessage); | 831 | size_t len = ntohs (message->size) - sizeof (struct MeshPhonePickupMessage); |
832 | char buf[len + sizeof (struct ClientPhonePickupMessage)]; | 832 | char buf[len + sizeof (struct ClientPhonePickupMessage)]; |
@@ -844,10 +844,10 @@ handle_mesh_pickup_message (void *cls, | |||
844 | if (NULL == line) | 844 | if (NULL == line) |
845 | { | 845 | { |
846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
847 | "PICKUP message received for non-existing line, dropping tunnel.\n"); | 847 | "PICKUP message received for non-existing line, dropping channel.\n"); |
848 | return GNUNET_SYSERR; | 848 | return GNUNET_SYSERR; |
849 | } | 849 | } |
850 | GNUNET_MESH_receive_done (tunnel); | 850 | GNUNET_MESH_receive_done (channel); |
851 | switch (line->status) | 851 | switch (line->status) |
852 | { | 852 | { |
853 | case LS_CALLEE_LISTEN: | 853 | case LS_CALLEE_LISTEN: |
@@ -856,13 +856,13 @@ handle_mesh_pickup_message (void *cls, | |||
856 | case LS_CALLEE_RINGING: | 856 | case LS_CALLEE_RINGING: |
857 | case LS_CALLEE_CONNECTED: | 857 | case LS_CALLEE_CONNECTED: |
858 | GNUNET_break_op (0); | 858 | GNUNET_break_op (0); |
859 | destroy_line_mesh_tunnels (line); | 859 | destroy_line_mesh_channels (line); |
860 | line->status = LS_CALLEE_LISTEN; | 860 | line->status = LS_CALLEE_LISTEN; |
861 | return GNUNET_SYSERR; | 861 | return GNUNET_SYSERR; |
862 | case LS_CALLEE_SHUTDOWN: | 862 | case LS_CALLEE_SHUTDOWN: |
863 | GNUNET_break_op (0); | 863 | GNUNET_break_op (0); |
864 | line->status = LS_CALLEE_LISTEN; | 864 | line->status = LS_CALLEE_LISTEN; |
865 | destroy_line_mesh_tunnels (line); | 865 | destroy_line_mesh_channels (line); |
866 | break; | 866 | break; |
867 | case LS_CALLER_CALLING: | 867 | case LS_CALLER_CALLING: |
868 | line->status = LS_CALLER_CONNECTED; | 868 | line->status = LS_CALLER_CONNECTED; |
@@ -886,13 +886,13 @@ handle_mesh_pickup_message (void *cls, | |||
886 | line->client, | 886 | line->client, |
887 | &pick->header, | 887 | &pick->header, |
888 | GNUNET_NO); | 888 | GNUNET_NO); |
889 | line->tunnel_unreliable = GNUNET_MESH_tunnel_create (mesh, | 889 | line->channel_unreliable = GNUNET_MESH_channel_create (mesh, |
890 | line, | 890 | line, |
891 | &line->target, | 891 | &line->target, |
892 | GNUNET_APPLICATION_TYPE_CONVERSATION_AUDIO, | 892 | GNUNET_APPLICATION_TYPE_CONVERSATION_AUDIO, |
893 | GNUNET_YES, | 893 | GNUNET_YES, |
894 | GNUNET_NO); | 894 | GNUNET_NO); |
895 | if (NULL == line->tunnel_unreliable) | 895 | if (NULL == line->channel_unreliable) |
896 | { | 896 | { |
897 | GNUNET_break (0); | 897 | GNUNET_break (0); |
898 | } | 898 | } |
@@ -904,30 +904,30 @@ handle_mesh_pickup_message (void *cls, | |||
904 | * Function to handle a busy message incoming over mesh | 904 | * Function to handle a busy message incoming over mesh |
905 | * | 905 | * |
906 | * @param cls closure, NULL | 906 | * @param cls closure, NULL |
907 | * @param tunnel the tunnel over which the message arrived | 907 | * @param channel the channel over which the message arrived |
908 | * @param tunnel_ctx the tunnel context, can be NULL | 908 | * @param channel_ctx the channel context, can be NULL |
909 | * @param message the incoming message | 909 | * @param message the incoming message |
910 | * @return #GNUNET_OK | 910 | * @return #GNUNET_OK |
911 | */ | 911 | */ |
912 | static int | 912 | static int |
913 | handle_mesh_busy_message (void *cls, | 913 | handle_mesh_busy_message (void *cls, |
914 | struct GNUNET_MESH_Tunnel *tunnel, | 914 | struct GNUNET_MESH_Channel *channel, |
915 | void **tunnel_ctx, | 915 | void **channel_ctx, |
916 | const struct GNUNET_MessageHeader *message) | 916 | const struct GNUNET_MessageHeader *message) |
917 | { | 917 | { |
918 | struct Line *line = *tunnel_ctx; | 918 | struct Line *line = *channel_ctx; |
919 | struct ClientPhoneBusyMessage busy; | 919 | struct ClientPhoneBusyMessage busy; |
920 | 920 | ||
921 | if (NULL == line) | 921 | if (NULL == line) |
922 | { | 922 | { |
923 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 923 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
924 | "HANGUP message received for non-existing line, dropping tunnel.\n"); | 924 | "HANGUP message received for non-existing line, dropping channel.\n"); |
925 | return GNUNET_SYSERR; | 925 | return GNUNET_SYSERR; |
926 | } | 926 | } |
927 | busy.header.size = sizeof (busy); | 927 | busy.header.size = sizeof (busy); |
928 | busy.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_BUSY); | 928 | busy.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_BUSY); |
929 | GNUNET_MESH_receive_done (tunnel); | 929 | GNUNET_MESH_receive_done (channel); |
930 | *tunnel_ctx = NULL; | 930 | *channel_ctx = NULL; |
931 | switch (line->status) | 931 | switch (line->status) |
932 | { | 932 | { |
933 | case LS_CALLEE_LISTEN: | 933 | case LS_CALLEE_LISTEN: |
@@ -970,43 +970,43 @@ handle_mesh_busy_message (void *cls, | |||
970 | * Function to handle an audio message incoming over mesh | 970 | * Function to handle an audio message incoming over mesh |
971 | * | 971 | * |
972 | * @param cls closure, NULL | 972 | * @param cls closure, NULL |
973 | * @param tunnel the tunnel over which the message arrived | 973 | * @param channel the channel over which the message arrived |
974 | * @param tunnel_ctx the tunnel context, can be NULL | 974 | * @param channel_ctx the channel context, can be NULL |
975 | * @param message the incoming message | 975 | * @param message the incoming message |
976 | * @return #GNUNET_OK | 976 | * @return #GNUNET_OK |
977 | */ | 977 | */ |
978 | static int | 978 | static int |
979 | handle_mesh_audio_message (void *cls, | 979 | handle_mesh_audio_message (void *cls, |
980 | struct GNUNET_MESH_Tunnel *tunnel, | 980 | struct GNUNET_MESH_Channel *channel, |
981 | void **tunnel_ctx, | 981 | void **channel_ctx, |
982 | const struct GNUNET_MessageHeader *message) | 982 | const struct GNUNET_MessageHeader *message) |
983 | { | 983 | { |
984 | const struct MeshAudioMessage *msg; | 984 | const struct MeshAudioMessage *msg; |
985 | struct Line *line = *tunnel_ctx; | 985 | struct Line *line = *channel_ctx; |
986 | struct GNUNET_PeerIdentity sender; | 986 | struct GNUNET_PeerIdentity sender; |
987 | size_t msize = ntohs (message->size) - sizeof (struct MeshAudioMessage); | 987 | size_t msize = ntohs (message->size) - sizeof (struct MeshAudioMessage); |
988 | char buf[msize + sizeof (struct ClientAudioMessage)]; | 988 | char buf[msize + sizeof (struct ClientAudioMessage)]; |
989 | struct ClientAudioMessage *cam; | 989 | struct ClientAudioMessage *cam; |
990 | const union GNUNET_MESH_TunnelInfo *info; | 990 | const union GNUNET_MESH_ChannelInfo *info; |
991 | 991 | ||
992 | msg = (const struct MeshAudioMessage *) message; | 992 | msg = (const struct MeshAudioMessage *) message; |
993 | if (NULL == line) | 993 | if (NULL == line) |
994 | { | 994 | { |
995 | info = GNUNET_MESH_tunnel_get_info (tunnel, | 995 | info = GNUNET_MESH_channel_get_info (channel, |
996 | GNUNET_MESH_OPTION_PEER); | 996 | GNUNET_MESH_OPTION_PEER); |
997 | if (NULL == info) | 997 | if (NULL == info) |
998 | { | 998 | { |
999 | GNUNET_break (0); | 999 | GNUNET_break (0); |
1000 | return GNUNET_OK; | 1000 | return GNUNET_OK; |
1001 | } | 1001 | } |
1002 | sender = info->peer; | 1002 | sender = *(info->peer); |
1003 | for (line = lines_head; NULL != line; line = line->next) | 1003 | for (line = lines_head; NULL != line; line = line->next) |
1004 | if ( (line->local_line == ntohl (msg->remote_line)) && | 1004 | if ( (line->local_line == ntohl (msg->remote_line)) && |
1005 | (LS_CALLEE_CONNECTED == line->status) && | 1005 | (LS_CALLEE_CONNECTED == line->status) && |
1006 | (0 == memcmp (&line->target, | 1006 | (0 == memcmp (&line->target, |
1007 | &sender, | 1007 | &sender, |
1008 | sizeof (struct GNUNET_PeerIdentity))) && | 1008 | sizeof (struct GNUNET_PeerIdentity))) && |
1009 | (NULL == line->tunnel_unreliable) ) | 1009 | (NULL == line->channel_unreliable) ) |
1010 | break; | 1010 | break; |
1011 | if (NULL == line) | 1011 | if (NULL == line) |
1012 | { | 1012 | { |
@@ -1015,8 +1015,8 @@ handle_mesh_audio_message (void *cls, | |||
1015 | ntohl (msg->remote_line)); | 1015 | ntohl (msg->remote_line)); |
1016 | return GNUNET_SYSERR; | 1016 | return GNUNET_SYSERR; |
1017 | } | 1017 | } |
1018 | line->tunnel_unreliable = tunnel; | 1018 | line->channel_unreliable = channel; |
1019 | *tunnel_ctx = line; | 1019 | *channel_ctx = line; |
1020 | } | 1020 | } |
1021 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1021 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1022 | "Forwarding %u bytes of AUDIO data to client\n", | 1022 | "Forwarding %u bytes of AUDIO data to client\n", |
@@ -1029,69 +1029,69 @@ handle_mesh_audio_message (void *cls, | |||
1029 | line->client, | 1029 | line->client, |
1030 | &cam->header, | 1030 | &cam->header, |
1031 | GNUNET_YES); | 1031 | GNUNET_YES); |
1032 | GNUNET_MESH_receive_done (tunnel); | 1032 | GNUNET_MESH_receive_done (channel); |
1033 | return GNUNET_OK; | 1033 | return GNUNET_OK; |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | 1036 | ||
1037 | /** | 1037 | /** |
1038 | * Method called whenever another peer has added us to a tunnel | 1038 | * Method called whenever another peer has added us to a channel |
1039 | * the other peer initiated. | 1039 | * the other peer initiated. |
1040 | * | 1040 | * |
1041 | * @param cls closure | 1041 | * @param cls closure |
1042 | * @param tunnel new handle to the tunnel | 1042 | * @param channel new handle to the channel |
1043 | * @param initiator peer that started the tunnel | 1043 | * @param initiator peer that started the channel |
1044 | * @param port port | 1044 | * @param port port |
1045 | * @return initial tunnel context for the tunnel (can be NULL -- that's not an error) | 1045 | * @return initial channel context for the channel (can be NULL -- that's not an error) |
1046 | */ | 1046 | */ |
1047 | static void * | 1047 | static void * |
1048 | inbound_tunnel (void *cls, | 1048 | inbound_channel (void *cls, |
1049 | struct GNUNET_MESH_Tunnel *tunnel, | 1049 | struct GNUNET_MESH_Channel *channel, |
1050 | const struct GNUNET_PeerIdentity *initiator, | 1050 | const struct GNUNET_PeerIdentity *initiator, |
1051 | uint32_t port) | 1051 | uint32_t port) |
1052 | { | 1052 | { |
1053 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1053 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1054 | _("Received incoming tunnel on port %u\n"), | 1054 | _("Received incoming channel on port %u\n"), |
1055 | (unsigned int) port); | 1055 | (unsigned int) port); |
1056 | return NULL; | 1056 | return NULL; |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | 1059 | ||
1060 | /** | 1060 | /** |
1061 | * Function called whenever an inbound tunnel is destroyed. Should clean up | 1061 | * Function called whenever an inbound channel is destroyed. Should clean up |
1062 | * any associated state. | 1062 | * any associated state. |
1063 | * | 1063 | * |
1064 | * @param cls closure (set from #GNUNET_MESH_connect) | 1064 | * @param cls closure (set from #GNUNET_MESH_connect) |
1065 | * @param tunnel connection to the other end (henceforth invalid) | 1065 | * @param channel connection to the other end (henceforth invalid) |
1066 | * @param tunnel_ctx place where local state associated | 1066 | * @param channel_ctx place where local state associated |
1067 | * with the tunnel is stored | 1067 | * with the channel is stored |
1068 | */ | 1068 | */ |
1069 | static void | 1069 | static void |
1070 | inbound_end (void *cls, | 1070 | inbound_end (void *cls, |
1071 | const struct GNUNET_MESH_Tunnel *tunnel, | 1071 | const struct GNUNET_MESH_Channel *channel, |
1072 | void *tunnel_ctx) | 1072 | void *channel_ctx) |
1073 | { | 1073 | { |
1074 | struct Line *line = tunnel_ctx; | 1074 | struct Line *line = channel_ctx; |
1075 | struct ClientPhoneHangupMessage hup; | 1075 | struct ClientPhoneHangupMessage hup; |
1076 | 1076 | ||
1077 | if (NULL == line) | 1077 | if (NULL == line) |
1078 | return; | 1078 | return; |
1079 | if (line->tunnel_unreliable == tunnel) | 1079 | if (line->channel_unreliable == channel) |
1080 | { | 1080 | { |
1081 | if (NULL != line->unreliable_mth) | 1081 | if (NULL != line->unreliable_mth) |
1082 | { | 1082 | { |
1083 | GNUNET_MESH_notify_transmit_ready_cancel (line->unreliable_mth); | 1083 | GNUNET_MESH_notify_transmit_ready_cancel (line->unreliable_mth); |
1084 | line->unreliable_mth = NULL; | 1084 | line->unreliable_mth = NULL; |
1085 | } | 1085 | } |
1086 | line->tunnel_unreliable = NULL; | 1086 | line->channel_unreliable = NULL; |
1087 | return; | 1087 | return; |
1088 | } | 1088 | } |
1089 | if (line->tunnel_reliable != tunnel) | 1089 | if (line->channel_reliable != channel) |
1090 | return; | 1090 | return; |
1091 | line->tunnel_reliable = NULL; | 1091 | line->channel_reliable = NULL; |
1092 | 1092 | ||
1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1094 | "Mesh tunnel destroyed by mesh\n"); | 1094 | "Mesh channel destroyed by mesh\n"); |
1095 | hup.header.size = sizeof (hup); | 1095 | hup.header.size = sizeof (hup); |
1096 | hup.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | 1096 | hup.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); |
1097 | switch (line->status) | 1097 | switch (line->status) |
@@ -1120,7 +1120,7 @@ inbound_end (void *cls, | |||
1120 | case LS_CALLER_SHUTDOWN: | 1120 | case LS_CALLER_SHUTDOWN: |
1121 | break; | 1121 | break; |
1122 | } | 1122 | } |
1123 | destroy_line_mesh_tunnels (line); | 1123 | destroy_line_mesh_channels (line); |
1124 | } | 1124 | } |
1125 | 1125 | ||
1126 | 1126 | ||
@@ -1147,7 +1147,7 @@ handle_client_disconnect (void *cls, | |||
1147 | GNUNET_CONTAINER_DLL_remove (lines_head, | 1147 | GNUNET_CONTAINER_DLL_remove (lines_head, |
1148 | lines_tail, | 1148 | lines_tail, |
1149 | line); | 1149 | line); |
1150 | destroy_line_mesh_tunnels (line); | 1150 | destroy_line_mesh_channels (line); |
1151 | GNUNET_free_non_null (line->audio_data); | 1151 | GNUNET_free_non_null (line->audio_data); |
1152 | GNUNET_free (line); | 1152 | GNUNET_free (line); |
1153 | } | 1153 | } |
@@ -1235,7 +1235,7 @@ run (void *cls, | |||
1235 | &my_identity)); | 1235 | &my_identity)); |
1236 | mesh = GNUNET_MESH_connect (cfg, | 1236 | mesh = GNUNET_MESH_connect (cfg, |
1237 | NULL, | 1237 | NULL, |
1238 | &inbound_tunnel, | 1238 | &inbound_channel, |
1239 | &inbound_end, | 1239 | &inbound_end, |
1240 | mesh_handlers, | 1240 | mesh_handlers, |
1241 | ports); | 1241 | ports); |
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index 2de707133..819e4f4b6 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c | |||
@@ -184,22 +184,22 @@ struct RedirectInformation | |||
184 | 184 | ||
185 | 185 | ||
186 | /** | 186 | /** |
187 | * Queue of messages to a tunnel. | 187 | * Queue of messages to a channel. |
188 | */ | 188 | */ |
189 | struct TunnelMessageQueue | 189 | struct ChannelMessageQueue |
190 | { | 190 | { |
191 | /** | 191 | /** |
192 | * This is a doubly-linked list. | 192 | * This is a doubly-linked list. |
193 | */ | 193 | */ |
194 | struct TunnelMessageQueue *next; | 194 | struct ChannelMessageQueue *next; |
195 | 195 | ||
196 | /** | 196 | /** |
197 | * This is a doubly-linked list. | 197 | * This is a doubly-linked list. |
198 | */ | 198 | */ |
199 | struct TunnelMessageQueue *prev; | 199 | struct ChannelMessageQueue *prev; |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * Payload to send via the tunnel. | 202 | * Payload to send via the channel. |
203 | */ | 203 | */ |
204 | const void *payload; | 204 | const void *payload; |
205 | 205 | ||
@@ -212,32 +212,32 @@ struct TunnelMessageQueue | |||
212 | 212 | ||
213 | /** | 213 | /** |
214 | * This struct is saved into connections_map to allow finding the | 214 | * This struct is saved into connections_map to allow finding the |
215 | * right tunnel given an IP packet from TUN. It is also associated | 215 | * right channel given an IP packet from TUN. It is also associated |
216 | * with the tunnel's closure so we can find it again for the next | 216 | * with the channel's closure so we can find it again for the next |
217 | * message from the tunnel. | 217 | * message from the channel. |
218 | */ | 218 | */ |
219 | struct TunnelState | 219 | struct ChannelState |
220 | { | 220 | { |
221 | /** | 221 | /** |
222 | * Mesh tunnel that is used for this connection. | 222 | * Mesh channel that is used for this connection. |
223 | */ | 223 | */ |
224 | struct GNUNET_MESH_Tunnel *tunnel; | 224 | struct GNUNET_MESH_Channel *channel; |
225 | 225 | ||
226 | /** | 226 | /** |
227 | * Who is the other end of this tunnel. | 227 | * Who is the other end of this channel. |
228 | * FIXME is this needed? Only used for debugging messages | 228 | * FIXME is this needed? Only used for debugging messages |
229 | */ | 229 | */ |
230 | struct GNUNET_PeerIdentity peer; | 230 | struct GNUNET_PeerIdentity peer; |
231 | 231 | ||
232 | /** | 232 | /** |
233 | * Active tunnel transmission request (or NULL). | 233 | * Active channel transmission request (or NULL). |
234 | */ | 234 | */ |
235 | struct GNUNET_MESH_TransmitHandle *th; | 235 | struct GNUNET_MESH_TransmitHandle *th; |
236 | 236 | ||
237 | /** | 237 | /** |
238 | * #GNUNET_NO if this is a tunnel for TCP/UDP, | 238 | * #GNUNET_NO if this is a channel for TCP/UDP, |
239 | * #GNUNET_YES if this is a tunnel for DNS, | 239 | * #GNUNET_YES if this is a channel for DNS, |
240 | * #GNUNET_SYSERR if the tunnel is not yet initialized. | 240 | * #GNUNET_SYSERR if the channel is not yet initialized. |
241 | */ | 241 | */ |
242 | int is_dns; | 242 | int is_dns; |
243 | 243 | ||
@@ -262,14 +262,14 @@ struct TunnelState | |||
262 | struct LocalService *serv; | 262 | struct LocalService *serv; |
263 | 263 | ||
264 | /** | 264 | /** |
265 | * Head of DLL of messages for this tunnel. | 265 | * Head of DLL of messages for this channel. |
266 | */ | 266 | */ |
267 | struct TunnelMessageQueue *head; | 267 | struct ChannelMessageQueue *head; |
268 | 268 | ||
269 | /** | 269 | /** |
270 | * Tail of DLL of messages for this tunnel. | 270 | * Tail of DLL of messages for this channel. |
271 | */ | 271 | */ |
272 | struct TunnelMessageQueue *tail; | 272 | struct ChannelMessageQueue *tail; |
273 | 273 | ||
274 | /** | 274 | /** |
275 | * Primary redirection information for this connection. | 275 | * Primary redirection information for this connection. |
@@ -375,7 +375,7 @@ static struct GNUNET_MESH_Handle *mesh_handle; | |||
375 | 375 | ||
376 | /** | 376 | /** |
377 | * This hashmaps contains the mapping from peer, service-descriptor, | 377 | * This hashmaps contains the mapping from peer, service-descriptor, |
378 | * source-port and destination-port to a struct TunnelState | 378 | * source-port and destination-port to a struct ChannelState |
379 | */ | 379 | */ |
380 | static struct GNUNET_CONTAINER_MultiHashMap *connections_map; | 380 | static struct GNUNET_CONTAINER_MultiHashMap *connections_map; |
381 | 381 | ||
@@ -400,9 +400,9 @@ static struct GNUNET_CONTAINER_MultiHashMap *udp_services; | |||
400 | static struct GNUNET_CONTAINER_MultiHashMap *tcp_services; | 400 | static struct GNUNET_CONTAINER_MultiHashMap *tcp_services; |
401 | 401 | ||
402 | /** | 402 | /** |
403 | * Array of all open DNS requests from tunnels. | 403 | * Array of all open DNS requests from channels. |
404 | */ | 404 | */ |
405 | static struct TunnelState *tunnels[UINT16_MAX + 1]; | 405 | static struct ChannelState *channels[UINT16_MAX + 1]; |
406 | 406 | ||
407 | /** | 407 | /** |
408 | * Handle to the DNS Stub resolver. | 408 | * Handle to the DNS Stub resolver. |
@@ -462,10 +462,10 @@ static int ipv6_enabled; | |||
462 | 462 | ||
463 | 463 | ||
464 | /** | 464 | /** |
465 | * We got a reply from DNS for a request of a MESH tunnel. Send it | 465 | * We got a reply from DNS for a request of a MESH channel. Send it |
466 | * via the tunnel (after changing the request ID back). | 466 | * via the channel (after changing the request ID back). |
467 | * | 467 | * |
468 | * @param cls the 'struct TunnelState' | 468 | * @param cls the 'struct ChannelState' |
469 | * @param size number of bytes available in buf | 469 | * @param size number of bytes available in buf |
470 | * @param buf where to copy the reply | 470 | * @param buf where to copy the reply |
471 | * @return number of bytes written to buf | 471 | * @return number of bytes written to buf |
@@ -475,7 +475,7 @@ transmit_reply_to_mesh (void *cls, | |||
475 | size_t size, | 475 | size_t size, |
476 | void *buf) | 476 | void *buf) |
477 | { | 477 | { |
478 | struct TunnelState *ts = cls; | 478 | struct ChannelState *ts = cls; |
479 | size_t off; | 479 | size_t off; |
480 | size_t ret; | 480 | size_t ret; |
481 | char *cbuf = buf; | 481 | char *cbuf = buf; |
@@ -523,26 +523,26 @@ process_dns_result (void *cls, | |||
523 | const struct GNUNET_TUN_DnsHeader *dns, | 523 | const struct GNUNET_TUN_DnsHeader *dns, |
524 | size_t r) | 524 | size_t r) |
525 | { | 525 | { |
526 | struct TunnelState *ts; | 526 | struct ChannelState *ts; |
527 | 527 | ||
528 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 528 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
529 | "Processing DNS result from stub resolver\n"); | 529 | "Processing DNS result from stub resolver\n"); |
530 | GNUNET_assert (NULL == cls); | 530 | GNUNET_assert (NULL == cls); |
531 | /* Handle case that this is a reply to a request from a MESH DNS tunnel */ | 531 | /* Handle case that this is a reply to a request from a MESH DNS channel */ |
532 | ts = tunnels[dns->id]; | 532 | ts = channels[dns->id]; |
533 | if ( (NULL == ts) || | 533 | if ( (NULL == ts) || |
534 | (ts->specifics.dns.rs != rs) ) | 534 | (ts->specifics.dns.rs != rs) ) |
535 | return; | 535 | return; |
536 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 536 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
537 | "Got a response from the stub resolver for DNS request received via MESH!\n"); | 537 | "Got a response from the stub resolver for DNS request received via MESH!\n"); |
538 | tunnels[dns->id] = NULL; | 538 | channels[dns->id] = NULL; |
539 | GNUNET_free_non_null (ts->specifics.dns.reply); | 539 | GNUNET_free_non_null (ts->specifics.dns.reply); |
540 | ts->specifics.dns.reply = GNUNET_malloc (r); | 540 | ts->specifics.dns.reply = GNUNET_malloc (r); |
541 | ts->specifics.dns.reply_length = r; | 541 | ts->specifics.dns.reply_length = r; |
542 | memcpy (ts->specifics.dns.reply, dns, r); | 542 | memcpy (ts->specifics.dns.reply, dns, r); |
543 | if (NULL != ts->th) | 543 | if (NULL != ts->th) |
544 | GNUNET_MESH_notify_transmit_ready_cancel (ts->th); | 544 | GNUNET_MESH_notify_transmit_ready_cancel (ts->th); |
545 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, | 545 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->channel, |
546 | GNUNET_NO, | 546 | GNUNET_NO, |
547 | GNUNET_TIME_UNIT_FOREVER_REL, | 547 | GNUNET_TIME_UNIT_FOREVER_REL, |
548 | sizeof (struct GNUNET_MessageHeader) + r, | 548 | sizeof (struct GNUNET_MessageHeader) + r, |
@@ -555,19 +555,19 @@ process_dns_result (void *cls, | |||
555 | * Process a request via mesh to perform a DNS query. | 555 | * Process a request via mesh to perform a DNS query. |
556 | * | 556 | * |
557 | * @param cls closure, NULL | 557 | * @param cls closure, NULL |
558 | * @param tunnel connection to the other end | 558 | * @param channel connection to the other end |
559 | * @param tunnel_ctx pointer to our `struct TunnelState *` | 559 | * @param channel_ctx pointer to our `struct ChannelState *` |
560 | * @param message the actual message | 560 | * @param message the actual message |
561 | * | 561 | * |
562 | * @return #GNUNET_OK to keep the connection open, | 562 | * @return #GNUNET_OK to keep the connection open, |
563 | * #GNUNET_SYSERR to close it (signal serious error) | 563 | * #GNUNET_SYSERR to close it (signal serious error) |
564 | */ | 564 | */ |
565 | static int | 565 | static int |
566 | receive_dns_request (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | 566 | receive_dns_request (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Channel *channel, |
567 | void **tunnel_ctx, | 567 | void **channel_ctx, |
568 | const struct GNUNET_MessageHeader *message) | 568 | const struct GNUNET_MessageHeader *message) |
569 | { | 569 | { |
570 | struct TunnelState *ts = *tunnel_ctx; | 570 | struct ChannelState *ts = *channel_ctx; |
571 | const struct GNUNET_TUN_DnsHeader *dns; | 571 | const struct GNUNET_TUN_DnsHeader *dns; |
572 | size_t mlen = ntohs (message->size); | 572 | size_t mlen = ntohs (message->size); |
573 | size_t dlen = mlen - sizeof (struct GNUNET_MessageHeader); | 573 | size_t dlen = mlen - sizeof (struct GNUNET_MessageHeader); |
@@ -583,7 +583,7 @@ receive_dns_request (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
583 | } | 583 | } |
584 | if (GNUNET_SYSERR == ts->is_dns) | 584 | if (GNUNET_SYSERR == ts->is_dns) |
585 | { | 585 | { |
586 | /* tunnel is DNS from now on */ | 586 | /* channel is DNS from now on */ |
587 | ts->is_dns = GNUNET_YES; | 587 | ts->is_dns = GNUNET_YES; |
588 | } | 588 | } |
589 | if (dlen < sizeof (struct GNUNET_TUN_DnsHeader)) | 589 | if (dlen < sizeof (struct GNUNET_TUN_DnsHeader)) |
@@ -593,11 +593,11 @@ receive_dns_request (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
593 | } | 593 | } |
594 | dns = (const struct GNUNET_TUN_DnsHeader *) &message[1]; | 594 | dns = (const struct GNUNET_TUN_DnsHeader *) &message[1]; |
595 | ts->specifics.dns.original_id = dns->id; | 595 | ts->specifics.dns.original_id = dns->id; |
596 | if (tunnels[ts->specifics.dns.my_id] == ts) | 596 | if (channels[ts->specifics.dns.my_id] == ts) |
597 | tunnels[ts->specifics.dns.my_id] = NULL; | 597 | channels[ts->specifics.dns.my_id] = NULL; |
598 | ts->specifics.dns.my_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 598 | ts->specifics.dns.my_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
599 | UINT16_MAX + 1); | 599 | UINT16_MAX + 1); |
600 | tunnels[ts->specifics.dns.my_id] = ts; | 600 | channels[ts->specifics.dns.my_id] = ts; |
601 | memcpy (buf, dns, dlen); | 601 | memcpy (buf, dns, dlen); |
602 | dout = (struct GNUNET_TUN_DnsHeader *) buf; | 602 | dout = (struct GNUNET_TUN_DnsHeader *) buf; |
603 | dout->id = ts->specifics.dns.my_id; | 603 | dout->id = ts->specifics.dns.my_id; |
@@ -676,7 +676,7 @@ hash_redirect_info (struct GNUNET_HashCode *hash, | |||
676 | * @param state_key set to hash's state if non-NULL | 676 | * @param state_key set to hash's state if non-NULL |
677 | * @return NULL if we have no tracking information for this tuple | 677 | * @return NULL if we have no tracking information for this tuple |
678 | */ | 678 | */ |
679 | static struct TunnelState * | 679 | static struct ChannelState * |
680 | get_redirect_state (int af, | 680 | get_redirect_state (int af, |
681 | int protocol, | 681 | int protocol, |
682 | const void *destination_ip, | 682 | const void *destination_ip, |
@@ -687,7 +687,7 @@ get_redirect_state (int af, | |||
687 | { | 687 | { |
688 | struct RedirectInformation ri; | 688 | struct RedirectInformation ri; |
689 | struct GNUNET_HashCode key; | 689 | struct GNUNET_HashCode key; |
690 | struct TunnelState *state; | 690 | struct ChannelState *state; |
691 | 691 | ||
692 | if ( ( (af == AF_INET) && (protocol == IPPROTO_ICMP) ) || | 692 | if ( ( (af == AF_INET) && (protocol == IPPROTO_ICMP) ) || |
693 | ( (af == AF_INET6) && (protocol == IPPROTO_ICMPV6) ) ) | 693 | ( (af == AF_INET6) && (protocol == IPPROTO_ICMPV6) ) ) |
@@ -807,9 +807,9 @@ store_service (struct GNUNET_CONTAINER_MultiHashMap *service_map, | |||
807 | 807 | ||
808 | 808 | ||
809 | /** | 809 | /** |
810 | * MESH is ready to receive a message for the tunnel. Transmit it. | 810 | * MESH is ready to receive a message for the channel. Transmit it. |
811 | * | 811 | * |
812 | * @param cls the 'struct TunnelState'. | 812 | * @param cls the 'struct ChannelState'. |
813 | * @param size number of bytes available in buf | 813 | * @param size number of bytes available in buf |
814 | * @param buf where to copy the message | 814 | * @param buf where to copy the message |
815 | * @return number of bytes copied to buf | 815 | * @return number of bytes copied to buf |
@@ -817,9 +817,9 @@ store_service (struct GNUNET_CONTAINER_MultiHashMap *service_map, | |||
817 | static size_t | 817 | static size_t |
818 | send_to_peer_notify_callback (void *cls, size_t size, void *buf) | 818 | send_to_peer_notify_callback (void *cls, size_t size, void *buf) |
819 | { | 819 | { |
820 | struct TunnelState *s = cls; | 820 | struct ChannelState *s = cls; |
821 | struct GNUNET_MESH_Tunnel *tunnel = s->tunnel; | 821 | struct GNUNET_MESH_Channel *channel = s->channel; |
822 | struct TunnelMessageQueue *tnq; | 822 | struct ChannelMessageQueue *tnq; |
823 | 823 | ||
824 | s->th = NULL; | 824 | s->th = NULL; |
825 | tnq = s->specifics.tcp_udp.head; | 825 | tnq = s->specifics.tcp_udp.head; |
@@ -827,7 +827,7 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
827 | return 0; | 827 | return 0; |
828 | if (0 == size) | 828 | if (0 == size) |
829 | { | 829 | { |
830 | s->th = GNUNET_MESH_notify_transmit_ready (tunnel, | 830 | s->th = GNUNET_MESH_notify_transmit_ready (channel, |
831 | GNUNET_NO /* corking */, | 831 | GNUNET_NO /* corking */, |
832 | GNUNET_TIME_UNIT_FOREVER_REL, | 832 | GNUNET_TIME_UNIT_FOREVER_REL, |
833 | tnq->len, | 833 | tnq->len, |
@@ -843,36 +843,36 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
843 | tnq); | 843 | tnq); |
844 | GNUNET_free (tnq); | 844 | GNUNET_free (tnq); |
845 | if (NULL != (tnq = s->specifics.tcp_udp.head)) | 845 | if (NULL != (tnq = s->specifics.tcp_udp.head)) |
846 | s->th = GNUNET_MESH_notify_transmit_ready (tunnel, | 846 | s->th = GNUNET_MESH_notify_transmit_ready (channel, |
847 | GNUNET_NO /* corking */, | 847 | GNUNET_NO /* corking */, |
848 | GNUNET_TIME_UNIT_FOREVER_REL, | 848 | GNUNET_TIME_UNIT_FOREVER_REL, |
849 | tnq->len, | 849 | tnq->len, |
850 | &send_to_peer_notify_callback, | 850 | &send_to_peer_notify_callback, |
851 | s); | 851 | s); |
852 | GNUNET_STATISTICS_update (stats, | 852 | GNUNET_STATISTICS_update (stats, |
853 | gettext_noop ("# Bytes transmitted via mesh tunnels"), | 853 | gettext_noop ("# Bytes transmitted via mesh channels"), |
854 | size, GNUNET_NO); | 854 | size, GNUNET_NO); |
855 | return size; | 855 | return size; |
856 | } | 856 | } |
857 | 857 | ||
858 | 858 | ||
859 | /** | 859 | /** |
860 | * Send the given packet via the mesh tunnel. | 860 | * Send the given packet via the mesh channel. |
861 | * | 861 | * |
862 | * @param s tunnel destination | 862 | * @param s channel destination |
863 | * @param tnq message to queue | 863 | * @param tnq message to queue |
864 | */ | 864 | */ |
865 | static void | 865 | static void |
866 | send_packet_to_mesh_tunnel (struct TunnelState *s, | 866 | send_packet_to_mesh_channel (struct ChannelState *s, |
867 | struct TunnelMessageQueue *tnq) | 867 | struct ChannelMessageQueue *tnq) |
868 | { | 868 | { |
869 | struct GNUNET_MESH_Tunnel *mesh_tunnel; | 869 | struct GNUNET_MESH_Channel *mesh_channel; |
870 | 870 | ||
871 | mesh_tunnel = s->tunnel; | 871 | mesh_channel = s->channel; |
872 | GNUNET_assert (NULL != s); | 872 | GNUNET_assert (NULL != s); |
873 | GNUNET_CONTAINER_DLL_insert_tail (s->specifics.tcp_udp.head, s->specifics.tcp_udp.tail, tnq); | 873 | GNUNET_CONTAINER_DLL_insert_tail (s->specifics.tcp_udp.head, s->specifics.tcp_udp.tail, tnq); |
874 | if (NULL == s->th) | 874 | if (NULL == s->th) |
875 | s->th = GNUNET_MESH_notify_transmit_ready (mesh_tunnel, | 875 | s->th = GNUNET_MESH_notify_transmit_ready (mesh_channel, |
876 | GNUNET_NO /* cork */, | 876 | GNUNET_NO /* cork */, |
877 | GNUNET_TIME_UNIT_FOREVER_REL, | 877 | GNUNET_TIME_UNIT_FOREVER_REL, |
878 | tnq->len, | 878 | tnq->len, |
@@ -899,8 +899,8 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, | |||
899 | const void *destination_ip, | 899 | const void *destination_ip, |
900 | const void *source_ip) | 900 | const void *source_ip) |
901 | { | 901 | { |
902 | struct TunnelState *state; | 902 | struct ChannelState *state; |
903 | struct TunnelMessageQueue *tnq; | 903 | struct ChannelMessageQueue *tnq; |
904 | struct GNUNET_EXIT_IcmpToVPNMessage *i2v; | 904 | struct GNUNET_EXIT_IcmpToVPNMessage *i2v; |
905 | const struct GNUNET_TUN_IPv4Header *ipv4; | 905 | const struct GNUNET_TUN_IPv4Header *ipv4; |
906 | const struct GNUNET_TUN_IPv6Header *ipv6; | 906 | const struct GNUNET_TUN_IPv6Header *ipv6; |
@@ -1055,7 +1055,7 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, | |||
1055 | return; | 1055 | return; |
1056 | } | 1056 | } |
1057 | mlen = sizeof (struct GNUNET_EXIT_IcmpToVPNMessage) + pktlen - sizeof (struct GNUNET_TUN_IcmpHeader); | 1057 | mlen = sizeof (struct GNUNET_EXIT_IcmpToVPNMessage) + pktlen - sizeof (struct GNUNET_TUN_IcmpHeader); |
1058 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueue) + mlen); | 1058 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueue) + mlen); |
1059 | tnq->payload = &tnq[1]; | 1059 | tnq->payload = &tnq[1]; |
1060 | tnq->len = mlen; | 1060 | tnq->len = mlen; |
1061 | i2v = (struct GNUNET_EXIT_IcmpToVPNMessage *) &tnq[1]; | 1061 | i2v = (struct GNUNET_EXIT_IcmpToVPNMessage *) &tnq[1]; |
@@ -1065,7 +1065,7 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, | |||
1065 | memcpy (&i2v->icmp_header, | 1065 | memcpy (&i2v->icmp_header, |
1066 | icmp, | 1066 | icmp, |
1067 | pktlen); | 1067 | pktlen); |
1068 | send_packet_to_mesh_tunnel (state, tnq); | 1068 | send_packet_to_mesh_channel (state, tnq); |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | 1071 | ||
@@ -1087,8 +1087,8 @@ udp_from_helper (const struct GNUNET_TUN_UdpHeader *udp, | |||
1087 | const void *destination_ip, | 1087 | const void *destination_ip, |
1088 | const void *source_ip) | 1088 | const void *source_ip) |
1089 | { | 1089 | { |
1090 | struct TunnelState *state; | 1090 | struct ChannelState *state; |
1091 | struct TunnelMessageQueue *tnq; | 1091 | struct ChannelMessageQueue *tnq; |
1092 | struct GNUNET_EXIT_UdpReplyMessage *urm; | 1092 | struct GNUNET_EXIT_UdpReplyMessage *urm; |
1093 | size_t mlen; | 1093 | size_t mlen; |
1094 | 1094 | ||
@@ -1131,7 +1131,7 @@ udp_from_helper (const struct GNUNET_TUN_UdpHeader *udp, | |||
1131 | return; | 1131 | return; |
1132 | } | 1132 | } |
1133 | mlen = sizeof (struct GNUNET_EXIT_UdpReplyMessage) + pktlen - sizeof (struct GNUNET_TUN_UdpHeader); | 1133 | mlen = sizeof (struct GNUNET_EXIT_UdpReplyMessage) + pktlen - sizeof (struct GNUNET_TUN_UdpHeader); |
1134 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueue) + mlen); | 1134 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueue) + mlen); |
1135 | tnq->payload = &tnq[1]; | 1135 | tnq->payload = &tnq[1]; |
1136 | tnq->len = mlen; | 1136 | tnq->len = mlen; |
1137 | urm = (struct GNUNET_EXIT_UdpReplyMessage *) &tnq[1]; | 1137 | urm = (struct GNUNET_EXIT_UdpReplyMessage *) &tnq[1]; |
@@ -1142,7 +1142,7 @@ udp_from_helper (const struct GNUNET_TUN_UdpHeader *udp, | |||
1142 | memcpy (&urm[1], | 1142 | memcpy (&urm[1], |
1143 | &udp[1], | 1143 | &udp[1], |
1144 | pktlen - sizeof (struct GNUNET_TUN_UdpHeader)); | 1144 | pktlen - sizeof (struct GNUNET_TUN_UdpHeader)); |
1145 | send_packet_to_mesh_tunnel (state, tnq); | 1145 | send_packet_to_mesh_channel (state, tnq); |
1146 | } | 1146 | } |
1147 | 1147 | ||
1148 | 1148 | ||
@@ -1164,11 +1164,11 @@ tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp, | |||
1164 | const void *destination_ip, | 1164 | const void *destination_ip, |
1165 | const void *source_ip) | 1165 | const void *source_ip) |
1166 | { | 1166 | { |
1167 | struct TunnelState *state; | 1167 | struct ChannelState *state; |
1168 | char buf[pktlen] GNUNET_ALIGN; | 1168 | char buf[pktlen] GNUNET_ALIGN; |
1169 | struct GNUNET_TUN_TcpHeader *mtcp; | 1169 | struct GNUNET_TUN_TcpHeader *mtcp; |
1170 | struct GNUNET_EXIT_TcpDataMessage *tdm; | 1170 | struct GNUNET_EXIT_TcpDataMessage *tdm; |
1171 | struct TunnelMessageQueue *tnq; | 1171 | struct ChannelMessageQueue *tnq; |
1172 | size_t mlen; | 1172 | size_t mlen; |
1173 | 1173 | ||
1174 | { | 1174 | { |
@@ -1220,7 +1220,7 @@ tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp, | |||
1220 | return; | 1220 | return; |
1221 | } | 1221 | } |
1222 | 1222 | ||
1223 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueue) + mlen); | 1223 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueue) + mlen); |
1224 | tnq->payload = &tnq[1]; | 1224 | tnq->payload = &tnq[1]; |
1225 | tnq->len = mlen; | 1225 | tnq->len = mlen; |
1226 | tdm = (struct GNUNET_EXIT_TcpDataMessage *) &tnq[1]; | 1226 | tdm = (struct GNUNET_EXIT_TcpDataMessage *) &tnq[1]; |
@@ -1230,7 +1230,7 @@ tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp, | |||
1230 | memcpy (&tdm->tcp_header, | 1230 | memcpy (&tdm->tcp_header, |
1231 | buf, | 1231 | buf, |
1232 | pktlen); | 1232 | pktlen); |
1233 | send_packet_to_mesh_tunnel (state, tnq); | 1233 | send_packet_to_mesh_channel (state, tnq); |
1234 | } | 1234 | } |
1235 | 1235 | ||
1236 | 1236 | ||
@@ -1486,7 +1486,7 @@ setup_fresh_address (int af, | |||
1486 | * We are starting a fresh connection (TCP or UDP) and need | 1486 | * We are starting a fresh connection (TCP or UDP) and need |
1487 | * to pick a source port and IP address (within the correct | 1487 | * to pick a source port and IP address (within the correct |
1488 | * range and address family) to associate replies with the | 1488 | * range and address family) to associate replies with the |
1489 | * connection / correct mesh tunnel. This function generates | 1489 | * connection / correct mesh channel. This function generates |
1490 | * a "fresh" source IP and source port number for a connection | 1490 | * a "fresh" source IP and source port number for a connection |
1491 | * After picking a good source address, this function sets up | 1491 | * After picking a good source address, this function sets up |
1492 | * the state in the 'connections_map' and 'connections_heap' | 1492 | * the state in the 'connections_map' and 'connections_heap' |
@@ -1497,17 +1497,17 @@ setup_fresh_address (int af, | |||
1497 | * @param state skeleton state to setup a record for; should | 1497 | * @param state skeleton state to setup a record for; should |
1498 | * 'state->specifics.tcp_udp.ri.remote_address' filled in so that | 1498 | * 'state->specifics.tcp_udp.ri.remote_address' filled in so that |
1499 | * this code can determine which AF/protocol is | 1499 | * this code can determine which AF/protocol is |
1500 | * going to be used (the 'tunnel' should also | 1500 | * going to be used (the 'channel' should also |
1501 | * already be set); after calling this function, | 1501 | * already be set); after calling this function, |
1502 | * heap_node and the local_address will be | 1502 | * heap_node and the local_address will be |
1503 | * also initialized (heap_node != NULL can be | 1503 | * also initialized (heap_node != NULL can be |
1504 | * used to test if a state has been fully setup). | 1504 | * used to test if a state has been fully setup). |
1505 | */ | 1505 | */ |
1506 | static void | 1506 | static void |
1507 | setup_state_record (struct TunnelState *state) | 1507 | setup_state_record (struct ChannelState *state) |
1508 | { | 1508 | { |
1509 | struct GNUNET_HashCode key; | 1509 | struct GNUNET_HashCode key; |
1510 | struct TunnelState *s; | 1510 | struct ChannelState *s; |
1511 | 1511 | ||
1512 | /* generate fresh, unique address */ | 1512 | /* generate fresh, unique address */ |
1513 | do | 1513 | do |
@@ -1549,7 +1549,7 @@ setup_state_record (struct TunnelState *state) | |||
1549 | s = GNUNET_CONTAINER_heap_remove_root (connections_heap); | 1549 | s = GNUNET_CONTAINER_heap_remove_root (connections_heap); |
1550 | GNUNET_assert (state != s); | 1550 | GNUNET_assert (state != s); |
1551 | s->specifics.tcp_udp.heap_node = NULL; | 1551 | s->specifics.tcp_udp.heap_node = NULL; |
1552 | GNUNET_MESH_tunnel_destroy (s->tunnel); | 1552 | GNUNET_MESH_channel_destroy (s->channel); |
1553 | GNUNET_assert (GNUNET_OK == | 1553 | GNUNET_assert (GNUNET_OK == |
1554 | GNUNET_CONTAINER_multihashmap_remove (connections_map, | 1554 | GNUNET_CONTAINER_multihashmap_remove (connections_map, |
1555 | &s->specifics.tcp_udp.state_key, | 1555 | &s->specifics.tcp_udp.state_key, |
@@ -1837,19 +1837,19 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address, | |||
1837 | * offered by this system. | 1837 | * offered by this system. |
1838 | * | 1838 | * |
1839 | * @param cls closure, NULL | 1839 | * @param cls closure, NULL |
1840 | * @param tunnel connection to the other end | 1840 | * @param channel connection to the other end |
1841 | * @param tunnel_ctx pointer to our `struct TunnelState *` | 1841 | * @param channel_ctx pointer to our `struct ChannelState *` |
1842 | * @param message the actual message | 1842 | * @param message the actual message |
1843 | * @return #GNUNET_OK to keep the connection open, | 1843 | * @return #GNUNET_OK to keep the connection open, |
1844 | * #GNUNET_SYSERR to close it (signal serious error) | 1844 | * #GNUNET_SYSERR to close it (signal serious error) |
1845 | */ | 1845 | */ |
1846 | static int | 1846 | static int |
1847 | receive_tcp_service (void *cls, | 1847 | receive_tcp_service (void *cls, |
1848 | struct GNUNET_MESH_Tunnel *tunnel, | 1848 | struct GNUNET_MESH_Channel *channel, |
1849 | void **tunnel_ctx, | 1849 | void **channel_ctx, |
1850 | const struct GNUNET_MessageHeader *message) | 1850 | const struct GNUNET_MessageHeader *message) |
1851 | { | 1851 | { |
1852 | struct TunnelState *state = *tunnel_ctx; | 1852 | struct ChannelState *state = *channel_ctx; |
1853 | const struct GNUNET_EXIT_TcpServiceStartMessage *start; | 1853 | const struct GNUNET_EXIT_TcpServiceStartMessage *start; |
1854 | uint16_t pkt_len = ntohs (message->size); | 1854 | uint16_t pkt_len = ntohs (message->size); |
1855 | 1855 | ||
@@ -1865,7 +1865,7 @@ receive_tcp_service (void *cls, | |||
1865 | } | 1865 | } |
1866 | if (GNUNET_SYSERR == state->is_dns) | 1866 | if (GNUNET_SYSERR == state->is_dns) |
1867 | { | 1867 | { |
1868 | /* tunnel is UDP/TCP from now on */ | 1868 | /* channel is UDP/TCP from now on */ |
1869 | state->is_dns = GNUNET_NO; | 1869 | state->is_dns = GNUNET_NO; |
1870 | } | 1870 | } |
1871 | GNUNET_STATISTICS_update (stats, | 1871 | GNUNET_STATISTICS_update (stats, |
@@ -1926,19 +1926,19 @@ receive_tcp_service (void *cls, | |||
1926 | * Process a request to forward TCP data to the Internet via this peer. | 1926 | * Process a request to forward TCP data to the Internet via this peer. |
1927 | * | 1927 | * |
1928 | * @param cls closure, NULL | 1928 | * @param cls closure, NULL |
1929 | * @param tunnel connection to the other end | 1929 | * @param channel connection to the other end |
1930 | * @param tunnel_ctx pointer to our 'struct TunnelState *' | 1930 | * @param channel_ctx pointer to our 'struct ChannelState *' |
1931 | * @param message the actual message | 1931 | * @param message the actual message |
1932 | * | 1932 | * |
1933 | * @return GNUNET_OK to keep the connection open, | 1933 | * @return GNUNET_OK to keep the connection open, |
1934 | * GNUNET_SYSERR to close it (signal serious error) | 1934 | * GNUNET_SYSERR to close it (signal serious error) |
1935 | */ | 1935 | */ |
1936 | static int | 1936 | static int |
1937 | receive_tcp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | 1937 | receive_tcp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Channel *channel, |
1938 | void **tunnel_ctx GNUNET_UNUSED, | 1938 | void **channel_ctx GNUNET_UNUSED, |
1939 | const struct GNUNET_MessageHeader *message) | 1939 | const struct GNUNET_MessageHeader *message) |
1940 | { | 1940 | { |
1941 | struct TunnelState *state = *tunnel_ctx; | 1941 | struct ChannelState *state = *channel_ctx; |
1942 | const struct GNUNET_EXIT_TcpInternetStartMessage *start; | 1942 | const struct GNUNET_EXIT_TcpInternetStartMessage *start; |
1943 | uint16_t pkt_len = ntohs (message->size); | 1943 | uint16_t pkt_len = ntohs (message->size); |
1944 | const struct in_addr *v4; | 1944 | const struct in_addr *v4; |
@@ -1958,7 +1958,7 @@ receive_tcp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1958 | } | 1958 | } |
1959 | if (GNUNET_SYSERR == state->is_dns) | 1959 | if (GNUNET_SYSERR == state->is_dns) |
1960 | { | 1960 | { |
1961 | /* tunnel is UDP/TCP from now on */ | 1961 | /* channel is UDP/TCP from now on */ |
1962 | state->is_dns = GNUNET_NO; | 1962 | state->is_dns = GNUNET_NO; |
1963 | } | 1963 | } |
1964 | GNUNET_STATISTICS_update (stats, | 1964 | GNUNET_STATISTICS_update (stats, |
@@ -2051,18 +2051,18 @@ receive_tcp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
2051 | * connection via this peer. | 2051 | * connection via this peer. |
2052 | * | 2052 | * |
2053 | * @param cls closure, NULL | 2053 | * @param cls closure, NULL |
2054 | * @param tunnel connection to the other end | 2054 | * @param channel connection to the other end |
2055 | * @param tunnel_ctx pointer to our 'struct TunnelState *' | 2055 | * @param channel_ctx pointer to our 'struct ChannelState *' |
2056 | * @param message the actual message | 2056 | * @param message the actual message |
2057 | * @return #GNUNET_OK to keep the connection open, | 2057 | * @return #GNUNET_OK to keep the connection open, |
2058 | * #GNUNET_SYSERR to close it (signal serious error) | 2058 | * #GNUNET_SYSERR to close it (signal serious error) |
2059 | */ | 2059 | */ |
2060 | static int | 2060 | static int |
2061 | receive_tcp_data (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | 2061 | receive_tcp_data (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Channel *channel, |
2062 | void **tunnel_ctx GNUNET_UNUSED, | 2062 | void **channel_ctx GNUNET_UNUSED, |
2063 | const struct GNUNET_MessageHeader *message) | 2063 | const struct GNUNET_MessageHeader *message) |
2064 | { | 2064 | { |
2065 | struct TunnelState *state = *tunnel_ctx; | 2065 | struct ChannelState *state = *channel_ctx; |
2066 | const struct GNUNET_EXIT_TcpDataMessage *data; | 2066 | const struct GNUNET_EXIT_TcpDataMessage *data; |
2067 | uint16_t pkt_len = ntohs (message->size); | 2067 | uint16_t pkt_len = ntohs (message->size); |
2068 | 2068 | ||
@@ -2100,7 +2100,7 @@ receive_tcp_data (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
2100 | } | 2100 | } |
2101 | if (GNUNET_SYSERR == state->is_dns) | 2101 | if (GNUNET_SYSERR == state->is_dns) |
2102 | { | 2102 | { |
2103 | /* tunnel is UDP/TCP from now on */ | 2103 | /* channel is UDP/TCP from now on */ |
2104 | state->is_dns = GNUNET_NO; | 2104 | state->is_dns = GNUNET_NO; |
2105 | } | 2105 | } |
2106 | 2106 | ||
@@ -2229,15 +2229,15 @@ send_icmp_packet_via_tun (const struct SocketAddress *destination_address, | |||
2229 | 2229 | ||
2230 | /** | 2230 | /** |
2231 | * Synthesize a plausible ICMP payload for an ICMPv4 error | 2231 | * Synthesize a plausible ICMP payload for an ICMPv4 error |
2232 | * response on the given tunnel. | 2232 | * response on the given channel. |
2233 | * | 2233 | * |
2234 | * @param state tunnel information | 2234 | * @param state channel information |
2235 | * @param ipp IPv6 header to fill in (ICMP payload) | 2235 | * @param ipp IPv6 header to fill in (ICMP payload) |
2236 | * @param udp "UDP" header to fill in (ICMP payload); might actually | 2236 | * @param udp "UDP" header to fill in (ICMP payload); might actually |
2237 | * also be the first 8 bytes of the TCP header | 2237 | * also be the first 8 bytes of the TCP header |
2238 | */ | 2238 | */ |
2239 | static void | 2239 | static void |
2240 | make_up_icmpv4_payload (struct TunnelState *state, | 2240 | make_up_icmpv4_payload (struct ChannelState *state, |
2241 | struct GNUNET_TUN_IPv4Header *ipp, | 2241 | struct GNUNET_TUN_IPv4Header *ipp, |
2242 | struct GNUNET_TUN_UdpHeader *udp) | 2242 | struct GNUNET_TUN_UdpHeader *udp) |
2243 | { | 2243 | { |
@@ -2255,15 +2255,15 @@ make_up_icmpv4_payload (struct TunnelState *state, | |||
2255 | 2255 | ||
2256 | /** | 2256 | /** |
2257 | * Synthesize a plausible ICMP payload for an ICMPv6 error | 2257 | * Synthesize a plausible ICMP payload for an ICMPv6 error |
2258 | * response on the given tunnel. | 2258 | * response on the given channel. |
2259 | * | 2259 | * |
2260 | * @param state tunnel information | 2260 | * @param state channel information |
2261 | * @param ipp IPv6 header to fill in (ICMP payload) | 2261 | * @param ipp IPv6 header to fill in (ICMP payload) |
2262 | * @param udp "UDP" header to fill in (ICMP payload); might actually | 2262 | * @param udp "UDP" header to fill in (ICMP payload); might actually |
2263 | * also be the first 8 bytes of the TCP header | 2263 | * also be the first 8 bytes of the TCP header |
2264 | */ | 2264 | */ |
2265 | static void | 2265 | static void |
2266 | make_up_icmpv6_payload (struct TunnelState *state, | 2266 | make_up_icmpv6_payload (struct ChannelState *state, |
2267 | struct GNUNET_TUN_IPv6Header *ipp, | 2267 | struct GNUNET_TUN_IPv6Header *ipp, |
2268 | struct GNUNET_TUN_UdpHeader *udp) | 2268 | struct GNUNET_TUN_UdpHeader *udp) |
2269 | { | 2269 | { |
@@ -2283,19 +2283,19 @@ make_up_icmpv6_payload (struct TunnelState *state, | |||
2283 | * Process a request to forward ICMP data to the Internet via this peer. | 2283 | * Process a request to forward ICMP data to the Internet via this peer. |
2284 | * | 2284 | * |
2285 | * @param cls closure, NULL | 2285 | * @param cls closure, NULL |
2286 | * @param tunnel connection to the other end | 2286 | * @param channel connection to the other end |
2287 | * @param tunnel_ctx pointer to our 'struct TunnelState *' | 2287 | * @param channel_ctx pointer to our 'struct ChannelState *' |
2288 | * @param message the actual message | 2288 | * @param message the actual message |
2289 | * @return #GNUNET_OK to keep the connection open, | 2289 | * @return #GNUNET_OK to keep the connection open, |
2290 | * #GNUNET_SYSERR to close it (signal serious error) | 2290 | * #GNUNET_SYSERR to close it (signal serious error) |
2291 | */ | 2291 | */ |
2292 | static int | 2292 | static int |
2293 | receive_icmp_remote (void *cls, | 2293 | receive_icmp_remote (void *cls, |
2294 | struct GNUNET_MESH_Tunnel *tunnel, | 2294 | struct GNUNET_MESH_Channel *channel, |
2295 | void **tunnel_ctx, | 2295 | void **channel_ctx, |
2296 | const struct GNUNET_MessageHeader *message) | 2296 | const struct GNUNET_MessageHeader *message) |
2297 | { | 2297 | { |
2298 | struct TunnelState *state = *tunnel_ctx; | 2298 | struct ChannelState *state = *channel_ctx; |
2299 | const struct GNUNET_EXIT_IcmpInternetMessage *msg; | 2299 | const struct GNUNET_EXIT_IcmpInternetMessage *msg; |
2300 | uint16_t pkt_len = ntohs (message->size); | 2300 | uint16_t pkt_len = ntohs (message->size); |
2301 | const struct in_addr *v4; | 2301 | const struct in_addr *v4; |
@@ -2311,7 +2311,7 @@ receive_icmp_remote (void *cls, | |||
2311 | } | 2311 | } |
2312 | if (GNUNET_SYSERR == state->is_dns) | 2312 | if (GNUNET_SYSERR == state->is_dns) |
2313 | { | 2313 | { |
2314 | /* tunnel is UDP/TCP from now on */ | 2314 | /* channel is UDP/TCP from now on */ |
2315 | state->is_dns = GNUNET_NO; | 2315 | state->is_dns = GNUNET_NO; |
2316 | } | 2316 | } |
2317 | GNUNET_STATISTICS_update (stats, | 2317 | GNUNET_STATISTICS_update (stats, |
@@ -2332,7 +2332,7 @@ receive_icmp_remote (void *cls, | |||
2332 | if ( (NULL != state->specifics.tcp_udp.heap_node) && | 2332 | if ( (NULL != state->specifics.tcp_udp.heap_node) && |
2333 | (af != state->specifics.tcp_udp.ri.remote_address.af) ) | 2333 | (af != state->specifics.tcp_udp.ri.remote_address.af) ) |
2334 | { | 2334 | { |
2335 | /* other peer switched AF on this tunnel; not allowed */ | 2335 | /* other peer switched AF on this channel; not allowed */ |
2336 | GNUNET_break_op (0); | 2336 | GNUNET_break_op (0); |
2337 | return GNUNET_SYSERR; | 2337 | return GNUNET_SYSERR; |
2338 | } | 2338 | } |
@@ -2489,7 +2489,7 @@ receive_icmp_remote (void *cls, | |||
2489 | * @return number of bytes of payload we created in buf | 2489 | * @return number of bytes of payload we created in buf |
2490 | */ | 2490 | */ |
2491 | static uint16_t | 2491 | static uint16_t |
2492 | make_up_icmp_service_payload (struct TunnelState *state, | 2492 | make_up_icmp_service_payload (struct ChannelState *state, |
2493 | char *buf) | 2493 | char *buf) |
2494 | { | 2494 | { |
2495 | switch (state->specifics.tcp_udp.serv->address.af) | 2495 | switch (state->specifics.tcp_udp.serv->address.af) |
@@ -2534,19 +2534,19 @@ make_up_icmp_service_payload (struct TunnelState *state, | |||
2534 | * offered by this system. | 2534 | * offered by this system. |
2535 | * | 2535 | * |
2536 | * @param cls closure, NULL | 2536 | * @param cls closure, NULL |
2537 | * @param tunnel connection to the other end | 2537 | * @param channel connection to the other end |
2538 | * @param tunnel_ctx pointer to our 'struct TunnelState *' | 2538 | * @param channel_ctx pointer to our 'struct ChannelState *' |
2539 | * @param message the actual message | 2539 | * @param message the actual message |
2540 | * @return #GNUNET_OK to keep the connection open, | 2540 | * @return #GNUNET_OK to keep the connection open, |
2541 | * #GNUNET_SYSERR to close it (signal serious error) | 2541 | * #GNUNET_SYSERR to close it (signal serious error) |
2542 | */ | 2542 | */ |
2543 | static int | 2543 | static int |
2544 | receive_icmp_service (void *cls, | 2544 | receive_icmp_service (void *cls, |
2545 | struct GNUNET_MESH_Tunnel *tunnel, | 2545 | struct GNUNET_MESH_Channel *channel, |
2546 | void **tunnel_ctx, | 2546 | void **channel_ctx, |
2547 | const struct GNUNET_MessageHeader *message) | 2547 | const struct GNUNET_MessageHeader *message) |
2548 | { | 2548 | { |
2549 | struct TunnelState *state = *tunnel_ctx; | 2549 | struct ChannelState *state = *channel_ctx; |
2550 | const struct GNUNET_EXIT_IcmpServiceMessage *msg; | 2550 | const struct GNUNET_EXIT_IcmpServiceMessage *msg; |
2551 | uint16_t pkt_len = ntohs (message->size); | 2551 | uint16_t pkt_len = ntohs (message->size); |
2552 | struct GNUNET_TUN_IcmpHeader icmp; | 2552 | struct GNUNET_TUN_IcmpHeader icmp; |
@@ -2560,7 +2560,7 @@ receive_icmp_service (void *cls, | |||
2560 | } | 2560 | } |
2561 | if (GNUNET_SYSERR == state->is_dns) | 2561 | if (GNUNET_SYSERR == state->is_dns) |
2562 | { | 2562 | { |
2563 | /* tunnel is UDP/TCP from now on */ | 2563 | /* channel is UDP/TCP from now on */ |
2564 | state->is_dns = GNUNET_NO; | 2564 | state->is_dns = GNUNET_NO; |
2565 | } | 2565 | } |
2566 | GNUNET_STATISTICS_update (stats, | 2566 | GNUNET_STATISTICS_update (stats, |
@@ -2822,19 +2822,19 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address, | |||
2822 | * Process a request to forward UDP data to the Internet via this peer. | 2822 | * Process a request to forward UDP data to the Internet via this peer. |
2823 | * | 2823 | * |
2824 | * @param cls closure, NULL | 2824 | * @param cls closure, NULL |
2825 | * @param tunnel connection to the other end | 2825 | * @param channel connection to the other end |
2826 | * @param tunnel_ctx pointer to our 'struct TunnelState *' | 2826 | * @param channel_ctx pointer to our 'struct ChannelState *' |
2827 | * @param message the actual message | 2827 | * @param message the actual message |
2828 | * @return #GNUNET_OK to keep the connection open, | 2828 | * @return #GNUNET_OK to keep the connection open, |
2829 | * #GNUNET_SYSERR to close it (signal serious error) | 2829 | * #GNUNET_SYSERR to close it (signal serious error) |
2830 | */ | 2830 | */ |
2831 | static int | 2831 | static int |
2832 | receive_udp_remote (void *cls, | 2832 | receive_udp_remote (void *cls, |
2833 | struct GNUNET_MESH_Tunnel *tunnel, | 2833 | struct GNUNET_MESH_Channel *channel, |
2834 | void **tunnel_ctx, | 2834 | void **channel_ctx, |
2835 | const struct GNUNET_MessageHeader *message) | 2835 | const struct GNUNET_MessageHeader *message) |
2836 | { | 2836 | { |
2837 | struct TunnelState *state = *tunnel_ctx; | 2837 | struct ChannelState *state = *channel_ctx; |
2838 | const struct GNUNET_EXIT_UdpInternetMessage *msg; | 2838 | const struct GNUNET_EXIT_UdpInternetMessage *msg; |
2839 | uint16_t pkt_len = ntohs (message->size); | 2839 | uint16_t pkt_len = ntohs (message->size); |
2840 | const struct in_addr *v4; | 2840 | const struct in_addr *v4; |
@@ -2849,7 +2849,7 @@ receive_udp_remote (void *cls, | |||
2849 | } | 2849 | } |
2850 | if (GNUNET_SYSERR == state->is_dns) | 2850 | if (GNUNET_SYSERR == state->is_dns) |
2851 | { | 2851 | { |
2852 | /* tunnel is UDP/TCP from now on */ | 2852 | /* channel is UDP/TCP from now on */ |
2853 | state->is_dns = GNUNET_NO; | 2853 | state->is_dns = GNUNET_NO; |
2854 | } | 2854 | } |
2855 | GNUNET_STATISTICS_update (stats, | 2855 | GNUNET_STATISTICS_update (stats, |
@@ -2933,19 +2933,19 @@ receive_udp_remote (void *cls, | |||
2933 | * offered by this system. | 2933 | * offered by this system. |
2934 | * | 2934 | * |
2935 | * @param cls closure, NULL | 2935 | * @param cls closure, NULL |
2936 | * @param tunnel connection to the other end | 2936 | * @param channel connection to the other end |
2937 | * @param tunnel_ctx pointer to our 'struct TunnelState *' | 2937 | * @param channel_ctx pointer to our 'struct ChannelState *' |
2938 | * @param message the actual message | 2938 | * @param message the actual message |
2939 | * @return #GNUNET_OK to keep the connection open, | 2939 | * @return #GNUNET_OK to keep the connection open, |
2940 | * #GNUNET_SYSERR to close it (signal serious error) | 2940 | * #GNUNET_SYSERR to close it (signal serious error) |
2941 | */ | 2941 | */ |
2942 | static int | 2942 | static int |
2943 | receive_udp_service (void *cls, | 2943 | receive_udp_service (void *cls, |
2944 | struct GNUNET_MESH_Tunnel *tunnel, | 2944 | struct GNUNET_MESH_Channel *channel, |
2945 | void **tunnel_ctx, | 2945 | void **channel_ctx, |
2946 | const struct GNUNET_MessageHeader *message) | 2946 | const struct GNUNET_MessageHeader *message) |
2947 | { | 2947 | { |
2948 | struct TunnelState *state = *tunnel_ctx; | 2948 | struct ChannelState *state = *channel_ctx; |
2949 | const struct GNUNET_EXIT_UdpServiceMessage *msg; | 2949 | const struct GNUNET_EXIT_UdpServiceMessage *msg; |
2950 | uint16_t pkt_len = ntohs (message->size); | 2950 | uint16_t pkt_len = ntohs (message->size); |
2951 | 2951 | ||
@@ -2956,7 +2956,7 @@ receive_udp_service (void *cls, | |||
2956 | } | 2956 | } |
2957 | if (GNUNET_SYSERR == state->is_dns) | 2957 | if (GNUNET_SYSERR == state->is_dns) |
2958 | { | 2958 | { |
2959 | /* tunnel is UDP/TCP from now on */ | 2959 | /* channel is UDP/TCP from now on */ |
2960 | state->is_dns = GNUNET_NO; | 2960 | state->is_dns = GNUNET_NO; |
2961 | } | 2961 | } |
2962 | GNUNET_STATISTICS_update (stats, | 2962 | GNUNET_STATISTICS_update (stats, |
@@ -3002,54 +3002,54 @@ receive_udp_service (void *cls, | |||
3002 | 3002 | ||
3003 | 3003 | ||
3004 | /** | 3004 | /** |
3005 | * Callback from GNUNET_MESH for new tunnels. | 3005 | * Callback from GNUNET_MESH for new channels. |
3006 | * | 3006 | * |
3007 | * @param cls closure | 3007 | * @param cls closure |
3008 | * @param tunnel new handle to the tunnel | 3008 | * @param channel new handle to the channel |
3009 | * @param initiator peer that started the tunnel | 3009 | * @param initiator peer that started the channel |
3010 | * @param port destination port | 3010 | * @param port destination port |
3011 | * @return initial tunnel context for the tunnel | 3011 | * @return initial channel context for the channel |
3012 | */ | 3012 | */ |
3013 | static void * | 3013 | static void * |
3014 | new_tunnel (void *cls, | 3014 | new_channel (void *cls, |
3015 | struct GNUNET_MESH_Tunnel *tunnel, | 3015 | struct GNUNET_MESH_Channel *channel, |
3016 | const struct GNUNET_PeerIdentity *initiator, | 3016 | const struct GNUNET_PeerIdentity *initiator, |
3017 | uint32_t port) | 3017 | uint32_t port) |
3018 | { | 3018 | { |
3019 | struct TunnelState *s = GNUNET_new (struct TunnelState); | 3019 | struct ChannelState *s = GNUNET_new (struct ChannelState); |
3020 | 3020 | ||
3021 | s->is_dns = GNUNET_SYSERR; | 3021 | s->is_dns = GNUNET_SYSERR; |
3022 | s->peer = *initiator; | 3022 | s->peer = *initiator; |
3023 | GNUNET_STATISTICS_update (stats, | 3023 | GNUNET_STATISTICS_update (stats, |
3024 | gettext_noop ("# Inbound MESH tunnels created"), | 3024 | gettext_noop ("# Inbound MESH channels created"), |
3025 | 1, GNUNET_NO); | 3025 | 1, GNUNET_NO); |
3026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3027 | "Received inbound tunnel from `%s'\n", | 3027 | "Received inbound channel from `%s'\n", |
3028 | GNUNET_i2s (initiator)); | 3028 | GNUNET_i2s (initiator)); |
3029 | s->tunnel = tunnel; | 3029 | s->channel = channel; |
3030 | return s; | 3030 | return s; |
3031 | } | 3031 | } |
3032 | 3032 | ||
3033 | 3033 | ||
3034 | /** | 3034 | /** |
3035 | * Function called by mesh whenever an inbound tunnel is destroyed. | 3035 | * Function called by mesh whenever an inbound channel is destroyed. |
3036 | * Should clean up any associated state. | 3036 | * Should clean up any associated state. |
3037 | * | 3037 | * |
3038 | * @param cls closure (set from #GNUNET_MESH_connect) | 3038 | * @param cls closure (set from #GNUNET_MESH_connect) |
3039 | * @param tunnel connection to the other end (henceforth invalid) | 3039 | * @param channel connection to the other end (henceforth invalid) |
3040 | * @param tunnel_ctx place where local state associated | 3040 | * @param channel_ctx place where local state associated |
3041 | * with the tunnel is stored | 3041 | * with the channel is stored |
3042 | */ | 3042 | */ |
3043 | static void | 3043 | static void |
3044 | clean_tunnel (void *cls, | 3044 | clean_channel (void *cls, |
3045 | const struct GNUNET_MESH_Tunnel *tunnel, | 3045 | const struct GNUNET_MESH_Channel *channel, |
3046 | void *tunnel_ctx) | 3046 | void *channel_ctx) |
3047 | { | 3047 | { |
3048 | struct TunnelState *s = tunnel_ctx; | 3048 | struct ChannelState *s = channel_ctx; |
3049 | struct TunnelMessageQueue *tnq; | 3049 | struct ChannelMessageQueue *tnq; |
3050 | 3050 | ||
3051 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3051 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3052 | "Tunnel destroyed\n"); | 3052 | "Channel destroyed\n"); |
3053 | if (GNUNET_SYSERR == s->is_dns) | 3053 | if (GNUNET_SYSERR == s->is_dns) |
3054 | { | 3054 | { |
3055 | GNUNET_free (s); | 3055 | GNUNET_free (s); |
@@ -3057,8 +3057,8 @@ clean_tunnel (void *cls, | |||
3057 | } | 3057 | } |
3058 | if (GNUNET_YES == s->is_dns) | 3058 | if (GNUNET_YES == s->is_dns) |
3059 | { | 3059 | { |
3060 | if (tunnels[s->specifics.dns.my_id] == s) | 3060 | if (channels[s->specifics.dns.my_id] == s) |
3061 | tunnels[s->specifics.dns.my_id] = NULL; | 3061 | channels[s->specifics.dns.my_id] = NULL; |
3062 | GNUNET_free_non_null (s->specifics.dns.reply); | 3062 | GNUNET_free_non_null (s->specifics.dns.reply); |
3063 | } | 3063 | } |
3064 | else | 3064 | else |
@@ -3703,8 +3703,8 @@ run (void *cls, | |||
3703 | connections_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 3703 | connections_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
3704 | mesh_handle | 3704 | mesh_handle |
3705 | = GNUNET_MESH_connect (cfg, NULL, | 3705 | = GNUNET_MESH_connect (cfg, NULL, |
3706 | &new_tunnel, | 3706 | &new_channel, |
3707 | &clean_tunnel, handlers, | 3707 | &clean_channel, handlers, |
3708 | apptypes); // FIXME use ports | 3708 | apptypes); // FIXME use ports |
3709 | if (NULL == mesh_handle) | 3709 | if (NULL == mesh_handle) |
3710 | { | 3710 | { |
diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index fa6382683..6819af655 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009, 2010, 2011, 2012, 2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2009 - 2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -19,13 +19,9 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file include/gnunet_mesh_service.h | 22 | * @file include/gnunet_mesh_service_enc.h |
23 | * @brief mesh service; establish tunnels to distant peers | 23 | * @brief mesh service; establish channels to distant peers |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * | ||
26 | * TODO: | ||
27 | * - need to do sanity check that this is consistent | ||
28 | * with current ideas for the multicast layer's needs | ||
29 | */ | 25 | */ |
30 | 26 | ||
31 | #ifndef GNUNET_MESH_SERVICE_H | 27 | #ifndef GNUNET_MESH_SERVICE_H |
@@ -45,7 +41,7 @@ extern "C" | |||
45 | /** | 41 | /** |
46 | * Version number of GNUnet-mesh API. | 42 | * Version number of GNUnet-mesh API. |
47 | */ | 43 | */ |
48 | #define GNUNET_MESH_VERSION 0x00000002 | 44 | #define GNUNET_MESH_VERSION 0x00000003 |
49 | 45 | ||
50 | 46 | ||
51 | /** | 47 | /** |
@@ -54,16 +50,16 @@ extern "C" | |||
54 | struct GNUNET_MESH_Handle; | 50 | struct GNUNET_MESH_Handle; |
55 | 51 | ||
56 | /** | 52 | /** |
57 | * Opaque handle to a tunnel. | 53 | * Opaque handle to a channel. |
58 | */ | 54 | */ |
59 | struct GNUNET_MESH_Tunnel; | 55 | struct GNUNET_MESH_Channel; |
60 | 56 | ||
61 | 57 | ||
62 | /** | 58 | /** |
63 | * Options for querying a tunnel. | 59 | * Channel options. |
64 | * Second line indicates filed in the MeshTunnelInfo union carrying the answer. | 60 | * Second line indicates filed in the MeshChannelInfo union carrying the answer. |
65 | */ | 61 | */ |
66 | enum MeshTunnelOption | 62 | enum MeshOption |
67 | { | 63 | { |
68 | /** | 64 | /** |
69 | * Disable buffering on intermediate nodes (for minimum latency). | 65 | * Disable buffering on intermediate nodes (for minimum latency). |
@@ -72,7 +68,7 @@ enum MeshTunnelOption | |||
72 | GNUNET_MESH_OPTION_NOBUFFER = 0x1, | 68 | GNUNET_MESH_OPTION_NOBUFFER = 0x1, |
73 | 69 | ||
74 | /** | 70 | /** |
75 | * Enable tunnel reliability, lost messages will be retransmitted. | 71 | * Enable channel reliability, lost messages will be retransmitted. |
76 | * Yes/No. | 72 | * Yes/No. |
77 | */ | 73 | */ |
78 | GNUNET_MESH_OPTION_RELIABLE = 0x2, | 74 | GNUNET_MESH_OPTION_RELIABLE = 0x2, |
@@ -84,7 +80,7 @@ enum MeshTunnelOption | |||
84 | GNUNET_MESH_OPTION_OOORDER = 0x4, | 80 | GNUNET_MESH_OPTION_OOORDER = 0x4, |
85 | 81 | ||
86 | /** | 82 | /** |
87 | * Who is the peer at the other end of the tunnel. | 83 | * Who is the peer at the other end of the channel. |
88 | * struct GNUNET_PeerIdentity *peer | 84 | * struct GNUNET_PeerIdentity *peer |
89 | */ | 85 | */ |
90 | GNUNET_MESH_OPTION_PEER = 0x8 | 86 | GNUNET_MESH_OPTION_PEER = 0x8 |
@@ -96,21 +92,20 @@ enum MeshTunnelOption | |||
96 | * Functions with this signature are called whenever a message is | 92 | * Functions with this signature are called whenever a message is |
97 | * received. | 93 | * received. |
98 | * | 94 | * |
99 | * Each time the function must call #GNUNET_MESH_receive_done on the tunnel | 95 | * Each time the function must call #GNUNET_MESH_receive_done on the channel |
100 | * in order to receive the next message. This doesn't need to be immediate: | 96 | * in order to receive the next message. This doesn't need to be immediate: |
101 | * can be delayed if some processing is done on the message. | 97 | * can be delayed if some processing is done on the message. |
102 | * | 98 | * |
103 | * @param cls Closure (set from #GNUNET_MESH_connect). | 99 | * @param cls Closure (set from #GNUNET_MESH_connect). |
104 | * @param tunnel Connection to the other end. | 100 | * @param channel Connection to the other end. |
105 | * @param tunnel_ctx Place to store local state associated with the tunnel. | 101 | * @param channel_ctx Place to store local state associated with the channel. |
106 | * @param message The actual message. | 102 | * @param message The actual message. |
107 | * | 103 | * @return #GNUNET_OK to keep the channel open, |
108 | * @return #GNUNET_OK to keep the tunnel open, | ||
109 | * #GNUNET_SYSERR to close it (signal serious error). | 104 | * #GNUNET_SYSERR to close it (signal serious error). |
110 | */ | 105 | */ |
111 | typedef int (*GNUNET_MESH_MessageCallback) (void *cls, | 106 | typedef int (*GNUNET_MESH_MessageCallback) (void *cls, |
112 | struct GNUNET_MESH_Tunnel *tunnel, | 107 | struct GNUNET_MESH_Channel *channel, |
113 | void **tunnel_ctx, | 108 | void **channel_ctx, |
114 | const struct GNUNET_MessageHeader *message); | 109 | const struct GNUNET_MessageHeader *message); |
115 | 110 | ||
116 | 111 | ||
@@ -140,42 +135,45 @@ struct GNUNET_MESH_MessageHandler | |||
140 | 135 | ||
141 | 136 | ||
142 | /** | 137 | /** |
143 | * Method called whenever another peer has added us to a tunnel | 138 | * Method called whenever another peer has added us to a channel |
144 | * the other peer initiated. | 139 | * the other peer initiated. |
145 | * Only called (once) upon reception of data with a message type which was | 140 | * Only called (once) upon reception of data with a message type which was |
146 | * subscribed to in #GNUNET_MESH_connect. A call to #GNUNET_MESH_tunnel_destroy | 141 | * subscribed to in #GNUNET_MESH_connect. A call to #GNUNET_MESH_channel_destroy |
147 | * causes te tunnel to be ignored and no further notifications are sent about | 142 | * causes te channel to be ignored and no further notifications are sent about |
148 | * the same tunnel. | 143 | * the same channel. |
149 | * | 144 | * |
150 | * @param cls closure | 145 | * @param cls closure |
151 | * @param tunnel new handle to the tunnel | 146 | * @param channel new handle to the channel |
152 | * @param initiator peer that started the tunnel | 147 | * @param initiator peer that started the channel |
153 | * @param port Port this tunnel is for. | 148 | * @param port Port this channel is for. |
154 | * @return initial tunnel context for the tunnel | 149 | * @return initial channel context for the channel |
155 | * (can be NULL -- that's not an error) | 150 | * (can be NULL -- that's not an error) |
156 | */ | 151 | */ |
157 | typedef void *(GNUNET_MESH_InboundTunnelNotificationHandler) (void *cls, | 152 | typedef void *(GNUNET_MESH_InboundChannelNotificationHandler) (void *cls, |
158 | struct GNUNET_MESH_Tunnel *tunnel, | 153 | struct |
159 | const struct | 154 | GNUNET_MESH_Channel |
160 | GNUNET_PeerIdentity | 155 | * channel, |
161 | * initiator, | 156 | const struct |
162 | uint32_t port); | 157 | GNUNET_PeerIdentity |
158 | * initiator, | ||
159 | uint32_t port); | ||
163 | 160 | ||
164 | 161 | ||
165 | /** | 162 | /** |
166 | * Function called whenever a tunnel is destroyed. Should clean up | 163 | * Function called whenever a channel is destroyed. Should clean up |
167 | * any associated state. | 164 | * any associated state. |
168 | * | 165 | * |
169 | * It must NOT call #GNUNET_MESH_tunnel_destroy on the tunnel. | 166 | * It must NOT call #GNUNET_MESH_channel_destroy on the channel. |
170 | * | 167 | * |
171 | * @param cls closure (set from #GNUNET_MESH_connect) | 168 | * @param cls closure (set from #GNUNET_MESH_connect) |
172 | * @param tunnel connection to the other end (henceforth invalid) | 169 | * @param channel connection to the other end (henceforth invalid) |
173 | * @param tunnel_ctx place where local state associated | 170 | * @param channel_ctx place where local state associated |
174 | * with the tunnel is stored | 171 | * with the channel is stored |
175 | */ | 172 | */ |
176 | typedef void (GNUNET_MESH_TunnelEndHandler) (void *cls, | 173 | typedef void (GNUNET_MESH_ChannelEndHandler) (void *cls, |
177 | const struct GNUNET_MESH_Tunnel * | 174 | const struct GNUNET_MESH_Channel * |
178 | tunnel, void *tunnel_ctx); | 175 | channel, |
176 | void *channel_ctx); | ||
179 | 177 | ||
180 | 178 | ||
181 | /** | 179 | /** |
@@ -184,36 +182,35 @@ typedef void (GNUNET_MESH_TunnelEndHandler) (void *cls, | |||
184 | * @param cfg Configuration to use. | 182 | * @param cfg Configuration to use. |
185 | * @param cls Closure for the various callbacks that follow (including | 183 | * @param cls Closure for the various callbacks that follow (including |
186 | * handlers in the handlers array). | 184 | * handlers in the handlers array). |
187 | * @param new_tunnel Function called when an *incoming* tunnel is created. | 185 | * @param new_channel Function called when an *incoming* channel is created. |
188 | * Can be NULL if no inbound tunnels are desired. | 186 | * Can be NULL if no inbound channels are desired. |
189 | * See @c ports. | 187 | * See @a ports. |
190 | * @param cleaner Function called when a tunnel is destroyed by the remote peer. | 188 | * @param cleaner Function called when a channel is destroyed by the remote peer. |
191 | * It is NOT called if #GNUNET_MESH_tunnel_destroy is called on | 189 | * It is NOT called if #GNUNET_MESH_channel_destroy is called on |
192 | * the tunnel. | 190 | * the channel. |
193 | * @param handlers Callbacks for messages we care about, NULL-terminated. Each | 191 | * @param handlers Callbacks for messages we care about, NULL-terminated. Each |
194 | * one must call #GNUNET_MESH_receive_done on the tunnel to | 192 | * one must call #GNUNET_MESH_receive_done on the channel to |
195 | * receive the next message. Messages of a type that is not | 193 | * receive the next message. Messages of a type that is not |
196 | * in the handlers array are ignored if received. | 194 | * in the handlers array are ignored if received. |
197 | * @param ports NULL or 0-terminated array of port numbers for incoming tunnels. | 195 | * @param ports NULL or 0-terminated array of port numbers for incoming channels. |
198 | * See @c new_tunnel. | 196 | * See @a new_channel. |
199 | * | 197 | * |
200 | * @return handle to the mesh service NULL on error | 198 | * @return handle to the mesh service NULL on error |
201 | * (in this case, init is never called) | 199 | * (in this case, init is never called) |
202 | */ | 200 | */ |
203 | struct GNUNET_MESH_Handle * | 201 | struct GNUNET_MESH_Handle * |
204 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 202 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, |
205 | void *cls, | 203 | GNUNET_MESH_InboundChannelNotificationHandler new_channel, |
206 | GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, | 204 | GNUNET_MESH_ChannelEndHandler cleaner, |
207 | GNUNET_MESH_TunnelEndHandler cleaner, | ||
208 | const struct GNUNET_MESH_MessageHandler *handlers, | 205 | const struct GNUNET_MESH_MessageHandler *handlers, |
209 | const uint32_t *ports); | 206 | const uint32_t *ports); |
210 | 207 | ||
211 | 208 | ||
212 | /** | 209 | /** |
213 | * Disconnect from the mesh service. All tunnels will be destroyed. All tunnel | 210 | * Disconnect from the mesh service. All channels will be destroyed. All channel |
214 | * disconnect callbacks will be called on any still connected peers, notifying | 211 | * disconnect callbacks will be called on any still connected peers, notifying |
215 | * about their disconnection. The registered inbound tunnel cleaner will be | 212 | * about their disconnection. The registered inbound channel cleaner will be |
216 | * called should any inbound tunnels still exist. | 213 | * called should any inbound channels still exist. |
217 | * | 214 | * |
218 | * @param handle connection to mesh to disconnect | 215 | * @param handle connection to mesh to disconnect |
219 | */ | 216 | */ |
@@ -222,43 +219,46 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle); | |||
222 | 219 | ||
223 | 220 | ||
224 | /** | 221 | /** |
225 | * Create a new tunnel (we're initiator and will be allowed to add/remove peers | 222 | * Create a new channel towards a remote peer. |
226 | * and to broadcast). | 223 | * |
224 | * If the destination port is not open by any peer or the destination peer | ||
225 | * does not accept the channel, #GNUNET_MESH_ChannelEndHandler will be called | ||
226 | * for this channel. | ||
227 | * | 227 | * |
228 | * @param h mesh handle | 228 | * @param h mesh handle |
229 | * @param tunnel_ctx client's tunnel context to associate with the tunnel | 229 | * @param channel_ctx client's channel context to associate with the channel |
230 | * @param peer peer identity the tunnel should go to | 230 | * @param peer peer identity the channel should go to |
231 | * @param port Port number. | 231 | * @param port Port number. |
232 | * @param nobuffer Flag for disabling buffering on relay nodes. | 232 | * @param nobuffer Flag for disabling buffering on relay nodes. |
233 | * @param reliable Flag for end-to-end reliability. | 233 | * @param reliable Flag for end-to-end reliability. |
234 | * @return handle to the tunnel | 234 | * @return handle to the channel |
235 | */ | 235 | */ |
236 | struct GNUNET_MESH_Tunnel * | 236 | struct GNUNET_MESH_Channel * |
237 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | 237 | GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h, |
238 | void *tunnel_ctx, | 238 | void *channel_ctx, |
239 | const struct GNUNET_PeerIdentity *peer, | 239 | const struct GNUNET_PeerIdentity *peer, |
240 | uint32_t port, | 240 | uint32_t port, |
241 | int nobuffer, | 241 | int nobuffer, |
242 | int reliable); | 242 | int reliable); |
243 | 243 | ||
244 | 244 | ||
245 | /** | 245 | /** |
246 | * Destroy an existing tunnel. | 246 | * Destroy an existing channel. |
247 | * | 247 | * |
248 | * The existing end callback for the tunnel will be called immediately. | 248 | * The existing end callback for the channel will be called immediately. |
249 | * Any pending outgoing messages will be sent but no incoming messages will be | 249 | * Any pending outgoing messages will be sent but no incoming messages will be |
250 | * accepted and no data callbacks will be called. | 250 | * accepted and no data callbacks will be called. |
251 | * | 251 | * |
252 | * @param tunnel Tunnel handle, becomes invalid after this call. | 252 | * @param channel Channel handle, becomes invalid after this call. |
253 | */ | 253 | */ |
254 | void | 254 | void |
255 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel); | 255 | GNUNET_MESH_channel_destroy (struct GNUNET_MESH_Channel *channel); |
256 | 256 | ||
257 | 257 | ||
258 | /** | 258 | /** |
259 | * Struct to retrieve info about a tunnel. | 259 | * Struct to retrieve info about a channel. |
260 | */ | 260 | */ |
261 | union GNUNET_MESH_TunnelInfo | 261 | union GNUNET_MESH_ChannelInfo |
262 | { | 262 | { |
263 | 263 | ||
264 | /** | 264 | /** |
@@ -267,24 +267,23 @@ union GNUNET_MESH_TunnelInfo | |||
267 | int yes_no; | 267 | int yes_no; |
268 | 268 | ||
269 | /** | 269 | /** |
270 | * Peer on the other side of the tunnel | 270 | * Peer on the other side of the channel |
271 | */ | 271 | */ |
272 | const struct GNUNET_PeerIdentity peer; | 272 | const struct GNUNET_PeerIdentity *peer; |
273 | }; | 273 | }; |
274 | 274 | ||
275 | 275 | ||
276 | /** | 276 | /** |
277 | * Get information about a tunnel. | 277 | * Get information about a channel. |
278 | * | 278 | * |
279 | * @param tunnel Tunnel handle. | 279 | * @param channel Channel handle. |
280 | * @param option Query, as listed in src/mesh/mesh.h (GNUNET_MESH_OPTION_*) | 280 | * @param option Query type GNUNET_MESH_OPTION_* |
281 | * @param ... dependant on option, currently not used | 281 | * @param ... dependant on option, currently not used |
282 | * | ||
283 | * @return Union with an answer to the query. | 282 | * @return Union with an answer to the query. |
284 | */ | 283 | */ |
285 | const union GNUNET_MESH_TunnelInfo * | 284 | const union GNUNET_MESH_ChannelInfo * |
286 | GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel, | 285 | GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel, |
287 | enum MeshTunnelOption option, ...); | 286 | enum MeshOption option, ...); |
288 | 287 | ||
289 | 288 | ||
290 | /** | 289 | /** |
@@ -295,14 +294,14 @@ struct GNUNET_MESH_TransmitHandle; | |||
295 | 294 | ||
296 | /** | 295 | /** |
297 | * Ask the mesh to call @a notify once it is ready to transmit the | 296 | * Ask the mesh to call @a notify once it is ready to transmit the |
298 | * given number of bytes to the specified tunnel. | 297 | * given number of bytes to the specified channel. |
299 | * Only one call can be active at any time, to issue another request, | 298 | * Only one call can be active at any time, to issue another request, |
300 | * wait for the callback or cancel the current request. | 299 | * wait for the callback or cancel the current request. |
301 | * | 300 | * |
302 | * @param tunnel tunnel to use for transmission | 301 | * @param channel channel to use for transmission |
303 | * @param cork is corking allowed for this transmission? | 302 | * @param cork is corking allowed for this transmission? |
304 | * @param maxdelay how long can the message wait? | 303 | * @param maxdelay how long can the message wait? |
305 | * @param notify_size how many bytes of buffer space does @a notify want? | 304 | * @param notify_size how many bytes of buffer space does notify want? |
306 | * @param notify function to call when buffer space is available; | 305 | * @param notify function to call when buffer space is available; |
307 | * will be called with NULL on timeout or if the overall queue | 306 | * will be called with NULL on timeout or if the overall queue |
308 | * for this peer is larger than queue_size and this is currently | 307 | * for this peer is larger than queue_size and this is currently |
@@ -310,10 +309,11 @@ struct GNUNET_MESH_TransmitHandle; | |||
310 | * @param notify_cls closure for @a notify | 309 | * @param notify_cls closure for @a notify |
311 | * @return non-NULL if the notify callback was queued, | 310 | * @return non-NULL if the notify callback was queued, |
312 | * NULL if we can not even queue the request (insufficient | 311 | * NULL if we can not even queue the request (insufficient |
313 | * memory); if NULL is returned, "notify" will NOT be called. | 312 | * memory); if NULL is returned, @a notify will NOT be called. |
314 | */ | 313 | */ |
315 | struct GNUNET_MESH_TransmitHandle * | 314 | struct GNUNET_MESH_TransmitHandle * |
316 | GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | 315 | GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Channel *channel, |
316 | int cork, | ||
317 | struct GNUNET_TIME_Relative maxdelay, | 317 | struct GNUNET_TIME_Relative maxdelay, |
318 | size_t notify_size, | 318 | size_t notify_size, |
319 | GNUNET_CONNECTION_TransmitReadyNotify notify, | 319 | GNUNET_CONNECTION_TransmitReadyNotify notify, |
@@ -331,14 +331,14 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle | |||
331 | 331 | ||
332 | 332 | ||
333 | /** | 333 | /** |
334 | * Indicate readiness to receive the next message on a tunnel. | 334 | * Indicate readiness to receive the next message on a channel. |
335 | * | 335 | * |
336 | * Should only be called once per handler called. | 336 | * Should only be called once per handler called. |
337 | * | 337 | * |
338 | * @param tunnel Tunnel that will be allowed to call another handler. | 338 | * @param channel Channel that will be allowed to call another handler. |
339 | */ | 339 | */ |
340 | void | 340 | void |
341 | GNUNET_MESH_receive_done (struct GNUNET_MESH_Tunnel *tunnel); | 341 | GNUNET_MESH_receive_done (struct GNUNET_MESH_Channel *channel); |
342 | 342 | ||
343 | 343 | ||
344 | 344 | ||
@@ -353,37 +353,37 @@ GNUNET_MESH_receive_done (struct GNUNET_MESH_Tunnel *tunnel); | |||
353 | /******************************************************************************/ | 353 | /******************************************************************************/ |
354 | 354 | ||
355 | /** | 355 | /** |
356 | * Method called to retrieve information about each tunnel the mesh peer | 356 | * Method called to retrieve information about each channel the mesh peer |
357 | * is aware of. | 357 | * is aware of. |
358 | * | 358 | * |
359 | * @param cls Closure. | 359 | * @param cls Closure. |
360 | * @param tunnel_number Tunnel number. | 360 | * @param channel_number Channel number. |
361 | * @param origin that started the tunnel (owner). | 361 | * @param origin that started the channel (owner). |
362 | * @param target other endpoint of the tunnel | 362 | * @param target other endpoint of the channel |
363 | */ | 363 | */ |
364 | typedef void (*GNUNET_MESH_TunnelsCB) (void *cls, | 364 | typedef void (*GNUNET_MESH_ChannelsCB) (void *cls, |
365 | uint32_t tunnel_number, | 365 | uint32_t channel_number, |
366 | const struct GNUNET_PeerIdentity *origin, | 366 | const struct GNUNET_PeerIdentity *origin, |
367 | const struct GNUNET_PeerIdentity *target); | 367 | const struct GNUNET_PeerIdentity *target); |
368 | 368 | ||
369 | 369 | ||
370 | /** | 370 | /** |
371 | * Method called to retrieve information about a specific tunnel the mesh peer | 371 | * Method called to retrieve information about a specific channel the mesh peer |
372 | * is aware of, including all transit nodes. | 372 | * is aware of, including all transit nodes. |
373 | * | 373 | * |
374 | * @param cls Closure. | 374 | * @param cls Closure. |
375 | * @param peer Peer in the tunnel's tree. | 375 | * @param peer Peer in the channel's tree. |
376 | * @param parent Parent of the current peer. All 0 when peer is root. | 376 | * @param parent Parent of the current peer. All 0 when peer is root. |
377 | */ | 377 | */ |
378 | typedef void (*GNUNET_MESH_TunnelCB) (void *cls, | 378 | typedef void (*GNUNET_MESH_ChannelCB) (void *cls, |
379 | const struct GNUNET_PeerIdentity *peer, | 379 | const struct GNUNET_PeerIdentity *peer, |
380 | const struct GNUNET_PeerIdentity *parent); | 380 | const struct GNUNET_PeerIdentity *parent); |
381 | 381 | ||
382 | 382 | ||
383 | /** | 383 | /** |
384 | * Request information about the running mesh peer. | 384 | * Request information about the running mesh peer. |
385 | * The callback will be called for every tunnel known to the service, | 385 | * The callback will be called for every channel known to the service, |
386 | * listing all active peers that belong to the tunnel. | 386 | * listing all active peers that belong to the channel. |
387 | * | 387 | * |
388 | * If called again on the same handle, it will overwrite the previous | 388 | * If called again on the same handle, it will overwrite the previous |
389 | * callback and cls. To retrieve the cls, monitor_cancel must be | 389 | * callback and cls. To retrieve the cls, monitor_cancel must be |
@@ -396,27 +396,27 @@ typedef void (*GNUNET_MESH_TunnelCB) (void *cls, | |||
396 | * @param callback_cls Closure for @c callback. | 396 | * @param callback_cls Closure for @c callback. |
397 | */ | 397 | */ |
398 | void | 398 | void |
399 | GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h, | 399 | GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h, |
400 | GNUNET_MESH_TunnelsCB callback, | 400 | GNUNET_MESH_ChannelsCB callback, |
401 | void *callback_cls); | 401 | void *callback_cls); |
402 | 402 | ||
403 | 403 | ||
404 | /** | 404 | /** |
405 | * Request information about a specific tunnel of the running mesh peer. | 405 | * Request information about a specific channel of the running mesh peer. |
406 | * | 406 | * |
407 | * WARNING: unstable API, likely to change in the future! | 407 | * WARNING: unstable API, likely to change in the future! |
408 | * | 408 | * |
409 | * @param h Handle to the mesh peer. | 409 | * @param h Handle to the mesh peer. |
410 | * @param initiator ID of the owner of the tunnel. | 410 | * @param initiator ID of the owner of the channel. |
411 | * @param tunnel_number Tunnel number. | 411 | * @param channel_number Channel number. |
412 | * @param callback Function to call with the requested data. | 412 | * @param callback Function to call with the requested data. |
413 | * @param callback_cls Closure for @a callback. | 413 | * @param callback_cls Closure for @c callback. |
414 | */ | 414 | */ |
415 | void | 415 | void |
416 | GNUNET_MESH_show_tunnel (struct GNUNET_MESH_Handle *h, | 416 | GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h, |
417 | struct GNUNET_PeerIdentity *initiator, | 417 | struct GNUNET_PeerIdentity *initiator, |
418 | uint32_t tunnel_number, | 418 | uint32_t channel_number, |
419 | GNUNET_MESH_TunnelCB callback, | 419 | GNUNET_MESH_ChannelCB callback, |
420 | void *callback_cls); | 420 | void *callback_cls); |
421 | 421 | ||
422 | 422 | ||
@@ -430,19 +430,19 @@ GNUNET_MESH_show_tunnel (struct GNUNET_MESH_Handle *h, | |||
430 | * @return Closure given to GNUNET_MESH_monitor, if any. | 430 | * @return Closure given to GNUNET_MESH_monitor, if any. |
431 | */ | 431 | */ |
432 | void * | 432 | void * |
433 | GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h); | 433 | GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h); |
434 | 434 | ||
435 | 435 | ||
436 | /** | 436 | /** |
437 | * Create a message queue for a mesh tunnel. | 437 | * Create a message queue for a mesh channel. |
438 | * The message queue can only be used to transmit messages, | 438 | * The message queue can only be used to transmit messages, |
439 | * not to receive them. | 439 | * not to receive them. |
440 | * | 440 | * |
441 | * @param tunnel the tunnel to create the message queue for | 441 | * @param channel the channel to create the message qeue for |
442 | * @return a message queue for sending messages over the tunnel | 442 | * @return a message queue to messages over the channel |
443 | */ | 443 | */ |
444 | struct GNUNET_MQ_Handle * | 444 | struct GNUNET_MQ_Handle * |
445 | GNUNET_MESH_mq_create (struct GNUNET_MESH_Tunnel *tunnel); | 445 | GNUNET_MESH_mq_create (struct GNUNET_MESH_Channel *channel); |
446 | 446 | ||
447 | 447 | ||
448 | #if 0 /* keep Emacsens' auto-indent happy */ | 448 | #if 0 /* keep Emacsens' auto-indent happy */ |
diff --git a/src/include/gnunet_mesh_service_enc.h b/src/include/gnunet_mesh_service_enc.h deleted file mode 100644 index 6819af655..000000000 --- a/src/include/gnunet_mesh_service_enc.h +++ /dev/null | |||
@@ -1,457 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 - 2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file include/gnunet_mesh_service_enc.h | ||
23 | * @brief mesh service; establish channels to distant peers | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_MESH_SERVICE_H | ||
28 | #define GNUNET_MESH_SERVICE_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_util_lib.h" | ||
39 | #include "gnunet_transport_service.h" | ||
40 | |||
41 | /** | ||
42 | * Version number of GNUnet-mesh API. | ||
43 | */ | ||
44 | #define GNUNET_MESH_VERSION 0x00000003 | ||
45 | |||
46 | |||
47 | /** | ||
48 | * Opaque handle to the service. | ||
49 | */ | ||
50 | struct GNUNET_MESH_Handle; | ||
51 | |||
52 | /** | ||
53 | * Opaque handle to a channel. | ||
54 | */ | ||
55 | struct GNUNET_MESH_Channel; | ||
56 | |||
57 | |||
58 | /** | ||
59 | * Channel options. | ||
60 | * Second line indicates filed in the MeshChannelInfo union carrying the answer. | ||
61 | */ | ||
62 | enum MeshOption | ||
63 | { | ||
64 | /** | ||
65 | * Disable buffering on intermediate nodes (for minimum latency). | ||
66 | * Yes/No. | ||
67 | */ | ||
68 | GNUNET_MESH_OPTION_NOBUFFER = 0x1, | ||
69 | |||
70 | /** | ||
71 | * Enable channel reliability, lost messages will be retransmitted. | ||
72 | * Yes/No. | ||
73 | */ | ||
74 | GNUNET_MESH_OPTION_RELIABLE = 0x2, | ||
75 | |||
76 | /** | ||
77 | * Enable out of order delivery of messages. | ||
78 | * Yes/No. | ||
79 | */ | ||
80 | GNUNET_MESH_OPTION_OOORDER = 0x4, | ||
81 | |||
82 | /** | ||
83 | * Who is the peer at the other end of the channel. | ||
84 | * struct GNUNET_PeerIdentity *peer | ||
85 | */ | ||
86 | GNUNET_MESH_OPTION_PEER = 0x8 | ||
87 | |||
88 | }; | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Functions with this signature are called whenever a message is | ||
93 | * received. | ||
94 | * | ||
95 | * Each time the function must call #GNUNET_MESH_receive_done on the channel | ||
96 | * in order to receive the next message. This doesn't need to be immediate: | ||
97 | * can be delayed if some processing is done on the message. | ||
98 | * | ||
99 | * @param cls Closure (set from #GNUNET_MESH_connect). | ||
100 | * @param channel Connection to the other end. | ||
101 | * @param channel_ctx Place to store local state associated with the channel. | ||
102 | * @param message The actual message. | ||
103 | * @return #GNUNET_OK to keep the channel open, | ||
104 | * #GNUNET_SYSERR to close it (signal serious error). | ||
105 | */ | ||
106 | typedef int (*GNUNET_MESH_MessageCallback) (void *cls, | ||
107 | struct GNUNET_MESH_Channel *channel, | ||
108 | void **channel_ctx, | ||
109 | const struct GNUNET_MessageHeader *message); | ||
110 | |||
111 | |||
112 | /** | ||
113 | * Message handler. Each struct specifies how to handle on particular | ||
114 | * type of message received. | ||
115 | */ | ||
116 | struct GNUNET_MESH_MessageHandler | ||
117 | { | ||
118 | /** | ||
119 | * Function to call for messages of "type". | ||
120 | */ | ||
121 | GNUNET_MESH_MessageCallback callback; | ||
122 | |||
123 | /** | ||
124 | * Type of the message this handler covers. | ||
125 | */ | ||
126 | uint16_t type; | ||
127 | |||
128 | /** | ||
129 | * Expected size of messages of this type. Use 0 for variable-size. | ||
130 | * If non-zero, messages of the given type will be discarded if they | ||
131 | * do not have the right size. | ||
132 | */ | ||
133 | uint16_t expected_size; | ||
134 | }; | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Method called whenever another peer has added us to a channel | ||
139 | * the other peer initiated. | ||
140 | * Only called (once) upon reception of data with a message type which was | ||
141 | * subscribed to in #GNUNET_MESH_connect. A call to #GNUNET_MESH_channel_destroy | ||
142 | * causes te channel to be ignored and no further notifications are sent about | ||
143 | * the same channel. | ||
144 | * | ||
145 | * @param cls closure | ||
146 | * @param channel new handle to the channel | ||
147 | * @param initiator peer that started the channel | ||
148 | * @param port Port this channel is for. | ||
149 | * @return initial channel context for the channel | ||
150 | * (can be NULL -- that's not an error) | ||
151 | */ | ||
152 | typedef void *(GNUNET_MESH_InboundChannelNotificationHandler) (void *cls, | ||
153 | struct | ||
154 | GNUNET_MESH_Channel | ||
155 | * channel, | ||
156 | const struct | ||
157 | GNUNET_PeerIdentity | ||
158 | * initiator, | ||
159 | uint32_t port); | ||
160 | |||
161 | |||
162 | /** | ||
163 | * Function called whenever a channel is destroyed. Should clean up | ||
164 | * any associated state. | ||
165 | * | ||
166 | * It must NOT call #GNUNET_MESH_channel_destroy on the channel. | ||
167 | * | ||
168 | * @param cls closure (set from #GNUNET_MESH_connect) | ||
169 | * @param channel connection to the other end (henceforth invalid) | ||
170 | * @param channel_ctx place where local state associated | ||
171 | * with the channel is stored | ||
172 | */ | ||
173 | typedef void (GNUNET_MESH_ChannelEndHandler) (void *cls, | ||
174 | const struct GNUNET_MESH_Channel * | ||
175 | channel, | ||
176 | void *channel_ctx); | ||
177 | |||
178 | |||
179 | /** | ||
180 | * Connect to the mesh service. | ||
181 | * | ||
182 | * @param cfg Configuration to use. | ||
183 | * @param cls Closure for the various callbacks that follow (including | ||
184 | * handlers in the handlers array). | ||
185 | * @param new_channel Function called when an *incoming* channel is created. | ||
186 | * Can be NULL if no inbound channels are desired. | ||
187 | * See @a ports. | ||
188 | * @param cleaner Function called when a channel is destroyed by the remote peer. | ||
189 | * It is NOT called if #GNUNET_MESH_channel_destroy is called on | ||
190 | * the channel. | ||
191 | * @param handlers Callbacks for messages we care about, NULL-terminated. Each | ||
192 | * one must call #GNUNET_MESH_receive_done on the channel to | ||
193 | * receive the next message. Messages of a type that is not | ||
194 | * in the handlers array are ignored if received. | ||
195 | * @param ports NULL or 0-terminated array of port numbers for incoming channels. | ||
196 | * See @a new_channel. | ||
197 | * | ||
198 | * @return handle to the mesh service NULL on error | ||
199 | * (in this case, init is never called) | ||
200 | */ | ||
201 | struct GNUNET_MESH_Handle * | ||
202 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | ||
203 | GNUNET_MESH_InboundChannelNotificationHandler new_channel, | ||
204 | GNUNET_MESH_ChannelEndHandler cleaner, | ||
205 | const struct GNUNET_MESH_MessageHandler *handlers, | ||
206 | const uint32_t *ports); | ||
207 | |||
208 | |||
209 | /** | ||
210 | * Disconnect from the mesh service. All channels will be destroyed. All channel | ||
211 | * disconnect callbacks will be called on any still connected peers, notifying | ||
212 | * about their disconnection. The registered inbound channel cleaner will be | ||
213 | * called should any inbound channels still exist. | ||
214 | * | ||
215 | * @param handle connection to mesh to disconnect | ||
216 | */ | ||
217 | void | ||
218 | GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle); | ||
219 | |||
220 | |||
221 | /** | ||
222 | * Create a new channel towards a remote peer. | ||
223 | * | ||
224 | * If the destination port is not open by any peer or the destination peer | ||
225 | * does not accept the channel, #GNUNET_MESH_ChannelEndHandler will be called | ||
226 | * for this channel. | ||
227 | * | ||
228 | * @param h mesh handle | ||
229 | * @param channel_ctx client's channel context to associate with the channel | ||
230 | * @param peer peer identity the channel should go to | ||
231 | * @param port Port number. | ||
232 | * @param nobuffer Flag for disabling buffering on relay nodes. | ||
233 | * @param reliable Flag for end-to-end reliability. | ||
234 | * @return handle to the channel | ||
235 | */ | ||
236 | struct GNUNET_MESH_Channel * | ||
237 | GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h, | ||
238 | void *channel_ctx, | ||
239 | const struct GNUNET_PeerIdentity *peer, | ||
240 | uint32_t port, | ||
241 | int nobuffer, | ||
242 | int reliable); | ||
243 | |||
244 | |||
245 | /** | ||
246 | * Destroy an existing channel. | ||
247 | * | ||
248 | * The existing end callback for the channel will be called immediately. | ||
249 | * Any pending outgoing messages will be sent but no incoming messages will be | ||
250 | * accepted and no data callbacks will be called. | ||
251 | * | ||
252 | * @param channel Channel handle, becomes invalid after this call. | ||
253 | */ | ||
254 | void | ||
255 | GNUNET_MESH_channel_destroy (struct GNUNET_MESH_Channel *channel); | ||
256 | |||
257 | |||
258 | /** | ||
259 | * Struct to retrieve info about a channel. | ||
260 | */ | ||
261 | union GNUNET_MESH_ChannelInfo | ||
262 | { | ||
263 | |||
264 | /** | ||
265 | * #GNUNET_YES / #GNUNET_NO, for binary flags. | ||
266 | */ | ||
267 | int yes_no; | ||
268 | |||
269 | /** | ||
270 | * Peer on the other side of the channel | ||
271 | */ | ||
272 | const struct GNUNET_PeerIdentity *peer; | ||
273 | }; | ||
274 | |||
275 | |||
276 | /** | ||
277 | * Get information about a channel. | ||
278 | * | ||
279 | * @param channel Channel handle. | ||
280 | * @param option Query type GNUNET_MESH_OPTION_* | ||
281 | * @param ... dependant on option, currently not used | ||
282 | * @return Union with an answer to the query. | ||
283 | */ | ||
284 | const union GNUNET_MESH_ChannelInfo * | ||
285 | GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel, | ||
286 | enum MeshOption option, ...); | ||
287 | |||
288 | |||
289 | /** | ||
290 | * Handle for a transmission request. | ||
291 | */ | ||
292 | struct GNUNET_MESH_TransmitHandle; | ||
293 | |||
294 | |||
295 | /** | ||
296 | * Ask the mesh to call @a notify once it is ready to transmit the | ||
297 | * given number of bytes to the specified channel. | ||
298 | * Only one call can be active at any time, to issue another request, | ||
299 | * wait for the callback or cancel the current request. | ||
300 | * | ||
301 | * @param channel channel to use for transmission | ||
302 | * @param cork is corking allowed for this transmission? | ||
303 | * @param maxdelay how long can the message wait? | ||
304 | * @param notify_size how many bytes of buffer space does notify want? | ||
305 | * @param notify function to call when buffer space is available; | ||
306 | * will be called with NULL on timeout or if the overall queue | ||
307 | * for this peer is larger than queue_size and this is currently | ||
308 | * the message with the lowest priority | ||
309 | * @param notify_cls closure for @a notify | ||
310 | * @return non-NULL if the notify callback was queued, | ||
311 | * NULL if we can not even queue the request (insufficient | ||
312 | * memory); if NULL is returned, @a notify will NOT be called. | ||
313 | */ | ||
314 | struct GNUNET_MESH_TransmitHandle * | ||
315 | GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Channel *channel, | ||
316 | int cork, | ||
317 | struct GNUNET_TIME_Relative maxdelay, | ||
318 | size_t notify_size, | ||
319 | GNUNET_CONNECTION_TransmitReadyNotify notify, | ||
320 | void *notify_cls); | ||
321 | |||
322 | |||
323 | /** | ||
324 | * Cancel the specified transmission-ready notification. | ||
325 | * | ||
326 | * @param th handle that was returned by "notify_transmit_ready". | ||
327 | */ | ||
328 | void | ||
329 | GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle | ||
330 | *th); | ||
331 | |||
332 | |||
333 | /** | ||
334 | * Indicate readiness to receive the next message on a channel. | ||
335 | * | ||
336 | * Should only be called once per handler called. | ||
337 | * | ||
338 | * @param channel Channel that will be allowed to call another handler. | ||
339 | */ | ||
340 | void | ||
341 | GNUNET_MESH_receive_done (struct GNUNET_MESH_Channel *channel); | ||
342 | |||
343 | |||
344 | |||
345 | /******************************************************************************/ | ||
346 | /******************** MONITORING /DEBUG API *************************/ | ||
347 | /******************************************************************************/ | ||
348 | /* The following calls are not useful for normal MESH operation, but for */ | ||
349 | /* debug and monitoring of the mesh state. They can be safely ignored. */ | ||
350 | /* The API can change at any point without notice. */ | ||
351 | /* Please contact the developer if you consider any of this calls useful for */ | ||
352 | /* normal mesh applications. */ | ||
353 | /******************************************************************************/ | ||
354 | |||
355 | /** | ||
356 | * Method called to retrieve information about each channel the mesh peer | ||
357 | * is aware of. | ||
358 | * | ||
359 | * @param cls Closure. | ||
360 | * @param channel_number Channel number. | ||
361 | * @param origin that started the channel (owner). | ||
362 | * @param target other endpoint of the channel | ||
363 | */ | ||
364 | typedef void (*GNUNET_MESH_ChannelsCB) (void *cls, | ||
365 | uint32_t channel_number, | ||
366 | const struct GNUNET_PeerIdentity *origin, | ||
367 | const struct GNUNET_PeerIdentity *target); | ||
368 | |||
369 | |||
370 | /** | ||
371 | * Method called to retrieve information about a specific channel the mesh peer | ||
372 | * is aware of, including all transit nodes. | ||
373 | * | ||
374 | * @param cls Closure. | ||
375 | * @param peer Peer in the channel's tree. | ||
376 | * @param parent Parent of the current peer. All 0 when peer is root. | ||
377 | */ | ||
378 | typedef void (*GNUNET_MESH_ChannelCB) (void *cls, | ||
379 | const struct GNUNET_PeerIdentity *peer, | ||
380 | const struct GNUNET_PeerIdentity *parent); | ||
381 | |||
382 | |||
383 | /** | ||
384 | * Request information about the running mesh peer. | ||
385 | * The callback will be called for every channel known to the service, | ||
386 | * listing all active peers that belong to the channel. | ||
387 | * | ||
388 | * If called again on the same handle, it will overwrite the previous | ||
389 | * callback and cls. To retrieve the cls, monitor_cancel must be | ||
390 | * called first. | ||
391 | * | ||
392 | * WARNING: unstable API, likely to change in the future! | ||
393 | * | ||
394 | * @param h Handle to the mesh peer. | ||
395 | * @param callback Function to call with the requested data. | ||
396 | * @param callback_cls Closure for @c callback. | ||
397 | */ | ||
398 | void | ||
399 | GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h, | ||
400 | GNUNET_MESH_ChannelsCB callback, | ||
401 | void *callback_cls); | ||
402 | |||
403 | |||
404 | /** | ||
405 | * Request information about a specific channel of the running mesh peer. | ||
406 | * | ||
407 | * WARNING: unstable API, likely to change in the future! | ||
408 | * | ||
409 | * @param h Handle to the mesh peer. | ||
410 | * @param initiator ID of the owner of the channel. | ||
411 | * @param channel_number Channel number. | ||
412 | * @param callback Function to call with the requested data. | ||
413 | * @param callback_cls Closure for @c callback. | ||
414 | */ | ||
415 | void | ||
416 | GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h, | ||
417 | struct GNUNET_PeerIdentity *initiator, | ||
418 | uint32_t channel_number, | ||
419 | GNUNET_MESH_ChannelCB callback, | ||
420 | void *callback_cls); | ||
421 | |||
422 | |||
423 | /** | ||
424 | * Cancel a monitor request. The monitor callback will not be called. | ||
425 | * | ||
426 | * WARNING: unstable API, likely to change in the future! | ||
427 | * | ||
428 | * @param h Mesh handle. | ||
429 | * | ||
430 | * @return Closure given to GNUNET_MESH_monitor, if any. | ||
431 | */ | ||
432 | void * | ||
433 | GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h); | ||
434 | |||
435 | |||
436 | /** | ||
437 | * Create a message queue for a mesh channel. | ||
438 | * The message queue can only be used to transmit messages, | ||
439 | * not to receive them. | ||
440 | * | ||
441 | * @param channel the channel to create the message qeue for | ||
442 | * @return a message queue to messages over the channel | ||
443 | */ | ||
444 | struct GNUNET_MQ_Handle * | ||
445 | GNUNET_MESH_mq_create (struct GNUNET_MESH_Channel *channel); | ||
446 | |||
447 | |||
448 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
449 | { | ||
450 | #endif | ||
451 | #ifdef __cplusplus | ||
452 | } | ||
453 | #endif | ||
454 | |||
455 | /* ifndef GNUNET_MESH_SERVICE_H */ | ||
456 | #endif | ||
457 | /* end of gnunet_mesh_service.h */ | ||
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index 3c71f4792..bc6d6e692 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am | |||
@@ -20,12 +20,6 @@ plugindir = $(libdir)/gnunet | |||
20 | 20 | ||
21 | AM_CLFAGS = -g | 21 | AM_CLFAGS = -g |
22 | 22 | ||
23 | EXP_LIB = \ | ||
24 | libgnunetmeshenc.la | ||
25 | |||
26 | EXP_LIBEXEC = \ | ||
27 | gnunet-service-mesh-enc | ||
28 | |||
29 | libexec_PROGRAMS = \ | 23 | libexec_PROGRAMS = \ |
30 | gnunet-service-mesh $(EXP_LIBEXEC) | 24 | gnunet-service-mesh $(EXP_LIBEXEC) |
31 | 25 | ||
@@ -58,19 +52,7 @@ libgnunetmesh_la_LIBADD = \ | |||
58 | $(LTLIBINTL) | 52 | $(LTLIBINTL) |
59 | libgnunetmesh_la_LDFLAGS = \ | 53 | libgnunetmesh_la_LDFLAGS = \ |
60 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | 54 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ |
61 | -version-info 3:0:0 | 55 | -version-info 4:0:0 |
62 | |||
63 | |||
64 | libgnunetmeshenc_la_SOURCES = \ | ||
65 | mesh_api_enc.c mesh_common.c | ||
66 | libgnunetmeshenc_la_LIBADD = \ | ||
67 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
68 | $(XLIB) \ | ||
69 | $(LTLIBINTL) | ||
70 | libgnunetmeshenc_la_LDFLAGS = \ | ||
71 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | ||
72 | -version-info 1:0:0 | ||
73 | |||
74 | 56 | ||
75 | gnunet_mesh_SOURCES = \ | 57 | gnunet_mesh_SOURCES = \ |
76 | gnunet-mesh.c | 58 | gnunet-mesh.c |
@@ -81,27 +63,6 @@ gnunet_mesh_DEPENDENCIES = \ | |||
81 | libgnunetmesh.la | 63 | libgnunetmesh.la |
82 | 64 | ||
83 | gnunet_service_mesh_SOURCES = \ | 65 | gnunet_service_mesh_SOURCES = \ |
84 | gnunet-service-mesh.c \ | ||
85 | mesh_path.c \ | ||
86 | mesh_common.c | ||
87 | gnunet_service_mesh_CFLAGS = $(AM_CFLAGS) | ||
88 | gnunet_service_mesh_LDADD = \ | ||
89 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
90 | $(top_builddir)/src/core/libgnunetcore.la \ | ||
91 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
92 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
93 | $(top_builddir)/src/block/libgnunetblock.la | ||
94 | gnunet_service_mesh_DEPENDENCIES = \ | ||
95 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
96 | $(top_builddir)/src/core/libgnunetcore.la \ | ||
97 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
98 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
99 | $(top_builddir)/src/block/libgnunetblock.la | ||
100 | if LINUX | ||
101 | gnunet_service_mesh_LDFLAGS = -lrt | ||
102 | endif | ||
103 | |||
104 | gnunet_service_mesh_enc_SOURCES = \ | ||
105 | gnunet-service-mesh_tunnel.c \ | 66 | gnunet-service-mesh_tunnel.c \ |
106 | gnunet-service-mesh_connection.c \ | 67 | gnunet-service-mesh_connection.c \ |
107 | gnunet-service-mesh_channel.c \ | 68 | gnunet-service-mesh_channel.c \ |
@@ -110,22 +71,22 @@ gnunet_service_mesh_enc_SOURCES = \ | |||
110 | gnunet-service-mesh_dht.c \ | 71 | gnunet-service-mesh_dht.c \ |
111 | mesh_path.c \ | 72 | mesh_path.c \ |
112 | mesh_common.c \ | 73 | mesh_common.c \ |
113 | gnunet-service-mesh-enc.c | 74 | gnunet-service-mesh.c |
114 | gnunet_service_mesh_enc_CFLAGS = $(AM_CFLAGS) | 75 | gnunet_service_mesh_CFLAGS = $(AM_CFLAGS) |
115 | gnunet_service_mesh_enc_LDADD = \ | 76 | gnunet_service_mesh_LDADD = \ |
116 | $(top_builddir)/src/util/libgnunetutil.la \ | 77 | $(top_builddir)/src/util/libgnunetutil.la \ |
117 | $(top_builddir)/src/core/libgnunetcore.la \ | 78 | $(top_builddir)/src/core/libgnunetcore.la \ |
118 | $(top_builddir)/src/dht/libgnunetdht.la \ | 79 | $(top_builddir)/src/dht/libgnunetdht.la \ |
119 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 80 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
120 | $(top_builddir)/src/block/libgnunetblock.la | 81 | $(top_builddir)/src/block/libgnunetblock.la |
121 | gnunet_service_mesh_enc_DEPENDENCIES = \ | 82 | gnunet_service_mesh_DEPENDENCIES = \ |
122 | $(top_builddir)/src/util/libgnunetutil.la \ | 83 | $(top_builddir)/src/util/libgnunetutil.la \ |
123 | $(top_builddir)/src/core/libgnunetcore.la \ | 84 | $(top_builddir)/src/core/libgnunetcore.la \ |
124 | $(top_builddir)/src/dht/libgnunetdht.la \ | 85 | $(top_builddir)/src/dht/libgnunetdht.la \ |
125 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 86 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
126 | $(top_builddir)/src/block/libgnunetblock.la | 87 | $(top_builddir)/src/block/libgnunetblock.la |
127 | if LINUX | 88 | if LINUX |
128 | gnunet_service_mesh_enc_LDFLAGS = -lrt | 89 | gnunet_service_mesh_LDFLAGS = -lrt |
129 | endif | 90 | endif |
130 | 91 | ||
131 | 92 | ||
@@ -138,9 +99,9 @@ libgnunetmeshtest_a_SOURCES = \ | |||
138 | libgnunetmeshtest_a_LIBADD = \ | 99 | libgnunetmeshtest_a_LIBADD = \ |
139 | $(top_builddir)/src/util/libgnunetutil.la \ | 100 | $(top_builddir)/src/util/libgnunetutil.la \ |
140 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | 101 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
141 | $(top_builddir)/src/mesh/libgnunetmeshenc.la | 102 | $(top_builddir)/src/mesh/libgnunetmesh.la |
142 | libgnunetmeshtest_a_DEPENDENCIES = \ | 103 | libgnunetmeshtest_a_DEPENDENCIES = \ |
143 | libgnunetmeshenc.la | 104 | libgnunetmesh.la |
144 | 105 | ||
145 | if HAVE_TESTING | 106 | if HAVE_TESTING |
146 | check_PROGRAMS = \ | 107 | check_PROGRAMS = \ |
@@ -161,11 +122,11 @@ ld_mesh_test_lib = \ | |||
161 | $(top_builddir)/src/util/libgnunetutil.la \ | 122 | $(top_builddir)/src/util/libgnunetutil.la \ |
162 | $(top_builddir)/src/testing/libgnunettesting.la \ | 123 | $(top_builddir)/src/testing/libgnunettesting.la \ |
163 | $(top_builddir)/src/mesh/libgnunetmeshtest.a \ | 124 | $(top_builddir)/src/mesh/libgnunetmeshtest.a \ |
164 | $(top_builddir)/src/mesh/libgnunetmeshenc.la \ | 125 | $(top_builddir)/src/mesh/libgnunetmesh.la \ |
165 | $(top_builddir)/src/testbed/libgnunettestbed.la | 126 | $(top_builddir)/src/testbed/libgnunettestbed.la |
166 | 127 | ||
167 | dep_mesh_test_lib = \ | 128 | dep_mesh_test_lib = \ |
168 | libgnunetmeshenc.la \ | 129 | libgnunetmesh.la \ |
169 | libgnunetmeshtest.a | 130 | libgnunetmeshtest.a |
170 | 131 | ||
171 | test_mesh_single_SOURCES = \ | 132 | test_mesh_single_SOURCES = \ |
diff --git a/src/mesh/gnunet-mesh.c b/src/mesh/gnunet-mesh.c index 77bb7317f..3d8aca183 100644 --- a/src/mesh/gnunet-mesh.c +++ b/src/mesh/gnunet-mesh.c | |||
@@ -118,7 +118,7 @@ get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
118 | { | 118 | { |
119 | return; | 119 | return; |
120 | } | 120 | } |
121 | GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL); | 121 | // GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL); |
122 | if (GNUNET_YES != monitor_connections) | 122 | if (GNUNET_YES != monitor_connections) |
123 | { | 123 | { |
124 | GNUNET_SCHEDULER_shutdown(); | 124 | GNUNET_SCHEDULER_shutdown(); |
@@ -148,7 +148,7 @@ show_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
148 | GNUNET_SCHEDULER_shutdown(); | 148 | GNUNET_SCHEDULER_shutdown(); |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | GNUNET_MESH_show_tunnel (mh, &pid, 0, tunnel_callback, NULL); | 151 | // GNUNET_MESH_show_tunnel (mh, &pid, 0, tunnel_callback, NULL); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c deleted file mode 100644 index f5e365e1c..000000000 --- a/src/mesh/gnunet-service-mesh-enc.c +++ /dev/null | |||
@@ -1,171 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001-2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file mesh/gnunet-service-mesh-enc.c | ||
23 | * @brief GNUnet MESH service with encryption | ||
24 | * @author Bartlomiej Polot | ||
25 | * | ||
26 | * FIXME in progress: | ||
27 | * - when sending in-order buffered data, wait for client ACKs | ||
28 | * - add signatures | ||
29 | * - add encryption | ||
30 | * - set connection IDs independently from tunnel, tunnel has no ID | ||
31 | * | ||
32 | * TODO: | ||
33 | * - relay corking down to core | ||
34 | * - set ttl relative to path length | ||
35 | * TODO END | ||
36 | * | ||
37 | * Dictionary: | ||
38 | * - peer: other mesh instance. If there is direct connection it's a neighbor. | ||
39 | * - tunnel: encrypted connection to a peer, neighbor or not. | ||
40 | * - channel: connection between two clients, on the same or different peers. | ||
41 | * have properties like reliability. | ||
42 | * - path: series of directly connected peer from one peer to another. | ||
43 | * - connection: path which is being used in a tunnel. | ||
44 | */ | ||
45 | |||
46 | #include "platform.h" | ||
47 | #include "gnunet_util_lib.h" | ||
48 | #include "mesh_enc.h" | ||
49 | #include "gnunet_statistics_service.h" | ||
50 | |||
51 | #include "gnunet-service-mesh_local.h" | ||
52 | #include "gnunet-service-mesh_channel.h" | ||
53 | #include "gnunet-service-mesh_connection.h" | ||
54 | #include "gnunet-service-mesh_tunnel.h" | ||
55 | #include "gnunet-service-mesh_dht.h" | ||
56 | #include "gnunet-service-mesh_peer.h" | ||
57 | |||
58 | |||
59 | /******************************************************************************/ | ||
60 | /*********************** GLOBAL VARIABLES ****************************/ | ||
61 | /******************************************************************************/ | ||
62 | |||
63 | /****************************** Global variables ******************************/ | ||
64 | |||
65 | /** | ||
66 | * Handle to the statistics service. | ||
67 | */ | ||
68 | struct GNUNET_STATISTICS_Handle *stats; | ||
69 | |||
70 | /** | ||
71 | * Local peer own ID (memory efficient handle). | ||
72 | */ | ||
73 | GNUNET_PEER_Id myid; | ||
74 | |||
75 | /** | ||
76 | * Local peer own ID (full value). | ||
77 | */ | ||
78 | struct GNUNET_PeerIdentity my_full_id; | ||
79 | |||
80 | /*************************** Static global variables **************************/ | ||
81 | |||
82 | /** | ||
83 | * Own private key. | ||
84 | */ | ||
85 | static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; | ||
86 | |||
87 | |||
88 | /******************************************************************************/ | ||
89 | /************************ MAIN FUNCTIONS ****************************/ | ||
90 | /******************************************************************************/ | ||
91 | |||
92 | /** | ||
93 | * Task run during shutdown. | ||
94 | * | ||
95 | * @param cls unused | ||
96 | * @param tc unused | ||
97 | */ | ||
98 | static void | ||
99 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
100 | { | ||
101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); | ||
102 | |||
103 | GML_shutdown (); | ||
104 | GMD_shutdown (); | ||
105 | GMP_shutdown (); | ||
106 | GMC_shutdown (); | ||
107 | GMT_shutdown (); | ||
108 | |||
109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n"); | ||
110 | } | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Process mesh requests. | ||
115 | * | ||
116 | * @param cls closure | ||
117 | * @param server the initialized server | ||
118 | * @param c configuration to use | ||
119 | */ | ||
120 | static void | ||
121 | run (void *cls, struct GNUNET_SERVER_Handle *server, | ||
122 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
123 | { | ||
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n"); | ||
125 | |||
126 | stats = GNUNET_STATISTICS_create ("mesh", c); | ||
127 | |||
128 | /* Scheduled the task to clean up when shutdown is called */ | ||
129 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | ||
130 | NULL); | ||
131 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n"); | ||
132 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c); | ||
133 | GNUNET_assert (NULL != my_private_key); | ||
134 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_full_id.public_key); | ||
135 | myid = GNUNET_PEER_intern (&my_full_id); | ||
136 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
137 | "Mesh for peer [%s] starting\n", | ||
138 | GNUNET_i2s (&my_full_id)); | ||
139 | |||
140 | GML_init (server); /* Local clients */ | ||
141 | GMC_init (c); /* Connections */ | ||
142 | GMP_init (c); /* Peers */ | ||
143 | GMD_init (c); /* DHT */ | ||
144 | GMT_init (c, my_private_key); /* Tunnels */ | ||
145 | |||
146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh service running\n"); | ||
147 | } | ||
148 | |||
149 | |||
150 | /** | ||
151 | * The main function for the mesh service. | ||
152 | * | ||
153 | * @param argc number of arguments from the command line | ||
154 | * @param argv command line arguments | ||
155 | * @return 0 ok, 1 on error | ||
156 | */ | ||
157 | int | ||
158 | main (int argc, char *const *argv) | ||
159 | { | ||
160 | int ret; | ||
161 | int r; | ||
162 | |||
163 | fprintf (stderr, "main()\n"); | ||
164 | r = GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run, | ||
165 | NULL); | ||
166 | GNUNET_free (my_private_key); | ||
167 | ret = (GNUNET_OK == r) ? 0 : 1; | ||
168 | fprintf (stderr, "main() END\n"); | ||
169 | |||
170 | return ret; | ||
171 | } | ||
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index d63576b4b..d187c93af 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -20,5696 +20,74 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file mesh/gnunet-service-mesh.c | 22 | * @file mesh/gnunet-service-mesh.c |
23 | * @brief GNUnet MESH service | 23 | * @brief GNUnet MESH service with encryption |
24 | * @author Bartlomiej Polot | 24 | * @author Bartlomiej Polot |
25 | * | 25 | * |
26 | * FIXME in progress: | 26 | * FIXME in progress: |
27 | * - when sending in-order buffered data, wait for client ACKs | 27 | * - rekey - reliability interaction |
28 | * - channel retransmit timing | ||
28 | * | 29 | * |
29 | * TODO: | 30 | * TODO: |
30 | * - relay corking down to core | 31 | * - relay corking down to core |
31 | * - set ttl relative to path length | 32 | * - set ttl relative to path length |
32 | * - add signatures | ||
33 | * - add encryption | ||
34 | * TODO END | 33 | * TODO END |
34 | * | ||
35 | * Dictionary: | ||
36 | * - peer: other mesh instance. If there is direct connection it's a neighbor. | ||
37 | * - tunnel: encrypted connection to a peer, neighbor or not. | ||
38 | * - channel: connection between two clients, on the same or different peers. | ||
39 | * have properties like reliability. | ||
40 | * - path: series of directly connected peer from one peer to another. | ||
41 | * - connection: path which is being used in a tunnel. | ||
35 | */ | 42 | */ |
36 | 43 | ||
37 | #include "platform.h" | 44 | #include "platform.h" |
45 | #include "gnunet_util_lib.h" | ||
38 | #include "mesh.h" | 46 | #include "mesh.h" |
39 | #include "mesh_protocol.h" | ||
40 | #include "mesh_path.h" | ||
41 | #include "block_mesh.h" | ||
42 | #include "gnunet_dht_service.h" | ||
43 | #include "gnunet_statistics_service.h" | 47 | #include "gnunet_statistics_service.h" |
44 | 48 | ||
45 | #define MESH_BLOOM_SIZE 128 | 49 | #include "gnunet-service-mesh_local.h" |
46 | 50 | #include "gnunet-service-mesh_channel.h" | |
47 | #define MESH_DEBUG_DHT GNUNET_NO | 51 | #include "gnunet-service-mesh_connection.h" |
48 | #define MESH_DEBUG_CONNECTION GNUNET_NO | 52 | #include "gnunet-service-mesh_tunnel.h" |
49 | #define MESH_DEBUG_TIMING __LINUX__ && GNUNET_NO | 53 | #include "gnunet-service-mesh_dht.h" |
50 | 54 | #include "gnunet-service-mesh_peer.h" | |
51 | #define MESH_MAX_POLL_TIME GNUNET_TIME_relative_multiply (\ | ||
52 | GNUNET_TIME_UNIT_MINUTES,\ | ||
53 | 10) | ||
54 | #define MESH_RETRANSMIT_TIME GNUNET_TIME_UNIT_SECONDS | ||
55 | #define MESH_RETRANSMIT_MARGIN 4 | ||
56 | |||
57 | #if MESH_DEBUG_CONNECTION | ||
58 | #define DEBUG_CONN(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
59 | #else | ||
60 | #define DEBUG_CONN(...) | ||
61 | #endif | ||
62 | |||
63 | #if MESH_DEBUG_DHT | ||
64 | #define DEBUG_DHT(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
65 | #else | ||
66 | #define DEBUG_DHT(...) | ||
67 | #endif | ||
68 | |||
69 | #if MESH_DEBUG_TIMING | ||
70 | #include <time.h> | ||
71 | double __sum; | ||
72 | uint64_t __count; | ||
73 | struct timespec __mesh_start; | ||
74 | struct timespec __mesh_end; | ||
75 | #define INTERVAL_START clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(__mesh_start)) | ||
76 | #define INTERVAL_END \ | ||
77 | do {\ | ||
78 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(__mesh_end));\ | ||
79 | double __diff = __mesh_end.tv_nsec - __mesh_start.tv_nsec;\ | ||
80 | if (__diff < 0) __diff += 1000000000;\ | ||
81 | __sum += __diff;\ | ||
82 | __count++;\ | ||
83 | } while (0) | ||
84 | #define INTERVAL_SHOW \ | ||
85 | if (0 < __count)\ | ||
86 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "AVG process time: %f ns\n", __sum/__count) | ||
87 | #else | ||
88 | #define INTERVAL_START | ||
89 | #define INTERVAL_END | ||
90 | #define INTERVAL_SHOW | ||
91 | #endif | ||
92 | |||
93 | /******************************************************************************/ | ||
94 | /************************ DATA STRUCTURES ****************************/ | ||
95 | /******************************************************************************/ | ||
96 | |||
97 | /** FWD declaration */ | ||
98 | struct MeshPeer; | ||
99 | struct MeshClient; | ||
100 | |||
101 | |||
102 | /** | ||
103 | * Struct containing info about a queued transmission to this peer | ||
104 | */ | ||
105 | struct MeshPeerQueue | ||
106 | { | ||
107 | /** | ||
108 | * DLL next | ||
109 | */ | ||
110 | struct MeshPeerQueue *next; | ||
111 | |||
112 | /** | ||
113 | * DLL previous | ||
114 | */ | ||
115 | struct MeshPeerQueue *prev; | ||
116 | |||
117 | /** | ||
118 | * Peer this transmission is directed to. | ||
119 | */ | ||
120 | struct MeshPeer *peer; | ||
121 | |||
122 | /** | ||
123 | * Tunnel this message belongs to. | ||
124 | */ | ||
125 | struct MeshTunnel *tunnel; | ||
126 | |||
127 | /** | ||
128 | * Pointer to info stucture used as cls. | ||
129 | */ | ||
130 | void *cls; | ||
131 | |||
132 | /** | ||
133 | * Type of message | ||
134 | */ | ||
135 | uint16_t type; | ||
136 | |||
137 | /** | ||
138 | * Size of the message | ||
139 | */ | ||
140 | size_t size; | ||
141 | }; | ||
142 | |||
143 | |||
144 | /** | ||
145 | * Struct containing all information regarding a given peer | ||
146 | */ | ||
147 | struct MeshPeer | ||
148 | { | ||
149 | /** | ||
150 | * ID of the peer | ||
151 | */ | ||
152 | GNUNET_PEER_Id id; | ||
153 | |||
154 | /** | ||
155 | * Last time we heard from this peer | ||
156 | */ | ||
157 | struct GNUNET_TIME_Absolute last_contact; | ||
158 | |||
159 | /** | ||
160 | * Number of attempts to reconnect so far | ||
161 | */ | ||
162 | int n_reconnect_attempts; | ||
163 | |||
164 | /** | ||
165 | * Paths to reach the peer, ordered by ascending hop count | ||
166 | */ | ||
167 | struct MeshPeerPath *path_head; | ||
168 | |||
169 | /** | ||
170 | * Paths to reach the peer, ordered by ascending hop count | ||
171 | */ | ||
172 | struct MeshPeerPath *path_tail; | ||
173 | |||
174 | /** | ||
175 | * Handle to stop the DHT search for a path to this peer | ||
176 | */ | ||
177 | struct GNUNET_DHT_GetHandle *dhtget; | ||
178 | |||
179 | /** | ||
180 | * Array of tunnels this peer is the target of. | ||
181 | * Most probably a small amount, therefore not a hashmap. | ||
182 | * When the path to the peer changes, notify these tunnels to let them | ||
183 | * re-adjust their path trees. | ||
184 | */ | ||
185 | struct MeshTunnel **tunnels; | ||
186 | |||
187 | /** | ||
188 | * Number of tunnels this peers participates in | ||
189 | */ | ||
190 | unsigned int ntunnels; | ||
191 | |||
192 | /** | ||
193 | * Transmission queue to core DLL head | ||
194 | */ | ||
195 | struct MeshPeerQueue *queue_head; | ||
196 | |||
197 | /** | ||
198 | * Transmission queue to core DLL tail | ||
199 | */ | ||
200 | struct MeshPeerQueue *queue_tail; | ||
201 | |||
202 | /** | ||
203 | * How many messages are in the queue to this peer. | ||
204 | */ | ||
205 | unsigned int queue_n; | ||
206 | |||
207 | /** | ||
208 | * Handle for queued transmissions | ||
209 | */ | ||
210 | struct GNUNET_CORE_TransmitHandle *core_transmit; | ||
211 | }; | ||
212 | |||
213 | |||
214 | /** | ||
215 | * Struct to encapsulate all the Flow Control information to a peer in the | ||
216 | * context of a tunnel: Same peer in different tunnels will have independent | ||
217 | * flow control structures, allowing to choke/free tunnels according to its | ||
218 | * own criteria. | ||
219 | */ | ||
220 | struct MeshFlowControl | ||
221 | { | ||
222 | /** | ||
223 | * ID of the last packet sent towards the peer. | ||
224 | */ | ||
225 | uint32_t last_pid_sent; | ||
226 | |||
227 | /** | ||
228 | * ID of the last packet received from the peer. | ||
229 | */ | ||
230 | uint32_t last_pid_recv; | ||
231 | |||
232 | /** | ||
233 | * Last ACK sent to the peer (peer can't send more than this PID). | ||
234 | */ | ||
235 | uint32_t last_ack_sent; | ||
236 | |||
237 | /** | ||
238 | * Last ACK sent towards the origin (for traffic towards leaf node). | ||
239 | */ | ||
240 | uint32_t last_ack_recv; | ||
241 | |||
242 | /** | ||
243 | * How many payload messages are in the queue towards this peer. | ||
244 | */ | ||
245 | uint32_t queue_n; | ||
246 | |||
247 | /** | ||
248 | * Task to poll the peer in case of a lost ACK causes stall. | ||
249 | */ | ||
250 | GNUNET_SCHEDULER_TaskIdentifier poll_task; | ||
251 | |||
252 | /** | ||
253 | * How frequently to poll for ACKs. | ||
254 | */ | ||
255 | struct GNUNET_TIME_Relative poll_time; | ||
256 | |||
257 | /** | ||
258 | * On which tunnel to poll. | ||
259 | * Using an explicit poll_ctx would not help memory wise, | ||
260 | * since the allocated context would have to be stored in the | ||
261 | * fc struct in order to free it upon cancelling poll_task. | ||
262 | */ | ||
263 | struct MeshTunnel *t; | ||
264 | }; | ||
265 | |||
266 | |||
267 | /** | ||
268 | * Globally unique tunnel identification (owner + number) | ||
269 | * DO NOT USE OVER THE NETWORK | ||
270 | */ | ||
271 | struct MESH_TunnelID | ||
272 | { | ||
273 | /** | ||
274 | * Node that owns the tunnel | ||
275 | */ | ||
276 | GNUNET_PEER_Id oid; | ||
277 | |||
278 | /** | ||
279 | * Tunnel number to differentiate all the tunnels owned by the node oid | ||
280 | * ( tid < GNUNET_MESH_LOCAL_TUNNEL_ID_CLI ) | ||
281 | */ | ||
282 | MESH_TunnelNumber tid; | ||
283 | }; | ||
284 | |||
285 | |||
286 | /** | ||
287 | * Data needed for reliable tunnel endpoint retransmission management. | ||
288 | */ | ||
289 | struct MeshTunnelReliability; | ||
290 | |||
291 | |||
292 | /** | ||
293 | * Info needed to retry a message in case it gets lost. | ||
294 | */ | ||
295 | struct MeshReliableMessage | ||
296 | { | ||
297 | /** | ||
298 | * Double linked list, FIFO style | ||
299 | */ | ||
300 | struct MeshReliableMessage *next; | ||
301 | struct MeshReliableMessage *prev; | ||
302 | |||
303 | /** | ||
304 | * Tunnel Reliability queue this message is in. | ||
305 | */ | ||
306 | struct MeshTunnelReliability *rel; | ||
307 | |||
308 | /** | ||
309 | * ID of the message (ACK needed to free) | ||
310 | */ | ||
311 | uint32_t mid; | ||
312 | |||
313 | /** | ||
314 | * When was this message issued (to calculate ACK delay) | ||
315 | */ | ||
316 | struct GNUNET_TIME_Absolute timestamp; | ||
317 | |||
318 | /* struct GNUNET_MESH_Data with payload */ | ||
319 | }; | ||
320 | |||
321 | |||
322 | struct MeshTunnelReliability | ||
323 | { | ||
324 | /** | ||
325 | * Tunnel this is about. | ||
326 | */ | ||
327 | struct MeshTunnel *t; | ||
328 | |||
329 | /** | ||
330 | * DLL of messages sent and not yet ACK'd. | ||
331 | */ | ||
332 | struct MeshReliableMessage *head_sent; | ||
333 | struct MeshReliableMessage *tail_sent; | ||
334 | |||
335 | /** | ||
336 | * Messages pending | ||
337 | */ | ||
338 | unsigned int n_sent; | ||
339 | |||
340 | /** | ||
341 | * Next MID to use. | ||
342 | */ | ||
343 | uint32_t mid_sent; | ||
344 | |||
345 | /** | ||
346 | * DLL of messages received out of order. | ||
347 | */ | ||
348 | struct MeshReliableMessage *head_recv; | ||
349 | struct MeshReliableMessage *tail_recv; | ||
350 | |||
351 | /** | ||
352 | * Next MID expected. | ||
353 | */ | ||
354 | uint32_t mid_recv; | ||
355 | |||
356 | /** | ||
357 | * Task to resend/poll in case no ACK is received. | ||
358 | */ | ||
359 | GNUNET_SCHEDULER_TaskIdentifier retry_task; | ||
360 | |||
361 | /** | ||
362 | * Counter for exponential backoff. | ||
363 | */ | ||
364 | struct GNUNET_TIME_Relative retry_timer; | ||
365 | |||
366 | /** | ||
367 | * How long does it usually take to get an ACK. | ||
368 | */ | ||
369 | struct GNUNET_TIME_Relative expected_delay; | ||
370 | }; | ||
371 | |||
372 | |||
373 | /** | ||
374 | * Struct containing all information regarding a tunnel | ||
375 | * For an intermediate node the improtant info used will be: | ||
376 | * - id Tunnel unique identification | ||
377 | * - paths[0] To know where to send it next | ||
378 | * - metainfo: ready, speeds, accounting | ||
379 | */ | ||
380 | struct MeshTunnel | ||
381 | { | ||
382 | /** | ||
383 | * Tunnel ID | ||
384 | */ | ||
385 | struct MESH_TunnelID id; | ||
386 | |||
387 | /** | ||
388 | * Port of the tunnel. | ||
389 | */ | ||
390 | uint32_t port; | ||
391 | |||
392 | /** | ||
393 | * State of the tunnel. | ||
394 | */ | ||
395 | enum MeshTunnelState state; | ||
396 | |||
397 | /** | ||
398 | * Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI or 0 ) | ||
399 | */ | ||
400 | MESH_TunnelNumber local_tid; | ||
401 | |||
402 | /** | ||
403 | * Local tunnel number for local destination clients (incoming number) | ||
404 | * ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV or 0). All clients share the same | ||
405 | * number. | ||
406 | */ | ||
407 | MESH_TunnelNumber local_tid_dest; | ||
408 | 55 | ||
409 | /** | ||
410 | * Is the tunnel bufferless (minimum latency)? | ||
411 | */ | ||
412 | int nobuffer; | ||
413 | |||
414 | /** | ||
415 | * Is the tunnel reliable? | ||
416 | */ | ||
417 | int reliable; | ||
418 | |||
419 | /** | ||
420 | * Force sending ACK? Flag to allow duplicate ACK on POLL. | ||
421 | */ | ||
422 | int force_ack; | ||
423 | |||
424 | /** | ||
425 | * How many messages do we accept in the forward queue. | ||
426 | */ | ||
427 | unsigned int queue_max; | ||
428 | |||
429 | /** | ||
430 | * Last time the tunnel was used | ||
431 | */ | ||
432 | struct GNUNET_TIME_Absolute timestamp; | ||
433 | |||
434 | /** | ||
435 | * Destination of the tunnel. | ||
436 | */ | ||
437 | GNUNET_PEER_Id dest; | ||
438 | |||
439 | /** | ||
440 | * Next hop in the tunnel. If 0, @c client must be set. | ||
441 | */ | ||
442 | GNUNET_PEER_Id next_hop; | ||
443 | |||
444 | /** | ||
445 | * Previous hop in the tunnel. If 0, @c owner must be set. | ||
446 | */ | ||
447 | GNUNET_PEER_Id prev_hop; | ||
448 | |||
449 | /** | ||
450 | * Flow control information about @c next_hop or @c client. | ||
451 | */ | ||
452 | struct MeshFlowControl next_fc; | ||
453 | |||
454 | /** | ||
455 | * Flow control information about @c prev_hop or @c owner. | ||
456 | */ | ||
457 | struct MeshFlowControl prev_fc; | ||
458 | |||
459 | /** | ||
460 | * Client owner of the tunnel, if any | ||
461 | */ | ||
462 | struct MeshClient *owner; | ||
463 | |||
464 | /** | ||
465 | * Client destination of the tunnel, if any. | ||
466 | */ | ||
467 | struct MeshClient *client; | ||
468 | |||
469 | /** | ||
470 | * Task to keep the used paths alive at the owner, | ||
471 | * time tunnel out on all the other peers. | ||
472 | */ | ||
473 | GNUNET_SCHEDULER_TaskIdentifier fwd_maintenance_task; | ||
474 | |||
475 | /** | ||
476 | * Task to keep the used paths alive at the destination, | ||
477 | * time tunnel out on all the other peers. | ||
478 | */ | ||
479 | GNUNET_SCHEDULER_TaskIdentifier bck_maintenance_task; | ||
480 | |||
481 | /** | ||
482 | * Path being used for the tunnel. | ||
483 | */ | ||
484 | struct MeshPeerPath *path; | ||
485 | |||
486 | /** | ||
487 | * Flag to signal the destruction of the tunnel. | ||
488 | * If this is set GNUNET_YES the tunnel will be destroyed | ||
489 | * when the queue is empty. | ||
490 | */ | ||
491 | int destroy; | ||
492 | |||
493 | /** | ||
494 | * Total messages pending for this tunnels, payload or not. | ||
495 | */ | ||
496 | unsigned int pending_messages; | ||
497 | |||
498 | /** | ||
499 | * Reliability data. | ||
500 | * Only present (non-NULL) at the owner of a tunnel. | ||
501 | */ | ||
502 | struct MeshTunnelReliability *fwd_rel; | ||
503 | |||
504 | /** | ||
505 | * Reliability data. | ||
506 | * Only present (non-NULL) at the destination of a tunnel. | ||
507 | */ | ||
508 | struct MeshTunnelReliability *bck_rel; | ||
509 | }; | ||
510 | |||
511 | |||
512 | /** | ||
513 | * Struct containing information about a client of the service | ||
514 | * | ||
515 | * TODO: add a list of 'waiting' ports | ||
516 | */ | ||
517 | struct MeshClient | ||
518 | { | ||
519 | /** | ||
520 | * Linked list next | ||
521 | */ | ||
522 | struct MeshClient *next; | ||
523 | |||
524 | /** | ||
525 | * Linked list prev | ||
526 | */ | ||
527 | struct MeshClient *prev; | ||
528 | |||
529 | /** | ||
530 | * Tunnels that belong to this client, indexed by local id | ||
531 | */ | ||
532 | struct GNUNET_CONTAINER_MultiHashMap32 *own_tunnels; | ||
533 | |||
534 | /** | ||
535 | * Tunnels this client has accepted, indexed by incoming local id | ||
536 | */ | ||
537 | struct GNUNET_CONTAINER_MultiHashMap32 *incoming_tunnels; | ||
538 | |||
539 | /** | ||
540 | * Handle to communicate with the client | ||
541 | */ | ||
542 | struct GNUNET_SERVER_Client *handle; | ||
543 | |||
544 | /** | ||
545 | * Ports that this client has declared interest in. | ||
546 | * Indexed by port, contains *Client. | ||
547 | */ | ||
548 | struct GNUNET_CONTAINER_MultiHashMap32 *ports; | ||
549 | |||
550 | /** | ||
551 | * Whether the client is active or shutting down (don't send confirmations | ||
552 | * to a client that is shutting down. | ||
553 | */ | ||
554 | int shutting_down; | ||
555 | |||
556 | /** | ||
557 | * ID of the client, mainly for debug messages | ||
558 | */ | ||
559 | unsigned int id; | ||
560 | |||
561 | }; | ||
562 | |||
563 | |||
564 | /******************************************************************************/ | ||
565 | /************************ DEBUG FUNCTIONS ****************************/ | ||
566 | /******************************************************************************/ | ||
567 | |||
568 | #if MESH_DEBUG | ||
569 | /** | ||
570 | * GNUNET_SCHEDULER_Task for printing a message after some operation is done | ||
571 | * @param cls string to print | ||
572 | * @param success GNUNET_OK if the PUT was transmitted, | ||
573 | * GNUNET_NO on timeout, | ||
574 | * GNUNET_SYSERR on disconnect from service | ||
575 | * after the PUT message was transmitted | ||
576 | * (so we don't know if it was received or not) | ||
577 | */ | ||
578 | |||
579 | #if 0 | ||
580 | static void | ||
581 | mesh_debug (void *cls, int success) | ||
582 | { | ||
583 | char *s = cls; | ||
584 | |||
585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s (%d)\n", s, success); | ||
586 | } | ||
587 | #endif | ||
588 | |||
589 | #endif | ||
590 | 56 | ||
591 | /******************************************************************************/ | 57 | /******************************************************************************/ |
592 | /*********************** GLOBAL VARIABLES ****************************/ | 58 | /*********************** GLOBAL VARIABLES ****************************/ |
593 | /******************************************************************************/ | 59 | /******************************************************************************/ |
594 | 60 | ||
595 | /************************** Configuration parameters **************************/ | 61 | /****************************** Global variables ******************************/ |
596 | |||
597 | /** | ||
598 | * How often to send tunnel keepalives. Tunnels timeout after 4 missed. | ||
599 | */ | ||
600 | static struct GNUNET_TIME_Relative refresh_path_time; | ||
601 | |||
602 | /** | ||
603 | * How often to PUT own ID in the DHT. | ||
604 | */ | ||
605 | static struct GNUNET_TIME_Relative id_announce_time; | ||
606 | |||
607 | /** | ||
608 | * Maximum time allowed to connect to a peer found by string. | ||
609 | */ | ||
610 | static struct GNUNET_TIME_Relative connect_timeout; | ||
611 | |||
612 | /** | ||
613 | * Default TTL for payload packets. | ||
614 | */ | ||
615 | static unsigned long long default_ttl; | ||
616 | |||
617 | /** | ||
618 | * DHT replication level, see DHT API: GNUNET_DHT_get_start, GNUNET_DHT_put. | ||
619 | */ | ||
620 | static unsigned long long dht_replication_level; | ||
621 | |||
622 | /** | ||
623 | * How many tunnels are we willing to maintain. | ||
624 | * Local tunnels are always allowed, even if there are more tunnels than max. | ||
625 | */ | ||
626 | static unsigned long long max_tunnels; | ||
627 | |||
628 | /** | ||
629 | * How many messages *in total* are we willing to queue, divided by number of | ||
630 | * tunnels to get tunnel queue size. | ||
631 | */ | ||
632 | static unsigned long long max_msgs_queue; | ||
633 | |||
634 | /** | ||
635 | * How many peers do we want to remember? | ||
636 | */ | ||
637 | static unsigned long long max_peers; | ||
638 | |||
639 | /** | ||
640 | * Percentage of messages that will be dropped (for test purposes only). | ||
641 | */ | ||
642 | static unsigned long long drop_percent; | ||
643 | |||
644 | /*************************** Static global variables **************************/ | ||
645 | |||
646 | /** | ||
647 | * DLL with all the clients, head. | ||
648 | */ | ||
649 | static struct MeshClient *clients_head; | ||
650 | |||
651 | /** | ||
652 | * DLL with all the clients, tail. | ||
653 | */ | ||
654 | static struct MeshClient *clients_tail; | ||
655 | |||
656 | /** | ||
657 | * Tunnels known, indexed by MESH_TunnelID (MeshTunnel). | ||
658 | */ | ||
659 | static struct GNUNET_CONTAINER_MultiHashMap *tunnels; | ||
660 | |||
661 | /** | ||
662 | * Number of tunnels known. | ||
663 | */ | ||
664 | static unsigned long long n_tunnels; | ||
665 | |||
666 | /** | ||
667 | * Tunnels incoming, indexed by MESH_TunnelNumber | ||
668 | * (which is greater than GNUNET_MESH_LOCAL_TUNNEL_ID_SERV). | ||
669 | */ | ||
670 | static struct GNUNET_CONTAINER_MultiHashMap32 *incoming_tunnels; | ||
671 | |||
672 | /** | ||
673 | * Peers known, indexed by PeerIdentity (MeshPeer). | ||
674 | */ | ||
675 | static struct GNUNET_CONTAINER_MultiPeerMap *peers; | ||
676 | |||
677 | /* | ||
678 | * Handle to communicate with transport | ||
679 | */ | ||
680 | // static struct GNUNET_TRANSPORT_Handle *transport_handle; | ||
681 | |||
682 | /** | ||
683 | * Handle to communicate with core. | ||
684 | */ | ||
685 | static struct GNUNET_CORE_Handle *core_handle; | ||
686 | |||
687 | /** | ||
688 | * Handle to use DHT. | ||
689 | */ | ||
690 | static struct GNUNET_DHT_Handle *dht_handle; | ||
691 | |||
692 | /** | ||
693 | * Handle to server. | ||
694 | */ | ||
695 | static struct GNUNET_SERVER_Handle *server_handle; | ||
696 | 62 | ||
697 | /** | 63 | /** |
698 | * Handle to the statistics service. | 64 | * Handle to the statistics service. |
699 | */ | 65 | */ |
700 | static struct GNUNET_STATISTICS_Handle *stats; | 66 | struct GNUNET_STATISTICS_Handle *stats; |
701 | |||
702 | /** | ||
703 | * Notification context, to send messages to local clients. | ||
704 | */ | ||
705 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
706 | 67 | ||
707 | /** | 68 | /** |
708 | * Local peer own ID (memory efficient handle). | 69 | * Local peer own ID (memory efficient handle). |
709 | */ | 70 | */ |
710 | static GNUNET_PEER_Id myid; | 71 | GNUNET_PEER_Id myid; |
711 | 72 | ||
712 | /** | 73 | /** |
713 | * Local peer own ID (full value). | 74 | * Local peer own ID (full value). |
714 | */ | 75 | */ |
715 | static struct GNUNET_PeerIdentity my_full_id; | 76 | struct GNUNET_PeerIdentity my_full_id; |
77 | |||
78 | /*************************** Static global variables **************************/ | ||
716 | 79 | ||
717 | /** | 80 | /** |
718 | * Own private key. | 81 | * Own private key. |
719 | */ | 82 | */ |
720 | static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; | 83 | static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; |
721 | 84 | ||
722 | /** | ||
723 | * Tunnel ID for the next created tunnel (global tunnel number). | ||
724 | */ | ||
725 | static MESH_TunnelNumber next_tid; | ||
726 | |||
727 | /** | ||
728 | * Tunnel ID for the next incoming tunnel (local tunnel number). | ||
729 | */ | ||
730 | static MESH_TunnelNumber next_local_tid; | ||
731 | |||
732 | /** | ||
733 | * All ports clients of this peer have opened. | ||
734 | */ | ||
735 | static struct GNUNET_CONTAINER_MultiHashMap32 *ports; | ||
736 | |||
737 | /** | ||
738 | * Task to periodically announce itself in the network. | ||
739 | */ | ||
740 | GNUNET_SCHEDULER_TaskIdentifier announce_id_task; | ||
741 | |||
742 | /** | ||
743 | * Next ID to assign to a client. | ||
744 | */ | ||
745 | unsigned int next_client_id; | ||
746 | |||
747 | |||
748 | /******************************************************************************/ | ||
749 | /*********************** DECLARATIONS **************************/ | ||
750 | /******************************************************************************/ | ||
751 | |||
752 | /** | ||
753 | * Function to process paths received for a new peer addition. The recorded | ||
754 | * paths form the initial tunnel, which can be optimized later. | ||
755 | * Called on each result obtained for the DHT search. | ||
756 | * | ||
757 | * @param cls closure | ||
758 | * @param exp when will this value expire | ||
759 | * @param key key of the result | ||
760 | * @param type type of the result | ||
761 | * @param size number of bytes in data | ||
762 | * @param data pointer to the result data | ||
763 | */ | ||
764 | static void | ||
765 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | ||
766 | const struct GNUNET_HashCode * key, | ||
767 | const struct GNUNET_PeerIdentity *get_path, | ||
768 | unsigned int get_path_length, | ||
769 | const struct GNUNET_PeerIdentity *put_path, | ||
770 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, | ||
771 | size_t size, const void *data); | ||
772 | |||
773 | |||
774 | /** | ||
775 | * Retrieve the MeshPeer stucture associated with the peer, create one | ||
776 | * and insert it in the appropriate structures if the peer is not known yet. | ||
777 | * | ||
778 | * @param peer_id Full identity of the peer. | ||
779 | * | ||
780 | * @return Existing or newly created peer info. | ||
781 | */ | ||
782 | static struct MeshPeer * | ||
783 | peer_get (const struct GNUNET_PeerIdentity *peer_id); | ||
784 | |||
785 | |||
786 | /** | ||
787 | * Retrieve the MeshPeer stucture associated with the peer, create one | ||
788 | * and insert it in the appropriate structures if the peer is not known yet. | ||
789 | * | ||
790 | * @param peer Short identity of the peer. | ||
791 | * | ||
792 | * @return Existing or newly created peer info. | ||
793 | */ | ||
794 | static struct MeshPeer * | ||
795 | peer_get_short (const GNUNET_PEER_Id peer); | ||
796 | |||
797 | |||
798 | /** | ||
799 | * Build a PeerPath from the paths returned from the DHT, reversing the paths | ||
800 | * to obtain a local peer -> destination path and interning the peer ids. | ||
801 | * | ||
802 | * @return Newly allocated and created path | ||
803 | */ | ||
804 | static struct MeshPeerPath * | ||
805 | path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | ||
806 | unsigned int get_path_length, | ||
807 | const struct GNUNET_PeerIdentity *put_path, | ||
808 | unsigned int put_path_length); | ||
809 | |||
810 | |||
811 | /** | ||
812 | * Adds a path to the peer_infos of all the peers in the path | ||
813 | * | ||
814 | * @param p Path to process. | ||
815 | * @param confirmed Whether we know if the path works or not. | ||
816 | */ | ||
817 | static void | ||
818 | path_add_to_peers (struct MeshPeerPath *p, int confirmed); | ||
819 | |||
820 | |||
821 | |||
822 | /** | ||
823 | * Search for a tunnel by global ID using full PeerIdentities. | ||
824 | * | ||
825 | * @param oid owner of the tunnel. | ||
826 | * @param tid global tunnel number. | ||
827 | * | ||
828 | * @return tunnel handler, NULL if doesn't exist. | ||
829 | */ | ||
830 | static struct MeshTunnel * | ||
831 | tunnel_get (const struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid); | ||
832 | |||
833 | |||
834 | /** | ||
835 | * Change the tunnel state. | ||
836 | * | ||
837 | * @param t Tunnel whose ttate to change. | ||
838 | * @param state New state. | ||
839 | */ | ||
840 | static void | ||
841 | tunnel_change_state (struct MeshTunnel *t, enum MeshTunnelState state); | ||
842 | |||
843 | |||
844 | /** | ||
845 | * Notify a tunnel that a connection has broken that affects at least | ||
846 | * some of its peers. | ||
847 | * | ||
848 | * @param t Tunnel affected. | ||
849 | * @param p1 Peer that got disconnected from p2. | ||
850 | * @param p2 Peer that got disconnected from p1. | ||
851 | * | ||
852 | * @return Short ID of the peer disconnected (either p1 or p2). | ||
853 | * 0 if the tunnel remained unaffected. | ||
854 | */ | ||
855 | static GNUNET_PEER_Id | ||
856 | tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1, | ||
857 | GNUNET_PEER_Id p2); | ||
858 | |||
859 | |||
860 | /** | ||
861 | * Send FWD keepalive packets for a tunnel. | ||
862 | * | ||
863 | * @param cls Closure (tunnel for which to send the keepalive). | ||
864 | * @param tc Notification context. | ||
865 | */ | ||
866 | static void | ||
867 | tunnel_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
868 | |||
869 | /** | ||
870 | * Send BCK keepalive packets for a tunnel. | ||
871 | * | ||
872 | * @param cls Closure (tunnel for which to send the keepalive). | ||
873 | * @param tc Notification context. | ||
874 | */ | ||
875 | static void | ||
876 | tunnel_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
877 | |||
878 | /** | ||
879 | * @brief Use the given path for the tunnel. | ||
880 | * Update the next and prev hops (and RCs). | ||
881 | * (Re)start the path refresh in case the tunnel is locally owned. | ||
882 | * | ||
883 | * @param t Tunnel to update. | ||
884 | * @param p Path to use. | ||
885 | */ | ||
886 | static void | ||
887 | tunnel_use_path (struct MeshTunnel *t, struct MeshPeerPath *p); | ||
888 | |||
889 | /** | ||
890 | * Tunnel is empty: destroy it. | ||
891 | * | ||
892 | * Notifies all participants (peers, cleints) about the destruction. | ||
893 | * | ||
894 | * @param t Tunnel to destroy. | ||
895 | */ | ||
896 | static void | ||
897 | tunnel_destroy_empty (struct MeshTunnel *t); | ||
898 | |||
899 | /** | ||
900 | * Destroy the tunnel. | ||
901 | * | ||
902 | * This function does not generate any warning traffic to clients or peers. | ||
903 | * | ||
904 | * Tasks: | ||
905 | * Remove the tunnel from peer_info's and clients' hashmaps. | ||
906 | * Cancel messages belonging to this tunnel queued to neighbors. | ||
907 | * Free any allocated resources linked to the tunnel. | ||
908 | * | ||
909 | * @param t the tunnel to destroy | ||
910 | * | ||
911 | * @return GNUNET_OK on success | ||
912 | */ | ||
913 | static int | ||
914 | tunnel_destroy (struct MeshTunnel *t); | ||
915 | |||
916 | /** | ||
917 | * @brief Queue and pass message to core when possible. | ||
918 | * | ||
919 | * If type is payload (UNICAST, TO_ORIGIN, MULTICAST) checks for queue status | ||
920 | * and accounts for it. In case the queue is full, the message is dropped and | ||
921 | * a break issued. | ||
922 | * | ||
923 | * Otherwise, message is treated as internal and allowed to go regardless of | ||
924 | * queue status. | ||
925 | * | ||
926 | * @param cls Closure (@c type dependant). It will be used by queue_send to | ||
927 | * build the message to be sent if not already prebuilt. | ||
928 | * @param type Type of the message, 0 for a raw message. | ||
929 | * @param size Size of the message. | ||
930 | * @param dst Neighbor to send message to. | ||
931 | * @param t Tunnel this message belongs to. | ||
932 | */ | ||
933 | static void | ||
934 | queue_add (void *cls, uint16_t type, size_t size, | ||
935 | struct MeshPeer *dst, struct MeshTunnel *t); | ||
936 | |||
937 | |||
938 | /** | ||
939 | * Free a transmission that was already queued with all resources | ||
940 | * associated to the request. | ||
941 | * | ||
942 | * @param queue Queue handler to cancel. | ||
943 | * @param clear_cls Is it necessary to free associated cls? | ||
944 | */ | ||
945 | static void | ||
946 | queue_destroy (struct MeshPeerQueue *queue, int clear_cls); | ||
947 | |||
948 | |||
949 | /** | ||
950 | * @brief Get the next transmittable message from the queue. | ||
951 | * | ||
952 | * This will be the head, except in the case of being a data packet | ||
953 | * not allowed by the destination peer. | ||
954 | * | ||
955 | * @param peer Destination peer. | ||
956 | * | ||
957 | * @return The next viable MeshPeerQueue element to send to that peer. | ||
958 | * NULL when there are no transmittable messages. | ||
959 | */ | ||
960 | struct MeshPeerQueue * | ||
961 | queue_get_next (const struct MeshPeer *peer); | ||
962 | |||
963 | |||
964 | /** | ||
965 | * Core callback to write a queued packet to core buffer | ||
966 | * | ||
967 | * @param cls Closure (peer info). | ||
968 | * @param size Number of bytes available in buf. | ||
969 | * @param buf Where the to write the message. | ||
970 | * | ||
971 | * @return number of bytes written to buf | ||
972 | */ | ||
973 | static size_t | ||
974 | queue_send (void *cls, size_t size, void *buf); | ||
975 | |||
976 | |||
977 | /** | ||
978 | * Dummy function to separate declarations from definitions in function list. | ||
979 | */ | ||
980 | void | ||
981 | __mesh_divider______________________________________________________________(); | ||
982 | |||
983 | |||
984 | static const char * | ||
985 | GNUNET_MESH_DEBUG_S2S (enum MeshTunnelState s) | ||
986 | { | ||
987 | static char buf[128]; | ||
988 | |||
989 | switch (s) | ||
990 | { | ||
991 | /** | ||
992 | * Uninitialized status, should never appear in operation. | ||
993 | */ | ||
994 | case MESH_TUNNEL_NEW: return "MESH_TUNNEL_NEW"; | ||
995 | |||
996 | /** | ||
997 | * Path to the peer not known yet | ||
998 | */ | ||
999 | case MESH_TUNNEL_SEARCHING: return "MESH_TUNNEL_SEARCHING"; | ||
1000 | |||
1001 | /** | ||
1002 | * Request sent, not yet answered. | ||
1003 | */ | ||
1004 | case MESH_TUNNEL_WAITING: return "MESH_TUNNEL_WAITING"; | ||
1005 | |||
1006 | /** | ||
1007 | * Peer connected and ready to accept data | ||
1008 | */ | ||
1009 | case MESH_TUNNEL_READY: return "MESH_TUNNEL_READY"; | ||
1010 | |||
1011 | /** | ||
1012 | * Peer connected previosly but not responding | ||
1013 | */ | ||
1014 | case MESH_TUNNEL_RECONNECTING: return "MESH_TUNNEL_RECONNECTING"; | ||
1015 | |||
1016 | default: | ||
1017 | sprintf (buf, "%u (UNKNOWN STATE)", s); | ||
1018 | return buf; | ||
1019 | } | ||
1020 | } | ||
1021 | |||
1022 | |||
1023 | /******************************************************************************/ | ||
1024 | /************************ PERIODIC FUNCTIONS ****************************/ | ||
1025 | /******************************************************************************/ | ||
1026 | |||
1027 | /** | ||
1028 | * Periodically announce self id in the DHT | ||
1029 | * | ||
1030 | * @param cls closure | ||
1031 | * @param tc task context | ||
1032 | */ | ||
1033 | static void | ||
1034 | announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1035 | { | ||
1036 | struct PBlock block; | ||
1037 | struct GNUNET_HashCode phash; | ||
1038 | |||
1039 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
1040 | { | ||
1041 | announce_id_task = GNUNET_SCHEDULER_NO_TASK; | ||
1042 | return; | ||
1043 | } | ||
1044 | /* TODO | ||
1045 | * - Set data expiration in function of X | ||
1046 | * - Adapt X to churn | ||
1047 | */ | ||
1048 | DEBUG_DHT ("DHT_put for ID %s started.\n", GNUNET_i2s (&my_full_id)); | ||
1049 | GNUNET_CRYPTO_hash (&my_full_id, sizeof (my_full_id), &phash); | ||
1050 | block.id = my_full_id; | ||
1051 | GNUNET_DHT_put (dht_handle, /* DHT handle */ | ||
1052 | &phash, | ||
1053 | dht_replication_level, /* Replication level */ | ||
1054 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ | ||
1055 | GNUNET_BLOCK_TYPE_MESH_PEER, /* Block type */ | ||
1056 | sizeof (block), /* Size of the data */ | ||
1057 | (const char *) &block, /* Data itself */ | ||
1058 | GNUNET_TIME_UNIT_FOREVER_ABS, /* Data expiration */ | ||
1059 | GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ | ||
1060 | NULL, /* Continuation */ | ||
1061 | NULL); /* Continuation closure */ | ||
1062 | announce_id_task = | ||
1063 | GNUNET_SCHEDULER_add_delayed (id_announce_time, &announce_id, cls); | ||
1064 | } | ||
1065 | |||
1066 | |||
1067 | /******************************************************************************/ | ||
1068 | /****************** GENERAL HELPER FUNCTIONS ************************/ | ||
1069 | /******************************************************************************/ | ||
1070 | |||
1071 | |||
1072 | /** | ||
1073 | * Check if client has registered with the service and has not disconnected | ||
1074 | * | ||
1075 | * @param client the client to check | ||
1076 | * | ||
1077 | * @return non-NULL if client exists in the global DLL | ||
1078 | */ | ||
1079 | static struct MeshClient * | ||
1080 | client_get (struct GNUNET_SERVER_Client *client) | ||
1081 | { | ||
1082 | return GNUNET_SERVER_client_get_user_context (client, struct MeshClient); | ||
1083 | } | ||
1084 | |||
1085 | |||
1086 | /** | ||
1087 | * Deletes a tunnel from a client (either owner or destination). To be used on | ||
1088 | * tunnel destroy. | ||
1089 | * | ||
1090 | * @param c Client whose tunnel to delete. | ||
1091 | * @param t Tunnel which should be deleted. | ||
1092 | */ | ||
1093 | static void | ||
1094 | client_delete_tunnel (struct MeshClient *c, struct MeshTunnel *t) | ||
1095 | { | ||
1096 | int res; | ||
1097 | |||
1098 | if (c == t->owner) | ||
1099 | { | ||
1100 | res = GNUNET_CONTAINER_multihashmap32_remove (c->own_tunnels, | ||
1101 | t->local_tid, t); | ||
1102 | if (GNUNET_YES != res) | ||
1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client_delete_tunnel owner KO\n"); | ||
1104 | } | ||
1105 | if (c == t->client) | ||
1106 | { | ||
1107 | res = GNUNET_CONTAINER_multihashmap32_remove (c->incoming_tunnels, | ||
1108 | t->local_tid_dest, t); | ||
1109 | if (GNUNET_YES != res) | ||
1110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client_delete_tunnel client KO\n"); | ||
1111 | } | ||
1112 | } | ||
1113 | |||
1114 | |||
1115 | /** | ||
1116 | * Notify the appropriate client that a new incoming tunnel was created. | ||
1117 | * | ||
1118 | * @param t Tunnel that was created. | ||
1119 | */ | ||
1120 | static void | ||
1121 | send_local_tunnel_create (struct MeshTunnel *t) | ||
1122 | { | ||
1123 | struct GNUNET_MESH_TunnelMessage msg; | ||
1124 | |||
1125 | if (NULL == t->client) | ||
1126 | return; | ||
1127 | msg.header.size = htons (sizeof (msg)); | ||
1128 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); | ||
1129 | msg.tunnel_id = htonl (t->local_tid_dest); | ||
1130 | msg.port = htonl (t->port); | ||
1131 | msg.opt = 0; | ||
1132 | msg.opt |= GNUNET_YES == t->reliable ? GNUNET_MESH_OPTION_RELIABLE : 0; | ||
1133 | msg.opt |= GNUNET_YES == t->nobuffer ? GNUNET_MESH_OPTION_NOBUFFER : 0; | ||
1134 | msg.opt = htonl (msg.opt); | ||
1135 | GNUNET_PEER_resolve (t->id.oid, &msg.peer); | ||
1136 | GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, | ||
1137 | &msg.header, GNUNET_NO); | ||
1138 | } | ||
1139 | |||
1140 | |||
1141 | /** | ||
1142 | * Notify a client that the incoming tunnel is no longer valid. | ||
1143 | * | ||
1144 | * @param t Tunnel that is destroyed. | ||
1145 | * @param fwd Forward notification (owner->dest)? | ||
1146 | */ | ||
1147 | static void | ||
1148 | send_local_tunnel_destroy (struct MeshTunnel *t, int fwd) | ||
1149 | { | ||
1150 | struct GNUNET_MESH_TunnelMessage msg; | ||
1151 | struct MeshClient *c; | ||
1152 | |||
1153 | c = fwd ? t->client : t->owner; | ||
1154 | if (NULL == c) | ||
1155 | { | ||
1156 | GNUNET_break (0); | ||
1157 | return; | ||
1158 | } | ||
1159 | msg.header.size = htons (sizeof (msg)); | ||
1160 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); | ||
1161 | msg.tunnel_id = htonl (fwd ? t->local_tid_dest : t->local_tid); | ||
1162 | msg.port = htonl (0); | ||
1163 | memset (&msg.peer, 0, sizeof (msg.peer)); | ||
1164 | msg.opt = htonl (0); | ||
1165 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, | ||
1166 | &msg.header, GNUNET_NO); | ||
1167 | } | ||
1168 | |||
1169 | |||
1170 | /** | ||
1171 | * Build a local ACK message and send it to a local client. | ||
1172 | * | ||
1173 | * @param t Tunnel on which to send the ACK. | ||
1174 | * @param c Client to whom send the ACK. | ||
1175 | * @param is_fwd Set to GNUNET_YES for FWD ACK (dest->owner) | ||
1176 | */ | ||
1177 | static void | ||
1178 | send_local_ack (struct MeshTunnel *t, | ||
1179 | struct MeshClient *c, | ||
1180 | int is_fwd) | ||
1181 | { | ||
1182 | struct GNUNET_MESH_LocalAck msg; | ||
1183 | |||
1184 | msg.header.size = htons (sizeof (msg)); | ||
1185 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK); | ||
1186 | msg.tunnel_id = htonl (is_fwd ? t->local_tid : t->local_tid_dest); | ||
1187 | GNUNET_SERVER_notification_context_unicast (nc, | ||
1188 | c->handle, | ||
1189 | &msg.header, | ||
1190 | GNUNET_NO); | ||
1191 | } | ||
1192 | |||
1193 | |||
1194 | |||
1195 | /** | ||
1196 | * Sends an already built message to a peer, properly registrating | ||
1197 | * all used resources. | ||
1198 | * | ||
1199 | * @param message Message to send. Function makes a copy of it. | ||
1200 | * @param peer Short ID of the neighbor whom to send the message. | ||
1201 | * @param t Tunnel on which this message is transmitted. | ||
1202 | */ | ||
1203 | static void | ||
1204 | send_prebuilt_message (const struct GNUNET_MessageHeader *message, | ||
1205 | GNUNET_PEER_Id peer, | ||
1206 | struct MeshTunnel *t) | ||
1207 | { | ||
1208 | struct GNUNET_PeerIdentity id; | ||
1209 | struct MeshPeer *neighbor; | ||
1210 | struct MeshPeerPath *p; | ||
1211 | void *data; | ||
1212 | size_t size; | ||
1213 | uint16_t type; | ||
1214 | |||
1215 | // GNUNET_TRANSPORT_try_connect(); FIXME use? | ||
1216 | |||
1217 | if (0 == peer) | ||
1218 | return; | ||
1219 | |||
1220 | size = ntohs (message->size); | ||
1221 | data = GNUNET_malloc (size); | ||
1222 | memcpy (data, message, size); | ||
1223 | type = ntohs(message->type); | ||
1224 | if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == type || | ||
1225 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN == type) | ||
1226 | { | ||
1227 | struct GNUNET_MESH_Data *u; | ||
1228 | |||
1229 | u = (struct GNUNET_MESH_Data *) data; | ||
1230 | u->ttl = htonl (ntohl (u->ttl) - 1); | ||
1231 | } | ||
1232 | GNUNET_PEER_resolve (peer, &id); | ||
1233 | neighbor = peer_get (&id); | ||
1234 | for (p = neighbor->path_head; NULL != p; p = p->next) | ||
1235 | { | ||
1236 | if (2 >= p->length) | ||
1237 | { | ||
1238 | break; | ||
1239 | } | ||
1240 | } | ||
1241 | if (NULL == p) | ||
1242 | { | ||
1243 | #if MESH_DEBUG | ||
1244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1245 | " %s IS NOT DIRECTLY CONNECTED\n", | ||
1246 | GNUNET_i2s(&id)); | ||
1247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1248 | " PATHS TO %s:\n", | ||
1249 | GNUNET_i2s(&id)); | ||
1250 | for (p = neighbor->path_head; NULL != p; p = p->next) | ||
1251 | { | ||
1252 | struct GNUNET_PeerIdentity debug_id; | ||
1253 | unsigned int i; | ||
1254 | |||
1255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1256 | " path with %u hops through:\n", | ||
1257 | p->length); | ||
1258 | for (i = 0; i < p->length; i++) | ||
1259 | { | ||
1260 | GNUNET_PEER_resolve(p->peers[i], &debug_id); | ||
1261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1262 | " hop %u: %s\n", | ||
1263 | i, GNUNET_i2s(&debug_id)); | ||
1264 | } | ||
1265 | } | ||
1266 | #endif | ||
1267 | GNUNET_break (0); | ||
1268 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1269 | " no direct connection to %s\n", | ||
1270 | GNUNET_i2s (&id)); | ||
1271 | GNUNET_free (data); | ||
1272 | return; | ||
1273 | } | ||
1274 | if (GNUNET_MESSAGE_TYPE_MESH_PATH_ACK == type) | ||
1275 | type = 0; | ||
1276 | queue_add (data, | ||
1277 | type, | ||
1278 | size, | ||
1279 | neighbor, | ||
1280 | t); | ||
1281 | } | ||
1282 | |||
1283 | |||
1284 | /** | ||
1285 | * Sends a CREATE PATH message for a path to a peer, properly registrating | ||
1286 | * all used resources. | ||
1287 | * | ||
1288 | * @param t Tunnel for which the path is created. | ||
1289 | */ | ||
1290 | static void | ||
1291 | send_path_create (struct MeshTunnel *t) | ||
1292 | { | ||
1293 | struct MeshPeer *neighbor; | ||
1294 | |||
1295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send create path\n"); | ||
1296 | neighbor = peer_get_short (t->next_hop); | ||
1297 | queue_add (t, | ||
1298 | GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, | ||
1299 | sizeof (struct GNUNET_MESH_CreateTunnel) + | ||
1300 | (t->path->length * sizeof (struct GNUNET_PeerIdentity)), | ||
1301 | neighbor, | ||
1302 | t); | ||
1303 | tunnel_change_state (t, MESH_TUNNEL_WAITING); | ||
1304 | } | ||
1305 | |||
1306 | |||
1307 | /** | ||
1308 | * Sends a PATH ACK message in reponse to a received PATH_CREATE directed to us. | ||
1309 | * | ||
1310 | * @param t Tunnel which to confirm. | ||
1311 | */ | ||
1312 | static void | ||
1313 | send_path_ack (struct MeshTunnel *t) | ||
1314 | { | ||
1315 | struct MeshPeer *neighbor; | ||
1316 | |||
1317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send path ack\n"); | ||
1318 | neighbor = peer_get_short (t->prev_hop); | ||
1319 | queue_add (t, | ||
1320 | GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, | ||
1321 | sizeof (struct GNUNET_MESH_PathACK), | ||
1322 | neighbor, | ||
1323 | t); | ||
1324 | tunnel_change_state (t, MESH_TUNNEL_WAITING); | ||
1325 | } | ||
1326 | |||
1327 | |||
1328 | /** | ||
1329 | * Build an ACK message and queue it to send to the given peer. | ||
1330 | * | ||
1331 | * @param t Tunnel on which to send the ACK. | ||
1332 | * @param peer Peer to whom send the ACK. | ||
1333 | * @param ack Value of the ACK. | ||
1334 | */ | ||
1335 | static void | ||
1336 | send_ack (struct MeshTunnel *t, GNUNET_PEER_Id peer, uint32_t ack) | ||
1337 | { | ||
1338 | struct GNUNET_MESH_ACK msg; | ||
1339 | |||
1340 | GNUNET_PEER_resolve (t->id.oid, &msg.oid); | ||
1341 | msg.header.size = htons (sizeof (msg)); | ||
1342 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ACK); | ||
1343 | msg.pid = htonl (ack); | ||
1344 | msg.tid = htonl (t->id.tid); | ||
1345 | |||
1346 | send_prebuilt_message (&msg.header, peer, t); | ||
1347 | } | ||
1348 | |||
1349 | |||
1350 | /** | ||
1351 | * Core callback to write a pre-constructed data packet to core buffer | ||
1352 | * | ||
1353 | * @param cls Closure (MeshTransmissionDescriptor with data in "data" member). | ||
1354 | * @param size Number of bytes available in buf. | ||
1355 | * @param buf Where the to write the message. | ||
1356 | * | ||
1357 | * @return number of bytes written to buf | ||
1358 | */ | ||
1359 | static size_t | ||
1360 | send_core_data_raw (void *cls, size_t size, void *buf) | ||
1361 | { | ||
1362 | struct GNUNET_MessageHeader *msg = cls; | ||
1363 | size_t total_size; | ||
1364 | |||
1365 | GNUNET_assert (NULL != msg); | ||
1366 | total_size = ntohs (msg->size); | ||
1367 | |||
1368 | if (total_size > size) | ||
1369 | { | ||
1370 | GNUNET_break (0); | ||
1371 | return 0; | ||
1372 | } | ||
1373 | memcpy (buf, msg, total_size); | ||
1374 | GNUNET_free (cls); | ||
1375 | return total_size; | ||
1376 | } | ||
1377 | |||
1378 | |||
1379 | /** | ||
1380 | * Function to send a create path packet to a peer. | ||
1381 | * | ||
1382 | * @param cls closure | ||
1383 | * @param size number of bytes available in buf | ||
1384 | * @param buf where the callee should write the message | ||
1385 | * @return number of bytes written to buf | ||
1386 | */ | ||
1387 | static size_t | ||
1388 | send_core_path_create (void *cls, size_t size, void *buf) | ||
1389 | { | ||
1390 | struct MeshTunnel *t = cls; | ||
1391 | struct GNUNET_MESH_CreateTunnel *msg; | ||
1392 | struct GNUNET_PeerIdentity *peer_ptr; | ||
1393 | struct MeshPeerPath *p = t->path; | ||
1394 | size_t size_needed; | ||
1395 | uint32_t opt; | ||
1396 | int i; | ||
1397 | |||
1398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATE PATH sending...\n"); | ||
1399 | size_needed = | ||
1400 | sizeof (struct GNUNET_MESH_CreateTunnel) + | ||
1401 | p->length * sizeof (struct GNUNET_PeerIdentity); | ||
1402 | |||
1403 | if (size < size_needed || NULL == buf) | ||
1404 | { | ||
1405 | GNUNET_break (0); | ||
1406 | return 0; | ||
1407 | } | ||
1408 | msg = (struct GNUNET_MESH_CreateTunnel *) buf; | ||
1409 | msg->header.size = htons (size_needed); | ||
1410 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); | ||
1411 | msg->tid = ntohl (t->id.tid); | ||
1412 | |||
1413 | opt = 0; | ||
1414 | if (GNUNET_YES == t->nobuffer) | ||
1415 | opt |= GNUNET_MESH_OPTION_NOBUFFER; | ||
1416 | if (GNUNET_YES == t->reliable) | ||
1417 | opt |= GNUNET_MESH_OPTION_RELIABLE; | ||
1418 | msg->opt = htonl (opt); | ||
1419 | msg->port = htonl (t->port); | ||
1420 | |||
1421 | peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
1422 | for (i = 0; i < p->length; i++) | ||
1423 | { | ||
1424 | GNUNET_PEER_resolve (p->peers[i], peer_ptr++); | ||
1425 | } | ||
1426 | |||
1427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1428 | "CREATE PATH (%u bytes long) sent!\n", size_needed); | ||
1429 | return size_needed; | ||
1430 | } | ||
1431 | |||
1432 | |||
1433 | /** | ||
1434 | * Creates a path ack message in buf and frees all unused resources. | ||
1435 | * | ||
1436 | * @param cls closure (MeshTransmissionDescriptor) | ||
1437 | * @param size number of bytes available in buf | ||
1438 | * @param buf where the callee should write the message | ||
1439 | * @return number of bytes written to buf | ||
1440 | */ | ||
1441 | static size_t | ||
1442 | send_core_path_ack (void *cls, size_t size, void *buf) | ||
1443 | { | ||
1444 | struct MeshTunnel *t = cls; | ||
1445 | struct GNUNET_MESH_PathACK *msg = buf; | ||
1446 | |||
1447 | GNUNET_assert (NULL != t); | ||
1448 | if (sizeof (struct GNUNET_MESH_PathACK) > size) | ||
1449 | { | ||
1450 | GNUNET_break (0); | ||
1451 | return 0; | ||
1452 | } | ||
1453 | t->prev_fc.last_ack_sent = t->nobuffer ? 0 : t->queue_max - 1; | ||
1454 | msg->header.size = htons (sizeof (struct GNUNET_MESH_PathACK)); | ||
1455 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_ACK); | ||
1456 | GNUNET_PEER_resolve (t->id.oid, &msg->oid); | ||
1457 | msg->tid = htonl (t->id.tid); | ||
1458 | msg->peer_id = my_full_id; | ||
1459 | msg->ack = htonl (t->prev_fc.last_ack_sent); | ||
1460 | |||
1461 | /* TODO add signature */ | ||
1462 | |||
1463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PATH ACK sent!\n"); | ||
1464 | return sizeof (struct GNUNET_MESH_PathACK); | ||
1465 | } | ||
1466 | |||
1467 | |||
1468 | /** | ||
1469 | * Iterator over all the peers to remove the oldest not-used entry. | ||
1470 | * | ||
1471 | * @param cls Closure (unsued). | ||
1472 | * @param key ID of the peer. | ||
1473 | * @param value Peer_Info of the peer. | ||
1474 | * | ||
1475 | * FIXME implement | ||
1476 | */ | ||
1477 | static int | ||
1478 | peer_timeout (void *cls, | ||
1479 | const struct GNUNET_PeerIdentity *key, | ||
1480 | void *value) | ||
1481 | { | ||
1482 | return GNUNET_YES; | ||
1483 | } | ||
1484 | |||
1485 | |||
1486 | /** | ||
1487 | * Retrieve the MeshPeer stucture associated with the peer, create one | ||
1488 | * and insert it in the appropriate structures if the peer is not known yet. | ||
1489 | * | ||
1490 | * @param peer_id Full identity of the peer. | ||
1491 | * | ||
1492 | * @return Existing or newly created peer info. | ||
1493 | */ | ||
1494 | static struct MeshPeer * | ||
1495 | peer_get (const struct GNUNET_PeerIdentity *peer_id) | ||
1496 | { | ||
1497 | struct MeshPeer *peer; | ||
1498 | |||
1499 | peer = GNUNET_CONTAINER_multipeermap_get (peers, peer_id); | ||
1500 | if (NULL == peer) | ||
1501 | { | ||
1502 | peer = GNUNET_new (struct MeshPeer); | ||
1503 | if (GNUNET_CONTAINER_multipeermap_size (peers) > max_peers) | ||
1504 | { | ||
1505 | GNUNET_CONTAINER_multipeermap_iterate (peers, | ||
1506 | &peer_timeout, | ||
1507 | NULL); | ||
1508 | } | ||
1509 | GNUNET_CONTAINER_multipeermap_put (peers, peer_id, peer, | ||
1510 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
1511 | peer->id = GNUNET_PEER_intern (peer_id); | ||
1512 | } | ||
1513 | peer->last_contact = GNUNET_TIME_absolute_get(); | ||
1514 | |||
1515 | return peer; | ||
1516 | } | ||
1517 | |||
1518 | |||
1519 | /** | ||
1520 | * Retrieve the MeshPeer stucture associated with the peer, create one | ||
1521 | * and insert it in the appropriate structures if the peer is not known yet. | ||
1522 | * | ||
1523 | * @param peer Short identity of the peer. | ||
1524 | * | ||
1525 | * @return Existing or newly created peer info. | ||
1526 | */ | ||
1527 | static struct MeshPeer * | ||
1528 | peer_get_short (const GNUNET_PEER_Id peer) | ||
1529 | { | ||
1530 | return peer_get (GNUNET_PEER_resolve2 (peer)); | ||
1531 | } | ||
1532 | |||
1533 | |||
1534 | /** | ||
1535 | * Select which PID to POLL for, to compensate for lost messages. | ||
1536 | * | ||
1537 | * @param p Peer we want to poll. | ||
1538 | * @param t Tunnel about which we want to poll. | ||
1539 | * | ||
1540 | * @return PID to use, either last sent or first_in_queue - 1 | ||
1541 | */ | ||
1542 | static uint32_t | ||
1543 | peer_get_first_payload_pid (struct MeshPeer *p, struct MeshTunnel *t) | ||
1544 | { | ||
1545 | struct MeshPeerQueue *q; | ||
1546 | uint16_t type; | ||
1547 | |||
1548 | type = p->id == t->next_hop ? GNUNET_MESSAGE_TYPE_MESH_UNICAST : | ||
1549 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN; | ||
1550 | |||
1551 | for (q = p->queue_head; NULL != q; q = q->next) | ||
1552 | { | ||
1553 | if (q->type == type && q->tunnel == t) | ||
1554 | { | ||
1555 | struct GNUNET_MESH_Data *msg = q->cls; | ||
1556 | |||
1557 | /* Pretend that the last one sent was the previous to this */ | ||
1558 | return ntohl (msg->pid) - 1; | ||
1559 | } | ||
1560 | } | ||
1561 | |||
1562 | /* No data in queue, use last sent */ | ||
1563 | { | ||
1564 | struct MeshFlowControl *fc; | ||
1565 | |||
1566 | fc = p->id == t->next_hop ? &t->next_fc : &t->prev_fc; | ||
1567 | return fc->last_pid_sent; | ||
1568 | } | ||
1569 | } | ||
1570 | |||
1571 | |||
1572 | /** | ||
1573 | * Choose the best path towards a peer considering the tunnel properties. | ||
1574 | * | ||
1575 | * @param peer The destination peer. | ||
1576 | * @param t The tunnel the path is for. | ||
1577 | * | ||
1578 | * @return Best current known path towards the peer, if any. | ||
1579 | */ | ||
1580 | static struct MeshPeerPath * | ||
1581 | peer_get_best_path (const struct MeshPeer *peer, const struct MeshTunnel *t) | ||
1582 | { | ||
1583 | struct MeshPeerPath *best_p; | ||
1584 | struct MeshPeerPath *p; | ||
1585 | unsigned int best_cost; | ||
1586 | unsigned int cost; | ||
1587 | |||
1588 | best_p = p = peer->path_head; | ||
1589 | best_cost = cost = p->length; | ||
1590 | while (NULL != p) | ||
1591 | { | ||
1592 | if ((cost = p->length) < best_cost) | ||
1593 | { | ||
1594 | best_cost = cost; | ||
1595 | best_p = p; | ||
1596 | } | ||
1597 | p = p->next; | ||
1598 | } | ||
1599 | return best_p; | ||
1600 | } | ||
1601 | |||
1602 | |||
1603 | /** | ||
1604 | * Try to establish a new connection to this peer in the given tunnel. | ||
1605 | * If the peer doesn't have any path to it yet, try to get one. | ||
1606 | * If the peer already has some path, send a CREATE PATH towards it. | ||
1607 | * | ||
1608 | * @param peer PeerInfo of the peer. | ||
1609 | * @param t Tunnel for which to create the path, if possible. | ||
1610 | */ | ||
1611 | static void | ||
1612 | peer_connect (struct MeshPeer *peer, struct MeshTunnel *t) | ||
1613 | { | ||
1614 | struct MeshPeerPath *p; | ||
1615 | struct GNUNET_HashCode phash; | ||
1616 | |||
1617 | if (NULL != peer->path_head) | ||
1618 | { | ||
1619 | p = peer_get_best_path (peer, t); | ||
1620 | tunnel_use_path (t, p); | ||
1621 | send_path_create (t); | ||
1622 | } | ||
1623 | else if (NULL == peer->dhtget) | ||
1624 | { | ||
1625 | struct GNUNET_PeerIdentity id; | ||
1626 | |||
1627 | GNUNET_PEER_resolve (peer->id, &id); | ||
1628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1629 | "Starting DHT GET for peer %s\n", | ||
1630 | GNUNET_i2s (&id)); | ||
1631 | GNUNET_CRYPTO_hash (&id, sizeof (my_full_id), &phash); | ||
1632 | peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ | ||
1633 | GNUNET_BLOCK_TYPE_MESH_PEER, /* type */ | ||
1634 | &phash, /* key to search */ | ||
1635 | dht_replication_level, /* replication level */ | ||
1636 | GNUNET_DHT_RO_RECORD_ROUTE | | ||
1637 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
1638 | NULL, /* xquery */ | ||
1639 | 0, /* xquery bits */ | ||
1640 | &dht_get_id_handler, peer); | ||
1641 | tunnel_change_state (t, MESH_TUNNEL_SEARCHING); | ||
1642 | } | ||
1643 | else | ||
1644 | { | ||
1645 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1646 | "There is no path but the DHT GET is already started.\n"); | ||
1647 | } | ||
1648 | } | ||
1649 | |||
1650 | |||
1651 | /** | ||
1652 | * @brief Re-initiate traffic to this peer if necessary. | ||
1653 | * | ||
1654 | * Check if there is traffic queued towards this peer | ||
1655 | * and the core transmit handle is NULL (traffic was stalled). | ||
1656 | * If so, call core tmt rdy. | ||
1657 | * | ||
1658 | * @param peer_id Short ID of peer to which initiate traffic. | ||
1659 | */ | ||
1660 | static void | ||
1661 | peer_unlock_queue (GNUNET_PEER_Id peer_id) | ||
1662 | { | ||
1663 | struct MeshPeer *peer; | ||
1664 | struct MeshPeerQueue *q; | ||
1665 | size_t size; | ||
1666 | |||
1667 | peer = peer_get_short (peer_id); | ||
1668 | if (NULL != peer->core_transmit) | ||
1669 | return; | ||
1670 | |||
1671 | q = queue_get_next (peer); | ||
1672 | if (NULL == q) | ||
1673 | return; | ||
1674 | |||
1675 | size = q->size; | ||
1676 | peer->core_transmit = | ||
1677 | GNUNET_CORE_notify_transmit_ready (core_handle, | ||
1678 | GNUNET_NO, | ||
1679 | 0, | ||
1680 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1681 | GNUNET_PEER_resolve2 (peer->id), | ||
1682 | size, | ||
1683 | &queue_send, | ||
1684 | peer); | ||
1685 | } | ||
1686 | |||
1687 | |||
1688 | /** | ||
1689 | * Cancel all transmissions towards a neighbor that belong to a certain tunnel. | ||
1690 | * | ||
1691 | * @param neighbor Short ID of the neighbor to whom cancel the transmissions. | ||
1692 | * @param t Tunnel which to cancel. | ||
1693 | */ | ||
1694 | static void | ||
1695 | peer_cancel_queues (GNUNET_PEER_Id neighbor, struct MeshTunnel *t) | ||
1696 | { | ||
1697 | struct MeshPeer *peer; | ||
1698 | struct MeshPeerQueue *q; | ||
1699 | struct MeshPeerQueue *next; | ||
1700 | struct MeshFlowControl *fc; | ||
1701 | |||
1702 | if (0 == neighbor) | ||
1703 | return; /* Was local peer, 0'ed in tunnel_destroy_iterator */ | ||
1704 | peer = peer_get_short (neighbor); | ||
1705 | for (q = peer->queue_head; NULL != q; q = next) | ||
1706 | { | ||
1707 | next = q->next; | ||
1708 | if (q->tunnel == t) | ||
1709 | { | ||
1710 | if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == q->type || | ||
1711 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN == q->type) | ||
1712 | { | ||
1713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1714 | "peer_cancel_queues %s\n", | ||
1715 | GNUNET_MESH_DEBUG_M2S (q->type)); | ||
1716 | } | ||
1717 | queue_destroy (q, GNUNET_YES); | ||
1718 | } | ||
1719 | } | ||
1720 | if (NULL == peer->queue_head && NULL != peer->core_transmit) | ||
1721 | { | ||
1722 | GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit); | ||
1723 | peer->core_transmit = NULL; | ||
1724 | } | ||
1725 | fc = neighbor == t->next_hop ? &t->next_fc : &t->prev_fc; | ||
1726 | if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task) | ||
1727 | { | ||
1728 | GNUNET_SCHEDULER_cancel (fc->poll_task); | ||
1729 | fc->poll_task = GNUNET_SCHEDULER_NO_TASK; | ||
1730 | } | ||
1731 | } | ||
1732 | |||
1733 | |||
1734 | /** | ||
1735 | * Destroy the peer_info and free any allocated resources linked to it | ||
1736 | * | ||
1737 | * @param peer The peer_info to destroy. | ||
1738 | * | ||
1739 | * @return GNUNET_OK on success | ||
1740 | */ | ||
1741 | static int | ||
1742 | peer_destroy (struct MeshPeer *peer) | ||
1743 | { | ||
1744 | struct GNUNET_PeerIdentity id; | ||
1745 | struct MeshPeerPath *p; | ||
1746 | struct MeshPeerPath *nextp; | ||
1747 | unsigned int i; | ||
1748 | |||
1749 | GNUNET_PEER_resolve (peer->id, &id); | ||
1750 | GNUNET_PEER_change_rc (peer->id, -1); | ||
1751 | |||
1752 | if (GNUNET_YES != | ||
1753 | GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer)) | ||
1754 | { | ||
1755 | GNUNET_break (0); | ||
1756 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1757 | "removing peer %s, not in hashmap\n", GNUNET_i2s (&id)); | ||
1758 | } | ||
1759 | if (NULL != peer->dhtget) | ||
1760 | { | ||
1761 | GNUNET_DHT_get_stop (peer->dhtget); | ||
1762 | } | ||
1763 | p = peer->path_head; | ||
1764 | while (NULL != p) | ||
1765 | { | ||
1766 | nextp = p->next; | ||
1767 | GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, p); | ||
1768 | path_destroy (p); | ||
1769 | p = nextp; | ||
1770 | } | ||
1771 | for (i = 0; i < peer->ntunnels; i++) | ||
1772 | tunnel_destroy_empty (peer->tunnels[i]); | ||
1773 | GNUNET_array_grow (peer->tunnels, peer->ntunnels, 0); | ||
1774 | GNUNET_free (peer); | ||
1775 | return GNUNET_OK; | ||
1776 | } | ||
1777 | |||
1778 | |||
1779 | /** | ||
1780 | * Remove all paths that rely on a direct connection between p1 and p2 | ||
1781 | * from the peer itself and notify all tunnels about it. | ||
1782 | * | ||
1783 | * @param peer PeerInfo of affected peer. | ||
1784 | * @param p1 GNUNET_PEER_Id of one peer. | ||
1785 | * @param p2 GNUNET_PEER_Id of another peer that was connected to the first and | ||
1786 | * no longer is. | ||
1787 | * | ||
1788 | * TODO: optimize (see below) | ||
1789 | */ | ||
1790 | static void | ||
1791 | peer_remove_path (struct MeshPeer *peer, GNUNET_PEER_Id p1, | ||
1792 | GNUNET_PEER_Id p2) | ||
1793 | { | ||
1794 | struct MeshPeerPath *p; | ||
1795 | struct MeshPeerPath *next; | ||
1796 | struct MeshPeer *peer_d; | ||
1797 | GNUNET_PEER_Id d; | ||
1798 | unsigned int destroyed; | ||
1799 | unsigned int i; | ||
1800 | |||
1801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer_info_remove_path\n"); | ||
1802 | destroyed = 0; | ||
1803 | for (p = peer->path_head; NULL != p; p = next) | ||
1804 | { | ||
1805 | next = p->next; | ||
1806 | for (i = 0; i < (p->length - 1); i++) | ||
1807 | { | ||
1808 | if ((p->peers[i] == p1 && p->peers[i + 1] == p2) || | ||
1809 | (p->peers[i] == p2 && p->peers[i + 1] == p1)) | ||
1810 | { | ||
1811 | GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, p); | ||
1812 | path_destroy (p); | ||
1813 | destroyed++; | ||
1814 | break; | ||
1815 | } | ||
1816 | } | ||
1817 | } | ||
1818 | if (0 == destroyed) | ||
1819 | return; | ||
1820 | |||
1821 | for (i = 0; i < peer->ntunnels; i++) | ||
1822 | { | ||
1823 | d = tunnel_notify_connection_broken (peer->tunnels[i], p1, p2); | ||
1824 | if (0 == d) | ||
1825 | continue; | ||
1826 | |||
1827 | peer_d = peer_get_short (d); | ||
1828 | next = peer_get_best_path (peer_d, peer->tunnels[i]); | ||
1829 | tunnel_use_path (peer->tunnels[i], next); | ||
1830 | peer_connect (peer_d, peer->tunnels[i]); | ||
1831 | } | ||
1832 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer_info_remove_path END\n"); | ||
1833 | } | ||
1834 | |||
1835 | |||
1836 | /** | ||
1837 | * Add the path to the peer and update the path used to reach it in case this | ||
1838 | * is the shortest. | ||
1839 | * | ||
1840 | * @param peer_info Destination peer to add the path to. | ||
1841 | * @param path New path to add. Last peer must be the peer in arg 1. | ||
1842 | * Path will be either used of freed if already known. | ||
1843 | * @param trusted Do we trust that this path is real? | ||
1844 | */ | ||
1845 | void | ||
1846 | peer_add_path (struct MeshPeer *peer_info, struct MeshPeerPath *path, | ||
1847 | int trusted) | ||
1848 | { | ||
1849 | struct MeshPeerPath *aux; | ||
1850 | unsigned int l; | ||
1851 | unsigned int l2; | ||
1852 | |||
1853 | if ((NULL == peer_info) || (NULL == path)) | ||
1854 | { | ||
1855 | GNUNET_break (0); | ||
1856 | path_destroy (path); | ||
1857 | return; | ||
1858 | } | ||
1859 | if (path->peers[path->length - 1] != peer_info->id) | ||
1860 | { | ||
1861 | GNUNET_break (0); | ||
1862 | path_destroy (path); | ||
1863 | return; | ||
1864 | } | ||
1865 | if (2 >= path->length && GNUNET_NO == trusted) | ||
1866 | { | ||
1867 | /* Only allow CORE to tell us about direct paths */ | ||
1868 | path_destroy (path); | ||
1869 | return; | ||
1870 | } | ||
1871 | for (l = 1; l < path->length; l++) | ||
1872 | { | ||
1873 | if (path->peers[l] == myid) | ||
1874 | { | ||
1875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shortening path by %u\n", l); | ||
1876 | for (l2 = 0; l2 < path->length - l; l2++) | ||
1877 | { | ||
1878 | path->peers[l2] = path->peers[l + l2]; | ||
1879 | } | ||
1880 | path->length -= l; | ||
1881 | l = 1; | ||
1882 | path->peers = | ||
1883 | GNUNET_realloc (path->peers, path->length * sizeof (GNUNET_PEER_Id)); | ||
1884 | } | ||
1885 | } | ||
1886 | #if MESH_DEBUG | ||
1887 | { | ||
1888 | struct GNUNET_PeerIdentity id; | ||
1889 | |||
1890 | GNUNET_PEER_resolve (peer_info->id, &id); | ||
1891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n", | ||
1892 | path->length, GNUNET_i2s (&id)); | ||
1893 | } | ||
1894 | #endif | ||
1895 | l = path_get_length (path); | ||
1896 | if (0 == l) | ||
1897 | { | ||
1898 | path_destroy (path); | ||
1899 | return; | ||
1900 | } | ||
1901 | |||
1902 | GNUNET_assert (peer_info->id == path->peers[path->length - 1]); | ||
1903 | for (aux = peer_info->path_head; aux != NULL; aux = aux->next) | ||
1904 | { | ||
1905 | l2 = path_get_length (aux); | ||
1906 | if (l2 > l) | ||
1907 | { | ||
1908 | GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head, | ||
1909 | peer_info->path_tail, aux, path); | ||
1910 | return; | ||
1911 | } | ||
1912 | else | ||
1913 | { | ||
1914 | if (l2 == l && memcmp (path->peers, aux->peers, l) == 0) | ||
1915 | { | ||
1916 | path_destroy (path); | ||
1917 | return; | ||
1918 | } | ||
1919 | } | ||
1920 | } | ||
1921 | GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, peer_info->path_tail, | ||
1922 | path); | ||
1923 | return; | ||
1924 | } | ||
1925 | |||
1926 | |||
1927 | /** | ||
1928 | * Add the path to the origin peer and update the path used to reach it in case | ||
1929 | * this is the shortest. | ||
1930 | * The path is given in peer_info -> destination, therefore we turn the path | ||
1931 | * upside down first. | ||
1932 | * | ||
1933 | * @param peer_info Peer to add the path to, being the origin of the path. | ||
1934 | * @param path New path to add after being inversed. | ||
1935 | * Path will be either used or freed. | ||
1936 | * @param trusted Do we trust that this path is real? | ||
1937 | */ | ||
1938 | static void | ||
1939 | peer_add_path_to_origin (struct MeshPeer *peer_info, | ||
1940 | struct MeshPeerPath *path, int trusted) | ||
1941 | { | ||
1942 | path_invert (path); | ||
1943 | peer_add_path (peer_info, path, trusted); | ||
1944 | } | ||
1945 | |||
1946 | |||
1947 | /** | ||
1948 | * Add a tunnel to the list of tunnels a peer participates in. | ||
1949 | * Update the tunnel's destination. | ||
1950 | * | ||
1951 | * @param p Peer to add to. | ||
1952 | * @param t Tunnel to add. | ||
1953 | */ | ||
1954 | static void | ||
1955 | peer_add_tunnel (struct MeshPeer *p, struct MeshTunnel *t) | ||
1956 | { | ||
1957 | if (0 != t->dest) | ||
1958 | { | ||
1959 | GNUNET_break (t->dest == p->id); | ||
1960 | return; | ||
1961 | } | ||
1962 | t->dest = p->id; | ||
1963 | GNUNET_PEER_change_rc (t->dest, 1); | ||
1964 | GNUNET_array_append (p->tunnels, p->ntunnels, t); | ||
1965 | } | ||
1966 | |||
1967 | |||
1968 | /** | ||
1969 | * Remove a tunnel from the list of tunnels a peer participates in. | ||
1970 | * Free the tunnel's destination. | ||
1971 | * | ||
1972 | * @param p Peer to clean. | ||
1973 | * @param t Tunnel to remove. | ||
1974 | */ | ||
1975 | static void | ||
1976 | peer_remove_tunnel (struct MeshPeer *p, struct MeshTunnel *t) | ||
1977 | { | ||
1978 | unsigned int i; | ||
1979 | |||
1980 | if (t->dest == p->id) | ||
1981 | { | ||
1982 | GNUNET_PEER_change_rc (t->dest, -1); | ||
1983 | t->dest = 0; | ||
1984 | } | ||
1985 | for (i = 0; i < p->ntunnels; i++) | ||
1986 | { | ||
1987 | if (p->tunnels[i] == t) | ||
1988 | { | ||
1989 | p->tunnels[i] = p->tunnels[p->ntunnels - 1]; | ||
1990 | GNUNET_array_grow (p->tunnels, p->ntunnels, p->ntunnels - 1); | ||
1991 | return; | ||
1992 | } | ||
1993 | } | ||
1994 | } | ||
1995 | |||
1996 | |||
1997 | /** | ||
1998 | * Function called if the connection to the peer has been stalled for a while, | ||
1999 | * possibly due to a missed ACK. Poll the peer about its ACK status. | ||
2000 | * | ||
2001 | * @param cls Closure (poll ctx). | ||
2002 | * @param tc TaskContext. | ||
2003 | */ | ||
2004 | static void | ||
2005 | tunnel_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2006 | { | ||
2007 | struct MeshFlowControl *fc = cls; | ||
2008 | struct GNUNET_MESH_Poll msg; | ||
2009 | struct MeshTunnel *t = fc->t; | ||
2010 | GNUNET_PEER_Id peer; | ||
2011 | |||
2012 | fc->poll_task = GNUNET_SCHEDULER_NO_TASK; | ||
2013 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
2014 | { | ||
2015 | return; | ||
2016 | } | ||
2017 | |||
2018 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** Polling!\n"); | ||
2019 | |||
2020 | GNUNET_PEER_resolve (t->id.oid, &msg.oid); | ||
2021 | |||
2022 | if (fc == &t->prev_fc) | ||
2023 | { | ||
2024 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** prev peer!\n"); | ||
2025 | peer = t->prev_hop; | ||
2026 | } | ||
2027 | else if (fc == &t->next_fc) | ||
2028 | { | ||
2029 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** next peer!\n"); | ||
2030 | peer = t->next_hop; | ||
2031 | } | ||
2032 | else | ||
2033 | { | ||
2034 | GNUNET_break (0); | ||
2035 | return; | ||
2036 | } | ||
2037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** peer: %s!\n", | ||
2038 | GNUNET_i2s(GNUNET_PEER_resolve2 (peer))); | ||
2039 | if (0 == peer) | ||
2040 | { | ||
2041 | if (GNUNET_YES == t->destroy) | ||
2042 | tunnel_destroy (t); | ||
2043 | else | ||
2044 | GNUNET_break (0); | ||
2045 | |||
2046 | return; | ||
2047 | } | ||
2048 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL); | ||
2049 | msg.header.size = htons (sizeof (msg)); | ||
2050 | msg.tid = htonl (t->id.tid); | ||
2051 | msg.pid = htonl (peer_get_first_payload_pid (peer_get_short (peer), t)); | ||
2052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** pid (%u)!\n", ntohl (msg.pid)); | ||
2053 | send_prebuilt_message (&msg.header, peer, t); | ||
2054 | fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); | ||
2055 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, | ||
2056 | &tunnel_poll, fc); | ||
2057 | } | ||
2058 | |||
2059 | |||
2060 | /** | ||
2061 | * Build a PeerPath from the paths returned from the DHT, reversing the paths | ||
2062 | * to obtain a local peer -> destination path and interning the peer ids. | ||
2063 | * | ||
2064 | * @return Newly allocated and created path | ||
2065 | */ | ||
2066 | static struct MeshPeerPath * | ||
2067 | path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | ||
2068 | unsigned int get_path_length, | ||
2069 | const struct GNUNET_PeerIdentity *put_path, | ||
2070 | unsigned int put_path_length) | ||
2071 | { | ||
2072 | struct MeshPeerPath *p; | ||
2073 | GNUNET_PEER_Id id; | ||
2074 | int i; | ||
2075 | |||
2076 | p = path_new (1); | ||
2077 | p->peers[0] = myid; | ||
2078 | GNUNET_PEER_change_rc (myid, 1); | ||
2079 | i = get_path_length; | ||
2080 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " GET has %d hops.\n", i); | ||
2081 | for (i--; i >= 0; i--) | ||
2082 | { | ||
2083 | id = GNUNET_PEER_intern (&get_path[i]); | ||
2084 | if (p->length > 0 && id == p->peers[p->length - 1]) | ||
2085 | { | ||
2086 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Optimizing 1 hop out.\n"); | ||
2087 | GNUNET_PEER_change_rc (id, -1); | ||
2088 | } | ||
2089 | else | ||
2090 | { | ||
2091 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Adding from GET: %s.\n", | ||
2092 | GNUNET_i2s (&get_path[i])); | ||
2093 | p->length++; | ||
2094 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | ||
2095 | p->peers[p->length - 1] = id; | ||
2096 | } | ||
2097 | } | ||
2098 | i = put_path_length; | ||
2099 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " PUT has %d hops.\n", i); | ||
2100 | for (i--; i >= 0; i--) | ||
2101 | { | ||
2102 | id = GNUNET_PEER_intern (&put_path[i]); | ||
2103 | if (id == myid) | ||
2104 | { | ||
2105 | /* PUT path went through us, so discard the path up until now and start | ||
2106 | * from here to get a much shorter (and loop-free) path. | ||
2107 | */ | ||
2108 | path_destroy (p); | ||
2109 | p = path_new (0); | ||
2110 | } | ||
2111 | if (p->length > 0 && id == p->peers[p->length - 1]) | ||
2112 | { | ||
2113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Optimizing 1 hop out.\n"); | ||
2114 | GNUNET_PEER_change_rc (id, -1); | ||
2115 | } | ||
2116 | else | ||
2117 | { | ||
2118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Adding from PUT: %s.\n", | ||
2119 | GNUNET_i2s (&put_path[i])); | ||
2120 | p->length++; | ||
2121 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | ||
2122 | p->peers[p->length - 1] = id; | ||
2123 | } | ||
2124 | } | ||
2125 | #if MESH_DEBUG | ||
2126 | if (get_path_length > 0) | ||
2127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (first of GET: %s)\n", | ||
2128 | GNUNET_i2s (&get_path[0])); | ||
2129 | if (put_path_length > 0) | ||
2130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (first of PUT: %s)\n", | ||
2131 | GNUNET_i2s (&put_path[0])); | ||
2132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " In total: %d hops\n", | ||
2133 | p->length); | ||
2134 | for (i = 0; i < p->length; i++) | ||
2135 | { | ||
2136 | struct GNUNET_PeerIdentity peer_id; | ||
2137 | |||
2138 | GNUNET_PEER_resolve (p->peers[i], &peer_id); | ||
2139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n", p->peers[i], | ||
2140 | GNUNET_i2s (&peer_id)); | ||
2141 | } | ||
2142 | #endif | ||
2143 | return p; | ||
2144 | } | ||
2145 | |||
2146 | |||
2147 | /** | ||
2148 | * Adds a path to the peer_infos of all the peers in the path | ||
2149 | * | ||
2150 | * @param p Path to process. | ||
2151 | * @param confirmed Whether we know if the path works or not. | ||
2152 | */ | ||
2153 | static void | ||
2154 | path_add_to_peers (struct MeshPeerPath *p, int confirmed) | ||
2155 | { | ||
2156 | unsigned int i; | ||
2157 | |||
2158 | /* TODO: invert and add */ | ||
2159 | for (i = 0; i < p->length && p->peers[i] != myid; i++) /* skip'em */ ; | ||
2160 | for (i++; i < p->length; i++) | ||
2161 | { | ||
2162 | struct MeshPeer *aux; | ||
2163 | struct MeshPeerPath *copy; | ||
2164 | |||
2165 | aux = peer_get_short (p->peers[i]); | ||
2166 | copy = path_duplicate (p); | ||
2167 | copy->length = i + 1; | ||
2168 | peer_add_path (aux, copy, p->length < 3 ? GNUNET_NO : confirmed); | ||
2169 | } | ||
2170 | } | ||
2171 | |||
2172 | |||
2173 | /** | ||
2174 | * Search for a tunnel among the incoming tunnels | ||
2175 | * | ||
2176 | * @param tid the local id of the tunnel | ||
2177 | * | ||
2178 | * @return tunnel handler, NULL if doesn't exist | ||
2179 | */ | ||
2180 | static struct MeshTunnel * | ||
2181 | tunnel_get_incoming (MESH_TunnelNumber tid) | ||
2182 | { | ||
2183 | GNUNET_assert (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV); | ||
2184 | return GNUNET_CONTAINER_multihashmap32_get (incoming_tunnels, tid); | ||
2185 | } | ||
2186 | |||
2187 | |||
2188 | /** | ||
2189 | * Search for a tunnel among the tunnels for a client | ||
2190 | * | ||
2191 | * @param c the client whose tunnels to search in | ||
2192 | * @param tid the local id of the tunnel | ||
2193 | * | ||
2194 | * @return tunnel handler, NULL if doesn't exist | ||
2195 | */ | ||
2196 | static struct MeshTunnel * | ||
2197 | tunnel_get_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid) | ||
2198 | { | ||
2199 | if (0 == (tid & GNUNET_MESH_LOCAL_TUNNEL_ID_CLI)) | ||
2200 | { | ||
2201 | GNUNET_break_op (0); | ||
2202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TID %X not a local tid\n", tid); | ||
2203 | return NULL; | ||
2204 | } | ||
2205 | if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | ||
2206 | { | ||
2207 | return tunnel_get_incoming (tid); | ||
2208 | } | ||
2209 | else | ||
2210 | { | ||
2211 | return GNUNET_CONTAINER_multihashmap32_get (c->own_tunnels, tid); | ||
2212 | } | ||
2213 | } | ||
2214 | |||
2215 | |||
2216 | /** | ||
2217 | * Search for a tunnel by global ID using PEER_ID | ||
2218 | * | ||
2219 | * @param pi owner of the tunnel | ||
2220 | * @param tid global tunnel number | ||
2221 | * | ||
2222 | * @return tunnel handler, NULL if doesn't exist | ||
2223 | */ | ||
2224 | static struct MeshTunnel * | ||
2225 | tunnel_get_by_pi (GNUNET_PEER_Id pi, MESH_TunnelNumber tid) | ||
2226 | { | ||
2227 | struct MESH_TunnelID id; | ||
2228 | struct GNUNET_HashCode hash; | ||
2229 | |||
2230 | id.oid = pi; | ||
2231 | id.tid = tid; | ||
2232 | |||
2233 | GNUNET_CRYPTO_hash (&id, sizeof (struct MESH_TunnelID), &hash); | ||
2234 | return GNUNET_CONTAINER_multihashmap_get (tunnels, &hash); | ||
2235 | } | ||
2236 | |||
2237 | |||
2238 | /** | ||
2239 | * Search for a tunnel by global ID using full PeerIdentities | ||
2240 | * | ||
2241 | * @param oid owner of the tunnel | ||
2242 | * @param tid global tunnel number | ||
2243 | * | ||
2244 | * @return tunnel handler, NULL if doesn't exist | ||
2245 | */ | ||
2246 | static struct MeshTunnel * | ||
2247 | tunnel_get (const struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) | ||
2248 | { | ||
2249 | return tunnel_get_by_pi (GNUNET_PEER_search (oid), tid); | ||
2250 | } | ||
2251 | |||
2252 | |||
2253 | /** | ||
2254 | * Change the tunnel state. | ||
2255 | * | ||
2256 | * @param t Tunnel whose ttate to change. | ||
2257 | * @param state New state. | ||
2258 | */ | ||
2259 | static void | ||
2260 | tunnel_change_state (struct MeshTunnel *t, enum MeshTunnelState state) | ||
2261 | { | ||
2262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2263 | "Tunnel %s[%X] state was %s\n", | ||
2264 | GNUNET_i2s (GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid, | ||
2265 | GNUNET_MESH_DEBUG_S2S (t->state)); | ||
2266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2267 | "Tunnel %s[%X] state is now %s\n", | ||
2268 | GNUNET_i2s (GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid, | ||
2269 | GNUNET_MESH_DEBUG_S2S (state)); | ||
2270 | t->state = state; | ||
2271 | } | ||
2272 | |||
2273 | |||
2274 | |||
2275 | /** | ||
2276 | * Add a client to a tunnel, initializing all needed data structures. | ||
2277 | * | ||
2278 | * @param t Tunnel to which add the client. | ||
2279 | * @param c Client which to add to the tunnel. | ||
2280 | */ | ||
2281 | static void | ||
2282 | tunnel_add_client (struct MeshTunnel *t, struct MeshClient *c) | ||
2283 | { | ||
2284 | if (NULL != t->client) | ||
2285 | { | ||
2286 | GNUNET_break(0); | ||
2287 | return; | ||
2288 | } | ||
2289 | if (GNUNET_OK != | ||
2290 | GNUNET_CONTAINER_multihashmap32_put (c->incoming_tunnels, | ||
2291 | t->local_tid_dest, t, | ||
2292 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
2293 | { | ||
2294 | GNUNET_break (0); | ||
2295 | return; | ||
2296 | } | ||
2297 | if (GNUNET_OK != | ||
2298 | GNUNET_CONTAINER_multihashmap32_put (incoming_tunnels, | ||
2299 | t->local_tid_dest, t, | ||
2300 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
2301 | { | ||
2302 | GNUNET_break (0); | ||
2303 | return; | ||
2304 | } | ||
2305 | t->client = c; | ||
2306 | } | ||
2307 | |||
2308 | |||
2309 | static void | ||
2310 | tunnel_use_path (struct MeshTunnel *t, struct MeshPeerPath *p) | ||
2311 | { | ||
2312 | unsigned int own_pos; | ||
2313 | |||
2314 | for (own_pos = 0; own_pos < p->length; own_pos++) | ||
2315 | { | ||
2316 | if (p->peers[own_pos] == myid) | ||
2317 | break; | ||
2318 | } | ||
2319 | if (own_pos > p->length - 1) | ||
2320 | { | ||
2321 | GNUNET_break (0); | ||
2322 | return; | ||
2323 | } | ||
2324 | |||
2325 | if (own_pos < p->length - 1) | ||
2326 | t->next_hop = p->peers[own_pos + 1]; | ||
2327 | else | ||
2328 | t->next_hop = p->peers[own_pos]; | ||
2329 | GNUNET_PEER_change_rc (t->next_hop, 1); | ||
2330 | if (0 < own_pos) | ||
2331 | t->prev_hop = p->peers[own_pos - 1]; | ||
2332 | else | ||
2333 | t->prev_hop = p->peers[0]; | ||
2334 | GNUNET_PEER_change_rc (t->prev_hop, 1); | ||
2335 | |||
2336 | if (NULL != t->path) | ||
2337 | path_destroy (t->path); | ||
2338 | t->path = path_duplicate (p); | ||
2339 | if (0 == own_pos) | ||
2340 | { | ||
2341 | if (GNUNET_SCHEDULER_NO_TASK != t->fwd_maintenance_task) | ||
2342 | GNUNET_SCHEDULER_cancel (t->fwd_maintenance_task); | ||
2343 | t->fwd_maintenance_task = | ||
2344 | GNUNET_SCHEDULER_add_delayed (refresh_path_time, | ||
2345 | &tunnel_fwd_keepalive, t); | ||
2346 | } | ||
2347 | } | ||
2348 | |||
2349 | |||
2350 | /** | ||
2351 | * Notifies a tunnel that a connection has broken that affects at least | ||
2352 | * some of its peers. Sends a notification towards the root of the tree. | ||
2353 | * In case the peer is the owner of the tree, notifies the client that owns | ||
2354 | * the tunnel and tries to reconnect. | ||
2355 | * | ||
2356 | * @param t Tunnel affected. | ||
2357 | * @param p1 Peer that got disconnected from p2. | ||
2358 | * @param p2 Peer that got disconnected from p1. | ||
2359 | * | ||
2360 | * @return Short ID of the peer disconnected (either p1 or p2). | ||
2361 | * 0 if the tunnel remained unaffected. | ||
2362 | */ | ||
2363 | static GNUNET_PEER_Id | ||
2364 | tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1, | ||
2365 | GNUNET_PEER_Id p2) | ||
2366 | { | ||
2367 | // if (myid != p1 && myid != p2) FIXME | ||
2368 | // { | ||
2369 | // return; | ||
2370 | // } | ||
2371 | // | ||
2372 | // if (tree_get_predecessor (t->tree) != 0) | ||
2373 | // { | ||
2374 | // /* We are the peer still connected, notify owner of the disconnection. */ | ||
2375 | // struct GNUNET_MESH_PathBroken msg; | ||
2376 | // struct GNUNET_PeerIdentity neighbor; | ||
2377 | // | ||
2378 | // msg.header.size = htons (sizeof (msg)); | ||
2379 | // msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN); | ||
2380 | // GNUNET_PEER_resolve (t->id.oid, &msg.oid); | ||
2381 | // msg.tid = htonl (t->id.tid); | ||
2382 | // msg.peer1 = my_full_id; | ||
2383 | // GNUNET_PEER_resolve (pid, &msg.peer2); | ||
2384 | // GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &neighbor); | ||
2385 | // send_prebuilt_message (&msg.header, &neighbor, t); | ||
2386 | // } | ||
2387 | return 0; | ||
2388 | } | ||
2389 | |||
2390 | |||
2391 | /** | ||
2392 | * Send an end-to-end FWD ACK message for the most recent in-sequence payload. | ||
2393 | * | ||
2394 | * @param t Tunnel this is about. | ||
2395 | * @param fwd Is for FWD traffic? (ACK dest->owner) | ||
2396 | */ | ||
2397 | static void | ||
2398 | tunnel_send_data_ack (struct MeshTunnel *t, int fwd) | ||
2399 | { | ||
2400 | struct GNUNET_MESH_DataACK msg; | ||
2401 | struct MeshTunnelReliability *rel; | ||
2402 | struct MeshReliableMessage *copy; | ||
2403 | GNUNET_PEER_Id hop; | ||
2404 | uint64_t mask; | ||
2405 | unsigned int delta; | ||
2406 | |||
2407 | rel = fwd ? t->bck_rel : t->fwd_rel; | ||
2408 | hop = fwd ? t->prev_hop : t->next_hop; | ||
2409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2410 | "send_data_ack for %u\n", | ||
2411 | rel->mid_recv - 1); | ||
2412 | |||
2413 | if (GNUNET_NO == t->reliable) | ||
2414 | { | ||
2415 | GNUNET_break_op (0); | ||
2416 | return; | ||
2417 | } | ||
2418 | msg.header.type = htons (fwd ? GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK : | ||
2419 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK); | ||
2420 | msg.header.size = htons (sizeof (msg)); | ||
2421 | msg.tid = htonl (t->id.tid); | ||
2422 | GNUNET_PEER_resolve (t->id.oid, &msg.oid); | ||
2423 | msg.mid = htonl (rel->mid_recv - 1); | ||
2424 | msg.futures = 0; | ||
2425 | for (copy = rel->head_recv; NULL != copy; copy = copy->next) | ||
2426 | { | ||
2427 | delta = copy->mid - rel->mid_recv; | ||
2428 | if (63 < delta) | ||
2429 | break; | ||
2430 | mask = 0x1LL << delta; | ||
2431 | msg.futures |= mask; | ||
2432 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2433 | " setting bit for %u (delta %u) (%llX) -> %llX\n", | ||
2434 | copy->mid, delta, mask, msg.futures); | ||
2435 | } | ||
2436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " final futures %llX\n", msg.futures); | ||
2437 | |||
2438 | send_prebuilt_message (&msg.header, hop, t); | ||
2439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_data_ack END\n"); | ||
2440 | } | ||
2441 | |||
2442 | |||
2443 | /** | ||
2444 | * Send an ACK informing the predecessor about the available buffer space. | ||
2445 | * In case there is no predecessor, inform the owning client. | ||
2446 | * If buffering is off, send only on behalf of children or self if endpoint. | ||
2447 | * If buffering is on, send when sent to children and buffer space is free. | ||
2448 | * Note that although the name is fwd_ack, the FWD mean forward *traffic*, | ||
2449 | * the ACK itself goes "back" (towards root). | ||
2450 | * | ||
2451 | * @param t Tunnel on which to send the ACK. | ||
2452 | * @param type Type of message that triggered the ACK transmission. | ||
2453 | * @param fwd Is this FWD ACK? (Going dest->owner) | ||
2454 | */ | ||
2455 | static void | ||
2456 | tunnel_send_ack (struct MeshTunnel *t, uint16_t type, int fwd) | ||
2457 | { | ||
2458 | struct MeshTunnelReliability *rel; | ||
2459 | struct MeshFlowControl *next_fc; | ||
2460 | struct MeshFlowControl *prev_fc; | ||
2461 | struct MeshClient *c; | ||
2462 | struct MeshClient *o; | ||
2463 | GNUNET_PEER_Id hop; | ||
2464 | uint32_t delta_mid; | ||
2465 | uint32_t ack; | ||
2466 | int delta; | ||
2467 | |||
2468 | rel = fwd ? t->fwd_rel : t->bck_rel; | ||
2469 | c = fwd ? t->client : t->owner; | ||
2470 | o = fwd ? t->owner : t->client; | ||
2471 | next_fc = fwd ? &t->next_fc : &t->prev_fc; | ||
2472 | prev_fc = fwd ? &t->prev_fc : &t->next_fc; | ||
2473 | hop = fwd ? t->prev_hop : t->next_hop; | ||
2474 | |||
2475 | switch (type) | ||
2476 | { | ||
2477 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
2478 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
2479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2480 | "ACK due to %s\n", | ||
2481 | GNUNET_MESH_DEBUG_M2S (type)); | ||
2482 | if (GNUNET_YES == t->nobuffer && (GNUNET_NO == t->reliable || NULL == c)) | ||
2483 | { | ||
2484 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, nobuffer\n"); | ||
2485 | return; | ||
2486 | } | ||
2487 | if (GNUNET_YES == t->reliable && NULL != c) | ||
2488 | tunnel_send_data_ack (t, fwd); | ||
2489 | break; | ||
2490 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK: | ||
2491 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK: | ||
2492 | case GNUNET_MESSAGE_TYPE_MESH_ACK: | ||
2493 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: | ||
2494 | break; | ||
2495 | case GNUNET_MESSAGE_TYPE_MESH_POLL: | ||
2496 | case GNUNET_MESSAGE_TYPE_MESH_PATH_ACK: | ||
2497 | t->force_ack = GNUNET_YES; | ||
2498 | break; | ||
2499 | default: | ||
2500 | GNUNET_break (0); | ||
2501 | } | ||
2502 | |||
2503 | /* Check if we need to transmit the ACK */ | ||
2504 | if (NULL == o && | ||
2505 | prev_fc->last_ack_sent - prev_fc->last_pid_recv > 3 && | ||
2506 | GNUNET_NO == t->force_ack) | ||
2507 | { | ||
2508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer free\n"); | ||
2509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2510 | " last pid recv: %u, last ack sent: %u\n", | ||
2511 | prev_fc->last_pid_recv, prev_fc->last_ack_sent); | ||
2512 | return; | ||
2513 | } | ||
2514 | |||
2515 | /* Ok, ACK might be necessary, what PID to ACK? */ | ||
2516 | delta = t->queue_max - next_fc->queue_n; | ||
2517 | if (NULL != o && GNUNET_YES == t->reliable && NULL != rel->head_sent) | ||
2518 | delta_mid = rel->mid_sent - rel->head_sent->mid; | ||
2519 | else | ||
2520 | delta_mid = 0; | ||
2521 | if (0 > delta || (GNUNET_YES == t->reliable && | ||
2522 | NULL != o && | ||
2523 | (10 < rel->n_sent || 64 <= delta_mid))) | ||
2524 | delta = 0; | ||
2525 | if (NULL != o && delta > 1) | ||
2526 | delta = 1; | ||
2527 | ack = prev_fc->last_pid_recv + delta; | ||
2528 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); | ||
2529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2530 | " last pid %u, last ack %u, qmax %u, q %u\n", | ||
2531 | prev_fc->last_pid_recv, prev_fc->last_ack_sent, | ||
2532 | t->queue_max, next_fc->queue_n); | ||
2533 | if (ack == prev_fc->last_ack_sent && GNUNET_NO == t->force_ack) | ||
2534 | { | ||
2535 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n"); | ||
2536 | return; | ||
2537 | } | ||
2538 | |||
2539 | prev_fc->last_ack_sent = ack; | ||
2540 | if (NULL != o) | ||
2541 | send_local_ack (t, o, fwd); | ||
2542 | else if (0 != hop) | ||
2543 | send_ack (t, hop, ack); | ||
2544 | else | ||
2545 | GNUNET_break (GNUNET_YES == t->destroy); | ||
2546 | t->force_ack = GNUNET_NO; | ||
2547 | } | ||
2548 | |||
2549 | |||
2550 | /** | ||
2551 | * Modify the mesh message TID from global to local and send to client. | ||
2552 | * | ||
2553 | * @param t Tunnel on which to send the message. | ||
2554 | * @param msg Message to modify and send. | ||
2555 | * @param c Client to send to. | ||
2556 | * @param tid Tunnel ID to use (c can be both owner and client). | ||
2557 | */ | ||
2558 | static void | ||
2559 | tunnel_send_client_to_tid (struct MeshTunnel *t, | ||
2560 | const struct GNUNET_MESH_Data *msg, | ||
2561 | struct MeshClient *c, MESH_TunnelNumber tid) | ||
2562 | { | ||
2563 | struct GNUNET_MESH_LocalData *copy; | ||
2564 | uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_MESH_Data); | ||
2565 | char cbuf[size + sizeof (struct GNUNET_MESH_LocalData)]; | ||
2566 | |||
2567 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
2568 | { | ||
2569 | GNUNET_break_op (0); | ||
2570 | return; | ||
2571 | } | ||
2572 | if (NULL == c) | ||
2573 | { | ||
2574 | GNUNET_break (0); | ||
2575 | return; | ||
2576 | } | ||
2577 | copy = (struct GNUNET_MESH_LocalData *) cbuf; | ||
2578 | memcpy (©[1], &msg[1], size); | ||
2579 | copy->header.size = htons (sizeof (struct GNUNET_MESH_LocalData) + size); | ||
2580 | copy->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA); | ||
2581 | copy->tid = htonl (tid); | ||
2582 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, | ||
2583 | ©->header, GNUNET_NO); | ||
2584 | } | ||
2585 | |||
2586 | /** | ||
2587 | * Modify the unicast message TID from global to local and send to client. | ||
2588 | * | ||
2589 | * @param t Tunnel on which to send the message. | ||
2590 | * @param msg Message to modify and send. | ||
2591 | * @param fwd Forward? | ||
2592 | */ | ||
2593 | static void | ||
2594 | tunnel_send_client_data (struct MeshTunnel *t, | ||
2595 | const struct GNUNET_MESH_Data *msg, | ||
2596 | int fwd) | ||
2597 | { | ||
2598 | if (fwd) | ||
2599 | tunnel_send_client_to_tid (t, msg, t->client, t->local_tid_dest); | ||
2600 | else | ||
2601 | tunnel_send_client_to_tid (t, msg, t->owner, t->local_tid); | ||
2602 | } | ||
2603 | |||
2604 | |||
2605 | /** | ||
2606 | * Send up to 64 buffered messages to the client for in order delivery. | ||
2607 | * | ||
2608 | * @param t Tunnel on which to empty the message buffer. | ||
2609 | * @param c Client to send to. | ||
2610 | * @param rel Reliability structure to corresponding peer. | ||
2611 | * If rel == t->bck_rel, this is FWD data. | ||
2612 | */ | ||
2613 | static void | ||
2614 | tunnel_send_client_buffered_data (struct MeshTunnel *t, struct MeshClient *c, | ||
2615 | struct MeshTunnelReliability *rel) | ||
2616 | { | ||
2617 | ; | ||
2618 | struct MeshReliableMessage *copy; | ||
2619 | struct MeshReliableMessage *next; | ||
2620 | |||
2621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n"); | ||
2622 | for (copy = rel->head_recv; NULL != copy; copy = next) | ||
2623 | { | ||
2624 | next = copy->next; | ||
2625 | if (copy->mid == rel->mid_recv) | ||
2626 | { | ||
2627 | struct GNUNET_MESH_Data *msg = (struct GNUNET_MESH_Data *) ©[1]; | ||
2628 | |||
2629 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2630 | " have %u! now expecting %u\n", | ||
2631 | copy->mid, rel->mid_recv + 1); | ||
2632 | tunnel_send_client_data (t, msg, (rel == t->bck_rel)); | ||
2633 | rel->mid_recv++; | ||
2634 | GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy); | ||
2635 | GNUNET_free (copy); | ||
2636 | } | ||
2637 | else | ||
2638 | { | ||
2639 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2640 | " don't have %u, next is %u\n", | ||
2641 | rel->mid_recv, | ||
2642 | copy->mid); | ||
2643 | return; | ||
2644 | } | ||
2645 | } | ||
2646 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data END\n"); | ||
2647 | } | ||
2648 | |||
2649 | |||
2650 | /** | ||
2651 | * We have received a message out of order, buffer it until we receive | ||
2652 | * the missing one and we can feed the rest to the client. | ||
2653 | * | ||
2654 | * @param t Tunnel to add to. | ||
2655 | * @param msg Message to buffer. | ||
2656 | * @param rel Reliability data to the corresponding direction. | ||
2657 | */ | ||
2658 | static void | ||
2659 | tunnel_add_buffered_data (struct MeshTunnel *t, | ||
2660 | const struct GNUNET_MESH_Data *msg, | ||
2661 | struct MeshTunnelReliability *rel) | ||
2662 | { | ||
2663 | struct MeshReliableMessage *copy; | ||
2664 | struct MeshReliableMessage *prev; | ||
2665 | uint32_t mid; | ||
2666 | uint16_t size; | ||
2667 | |||
2668 | size = ntohs (msg->header.size); | ||
2669 | mid = ntohl (msg->mid); | ||
2670 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add_buffered_data %u\n", mid); | ||
2671 | |||
2672 | copy = GNUNET_malloc (sizeof (*copy) + size); | ||
2673 | copy->mid = mid; | ||
2674 | copy->rel = rel; | ||
2675 | memcpy (©[1], msg, size); | ||
2676 | |||
2677 | // FIXME do something better than O(n), although n < 64... | ||
2678 | // FIXME start from the end (most messages are the latest ones) | ||
2679 | for (prev = rel->head_recv; NULL != prev; prev = prev->next) | ||
2680 | { | ||
2681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " prev %u\n", prev->mid); | ||
2682 | if (GMC_is_pid_bigger (prev->mid, mid)) | ||
2683 | { | ||
2684 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " bingo!\n"); | ||
2685 | GNUNET_CONTAINER_DLL_insert_before (rel->head_recv, rel->tail_recv, | ||
2686 | prev, copy); | ||
2687 | return; | ||
2688 | } | ||
2689 | } | ||
2690 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " insert at tail!\n"); | ||
2691 | GNUNET_CONTAINER_DLL_insert_tail (rel->head_recv, rel->tail_recv, copy); | ||
2692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add_buffered_data END\n"); | ||
2693 | } | ||
2694 | |||
2695 | |||
2696 | /** | ||
2697 | * Destroy a reliable message after it has been acknowledged, either by | ||
2698 | * direct mid ACK or bitfield. Updates the appropriate data structures and | ||
2699 | * timers and frees all memory. | ||
2700 | * | ||
2701 | * @param copy Message that is no longer needed: remote peer got it. | ||
2702 | */ | ||
2703 | static void | ||
2704 | tunnel_free_reliable_message (struct MeshReliableMessage *copy) | ||
2705 | { | ||
2706 | struct MeshTunnelReliability *rel; | ||
2707 | struct GNUNET_TIME_Relative time; | ||
2708 | |||
2709 | rel = copy->rel; | ||
2710 | time = GNUNET_TIME_absolute_get_duration (copy->timestamp); | ||
2711 | rel->expected_delay.rel_value_us *= 7; | ||
2712 | rel->expected_delay.rel_value_us += time.rel_value_us; | ||
2713 | rel->expected_delay.rel_value_us /= 8; | ||
2714 | rel->n_sent--; | ||
2715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! Freeing %u\n", copy->mid); | ||
2716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " n_sent %u\n", rel->n_sent); | ||
2717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! took %s\n", | ||
2718 | GNUNET_STRINGS_relative_time_to_string (time, GNUNET_NO)); | ||
2719 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! new expected delay %s\n", | ||
2720 | GNUNET_STRINGS_relative_time_to_string (rel->expected_delay, | ||
2721 | GNUNET_NO)); | ||
2722 | rel->retry_timer = rel->expected_delay; | ||
2723 | GNUNET_CONTAINER_DLL_remove (rel->head_sent, rel->tail_sent, copy); | ||
2724 | GNUNET_free (copy); | ||
2725 | } | ||
2726 | |||
2727 | |||
2728 | /** | ||
2729 | * Destroy all reliable messages queued for a tunnel, | ||
2730 | * during a tunnel destruction. | ||
2731 | * Frees the reliability structure itself. | ||
2732 | * | ||
2733 | * @param rel Reliability data for a tunnel. | ||
2734 | */ | ||
2735 | static void | ||
2736 | tunnel_free_reliable_all (struct MeshTunnelReliability *rel) | ||
2737 | { | ||
2738 | struct MeshReliableMessage *copy; | ||
2739 | struct MeshReliableMessage *next; | ||
2740 | |||
2741 | if (NULL == rel) | ||
2742 | return; | ||
2743 | |||
2744 | for (copy = rel->head_recv; NULL != copy; copy = next) | ||
2745 | { | ||
2746 | next = copy->next; | ||
2747 | GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy); | ||
2748 | GNUNET_free (copy); | ||
2749 | } | ||
2750 | for (copy = rel->head_sent; NULL != copy; copy = next) | ||
2751 | { | ||
2752 | next = copy->next; | ||
2753 | GNUNET_CONTAINER_DLL_remove (rel->head_sent, rel->tail_sent, copy); | ||
2754 | GNUNET_free (copy); | ||
2755 | } | ||
2756 | if (GNUNET_SCHEDULER_NO_TASK != rel->retry_task) | ||
2757 | GNUNET_SCHEDULER_cancel (rel->retry_task); | ||
2758 | GNUNET_free (rel); | ||
2759 | } | ||
2760 | |||
2761 | |||
2762 | /** | ||
2763 | * Mark future messages as ACK'd. | ||
2764 | * | ||
2765 | * @param t Tunnel whose sent buffer to clean. | ||
2766 | * @param msg DataACK message with a bitfield of future ACK'd messages. | ||
2767 | * @param rel Reliability data. | ||
2768 | */ | ||
2769 | static void | ||
2770 | tunnel_free_sent_reliable (struct MeshTunnel *t, | ||
2771 | const struct GNUNET_MESH_DataACK *msg, | ||
2772 | struct MeshTunnelReliability *rel) | ||
2773 | { | ||
2774 | struct MeshReliableMessage *copy; | ||
2775 | struct MeshReliableMessage *next; | ||
2776 | uint64_t bitfield; | ||
2777 | uint64_t mask; | ||
2778 | uint32_t mid; | ||
2779 | uint32_t target; | ||
2780 | unsigned int i; | ||
2781 | |||
2782 | bitfield = msg->futures; | ||
2783 | mid = ntohl (msg->mid); | ||
2784 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2785 | "free_sent_reliable %u %llX\n", | ||
2786 | mid, bitfield); | ||
2787 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2788 | " rel %p, head %p\n", | ||
2789 | rel, rel->head_sent); | ||
2790 | for (i = 0, copy = rel->head_sent; | ||
2791 | i < 64 && NULL != copy && 0 != bitfield; | ||
2792 | i++) | ||
2793 | { | ||
2794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2795 | " trying bit %u (mid %u)\n", | ||
2796 | i, mid + i + 1); | ||
2797 | mask = 0x1LL << i; | ||
2798 | if (0 == (bitfield & mask)) | ||
2799 | continue; | ||
2800 | |||
2801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " set!\n"); | ||
2802 | /* Bit was set, clear the bit from the bitfield */ | ||
2803 | bitfield &= ~mask; | ||
2804 | |||
2805 | /* The i-th bit was set. Do we have that copy? */ | ||
2806 | /* Skip copies with mid < target */ | ||
2807 | target = mid + i + 1; | ||
2808 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " target %u\n", target); | ||
2809 | while (NULL != copy && GMC_is_pid_bigger (target, copy->mid)) | ||
2810 | copy = copy->next; | ||
2811 | |||
2812 | /* Did we run out of copies? (previously freed, it's ok) */ | ||
2813 | if (NULL == copy) | ||
2814 | { | ||
2815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "run out of copies...\n"); | ||
2816 | return; | ||
2817 | } | ||
2818 | |||
2819 | /* Did we overshoot the target? (previously freed, it's ok) */ | ||
2820 | if (GMC_is_pid_bigger (copy->mid, target)) | ||
2821 | { | ||
2822 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " next copy %u\n", copy->mid); | ||
2823 | continue; | ||
2824 | } | ||
2825 | |||
2826 | /* Now copy->mid == target, free it */ | ||
2827 | next = copy->next; | ||
2828 | tunnel_free_reliable_message (copy); | ||
2829 | copy = next; | ||
2830 | } | ||
2831 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "free_sent_reliable END\n"); | ||
2832 | } | ||
2833 | |||
2834 | |||
2835 | /** | ||
2836 | * We haven't received an ACK after a certain time: restransmit the message. | ||
2837 | * | ||
2838 | * @param cls Closure (MeshReliableMessage with the message to restransmit) | ||
2839 | * @param tc TaskContext. | ||
2840 | */ | ||
2841 | static void | ||
2842 | tunnel_retransmit_message (void *cls, | ||
2843 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2844 | { | ||
2845 | struct MeshTunnelReliability *rel = cls; | ||
2846 | struct MeshReliableMessage *copy; | ||
2847 | struct MeshFlowControl *fc; | ||
2848 | struct MeshPeerQueue *q; | ||
2849 | struct MeshPeer *pi; | ||
2850 | struct MeshTunnel *t; | ||
2851 | struct GNUNET_MESH_Data *payload; | ||
2852 | GNUNET_PEER_Id hop; | ||
2853 | |||
2854 | rel->retry_task = GNUNET_SCHEDULER_NO_TASK; | ||
2855 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
2856 | return; | ||
2857 | |||
2858 | t = rel->t; | ||
2859 | copy = rel->head_sent; | ||
2860 | if (NULL == copy) | ||
2861 | { | ||
2862 | GNUNET_break (0); | ||
2863 | return; | ||
2864 | } | ||
2865 | |||
2866 | /* Search the message to be retransmitted in the outgoing queue */ | ||
2867 | payload = (struct GNUNET_MESH_Data *) ©[1]; | ||
2868 | hop = rel == t->fwd_rel ? t->next_hop : t->prev_hop; | ||
2869 | fc = rel == t->fwd_rel ? &t->prev_fc : &t->next_fc; | ||
2870 | pi = peer_get_short (hop); | ||
2871 | for (q = pi->queue_head; NULL != q; q = q->next) | ||
2872 | { | ||
2873 | if (ntohs (payload->header.type) == q->type) | ||
2874 | { | ||
2875 | struct GNUNET_MESH_Data *queued_data = q->cls; | ||
2876 | |||
2877 | if (queued_data->mid == payload->mid) | ||
2878 | break; | ||
2879 | } | ||
2880 | } | ||
2881 | |||
2882 | /* Message not found in the queue */ | ||
2883 | if (NULL == q) | ||
2884 | { | ||
2885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! RETRANSMIT %u\n", copy->mid); | ||
2886 | |||
2887 | fc->last_ack_sent++; | ||
2888 | fc->last_pid_recv++; | ||
2889 | payload->pid = htonl (fc->last_pid_recv); | ||
2890 | send_prebuilt_message (&payload->header, hop, t); | ||
2891 | GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO); | ||
2892 | } | ||
2893 | else | ||
2894 | { | ||
2895 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! STILL IN QUEUE %u\n", copy->mid); | ||
2896 | } | ||
2897 | |||
2898 | rel->retry_timer = GNUNET_TIME_STD_BACKOFF (rel->retry_timer); | ||
2899 | rel->retry_task = GNUNET_SCHEDULER_add_delayed (rel->retry_timer, | ||
2900 | &tunnel_retransmit_message, | ||
2901 | cls); | ||
2902 | } | ||
2903 | |||
2904 | |||
2905 | /** | ||
2906 | * Send keepalive packets for a tunnel. | ||
2907 | * | ||
2908 | * @param t Tunnel to keep alive.. | ||
2909 | * @param fwd Is this a FWD keepalive? (owner -> dest). | ||
2910 | */ | ||
2911 | static void | ||
2912 | tunnel_keepalive (struct MeshTunnel *t, int fwd) | ||
2913 | { | ||
2914 | struct GNUNET_MESH_TunnelKeepAlive *msg; | ||
2915 | size_t size = sizeof (struct GNUNET_MESH_TunnelKeepAlive); | ||
2916 | char cbuf[size]; | ||
2917 | GNUNET_PEER_Id hop; | ||
2918 | uint16_t type; | ||
2919 | |||
2920 | type = fwd ? GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE : | ||
2921 | GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE; | ||
2922 | hop = fwd ? t->next_hop : t->prev_hop; | ||
2923 | |||
2924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2925 | "sending %s keepalive for tunnel %d\n", | ||
2926 | fwd ? "FWD" : "BCK", t->id.tid); | ||
2927 | |||
2928 | msg = (struct GNUNET_MESH_TunnelKeepAlive *) cbuf; | ||
2929 | msg->header.size = htons (size); | ||
2930 | msg->header.type = htons (type); | ||
2931 | msg->oid = *(GNUNET_PEER_resolve2 (t->id.oid)); | ||
2932 | msg->tid = htonl (t->id.tid); | ||
2933 | send_prebuilt_message (&msg->header, hop, t); | ||
2934 | } | ||
2935 | |||
2936 | |||
2937 | /** | ||
2938 | * Send create (PATH_CREATE/PATH_ACK) packets for a tunnel. | ||
2939 | * | ||
2940 | * @param t Tunnel for which to send the message. | ||
2941 | * @param fwd If GNUNET_YES, send CREATE, otherwise send ACK. | ||
2942 | */ | ||
2943 | static void | ||
2944 | tunnel_recreate (struct MeshTunnel *t, int fwd) | ||
2945 | { | ||
2946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2947 | "sending path recreate for tunnel %s[%X]\n", | ||
2948 | GNUNET_i2s (GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid); | ||
2949 | if (fwd) | ||
2950 | send_path_create (t); | ||
2951 | else | ||
2952 | send_path_ack (t); | ||
2953 | } | ||
2954 | |||
2955 | |||
2956 | /** | ||
2957 | * Generic tunnel timer management. | ||
2958 | * Depending on the role of the peer in the tunnel will send the | ||
2959 | * appropriate message (build or keepalive) | ||
2960 | * | ||
2961 | * @param t Tunnel to maintain. | ||
2962 | * @param fwd Is FWD? | ||
2963 | */ | ||
2964 | static void | ||
2965 | tunnel_maintain (struct MeshTunnel *t, int fwd) | ||
2966 | { | ||
2967 | switch (t->state) | ||
2968 | { | ||
2969 | case MESH_TUNNEL_NEW: | ||
2970 | GNUNET_break (0); | ||
2971 | case MESH_TUNNEL_SEARCHING: | ||
2972 | /* TODO DHT GET with RO_BART */ | ||
2973 | break; | ||
2974 | case MESH_TUNNEL_WAITING: | ||
2975 | tunnel_recreate (t, fwd); | ||
2976 | break; | ||
2977 | case MESH_TUNNEL_READY: | ||
2978 | tunnel_keepalive (t, fwd); | ||
2979 | break; | ||
2980 | default: | ||
2981 | break; | ||
2982 | } | ||
2983 | } | ||
2984 | |||
2985 | |||
2986 | static void | ||
2987 | tunnel_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2988 | { | ||
2989 | struct MeshTunnel *t = cls; | ||
2990 | |||
2991 | t->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK; | ||
2992 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || | ||
2993 | NULL == t->owner) | ||
2994 | return; | ||
2995 | |||
2996 | tunnel_maintain (t, GNUNET_YES); | ||
2997 | t->fwd_maintenance_task = GNUNET_SCHEDULER_add_delayed (refresh_path_time, | ||
2998 | &tunnel_fwd_keepalive, | ||
2999 | t); | ||
3000 | } | ||
3001 | |||
3002 | |||
3003 | static void | ||
3004 | tunnel_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3005 | { | ||
3006 | struct MeshTunnel *t = cls; | ||
3007 | |||
3008 | t->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK; | ||
3009 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || | ||
3010 | NULL == t->client) | ||
3011 | return; | ||
3012 | |||
3013 | tunnel_keepalive (t, GNUNET_NO); | ||
3014 | t->bck_maintenance_task = GNUNET_SCHEDULER_add_delayed (refresh_path_time, | ||
3015 | &tunnel_bck_keepalive, | ||
3016 | t); | ||
3017 | } | ||
3018 | |||
3019 | |||
3020 | /** | ||
3021 | * Send a message to all peers and clients in this tunnel that the tunnel | ||
3022 | * is no longer valid. If some peer or client should not receive the message, | ||
3023 | * should be zero'ed out before calling this function. | ||
3024 | * | ||
3025 | * @param t The tunnel whose peers and clients to notify. | ||
3026 | */ | ||
3027 | static void | ||
3028 | tunnel_send_destroy (struct MeshTunnel *t) | ||
3029 | { | ||
3030 | struct GNUNET_MESH_TunnelDestroy msg; | ||
3031 | struct GNUNET_PeerIdentity id; | ||
3032 | |||
3033 | msg.header.size = htons (sizeof (msg)); | ||
3034 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY); | ||
3035 | GNUNET_PEER_resolve (t->id.oid, &msg.oid); | ||
3036 | msg.tid = htonl (t->id.tid); | ||
3037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3038 | " sending tunnel destroy for tunnel: %s [%X]\n", | ||
3039 | GNUNET_i2s (&msg.oid), t->id.tid); | ||
3040 | |||
3041 | if (NULL == t->client && 0 != t->next_hop) | ||
3042 | { | ||
3043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " child: %u\n", t->next_hop); | ||
3044 | GNUNET_PEER_resolve (t->next_hop, &id); | ||
3045 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3046 | " sending forward to %s\n", | ||
3047 | GNUNET_i2s (&id)); | ||
3048 | send_prebuilt_message (&msg.header, t->next_hop, t); | ||
3049 | } | ||
3050 | if (NULL == t->owner && 0 != t->prev_hop) | ||
3051 | { | ||
3052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " parent: %u\n", t->prev_hop); | ||
3053 | GNUNET_PEER_resolve (t->prev_hop, &id); | ||
3054 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3055 | " sending back to %s\n", | ||
3056 | GNUNET_i2s (&id)); | ||
3057 | send_prebuilt_message (&msg.header, t->prev_hop, t); | ||
3058 | } | ||
3059 | if (NULL != t->owner) | ||
3060 | { | ||
3061 | send_local_tunnel_destroy (t, GNUNET_NO); | ||
3062 | } | ||
3063 | if (NULL != t->client) | ||
3064 | { | ||
3065 | send_local_tunnel_destroy (t, GNUNET_YES); | ||
3066 | } | ||
3067 | } | ||
3068 | |||
3069 | static int | ||
3070 | tunnel_destroy (struct MeshTunnel *t) | ||
3071 | { | ||
3072 | struct MeshClient *c; | ||
3073 | struct GNUNET_HashCode hash; | ||
3074 | int r; | ||
3075 | |||
3076 | if (NULL == t) | ||
3077 | return GNUNET_OK; | ||
3078 | |||
3079 | r = GNUNET_OK; | ||
3080 | c = t->owner; | ||
3081 | |||
3082 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s [%x]\n", | ||
3083 | GNUNET_i2s (GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid); | ||
3084 | if (NULL != c) | ||
3085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); | ||
3086 | |||
3087 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); | ||
3088 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t)) | ||
3089 | { | ||
3090 | GNUNET_break (0); | ||
3091 | r = GNUNET_SYSERR; | ||
3092 | } | ||
3093 | |||
3094 | if (NULL != c) | ||
3095 | { | ||
3096 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap32_remove (c->own_tunnels, | ||
3097 | t->local_tid, t)) | ||
3098 | { | ||
3099 | GNUNET_break (0); | ||
3100 | r = GNUNET_SYSERR; | ||
3101 | } | ||
3102 | } | ||
3103 | |||
3104 | c = t->client; | ||
3105 | if (NULL != c) | ||
3106 | { | ||
3107 | if (GNUNET_YES != | ||
3108 | GNUNET_CONTAINER_multihashmap32_remove (c->incoming_tunnels, | ||
3109 | t->local_tid_dest, t)) | ||
3110 | { | ||
3111 | GNUNET_break (0); | ||
3112 | r = GNUNET_SYSERR; | ||
3113 | } | ||
3114 | if (GNUNET_YES != | ||
3115 | GNUNET_CONTAINER_multihashmap32_remove (incoming_tunnels, | ||
3116 | t->local_tid_dest, t)) | ||
3117 | { | ||
3118 | GNUNET_break (0); | ||
3119 | r = GNUNET_SYSERR; | ||
3120 | } | ||
3121 | } | ||
3122 | |||
3123 | if(GNUNET_YES == t->reliable) | ||
3124 | { | ||
3125 | tunnel_free_reliable_all (t->fwd_rel); | ||
3126 | tunnel_free_reliable_all (t->bck_rel); | ||
3127 | } | ||
3128 | if (0 != t->prev_hop) | ||
3129 | { | ||
3130 | peer_cancel_queues (t->prev_hop, t); | ||
3131 | GNUNET_PEER_change_rc (t->prev_hop, -1); | ||
3132 | } | ||
3133 | if (0 != t->next_hop) | ||
3134 | { | ||
3135 | peer_cancel_queues (t->next_hop, t); | ||
3136 | GNUNET_PEER_change_rc (t->next_hop, -1); | ||
3137 | } | ||
3138 | if (GNUNET_SCHEDULER_NO_TASK != t->next_fc.poll_task) | ||
3139 | { | ||
3140 | GNUNET_SCHEDULER_cancel (t->next_fc.poll_task); | ||
3141 | t->next_fc.poll_task = GNUNET_SCHEDULER_NO_TASK; | ||
3142 | } | ||
3143 | if (GNUNET_SCHEDULER_NO_TASK != t->prev_fc.poll_task) | ||
3144 | { | ||
3145 | GNUNET_SCHEDULER_cancel (t->prev_fc.poll_task); | ||
3146 | t->prev_fc.poll_task = GNUNET_SCHEDULER_NO_TASK; | ||
3147 | } | ||
3148 | if (0 != t->dest) { | ||
3149 | peer_remove_tunnel (peer_get_short (t->dest), t); | ||
3150 | } | ||
3151 | |||
3152 | if (GNUNET_SCHEDULER_NO_TASK != t->fwd_maintenance_task) | ||
3153 | GNUNET_SCHEDULER_cancel (t->fwd_maintenance_task); | ||
3154 | if (GNUNET_SCHEDULER_NO_TASK != t->bck_maintenance_task) | ||
3155 | GNUNET_SCHEDULER_cancel (t->bck_maintenance_task); | ||
3156 | |||
3157 | n_tunnels--; | ||
3158 | GNUNET_STATISTICS_update (stats, "# tunnels", -1, GNUNET_NO); | ||
3159 | path_destroy (t->path); | ||
3160 | GNUNET_free (t); | ||
3161 | return r; | ||
3162 | } | ||
3163 | |||
3164 | /** | ||
3165 | * Tunnel is empty: destroy it. | ||
3166 | * | ||
3167 | * Notifies all participants (peers, cleints) about the destruction. | ||
3168 | * | ||
3169 | * @param t Tunnel to destroy. | ||
3170 | */ | ||
3171 | static void | ||
3172 | tunnel_destroy_empty (struct MeshTunnel *t) | ||
3173 | { | ||
3174 | #if MESH_DEBUG | ||
3175 | { | ||
3176 | struct GNUNET_PeerIdentity id; | ||
3177 | |||
3178 | GNUNET_PEER_resolve (t->id.oid, &id); | ||
3179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3180 | "executing destruction of empty tunnel %s [%X]\n", | ||
3181 | GNUNET_i2s (&id), t->id.tid); | ||
3182 | } | ||
3183 | #endif | ||
3184 | |||
3185 | if (GNUNET_NO == t->destroy) | ||
3186 | tunnel_send_destroy (t); | ||
3187 | if (0 == t->pending_messages) | ||
3188 | tunnel_destroy (t); | ||
3189 | else | ||
3190 | t->destroy = GNUNET_YES; | ||
3191 | } | ||
3192 | |||
3193 | /** | ||
3194 | * Initialize a Flow Control structure to the initial state. | ||
3195 | * | ||
3196 | * @param fc Flow Control structure to initialize. | ||
3197 | */ | ||
3198 | static void | ||
3199 | fc_init (struct MeshFlowControl *fc) | ||
3200 | { | ||
3201 | fc->last_pid_sent = (uint32_t) -1; /* Next (expected) = 0 */ | ||
3202 | fc->last_pid_recv = (uint32_t) -1; | ||
3203 | fc->last_ack_sent = (uint32_t) -1; /* No traffic allowed yet */ | ||
3204 | fc->last_ack_recv = (uint32_t) -1; | ||
3205 | fc->poll_task = GNUNET_SCHEDULER_NO_TASK; | ||
3206 | fc->poll_time = GNUNET_TIME_UNIT_SECONDS; | ||
3207 | fc->queue_n = 0; | ||
3208 | } | ||
3209 | |||
3210 | /** | ||
3211 | * Create a new tunnel | ||
3212 | * | ||
3213 | * @param owner Who is the owner of the tunnel (short ID). | ||
3214 | * @param tid Tunnel Number of the tunnel. | ||
3215 | * @param client Clients that owns the tunnel, NULL for foreign tunnels. | ||
3216 | * @param local Tunnel Number for the tunnel, for the client point of view. | ||
3217 | * | ||
3218 | * @return A new initialized tunnel. NULL on error. | ||
3219 | */ | ||
3220 | static struct MeshTunnel * | ||
3221 | tunnel_new (GNUNET_PEER_Id owner, | ||
3222 | MESH_TunnelNumber tid, | ||
3223 | struct MeshClient *client, | ||
3224 | MESH_TunnelNumber local) | ||
3225 | { | ||
3226 | struct MeshTunnel *t; | ||
3227 | struct GNUNET_HashCode hash; | ||
3228 | |||
3229 | if (n_tunnels >= max_tunnels && NULL == client) | ||
3230 | return NULL; | ||
3231 | |||
3232 | t = GNUNET_malloc (sizeof (struct MeshTunnel)); | ||
3233 | t->id.oid = owner; | ||
3234 | t->id.tid = tid; | ||
3235 | t->queue_max = (max_msgs_queue / max_tunnels) + 1; | ||
3236 | t->owner = client; | ||
3237 | fc_init (&t->next_fc); | ||
3238 | fc_init (&t->prev_fc); | ||
3239 | t->next_fc.t = t; | ||
3240 | t->prev_fc.t = t; | ||
3241 | t->local_tid = local; | ||
3242 | n_tunnels++; | ||
3243 | GNUNET_STATISTICS_update (stats, "# tunnels", 1, GNUNET_NO); | ||
3244 | |||
3245 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); | ||
3246 | if (GNUNET_OK != | ||
3247 | GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t, | ||
3248 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
3249 | { | ||
3250 | GNUNET_break (0); | ||
3251 | tunnel_destroy (t); | ||
3252 | if (NULL != client) | ||
3253 | { | ||
3254 | GNUNET_break (0); | ||
3255 | GNUNET_SERVER_receive_done (client->handle, GNUNET_SYSERR); | ||
3256 | } | ||
3257 | return NULL; | ||
3258 | } | ||
3259 | |||
3260 | if (NULL != client) | ||
3261 | { | ||
3262 | if (GNUNET_OK != | ||
3263 | GNUNET_CONTAINER_multihashmap32_put (client->own_tunnels, | ||
3264 | t->local_tid, t, | ||
3265 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
3266 | { | ||
3267 | tunnel_destroy (t); | ||
3268 | GNUNET_break (0); | ||
3269 | GNUNET_SERVER_receive_done (client->handle, GNUNET_SYSERR); | ||
3270 | return NULL; | ||
3271 | } | ||
3272 | } | ||
3273 | |||
3274 | return t; | ||
3275 | } | ||
3276 | |||
3277 | |||
3278 | /** | ||
3279 | * Set options in a tunnel, extracted from a bit flag field | ||
3280 | * | ||
3281 | * @param t Tunnel to set options to. | ||
3282 | * @param options Bit array in host byte order. | ||
3283 | */ | ||
3284 | static void | ||
3285 | tunnel_set_options (struct MeshTunnel *t, uint32_t options) | ||
3286 | { | ||
3287 | t->nobuffer = (options & GNUNET_MESH_OPTION_NOBUFFER) != 0 ? | ||
3288 | GNUNET_YES : GNUNET_NO; | ||
3289 | t->reliable = (options & GNUNET_MESH_OPTION_RELIABLE) != 0 ? | ||
3290 | GNUNET_YES : GNUNET_NO; | ||
3291 | } | ||
3292 | |||
3293 | |||
3294 | /** | ||
3295 | * Iterator for deleting each tunnel whose client endpoint disconnected. | ||
3296 | * | ||
3297 | * @param cls Closure (client that has disconnected). | ||
3298 | * @param key The local tunnel id (used to access the hashmap). | ||
3299 | * @param value The value stored at the key (tunnel to destroy). | ||
3300 | * | ||
3301 | * @return GNUNET_OK, keep iterating. | ||
3302 | */ | ||
3303 | static int | ||
3304 | tunnel_destroy_iterator (void *cls, | ||
3305 | uint32_t key, | ||
3306 | void *value) | ||
3307 | { | ||
3308 | struct MeshTunnel *t = value; | ||
3309 | struct MeshClient *c = cls; | ||
3310 | |||
3311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3312 | " Tunnel %X / %X destroy, due to client %u shutdown.\n", | ||
3313 | t->local_tid, t->local_tid_dest, c->id); | ||
3314 | client_delete_tunnel (c, t); | ||
3315 | if (c == t->client) | ||
3316 | { | ||
3317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Client %u is destination.\n", c->id); | ||
3318 | t->client = NULL; | ||
3319 | if (0 != t->next_hop) { /* destroy could come before a path is used */ | ||
3320 | GNUNET_PEER_change_rc (t->next_hop, -1); | ||
3321 | t->next_hop = 0; | ||
3322 | } | ||
3323 | } | ||
3324 | if (c == t->owner) | ||
3325 | { | ||
3326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Client %u is owner.\n", c->id); | ||
3327 | t->owner = NULL; | ||
3328 | if (0 != t->prev_hop) { /* destroy could come before a path is used */ | ||
3329 | GNUNET_PEER_change_rc (t->prev_hop, -1); | ||
3330 | t->prev_hop = 0; | ||
3331 | } | ||
3332 | } | ||
3333 | |||
3334 | tunnel_destroy_empty (t); | ||
3335 | |||
3336 | return GNUNET_OK; | ||
3337 | } | ||
3338 | |||
3339 | |||
3340 | /** | ||
3341 | * remove client's ports from the global hashmap on diconnect. | ||
3342 | * | ||
3343 | * @param cls Closure (unused). | ||
3344 | * @param key Port. | ||
3345 | * @param value ThClient structure. | ||
3346 | * | ||
3347 | * @return GNUNET_OK, keep iterating. | ||
3348 | */ | ||
3349 | static int | ||
3350 | client_release_ports (void *cls, | ||
3351 | uint32_t key, | ||
3352 | void *value) | ||
3353 | { | ||
3354 | int res; | ||
3355 | |||
3356 | res = GNUNET_CONTAINER_multihashmap32_remove (ports, key, value); | ||
3357 | if (GNUNET_YES != res) | ||
3358 | { | ||
3359 | GNUNET_break (0); | ||
3360 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3361 | "Port %u by client %p was not registered.\n", | ||
3362 | key, value); | ||
3363 | } | ||
3364 | return GNUNET_OK; | ||
3365 | } | ||
3366 | |||
3367 | /** | ||
3368 | * Timeout function due to lack of keepalive/traffic from the owner. | ||
3369 | * Destroys tunnel if called. | ||
3370 | * | ||
3371 | * @param cls Closure (tunnel to destroy). | ||
3372 | * @param tc TaskContext | ||
3373 | */ | ||
3374 | static void | ||
3375 | tunnel_fwd_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3376 | { | ||
3377 | struct MeshTunnel *t = cls; | ||
3378 | |||
3379 | t->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK; | ||
3380 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
3381 | return; | ||
3382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3383 | "Tunnel %s [%X] FWD timed out. Destroying.\n", | ||
3384 | GNUNET_i2s(GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid); | ||
3385 | if (NULL != t->client) | ||
3386 | send_local_tunnel_destroy (t, GNUNET_YES); | ||
3387 | tunnel_destroy (t); /* Do not notify other */ | ||
3388 | } | ||
3389 | |||
3390 | |||
3391 | /** | ||
3392 | * Timeout function due to lack of keepalive/traffic from the destination. | ||
3393 | * Destroys tunnel if called. | ||
3394 | * | ||
3395 | * @param cls Closure (tunnel to destroy). | ||
3396 | * @param tc TaskContext | ||
3397 | */ | ||
3398 | static void | ||
3399 | tunnel_bck_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3400 | { | ||
3401 | struct MeshTunnel *t = cls; | ||
3402 | |||
3403 | t->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK; | ||
3404 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
3405 | return; | ||
3406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3407 | "Tunnel %s [%X] BCK timed out. Destroying.\n", | ||
3408 | GNUNET_i2s(GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid); | ||
3409 | if (NULL != t->owner) | ||
3410 | send_local_tunnel_destroy (t, GNUNET_NO); | ||
3411 | tunnel_destroy (t); /* Do not notify other */ | ||
3412 | } | ||
3413 | |||
3414 | |||
3415 | /** | ||
3416 | * Resets the tunnel timeout task, some other message has done the task's job. | ||
3417 | * - For the first peer on the direction this means to send | ||
3418 | * a keepalive or a path confirmation message (either create or ACK). | ||
3419 | * - For all other peers, this means to destroy the tunnel, | ||
3420 | * due to lack of activity. | ||
3421 | * Starts the tiemout if no timeout was running (tunnel just created). | ||
3422 | * | ||
3423 | * @param t Tunnel whose timeout to reset. | ||
3424 | * @param fwd Is this forward? | ||
3425 | * | ||
3426 | * TODO use heap to improve efficiency of scheduler. | ||
3427 | */ | ||
3428 | static void | ||
3429 | tunnel_reset_timeout (struct MeshTunnel *t, int fwd) | ||
3430 | { | ||
3431 | GNUNET_SCHEDULER_TaskIdentifier *ti; | ||
3432 | GNUNET_SCHEDULER_Task f; | ||
3433 | struct MeshClient *c; | ||
3434 | |||
3435 | ti = fwd ? &t->fwd_maintenance_task : &t->bck_maintenance_task; | ||
3436 | c = fwd ? t->owner : t->client; | ||
3437 | |||
3438 | if (GNUNET_SCHEDULER_NO_TASK != *ti) | ||
3439 | GNUNET_SCHEDULER_cancel (*ti); | ||
3440 | |||
3441 | if (NULL != c) | ||
3442 | { | ||
3443 | f = fwd ? &tunnel_fwd_keepalive : &tunnel_bck_keepalive; | ||
3444 | *ti = GNUNET_SCHEDULER_add_delayed (refresh_path_time, f, t); | ||
3445 | } | ||
3446 | else | ||
3447 | { | ||
3448 | f = fwd ? &tunnel_fwd_timeout : &tunnel_bck_timeout; | ||
3449 | *ti = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
3450 | (refresh_path_time, 4), | ||
3451 | f, t); | ||
3452 | } | ||
3453 | } | ||
3454 | |||
3455 | |||
3456 | /******************************************************************************/ | ||
3457 | /**************** MESH NETWORK HANDLER HELPERS ***********************/ | ||
3458 | /******************************************************************************/ | ||
3459 | |||
3460 | /** | ||
3461 | * Free a transmission that was already queued with all resources | ||
3462 | * associated to the request. | ||
3463 | * | ||
3464 | * @param queue Queue handler to cancel. | ||
3465 | * @param clear_cls Is it necessary to free associated cls? | ||
3466 | */ | ||
3467 | static void | ||
3468 | queue_destroy (struct MeshPeerQueue *queue, int clear_cls) | ||
3469 | { | ||
3470 | struct MeshFlowControl *fc; | ||
3471 | |||
3472 | if (GNUNET_YES == clear_cls) | ||
3473 | { | ||
3474 | switch (queue->type) | ||
3475 | { | ||
3476 | case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY: | ||
3477 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " cancelling TUNNEL_DESTROY\n"); | ||
3478 | GNUNET_break (GNUNET_YES == queue->tunnel->destroy); | ||
3479 | /* fall through */ | ||
3480 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
3481 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
3482 | case GNUNET_MESSAGE_TYPE_MESH_ACK: | ||
3483 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK: | ||
3484 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK: | ||
3485 | case GNUNET_MESSAGE_TYPE_MESH_POLL: | ||
3486 | case GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE: | ||
3487 | case GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE: | ||
3488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3489 | " prebuilt message\n"); | ||
3490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3491 | " type %s\n", | ||
3492 | GNUNET_MESH_DEBUG_M2S (queue->type)); | ||
3493 | break; | ||
3494 | case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: | ||
3495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type create path\n"); | ||
3496 | break; | ||
3497 | default: | ||
3498 | GNUNET_break (0); | ||
3499 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3500 | " type %s unknown!\n", | ||
3501 | GNUNET_MESH_DEBUG_M2S (queue->type)); | ||
3502 | } | ||
3503 | GNUNET_free_non_null (queue->cls); | ||
3504 | } | ||
3505 | GNUNET_CONTAINER_DLL_remove (queue->peer->queue_head, | ||
3506 | queue->peer->queue_tail, | ||
3507 | queue); | ||
3508 | |||
3509 | /* Delete from appropriate fc in the tunnel */ | ||
3510 | if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == queue->type || | ||
3511 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN == queue->type ) | ||
3512 | { | ||
3513 | if (queue->peer->id == queue->tunnel->prev_hop) | ||
3514 | fc = &queue->tunnel->prev_fc; | ||
3515 | else if (queue->peer->id == queue->tunnel->next_hop) | ||
3516 | fc = &queue->tunnel->next_fc; | ||
3517 | else | ||
3518 | { | ||
3519 | GNUNET_break (0); | ||
3520 | GNUNET_free (queue); | ||
3521 | return; | ||
3522 | } | ||
3523 | fc->queue_n--; | ||
3524 | } | ||
3525 | GNUNET_free (queue); | ||
3526 | } | ||
3527 | |||
3528 | |||
3529 | /** | ||
3530 | * @brief Get the next transmittable message from the queue. | ||
3531 | * | ||
3532 | * This will be the head, except in the case of being a data packet | ||
3533 | * not allowed by the destination peer. | ||
3534 | * | ||
3535 | * @param peer Destination peer. | ||
3536 | * | ||
3537 | * @return The next viable MeshPeerQueue element to send to that peer. | ||
3538 | * NULL when there are no transmittable messages. | ||
3539 | */ | ||
3540 | struct MeshPeerQueue * | ||
3541 | queue_get_next (const struct MeshPeer *peer) | ||
3542 | { | ||
3543 | struct MeshPeerQueue *q; | ||
3544 | |||
3545 | struct GNUNET_MESH_Data *dmsg; | ||
3546 | struct MeshTunnel* t; | ||
3547 | uint32_t pid; | ||
3548 | uint32_t ack; | ||
3549 | |||
3550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* selecting message\n"); | ||
3551 | for (q = peer->queue_head; NULL != q; q = q->next) | ||
3552 | { | ||
3553 | t = q->tunnel; | ||
3554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3555 | "* %s\n", | ||
3556 | GNUNET_MESH_DEBUG_M2S (q->type)); | ||
3557 | dmsg = (struct GNUNET_MESH_Data *) q->cls; | ||
3558 | pid = ntohl (dmsg->pid); | ||
3559 | switch (q->type) | ||
3560 | { | ||
3561 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
3562 | ack = t->next_fc.last_ack_recv; | ||
3563 | break; | ||
3564 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
3565 | ack = t->prev_fc.last_ack_recv; | ||
3566 | break; | ||
3567 | default: | ||
3568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3569 | "* OK!\n"); | ||
3570 | return q; | ||
3571 | } | ||
3572 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3573 | "* ACK: %u, PID: %u, MID: %u\n", | ||
3574 | ack, pid, ntohl (dmsg->mid)); | ||
3575 | if (GNUNET_NO == GMC_is_pid_bigger (pid, ack)) | ||
3576 | { | ||
3577 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3578 | "* OK!\n"); | ||
3579 | return q; | ||
3580 | } | ||
3581 | else | ||
3582 | { | ||
3583 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3584 | "* NEXT!\n"); | ||
3585 | } | ||
3586 | } | ||
3587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3588 | "* nothing found\n"); | ||
3589 | return NULL; | ||
3590 | } | ||
3591 | |||
3592 | |||
3593 | static size_t | ||
3594 | queue_send (void *cls, size_t size, void *buf) | ||
3595 | { | ||
3596 | struct MeshPeer *peer = cls; | ||
3597 | struct GNUNET_MessageHeader *msg; | ||
3598 | struct MeshPeerQueue *queue; | ||
3599 | struct MeshTunnel *t; | ||
3600 | struct GNUNET_PeerIdentity dst_id; | ||
3601 | struct MeshFlowControl *fc; | ||
3602 | size_t data_size; | ||
3603 | uint32_t pid; | ||
3604 | uint16_t type; | ||
3605 | |||
3606 | peer->core_transmit = NULL; | ||
3607 | |||
3608 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Queue send\n"); | ||
3609 | |||
3610 | if (NULL == buf || 0 == size) | ||
3611 | { | ||
3612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Buffer size 0.\n"); | ||
3613 | return 0; | ||
3614 | } | ||
3615 | queue = queue_get_next (peer); | ||
3616 | |||
3617 | /* Queue has no internal mesh traffic nor sendable payload */ | ||
3618 | if (NULL == queue) | ||
3619 | { | ||
3620 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* not ready, return\n"); | ||
3621 | if (NULL == peer->queue_head) | ||
3622 | GNUNET_break (0); /* Core tmt_rdy should've been canceled */ | ||
3623 | return 0; | ||
3624 | } | ||
3625 | |||
3626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* not empty\n"); | ||
3627 | |||
3628 | GNUNET_PEER_resolve (peer->id, &dst_id); | ||
3629 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3630 | "* towards %s\n", | ||
3631 | GNUNET_i2s (&dst_id)); | ||
3632 | /* Check if buffer size is enough for the message */ | ||
3633 | if (queue->size > size) | ||
3634 | { | ||
3635 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3636 | "* not enough room, reissue\n"); | ||
3637 | peer->core_transmit = | ||
3638 | GNUNET_CORE_notify_transmit_ready (core_handle, | ||
3639 | GNUNET_NO, | ||
3640 | 0, | ||
3641 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
3642 | &dst_id, | ||
3643 | queue->size, | ||
3644 | &queue_send, | ||
3645 | peer); | ||
3646 | return 0; | ||
3647 | } | ||
3648 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* size ok\n"); | ||
3649 | |||
3650 | t = queue->tunnel; | ||
3651 | GNUNET_assert (0 < t->pending_messages); | ||
3652 | t->pending_messages--; | ||
3653 | type = 0; | ||
3654 | |||
3655 | /* Fill buf */ | ||
3656 | switch (queue->type) | ||
3657 | { | ||
3658 | case 0: | ||
3659 | case GNUNET_MESSAGE_TYPE_MESH_ACK: | ||
3660 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK: | ||
3661 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK: | ||
3662 | case GNUNET_MESSAGE_TYPE_MESH_POLL: | ||
3663 | case GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN: | ||
3664 | case GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY: | ||
3665 | case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY: | ||
3666 | case GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE: | ||
3667 | case GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE: | ||
3668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3669 | "* raw: %s\n", | ||
3670 | GNUNET_MESH_DEBUG_M2S (queue->type)); | ||
3671 | /* Fall through */ | ||
3672 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
3673 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
3674 | data_size = send_core_data_raw (queue->cls, size, buf); | ||
3675 | msg = (struct GNUNET_MessageHeader *) buf; | ||
3676 | type = ntohs (msg->type); | ||
3677 | break; | ||
3678 | case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: | ||
3679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* path create\n"); | ||
3680 | data_size = send_core_path_create (queue->cls, size, buf); | ||
3681 | break; | ||
3682 | case GNUNET_MESSAGE_TYPE_MESH_PATH_ACK: | ||
3683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* path ack\n"); | ||
3684 | data_size = send_core_path_ack (queue->cls, size, buf); | ||
3685 | break; | ||
3686 | default: | ||
3687 | GNUNET_break (0); | ||
3688 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3689 | "* type unknown: %u\n", | ||
3690 | queue->type); | ||
3691 | data_size = 0; | ||
3692 | } | ||
3693 | |||
3694 | if (0 < drop_percent && | ||
3695 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 101) < drop_percent) | ||
3696 | { | ||
3697 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3698 | "Dropping message of type %s\n", | ||
3699 | GNUNET_MESH_DEBUG_M2S(queue->type)); | ||
3700 | data_size = 0; | ||
3701 | } | ||
3702 | /* Free queue, but cls was freed by send_core_* */ | ||
3703 | queue_destroy (queue, GNUNET_NO); | ||
3704 | |||
3705 | /* Send ACK if needed, after accounting for sent ID in fc->queue_n */ | ||
3706 | pid = ((struct GNUNET_MESH_Data *) buf)->pid; | ||
3707 | pid = ntohl (pid); | ||
3708 | switch (type) | ||
3709 | { | ||
3710 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
3711 | t->next_fc.last_pid_sent = pid; | ||
3712 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_UNICAST, GNUNET_YES); | ||
3713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3714 | "!!! FWD %u\n", | ||
3715 | ntohl ( ((struct GNUNET_MESH_Data *) buf)->mid ) ); | ||
3716 | break; | ||
3717 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
3718 | t->prev_fc.last_pid_sent = pid; | ||
3719 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3720 | "!!! BCK %u\n", | ||
3721 | ntohl ( ((struct GNUNET_MESH_Data *) buf)->mid ) ); | ||
3722 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, GNUNET_NO); | ||
3723 | break; | ||
3724 | default: | ||
3725 | break; | ||
3726 | } | ||
3727 | |||
3728 | /* If more data in queue, send next */ | ||
3729 | queue = queue_get_next (peer); | ||
3730 | if (NULL != queue) | ||
3731 | { | ||
3732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* more data!\n"); | ||
3733 | if (NULL == peer->core_transmit) { | ||
3734 | peer->core_transmit = | ||
3735 | GNUNET_CORE_notify_transmit_ready(core_handle, | ||
3736 | 0, | ||
3737 | 0, | ||
3738 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
3739 | &dst_id, | ||
3740 | queue->size, | ||
3741 | &queue_send, | ||
3742 | peer); | ||
3743 | } | ||
3744 | else | ||
3745 | { | ||
3746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3747 | "* tmt rdy called somewhere else\n"); | ||
3748 | } | ||
3749 | } | ||
3750 | if (peer->id == t->next_hop) | ||
3751 | fc = &t->next_fc; | ||
3752 | else if (peer->id == t->prev_hop) | ||
3753 | fc = &t->prev_fc; | ||
3754 | else | ||
3755 | { | ||
3756 | GNUNET_break (0); | ||
3757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "id: %u, next: %u, prev: %u\n", | ||
3758 | peer->id, t->next_hop, t->prev_hop); | ||
3759 | return data_size; | ||
3760 | } | ||
3761 | if (NULL != peer->queue_head) | ||
3762 | { | ||
3763 | if (GNUNET_SCHEDULER_NO_TASK == fc->poll_task && fc->queue_n > 0) | ||
3764 | { | ||
3765 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
3766 | "* %s starting poll timeout\n", | ||
3767 | GNUNET_i2s (&my_full_id)); | ||
3768 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, | ||
3769 | &tunnel_poll, fc); | ||
3770 | } | ||
3771 | } | ||
3772 | else | ||
3773 | { | ||
3774 | if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task) | ||
3775 | { | ||
3776 | GNUNET_SCHEDULER_cancel (fc->poll_task); | ||
3777 | fc->poll_task = GNUNET_SCHEDULER_NO_TASK; | ||
3778 | } | ||
3779 | } | ||
3780 | if (GNUNET_YES == t->destroy && 0 == t->pending_messages) | ||
3781 | { | ||
3782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* destroying tunnel!\n"); | ||
3783 | tunnel_destroy (t); | ||
3784 | } | ||
3785 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Return %d\n", data_size); | ||
3786 | return data_size; | ||
3787 | } | ||
3788 | |||
3789 | |||
3790 | /** | ||
3791 | * @brief Queue and pass message to core when possible. | ||
3792 | * | ||
3793 | * If type is payload (UNICAST, TO_ORIGIN) checks for queue status and | ||
3794 | * accounts for it. In case the queue is full, the message is dropped and | ||
3795 | * a break issued. | ||
3796 | * | ||
3797 | * Otherwise, message is treated as internal and allowed to go regardless of | ||
3798 | * queue status. | ||
3799 | * | ||
3800 | * @param cls Closure (@c type dependant). It will be used by queue_send to | ||
3801 | * build the message to be sent if not already prebuilt. | ||
3802 | * @param type Type of the message, 0 for a raw message. | ||
3803 | * @param size Size of the message. | ||
3804 | * @param dst Neighbor to send message to. | ||
3805 | * @param t Tunnel this message belongs to. | ||
3806 | */ | ||
3807 | static void | ||
3808 | queue_add (void *cls, uint16_t type, size_t size, | ||
3809 | struct MeshPeer *dst, struct MeshTunnel *t) | ||
3810 | { | ||
3811 | struct MeshPeerQueue *queue; | ||
3812 | struct MeshFlowControl *fc; | ||
3813 | int priority; | ||
3814 | |||
3815 | fc = NULL; | ||
3816 | priority = GNUNET_NO; | ||
3817 | if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == type) | ||
3818 | { | ||
3819 | fc = &t->next_fc; | ||
3820 | } | ||
3821 | else if (GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN == type) | ||
3822 | { | ||
3823 | fc = &t->prev_fc; | ||
3824 | } | ||
3825 | if (NULL != fc) | ||
3826 | { | ||
3827 | if (fc->queue_n >= t->queue_max) | ||
3828 | { | ||
3829 | /* If this isn't a retransmission, drop the message */ | ||
3830 | if (GNUNET_NO == t->reliable || | ||
3831 | (NULL == t->owner && GNUNET_MESSAGE_TYPE_MESH_UNICAST == type) || | ||
3832 | (NULL == t->client && GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN == type)) | ||
3833 | { | ||
3834 | GNUNET_STATISTICS_update (stats, "# messages dropped (buffer full)", | ||
3835 | 1, GNUNET_NO); | ||
3836 | GNUNET_break (0); | ||
3837 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3838 | "queue full: %u/%u\n", | ||
3839 | fc->queue_n, t->queue_max); | ||
3840 | return; /* Drop this message */ | ||
3841 | } | ||
3842 | priority = GNUNET_YES; | ||
3843 | } | ||
3844 | fc->queue_n++; | ||
3845 | if (GMC_is_pid_bigger(fc->last_pid_sent + 1, fc->last_ack_recv) && | ||
3846 | GNUNET_SCHEDULER_NO_TASK == fc->poll_task) | ||
3847 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, | ||
3848 | &tunnel_poll, | ||
3849 | fc); | ||
3850 | } | ||
3851 | queue = GNUNET_malloc (sizeof (struct MeshPeerQueue)); | ||
3852 | queue->cls = cls; | ||
3853 | queue->type = type; | ||
3854 | queue->size = size; | ||
3855 | queue->peer = dst; | ||
3856 | queue->tunnel = t; | ||
3857 | if (GNUNET_YES == priority) | ||
3858 | { | ||
3859 | struct GNUNET_MESH_Data *d; | ||
3860 | uint32_t prev; | ||
3861 | uint32_t next; | ||
3862 | |||
3863 | GNUNET_CONTAINER_DLL_insert (dst->queue_head, dst->queue_tail, queue); | ||
3864 | d = (struct GNUNET_MESH_Data *) queue->cls; | ||
3865 | prev = d->pid; | ||
3866 | for (queue = dst->queue_tail; NULL != queue; queue = queue->prev) | ||
3867 | { | ||
3868 | if (queue->type != type) | ||
3869 | continue; | ||
3870 | d = (struct GNUNET_MESH_Data *) queue->cls; | ||
3871 | next = d->pid; | ||
3872 | d->pid = prev; | ||
3873 | prev = next; | ||
3874 | } | ||
3875 | } | ||
3876 | else | ||
3877 | GNUNET_CONTAINER_DLL_insert_tail (dst->queue_head, dst->queue_tail, queue); | ||
3878 | |||
3879 | if (NULL == dst->core_transmit) | ||
3880 | { | ||
3881 | dst->core_transmit = | ||
3882 | GNUNET_CORE_notify_transmit_ready (core_handle, | ||
3883 | 0, | ||
3884 | 0, | ||
3885 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
3886 | GNUNET_PEER_resolve2 (dst->id), | ||
3887 | size, | ||
3888 | &queue_send, | ||
3889 | dst); | ||
3890 | } | ||
3891 | t->pending_messages++; | ||
3892 | } | ||
3893 | |||
3894 | |||
3895 | /******************************************************************************/ | ||
3896 | /******************** MESH NETWORK HANDLERS **************************/ | ||
3897 | /******************************************************************************/ | ||
3898 | |||
3899 | |||
3900 | /** | ||
3901 | * Core handler for path creation | ||
3902 | * | ||
3903 | * @param cls closure | ||
3904 | * @param message message | ||
3905 | * @param peer peer identity this notification is about | ||
3906 | * | ||
3907 | * @return GNUNET_OK to keep the connection open, | ||
3908 | * GNUNET_SYSERR to close it (signal serious error) | ||
3909 | */ | ||
3910 | static int | ||
3911 | handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
3912 | const struct GNUNET_MessageHeader *message) | ||
3913 | { | ||
3914 | unsigned int own_pos; | ||
3915 | uint16_t size; | ||
3916 | uint16_t i; | ||
3917 | MESH_TunnelNumber tid; | ||
3918 | struct GNUNET_MESH_CreateTunnel *msg; | ||
3919 | struct GNUNET_PeerIdentity *pi; | ||
3920 | struct MeshPeerPath *path; | ||
3921 | struct MeshPeer *dest_peer_info; | ||
3922 | struct MeshPeer *orig_peer_info; | ||
3923 | struct MeshTunnel *t; | ||
3924 | |||
3925 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3926 | "Received a path create msg [%s]\n", | ||
3927 | GNUNET_i2s (&my_full_id)); | ||
3928 | size = ntohs (message->size); | ||
3929 | if (size < sizeof (struct GNUNET_MESH_CreateTunnel)) | ||
3930 | { | ||
3931 | GNUNET_break_op (0); | ||
3932 | return GNUNET_OK; | ||
3933 | } | ||
3934 | |||
3935 | size -= sizeof (struct GNUNET_MESH_CreateTunnel); | ||
3936 | if (size % sizeof (struct GNUNET_PeerIdentity)) | ||
3937 | { | ||
3938 | GNUNET_break_op (0); | ||
3939 | return GNUNET_OK; | ||
3940 | } | ||
3941 | size /= sizeof (struct GNUNET_PeerIdentity); | ||
3942 | if (size < 1) | ||
3943 | { | ||
3944 | GNUNET_break_op (0); | ||
3945 | return GNUNET_OK; | ||
3946 | } | ||
3947 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " path has %u hops.\n", size); | ||
3948 | msg = (struct GNUNET_MESH_CreateTunnel *) message; | ||
3949 | |||
3950 | tid = ntohl (msg->tid); | ||
3951 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
3952 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3953 | " path is for tunnel %s[%X]:%u.\n", | ||
3954 | GNUNET_i2s (pi), tid, ntohl (msg->port)); | ||
3955 | t = tunnel_get (pi, tid); | ||
3956 | if (NULL == t) /* might be a local tunnel */ | ||
3957 | { | ||
3958 | uint32_t opt; | ||
3959 | |||
3960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating tunnel\n"); | ||
3961 | t = tunnel_new (GNUNET_PEER_intern (pi), tid, NULL, 0); | ||
3962 | if (NULL == t) | ||
3963 | { | ||
3964 | GNUNET_break (0); | ||
3965 | return GNUNET_OK; | ||
3966 | } | ||
3967 | t->port = ntohl (msg->port); | ||
3968 | opt = ntohl (msg->opt); | ||
3969 | if (0 != (opt & GNUNET_MESH_OPTION_NOBUFFER)) | ||
3970 | { | ||
3971 | t->nobuffer = GNUNET_YES; | ||
3972 | t->queue_max = 1; | ||
3973 | } | ||
3974 | if (0 != (opt & GNUNET_MESH_OPTION_RELIABLE)) | ||
3975 | { | ||
3976 | t->reliable = GNUNET_YES; | ||
3977 | } | ||
3978 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " nobuffer:%d\n", t->nobuffer); | ||
3979 | } | ||
3980 | tunnel_reset_timeout (t, GNUNET_YES); | ||
3981 | tunnel_change_state (t, MESH_TUNNEL_WAITING); | ||
3982 | dest_peer_info = | ||
3983 | GNUNET_CONTAINER_multipeermap_get (peers, &pi[size - 1]); | ||
3984 | if (NULL == dest_peer_info) | ||
3985 | { | ||
3986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3987 | " Creating PeerInfo for destination.\n"); | ||
3988 | dest_peer_info = GNUNET_malloc (sizeof (struct MeshPeer)); | ||
3989 | dest_peer_info->id = GNUNET_PEER_intern (&pi[size - 1]); | ||
3990 | GNUNET_CONTAINER_multipeermap_put (peers, &pi[size - 1], | ||
3991 | dest_peer_info, | ||
3992 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
3993 | } | ||
3994 | orig_peer_info = GNUNET_CONTAINER_multipeermap_get (peers, pi); | ||
3995 | if (NULL == orig_peer_info) | ||
3996 | { | ||
3997 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3998 | " Creating PeerInfo for origin.\n"); | ||
3999 | orig_peer_info = GNUNET_new (struct MeshPeer); | ||
4000 | orig_peer_info->id = GNUNET_PEER_intern (pi); | ||
4001 | GNUNET_CONTAINER_multipeermap_put (peers, pi, orig_peer_info, | ||
4002 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
4003 | } | ||
4004 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n"); | ||
4005 | path = path_new (size); | ||
4006 | own_pos = 0; | ||
4007 | for (i = 0; i < size; i++) | ||
4008 | { | ||
4009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n", | ||
4010 | GNUNET_i2s (&pi[i])); | ||
4011 | path->peers[i] = GNUNET_PEER_intern (&pi[i]); | ||
4012 | if (path->peers[i] == myid) | ||
4013 | own_pos = i; | ||
4014 | } | ||
4015 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); | ||
4016 | if (own_pos == 0 && path->peers[own_pos] != myid) | ||
4017 | { | ||
4018 | /* create path: self not found in path through self */ | ||
4019 | GNUNET_break_op (0); | ||
4020 | path_destroy (path); | ||
4021 | tunnel_destroy (t); | ||
4022 | return GNUNET_OK; | ||
4023 | } | ||
4024 | path_add_to_peers (path, GNUNET_NO); | ||
4025 | tunnel_use_path (t, path); | ||
4026 | |||
4027 | peer_add_tunnel (dest_peer_info, t); | ||
4028 | |||
4029 | if (own_pos == size - 1) | ||
4030 | { | ||
4031 | struct MeshClient *c; | ||
4032 | |||
4033 | /* Find target client */ | ||
4034 | c = GNUNET_CONTAINER_multihashmap32_get (ports, t->port); | ||
4035 | if (NULL == c) | ||
4036 | { | ||
4037 | /* TODO send reject */ | ||
4038 | return GNUNET_OK; | ||
4039 | } | ||
4040 | |||
4041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); | ||
4042 | peer_add_path_to_origin (orig_peer_info, path, GNUNET_YES); | ||
4043 | /* This can be a retransmission due to a lost PATH ACK. | ||
4044 | * Check if we already have a destination client for the tunnel. */ | ||
4045 | if (t->client != c) | ||
4046 | { | ||
4047 | /* Assign local tid */ | ||
4048 | while (NULL != tunnel_get_incoming (next_local_tid)) | ||
4049 | next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | ||
4050 | t->local_tid_dest = next_local_tid++; | ||
4051 | next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | ||
4052 | |||
4053 | if (GNUNET_YES == t->reliable) | ||
4054 | { | ||
4055 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! Reliable\n"); | ||
4056 | t->bck_rel = GNUNET_malloc (sizeof (struct MeshTunnelReliability)); | ||
4057 | t->bck_rel->t = t; | ||
4058 | t->bck_rel->expected_delay = MESH_RETRANSMIT_TIME; | ||
4059 | } | ||
4060 | |||
4061 | tunnel_add_client (t, c); | ||
4062 | send_local_tunnel_create (t); | ||
4063 | } | ||
4064 | send_path_ack (t); | ||
4065 | /* Eliminate tunnel when origin dies */ | ||
4066 | tunnel_reset_timeout (t, GNUNET_YES); | ||
4067 | /* Keep tunnel alive in direction dest->owner*/ | ||
4068 | tunnel_reset_timeout (t, GNUNET_NO); | ||
4069 | } | ||
4070 | else | ||
4071 | { | ||
4072 | struct MeshPeerPath *path2; | ||
4073 | |||
4074 | t->next_hop = path->peers[own_pos + 1]; | ||
4075 | GNUNET_PEER_change_rc(t->next_hop, 1); | ||
4076 | |||
4077 | /* It's for somebody else! Retransmit. */ | ||
4078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Retransmitting.\n"); | ||
4079 | path2 = path_duplicate (path); | ||
4080 | peer_add_path (dest_peer_info, path2, GNUNET_NO); | ||
4081 | peer_add_path_to_origin (orig_peer_info, path, GNUNET_NO); | ||
4082 | send_path_create (t); | ||
4083 | } | ||
4084 | return GNUNET_OK; | ||
4085 | } | ||
4086 | |||
4087 | |||
4088 | |||
4089 | /** | ||
4090 | * Core handler for path ACKs | ||
4091 | * | ||
4092 | * @param cls closure | ||
4093 | * @param message message | ||
4094 | * @param peer peer identity this notification is about | ||
4095 | * | ||
4096 | * @return GNUNET_OK to keep the connection open, | ||
4097 | * GNUNET_SYSERR to close it (signal serious error) | ||
4098 | */ | ||
4099 | static int | ||
4100 | handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
4101 | const struct GNUNET_MessageHeader *message) | ||
4102 | { | ||
4103 | struct GNUNET_MESH_PathACK *msg; | ||
4104 | struct MeshPeer *peer_info; | ||
4105 | struct MeshPeerPath *p; | ||
4106 | struct MeshTunnel *t; | ||
4107 | |||
4108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a path ACK msg [%s]\n", | ||
4109 | GNUNET_i2s (&my_full_id)); | ||
4110 | msg = (struct GNUNET_MESH_PathACK *) message; | ||
4111 | t = tunnel_get (&msg->oid, ntohl(msg->tid)); | ||
4112 | if (NULL == t) | ||
4113 | { | ||
4114 | /* TODO notify that we don't know the tunnel */ | ||
4115 | GNUNET_STATISTICS_update (stats, "# control on unknown tunnel", 1, GNUNET_NO); | ||
4116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " don't know the tunnel %s [%X]!\n", | ||
4117 | GNUNET_i2s (&msg->oid), ntohl(msg->tid)); | ||
4118 | return GNUNET_OK; | ||
4119 | } | ||
4120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %s [%X]\n", | ||
4121 | GNUNET_i2s (&msg->oid), ntohl(msg->tid)); | ||
4122 | |||
4123 | peer_info = peer_get (&msg->peer_id); | ||
4124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by peer %s\n", | ||
4125 | GNUNET_i2s (&msg->peer_id)); | ||
4126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " via peer %s\n", | ||
4127 | GNUNET_i2s (peer)); | ||
4128 | |||
4129 | /* Add path to peers? */ | ||
4130 | p = t->path; | ||
4131 | if (NULL != p) | ||
4132 | { | ||
4133 | path_add_to_peers (p, GNUNET_YES); | ||
4134 | } | ||
4135 | else | ||
4136 | { | ||
4137 | GNUNET_break (0); | ||
4138 | } | ||
4139 | tunnel_change_state (t, MESH_TUNNEL_READY); | ||
4140 | tunnel_reset_timeout (t, GNUNET_NO); | ||
4141 | t->next_fc.last_ack_recv = (NULL == t->client) ? ntohl (msg->ack) : 0; | ||
4142 | t->prev_fc.last_ack_sent = ntohl (msg->ack); | ||
4143 | |||
4144 | /* Message for us? */ | ||
4145 | if (0 == memcmp (&msg->oid, &my_full_id, sizeof (struct GNUNET_PeerIdentity))) | ||
4146 | { | ||
4147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); | ||
4148 | if (NULL == t->owner) | ||
4149 | { | ||
4150 | GNUNET_break_op (0); | ||
4151 | return GNUNET_OK; | ||
4152 | } | ||
4153 | if (NULL != peer_info->dhtget) | ||
4154 | { | ||
4155 | GNUNET_DHT_get_stop (peer_info->dhtget); | ||
4156 | peer_info->dhtget = NULL; | ||
4157 | } | ||
4158 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, GNUNET_YES); | ||
4159 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, GNUNET_NO); | ||
4160 | return GNUNET_OK; | ||
4161 | } | ||
4162 | |||
4163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4164 | " not for us, retransmitting...\n"); | ||
4165 | send_prebuilt_message (message, t->prev_hop, t); | ||
4166 | return GNUNET_OK; | ||
4167 | } | ||
4168 | |||
4169 | |||
4170 | /** | ||
4171 | * Core handler for notifications of broken paths | ||
4172 | * | ||
4173 | * @param cls closure | ||
4174 | * @param message message | ||
4175 | * @param peer peer identity this notification is about | ||
4176 | * | ||
4177 | * @return GNUNET_OK to keep the connection open, | ||
4178 | * GNUNET_SYSERR to close it (signal serious error) | ||
4179 | */ | ||
4180 | static int | ||
4181 | handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
4182 | const struct GNUNET_MessageHeader *message) | ||
4183 | { | ||
4184 | struct GNUNET_MESH_PathBroken *msg; | ||
4185 | struct MeshTunnel *t; | ||
4186 | |||
4187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4188 | "Received a PATH BROKEN msg from %s\n", GNUNET_i2s (peer)); | ||
4189 | msg = (struct GNUNET_MESH_PathBroken *) message; | ||
4190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regarding %s\n", | ||
4191 | GNUNET_i2s (&msg->peer1)); | ||
4192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regarding %s\n", | ||
4193 | GNUNET_i2s (&msg->peer2)); | ||
4194 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | ||
4195 | if (NULL == t) | ||
4196 | { | ||
4197 | GNUNET_break_op (0); | ||
4198 | return GNUNET_OK; | ||
4199 | } | ||
4200 | tunnel_notify_connection_broken (t, GNUNET_PEER_search (&msg->peer1), | ||
4201 | GNUNET_PEER_search (&msg->peer2)); | ||
4202 | return GNUNET_OK; | ||
4203 | |||
4204 | } | ||
4205 | |||
4206 | |||
4207 | /** | ||
4208 | * Core handler for tunnel destruction | ||
4209 | * | ||
4210 | * @param cls closure | ||
4211 | * @param message message | ||
4212 | * @param peer peer identity this notification is about | ||
4213 | * | ||
4214 | * @return GNUNET_OK to keep the connection open, | ||
4215 | * GNUNET_SYSERR to close it (signal serious error) | ||
4216 | */ | ||
4217 | static int | ||
4218 | handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
4219 | const struct GNUNET_MessageHeader *message) | ||
4220 | { | ||
4221 | struct GNUNET_MESH_TunnelDestroy *msg; | ||
4222 | struct MeshTunnel *t; | ||
4223 | |||
4224 | msg = (struct GNUNET_MESH_TunnelDestroy *) message; | ||
4225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4226 | "Got a TUNNEL DESTROY packet from %s\n", | ||
4227 | GNUNET_i2s (peer)); | ||
4228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4229 | " for tunnel %s [%u]\n", | ||
4230 | GNUNET_i2s (&msg->oid), ntohl (msg->tid)); | ||
4231 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | ||
4232 | if (NULL == t) | ||
4233 | { | ||
4234 | /* Probably already got the message from another path, | ||
4235 | * destroyed the tunnel and retransmitted to children. | ||
4236 | * Safe to ignore. | ||
4237 | */ | ||
4238 | GNUNET_STATISTICS_update (stats, "# control on unknown tunnel", | ||
4239 | 1, GNUNET_NO); | ||
4240 | return GNUNET_OK; | ||
4241 | } | ||
4242 | if (t->local_tid_dest >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | ||
4243 | { | ||
4244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "INCOMING TUNNEL %X %X\n", | ||
4245 | t->local_tid, t->local_tid_dest); | ||
4246 | } | ||
4247 | if (GNUNET_PEER_search (peer) == t->prev_hop) | ||
4248 | { | ||
4249 | // TODO check owner's signature | ||
4250 | // TODO add owner's signatue to tunnel for retransmission | ||
4251 | peer_cancel_queues (t->prev_hop, t); | ||
4252 | GNUNET_PEER_change_rc (t->prev_hop, -1); | ||
4253 | t->prev_hop = 0; | ||
4254 | } | ||
4255 | else if (GNUNET_PEER_search (peer) == t->next_hop) | ||
4256 | { | ||
4257 | // TODO check dest's signature | ||
4258 | // TODO add dest's signatue to tunnel for retransmission | ||
4259 | peer_cancel_queues (t->next_hop, t); | ||
4260 | GNUNET_PEER_change_rc (t->next_hop, -1); | ||
4261 | t->next_hop = 0; | ||
4262 | } | ||
4263 | else | ||
4264 | { | ||
4265 | GNUNET_break_op (0); | ||
4266 | // TODO check both owner AND destination's signature to see which matches | ||
4267 | // TODO restransmit in appropriate direction | ||
4268 | return GNUNET_OK; | ||
4269 | } | ||
4270 | tunnel_destroy_empty (t); | ||
4271 | |||
4272 | // TODO: add timeout to destroy the tunnel anyway | ||
4273 | return GNUNET_OK; | ||
4274 | } | ||
4275 | |||
4276 | |||
4277 | /** | ||
4278 | * Generic handler for mesh network payload traffic. | ||
4279 | * | ||
4280 | * @param peer Peer identity this notification is about. | ||
4281 | * @param message Data message. | ||
4282 | * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; | ||
4283 | * | ||
4284 | * @return GNUNET_OK to keep the connection open, | ||
4285 | * GNUNET_SYSERR to close it (signal serious error) | ||
4286 | */ | ||
4287 | static int | ||
4288 | handle_mesh_data (const struct GNUNET_PeerIdentity *peer, | ||
4289 | const struct GNUNET_MessageHeader *message, | ||
4290 | int fwd) | ||
4291 | { | ||
4292 | struct GNUNET_MESH_Data *msg; | ||
4293 | struct MeshFlowControl *fc; | ||
4294 | struct MeshTunnelReliability *rel; | ||
4295 | struct MeshTunnel *t; | ||
4296 | struct MeshClient *c; | ||
4297 | GNUNET_PEER_Id hop; | ||
4298 | uint32_t pid; | ||
4299 | uint32_t ttl; | ||
4300 | uint16_t type; | ||
4301 | size_t size; | ||
4302 | |||
4303 | /* Check size */ | ||
4304 | size = ntohs (message->size); | ||
4305 | if (size < | ||
4306 | sizeof (struct GNUNET_MESH_Data) + | ||
4307 | sizeof (struct GNUNET_MessageHeader)) | ||
4308 | { | ||
4309 | GNUNET_break (0); | ||
4310 | return GNUNET_OK; | ||
4311 | } | ||
4312 | type =ntohs (message->type); | ||
4313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a %s message from %s\n", | ||
4314 | GNUNET_MESH_DEBUG_M2S (type), GNUNET_i2s (peer)); | ||
4315 | msg = (struct GNUNET_MESH_Data *) message; | ||
4316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " payload of type %s\n", | ||
4317 | GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type))); | ||
4318 | /* Check tunnel */ | ||
4319 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | ||
4320 | if (NULL == t) | ||
4321 | { | ||
4322 | /* TODO notify back: we don't know this tunnel */ | ||
4323 | GNUNET_STATISTICS_update (stats, "# data on unknown tunnel", 1, GNUNET_NO); | ||
4324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WARNING tunnel unknown\n"); | ||
4325 | return GNUNET_OK; | ||
4326 | } | ||
4327 | |||
4328 | /* Initialize FWD/BCK data */ | ||
4329 | pid = ntohl (msg->pid); | ||
4330 | fc = fwd ? &t->prev_fc : &t->next_fc; | ||
4331 | c = fwd ? t->client : t->owner; | ||
4332 | rel = fwd ? t->bck_rel : t->fwd_rel; | ||
4333 | hop = fwd ? t->next_hop : t->prev_hop; | ||
4334 | if (GMC_is_pid_bigger (pid, fc->last_ack_sent)) | ||
4335 | { | ||
4336 | GNUNET_STATISTICS_update (stats, "# unsolicited data", 1, GNUNET_NO); | ||
4337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4338 | "WARNING Received PID %u, (prev %u), ACK %u\n", | ||
4339 | pid, fc->last_pid_recv, fc->last_ack_sent); | ||
4340 | return GNUNET_OK; | ||
4341 | } | ||
4342 | if (NULL != c) | ||
4343 | tunnel_change_state (t, MESH_TUNNEL_READY); | ||
4344 | tunnel_reset_timeout (t, fwd); | ||
4345 | if (NULL != c) | ||
4346 | { | ||
4347 | /* TODO signature verification */ | ||
4348 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " it's for us! sending to client\n"); | ||
4349 | GNUNET_STATISTICS_update (stats, "# data received", 1, GNUNET_NO); | ||
4350 | if (GMC_is_pid_bigger (pid, fc->last_pid_recv)) | ||
4351 | { | ||
4352 | uint32_t mid; | ||
4353 | |||
4354 | mid = ntohl (msg->mid); | ||
4355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4356 | " pid %u (mid %u) not seen yet\n", pid, mid); | ||
4357 | fc->last_pid_recv = pid; | ||
4358 | |||
4359 | if (GNUNET_NO == t->reliable || | ||
4360 | ( !GMC_is_pid_bigger (rel->mid_recv, mid) && | ||
4361 | GMC_is_pid_bigger (rel->mid_recv + 64, mid) ) ) | ||
4362 | { | ||
4363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4364 | "!!! RECV %u\n", ntohl (msg->mid)); | ||
4365 | if (GNUNET_YES == t->reliable) | ||
4366 | { | ||
4367 | /* Is this the exact next expected messasge? */ | ||
4368 | if (mid == rel->mid_recv) | ||
4369 | { | ||
4370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "as expected\n"); | ||
4371 | rel->mid_recv++; | ||
4372 | tunnel_send_client_data (t, msg, fwd); | ||
4373 | tunnel_send_client_buffered_data (t, c, rel); | ||
4374 | } | ||
4375 | else | ||
4376 | { | ||
4377 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "save for later\n"); | ||
4378 | tunnel_add_buffered_data (t, msg, rel); | ||
4379 | } | ||
4380 | } | ||
4381 | else /* Tunnel unreliable, send to clients directly */ | ||
4382 | { | ||
4383 | tunnel_send_client_data (t, msg, fwd); | ||
4384 | } | ||
4385 | } | ||
4386 | else | ||
4387 | { | ||
4388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4389 | " MID %u not expected (%u - %u), dropping!\n", | ||
4390 | ntohl (msg->mid), rel->mid_recv, rel->mid_recv + 64); | ||
4391 | } | ||
4392 | } | ||
4393 | else | ||
4394 | { | ||
4395 | // GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO); | ||
4396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4397 | " Pid %u not expected (%u+), dropping!\n", | ||
4398 | pid, fc->last_pid_recv + 1); | ||
4399 | } | ||
4400 | tunnel_send_ack (t, type, fwd); | ||
4401 | return GNUNET_OK; | ||
4402 | } | ||
4403 | fc->last_pid_recv = pid; | ||
4404 | if (0 == hop) | ||
4405 | { | ||
4406 | GNUNET_STATISTICS_update (stats, "# data on dying tunnel", 1, GNUNET_NO); | ||
4407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "data on dying tunnel %s[%X]\n", | ||
4408 | GNUNET_PEER_resolve2 (t->id.oid), ntohl (msg->tid)); | ||
4409 | return GNUNET_OK; /* Next hop has destoyed the tunnel, drop */ | ||
4410 | } | ||
4411 | ttl = ntohl (msg->ttl); | ||
4412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ttl: %u\n", ttl); | ||
4413 | if (ttl == 0) | ||
4414 | { | ||
4415 | GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO); | ||
4416 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n"); | ||
4417 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK, fwd); | ||
4418 | return GNUNET_OK; | ||
4419 | } | ||
4420 | |||
4421 | if (myid != hop) | ||
4422 | { | ||
4423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | ||
4424 | send_prebuilt_message (message, hop, t); | ||
4425 | GNUNET_STATISTICS_update (stats, "# unicast forwarded", 1, GNUNET_NO); | ||
4426 | } | ||
4427 | return GNUNET_OK; | ||
4428 | } | ||
4429 | |||
4430 | |||
4431 | /** | ||
4432 | * Core handler for mesh network traffic going from the origin to a peer | ||
4433 | * | ||
4434 | * @param cls Closure (unused). | ||
4435 | * @param message Message received. | ||
4436 | * @param peer Peer who sent the message. | ||
4437 | * | ||
4438 | * @return GNUNET_OK to keep the connection open, | ||
4439 | * GNUNET_SYSERR to close it (signal serious error) | ||
4440 | */ | ||
4441 | static int | ||
4442 | handle_mesh_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
4443 | const struct GNUNET_MessageHeader *message) | ||
4444 | { | ||
4445 | return handle_mesh_data (peer, message, GNUNET_YES); | ||
4446 | } | ||
4447 | |||
4448 | /** | ||
4449 | * Core handler for mesh network traffic towards the owner of a tunnel. | ||
4450 | * | ||
4451 | * @param cls Closure (unused). | ||
4452 | * @param message Message received. | ||
4453 | * @param peer Peer who sent the message. | ||
4454 | * | ||
4455 | * @return GNUNET_OK to keep the connection open, | ||
4456 | * GNUNET_SYSERR to close it (signal serious error) | ||
4457 | */ | ||
4458 | static int | ||
4459 | handle_mesh_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
4460 | const struct GNUNET_MessageHeader *message) | ||
4461 | { | ||
4462 | return handle_mesh_data (peer, message, GNUNET_NO); | ||
4463 | } | ||
4464 | |||
4465 | |||
4466 | /** | ||
4467 | * Core handler for mesh network traffic end-to-end ACKs. | ||
4468 | * | ||
4469 | * @param cls Closure. | ||
4470 | * @param message Message. | ||
4471 | * @param peer Peer identity this notification is about. | ||
4472 | * | ||
4473 | * @return GNUNET_OK to keep the connection open, | ||
4474 | * GNUNET_SYSERR to close it (signal serious error) | ||
4475 | */ | ||
4476 | static int | ||
4477 | handle_mesh_data_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
4478 | const struct GNUNET_MessageHeader *message) | ||
4479 | { | ||
4480 | struct GNUNET_MESH_DataACK *msg; | ||
4481 | struct MeshTunnelReliability *rel; | ||
4482 | struct MeshReliableMessage *copy; | ||
4483 | struct MeshReliableMessage *next; | ||
4484 | struct MeshTunnel *t; | ||
4485 | GNUNET_PEER_Id id; | ||
4486 | uint32_t ack; | ||
4487 | uint16_t type; | ||
4488 | int work; | ||
4489 | |||
4490 | type = ntohs (message->type); | ||
4491 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a %s message from %s!\n", | ||
4492 | GNUNET_MESH_DEBUG_M2S (type), GNUNET_i2s (peer)); | ||
4493 | msg = (struct GNUNET_MESH_DataACK *) message; | ||
4494 | |||
4495 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | ||
4496 | if (NULL == t) | ||
4497 | { | ||
4498 | /* TODO notify that we dont know this tunnel (whom)? */ | ||
4499 | GNUNET_STATISTICS_update (stats, "# ack on unknown tunnel", 1, GNUNET_NO); | ||
4500 | return GNUNET_OK; | ||
4501 | } | ||
4502 | ack = ntohl (msg->mid); | ||
4503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); | ||
4504 | |||
4505 | /* Is this a forward or backward ACK? */ | ||
4506 | id = GNUNET_PEER_search (peer); | ||
4507 | if (t->next_hop == id && GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK == type) | ||
4508 | { | ||
4509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); | ||
4510 | if (NULL == t->owner) | ||
4511 | { | ||
4512 | send_prebuilt_message (message, t->prev_hop, t); | ||
4513 | return GNUNET_OK; | ||
4514 | } | ||
4515 | rel = t->fwd_rel; | ||
4516 | } | ||
4517 | else if (t->prev_hop == id && GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK == type) | ||
4518 | { | ||
4519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); | ||
4520 | if (NULL == t->client) | ||
4521 | { | ||
4522 | send_prebuilt_message (message, t->next_hop, t); | ||
4523 | return GNUNET_OK; | ||
4524 | } | ||
4525 | rel = t->bck_rel; | ||
4526 | } | ||
4527 | else | ||
4528 | { | ||
4529 | GNUNET_break_op (0); | ||
4530 | return GNUNET_OK; | ||
4531 | } | ||
4532 | |||
4533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! ACK %u\n", ack); | ||
4534 | for (work = GNUNET_NO, copy = rel->head_sent; copy != NULL; copy = next) | ||
4535 | { | ||
4536 | if (GMC_is_pid_bigger (copy->mid, ack)) | ||
4537 | { | ||
4538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! head %u, out!\n", copy->mid); | ||
4539 | tunnel_free_sent_reliable (t, msg, rel); | ||
4540 | break; | ||
4541 | } | ||
4542 | work = GNUNET_YES; | ||
4543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! id %u\n", copy->mid); | ||
4544 | next = copy->next; | ||
4545 | tunnel_free_reliable_message (copy); | ||
4546 | } | ||
4547 | /* Once buffers have been free'd, send ACK */ | ||
4548 | tunnel_send_ack (t, type, GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK == type); | ||
4549 | |||
4550 | /* If some message was free'd, update the retransmission delay*/ | ||
4551 | if (GNUNET_YES == work) | ||
4552 | { | ||
4553 | if (GNUNET_SCHEDULER_NO_TASK != rel->retry_task) | ||
4554 | { | ||
4555 | GNUNET_SCHEDULER_cancel (rel->retry_task); | ||
4556 | if (NULL == rel->head_sent) | ||
4557 | { | ||
4558 | rel->retry_task = GNUNET_SCHEDULER_NO_TASK; | ||
4559 | } | ||
4560 | else | ||
4561 | { | ||
4562 | struct GNUNET_TIME_Absolute new_target; | ||
4563 | struct GNUNET_TIME_Relative delay; | ||
4564 | |||
4565 | delay = GNUNET_TIME_relative_multiply (rel->retry_timer, | ||
4566 | MESH_RETRANSMIT_MARGIN); | ||
4567 | new_target = GNUNET_TIME_absolute_add (rel->head_sent->timestamp, | ||
4568 | delay); | ||
4569 | delay = GNUNET_TIME_absolute_get_remaining (new_target); | ||
4570 | rel->retry_task = | ||
4571 | GNUNET_SCHEDULER_add_delayed (delay, | ||
4572 | &tunnel_retransmit_message, | ||
4573 | rel); | ||
4574 | } | ||
4575 | } | ||
4576 | else | ||
4577 | GNUNET_break (0); | ||
4578 | } | ||
4579 | return GNUNET_OK; | ||
4580 | } | ||
4581 | |||
4582 | /** | ||
4583 | * Core handler for mesh network traffic point-to-point acks. | ||
4584 | * | ||
4585 | * @param cls closure | ||
4586 | * @param message message | ||
4587 | * @param peer peer identity this notification is about | ||
4588 | * | ||
4589 | * @return GNUNET_OK to keep the connection open, | ||
4590 | * GNUNET_SYSERR to close it (signal serious error) | ||
4591 | */ | ||
4592 | static int | ||
4593 | handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
4594 | const struct GNUNET_MessageHeader *message) | ||
4595 | { | ||
4596 | struct GNUNET_MESH_ACK *msg; | ||
4597 | struct MeshTunnel *t; | ||
4598 | struct MeshFlowControl *fc; | ||
4599 | GNUNET_PEER_Id id; | ||
4600 | uint32_t ack; | ||
4601 | |||
4602 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK packet from %s!\n", | ||
4603 | GNUNET_i2s (peer)); | ||
4604 | msg = (struct GNUNET_MESH_ACK *) message; | ||
4605 | |||
4606 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | ||
4607 | |||
4608 | if (NULL == t) | ||
4609 | { | ||
4610 | /* TODO notify that we dont know this tunnel (whom)? */ | ||
4611 | GNUNET_STATISTICS_update (stats, "# ack on unknown tunnel", 1, GNUNET_NO); | ||
4612 | return GNUNET_OK; | ||
4613 | } | ||
4614 | ack = ntohl (msg->pid); | ||
4615 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); | ||
4616 | |||
4617 | /* Is this a forward or backward ACK? */ | ||
4618 | id = GNUNET_PEER_search (peer); | ||
4619 | if (t->next_hop == id) | ||
4620 | { | ||
4621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); | ||
4622 | fc = &t->next_fc; | ||
4623 | } | ||
4624 | else if (t->prev_hop == id) | ||
4625 | { | ||
4626 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); | ||
4627 | fc = &t->prev_fc; | ||
4628 | } | ||
4629 | else | ||
4630 | { | ||
4631 | GNUNET_break_op (0); | ||
4632 | return GNUNET_OK; | ||
4633 | } | ||
4634 | |||
4635 | if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task && | ||
4636 | GMC_is_pid_bigger (ack, fc->last_ack_recv)) | ||
4637 | { | ||
4638 | GNUNET_SCHEDULER_cancel (fc->poll_task); | ||
4639 | fc->poll_task = GNUNET_SCHEDULER_NO_TASK; | ||
4640 | fc->poll_time = GNUNET_TIME_UNIT_SECONDS; | ||
4641 | } | ||
4642 | |||
4643 | fc->last_ack_recv = ack; | ||
4644 | peer_unlock_queue (id); | ||
4645 | tunnel_change_state (t, MESH_TUNNEL_READY); | ||
4646 | |||
4647 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK, t->next_hop == id); | ||
4648 | |||
4649 | return GNUNET_OK; | ||
4650 | } | ||
4651 | |||
4652 | |||
4653 | /** | ||
4654 | * Core handler for mesh network traffic point-to-point ack polls. | ||
4655 | * | ||
4656 | * @param cls closure | ||
4657 | * @param message message | ||
4658 | * @param peer peer identity this notification is about | ||
4659 | * | ||
4660 | * @return GNUNET_OK to keep the connection open, | ||
4661 | * GNUNET_SYSERR to close it (signal serious error) | ||
4662 | */ | ||
4663 | static int | ||
4664 | handle_mesh_poll (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
4665 | const struct GNUNET_MessageHeader *message) | ||
4666 | { | ||
4667 | struct GNUNET_MESH_Poll *msg; | ||
4668 | struct MeshTunnel *t; | ||
4669 | struct MeshFlowControl *fc; | ||
4670 | GNUNET_PEER_Id id; | ||
4671 | uint32_t pid; | ||
4672 | uint32_t old; | ||
4673 | |||
4674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a POLL packet from %s!\n", | ||
4675 | GNUNET_i2s (peer)); | ||
4676 | |||
4677 | msg = (struct GNUNET_MESH_Poll *) message; | ||
4678 | |||
4679 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | ||
4680 | |||
4681 | if (NULL == t) | ||
4682 | { | ||
4683 | /* TODO notify that we dont know this tunnel (whom)? */ | ||
4684 | GNUNET_STATISTICS_update (stats, "# poll on unknown tunnel", 1, GNUNET_NO); | ||
4685 | GNUNET_break_op (0); | ||
4686 | return GNUNET_OK; | ||
4687 | } | ||
4688 | |||
4689 | /* Is this a forward or backward ACK? */ | ||
4690 | id = GNUNET_PEER_search (peer); | ||
4691 | pid = ntohl (msg->pid); | ||
4692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " PID %u\n", pid); | ||
4693 | if (t->next_hop == id) | ||
4694 | { | ||
4695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " from FWD\n"); | ||
4696 | fc = &t->next_fc; | ||
4697 | old = fc->last_pid_recv; | ||
4698 | } | ||
4699 | else if (t->prev_hop == id) | ||
4700 | { | ||
4701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " from BCK\n"); | ||
4702 | fc = &t->prev_fc; | ||
4703 | old = fc->last_pid_recv; | ||
4704 | } | ||
4705 | else | ||
4706 | { | ||
4707 | GNUNET_break (0); | ||
4708 | return GNUNET_OK; | ||
4709 | } | ||
4710 | |||
4711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " was %u\n", fc->last_pid_recv); | ||
4712 | fc->last_pid_recv = pid; | ||
4713 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_POLL, t->prev_hop == id); | ||
4714 | |||
4715 | if (GNUNET_YES == t->reliable) | ||
4716 | fc->last_pid_recv = old; | ||
4717 | |||
4718 | return GNUNET_OK; | ||
4719 | } | ||
4720 | |||
4721 | |||
4722 | /** | ||
4723 | * Core handler for mesh keepalives. | ||
4724 | * | ||
4725 | * @param cls closure | ||
4726 | * @param message message | ||
4727 | * @param peer peer identity this notification is about | ||
4728 | * @return GNUNET_OK to keep the connection open, | ||
4729 | * GNUNET_SYSERR to close it (signal serious error) | ||
4730 | * | ||
4731 | * TODO: Check who we got this from, to validate route. | ||
4732 | */ | ||
4733 | static int | ||
4734 | handle_mesh_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
4735 | const struct GNUNET_MessageHeader *message) | ||
4736 | { | ||
4737 | struct GNUNET_MESH_TunnelKeepAlive *msg; | ||
4738 | struct MeshTunnel *t; | ||
4739 | struct MeshClient *c; | ||
4740 | GNUNET_PEER_Id hop; | ||
4741 | int fwd; | ||
4742 | |||
4743 | msg = (struct GNUNET_MESH_TunnelKeepAlive *) message; | ||
4744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a keepalive packet from %s\n", | ||
4745 | GNUNET_i2s (peer)); | ||
4746 | |||
4747 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | ||
4748 | if (NULL == t) | ||
4749 | { | ||
4750 | /* TODO notify that we dont know that tunnel */ | ||
4751 | GNUNET_STATISTICS_update (stats, "# keepalive on unknown tunnel", 1, | ||
4752 | GNUNET_NO); | ||
4753 | return GNUNET_OK; | ||
4754 | } | ||
4755 | |||
4756 | fwd = GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE == ntohs (message->type) ? | ||
4757 | GNUNET_YES : GNUNET_NO; | ||
4758 | c = fwd ? t->client : t->owner; | ||
4759 | hop = fwd ? t->next_hop : t->prev_hop; | ||
4760 | |||
4761 | if (NULL != c) | ||
4762 | tunnel_change_state (t, MESH_TUNNEL_READY); | ||
4763 | tunnel_reset_timeout (t, fwd); | ||
4764 | if (NULL != c || 0 == hop || myid == hop) | ||
4765 | return GNUNET_OK; | ||
4766 | |||
4767 | GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO); | ||
4768 | send_prebuilt_message (message, hop, t); | ||
4769 | return GNUNET_OK; | ||
4770 | } | ||
4771 | |||
4772 | |||
4773 | |||
4774 | /** | ||
4775 | * Functions to handle messages from core | ||
4776 | */ | ||
4777 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { | ||
4778 | {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, | ||
4779 | {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, | ||
4780 | sizeof (struct GNUNET_MESH_PathBroken)}, | ||
4781 | {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, | ||
4782 | sizeof (struct GNUNET_MESH_TunnelDestroy)}, | ||
4783 | {&handle_mesh_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, | ||
4784 | {&handle_mesh_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, | ||
4785 | {&handle_mesh_data_ack, GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK, | ||
4786 | sizeof (struct GNUNET_MESH_DataACK)}, | ||
4787 | {&handle_mesh_data_ack, GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK, | ||
4788 | sizeof (struct GNUNET_MESH_DataACK)}, | ||
4789 | {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE, | ||
4790 | sizeof (struct GNUNET_MESH_TunnelKeepAlive)}, | ||
4791 | {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE, | ||
4792 | sizeof (struct GNUNET_MESH_TunnelKeepAlive)}, | ||
4793 | {&handle_mesh_ack, GNUNET_MESSAGE_TYPE_MESH_ACK, | ||
4794 | sizeof (struct GNUNET_MESH_ACK)}, | ||
4795 | {&handle_mesh_poll, GNUNET_MESSAGE_TYPE_MESH_POLL, | ||
4796 | sizeof (struct GNUNET_MESH_Poll)}, | ||
4797 | {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, | ||
4798 | sizeof (struct GNUNET_MESH_PathACK)}, | ||
4799 | {NULL, 0, 0} | ||
4800 | }; | ||
4801 | |||
4802 | |||
4803 | /** | ||
4804 | * Function to process paths received for a new peer addition. The recorded | ||
4805 | * paths form the initial tunnel, which can be optimized later. | ||
4806 | * Called on each result obtained for the DHT search. | ||
4807 | * | ||
4808 | * @param cls closure | ||
4809 | * @param exp when will this value expire | ||
4810 | * @param key key of the result | ||
4811 | * @param get_path path of the get request | ||
4812 | * @param get_path_length lenght of get_path | ||
4813 | * @param put_path path of the put request | ||
4814 | * @param put_path_length length of the put_path | ||
4815 | * @param type type of the result | ||
4816 | * @param size number of bytes in data | ||
4817 | * @param data pointer to the result data | ||
4818 | */ | ||
4819 | static void | ||
4820 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | ||
4821 | const struct GNUNET_HashCode * key, | ||
4822 | const struct GNUNET_PeerIdentity *get_path, | ||
4823 | unsigned int get_path_length, | ||
4824 | const struct GNUNET_PeerIdentity *put_path, | ||
4825 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, | ||
4826 | size_t size, const void *data) | ||
4827 | { | ||
4828 | struct MeshPeer *peer = cls; | ||
4829 | struct MeshPeerPath *p; | ||
4830 | struct GNUNET_PeerIdentity pi; | ||
4831 | int i; | ||
4832 | |||
4833 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got results from DHT!\n"); | ||
4834 | GNUNET_PEER_resolve (peer->id, &pi); | ||
4835 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for %s\n", GNUNET_i2s (&pi)); | ||
4836 | |||
4837 | p = path_build_from_dht (get_path, get_path_length, | ||
4838 | put_path, put_path_length); | ||
4839 | path_add_to_peers (p, GNUNET_NO); | ||
4840 | path_destroy (p); | ||
4841 | for (i = 0; i < peer->ntunnels; i++) | ||
4842 | { | ||
4843 | struct GNUNET_PeerIdentity id; | ||
4844 | |||
4845 | GNUNET_PEER_resolve (peer->tunnels[i]->id.oid, &id); | ||
4846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... tunnel %s:%X (%X / %X)\n", | ||
4847 | GNUNET_i2s (&id), peer->tunnels[i]->id.tid, | ||
4848 | peer->tunnels[i]->local_tid, | ||
4849 | peer->tunnels[i]->local_tid_dest); | ||
4850 | if (peer->tunnels[i]->state == MESH_TUNNEL_SEARCHING) | ||
4851 | { | ||
4852 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... connect!\n"); | ||
4853 | peer_connect (peer, peer->tunnels[i]); | ||
4854 | } | ||
4855 | } | ||
4856 | |||
4857 | return; | ||
4858 | } | ||
4859 | |||
4860 | |||
4861 | /******************************************************************************/ | ||
4862 | /********************* MESH LOCAL HANDLES **************************/ | ||
4863 | /******************************************************************************/ | ||
4864 | |||
4865 | |||
4866 | /** | ||
4867 | * Handler for client connection. | ||
4868 | * | ||
4869 | * @param cls Closure (unused). | ||
4870 | * @param client Client handler. | ||
4871 | */ | ||
4872 | static void | ||
4873 | handle_local_client_connect (void *cls, struct GNUNET_SERVER_Client *client) | ||
4874 | { | ||
4875 | struct MeshClient *c; | ||
4876 | |||
4877 | if (NULL == client) | ||
4878 | return; | ||
4879 | c = GNUNET_malloc (sizeof (struct MeshClient)); | ||
4880 | c->handle = client; | ||
4881 | GNUNET_SERVER_client_keep (client); | ||
4882 | GNUNET_SERVER_client_set_user_context (client, c); | ||
4883 | GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c); | ||
4884 | } | ||
4885 | |||
4886 | |||
4887 | /** | ||
4888 | * Handler for client disconnection | ||
4889 | * | ||
4890 | * @param cls closure | ||
4891 | * @param client identification of the client; NULL | ||
4892 | * for the last call when the server is destroyed | ||
4893 | */ | ||
4894 | static void | ||
4895 | handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | ||
4896 | { | ||
4897 | struct MeshClient *c; | ||
4898 | |||
4899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected: %p\n", client); | ||
4900 | if (client == NULL) | ||
4901 | { | ||
4902 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (SERVER DOWN)\n"); | ||
4903 | return; | ||
4904 | } | ||
4905 | |||
4906 | c = client_get (client); | ||
4907 | if (NULL != c) | ||
4908 | { | ||
4909 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "matching client found (%u, %p)\n", | ||
4910 | c->id, c); | ||
4911 | GNUNET_SERVER_client_drop (c->handle); | ||
4912 | c->shutting_down = GNUNET_YES; | ||
4913 | if (NULL != c->own_tunnels) | ||
4914 | { | ||
4915 | GNUNET_CONTAINER_multihashmap32_iterate (c->own_tunnels, | ||
4916 | &tunnel_destroy_iterator, c); | ||
4917 | GNUNET_CONTAINER_multihashmap32_destroy (c->own_tunnels); | ||
4918 | } | ||
4919 | |||
4920 | if (NULL != c->incoming_tunnels) | ||
4921 | { | ||
4922 | GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_tunnels, | ||
4923 | &tunnel_destroy_iterator, c); | ||
4924 | GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_tunnels); | ||
4925 | } | ||
4926 | |||
4927 | if (NULL != c->ports) | ||
4928 | { | ||
4929 | GNUNET_CONTAINER_multihashmap32_iterate (c->ports, | ||
4930 | &client_release_ports, c); | ||
4931 | GNUNET_CONTAINER_multihashmap32_destroy (c->ports); | ||
4932 | } | ||
4933 | GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); | ||
4934 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client free (%p)\n", c); | ||
4935 | GNUNET_free (c); | ||
4936 | GNUNET_STATISTICS_update (stats, "# clients", -1, GNUNET_NO); | ||
4937 | } | ||
4938 | else | ||
4939 | { | ||
4940 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " context NULL!\n"); | ||
4941 | } | ||
4942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done!\n"); | ||
4943 | return; | ||
4944 | } | ||
4945 | |||
4946 | |||
4947 | /** | ||
4948 | * Handler for new clients | ||
4949 | * | ||
4950 | * @param cls closure | ||
4951 | * @param client identification of the client | ||
4952 | * @param message the actual message, which includes messages the client wants | ||
4953 | */ | ||
4954 | static void | ||
4955 | handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | ||
4956 | const struct GNUNET_MessageHeader *message) | ||
4957 | { | ||
4958 | struct GNUNET_MESH_ClientConnect *cc_msg; | ||
4959 | struct MeshClient *c; | ||
4960 | unsigned int size; | ||
4961 | uint32_t *p; | ||
4962 | unsigned int i; | ||
4963 | |||
4964 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected %p\n", client); | ||
4965 | |||
4966 | /* Check data sanity */ | ||
4967 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); | ||
4968 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; | ||
4969 | if (0 != (size % sizeof (uint32_t))) | ||
4970 | { | ||
4971 | GNUNET_break (0); | ||
4972 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
4973 | return; | ||
4974 | } | ||
4975 | size /= sizeof (uint32_t); | ||
4976 | |||
4977 | /* Initialize new client structure */ | ||
4978 | c = GNUNET_SERVER_client_get_user_context (client, struct MeshClient); | ||
4979 | c->id = next_client_id++; /* overflow not important: just for debug */ | ||
4980 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client id %u\n", c->id); | ||
4981 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u ports\n", size); | ||
4982 | if (size > 0) | ||
4983 | { | ||
4984 | uint32_t u32; | ||
4985 | |||
4986 | p = (uint32_t *) &cc_msg[1]; | ||
4987 | c->ports = GNUNET_CONTAINER_multihashmap32_create (size); | ||
4988 | for (i = 0; i < size; i++) | ||
4989 | { | ||
4990 | u32 = ntohl (p[i]); | ||
4991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " port: %u\n", u32); | ||
4992 | |||
4993 | /* store in client's hashmap */ | ||
4994 | GNUNET_CONTAINER_multihashmap32_put (c->ports, u32, c, | ||
4995 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
4996 | /* store in global hashmap */ | ||
4997 | /* FIXME only allow one client to have the port open, | ||
4998 | * have a backup hashmap with waiting clients */ | ||
4999 | GNUNET_CONTAINER_multihashmap32_put (ports, u32, c, | ||
5000 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
5001 | } | ||
5002 | } | ||
5003 | |||
5004 | c->own_tunnels = GNUNET_CONTAINER_multihashmap32_create (32); | ||
5005 | c->incoming_tunnels = GNUNET_CONTAINER_multihashmap32_create (32); | ||
5006 | GNUNET_SERVER_notification_context_add (nc, client); | ||
5007 | GNUNET_STATISTICS_update (stats, "# clients", 1, GNUNET_NO); | ||
5008 | |||
5009 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
5010 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client processed\n"); | ||
5011 | } | ||
5012 | |||
5013 | |||
5014 | /** | ||
5015 | * Handler for requests of new tunnels | ||
5016 | * | ||
5017 | * @param cls Closure. | ||
5018 | * @param client Identification of the client. | ||
5019 | * @param message The actual message. | ||
5020 | */ | ||
5021 | static void | ||
5022 | handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | ||
5023 | const struct GNUNET_MessageHeader *message) | ||
5024 | { | ||
5025 | struct GNUNET_MESH_TunnelMessage *t_msg; | ||
5026 | struct MeshPeer *peer_info; | ||
5027 | struct MeshTunnel *t; | ||
5028 | struct MeshClient *c; | ||
5029 | MESH_TunnelNumber tid; | ||
5030 | |||
5031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new tunnel requested\n"); | ||
5032 | |||
5033 | /* Sanity check for client registration */ | ||
5034 | if (NULL == (c = client_get (client))) | ||
5035 | { | ||
5036 | GNUNET_break (0); | ||
5037 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5038 | return; | ||
5039 | } | ||
5040 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); | ||
5041 | |||
5042 | /* Message size sanity check */ | ||
5043 | if (sizeof (struct GNUNET_MESH_TunnelMessage) != ntohs (message->size)) | ||
5044 | { | ||
5045 | GNUNET_break (0); | ||
5046 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5047 | return; | ||
5048 | } | ||
5049 | |||
5050 | t_msg = (struct GNUNET_MESH_TunnelMessage *) message; | ||
5051 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n", | ||
5052 | GNUNET_i2s (&t_msg->peer), ntohl (t_msg->port)); | ||
5053 | tid = ntohl (t_msg->tunnel_id); | ||
5054 | /* Sanity check for duplicate tunnel IDs */ | ||
5055 | if (NULL != tunnel_get_by_local_id (c, tid)) | ||
5056 | { | ||
5057 | GNUNET_break (0); | ||
5058 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5059 | return; | ||
5060 | } | ||
5061 | |||
5062 | /* Create tunnel */ | ||
5063 | while (NULL != tunnel_get_by_pi (myid, next_tid)) | ||
5064 | next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; | ||
5065 | t = tunnel_new (myid, next_tid, c, tid); | ||
5066 | next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; | ||
5067 | if (NULL == t) | ||
5068 | { | ||
5069 | GNUNET_break (0); | ||
5070 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5071 | return; | ||
5072 | } | ||
5073 | t->port = ntohl (t_msg->port); | ||
5074 | tunnel_set_options (t, ntohl (t_msg->opt)); | ||
5075 | if (GNUNET_YES == t->reliable) | ||
5076 | { | ||
5077 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! Reliable\n"); | ||
5078 | t->fwd_rel = GNUNET_malloc (sizeof (struct MeshTunnelReliability)); | ||
5079 | t->fwd_rel->t = t; | ||
5080 | t->fwd_rel->expected_delay = MESH_RETRANSMIT_TIME; | ||
5081 | } | ||
5082 | |||
5083 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s[%x]:%u (%x)\n", | ||
5084 | GNUNET_i2s (&my_full_id), t->id.tid, t->port, t->local_tid); | ||
5085 | |||
5086 | peer_info = peer_get (&t_msg->peer); | ||
5087 | peer_add_tunnel (peer_info, t); | ||
5088 | peer_connect (peer_info, t); | ||
5089 | tunnel_reset_timeout (t, GNUNET_YES); | ||
5090 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
5091 | return; | ||
5092 | } | ||
5093 | |||
5094 | |||
5095 | /** | ||
5096 | * Handler for requests of deleting tunnels | ||
5097 | * | ||
5098 | * @param cls closure | ||
5099 | * @param client identification of the client | ||
5100 | * @param message the actual message | ||
5101 | */ | ||
5102 | static void | ||
5103 | handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client, | ||
5104 | const struct GNUNET_MessageHeader *message) | ||
5105 | { | ||
5106 | struct GNUNET_MESH_TunnelMessage *tunnel_msg; | ||
5107 | struct MeshClient *c; | ||
5108 | struct MeshTunnel *t; | ||
5109 | MESH_TunnelNumber tid; | ||
5110 | |||
5111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
5112 | "Got a DESTROY TUNNEL from client!\n"); | ||
5113 | |||
5114 | /* Sanity check for client registration */ | ||
5115 | if (NULL == (c = client_get (client))) | ||
5116 | { | ||
5117 | GNUNET_break (0); | ||
5118 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5119 | return; | ||
5120 | } | ||
5121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); | ||
5122 | |||
5123 | /* Message sanity check */ | ||
5124 | if (sizeof (struct GNUNET_MESH_TunnelMessage) != ntohs (message->size)) | ||
5125 | { | ||
5126 | GNUNET_break (0); | ||
5127 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5128 | return; | ||
5129 | } | ||
5130 | |||
5131 | tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; | ||
5132 | |||
5133 | /* Retrieve tunnel */ | ||
5134 | tid = ntohl (tunnel_msg->tunnel_id); | ||
5135 | t = tunnel_get_by_local_id (c, tid); | ||
5136 | if (NULL == t) | ||
5137 | { | ||
5138 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " tunnel %X not found\n", tid); | ||
5139 | GNUNET_break (0); | ||
5140 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5141 | return; | ||
5142 | } | ||
5143 | |||
5144 | /* Cleanup after the tunnel */ | ||
5145 | client_delete_tunnel (c, t); | ||
5146 | if (c == t->client && GNUNET_MESH_LOCAL_TUNNEL_ID_SERV <= tid) | ||
5147 | { | ||
5148 | t->client = NULL; | ||
5149 | } | ||
5150 | else if (c == t->owner && GNUNET_MESH_LOCAL_TUNNEL_ID_SERV > tid) | ||
5151 | { | ||
5152 | peer_remove_tunnel (peer_get_short (t->dest), t); | ||
5153 | t->owner = NULL; | ||
5154 | } | ||
5155 | else | ||
5156 | { | ||
5157 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5158 | " tunnel %X client %p (%p, %p)\n", | ||
5159 | tid, c, t->owner, t->client); | ||
5160 | GNUNET_break (0); | ||
5161 | } | ||
5162 | |||
5163 | /* The tunnel will be destroyed when the last message is transmitted. */ | ||
5164 | tunnel_destroy_empty (t); | ||
5165 | |||
5166 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
5167 | return; | ||
5168 | } | ||
5169 | |||
5170 | |||
5171 | /** | ||
5172 | * Handler for client traffic | ||
5173 | * | ||
5174 | * @param cls closure | ||
5175 | * @param client identification of the client | ||
5176 | * @param message the actual message | ||
5177 | */ | ||
5178 | static void | ||
5179 | handle_local_data (void *cls, struct GNUNET_SERVER_Client *client, | ||
5180 | const struct GNUNET_MessageHeader *message) | ||
5181 | { | ||
5182 | struct GNUNET_MESH_LocalData *data_msg; | ||
5183 | struct MeshClient *c; | ||
5184 | struct MeshTunnel *t; | ||
5185 | struct MeshFlowControl *fc; | ||
5186 | MESH_TunnelNumber tid; | ||
5187 | size_t size; | ||
5188 | |||
5189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
5190 | "Got data from a client!\n"); | ||
5191 | |||
5192 | /* Sanity check for client registration */ | ||
5193 | if (NULL == (c = client_get (client))) | ||
5194 | { | ||
5195 | GNUNET_break (0); | ||
5196 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5197 | return; | ||
5198 | } | ||
5199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); | ||
5200 | |||
5201 | data_msg = (struct GNUNET_MESH_LocalData *) message; | ||
5202 | |||
5203 | /* Sanity check for message size */ | ||
5204 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_LocalData); | ||
5205 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
5206 | { | ||
5207 | GNUNET_break (0); | ||
5208 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5209 | return; | ||
5210 | } | ||
5211 | |||
5212 | /* Tunnel exists? */ | ||
5213 | tid = ntohl (data_msg->tid); | ||
5214 | t = tunnel_get_by_local_id (c, tid); | ||
5215 | if (NULL == t) | ||
5216 | { | ||
5217 | GNUNET_break (0); | ||
5218 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5219 | return; | ||
5220 | } | ||
5221 | |||
5222 | /* Is the client in the tunnel? */ | ||
5223 | if ( !( (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV && | ||
5224 | t->owner && | ||
5225 | t->owner->handle == client) | ||
5226 | || | ||
5227 | (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV && | ||
5228 | t->client && | ||
5229 | t->client->handle == client) ) ) | ||
5230 | { | ||
5231 | GNUNET_break (0); | ||
5232 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5233 | return; | ||
5234 | } | ||
5235 | |||
5236 | /* Ok, everything is correct, send the message | ||
5237 | * (pretend we got it from a mesh peer) | ||
5238 | */ | ||
5239 | { | ||
5240 | struct GNUNET_MESH_Data *payload; | ||
5241 | char cbuf[sizeof(struct GNUNET_MESH_Data) + size]; | ||
5242 | |||
5243 | fc = tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV ? &t->prev_fc : &t->next_fc; | ||
5244 | if (GNUNET_YES == t->reliable) | ||
5245 | { | ||
5246 | struct MeshTunnelReliability *rel; | ||
5247 | struct MeshReliableMessage *copy; | ||
5248 | |||
5249 | rel = (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) ? t->fwd_rel : t->bck_rel; | ||
5250 | copy = GNUNET_malloc (sizeof (struct MeshReliableMessage) | ||
5251 | + sizeof(struct GNUNET_MESH_Data) | ||
5252 | + size); | ||
5253 | copy->mid = rel->mid_sent++; | ||
5254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! DATA %u\n", copy->mid); | ||
5255 | copy->timestamp = GNUNET_TIME_absolute_get (); | ||
5256 | copy->rel = rel; | ||
5257 | rel->n_sent++; | ||
5258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " n_sent %u\n", rel->n_sent); | ||
5259 | GNUNET_CONTAINER_DLL_insert_tail (rel->head_sent, rel->tail_sent, copy); | ||
5260 | if (GNUNET_SCHEDULER_NO_TASK == rel->retry_task) | ||
5261 | { | ||
5262 | rel->retry_timer = | ||
5263 | GNUNET_TIME_relative_multiply (rel->expected_delay, | ||
5264 | MESH_RETRANSMIT_MARGIN); | ||
5265 | rel->retry_task = | ||
5266 | GNUNET_SCHEDULER_add_delayed (rel->retry_timer, | ||
5267 | &tunnel_retransmit_message, | ||
5268 | rel); | ||
5269 | } | ||
5270 | payload = (struct GNUNET_MESH_Data *) ©[1]; | ||
5271 | payload->mid = htonl (copy->mid); | ||
5272 | } | ||
5273 | else | ||
5274 | { | ||
5275 | payload = (struct GNUNET_MESH_Data *) cbuf; | ||
5276 | payload->mid = htonl (fc->last_pid_recv + 1); | ||
5277 | } | ||
5278 | memcpy (&payload[1], &data_msg[1], size); | ||
5279 | payload->header.size = htons (sizeof (struct GNUNET_MESH_Data) + size); | ||
5280 | payload->header.type = htons (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV ? | ||
5281 | GNUNET_MESSAGE_TYPE_MESH_UNICAST : | ||
5282 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN); | ||
5283 | GNUNET_PEER_resolve(t->id.oid, &payload->oid);; | ||
5284 | payload->tid = htonl (t->id.tid); | ||
5285 | payload->ttl = htonl (default_ttl); | ||
5286 | payload->pid = htonl (fc->last_pid_recv + 1); | ||
5287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
5288 | " calling generic handler...\n"); | ||
5289 | if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | ||
5290 | handle_mesh_unicast (NULL, &my_full_id, &payload->header); | ||
5291 | else | ||
5292 | handle_mesh_to_orig (NULL, &my_full_id, &payload->header); | ||
5293 | } | ||
5294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n"); | ||
5295 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
5296 | |||
5297 | return; | ||
5298 | } | ||
5299 | |||
5300 | |||
5301 | /** | ||
5302 | * Handler for client's ACKs for payload traffic. | ||
5303 | * | ||
5304 | * @param cls Closure (unused). | ||
5305 | * @param client Identification of the client. | ||
5306 | * @param message The actual message. | ||
5307 | */ | ||
5308 | static void | ||
5309 | handle_local_ack (void *cls, struct GNUNET_SERVER_Client *client, | ||
5310 | const struct GNUNET_MessageHeader *message) | ||
5311 | { | ||
5312 | struct GNUNET_MESH_LocalAck *msg; | ||
5313 | struct MeshTunnel *t; | ||
5314 | struct MeshClient *c; | ||
5315 | MESH_TunnelNumber tid; | ||
5316 | |||
5317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a local ACK\n"); | ||
5318 | /* Sanity check for client registration */ | ||
5319 | if (NULL == (c = client_get (client))) | ||
5320 | { | ||
5321 | GNUNET_break (0); | ||
5322 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5323 | return; | ||
5324 | } | ||
5325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); | ||
5326 | |||
5327 | msg = (struct GNUNET_MESH_LocalAck *) message; | ||
5328 | |||
5329 | /* Tunnel exists? */ | ||
5330 | tid = ntohl (msg->tunnel_id); | ||
5331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %X\n", tid); | ||
5332 | t = tunnel_get_by_local_id (c, tid); | ||
5333 | if (NULL == t) | ||
5334 | { | ||
5335 | GNUNET_break (0); | ||
5336 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Tunnel %X unknown.\n", tid); | ||
5337 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " for client %u.\n", c->id); | ||
5338 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5339 | return; | ||
5340 | } | ||
5341 | |||
5342 | /* Does client own tunnel? I.E: Is this an ACK for BCK traffic? */ | ||
5343 | if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | ||
5344 | { | ||
5345 | /* The client owns the tunnel, ACK is for data to_origin, send BCK ACK. */ | ||
5346 | t->prev_fc.last_ack_recv++; | ||
5347 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK, GNUNET_NO); | ||
5348 | } | ||
5349 | else | ||
5350 | { | ||
5351 | /* The client doesn't own the tunnel, this ACK is for FWD traffic. */ | ||
5352 | t->next_fc.last_ack_recv++; | ||
5353 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK, GNUNET_YES); | ||
5354 | } | ||
5355 | |||
5356 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
5357 | |||
5358 | return; | ||
5359 | } | ||
5360 | |||
5361 | |||
5362 | |||
5363 | /** | ||
5364 | * Iterator over all tunnels to send a monitoring client info about each tunnel. | ||
5365 | * | ||
5366 | * @param cls Closure (client handle). | ||
5367 | * @param key Key (hashed tunnel ID, unused). | ||
5368 | * @param value Tunnel info. | ||
5369 | * | ||
5370 | * @return GNUNET_YES, to keep iterating. | ||
5371 | */ | ||
5372 | static int | ||
5373 | monitor_all_tunnels_iterator (void *cls, | ||
5374 | const struct GNUNET_HashCode * key, | ||
5375 | void *value) | ||
5376 | { | ||
5377 | struct GNUNET_SERVER_Client *client = cls; | ||
5378 | struct MeshTunnel *t = value; | ||
5379 | struct GNUNET_MESH_LocalMonitor *msg; | ||
5380 | |||
5381 | msg = GNUNET_malloc (sizeof(struct GNUNET_MESH_LocalMonitor)); | ||
5382 | GNUNET_PEER_resolve(t->id.oid, &msg->owner); | ||
5383 | msg->tunnel_id = htonl (t->id.tid); | ||
5384 | msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor)); | ||
5385 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); | ||
5386 | GNUNET_PEER_resolve (t->dest, &msg->destination); | ||
5387 | |||
5388 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
5389 | "* sending info about tunnel %s [%u]\n", | ||
5390 | GNUNET_i2s (&msg->owner), t->id.tid); | ||
5391 | |||
5392 | GNUNET_SERVER_notification_context_unicast (nc, client, | ||
5393 | &msg->header, GNUNET_NO); | ||
5394 | return GNUNET_YES; | ||
5395 | } | ||
5396 | |||
5397 | |||
5398 | /** | ||
5399 | * Handler for client's MONITOR request. | ||
5400 | * | ||
5401 | * @param cls Closure (unused). | ||
5402 | * @param client Identification of the client. | ||
5403 | * @param message The actual message. | ||
5404 | */ | ||
5405 | static void | ||
5406 | handle_local_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client, | ||
5407 | const struct GNUNET_MessageHeader *message) | ||
5408 | { | ||
5409 | struct MeshClient *c; | ||
5410 | |||
5411 | /* Sanity check for client registration */ | ||
5412 | if (NULL == (c = client_get (client))) | ||
5413 | { | ||
5414 | GNUNET_break (0); | ||
5415 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5416 | return; | ||
5417 | } | ||
5418 | |||
5419 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
5420 | "Received get tunnels request from client %u\n", | ||
5421 | c->id); | ||
5422 | GNUNET_CONTAINER_multihashmap_iterate (tunnels, | ||
5423 | monitor_all_tunnels_iterator, | ||
5424 | client); | ||
5425 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
5426 | "Get tunnels request from client %u completed\n", | ||
5427 | c->id); | ||
5428 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
5429 | } | ||
5430 | |||
5431 | |||
5432 | /** | ||
5433 | * Handler for client's MONITOR_TUNNEL request. | ||
5434 | * | ||
5435 | * @param cls Closure (unused). | ||
5436 | * @param client Identification of the client. | ||
5437 | * @param message The actual message. | ||
5438 | */ | ||
5439 | static void | ||
5440 | handle_local_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, | ||
5441 | const struct GNUNET_MessageHeader *message) | ||
5442 | { | ||
5443 | const struct GNUNET_MESH_LocalMonitor *msg; | ||
5444 | struct GNUNET_MESH_LocalMonitor *resp; | ||
5445 | struct MeshClient *c; | ||
5446 | struct MeshTunnel *t; | ||
5447 | |||
5448 | /* Sanity check for client registration */ | ||
5449 | if (NULL == (c = client_get (client))) | ||
5450 | { | ||
5451 | GNUNET_break (0); | ||
5452 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5453 | return; | ||
5454 | } | ||
5455 | |||
5456 | msg = (struct GNUNET_MESH_LocalMonitor *) message; | ||
5457 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
5458 | "Received tunnel info request from client %u for tunnel %s[%X]\n", | ||
5459 | c->id, | ||
5460 | &msg->owner, | ||
5461 | ntohl (msg->tunnel_id)); | ||
5462 | t = tunnel_get (&msg->owner, ntohl (msg->tunnel_id)); | ||
5463 | if (NULL == t) | ||
5464 | { | ||
5465 | /* We don't know the tunnel FIXME */ | ||
5466 | struct GNUNET_MESH_LocalMonitor warn; | ||
5467 | |||
5468 | warn = *msg; | ||
5469 | GNUNET_SERVER_notification_context_unicast (nc, client, | ||
5470 | &warn.header, | ||
5471 | GNUNET_NO); | ||
5472 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
5473 | return; | ||
5474 | } | ||
5475 | |||
5476 | /* Initialize context */ | ||
5477 | resp = GNUNET_malloc (sizeof (struct GNUNET_MESH_LocalMonitor)); | ||
5478 | *resp = *msg; | ||
5479 | GNUNET_PEER_resolve (t->dest, &resp->destination); | ||
5480 | resp->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor)); | ||
5481 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, | ||
5482 | &resp->header, GNUNET_NO); | ||
5483 | GNUNET_free (resp); | ||
5484 | |||
5485 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
5486 | "Monitor tunnel request from client %u completed\n", | ||
5487 | c->id); | ||
5488 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
5489 | } | ||
5490 | |||
5491 | |||
5492 | /** | ||
5493 | * Functions to handle messages from clients | ||
5494 | */ | ||
5495 | static struct GNUNET_SERVER_MessageHandler client_handlers[] = { | ||
5496 | {&handle_local_new_client, NULL, | ||
5497 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, | ||
5498 | {&handle_local_tunnel_create, NULL, | ||
5499 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, | ||
5500 | sizeof (struct GNUNET_MESH_TunnelMessage)}, | ||
5501 | {&handle_local_tunnel_destroy, NULL, | ||
5502 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, | ||
5503 | sizeof (struct GNUNET_MESH_TunnelMessage)}, | ||
5504 | {&handle_local_data, NULL, | ||
5505 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, | ||
5506 | {&handle_local_ack, NULL, | ||
5507 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK, | ||
5508 | sizeof (struct GNUNET_MESH_LocalAck)}, | ||
5509 | {&handle_local_get_tunnels, NULL, | ||
5510 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS, | ||
5511 | sizeof (struct GNUNET_MessageHeader)}, | ||
5512 | {&handle_local_show_tunnel, NULL, | ||
5513 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL, | ||
5514 | sizeof (struct GNUNET_MESH_LocalMonitor)}, | ||
5515 | {NULL, NULL, 0, 0} | ||
5516 | }; | ||
5517 | |||
5518 | |||
5519 | /** | ||
5520 | * Method called whenever a given peer connects. | ||
5521 | * | ||
5522 | * @param cls closure | ||
5523 | * @param peer peer identity this notification is about | ||
5524 | */ | ||
5525 | static void | ||
5526 | core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
5527 | { | ||
5528 | struct MeshPeer *peer_info; | ||
5529 | struct MeshPeerPath *path; | ||
5530 | |||
5531 | DEBUG_CONN ("Peer connected\n"); | ||
5532 | DEBUG_CONN (" %s\n", GNUNET_i2s (&my_full_id)); | ||
5533 | peer_info = peer_get (peer); | ||
5534 | if (myid == peer_info->id) | ||
5535 | { | ||
5536 | DEBUG_CONN (" (self)\n"); | ||
5537 | path = path_new (1); | ||
5538 | } | ||
5539 | else | ||
5540 | { | ||
5541 | DEBUG_CONN (" %s\n", GNUNET_i2s (peer)); | ||
5542 | path = path_new (2); | ||
5543 | path->peers[1] = peer_info->id; | ||
5544 | GNUNET_PEER_change_rc (peer_info->id, 1); | ||
5545 | GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO); | ||
5546 | } | ||
5547 | path->peers[0] = myid; | ||
5548 | GNUNET_PEER_change_rc (myid, 1); | ||
5549 | peer_add_path (peer_info, path, GNUNET_YES); | ||
5550 | return; | ||
5551 | } | ||
5552 | |||
5553 | |||
5554 | /** | ||
5555 | * Method called whenever a peer disconnects. | ||
5556 | * | ||
5557 | * @param cls closure | ||
5558 | * @param peer peer identity this notification is about | ||
5559 | */ | ||
5560 | static void | ||
5561 | core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
5562 | { | ||
5563 | struct MeshPeer *pi; | ||
5564 | struct MeshPeerQueue *q; | ||
5565 | struct MeshPeerQueue *n; | ||
5566 | |||
5567 | DEBUG_CONN ("Peer disconnected\n"); | ||
5568 | pi = GNUNET_CONTAINER_multipeermap_get (peers, peer); | ||
5569 | if (NULL == pi) | ||
5570 | { | ||
5571 | GNUNET_break (0); | ||
5572 | return; | ||
5573 | } | ||
5574 | q = pi->queue_head; | ||
5575 | while (NULL != q) | ||
5576 | { | ||
5577 | n = q->next; | ||
5578 | /* TODO try to reroute this traffic instead */ | ||
5579 | queue_destroy(q, GNUNET_YES); | ||
5580 | q = n; | ||
5581 | } | ||
5582 | if (NULL != pi->core_transmit) | ||
5583 | { | ||
5584 | GNUNET_CORE_notify_transmit_ready_cancel(pi->core_transmit); | ||
5585 | pi->core_transmit = NULL; | ||
5586 | } | ||
5587 | peer_remove_path (pi, pi->id, myid); | ||
5588 | if (myid == pi->id) | ||
5589 | { | ||
5590 | DEBUG_CONN (" (self)\n"); | ||
5591 | } | ||
5592 | GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO); | ||
5593 | return; | ||
5594 | } | ||
5595 | |||
5596 | |||
5597 | /** | ||
5598 | * Install server (service) handlers and start listening to clients. | ||
5599 | */ | ||
5600 | static void | ||
5601 | server_init (void) | ||
5602 | { | ||
5603 | GNUNET_SERVER_add_handlers (server_handle, client_handlers); | ||
5604 | GNUNET_SERVER_connect_notify (server_handle, | ||
5605 | &handle_local_client_connect, NULL); | ||
5606 | GNUNET_SERVER_disconnect_notify (server_handle, | ||
5607 | &handle_local_client_disconnect, NULL); | ||
5608 | nc = GNUNET_SERVER_notification_context_create (server_handle, 1); | ||
5609 | |||
5610 | clients_head = NULL; | ||
5611 | clients_tail = NULL; | ||
5612 | next_client_id = 0; | ||
5613 | GNUNET_SERVER_resume (server_handle); | ||
5614 | } | ||
5615 | |||
5616 | |||
5617 | /** | ||
5618 | * To be called on core init/fail. | ||
5619 | * | ||
5620 | * @param cls Closure (config) | ||
5621 | * @param identity the public identity of this peer | ||
5622 | */ | ||
5623 | static void | ||
5624 | core_init (void *cls, | ||
5625 | const struct GNUNET_PeerIdentity *identity) | ||
5626 | { | ||
5627 | const struct GNUNET_CONFIGURATION_Handle *c = cls; | ||
5628 | static int i = 0; | ||
5629 | |||
5630 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n"); | ||
5631 | if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id))) | ||
5632 | { | ||
5633 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n")); | ||
5634 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5635 | " core id %s\n", | ||
5636 | GNUNET_i2s (identity)); | ||
5637 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5638 | " my id %s\n", | ||
5639 | GNUNET_i2s (&my_full_id)); | ||
5640 | GNUNET_CORE_disconnect (core_handle); | ||
5641 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | ||
5642 | NULL, /* Closure passed to MESH functions */ | ||
5643 | &core_init, /* Call core_init once connected */ | ||
5644 | &core_connect, /* Handle connects */ | ||
5645 | &core_disconnect, /* remove peers on disconnects */ | ||
5646 | NULL, /* Don't notify about all incoming messages */ | ||
5647 | GNUNET_NO, /* For header only in notification */ | ||
5648 | NULL, /* Don't notify about all outbound messages */ | ||
5649 | GNUNET_NO, /* For header-only out notification */ | ||
5650 | core_handlers); /* Register these handlers */ | ||
5651 | if (10 < i++) | ||
5652 | GNUNET_abort(); | ||
5653 | } | ||
5654 | server_init (); | ||
5655 | return; | ||
5656 | } | ||
5657 | |||
5658 | 85 | ||
5659 | /******************************************************************************/ | 86 | /******************************************************************************/ |
5660 | /************************ MAIN FUNCTIONS ****************************/ | 87 | /************************ MAIN FUNCTIONS ****************************/ |
5661 | /******************************************************************************/ | 88 | /******************************************************************************/ |
5662 | 89 | ||
5663 | /** | 90 | /** |
5664 | * Iterator over tunnel hash map entries to destroy the tunnel during shutdown. | ||
5665 | * | ||
5666 | * @param cls closure | ||
5667 | * @param key current key code | ||
5668 | * @param value value in the hash map | ||
5669 | * @return GNUNET_YES if we should continue to iterate, | ||
5670 | * GNUNET_NO if not. | ||
5671 | */ | ||
5672 | static int | ||
5673 | shutdown_tunnel (void *cls, const struct GNUNET_HashCode * key, void *value) | ||
5674 | { | ||
5675 | struct MeshTunnel *t = value; | ||
5676 | |||
5677 | tunnel_destroy (t); | ||
5678 | return GNUNET_YES; | ||
5679 | } | ||
5680 | |||
5681 | /** | ||
5682 | * Iterator over peer hash map entries to destroy the tunnel during shutdown. | ||
5683 | * | ||
5684 | * @param cls closure | ||
5685 | * @param key current key code | ||
5686 | * @param value value in the hash map | ||
5687 | * @return GNUNET_YES if we should continue to iterate, | ||
5688 | * GNUNET_NO if not. | ||
5689 | */ | ||
5690 | static int | ||
5691 | shutdown_peer (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | ||
5692 | { | ||
5693 | struct MeshPeer *p = value; | ||
5694 | struct MeshPeerQueue *q; | ||
5695 | struct MeshPeerQueue *n; | ||
5696 | |||
5697 | q = p->queue_head; | ||
5698 | while (NULL != q) | ||
5699 | { | ||
5700 | n = q->next; | ||
5701 | if (q->peer == p) | ||
5702 | { | ||
5703 | queue_destroy(q, GNUNET_YES); | ||
5704 | } | ||
5705 | q = n; | ||
5706 | } | ||
5707 | peer_destroy (p); | ||
5708 | return GNUNET_YES; | ||
5709 | } | ||
5710 | |||
5711 | |||
5712 | /** | ||
5713 | * Task run during shutdown. | 91 | * Task run during shutdown. |
5714 | * | 92 | * |
5715 | * @param cls unused | 93 | * @param cls unused |
@@ -5720,28 +98,12 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
5720 | { | 98 | { |
5721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); | 99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); |
5722 | 100 | ||
5723 | if (core_handle != NULL) | 101 | GML_shutdown (); |
5724 | { | 102 | GMD_shutdown (); |
5725 | GNUNET_CORE_disconnect (core_handle); | 103 | GMP_shutdown (); |
5726 | core_handle = NULL; | 104 | GMC_shutdown (); |
5727 | } | 105 | GMT_shutdown (); |
5728 | GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL); | 106 | |
5729 | GNUNET_CONTAINER_multipeermap_iterate (peers, &shutdown_peer, NULL); | ||
5730 | if (dht_handle != NULL) | ||
5731 | { | ||
5732 | GNUNET_DHT_disconnect (dht_handle); | ||
5733 | dht_handle = NULL; | ||
5734 | } | ||
5735 | if (nc != NULL) | ||
5736 | { | ||
5737 | GNUNET_SERVER_notification_context_destroy (nc); | ||
5738 | nc = NULL; | ||
5739 | } | ||
5740 | if (GNUNET_SCHEDULER_NO_TASK != announce_id_task) | ||
5741 | { | ||
5742 | GNUNET_SCHEDULER_cancel (announce_id_task); | ||
5743 | announce_id_task = GNUNET_SCHEDULER_NO_TASK; | ||
5744 | } | ||
5745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n"); | 107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n"); |
5746 | } | 108 | } |
5747 | 109 | ||
@@ -5757,176 +119,28 @@ static void | |||
5757 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 119 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
5758 | const struct GNUNET_CONFIGURATION_Handle *c) | 120 | const struct GNUNET_CONFIGURATION_Handle *c) |
5759 | { | 121 | { |
5760 | char *keyfile; | ||
5761 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | ||
5762 | |||
5763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n"); | 122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n"); |
5764 | server_handle = server; | ||
5765 | GNUNET_SERVER_suspend (server_handle); | ||
5766 | |||
5767 | if (GNUNET_OK != | ||
5768 | GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", | ||
5769 | &keyfile)) | ||
5770 | { | ||
5771 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5772 | _ | ||
5773 | ("%s service is lacking key configuration settings (%s). Exiting.\n"), | ||
5774 | "mesh", "peer/privatekey"); | ||
5775 | GNUNET_SCHEDULER_shutdown (); | ||
5776 | return; | ||
5777 | } | ||
5778 | |||
5779 | if (GNUNET_OK != | ||
5780 | GNUNET_CONFIGURATION_get_value_time (c, "MESH", "REFRESH_PATH_TIME", | ||
5781 | &refresh_path_time)) | ||
5782 | { | ||
5783 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5784 | _ | ||
5785 | ("%s service is lacking key configuration settings (%s). Exiting.\n"), | ||
5786 | "mesh", "refresh path time"); | ||
5787 | GNUNET_SCHEDULER_shutdown (); | ||
5788 | return; | ||
5789 | } | ||
5790 | |||
5791 | if (GNUNET_OK != | ||
5792 | GNUNET_CONFIGURATION_get_value_time (c, "MESH", "ID_ANNOUNCE_TIME", | ||
5793 | &id_announce_time)) | ||
5794 | { | ||
5795 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5796 | _ | ||
5797 | ("%s service is lacking key configuration settings (%s). Exiting.\n"), | ||
5798 | "mesh", "id announce time"); | ||
5799 | GNUNET_SCHEDULER_shutdown (); | ||
5800 | return; | ||
5801 | } | ||
5802 | |||
5803 | if (GNUNET_OK != | ||
5804 | GNUNET_CONFIGURATION_get_value_time (c, "MESH", "CONNECT_TIMEOUT", | ||
5805 | &connect_timeout)) | ||
5806 | { | ||
5807 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5808 | _ | ||
5809 | ("%s service is lacking key configuration settings (%s). Exiting.\n"), | ||
5810 | "mesh", "connect timeout"); | ||
5811 | GNUNET_SCHEDULER_shutdown (); | ||
5812 | return; | ||
5813 | } | ||
5814 | 123 | ||
5815 | if (GNUNET_OK != | ||
5816 | GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_MSGS_QUEUE", | ||
5817 | &max_msgs_queue)) | ||
5818 | { | ||
5819 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5820 | _ | ||
5821 | ("%s service is lacking key configuration settings (%s). Exiting.\n"), | ||
5822 | "mesh", "max msgs queue"); | ||
5823 | GNUNET_SCHEDULER_shutdown (); | ||
5824 | return; | ||
5825 | } | ||
5826 | |||
5827 | if (GNUNET_OK != | ||
5828 | GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_TUNNELS", | ||
5829 | &max_tunnels)) | ||
5830 | { | ||
5831 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5832 | _ | ||
5833 | ("%s service is lacking key configuration settings (%s). Exiting.\n"), | ||
5834 | "mesh", "max tunnels"); | ||
5835 | GNUNET_SCHEDULER_shutdown (); | ||
5836 | return; | ||
5837 | } | ||
5838 | |||
5839 | if (GNUNET_OK != | ||
5840 | GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DEFAULT_TTL", | ||
5841 | &default_ttl)) | ||
5842 | { | ||
5843 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
5844 | _ | ||
5845 | ("%s service is lacking key configuration settings (%s). Using default (%u).\n"), | ||
5846 | "mesh", "default ttl", 64); | ||
5847 | default_ttl = 64; | ||
5848 | } | ||
5849 | |||
5850 | if (GNUNET_OK != | ||
5851 | GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_PEERS", | ||
5852 | &max_peers)) | ||
5853 | { | ||
5854 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
5855 | _("%s service is lacking key configuration settings (%s). Using default (%u).\n"), | ||
5856 | "mesh", "max peers", 1000); | ||
5857 | max_peers = 1000; | ||
5858 | } | ||
5859 | |||
5860 | if (GNUNET_OK != | ||
5861 | GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DROP_PERCENT", | ||
5862 | &drop_percent)) | ||
5863 | { | ||
5864 | drop_percent = 0; | ||
5865 | } | ||
5866 | else | ||
5867 | { | ||
5868 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
5869 | "Mesh is running with drop mode enabled. " | ||
5870 | "This is NOT a good idea! " | ||
5871 | "Remove the DROP_PERCENT option from your configuration.\n"); | ||
5872 | } | ||
5873 | |||
5874 | if (GNUNET_OK != | ||
5875 | GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DHT_REPLICATION_LEVEL", | ||
5876 | &dht_replication_level)) | ||
5877 | { | ||
5878 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
5879 | _ | ||
5880 | ("%s service is lacking key configuration settings (%s). Using default (%u).\n"), | ||
5881 | "mesh", "dht replication level", 3); | ||
5882 | dht_replication_level = 3; | ||
5883 | } | ||
5884 | |||
5885 | tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); | ||
5886 | incoming_tunnels = GNUNET_CONTAINER_multihashmap32_create (32); | ||
5887 | peers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_NO); | ||
5888 | ports = GNUNET_CONTAINER_multihashmap32_create (32); | ||
5889 | |||
5890 | dht_handle = GNUNET_DHT_connect (c, 64); | ||
5891 | if (NULL == dht_handle) | ||
5892 | { | ||
5893 | GNUNET_break (0); | ||
5894 | } | ||
5895 | stats = GNUNET_STATISTICS_create ("mesh", c); | 124 | stats = GNUNET_STATISTICS_create ("mesh", c); |
5896 | 125 | ||
5897 | /* Scheduled the task to clean up when shutdown is called */ | 126 | /* Scheduled the task to clean up when shutdown is called */ |
5898 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 127 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
5899 | NULL); | 128 | NULL); |
5900 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 129 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n"); |
5901 | GNUNET_free (keyfile); | 130 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c); |
5902 | GNUNET_assert (NULL != pk); | 131 | GNUNET_assert (NULL != my_private_key); |
5903 | my_private_key = pk; | 132 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_full_id.public_key); |
5904 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, | ||
5905 | &my_full_id.public_key); | ||
5906 | myid = GNUNET_PEER_intern (&my_full_id); | 133 | myid = GNUNET_PEER_intern (&my_full_id); |
5907 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 134 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
5908 | "Mesh for peer [%s] starting\n", | 135 | "Mesh for peer [%s] starting\n", |
5909 | GNUNET_i2s(&my_full_id)); | 136 | GNUNET_i2s (&my_full_id)); |
137 | |||
138 | GML_init (server); /* Local clients */ | ||
139 | GMC_init (c); /* Connections */ | ||
140 | GMP_init (c); /* Peers */ | ||
141 | GMD_init (c); /* DHT */ | ||
142 | GMT_init (c, my_private_key); /* Tunnels */ | ||
5910 | 143 | ||
5911 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | ||
5912 | NULL, /* Closure passed to MESH functions */ | ||
5913 | &core_init, /* Call core_init once connected */ | ||
5914 | &core_connect, /* Handle connects */ | ||
5915 | &core_disconnect, /* remove peers on disconnects */ | ||
5916 | NULL, /* Don't notify about all incoming messages */ | ||
5917 | GNUNET_NO, /* For header only in notification */ | ||
5918 | NULL, /* Don't notify about all outbound messages */ | ||
5919 | GNUNET_NO, /* For header-only out notification */ | ||
5920 | core_handlers); /* Register these handlers */ | ||
5921 | if (NULL == core_handle) | ||
5922 | { | ||
5923 | GNUNET_break (0); | ||
5924 | GNUNET_SCHEDULER_shutdown (); | ||
5925 | return; | ||
5926 | } | ||
5927 | next_tid = 0; | ||
5928 | next_local_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | ||
5929 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); | ||
5930 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh service running\n"); | 144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh service running\n"); |
5931 | } | 145 | } |
5932 | 146 | ||
@@ -5944,13 +158,12 @@ main (int argc, char *const *argv) | |||
5944 | int ret; | 158 | int ret; |
5945 | int r; | 159 | int r; |
5946 | 160 | ||
5947 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n"); | 161 | fprintf (stderr, "main()\n"); |
5948 | r = GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run, | 162 | r = GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run, |
5949 | NULL); | 163 | NULL); |
164 | GNUNET_free (my_private_key); | ||
5950 | ret = (GNUNET_OK == r) ? 0 : 1; | 165 | ret = (GNUNET_OK == r) ? 0 : 1; |
5951 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n"); | 166 | fprintf (stderr, "main() END\n"); |
5952 | |||
5953 | INTERVAL_SHOW; | ||
5954 | 167 | ||
5955 | return ret; | 168 | return ret; |
5956 | } | 169 | } |
diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index 05cdeaa2e..ac3c8bf3f 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c | |||
@@ -24,8 +24,8 @@ | |||
24 | 24 | ||
25 | #include "gnunet_statistics_service.h" | 25 | #include "gnunet_statistics_service.h" |
26 | 26 | ||
27 | #include "mesh_enc.h" | 27 | #include "mesh.h" |
28 | #include "mesh_protocol_enc.h" | 28 | #include "mesh_protocol.h" |
29 | 29 | ||
30 | #include "gnunet-service-mesh_channel.h" | 30 | #include "gnunet-service-mesh_channel.h" |
31 | #include "gnunet-service-mesh_local.h" | 31 | #include "gnunet-service-mesh_local.h" |
diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h index e718b315c..c6e051356 100644 --- a/src/mesh/gnunet-service-mesh_channel.h +++ b/src/mesh/gnunet-service-mesh_channel.h | |||
@@ -40,8 +40,8 @@ extern "C" | |||
40 | #include "platform.h" | 40 | #include "platform.h" |
41 | #include "gnunet_util_lib.h" | 41 | #include "gnunet_util_lib.h" |
42 | 42 | ||
43 | #include "mesh_protocol_enc.h" | 43 | #include "mesh_protocol.h" |
44 | #include "mesh_enc.h" | 44 | #include "mesh.h" |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Struct containing all information regarding a channel to a remote client. | 47 | * Struct containing all information regarding a channel to a remote client. |
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index b2c310c93..2787b6a03 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c | |||
@@ -30,8 +30,8 @@ | |||
30 | #include "gnunet_statistics_service.h" | 30 | #include "gnunet_statistics_service.h" |
31 | 31 | ||
32 | #include "mesh_path.h" | 32 | #include "mesh_path.h" |
33 | #include "mesh_protocol_enc.h" | 33 | #include "mesh_protocol.h" |
34 | #include "mesh_enc.h" | 34 | #include "mesh.h" |
35 | #include "gnunet-service-mesh_connection.h" | 35 | #include "gnunet-service-mesh_connection.h" |
36 | #include "gnunet-service-mesh_peer.h" | 36 | #include "gnunet-service-mesh_peer.h" |
37 | #include "gnunet-service-mesh_tunnel.h" | 37 | #include "gnunet-service-mesh_tunnel.h" |
diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index 9430fbefa..2849a75b7 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c | |||
@@ -24,8 +24,8 @@ | |||
24 | 24 | ||
25 | #include "gnunet_statistics_service.h" | 25 | #include "gnunet_statistics_service.h" |
26 | 26 | ||
27 | #include "mesh_enc.h" | 27 | #include "mesh.h" |
28 | #include "mesh_protocol_enc.h" // GNUNET_MESH_Data is shared | 28 | #include "mesh_protocol.h" /* GNUNET_MESH_Data is shared */ |
29 | 29 | ||
30 | #include "gnunet-service-mesh_local.h" | 30 | #include "gnunet-service-mesh_local.h" |
31 | 31 | ||
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index c1dac276f..0d0480c32 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include "gnunet_core_service.h" | 25 | #include "gnunet_core_service.h" |
26 | #include "gnunet_statistics_service.h" | 26 | #include "gnunet_statistics_service.h" |
27 | 27 | ||
28 | #include "mesh_protocol_enc.h" | 28 | #include "mesh_protocol.h" |
29 | 29 | ||
30 | #include "gnunet-service-mesh_peer.h" | 30 | #include "gnunet-service-mesh_peer.h" |
31 | #include "gnunet-service-mesh_dht.h" | 31 | #include "gnunet-service-mesh_dht.h" |
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index d745e6da1..80a446ea3 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "gnunet_signatures.h" | 24 | #include "gnunet_signatures.h" |
25 | #include "gnunet_statistics_service.h" | 25 | #include "gnunet_statistics_service.h" |
26 | 26 | ||
27 | #include "mesh_protocol_enc.h" | 27 | #include "mesh_protocol.h" |
28 | #include "mesh_path.h" | 28 | #include "mesh_path.h" |
29 | 29 | ||
30 | #include "gnunet-service-mesh_tunnel.h" | 30 | #include "gnunet-service-mesh_tunnel.h" |
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index dc515b473..f3abef8ca 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h | |||
@@ -39,49 +39,19 @@ extern "C" | |||
39 | #define MESH_DEBUG GNUNET_YES | 39 | #define MESH_DEBUG GNUNET_YES |
40 | 40 | ||
41 | #include "platform.h" | 41 | #include "platform.h" |
42 | #include "gnunet_common.h" | ||
42 | #include "gnunet_util_lib.h" | 43 | #include "gnunet_util_lib.h" |
44 | #include "gnunet_peer_lib.h" | ||
43 | #include "gnunet_core_service.h" | 45 | #include "gnunet_core_service.h" |
44 | #include "gnunet_protocols.h" | 46 | #include "gnunet_protocols.h" |
45 | #include <gnunet_mesh_service.h> | 47 | #include <gnunet_mesh_service.h> |
46 | 48 | ||
47 | /******************************************************************************/ | 49 | /******************************************************************************/ |
48 | /******************** MESH LOCAL MESSAGES *************************/ | ||
49 | /******************************************************************************/ | ||
50 | /* Any API call should be documented in the folowing table under API CALL. | ||
51 | * Also, any message type should be documented in the following table, with the | ||
52 | * associated event. | ||
53 | * | ||
54 | * API CALL (GNUNET_MESH_*) MESSAGE USED | ||
55 | * ------------------------ ------------ | ||
56 | * connect GNUNET_MESH_ClientConnect | ||
57 | * disconnect None (network level disconnect) | ||
58 | * | ||
59 | * tunnel_create GNUNET_MESH_TunnelMessage | ||
60 | * tunnel_destroy GNUNET_MESH_TunnelMessage | ||
61 | * tunnel_buffer GNUNET_MESH_TunnelMessage | ||
62 | * | ||
63 | * notify_transmit_ready None (queue / GNUNET_CLIENT_ntf_tmt_rdy) | ||
64 | * notify_transmit_ready_cancel None (clear of internal data structures) | ||
65 | * | ||
66 | * | ||
67 | * EVENT MESSAGE USED | ||
68 | * ----- ------------ | ||
69 | * data GNUNET_MESH_Unicast OR | ||
70 | * GNUNET_MESH_Multicast OR | ||
71 | * GNUNET_MESH_ToOrigin | ||
72 | * data ack GNUNET_MESH_LocalAck | ||
73 | * | ||
74 | * new incoming tunnel GNUNET_MESH_PeerControl | ||
75 | * peer connects to a tunnel FIXME | ||
76 | * peer disconnects from a tunnel FIXME | ||
77 | */ | ||
78 | |||
79 | /******************************************************************************/ | ||
80 | /************************** CONSTANTS ******************************/ | 50 | /************************** CONSTANTS ******************************/ |
81 | /******************************************************************************/ | 51 | /******************************************************************************/ |
82 | 52 | ||
83 | #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000 | 53 | #define GNUNET_MESH_LOCAL_CHANNEL_ID_CLI 0x80000000 |
84 | #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000 | 54 | #define GNUNET_MESH_LOCAL_CHANNEL_ID_SERV 0xB0000000 |
85 | 55 | ||
86 | #define HIGH_PID 0xFFFF0000 | 56 | #define HIGH_PID 0xFFFF0000 |
87 | #define LOW_PID 0x0000FFFF | 57 | #define LOW_PID 0x0000FFFF |
@@ -112,38 +82,38 @@ struct GNUNET_MESH_ClientConnect | |||
112 | 82 | ||
113 | 83 | ||
114 | /** | 84 | /** |
115 | * Type for tunnel numbering. | 85 | * Type for channel numbering. |
116 | * - Local tunnel numbers given by the service (incoming) are >= 0xB0000000 | 86 | * - Local channel numbers given by the service (incoming) are >= 0xB0000000 |
117 | * - Local tunnel numbers given by the client (created) are >= 0x80000000 | 87 | * - Local channel numbers given by the client (created) are >= 0x80000000 |
118 | * - Global tunnel numbers are < 0x80000000 | 88 | * - Global channel numbers are < 0x80000000 |
119 | */ | 89 | */ |
120 | typedef uint32_t MESH_TunnelNumber; | 90 | typedef uint32_t MESH_ChannelNumber; |
121 | 91 | ||
122 | 92 | ||
123 | /** | 93 | /** |
124 | * Message for a client to create and destroy tunnels. | 94 | * Message for a client to create and destroy channels. |
125 | */ | 95 | */ |
126 | struct GNUNET_MESH_TunnelMessage | 96 | struct GNUNET_MESH_ChannelMessage |
127 | { | 97 | { |
128 | /** | 98 | /** |
129 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY] | 99 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY] |
130 | * | 100 | * |
131 | * Size: sizeof(struct GNUNET_MESH_TunnelMessage) | 101 | * Size: sizeof(struct GNUNET_MESH_ChannelMessage) |
132 | */ | 102 | */ |
133 | struct GNUNET_MessageHeader header; | 103 | struct GNUNET_MessageHeader header; |
134 | 104 | ||
135 | /** | 105 | /** |
136 | * ID of a tunnel controlled by this client. | 106 | * ID of a channel controlled by this client. |
137 | */ | 107 | */ |
138 | MESH_TunnelNumber tunnel_id GNUNET_PACKED; | 108 | MESH_ChannelNumber channel_id GNUNET_PACKED; |
139 | 109 | ||
140 | /** | 110 | /** |
141 | * Tunnel's peer | 111 | * Channel's peer |
142 | */ | 112 | */ |
143 | struct GNUNET_PeerIdentity peer; | 113 | struct GNUNET_PeerIdentity peer; |
144 | 114 | ||
145 | /** | 115 | /** |
146 | * Port of the tunnel. | 116 | * Port of the channel. |
147 | */ | 117 | */ |
148 | uint32_t port GNUNET_PACKED; | 118 | uint32_t port GNUNET_PACKED; |
149 | 119 | ||
@@ -165,9 +135,9 @@ struct GNUNET_MESH_LocalData | |||
165 | struct GNUNET_MessageHeader header; | 135 | struct GNUNET_MessageHeader header; |
166 | 136 | ||
167 | /** | 137 | /** |
168 | * TID of the tunnel | 138 | * ID of the channel |
169 | */ | 139 | */ |
170 | uint32_t tid GNUNET_PACKED; | 140 | uint32_t id GNUNET_PACKED; |
171 | 141 | ||
172 | /** | 142 | /** |
173 | * Payload follows | 143 | * Payload follows |
@@ -187,15 +157,15 @@ struct GNUNET_MESH_LocalAck | |||
187 | struct GNUNET_MessageHeader header; | 157 | struct GNUNET_MessageHeader header; |
188 | 158 | ||
189 | /** | 159 | /** |
190 | * ID of the tunnel allowed to send more data. | 160 | * ID of the channel allowed to send more data. |
191 | */ | 161 | */ |
192 | MESH_TunnelNumber tunnel_id GNUNET_PACKED; | 162 | MESH_ChannelNumber channel_id GNUNET_PACKED; |
193 | 163 | ||
194 | }; | 164 | }; |
195 | 165 | ||
196 | 166 | ||
197 | /** | 167 | /** |
198 | * Message to inform the client about tunnels in the service. | 168 | * Message to inform the client about channels in the service. |
199 | */ | 169 | */ |
200 | struct GNUNET_MESH_LocalMonitor | 170 | struct GNUNET_MESH_LocalMonitor |
201 | { | 171 | { |
@@ -205,9 +175,9 @@ struct GNUNET_MESH_LocalMonitor | |||
205 | struct GNUNET_MessageHeader header; | 175 | struct GNUNET_MessageHeader header; |
206 | 176 | ||
207 | /** | 177 | /** |
208 | * ID of the tunnel allowed to send more data. | 178 | * ID of the channel allowed to send more data. |
209 | */ | 179 | */ |
210 | MESH_TunnelNumber tunnel_id GNUNET_PACKED; | 180 | MESH_ChannelNumber channel_id GNUNET_PACKED; |
211 | 181 | ||
212 | /** | 182 | /** |
213 | * Alignment. | 183 | * Alignment. |
@@ -215,12 +185,12 @@ struct GNUNET_MESH_LocalMonitor | |||
215 | uint32_t reserved GNUNET_PACKED; | 185 | uint32_t reserved GNUNET_PACKED; |
216 | 186 | ||
217 | /** | 187 | /** |
218 | * ID of the owner of the tunnel (can be local peer). | 188 | * ID of the owner of the channel (can be local peer). |
219 | */ | 189 | */ |
220 | struct GNUNET_PeerIdentity owner; | 190 | struct GNUNET_PeerIdentity owner; |
221 | 191 | ||
222 | /** | 192 | /** |
223 | * ID of the destination of the tunnel (can be local peer). | 193 | * ID of the destination of the channel (can be local peer). |
224 | */ | 194 | */ |
225 | struct GNUNET_PeerIdentity destination; | 195 | struct GNUNET_PeerIdentity destination; |
226 | }; | 196 | }; |
@@ -228,40 +198,6 @@ struct GNUNET_MESH_LocalMonitor | |||
228 | 198 | ||
229 | GNUNET_NETWORK_STRUCT_END | 199 | GNUNET_NETWORK_STRUCT_END |
230 | 200 | ||
231 | /******************************************************************************/ | ||
232 | /************************ ENUMERATIONS ****************************/ | ||
233 | /******************************************************************************/ | ||
234 | |||
235 | /** | ||
236 | * All the states a tunnel can be in. | ||
237 | */ | ||
238 | enum MeshTunnelState | ||
239 | { | ||
240 | /** | ||
241 | * Uninitialized status, should never appear in operation. | ||
242 | */ | ||
243 | MESH_TUNNEL_NEW, | ||
244 | |||
245 | /** | ||
246 | * Path to the peer not known yet | ||
247 | */ | ||
248 | MESH_TUNNEL_SEARCHING, | ||
249 | |||
250 | /** | ||
251 | * Request sent, not yet answered. | ||
252 | */ | ||
253 | MESH_TUNNEL_WAITING, | ||
254 | |||
255 | /** | ||
256 | * Peer connected and ready to accept data | ||
257 | */ | ||
258 | MESH_TUNNEL_READY, | ||
259 | |||
260 | /** | ||
261 | * Peer connected previosly but not responding | ||
262 | */ | ||
263 | MESH_TUNNEL_RECONNECTING | ||
264 | }; | ||
265 | 201 | ||
266 | 202 | ||
267 | /** | 203 | /** |
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 2db89fc6e..a9f463932 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c | |||
@@ -16,20 +16,11 @@ | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * @file mesh/mesh_api.c | 19 | * @file mesh/mesh_api_enc.c |
20 | * @brief mesh api: client implementation of new mesh service | 20 | * @brief mesh api: client implementation of new mesh service |
21 | * @author Bartlomiej Polot | 21 | * @author Bartlomiej Polot |
22 | * | ||
23 | * STRUCTURE: | ||
24 | * - DATA STRUCTURES | ||
25 | * - DECLARATIONS | ||
26 | * - AUXILIARY FUNCTIONS | ||
27 | * - RECEIVE HANDLERS | ||
28 | * - SEND FUNCTIONS | ||
29 | * - API CALL DEFINITIONS | ||
30 | * | ||
31 | * TODO: add regex to reconnect | ||
32 | */ | 22 | */ |
23 | |||
33 | #include "platform.h" | 24 | #include "platform.h" |
34 | #include "gnunet_util_lib.h" | 25 | #include "gnunet_util_lib.h" |
35 | #include "gnunet_mesh_service.h" | 26 | #include "gnunet_mesh_service.h" |
@@ -37,7 +28,6 @@ | |||
37 | #include "mesh_protocol.h" | 28 | #include "mesh_protocol.h" |
38 | 29 | ||
39 | #define LOG(kind,...) GNUNET_log_from (kind, "mesh-api",__VA_ARGS__) | 30 | #define LOG(kind,...) GNUNET_log_from (kind, "mesh-api",__VA_ARGS__) |
40 | #define DEBUG_ACK GNUNET_YES | ||
41 | 31 | ||
42 | /******************************************************************************/ | 32 | /******************************************************************************/ |
43 | /************************ DATA STRUCTURES ****************************/ | 33 | /************************ DATA STRUCTURES ****************************/ |
@@ -60,9 +50,9 @@ struct GNUNET_MESH_TransmitHandle | |||
60 | struct GNUNET_MESH_TransmitHandle *prev; | 50 | struct GNUNET_MESH_TransmitHandle *prev; |
61 | 51 | ||
62 | /** | 52 | /** |
63 | * Tunnel this message is sent on / for (may be NULL for control messages). | 53 | * Channel this message is sent on / for (may be NULL for control messages). |
64 | */ | 54 | */ |
65 | struct GNUNET_MESH_Tunnel *tunnel; | 55 | struct GNUNET_MESH_Channel *channel; |
66 | 56 | ||
67 | /** | 57 | /** |
68 | * Callback to obtain the message to transmit, or NULL if we | 58 | * Callback to obtain the message to transmit, or NULL if we |
@@ -109,7 +99,7 @@ struct GNUNET_MESH_Handle | |||
109 | struct GNUNET_CLIENT_Connection *client; | 99 | struct GNUNET_CLIENT_Connection *client; |
110 | 100 | ||
111 | /** | 101 | /** |
112 | * Set of handlers used for processing incoming messages in the tunnels | 102 | * Set of handlers used for processing incoming messages in the channels |
113 | */ | 103 | */ |
114 | const struct GNUNET_MESH_MessageHandler *message_handlers; | 104 | const struct GNUNET_MESH_MessageHandler *message_handlers; |
115 | 105 | ||
@@ -129,24 +119,24 @@ struct GNUNET_MESH_Handle | |||
129 | unsigned int n_ports; | 119 | unsigned int n_ports; |
130 | 120 | ||
131 | /** | 121 | /** |
132 | * Double linked list of the tunnels this client is connected to, head. | 122 | * Double linked list of the channels this client is connected to, head. |
133 | */ | 123 | */ |
134 | struct GNUNET_MESH_Tunnel *tunnels_head; | 124 | struct GNUNET_MESH_Channel *channels_head; |
135 | 125 | ||
136 | /** | 126 | /** |
137 | * Double linked list of the tunnels this client is connected to, tail. | 127 | * Double linked list of the channels this client is connected to, tail. |
138 | */ | 128 | */ |
139 | struct GNUNET_MESH_Tunnel *tunnels_tail; | 129 | struct GNUNET_MESH_Channel *channels_tail; |
140 | 130 | ||
141 | /** | 131 | /** |
142 | * Callback for inbound tunnel creation | 132 | * Callback for inbound channel creation |
143 | */ | 133 | */ |
144 | GNUNET_MESH_InboundTunnelNotificationHandler *new_tunnel; | 134 | GNUNET_MESH_InboundChannelNotificationHandler *new_channel; |
145 | 135 | ||
146 | /** | 136 | /** |
147 | * Callback for inbound tunnel disconnection | 137 | * Callback for inbound channel disconnection |
148 | */ | 138 | */ |
149 | GNUNET_MESH_TunnelEndHandler *cleaner; | 139 | GNUNET_MESH_ChannelEndHandler *cleaner; |
150 | 140 | ||
151 | /** | 141 | /** |
152 | * Handle to cancel pending transmissions in case of disconnection | 142 | * Handle to cancel pending transmissions in case of disconnection |
@@ -169,9 +159,9 @@ struct GNUNET_MESH_Handle | |||
169 | struct GNUNET_MESH_TransmitHandle *th_tail; | 159 | struct GNUNET_MESH_TransmitHandle *th_tail; |
170 | 160 | ||
171 | /** | 161 | /** |
172 | * tid of the next tunnel to create (to avoid reusing IDs often) | 162 | * chid of the next channel to create (to avoid reusing IDs often) |
173 | */ | 163 | */ |
174 | MESH_TunnelNumber next_tid; | 164 | MESH_ChannelNumber next_chid; |
175 | 165 | ||
176 | /** | 166 | /** |
177 | * Have we started the task to receive messages from the service | 167 | * Have we started the task to receive messages from the service |
@@ -197,27 +187,22 @@ struct GNUNET_MESH_Handle | |||
197 | /** | 187 | /** |
198 | * Monitor callback | 188 | * Monitor callback |
199 | */ | 189 | */ |
200 | GNUNET_MESH_TunnelsCB tunnels_cb; | 190 | GNUNET_MESH_ChannelsCB channels_cb; |
201 | 191 | ||
202 | /** | 192 | /** |
203 | * Monitor callback closure. | 193 | * Monitor callback closure. |
204 | */ | 194 | */ |
205 | void *tunnels_cls; | 195 | void *channels_cls; |
206 | 196 | ||
207 | /** | 197 | /** |
208 | * Tunnel callback. | 198 | * Channel callback. |
209 | */ | 199 | */ |
210 | GNUNET_MESH_TunnelCB tunnel_cb; | 200 | GNUNET_MESH_ChannelCB channel_cb; |
211 | 201 | ||
212 | /** | 202 | /** |
213 | * Tunnel callback closure. | 203 | * Channel callback closure. |
214 | */ | 204 | */ |
215 | void *tunnel_cls; | 205 | void *channel_cls; |
216 | |||
217 | #if DEBUG_ACK | ||
218 | unsigned int acks_sent; | ||
219 | unsigned int acks_recv; | ||
220 | #endif | ||
221 | }; | 206 | }; |
222 | 207 | ||
223 | 208 | ||
@@ -226,15 +211,15 @@ struct GNUNET_MESH_Handle | |||
226 | */ | 211 | */ |
227 | struct GNUNET_MESH_Peer | 212 | struct GNUNET_MESH_Peer |
228 | { | 213 | { |
229 | /** | 214 | /** |
230 | * ID of the peer in short form | 215 | * ID of the peer in short form |
231 | */ | 216 | */ |
232 | GNUNET_PEER_Id id; | 217 | GNUNET_PEER_Id id; |
233 | 218 | ||
234 | /** | 219 | /** |
235 | * Tunnel this peer belongs to | 220 | * Channel this peer belongs to |
236 | */ | 221 | */ |
237 | struct GNUNET_MESH_Tunnel *t; | 222 | struct GNUNET_MESH_Channel *t; |
238 | 223 | ||
239 | /** | 224 | /** |
240 | * Flag indicating whether service has informed about its connection | 225 | * Flag indicating whether service has informed about its connection |
@@ -246,30 +231,30 @@ struct GNUNET_MESH_Peer | |||
246 | 231 | ||
247 | 232 | ||
248 | /** | 233 | /** |
249 | * Opaque handle to a tunnel. | 234 | * Opaque handle to a channel. |
250 | */ | 235 | */ |
251 | struct GNUNET_MESH_Tunnel | 236 | struct GNUNET_MESH_Channel |
252 | { | 237 | { |
253 | 238 | ||
254 | /** | 239 | /** |
255 | * DLL next | 240 | * DLL next |
256 | */ | 241 | */ |
257 | struct GNUNET_MESH_Tunnel *next; | 242 | struct GNUNET_MESH_Channel *next; |
258 | 243 | ||
259 | /** | 244 | /** |
260 | * DLL prev | 245 | * DLL prev |
261 | */ | 246 | */ |
262 | struct GNUNET_MESH_Tunnel *prev; | 247 | struct GNUNET_MESH_Channel *prev; |
263 | 248 | ||
264 | /** | 249 | /** |
265 | * Handle to the mesh this tunnel belongs to | 250 | * Handle to the mesh this channel belongs to |
266 | */ | 251 | */ |
267 | struct GNUNET_MESH_Handle *mesh; | 252 | struct GNUNET_MESH_Handle *mesh; |
268 | 253 | ||
269 | /** | 254 | /** |
270 | * Local ID of the tunnel | 255 | * Local ID of the channel |
271 | */ | 256 | */ |
272 | MESH_TunnelNumber tid; | 257 | MESH_ChannelNumber chid; |
273 | 258 | ||
274 | /** | 259 | /** |
275 | * Port number. | 260 | * Port number. |
@@ -277,34 +262,32 @@ struct GNUNET_MESH_Tunnel | |||
277 | uint32_t port; | 262 | uint32_t port; |
278 | 263 | ||
279 | /** | 264 | /** |
280 | * Other end of the tunnel. | 265 | * Other end of the channel. |
281 | */ | 266 | */ |
282 | GNUNET_PEER_Id peer; | 267 | GNUNET_PEER_Id peer; |
283 | 268 | ||
284 | struct GNUNET_PeerIdentity pid; | ||
285 | |||
286 | /** | 269 | /** |
287 | * Any data the caller wants to put in here | 270 | * Any data the caller wants to put in here |
288 | */ | 271 | */ |
289 | void *ctx; | 272 | void *ctx; |
290 | 273 | ||
291 | /** | 274 | /** |
292 | * Size of packet queued in this tunnel | 275 | * Size of packet queued in this channel |
293 | */ | 276 | */ |
294 | unsigned int packet_size; | 277 | unsigned int packet_size; |
295 | 278 | ||
296 | /** | 279 | /** |
297 | * Is the tunnel allowed to buffer? | 280 | * Is the channel allowed to buffer? |
298 | */ | 281 | */ |
299 | int nobuffer; | 282 | int nobuffer; |
300 | 283 | ||
301 | /** | 284 | /** |
302 | * Is the tunnel realiable? | 285 | * Is the channel realiable? |
303 | */ | 286 | */ |
304 | int reliable; | 287 | int reliable; |
305 | 288 | ||
306 | /** | 289 | /** |
307 | * If reliable, is the tunnel out of order? | 290 | * If reliable, is the channel out of order? |
308 | */ | 291 | */ |
309 | int ooorder; | 292 | int ooorder; |
310 | 293 | ||
@@ -328,9 +311,9 @@ struct MeshMQState | |||
328 | struct GNUNET_MESH_TransmitHandle *th; | 311 | struct GNUNET_MESH_TransmitHandle *th; |
329 | 312 | ||
330 | /** | 313 | /** |
331 | * Tunnel to send the data over. | 314 | * Channel to send the data over. |
332 | */ | 315 | */ |
333 | struct GNUNET_MESH_Tunnel *tunnel; | 316 | struct GNUNET_MESH_Channel *channel; |
334 | }; | 317 | }; |
335 | 318 | ||
336 | 319 | ||
@@ -383,17 +366,17 @@ static size_t | |||
383 | message_ready_size (struct GNUNET_MESH_Handle *h) | 366 | message_ready_size (struct GNUNET_MESH_Handle *h) |
384 | { | 367 | { |
385 | struct GNUNET_MESH_TransmitHandle *th; | 368 | struct GNUNET_MESH_TransmitHandle *th; |
386 | struct GNUNET_MESH_Tunnel *t; | 369 | struct GNUNET_MESH_Channel *ch; |
387 | 370 | ||
388 | for (th = h->th_head; NULL != th; th = th->next) | 371 | for (th = h->th_head; NULL != th; th = th->next) |
389 | { | 372 | { |
390 | t = th->tunnel; | 373 | ch = th->channel; |
391 | if (GNUNET_NO == th_is_payload (th)) | 374 | if (GNUNET_NO == th_is_payload (th)) |
392 | { | 375 | { |
393 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# message internal\n"); | 376 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# message internal\n"); |
394 | return th->size; | 377 | return th->size; |
395 | } | 378 | } |
396 | if (GNUNET_YES == t->allow_send) | 379 | if (GNUNET_YES == ch->allow_send) |
397 | { | 380 | { |
398 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# message payload ok\n"); | 381 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# message payload ok\n"); |
399 | return th->size; | 382 | return th->size; |
@@ -404,105 +387,106 @@ message_ready_size (struct GNUNET_MESH_Handle *h) | |||
404 | 387 | ||
405 | 388 | ||
406 | /** | 389 | /** |
407 | * Get the tunnel handler for the tunnel specified by id from the given handle | 390 | * Get the channel handler for the channel specified by id from the given handle |
408 | * @param h Mesh handle | 391 | * @param h Mesh handle |
409 | * @param tid ID of the wanted tunnel | 392 | * @param chid ID of the wanted channel |
410 | * @return handle to the required tunnel or NULL if not found | 393 | * @return handle to the required channel or NULL if not found |
411 | */ | 394 | */ |
412 | static struct GNUNET_MESH_Tunnel * | 395 | static struct GNUNET_MESH_Channel * |
413 | retrieve_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) | 396 | retrieve_channel (struct GNUNET_MESH_Handle *h, MESH_ChannelNumber chid) |
414 | { | 397 | { |
415 | struct GNUNET_MESH_Tunnel *t; | 398 | struct GNUNET_MESH_Channel *ch; |
416 | 399 | ||
417 | t = h->tunnels_head; | 400 | ch = h->channels_head; |
418 | while (t != NULL) | 401 | while (ch != NULL) |
419 | { | 402 | { |
420 | if (t->tid == tid) | 403 | if (ch->chid == chid) |
421 | return t; | 404 | return ch; |
422 | t = t->next; | 405 | ch = ch->next; |
423 | } | 406 | } |
424 | return NULL; | 407 | return NULL; |
425 | } | 408 | } |
426 | 409 | ||
427 | 410 | ||
428 | /** | 411 | /** |
429 | * Create a new tunnel and insert it in the tunnel list of the mesh handle | 412 | * Create a new channel and insert it in the channel list of the mesh handle |
413 | * | ||
430 | * @param h Mesh handle | 414 | * @param h Mesh handle |
431 | * @param tid desired tid of the tunnel, 0 to assign one automatically | 415 | * @param chid Desired chid of the channel, 0 to assign one automatically. |
432 | * @return handle to the created tunnel | 416 | * |
417 | * @return Handle to the created channel. | ||
433 | */ | 418 | */ |
434 | static struct GNUNET_MESH_Tunnel * | 419 | static struct GNUNET_MESH_Channel * |
435 | create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) | 420 | create_channel (struct GNUNET_MESH_Handle *h, MESH_ChannelNumber chid) |
436 | { | 421 | { |
437 | struct GNUNET_MESH_Tunnel *t; | 422 | struct GNUNET_MESH_Channel *ch; |
438 | 423 | ||
439 | t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); | 424 | ch = GNUNET_malloc (sizeof (struct GNUNET_MESH_Channel)); |
440 | GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t); | 425 | GNUNET_CONTAINER_DLL_insert (h->channels_head, h->channels_tail, ch); |
441 | t->mesh = h; | 426 | ch->mesh = h; |
442 | if (0 == tid) | 427 | if (0 == chid) |
443 | { | 428 | { |
444 | t->tid = h->next_tid; | 429 | ch->chid = h->next_chid; |
445 | while (NULL != retrieve_tunnel (h, h->next_tid)) | 430 | while (NULL != retrieve_channel (h, h->next_chid)) |
446 | { | 431 | { |
447 | h->next_tid++; | 432 | h->next_chid++; |
448 | h->next_tid &= ~GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | 433 | h->next_chid &= ~GNUNET_MESH_LOCAL_CHANNEL_ID_SERV; |
449 | h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; | 434 | h->next_chid |= GNUNET_MESH_LOCAL_CHANNEL_ID_CLI; |
450 | } | 435 | } |
451 | } | 436 | } |
452 | else | 437 | else |
453 | { | 438 | { |
454 | t->tid = tid; | 439 | ch->chid = chid; |
455 | } | 440 | } |
456 | t->allow_send = GNUNET_NO; | 441 | ch->allow_send = GNUNET_NO; |
457 | t->nobuffer = GNUNET_NO; | 442 | ch->nobuffer = GNUNET_NO; |
458 | return t; | 443 | return ch; |
459 | } | 444 | } |
460 | 445 | ||
461 | 446 | ||
462 | /** | 447 | /** |
463 | * Destroy the specified tunnel. | 448 | * Destroy the specified channel. |
464 | * - Destroys all peers, calling the disconnect callback on each if needed | 449 | * - Destroys all peers, calling the disconnect callback on each if needed |
465 | * - Cancels all outgoing traffic for that tunnel, calling respective notifys | 450 | * - Cancels all outgoing traffic for that channel, calling respective notifys |
466 | * - Calls cleaner if tunnel was inbound | 451 | * - Calls cleaner if channel was inbound |
467 | * - Frees all memory used | 452 | * - Frees all memory used |
468 | * | 453 | * |
469 | * @param t Pointer to the tunnel. | 454 | * @param ch Pointer to the channel. |
470 | * @param call_cleaner Whether to call the cleaner handler. | 455 | * @param call_cleaner Whether to call the cleaner handler. |
471 | * | 456 | * |
472 | * @return Handle to the required tunnel or NULL if not found. | 457 | * @return Handle to the required channel or NULL if not found. |
473 | */ | 458 | */ |
474 | static void | 459 | static void |
475 | destroy_tunnel (struct GNUNET_MESH_Tunnel *t, int call_cleaner) | 460 | destroy_channel (struct GNUNET_MESH_Channel *ch, int call_cleaner) |
476 | { | 461 | { |
477 | struct GNUNET_MESH_Handle *h; | 462 | struct GNUNET_MESH_Handle *h; |
478 | struct GNUNET_MESH_TransmitHandle *th; | 463 | struct GNUNET_MESH_TransmitHandle *th; |
479 | struct GNUNET_MESH_TransmitHandle *next; | 464 | struct GNUNET_MESH_TransmitHandle *next; |
480 | 465 | ||
481 | if (NULL == t) | 466 | LOG (GNUNET_ERROR_TYPE_DEBUG, "destroy_channel %X\n", ch->chid); |
467 | |||
468 | if (NULL == ch) | ||
482 | { | 469 | { |
483 | GNUNET_break (0); | 470 | GNUNET_break (0); |
484 | return; | 471 | return; |
485 | } | 472 | } |
486 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 473 | h = ch->mesh; |
487 | "destroy_tunnel %X\n", | ||
488 | t->tid); | ||
489 | h = t->mesh; | ||
490 | 474 | ||
491 | GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t); | 475 | GNUNET_CONTAINER_DLL_remove (h->channels_head, h->channels_tail, ch); |
492 | 476 | ||
493 | /* signal tunnel destruction */ | 477 | /* signal channel destruction */ |
494 | if ( (NULL != h->cleaner) && (0 != t->peer) && (GNUNET_YES == call_cleaner) ) | 478 | if ( (NULL != h->cleaner) && (0 != ch->peer) && (GNUNET_YES == call_cleaner) ) |
495 | h->cleaner (h->cls, t, t->ctx); | 479 | h->cleaner (h->cls, ch, ch->ctx); |
496 | 480 | ||
497 | /* check that clients did not leave messages behind in the queue */ | 481 | /* check that clients did not leave messages behind in the queue */ |
498 | for (th = h->th_head; NULL != th; th = next) | 482 | for (th = h->th_head; NULL != th; th = next) |
499 | { | 483 | { |
500 | next = th->next; | 484 | next = th->next; |
501 | if (th->tunnel != t) | 485 | if (th->channel != ch) |
502 | continue; | 486 | continue; |
503 | /* Clients should have aborted their requests already. | 487 | /* Clients should have aborted their requests already. |
504 | * Management traffic should be ok, as clients can't cancel that */ | 488 | * Management traffic should be ok, as clients can't cancel that */ |
505 | GNUNET_break (GNUNET_NO == th_is_payload(th)); | 489 | GNUNET_break (GNUNET_NO == th_is_payload (th)); |
506 | GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); | 490 | GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); |
507 | 491 | ||
508 | /* clean up request */ | 492 | /* clean up request */ |
@@ -519,9 +503,9 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t, int call_cleaner) | |||
519 | h->th = NULL; | 503 | h->th = NULL; |
520 | } | 504 | } |
521 | 505 | ||
522 | if (0 != t->peer) | 506 | if (0 != ch->peer) |
523 | GNUNET_PEER_change_rc (t->peer, -1); | 507 | GNUNET_PEER_change_rc (ch->peer, -1); |
524 | GNUNET_free (t); | 508 | GNUNET_free (ch); |
525 | return; | 509 | return; |
526 | } | 510 | } |
527 | 511 | ||
@@ -538,9 +522,9 @@ timeout_transmission (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
538 | struct GNUNET_MESH_TransmitHandle *th = cls; | 522 | struct GNUNET_MESH_TransmitHandle *th = cls; |
539 | struct GNUNET_MESH_Handle *mesh; | 523 | struct GNUNET_MESH_Handle *mesh; |
540 | 524 | ||
541 | mesh = th->tunnel->mesh; | 525 | mesh = th->channel->mesh; |
542 | GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th); | 526 | GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th); |
543 | th->tunnel->packet_size = 0; | 527 | th->channel->packet_size = 0; |
544 | if (GNUNET_YES == th_is_payload (th)) | 528 | if (GNUNET_YES == th_is_payload (th)) |
545 | th->notify (th->notify_cls, 0, NULL); | 529 | th->notify (th->notify_cls, 0, NULL); |
546 | GNUNET_free (th); | 530 | GNUNET_free (th); |
@@ -580,34 +564,30 @@ add_to_queue (struct GNUNET_MESH_Handle *h, | |||
580 | * | 564 | * |
581 | * @param h mesh handle | 565 | * @param h mesh handle |
582 | * @param msg message to transmit | 566 | * @param msg message to transmit |
583 | * @param tunnel tunnel this send is related to (NULL if N/A) | 567 | * @param channel channel this send is related to (NULL if N/A) |
584 | */ | 568 | */ |
585 | static void | 569 | static void |
586 | send_packet (struct GNUNET_MESH_Handle *h, | 570 | send_packet (struct GNUNET_MESH_Handle *h, |
587 | const struct GNUNET_MessageHeader *msg, | 571 | const struct GNUNET_MessageHeader *msg, |
588 | struct GNUNET_MESH_Tunnel *tunnel); | 572 | struct GNUNET_MESH_Channel *channel); |
589 | 573 | ||
590 | 574 | ||
591 | /** | 575 | /** |
592 | * Send an ack on the tunnel to confirm the processing of a message. | 576 | * Send an ack on the channel to confirm the processing of a message. |
593 | * | 577 | * |
594 | * @param t Tunnel on which to send the ACK. | 578 | * @param ch Channel on which to send the ACK. |
595 | */ | 579 | */ |
596 | static void | 580 | static void |
597 | send_ack (struct GNUNET_MESH_Tunnel *t) | 581 | send_ack (struct GNUNET_MESH_Channel *ch) |
598 | { | 582 | { |
599 | struct GNUNET_MESH_LocalAck msg; | 583 | struct GNUNET_MESH_LocalAck msg; |
600 | 584 | ||
601 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK on tunnel %X\n", t->tid); | 585 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK on channel %X\n", ch->chid); |
602 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK); | 586 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK); |
603 | msg.header.size = htons (sizeof (msg)); | 587 | msg.header.size = htons (sizeof (msg)); |
604 | msg.tunnel_id = htonl (t->tid); | 588 | msg.channel_id = htonl (ch->chid); |
605 | 589 | ||
606 | #if DEBUG_ACK | 590 | send_packet (ch->mesh, &msg.header, ch); |
607 | t->mesh->acks_sent++; | ||
608 | #endif | ||
609 | |||
610 | send_packet (t->mesh, &msg.header, t); | ||
611 | return; | 591 | return; |
612 | } | 592 | } |
613 | 593 | ||
@@ -673,7 +653,7 @@ send_connect (struct GNUNET_MESH_Handle *h) | |||
673 | static int | 653 | static int |
674 | do_reconnect (struct GNUNET_MESH_Handle *h) | 654 | do_reconnect (struct GNUNET_MESH_Handle *h) |
675 | { | 655 | { |
676 | struct GNUNET_MESH_Tunnel *t; | 656 | struct GNUNET_MESH_Channel *ch; |
677 | 657 | ||
678 | LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n"); | 658 | LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n"); |
679 | LOG (GNUNET_ERROR_TYPE_DEBUG, "******* RECONNECT *******\n"); | 659 | LOG (GNUNET_ERROR_TYPE_DEBUG, "******* RECONNECT *******\n"); |
@@ -702,10 +682,9 @@ do_reconnect (struct GNUNET_MESH_Handle *h) | |||
702 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, | 682 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, |
703 | GNUNET_TIME_relative_multiply | 683 | GNUNET_TIME_relative_multiply |
704 | (h->reconnect_time, 2)); | 684 | (h->reconnect_time, 2)); |
705 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 685 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Next retry in %s\n", |
706 | "Next retry in %s\n", | ||
707 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_time, | 686 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_time, |
708 | GNUNET_NO)); | 687 | GNUNET_NO)); |
709 | GNUNET_break (0); | 688 | GNUNET_break (0); |
710 | return GNUNET_NO; | 689 | return GNUNET_NO; |
711 | } | 690 | } |
@@ -714,37 +693,36 @@ do_reconnect (struct GNUNET_MESH_Handle *h) | |||
714 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; | 693 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; |
715 | } | 694 | } |
716 | send_connect (h); | 695 | send_connect (h); |
717 | /* Rebuild all tunnels */ | 696 | /* Rebuild all channels */ |
718 | for (t = h->tunnels_head; NULL != t; t = t->next) | 697 | for (ch = h->channels_head; NULL != ch; ch = ch->next) |
719 | { | 698 | { |
720 | struct GNUNET_MESH_TunnelMessage tmsg; | 699 | struct GNUNET_MESH_ChannelMessage tmsg; |
721 | uint32_t options; | 700 | uint32_t options; |
722 | 701 | ||
723 | if (t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | 702 | if (ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) |
724 | { | 703 | { |
725 | /* Tunnel was created by service (incoming tunnel) */ | 704 | /* Channel was created by service (incoming channel) */ |
726 | /* TODO: Notify service of missing tunnel, to request | 705 | /* TODO: Notify service of missing channel, to request |
727 | * creator to recreate path (find a path to him via DHT?) | 706 | * creator to recreate path (find a path to him via DHT?) |
728 | */ | 707 | */ |
729 | continue; | 708 | continue; |
730 | } | 709 | } |
731 | t->allow_send = GNUNET_NO; | 710 | ch->allow_send = GNUNET_NO; |
732 | tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); | 711 | tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE); |
733 | tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 712 | tmsg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage)); |
734 | tmsg.tunnel_id = htonl (t->tid); | 713 | tmsg.channel_id = htonl (ch->chid); |
735 | tmsg.port = htonl (t->port); | 714 | tmsg.port = htonl (ch->port); |
736 | t->pid = tmsg.peer; | 715 | GNUNET_PEER_resolve (ch->peer, &tmsg.peer); |
737 | GNUNET_PEER_resolve (t->peer, &tmsg.peer); | ||
738 | 716 | ||
739 | options = 0; | 717 | options = 0; |
740 | if (GNUNET_YES == t->nobuffer) | 718 | if (GNUNET_YES == ch->nobuffer) |
741 | options |= GNUNET_MESH_OPTION_NOBUFFER; | 719 | options |= GNUNET_MESH_OPTION_NOBUFFER; |
742 | 720 | ||
743 | if (GNUNET_YES == t->reliable) | 721 | if (GNUNET_YES == ch->reliable) |
744 | options |= GNUNET_MESH_OPTION_RELIABLE; | 722 | options |= GNUNET_MESH_OPTION_RELIABLE; |
745 | 723 | ||
746 | tmsg.opt = htonl (options); | 724 | tmsg.opt = htonl (options); |
747 | send_packet (h, &tmsg.header, t); | 725 | send_packet (h, &tmsg.header, ch); |
748 | } | 726 | } |
749 | return GNUNET_YES; | 727 | return GNUNET_YES; |
750 | } | 728 | } |
@@ -791,62 +769,64 @@ reconnect (struct GNUNET_MESH_Handle *h) | |||
791 | /******************************************************************************/ | 769 | /******************************************************************************/ |
792 | 770 | ||
793 | /** | 771 | /** |
794 | * Process the new tunnel notification and add it to the tunnels in the handle | 772 | * Process the new channel notification and add it to the channels in the handle |
795 | * | 773 | * |
796 | * @param h The mesh handle | 774 | * @param h The mesh handle |
797 | * @param msg A message with the details of the new incoming tunnel | 775 | * @param msg A message with the details of the new incoming channel |
798 | */ | 776 | */ |
799 | static void | 777 | static void |
800 | process_tunnel_created (struct GNUNET_MESH_Handle *h, | 778 | process_channel_created (struct GNUNET_MESH_Handle *h, |
801 | const struct GNUNET_MESH_TunnelMessage *msg) | 779 | const struct GNUNET_MESH_ChannelMessage *msg) |
802 | { | 780 | { |
803 | struct GNUNET_MESH_Tunnel *t; | 781 | struct GNUNET_MESH_Channel *ch; |
804 | MESH_TunnelNumber tid; | 782 | MESH_ChannelNumber chid; |
805 | uint32_t port; | 783 | uint32_t port; |
806 | 784 | ||
807 | tid = ntohl (msg->tunnel_id); | 785 | chid = ntohl (msg->channel_id); |
808 | port = ntohl (msg->port); | 786 | port = ntohl (msg->port); |
809 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming tunnel %X:%u\n", tid, port); | 787 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming channel %X:%u\n", chid, port); |
810 | if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | 788 | if (chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) |
811 | { | 789 | { |
812 | GNUNET_break (0); | 790 | GNUNET_break (0); |
813 | return; | 791 | return; |
814 | } | 792 | } |
815 | if (NULL != h->new_tunnel) | 793 | if (NULL != h->new_channel) |
816 | { | 794 | { |
817 | t = create_tunnel (h, tid); | 795 | ch = create_channel (h, chid); |
818 | t->allow_send = GNUNET_NO; | 796 | ch->allow_send = GNUNET_NO; |
819 | t->peer = GNUNET_PEER_intern (&msg->peer); | 797 | ch->peer = GNUNET_PEER_intern (&msg->peer); |
820 | t->pid = msg->peer; | 798 | ch->mesh = h; |
821 | t->mesh = h; | 799 | ch->chid = chid; |
822 | t->tid = tid; | 800 | ch->port = port; |
823 | t->port = port; | ||
824 | if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER)) | 801 | if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER)) |
825 | t->nobuffer = GNUNET_YES; | 802 | ch->nobuffer = GNUNET_YES; |
826 | else | 803 | else |
827 | t->nobuffer = GNUNET_NO; | 804 | ch->nobuffer = GNUNET_NO; |
805 | |||
828 | if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE)) | 806 | if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE)) |
829 | t->reliable = GNUNET_YES; | 807 | ch->reliable = GNUNET_YES; |
830 | else | 808 | else |
831 | t->reliable = GNUNET_NO; | 809 | ch->reliable = GNUNET_NO; |
832 | if (GNUNET_YES == t->reliable && | 810 | |
811 | if (GNUNET_YES == ch->reliable && | ||
833 | 0 != (msg->opt & GNUNET_MESH_OPTION_OOORDER)) | 812 | 0 != (msg->opt & GNUNET_MESH_OPTION_OOORDER)) |
834 | t->ooorder = GNUNET_YES; | 813 | ch->ooorder = GNUNET_YES; |
835 | else | 814 | else |
836 | t->ooorder = GNUNET_NO; | 815 | ch->ooorder = GNUNET_NO; |
837 | LOG (GNUNET_ERROR_TYPE_DEBUG, " created tunnel %p\n", t); | 816 | |
838 | t->ctx = h->new_tunnel (h->cls, t, &msg->peer, t->port); | 817 | LOG (GNUNET_ERROR_TYPE_DEBUG, " created channel %p\n", ch); |
818 | ch->ctx = h->new_channel (h->cls, ch, &msg->peer, ch->port); | ||
839 | LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); | 819 | LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); |
840 | } | 820 | } |
841 | else | 821 | else |
842 | { | 822 | { |
843 | struct GNUNET_MESH_TunnelMessage d_msg; | 823 | struct GNUNET_MESH_ChannelMessage d_msg; |
844 | 824 | ||
845 | LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming tunnels\n"); | 825 | LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming channels\n"); |
846 | 826 | ||
847 | d_msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); | 827 | d_msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY); |
848 | d_msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 828 | d_msg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage)); |
849 | d_msg.tunnel_id = msg->tunnel_id; | 829 | d_msg.channel_id = msg->channel_id; |
850 | memset (&d_msg.peer, 0, sizeof (struct GNUNET_PeerIdentity)); | 830 | memset (&d_msg.peer, 0, sizeof (struct GNUNET_PeerIdentity)); |
851 | d_msg.port = 0; | 831 | d_msg.port = 0; |
852 | d_msg.opt = 0; | 832 | d_msg.opt = 0; |
@@ -858,29 +838,29 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h, | |||
858 | 838 | ||
859 | 839 | ||
860 | /** | 840 | /** |
861 | * Process the tunnel destroy notification and free associated resources | 841 | * Process the channel destroy notification and free associated resources |
862 | * | 842 | * |
863 | * @param h The mesh handle | 843 | * @param h The mesh handle |
864 | * @param msg A message with the details of the tunnel being destroyed | 844 | * @param msg A message with the details of the channel being destroyed |
865 | */ | 845 | */ |
866 | static void | 846 | static void |
867 | process_tunnel_destroy (struct GNUNET_MESH_Handle *h, | 847 | process_channel_destroy (struct GNUNET_MESH_Handle *h, |
868 | const struct GNUNET_MESH_TunnelMessage *msg) | 848 | const struct GNUNET_MESH_ChannelMessage *msg) |
869 | { | 849 | { |
870 | struct GNUNET_MESH_Tunnel *t; | 850 | struct GNUNET_MESH_Channel *ch; |
871 | MESH_TunnelNumber tid; | 851 | MESH_ChannelNumber chid; |
872 | 852 | ||
873 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying tunnel from service\n"); | 853 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying channel from service\n"); |
874 | tid = ntohl (msg->tunnel_id); | 854 | chid = ntohl (msg->channel_id); |
875 | t = retrieve_tunnel (h, tid); | 855 | ch = retrieve_channel (h, chid); |
876 | 856 | ||
877 | if (NULL == t) | 857 | if (NULL == ch) |
878 | { | 858 | { |
879 | LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X unknown\n", tid); | 859 | LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X unknown\n", chid); |
880 | return; | 860 | return; |
881 | } | 861 | } |
882 | LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X destroyed\n", t->tid); | 862 | LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X destroyed\n", ch->chid); |
883 | destroy_tunnel (t, GNUNET_YES); | 863 | destroy_channel (ch, GNUNET_YES); |
884 | } | 864 | } |
885 | 865 | ||
886 | 866 | ||
@@ -897,7 +877,7 @@ process_incoming_data (struct GNUNET_MESH_Handle *h, | |||
897 | const struct GNUNET_MessageHeader *payload; | 877 | const struct GNUNET_MessageHeader *payload; |
898 | const struct GNUNET_MESH_MessageHandler *handler; | 878 | const struct GNUNET_MESH_MessageHandler *handler; |
899 | struct GNUNET_MESH_LocalData *dmsg; | 879 | struct GNUNET_MESH_LocalData *dmsg; |
900 | struct GNUNET_MESH_Tunnel *t; | 880 | struct GNUNET_MESH_Channel *ch; |
901 | unsigned int i; | 881 | unsigned int i; |
902 | uint16_t type; | 882 | uint16_t type; |
903 | 883 | ||
@@ -905,19 +885,17 @@ process_incoming_data (struct GNUNET_MESH_Handle *h, | |||
905 | 885 | ||
906 | dmsg = (struct GNUNET_MESH_LocalData *) message; | 886 | dmsg = (struct GNUNET_MESH_LocalData *) message; |
907 | 887 | ||
908 | t = retrieve_tunnel (h, ntohl (dmsg->tid)); | 888 | ch = retrieve_channel (h, ntohl (dmsg->id)); |
909 | payload = (struct GNUNET_MessageHeader *) &dmsg[1]; | 889 | payload = (struct GNUNET_MessageHeader *) &dmsg[1]; |
910 | if (NULL == t) | 890 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n", |
891 | ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ? "fwd" : "bck", | ||
892 | GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)), ntohl (dmsg->id)); | ||
893 | if (NULL == ch) | ||
911 | { | 894 | { |
912 | /* Tunnel was ignored/destroyed, probably service didn't get it yet */ | 895 | /* Channel was ignored/destroyed, probably service didn't get it yet */ |
913 | LOG (GNUNET_ERROR_TYPE_DEBUG, " ignored!\n"); | 896 | LOG (GNUNET_ERROR_TYPE_DEBUG, " ignored!\n"); |
914 | return; | 897 | return; |
915 | } | 898 | } |
916 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
917 | " %s data on tunnel %s [%X]\n", | ||
918 | t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV ? "fwd" : "bck", | ||
919 | GNUNET_i2s (GNUNET_PEER_resolve2(t->peer)), | ||
920 | ntohl (dmsg->tid)); | ||
921 | type = ntohs (payload->type); | 899 | type = ntohs (payload->type); |
922 | LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %u\n", type); | 900 | LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %u\n", type); |
923 | for (i = 0; i < h->n_handlers; i++) | 901 | for (i = 0; i < h->n_handlers; i++) |
@@ -929,10 +907,10 @@ process_incoming_data (struct GNUNET_MESH_Handle *h, | |||
929 | if (handler->type == type) | 907 | if (handler->type == type) |
930 | { | 908 | { |
931 | if (GNUNET_OK != | 909 | if (GNUNET_OK != |
932 | handler->callback (h->cls, t, &t->ctx, payload)) | 910 | handler->callback (h->cls, ch, &ch->ctx, payload)) |
933 | { | 911 | { |
934 | LOG (GNUNET_ERROR_TYPE_DEBUG, "callback caused disconnection\n"); | 912 | LOG (GNUNET_ERROR_TYPE_DEBUG, "callback caused disconnection\n"); |
935 | GNUNET_MESH_tunnel_destroy (t); | 913 | GNUNET_MESH_channel_destroy (ch); |
936 | return; | 914 | return; |
937 | } | 915 | } |
938 | else | 916 | else |
@@ -957,115 +935,114 @@ process_ack (struct GNUNET_MESH_Handle *h, | |||
957 | const struct GNUNET_MessageHeader *message) | 935 | const struct GNUNET_MessageHeader *message) |
958 | { | 936 | { |
959 | struct GNUNET_MESH_LocalAck *msg; | 937 | struct GNUNET_MESH_LocalAck *msg; |
960 | struct GNUNET_MESH_Tunnel *t; | 938 | struct GNUNET_MESH_Channel *ch; |
961 | MESH_TunnelNumber tid; | 939 | MESH_ChannelNumber chid; |
962 | 940 | ||
963 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n"); | 941 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n"); |
964 | h->acks_recv++; | ||
965 | msg = (struct GNUNET_MESH_LocalAck *) message; | 942 | msg = (struct GNUNET_MESH_LocalAck *) message; |
966 | tid = ntohl (msg->tunnel_id); | 943 | chid = ntohl (msg->channel_id); |
967 | t = retrieve_tunnel (h, tid); | 944 | ch = retrieve_channel (h, chid); |
968 | if (NULL == t) | 945 | if (NULL == ch) |
969 | { | 946 | { |
970 | LOG (GNUNET_ERROR_TYPE_WARNING, "ACK on unknown tunnel %X\n", tid); | 947 | LOG (GNUNET_ERROR_TYPE_WARNING, "ACK on unknown channel %X\n", chid); |
971 | return; | 948 | return; |
972 | } | 949 | } |
973 | LOG (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %X!\n", t->tid); | 950 | LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X!\n", ch->chid); |
974 | t->allow_send = GNUNET_YES; | 951 | ch->allow_send = GNUNET_YES; |
975 | if (NULL == h->th && 0 < t->packet_size) | 952 | if (NULL == h->th && 0 < ch->packet_size) |
976 | { | 953 | { |
977 | LOG (GNUNET_ERROR_TYPE_DEBUG, " tmt rdy was NULL, requesting!\n"); | 954 | LOG (GNUNET_ERROR_TYPE_DEBUG, " tmt rdy was NULL, requesting!\n"); |
978 | h->th = | 955 | h->th = |
979 | GNUNET_CLIENT_notify_transmit_ready (h->client, t->packet_size, | 956 | GNUNET_CLIENT_notify_transmit_ready (h->client, ch->packet_size, |
980 | GNUNET_TIME_UNIT_FOREVER_REL, | 957 | GNUNET_TIME_UNIT_FOREVER_REL, |
981 | GNUNET_YES, &send_callback, h); | 958 | GNUNET_YES, &send_callback, h); |
982 | } | 959 | } |
983 | } | 960 | } |
984 | 961 | ||
985 | 962 | ||
986 | /** | 963 | /* |
987 | * Process a local reply about info on all tunnels, pass info to the user. | 964 | * Process a local reply about info on all channels, pass info to the user. |
988 | * | 965 | * |
989 | * @param h Mesh handle. | 966 | * @param h Mesh handle. |
990 | * @param message Message itself. | 967 | * @param message Message itself. |
991 | */ | 968 | */ |
992 | static void | 969 | // static void |
993 | process_get_tunnels (struct GNUNET_MESH_Handle *h, | 970 | // process_get_channels (struct GNUNET_MESH_Handle *h, |
994 | const struct GNUNET_MessageHeader *message) | 971 | // const struct GNUNET_MessageHeader *message) |
995 | { | 972 | // { |
996 | struct GNUNET_MESH_LocalMonitor *msg; | 973 | // struct GNUNET_MESH_LocalMonitor *msg; |
997 | 974 | // | |
998 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnels messasge received\n"); | 975 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n"); |
999 | 976 | // | |
1000 | if (NULL == h->tunnels_cb) | 977 | // if (NULL == h->channels_cb) |
1001 | { | 978 | // { |
1002 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); | 979 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); |
1003 | return; | 980 | // return; |
1004 | } | 981 | // } |
1005 | 982 | // | |
1006 | msg = (struct GNUNET_MESH_LocalMonitor *) message; | 983 | // msg = (struct GNUNET_MESH_LocalMonitor *) message; |
1007 | if (ntohs (message->size) != | 984 | // if (ntohs (message->size) != |
1008 | (sizeof (struct GNUNET_MESH_LocalMonitor) + | 985 | // (sizeof (struct GNUNET_MESH_LocalMonitor) + |
1009 | sizeof (struct GNUNET_PeerIdentity))) | 986 | // sizeof (struct GNUNET_PeerIdentity))) |
1010 | { | 987 | // { |
1011 | GNUNET_break_op (0); | 988 | // GNUNET_break_op (0); |
1012 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 989 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1013 | "Get tunnels message: size %hu - expected %u\n", | 990 | // "Get channels message: size %hu - expected %u\n", |
1014 | ntohs (message->size), | 991 | // ntohs (message->size), |
1015 | sizeof (struct GNUNET_MESH_LocalMonitor)); | 992 | // sizeof (struct GNUNET_MESH_LocalMonitor)); |
1016 | return; | 993 | // return; |
1017 | } | 994 | // } |
1018 | h->tunnels_cb (h->tunnels_cls, | 995 | // h->channels_cb (h->channels_cls, |
1019 | ntohl (msg->tunnel_id), | 996 | // ntohl (msg->channel_id), |
1020 | &msg->owner, | 997 | // &msg->owner, |
1021 | &msg->destination); | 998 | // &msg->destination); |
1022 | } | 999 | // } |
1023 | 1000 | ||
1024 | 1001 | ||
1025 | 1002 | ||
1026 | /** | 1003 | /* |
1027 | * Process a local monitor_tunnel reply, pass info to the user. | 1004 | * Process a local monitor_channel reply, pass info to the user. |
1028 | * | 1005 | * |
1029 | * @param h Mesh handle. | 1006 | * @param h Mesh handle. |
1030 | * @param message Message itself. | 1007 | * @param message Message itself. |
1031 | */ | 1008 | */ |
1032 | static void | 1009 | // static void |
1033 | process_show_tunnel (struct GNUNET_MESH_Handle *h, | 1010 | // process_show_channel (struct GNUNET_MESH_Handle *h, |
1034 | const struct GNUNET_MessageHeader *message) | 1011 | // const struct GNUNET_MessageHeader *message) |
1035 | { | 1012 | // { |
1036 | struct GNUNET_MESH_LocalMonitor *msg; | 1013 | // struct GNUNET_MESH_LocalMonitor *msg; |
1037 | size_t esize; | 1014 | // size_t esize; |
1038 | 1015 | // | |
1039 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Tunnel messasge received\n"); | 1016 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n"); |
1040 | 1017 | // | |
1041 | if (NULL == h->tunnel_cb) | 1018 | // if (NULL == h->channel_cb) |
1042 | { | 1019 | // { |
1043 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); | 1020 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); |
1044 | return; | 1021 | // return; |
1045 | } | 1022 | // } |
1046 | 1023 | // | |
1047 | /* Verify message sanity */ | 1024 | // /* Verify message sanity */ |
1048 | msg = (struct GNUNET_MESH_LocalMonitor *) message; | 1025 | // msg = (struct GNUNET_MESH_LocalMonitor *) message; |
1049 | esize = sizeof (struct GNUNET_MESH_LocalMonitor); | 1026 | // esize = sizeof (struct GNUNET_MESH_LocalMonitor); |
1050 | if (ntohs (message->size) != esize) | 1027 | // if (ntohs (message->size) != esize) |
1051 | { | 1028 | // { |
1052 | GNUNET_break_op (0); | 1029 | // GNUNET_break_op (0); |
1053 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1030 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1054 | "Show tunnel message: size %hu - expected %u\n", | 1031 | // "Show channel message: size %hu - expected %u\n", |
1055 | ntohs (message->size), | 1032 | // ntohs (message->size), |
1056 | esize); | 1033 | // esize); |
1057 | 1034 | // | |
1058 | h->tunnel_cb (h->tunnel_cls, NULL, NULL); | 1035 | // h->channel_cb (h->channel_cls, NULL, NULL); |
1059 | h->tunnel_cb = NULL; | 1036 | // h->channel_cb = NULL; |
1060 | h->tunnel_cls = NULL; | 1037 | // h->channel_cls = NULL; |
1061 | 1038 | // | |
1062 | return; | 1039 | // return; |
1063 | } | 1040 | // } |
1064 | 1041 | // | |
1065 | h->tunnel_cb (h->tunnel_cls, | 1042 | // h->channel_cb (h->channel_cls, |
1066 | &msg->destination, | 1043 | // &msg->destination, |
1067 | &msg->owner); | 1044 | // &msg->owner); |
1068 | } | 1045 | // } |
1069 | 1046 | ||
1070 | 1047 | ||
1071 | /** | 1048 | /** |
@@ -1093,27 +1070,27 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1093 | GNUNET_MESH_DEBUG_M2S (type)); | 1070 | GNUNET_MESH_DEBUG_M2S (type)); |
1094 | switch (type) | 1071 | switch (type) |
1095 | { | 1072 | { |
1096 | /* Notify of a new incoming tunnel */ | 1073 | /* Notify of a new incoming channel */ |
1097 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE: | 1074 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: |
1098 | process_tunnel_created (h, (struct GNUNET_MESH_TunnelMessage *) msg); | 1075 | process_channel_created (h, (struct GNUNET_MESH_ChannelMessage *) msg); |
1099 | break; | 1076 | break; |
1100 | /* Notify of a tunnel disconnection */ | 1077 | /* Notify of a channel disconnection */ |
1101 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY: | 1078 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: |
1102 | process_tunnel_destroy (h, (struct GNUNET_MESH_TunnelMessage *) msg); | 1079 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_NACK: |
1080 | process_channel_destroy (h, (struct GNUNET_MESH_ChannelMessage *) msg); | ||
1103 | break; | 1081 | break; |
1104 | /* Notify of a new data packet in the tunnel */ | ||
1105 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA: | 1082 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA: |
1106 | process_incoming_data (h, msg); | 1083 | process_incoming_data (h, msg); |
1107 | break; | 1084 | break; |
1108 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: | 1085 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: |
1109 | process_ack (h, msg); | 1086 | process_ack (h, msg); |
1110 | break; | 1087 | break; |
1111 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS: | 1088 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: DEPRECATED |
1112 | process_get_tunnels (h, msg); | 1089 | // process_get_channels (h, msg); |
1113 | break; | 1090 | // break; |
1114 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL: | 1091 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: DEPRECATED |
1115 | process_show_tunnel (h, msg); | 1092 | // process_show_channel (h, msg); |
1116 | break; | 1093 | // break; |
1117 | default: | 1094 | default: |
1118 | /* We shouldn't get any other packages, log and ignore */ | 1095 | /* We shouldn't get any other packages, log and ignore */ |
1119 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1096 | LOG (GNUNET_ERROR_TYPE_WARNING, |
@@ -1154,7 +1131,7 @@ send_callback (void *cls, size_t size, void *buf) | |||
1154 | struct GNUNET_MESH_Handle *h = cls; | 1131 | struct GNUNET_MESH_Handle *h = cls; |
1155 | struct GNUNET_MESH_TransmitHandle *th; | 1132 | struct GNUNET_MESH_TransmitHandle *th; |
1156 | struct GNUNET_MESH_TransmitHandle *next; | 1133 | struct GNUNET_MESH_TransmitHandle *next; |
1157 | struct GNUNET_MESH_Tunnel *t; | 1134 | struct GNUNET_MESH_Channel *ch; |
1158 | char *cbuf = buf; | 1135 | char *cbuf = buf; |
1159 | size_t tsize; | 1136 | size_t tsize; |
1160 | size_t psize; | 1137 | size_t psize; |
@@ -1174,20 +1151,20 @@ send_callback (void *cls, size_t size, void *buf) | |||
1174 | nsize = message_ready_size (h); | 1151 | nsize = message_ready_size (h); |
1175 | while ((NULL != (th = next)) && (0 < nsize) && (size >= nsize)) | 1152 | while ((NULL != (th = next)) && (0 < nsize) && (size >= nsize)) |
1176 | { | 1153 | { |
1177 | t = th->tunnel; | 1154 | ch = th->channel; |
1178 | if (GNUNET_YES == th_is_payload (th)) | 1155 | if (GNUNET_YES == th_is_payload (th)) |
1179 | { | 1156 | { |
1180 | struct GNUNET_MESH_LocalData *dmsg; | 1157 | struct GNUNET_MESH_LocalData *dmsg; |
1181 | struct GNUNET_MessageHeader *mh; | 1158 | struct GNUNET_MessageHeader *mh; |
1182 | 1159 | ||
1183 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload\n"); | 1160 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload\n"); |
1184 | if (GNUNET_NO == t->allow_send) | 1161 | if (GNUNET_NO == ch->allow_send) |
1185 | { | 1162 | { |
1186 | /* This tunnel is not ready to transmit yet, try next message */ | 1163 | /* This channel is not ready to transmit yet, try next message */ |
1187 | next = th->next; | 1164 | next = th->next; |
1188 | continue; | 1165 | continue; |
1189 | } | 1166 | } |
1190 | t->packet_size = 0; | 1167 | ch->packet_size = 0; |
1191 | GNUNET_assert (size >= th->size); | 1168 | GNUNET_assert (size >= th->size); |
1192 | dmsg = (struct GNUNET_MESH_LocalData *) cbuf; | 1169 | dmsg = (struct GNUNET_MESH_LocalData *) cbuf; |
1193 | mh = (struct GNUNET_MessageHeader *) &dmsg[1]; | 1170 | mh = (struct GNUNET_MessageHeader *) &dmsg[1]; |
@@ -1199,11 +1176,11 @@ send_callback (void *cls, size_t size, void *buf) | |||
1199 | psize += sizeof (struct GNUNET_MESH_LocalData); | 1176 | psize += sizeof (struct GNUNET_MESH_LocalData); |
1200 | GNUNET_assert (size >= psize); | 1177 | GNUNET_assert (size >= psize); |
1201 | dmsg->header.size = htons (psize); | 1178 | dmsg->header.size = htons (psize); |
1202 | dmsg->tid = htonl (t->tid); | 1179 | dmsg->id = htonl (ch->chid); |
1203 | dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA); | 1180 | dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA); |
1204 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n", | 1181 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n", |
1205 | GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); | 1182 | GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); |
1206 | t->allow_send = GNUNET_NO; | 1183 | ch->allow_send = GNUNET_NO; |
1207 | } | 1184 | } |
1208 | else | 1185 | else |
1209 | { | 1186 | { |
@@ -1268,12 +1245,12 @@ send_callback (void *cls, size_t size, void *buf) | |||
1268 | * | 1245 | * |
1269 | * @param h mesh handle | 1246 | * @param h mesh handle |
1270 | * @param msg message to transmit | 1247 | * @param msg message to transmit |
1271 | * @param tunnel tunnel this send is related to (NULL if N/A) | 1248 | * @param channel channel this send is related to (NULL if N/A) |
1272 | */ | 1249 | */ |
1273 | static void | 1250 | static void |
1274 | send_packet (struct GNUNET_MESH_Handle *h, | 1251 | send_packet (struct GNUNET_MESH_Handle *h, |
1275 | const struct GNUNET_MessageHeader *msg, | 1252 | const struct GNUNET_MessageHeader *msg, |
1276 | struct GNUNET_MESH_Tunnel *tunnel) | 1253 | struct GNUNET_MESH_Channel *channel) |
1277 | { | 1254 | { |
1278 | struct GNUNET_MESH_TransmitHandle *th; | 1255 | struct GNUNET_MESH_TransmitHandle *th; |
1279 | size_t msize; | 1256 | size_t msize; |
@@ -1284,7 +1261,7 @@ send_packet (struct GNUNET_MESH_Handle *h, | |||
1284 | th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize); | 1261 | th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize); |
1285 | th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 1262 | th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
1286 | th->size = msize; | 1263 | th->size = msize; |
1287 | th->tunnel = tunnel; | 1264 | th->channel = channel; |
1288 | memcpy (&th[1], msg, msize); | 1265 | memcpy (&th[1], msg, msize); |
1289 | add_to_queue (h, th); | 1266 | add_to_queue (h, th); |
1290 | LOG (GNUNET_ERROR_TYPE_DEBUG, " queued\n"); | 1267 | LOG (GNUNET_ERROR_TYPE_DEBUG, " queued\n"); |
@@ -1304,8 +1281,8 @@ send_packet (struct GNUNET_MESH_Handle *h, | |||
1304 | 1281 | ||
1305 | struct GNUNET_MESH_Handle * | 1282 | struct GNUNET_MESH_Handle * |
1306 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | 1283 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, |
1307 | GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, | 1284 | GNUNET_MESH_InboundChannelNotificationHandler new_channel, |
1308 | GNUNET_MESH_TunnelEndHandler cleaner, | 1285 | GNUNET_MESH_ChannelEndHandler cleaner, |
1309 | const struct GNUNET_MESH_MessageHandler *handlers, | 1286 | const struct GNUNET_MESH_MessageHandler *handlers, |
1310 | const uint32_t *ports) | 1287 | const uint32_t *ports) |
1311 | { | 1288 | { |
@@ -1315,7 +1292,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
1315 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); | 1292 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); |
1316 | LOG (GNUNET_ERROR_TYPE_DEBUG, " addr %p\n", h); | 1293 | LOG (GNUNET_ERROR_TYPE_DEBUG, " addr %p\n", h); |
1317 | h->cfg = cfg; | 1294 | h->cfg = cfg; |
1318 | h->new_tunnel = new_tunnel; | 1295 | h->new_channel = new_channel; |
1319 | h->cleaner = cleaner; | 1296 | h->cleaner = cleaner; |
1320 | h->client = GNUNET_CLIENT_connect ("mesh", cfg); | 1297 | h->client = GNUNET_CLIENT_connect ("mesh", cfg); |
1321 | if (h->client == NULL) | 1298 | if (h->client == NULL) |
@@ -1327,21 +1304,21 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
1327 | h->cls = cls; | 1304 | h->cls = cls; |
1328 | h->message_handlers = handlers; | 1305 | h->message_handlers = handlers; |
1329 | h->ports = ports; | 1306 | h->ports = ports; |
1330 | h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; | 1307 | h->next_chid = GNUNET_MESH_LOCAL_CHANNEL_ID_CLI; |
1331 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; | 1308 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; |
1332 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 1309 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
1333 | 1310 | ||
1334 | if (NULL != ports && ports[0] != 0 && NULL == new_tunnel) | 1311 | if (NULL != ports && ports[0] != 0 && NULL == new_channel) |
1335 | { | 1312 | { |
1336 | GNUNET_break (0); | 1313 | GNUNET_break (0); |
1337 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1314 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1338 | "no new tunnel handler given, ports parameter is useless!!\n"); | 1315 | "no new channel handler given, ports parameter is useless!!\n"); |
1339 | } | 1316 | } |
1340 | if ((NULL == ports || ports[0] == 0) && NULL != new_tunnel) | 1317 | if ((NULL == ports || ports[0] == 0) && NULL != new_channel) |
1341 | { | 1318 | { |
1342 | GNUNET_break (0); | 1319 | GNUNET_break (0); |
1343 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1320 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1344 | "no ports given, new tunnel handler will never be called!!\n"); | 1321 | "no ports given, new channel handler will never be called!!\n"); |
1345 | } | 1322 | } |
1346 | /* count handlers */ | 1323 | /* count handlers */ |
1347 | for (h->n_handlers = 0; | 1324 | for (h->n_handlers = 0; |
@@ -1359,28 +1336,23 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
1359 | void | 1336 | void |
1360 | GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | 1337 | GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) |
1361 | { | 1338 | { |
1362 | struct GNUNET_MESH_Tunnel *t; | 1339 | struct GNUNET_MESH_Channel *ch; |
1363 | struct GNUNET_MESH_Tunnel *aux; | 1340 | struct GNUNET_MESH_Channel *aux; |
1364 | struct GNUNET_MESH_TransmitHandle *th; | 1341 | struct GNUNET_MESH_TransmitHandle *th; |
1365 | 1342 | ||
1366 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH DISCONNECT\n"); | 1343 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH DISCONNECT\n"); |
1367 | 1344 | ||
1368 | #if DEBUG_ACK | 1345 | ch = handle->channels_head; |
1369 | LOG (GNUNET_ERROR_TYPE_INFO, "Sent %d ACKs\n", handle->acks_sent); | 1346 | while (NULL != ch) |
1370 | LOG (GNUNET_ERROR_TYPE_INFO, "Recv %d ACKs\n\n", handle->acks_recv); | ||
1371 | #endif | ||
1372 | |||
1373 | t = handle->tunnels_head; | ||
1374 | while (NULL != t) | ||
1375 | { | 1347 | { |
1376 | aux = t->next; | 1348 | aux = ch->next; |
1377 | if (t->tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | 1349 | if (ch->chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) |
1378 | { | 1350 | { |
1379 | GNUNET_break (0); | 1351 | GNUNET_break (0); |
1380 | LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X not destroyed\n", t->tid); | 1352 | LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X not destroyed\n", ch->chid); |
1381 | } | 1353 | } |
1382 | destroy_tunnel (t, GNUNET_YES); | 1354 | destroy_channel (ch, GNUNET_YES); |
1383 | t = aux; | 1355 | ch = aux; |
1384 | } | 1356 | } |
1385 | while ( (th = handle->th_head) != NULL) | 1357 | while ( (th = handle->th_head) != NULL) |
1386 | { | 1358 | { |
@@ -1394,9 +1366,10 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
1394 | switch (ntohs(msg->type)) | 1366 | switch (ntohs(msg->type)) |
1395 | { | 1367 | { |
1396 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT: | 1368 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT: |
1397 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY: | 1369 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: |
1398 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS: | 1370 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: |
1399 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL: | 1371 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: |
1372 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: | ||
1400 | break; | 1373 | break; |
1401 | default: | 1374 | default: |
1402 | GNUNET_break (0); | 1375 | GNUNET_break (0); |
@@ -1428,41 +1401,43 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
1428 | 1401 | ||
1429 | 1402 | ||
1430 | /** | 1403 | /** |
1431 | * Create a new tunnel (we're initiator and will be allowed to add/remove peers | 1404 | * Create a new channel towards a remote peer. |
1432 | * and to broadcast). | 1405 | * |
1406 | * If the destination port is not open by any peer or the destination peer | ||
1407 | * does not accept the channel, #GNUNET_MESH_ChannelEndHandler will be called | ||
1408 | * for this channel. | ||
1433 | * | 1409 | * |
1434 | * @param h mesh handle | 1410 | * @param h mesh handle |
1435 | * @param tunnel_ctx client's tunnel context to associate with the tunnel | 1411 | * @param channel_ctx client's channel context to associate with the channel |
1436 | * @param peer peer identity the tunnel should go to | 1412 | * @param peer peer identity the channel should go to |
1437 | * @param port Port number. | 1413 | * @param port Port number. |
1438 | * @param nobuffer Flag for disabling buffering on relay nodes. | 1414 | * @param nobuffer Flag for disabling buffering on relay nodes. |
1439 | * @param reliable Flag for end-to-end reliability. | 1415 | * @param reliable Flag for end-to-end reliability. |
1440 | * | 1416 | * |
1441 | * @return handle to the tunnel | 1417 | * @return handle to the channel |
1442 | */ | 1418 | */ |
1443 | struct GNUNET_MESH_Tunnel * | 1419 | struct GNUNET_MESH_Channel * |
1444 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | 1420 | GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h, |
1445 | void *tunnel_ctx, | 1421 | void *channel_ctx, |
1446 | const struct GNUNET_PeerIdentity *peer, | 1422 | const struct GNUNET_PeerIdentity *peer, |
1447 | uint32_t port, | 1423 | uint32_t port, |
1448 | int nobuffer, | 1424 | int nobuffer, |
1449 | int reliable) | 1425 | int reliable) |
1450 | { | 1426 | { |
1451 | struct GNUNET_MESH_Tunnel *t; | 1427 | struct GNUNET_MESH_Channel *ch; |
1452 | struct GNUNET_MESH_TunnelMessage msg; | 1428 | struct GNUNET_MESH_ChannelMessage msg; |
1453 | 1429 | ||
1454 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1430 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1455 | "Creating new tunnel to %s:%u\n", | 1431 | "Creating new channel to %s:%u\n", |
1456 | GNUNET_i2s (peer), port); | 1432 | GNUNET_i2s (peer), port); |
1457 | t = create_tunnel (h, 0); | 1433 | ch = create_channel (h, 0); |
1458 | LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", t); | 1434 | LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch); |
1459 | LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", t->tid); | 1435 | LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", ch->chid); |
1460 | t->ctx = tunnel_ctx; | 1436 | ch->ctx = channel_ctx; |
1461 | t->peer = GNUNET_PEER_intern (peer); | 1437 | ch->peer = GNUNET_PEER_intern (peer); |
1462 | t->pid = *peer; | 1438 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE); |
1463 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); | 1439 | msg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage)); |
1464 | msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 1440 | msg.channel_id = htonl (ch->chid); |
1465 | msg.tunnel_id = htonl (t->tid); | ||
1466 | msg.port = htonl (port); | 1441 | msg.port = htonl (port); |
1467 | msg.peer = *peer; | 1442 | msg.peer = *peer; |
1468 | msg.opt = 0; | 1443 | msg.opt = 0; |
@@ -1471,25 +1446,25 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | |||
1471 | if (GNUNET_YES == nobuffer) | 1446 | if (GNUNET_YES == nobuffer) |
1472 | msg.opt |= GNUNET_MESH_OPTION_NOBUFFER; | 1447 | msg.opt |= GNUNET_MESH_OPTION_NOBUFFER; |
1473 | msg.opt = htonl (msg.opt); | 1448 | msg.opt = htonl (msg.opt); |
1474 | t->allow_send = 0; | 1449 | ch->allow_send = 0; |
1475 | send_packet (h, &msg.header, t); | 1450 | send_packet (h, &msg.header, ch); |
1476 | return t; | 1451 | return ch; |
1477 | } | 1452 | } |
1478 | 1453 | ||
1479 | 1454 | ||
1480 | void | 1455 | void |
1481 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel) | 1456 | GNUNET_MESH_channel_destroy (struct GNUNET_MESH_Channel *channel) |
1482 | { | 1457 | { |
1483 | struct GNUNET_MESH_Handle *h; | 1458 | struct GNUNET_MESH_Handle *h; |
1484 | struct GNUNET_MESH_TunnelMessage msg; | 1459 | struct GNUNET_MESH_ChannelMessage msg; |
1485 | struct GNUNET_MESH_TransmitHandle *th; | 1460 | struct GNUNET_MESH_TransmitHandle *th; |
1486 | 1461 | ||
1487 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying tunnel\n"); | 1462 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying channel\n"); |
1488 | h = tunnel->mesh; | 1463 | h = channel->mesh; |
1489 | 1464 | ||
1490 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); | 1465 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY); |
1491 | msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 1466 | msg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage)); |
1492 | msg.tunnel_id = htonl (tunnel->tid); | 1467 | msg.channel_id = htonl (channel->chid); |
1493 | memset (&msg.peer, 0, sizeof (struct GNUNET_PeerIdentity)); | 1468 | memset (&msg.peer, 0, sizeof (struct GNUNET_PeerIdentity)); |
1494 | msg.port = 0; | 1469 | msg.port = 0; |
1495 | msg.opt = 0; | 1470 | msg.opt = 0; |
@@ -1497,7 +1472,7 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel) | |||
1497 | while (th != NULL) | 1472 | while (th != NULL) |
1498 | { | 1473 | { |
1499 | struct GNUNET_MESH_TransmitHandle *aux; | 1474 | struct GNUNET_MESH_TransmitHandle *aux; |
1500 | if (th->tunnel == tunnel) | 1475 | if (th->channel == channel) |
1501 | { | 1476 | { |
1502 | aux = th->next; | 1477 | aux = th->next; |
1503 | /* FIXME call the handler? */ | 1478 | /* FIXME call the handler? */ |
@@ -1511,39 +1486,39 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel) | |||
1511 | th = th->next; | 1486 | th = th->next; |
1512 | } | 1487 | } |
1513 | 1488 | ||
1514 | destroy_tunnel (tunnel, GNUNET_YES); | 1489 | destroy_channel (channel, GNUNET_YES); |
1515 | send_packet (h, &msg.header, NULL); | 1490 | send_packet (h, &msg.header, NULL); |
1516 | } | 1491 | } |
1517 | 1492 | ||
1518 | 1493 | ||
1519 | /** | 1494 | /** |
1520 | * Get information about a tunnel. | 1495 | * Get information about a channel. |
1521 | * | 1496 | * |
1522 | * @param tunnel Tunnel handle. | 1497 | * @param channel Channel handle. |
1523 | * @param option Query (GNUNET_MESH_OPTION_*). | 1498 | * @param option Query (GNUNET_MESH_OPTION_*). |
1524 | * @param ... dependant on option, currently not used | 1499 | * @param ... dependant on option, currently not used |
1525 | * | 1500 | * |
1526 | * @return Union with an answer to the query. | 1501 | * @return Union with an answer to the query. |
1527 | */ | 1502 | */ |
1528 | const union GNUNET_MESH_TunnelInfo * | 1503 | const union GNUNET_MESH_ChannelInfo * |
1529 | GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel, | 1504 | GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel, |
1530 | enum MeshTunnelOption option, ...) | 1505 | enum MeshOption option, ...) |
1531 | { | 1506 | { |
1532 | const union GNUNET_MESH_TunnelInfo *ret; | 1507 | const union GNUNET_MESH_ChannelInfo *ret; |
1533 | 1508 | ||
1534 | switch (option) | 1509 | switch (option) |
1535 | { | 1510 | { |
1536 | case GNUNET_MESH_OPTION_NOBUFFER: | 1511 | case GNUNET_MESH_OPTION_NOBUFFER: |
1537 | ret = (const union GNUNET_MESH_TunnelInfo *) &tunnel->nobuffer; | 1512 | ret = (const union GNUNET_MESH_ChannelInfo *) &channel->nobuffer; |
1538 | break; | 1513 | break; |
1539 | case GNUNET_MESH_OPTION_RELIABLE: | 1514 | case GNUNET_MESH_OPTION_RELIABLE: |
1540 | ret = (const union GNUNET_MESH_TunnelInfo *) &tunnel->reliable; | 1515 | ret = (const union GNUNET_MESH_ChannelInfo *) &channel->reliable; |
1541 | break; | 1516 | break; |
1542 | case GNUNET_MESH_OPTION_OOORDER: | 1517 | case GNUNET_MESH_OPTION_OOORDER: |
1543 | ret = (const union GNUNET_MESH_TunnelInfo *) &tunnel->ooorder; | 1518 | ret = (const union GNUNET_MESH_ChannelInfo *) &channel->ooorder; |
1544 | break; | 1519 | break; |
1545 | case GNUNET_MESH_OPTION_PEER: | 1520 | case GNUNET_MESH_OPTION_PEER: |
1546 | ret = (const union GNUNET_MESH_TunnelInfo *) &tunnel->pid; | 1521 | ret = (const union GNUNET_MESH_ChannelInfo *) &channel->peer; |
1547 | break; | 1522 | break; |
1548 | default: | 1523 | default: |
1549 | GNUNET_break (0); | 1524 | GNUNET_break (0); |
@@ -1554,7 +1529,7 @@ GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel, | |||
1554 | } | 1529 | } |
1555 | 1530 | ||
1556 | struct GNUNET_MESH_TransmitHandle * | 1531 | struct GNUNET_MESH_TransmitHandle * |
1557 | GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | 1532 | GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Channel *channel, int cork, |
1558 | struct GNUNET_TIME_Relative maxdelay, | 1533 | struct GNUNET_TIME_Relative maxdelay, |
1559 | size_t notify_size, | 1534 | size_t notify_size, |
1560 | GNUNET_CONNECTION_TransmitReadyNotify notify, | 1535 | GNUNET_CONNECTION_TransmitReadyNotify notify, |
@@ -1562,36 +1537,36 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | |||
1562 | { | 1537 | { |
1563 | struct GNUNET_MESH_TransmitHandle *th; | 1538 | struct GNUNET_MESH_TransmitHandle *th; |
1564 | 1539 | ||
1565 | GNUNET_assert (NULL != tunnel); | 1540 | GNUNET_assert (NULL != channel); |
1566 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY\n"); | 1541 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY\n"); |
1567 | LOG (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %X\n", tunnel->tid); | 1542 | LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->chid); |
1568 | LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", tunnel->allow_send); | 1543 | LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send); |
1569 | if (tunnel->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | 1544 | if (channel->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) |
1570 | LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n"); | 1545 | LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n"); |
1571 | else | 1546 | else |
1572 | LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n"); | 1547 | LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n"); |
1573 | LOG (GNUNET_ERROR_TYPE_DEBUG, " payload size %u\n", notify_size); | 1548 | LOG (GNUNET_ERROR_TYPE_DEBUG, " payload size %u\n", notify_size); |
1574 | GNUNET_assert (NULL != notify); | 1549 | GNUNET_assert (NULL != notify); |
1575 | GNUNET_assert (0 == tunnel->packet_size); // Only one data packet allowed | 1550 | GNUNET_assert (0 == channel->packet_size); // Only one data packet allowed |
1576 | th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle)); | 1551 | th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle)); |
1577 | th->tunnel = tunnel; | 1552 | th->channel = channel; |
1578 | th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); | 1553 | th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); |
1579 | th->size = notify_size + sizeof (struct GNUNET_MESH_LocalData); | 1554 | th->size = notify_size + sizeof (struct GNUNET_MESH_LocalData); |
1580 | tunnel->packet_size = th->size; | 1555 | channel->packet_size = th->size; |
1581 | LOG (GNUNET_ERROR_TYPE_DEBUG, " total size %u\n", th->size); | 1556 | LOG (GNUNET_ERROR_TYPE_DEBUG, " total size %u\n", th->size); |
1582 | th->notify = notify; | 1557 | th->notify = notify; |
1583 | th->notify_cls = notify_cls; | 1558 | th->notify_cls = notify_cls; |
1584 | add_to_queue (tunnel->mesh, th); | 1559 | add_to_queue (channel->mesh, th); |
1585 | if (NULL != tunnel->mesh->th) | 1560 | if (NULL != channel->mesh->th) |
1586 | return th; | 1561 | return th; |
1587 | if (GNUNET_NO == tunnel->allow_send) | 1562 | if (GNUNET_NO == channel->allow_send) |
1588 | return th; | 1563 | return th; |
1589 | LOG (GNUNET_ERROR_TYPE_DEBUG, " call client notify tmt rdy\n"); | 1564 | LOG (GNUNET_ERROR_TYPE_DEBUG, " call client notify tmt rdy\n"); |
1590 | tunnel->mesh->th = | 1565 | channel->mesh->th = |
1591 | GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, th->size, | 1566 | GNUNET_CLIENT_notify_transmit_ready (channel->mesh->client, th->size, |
1592 | GNUNET_TIME_UNIT_FOREVER_REL, | 1567 | GNUNET_TIME_UNIT_FOREVER_REL, |
1593 | GNUNET_YES, &send_callback, | 1568 | GNUNET_YES, &send_callback, |
1594 | tunnel->mesh); | 1569 | channel->mesh); |
1595 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY END\n"); | 1570 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY END\n"); |
1596 | return th; | 1571 | return th; |
1597 | } | 1572 | } |
@@ -1602,8 +1577,8 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th) | |||
1602 | { | 1577 | { |
1603 | struct GNUNET_MESH_Handle *mesh; | 1578 | struct GNUNET_MESH_Handle *mesh; |
1604 | 1579 | ||
1605 | th->tunnel->packet_size = 0; | 1580 | th->channel->packet_size = 0; |
1606 | mesh = th->tunnel->mesh; | 1581 | mesh = th->channel->mesh; |
1607 | if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 1582 | if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
1608 | GNUNET_SCHEDULER_cancel (th->timeout_task); | 1583 | GNUNET_SCHEDULER_cancel (th->timeout_task); |
1609 | GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th); | 1584 | GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th); |
@@ -1617,16 +1592,16 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th) | |||
1617 | } | 1592 | } |
1618 | 1593 | ||
1619 | void | 1594 | void |
1620 | GNUNET_MESH_receive_done (struct GNUNET_MESH_Tunnel *tunnel) | 1595 | GNUNET_MESH_receive_done (struct GNUNET_MESH_Channel *channel) |
1621 | { | 1596 | { |
1622 | send_ack (tunnel); | 1597 | send_ack (channel); |
1623 | } | 1598 | } |
1624 | 1599 | ||
1625 | 1600 | ||
1626 | /** | 1601 | /** |
1627 | * Request information about the running mesh peer. | 1602 | * Request information about the running mesh peer. |
1628 | * The callback will be called for every tunnel known to the service, | 1603 | * The callback will be called for every channel known to the service, |
1629 | * listing all active peers that blong to the tunnel. | 1604 | * listing all active peers that blong to the channel. |
1630 | * | 1605 | * |
1631 | * If called again on the same handle, it will overwrite the previous | 1606 | * If called again on the same handle, it will overwrite the previous |
1632 | * callback and cls. To retrieve the cls, monitor_cancel must be | 1607 | * callback and cls. To retrieve the cls, monitor_cancel must be |
@@ -1639,17 +1614,17 @@ GNUNET_MESH_receive_done (struct GNUNET_MESH_Tunnel *tunnel) | |||
1639 | * @param callback_cls Closure for @c callback. | 1614 | * @param callback_cls Closure for @c callback. |
1640 | */ | 1615 | */ |
1641 | void | 1616 | void |
1642 | GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h, | 1617 | GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h, |
1643 | GNUNET_MESH_TunnelsCB callback, | 1618 | GNUNET_MESH_ChannelsCB callback, |
1644 | void *callback_cls) | 1619 | void *callback_cls) |
1645 | { | 1620 | { |
1646 | struct GNUNET_MessageHeader msg; | 1621 | struct GNUNET_MessageHeader msg; |
1647 | 1622 | ||
1648 | msg.size = htons (sizeof (msg)); | 1623 | msg.size = htons (sizeof (msg)); |
1649 | msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); | 1624 | msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS); |
1650 | send_packet (h, &msg, NULL); | 1625 | send_packet (h, &msg, NULL); |
1651 | h->tunnels_cb = callback; | 1626 | h->channels_cb = callback; |
1652 | h->tunnels_cls = callback_cls; | 1627 | h->channels_cls = callback_cls; |
1653 | 1628 | ||
1654 | return; | 1629 | return; |
1655 | } | 1630 | } |
@@ -1663,46 +1638,46 @@ GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h, | |||
1663 | * @return Closure given to GNUNET_MESH_monitor, if any. | 1638 | * @return Closure given to GNUNET_MESH_monitor, if any. |
1664 | */ | 1639 | */ |
1665 | void * | 1640 | void * |
1666 | GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h) | 1641 | GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h) |
1667 | { | 1642 | { |
1668 | void *cls; | 1643 | void *cls; |
1669 | 1644 | ||
1670 | cls = h->tunnels_cls; | 1645 | cls = h->channels_cls; |
1671 | h->tunnels_cb = NULL; | 1646 | h->channels_cb = NULL; |
1672 | h->tunnels_cls = NULL; | 1647 | h->channels_cls = NULL; |
1673 | return cls; | 1648 | return cls; |
1674 | } | 1649 | } |
1675 | 1650 | ||
1676 | 1651 | ||
1677 | /** | 1652 | /** |
1678 | * Request information about a specific tunnel of the running mesh peer. | 1653 | * Request information about a specific channel of the running mesh peer. |
1679 | * | 1654 | * |
1680 | * WARNING: unstable API, likely to change in the future! | 1655 | * WARNING: unstable API, likely to change in the future! |
1681 | * FIXME Add destination option. | 1656 | * FIXME Add destination option. |
1682 | * | 1657 | * |
1683 | * @param h Handle to the mesh peer. | 1658 | * @param h Handle to the mesh peer. |
1684 | * @param initiator ID of the owner of the tunnel. | 1659 | * @param initiator ID of the owner of the channel. |
1685 | * @param tunnel_number Tunnel number. | 1660 | * @param channel_number Channel number. |
1686 | * @param callback Function to call with the requested data. | 1661 | * @param callback Function to call with the requested data. |
1687 | * @param callback_cls Closure for @c callback. | 1662 | * @param callback_cls Closure for @c callback. |
1688 | */ | 1663 | */ |
1689 | void | 1664 | void |
1690 | GNUNET_MESH_show_tunnel (struct GNUNET_MESH_Handle *h, | 1665 | GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h, |
1691 | struct GNUNET_PeerIdentity *initiator, | 1666 | struct GNUNET_PeerIdentity *initiator, |
1692 | unsigned int tunnel_number, | 1667 | unsigned int channel_number, |
1693 | GNUNET_MESH_TunnelCB callback, | 1668 | GNUNET_MESH_ChannelCB callback, |
1694 | void *callback_cls) | 1669 | void *callback_cls) |
1695 | { | 1670 | { |
1696 | struct GNUNET_MESH_LocalMonitor msg; | 1671 | struct GNUNET_MESH_LocalMonitor msg; |
1697 | 1672 | ||
1698 | msg.header.size = htons (sizeof (msg)); | 1673 | msg.header.size = htons (sizeof (msg)); |
1699 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL); | 1674 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL); |
1700 | msg.owner = *initiator; | 1675 | msg.owner = *initiator; |
1701 | msg.tunnel_id = htonl (tunnel_number); | 1676 | msg.channel_id = htonl (channel_number); |
1702 | msg.reserved = 0; | 1677 | msg.reserved = 0; |
1703 | send_packet (h, &msg.header, NULL); | 1678 | send_packet (h, &msg.header, NULL); |
1704 | h->tunnel_cb = callback; | 1679 | h->channel_cb = callback; |
1705 | h->tunnel_cls = callback_cls; | 1680 | h->channel_cls = callback_cls; |
1706 | 1681 | ||
1707 | return; | 1682 | return; |
1708 | } | 1683 | } |
@@ -1728,10 +1703,6 @@ mesh_mq_ntr (void *cls, size_t size, | |||
1728 | const struct GNUNET_MessageHeader *msg = GNUNET_MQ_impl_current (mq); | 1703 | const struct GNUNET_MessageHeader *msg = GNUNET_MQ_impl_current (mq); |
1729 | uint16_t msize; | 1704 | uint16_t msize; |
1730 | 1705 | ||
1731 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "mesh-mq", | ||
1732 | "writing message (t: %u, s: %u) to buffer\n", | ||
1733 | ntohs (msg->type), ntohs (msg->size)); | ||
1734 | |||
1735 | state->th = NULL; | 1706 | state->th = NULL; |
1736 | if (NULL == buf) | 1707 | if (NULL == buf) |
1737 | { | 1708 | { |
@@ -1762,11 +1733,8 @@ mesh_mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
1762 | 1733 | ||
1763 | GNUNET_assert (NULL == state->th); | 1734 | GNUNET_assert (NULL == state->th); |
1764 | GNUNET_MQ_impl_send_commit (mq); | 1735 | GNUNET_MQ_impl_send_commit (mq); |
1765 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "mesh-mq", | ||
1766 | "calling ntr for message (t: %u, s: %u)\n", | ||
1767 | ntohs (msg->type), ntohs (msg->size)); | ||
1768 | state->th = | 1736 | state->th = |
1769 | GNUNET_MESH_notify_transmit_ready (state->tunnel, | 1737 | GNUNET_MESH_notify_transmit_ready (state->channel, |
1770 | /* FIXME: add option for corking */ | 1738 | /* FIXME: add option for corking */ |
1771 | GNUNET_NO, | 1739 | GNUNET_NO, |
1772 | GNUNET_TIME_UNIT_FOREVER_REL, | 1740 | GNUNET_TIME_UNIT_FOREVER_REL, |
@@ -1798,21 +1766,21 @@ mesh_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
1798 | 1766 | ||
1799 | 1767 | ||
1800 | /** | 1768 | /** |
1801 | * Create a message queue for a mesh tunnel. | 1769 | * Create a message queue for a mesh channel. |
1802 | * The message queue can only be used to transmit messages, | 1770 | * The message queue can only be used to transmit messages, |
1803 | * not to receive them. | 1771 | * not to receive them. |
1804 | * | 1772 | * |
1805 | * @param tunnel the tunnel to create the message qeue for | 1773 | * @param channel the channel to create the message qeue for |
1806 | * @return a message queue to messages over the tunnel | 1774 | * @return a message queue to messages over the channel |
1807 | */ | 1775 | */ |
1808 | struct GNUNET_MQ_Handle * | 1776 | struct GNUNET_MQ_Handle * |
1809 | GNUNET_MESH_mq_create (struct GNUNET_MESH_Tunnel *tunnel) | 1777 | GNUNET_MESH_mq_create (struct GNUNET_MESH_Channel *channel) |
1810 | { | 1778 | { |
1811 | struct GNUNET_MQ_Handle *mq; | 1779 | struct GNUNET_MQ_Handle *mq; |
1812 | struct MeshMQState *state; | 1780 | struct MeshMQState *state; |
1813 | 1781 | ||
1814 | state = GNUNET_new (struct MeshMQState); | 1782 | state = GNUNET_new (struct MeshMQState); |
1815 | state->tunnel = tunnel; | 1783 | state->channel = channel; |
1816 | 1784 | ||
1817 | mq = GNUNET_MQ_queue_for_callbacks (mesh_mq_send_impl, | 1785 | mq = GNUNET_MQ_queue_for_callbacks (mesh_mq_send_impl, |
1818 | mesh_mq_destroy_impl, | 1786 | mesh_mq_destroy_impl, |
diff --git a/src/mesh/mesh_api_enc.c b/src/mesh/mesh_api_enc.c deleted file mode 100644 index a8009dd26..000000000 --- a/src/mesh/mesh_api_enc.c +++ /dev/null | |||
@@ -1,1794 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011 Christian Grothoff (and other contributing authors) | ||
4 | GNUnet is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published | ||
6 | by the Free Software Foundation; either version 3, or (at your | ||
7 | option) any later version. | ||
8 | GNUnet is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | You should have received a copy of the GNU General Public License | ||
13 | along with GNUnet; see the file COPYING. If not, write to the | ||
14 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
15 | Boston, MA 02111-1307, USA. | ||
16 | */ | ||
17 | |||
18 | /** | ||
19 | * @file mesh/mesh_api_enc.c | ||
20 | * @brief mesh api: client implementation of new mesh service | ||
21 | * @author Bartlomiej Polot | ||
22 | */ | ||
23 | |||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | #include "gnunet_mesh_service_enc.h" | ||
27 | #include "mesh_enc.h" | ||
28 | #include "mesh_protocol_enc.h" | ||
29 | |||
30 | #define LOG(kind,...) GNUNET_log_from (kind, "mesh-api",__VA_ARGS__) | ||
31 | |||
32 | /******************************************************************************/ | ||
33 | /************************ DATA STRUCTURES ****************************/ | ||
34 | /******************************************************************************/ | ||
35 | |||
36 | /** | ||
37 | * Transmission queue to the service | ||
38 | */ | ||
39 | struct GNUNET_MESH_TransmitHandle | ||
40 | { | ||
41 | |||
42 | /** | ||
43 | * Double Linked list | ||
44 | */ | ||
45 | struct GNUNET_MESH_TransmitHandle *next; | ||
46 | |||
47 | /** | ||
48 | * Double Linked list | ||
49 | */ | ||
50 | struct GNUNET_MESH_TransmitHandle *prev; | ||
51 | |||
52 | /** | ||
53 | * Channel this message is sent on / for (may be NULL for control messages). | ||
54 | */ | ||
55 | struct GNUNET_MESH_Channel *channel; | ||
56 | |||
57 | /** | ||
58 | * Callback to obtain the message to transmit, or NULL if we | ||
59 | * got the message in 'data'. Notice that messages built | ||
60 | * by 'notify' need to be encapsulated with information about | ||
61 | * the 'target'. | ||
62 | */ | ||
63 | GNUNET_CONNECTION_TransmitReadyNotify notify; | ||
64 | |||
65 | /** | ||
66 | * Closure for 'notify' | ||
67 | */ | ||
68 | void *notify_cls; | ||
69 | |||
70 | /** | ||
71 | * How long is this message valid. Once the timeout has been | ||
72 | * reached, the message must no longer be sent. If this | ||
73 | * is a message with a 'notify' callback set, the 'notify' | ||
74 | * function should be called with 'buf' NULL and size 0. | ||
75 | */ | ||
76 | struct GNUNET_TIME_Absolute timeout; | ||
77 | |||
78 | /** | ||
79 | * Task triggering a timeout, can be NO_TASK if the timeout is FOREVER. | ||
80 | */ | ||
81 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | ||
82 | |||
83 | /** | ||
84 | * Size of 'data' -- or the desired size of 'notify' if 'data' is NULL. | ||
85 | */ | ||
86 | size_t size; | ||
87 | }; | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Opaque handle to the service. | ||
92 | */ | ||
93 | struct GNUNET_MESH_Handle | ||
94 | { | ||
95 | |||
96 | /** | ||
97 | * Handle to the server connection, to send messages later | ||
98 | */ | ||
99 | struct GNUNET_CLIENT_Connection *client; | ||
100 | |||
101 | /** | ||
102 | * Set of handlers used for processing incoming messages in the channels | ||
103 | */ | ||
104 | const struct GNUNET_MESH_MessageHandler *message_handlers; | ||
105 | |||
106 | /** | ||
107 | * Number of handlers in the handlers array. | ||
108 | */ | ||
109 | unsigned int n_handlers; | ||
110 | |||
111 | /** | ||
112 | * Ports open. | ||
113 | */ | ||
114 | const uint32_t *ports; | ||
115 | |||
116 | /** | ||
117 | * Number of ports. | ||
118 | */ | ||
119 | unsigned int n_ports; | ||
120 | |||
121 | /** | ||
122 | * Double linked list of the channels this client is connected to, head. | ||
123 | */ | ||
124 | struct GNUNET_MESH_Channel *channels_head; | ||
125 | |||
126 | /** | ||
127 | * Double linked list of the channels this client is connected to, tail. | ||
128 | */ | ||
129 | struct GNUNET_MESH_Channel *channels_tail; | ||
130 | |||
131 | /** | ||
132 | * Callback for inbound channel creation | ||
133 | */ | ||
134 | GNUNET_MESH_InboundChannelNotificationHandler *new_channel; | ||
135 | |||
136 | /** | ||
137 | * Callback for inbound channel disconnection | ||
138 | */ | ||
139 | GNUNET_MESH_ChannelEndHandler *cleaner; | ||
140 | |||
141 | /** | ||
142 | * Handle to cancel pending transmissions in case of disconnection | ||
143 | */ | ||
144 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
145 | |||
146 | /** | ||
147 | * Closure for all the handlers given by the client | ||
148 | */ | ||
149 | void *cls; | ||
150 | |||
151 | /** | ||
152 | * Messages to send to the service, head. | ||
153 | */ | ||
154 | struct GNUNET_MESH_TransmitHandle *th_head; | ||
155 | |||
156 | /** | ||
157 | * Messages to send to the service, tail. | ||
158 | */ | ||
159 | struct GNUNET_MESH_TransmitHandle *th_tail; | ||
160 | |||
161 | /** | ||
162 | * chid of the next channel to create (to avoid reusing IDs often) | ||
163 | */ | ||
164 | MESH_ChannelNumber next_chid; | ||
165 | |||
166 | /** | ||
167 | * Have we started the task to receive messages from the service | ||
168 | * yet? We do this after we send the 'MESH_LOCAL_CONNECT' message. | ||
169 | */ | ||
170 | int in_receive; | ||
171 | |||
172 | /** | ||
173 | * Configuration given by the client, in case of reconnection | ||
174 | */ | ||
175 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
176 | |||
177 | /** | ||
178 | * Time to the next reconnect in case one reconnect fails | ||
179 | */ | ||
180 | struct GNUNET_TIME_Relative reconnect_time; | ||
181 | |||
182 | /** | ||
183 | * Task for trying to reconnect. | ||
184 | */ | ||
185 | GNUNET_SCHEDULER_TaskIdentifier reconnect_task; | ||
186 | |||
187 | /** | ||
188 | * Monitor callback | ||
189 | */ | ||
190 | GNUNET_MESH_ChannelsCB channels_cb; | ||
191 | |||
192 | /** | ||
193 | * Monitor callback closure. | ||
194 | */ | ||
195 | void *channels_cls; | ||
196 | |||
197 | /** | ||
198 | * Channel callback. | ||
199 | */ | ||
200 | GNUNET_MESH_ChannelCB channel_cb; | ||
201 | |||
202 | /** | ||
203 | * Channel callback closure. | ||
204 | */ | ||
205 | void *channel_cls; | ||
206 | }; | ||
207 | |||
208 | |||
209 | /** | ||
210 | * Description of a peer | ||
211 | */ | ||
212 | struct GNUNET_MESH_Peer | ||
213 | { | ||
214 | /** | ||
215 | * ID of the peer in short form | ||
216 | */ | ||
217 | GNUNET_PEER_Id id; | ||
218 | |||
219 | /** | ||
220 | * Channel this peer belongs to | ||
221 | */ | ||
222 | struct GNUNET_MESH_Channel *t; | ||
223 | |||
224 | /** | ||
225 | * Flag indicating whether service has informed about its connection | ||
226 | * FIXME-BART: is this flag used? Seems dead right now... | ||
227 | */ | ||
228 | int connected; | ||
229 | |||
230 | }; | ||
231 | |||
232 | |||
233 | /** | ||
234 | * Opaque handle to a channel. | ||
235 | */ | ||
236 | struct GNUNET_MESH_Channel | ||
237 | { | ||
238 | |||
239 | /** | ||
240 | * DLL next | ||
241 | */ | ||
242 | struct GNUNET_MESH_Channel *next; | ||
243 | |||
244 | /** | ||
245 | * DLL prev | ||
246 | */ | ||
247 | struct GNUNET_MESH_Channel *prev; | ||
248 | |||
249 | /** | ||
250 | * Handle to the mesh this channel belongs to | ||
251 | */ | ||
252 | struct GNUNET_MESH_Handle *mesh; | ||
253 | |||
254 | /** | ||
255 | * Local ID of the channel | ||
256 | */ | ||
257 | MESH_ChannelNumber chid; | ||
258 | |||
259 | /** | ||
260 | * Port number. | ||
261 | */ | ||
262 | uint32_t port; | ||
263 | |||
264 | /** | ||
265 | * Other end of the channel. | ||
266 | */ | ||
267 | GNUNET_PEER_Id peer; | ||
268 | |||
269 | /** | ||
270 | * Any data the caller wants to put in here | ||
271 | */ | ||
272 | void *ctx; | ||
273 | |||
274 | /** | ||
275 | * Size of packet queued in this channel | ||
276 | */ | ||
277 | unsigned int packet_size; | ||
278 | |||
279 | /** | ||
280 | * Is the channel allowed to buffer? | ||
281 | */ | ||
282 | int nobuffer; | ||
283 | |||
284 | /** | ||
285 | * Is the channel realiable? | ||
286 | */ | ||
287 | int reliable; | ||
288 | |||
289 | /** | ||
290 | * If reliable, is the channel out of order? | ||
291 | */ | ||
292 | int ooorder; | ||
293 | |||
294 | /** | ||
295 | * Are we allowed to send to the service? | ||
296 | */ | ||
297 | int allow_send; | ||
298 | |||
299 | }; | ||
300 | |||
301 | |||
302 | /** | ||
303 | * Implementation state for mesh's message queue. | ||
304 | */ | ||
305 | struct MeshMQState | ||
306 | { | ||
307 | /** | ||
308 | * The current transmit handle, or NULL | ||
309 | * if no transmit is active. | ||
310 | */ | ||
311 | struct GNUNET_MESH_TransmitHandle *th; | ||
312 | |||
313 | /** | ||
314 | * Channel to send the data over. | ||
315 | */ | ||
316 | struct GNUNET_MESH_Channel *channel; | ||
317 | }; | ||
318 | |||
319 | |||
320 | /******************************************************************************/ | ||
321 | /*********************** DECLARATIONS *************************/ | ||
322 | /******************************************************************************/ | ||
323 | |||
324 | /** | ||
325 | * Function called to send a message to the service. | ||
326 | * "buf" will be NULL and "size" zero if the socket was closed for writing in | ||
327 | * the meantime. | ||
328 | * | ||
329 | * @param cls closure, the mesh handle | ||
330 | * @param size number of bytes available in buf | ||
331 | * @param buf where the callee should write the connect message | ||
332 | * @return number of bytes written to buf | ||
333 | */ | ||
334 | static size_t | ||
335 | send_callback (void *cls, size_t size, void *buf); | ||
336 | |||
337 | |||
338 | /******************************************************************************/ | ||
339 | /*********************** AUXILIARY FUNCTIONS *************************/ | ||
340 | /******************************************************************************/ | ||
341 | |||
342 | /** | ||
343 | * Check if transmission is a payload packet. | ||
344 | * | ||
345 | * @param th Transmission handle. | ||
346 | * | ||
347 | * @return GNUNET_YES if it is a payload packet, | ||
348 | * GNUNET_NO if it is a mesh management packet. | ||
349 | */ | ||
350 | static int | ||
351 | th_is_payload (struct GNUNET_MESH_TransmitHandle *th) | ||
352 | { | ||
353 | return (th->notify != NULL) ? GNUNET_YES : GNUNET_NO; | ||
354 | } | ||
355 | |||
356 | |||
357 | /** | ||
358 | * Check whether there is any message ready in the queue and find the size. | ||
359 | * | ||
360 | * @param h Mesh handle. | ||
361 | * | ||
362 | * @return The size of the first ready message in the queue, | ||
363 | * 0 if there is none. | ||
364 | */ | ||
365 | static size_t | ||
366 | message_ready_size (struct GNUNET_MESH_Handle *h) | ||
367 | { | ||
368 | struct GNUNET_MESH_TransmitHandle *th; | ||
369 | struct GNUNET_MESH_Channel *ch; | ||
370 | |||
371 | for (th = h->th_head; NULL != th; th = th->next) | ||
372 | { | ||
373 | ch = th->channel; | ||
374 | if (GNUNET_NO == th_is_payload (th)) | ||
375 | { | ||
376 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# message internal\n"); | ||
377 | return th->size; | ||
378 | } | ||
379 | if (GNUNET_YES == ch->allow_send) | ||
380 | { | ||
381 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# message payload ok\n"); | ||
382 | return th->size; | ||
383 | } | ||
384 | } | ||
385 | return 0; | ||
386 | } | ||
387 | |||
388 | |||
389 | /** | ||
390 | * Get the channel handler for the channel specified by id from the given handle | ||
391 | * @param h Mesh handle | ||
392 | * @param chid ID of the wanted channel | ||
393 | * @return handle to the required channel or NULL if not found | ||
394 | */ | ||
395 | static struct GNUNET_MESH_Channel * | ||
396 | retrieve_channel (struct GNUNET_MESH_Handle *h, MESH_ChannelNumber chid) | ||
397 | { | ||
398 | struct GNUNET_MESH_Channel *ch; | ||
399 | |||
400 | ch = h->channels_head; | ||
401 | while (ch != NULL) | ||
402 | { | ||
403 | if (ch->chid == chid) | ||
404 | return ch; | ||
405 | ch = ch->next; | ||
406 | } | ||
407 | return NULL; | ||
408 | } | ||
409 | |||
410 | |||
411 | /** | ||
412 | * Create a new channel and insert it in the channel list of the mesh handle | ||
413 | * | ||
414 | * @param h Mesh handle | ||
415 | * @param chid Desired chid of the channel, 0 to assign one automatically. | ||
416 | * | ||
417 | * @return Handle to the created channel. | ||
418 | */ | ||
419 | static struct GNUNET_MESH_Channel * | ||
420 | create_channel (struct GNUNET_MESH_Handle *h, MESH_ChannelNumber chid) | ||
421 | { | ||
422 | struct GNUNET_MESH_Channel *ch; | ||
423 | |||
424 | ch = GNUNET_malloc (sizeof (struct GNUNET_MESH_Channel)); | ||
425 | GNUNET_CONTAINER_DLL_insert (h->channels_head, h->channels_tail, ch); | ||
426 | ch->mesh = h; | ||
427 | if (0 == chid) | ||
428 | { | ||
429 | ch->chid = h->next_chid; | ||
430 | while (NULL != retrieve_channel (h, h->next_chid)) | ||
431 | { | ||
432 | h->next_chid++; | ||
433 | h->next_chid &= ~GNUNET_MESH_LOCAL_CHANNEL_ID_SERV; | ||
434 | h->next_chid |= GNUNET_MESH_LOCAL_CHANNEL_ID_CLI; | ||
435 | } | ||
436 | } | ||
437 | else | ||
438 | { | ||
439 | ch->chid = chid; | ||
440 | } | ||
441 | ch->allow_send = GNUNET_NO; | ||
442 | ch->nobuffer = GNUNET_NO; | ||
443 | return ch; | ||
444 | } | ||
445 | |||
446 | |||
447 | /** | ||
448 | * Destroy the specified channel. | ||
449 | * - Destroys all peers, calling the disconnect callback on each if needed | ||
450 | * - Cancels all outgoing traffic for that channel, calling respective notifys | ||
451 | * - Calls cleaner if channel was inbound | ||
452 | * - Frees all memory used | ||
453 | * | ||
454 | * @param ch Pointer to the channel. | ||
455 | * @param call_cleaner Whether to call the cleaner handler. | ||
456 | * | ||
457 | * @return Handle to the required channel or NULL if not found. | ||
458 | */ | ||
459 | static void | ||
460 | destroy_channel (struct GNUNET_MESH_Channel *ch, int call_cleaner) | ||
461 | { | ||
462 | struct GNUNET_MESH_Handle *h; | ||
463 | struct GNUNET_MESH_TransmitHandle *th; | ||
464 | struct GNUNET_MESH_TransmitHandle *next; | ||
465 | |||
466 | LOG (GNUNET_ERROR_TYPE_DEBUG, "destroy_channel %X\n", ch->chid); | ||
467 | |||
468 | if (NULL == ch) | ||
469 | { | ||
470 | GNUNET_break (0); | ||
471 | return; | ||
472 | } | ||
473 | h = ch->mesh; | ||
474 | |||
475 | GNUNET_CONTAINER_DLL_remove (h->channels_head, h->channels_tail, ch); | ||
476 | |||
477 | /* signal channel destruction */ | ||
478 | if ( (NULL != h->cleaner) && (0 != ch->peer) && (GNUNET_YES == call_cleaner) ) | ||
479 | h->cleaner (h->cls, ch, ch->ctx); | ||
480 | |||
481 | /* check that clients did not leave messages behind in the queue */ | ||
482 | for (th = h->th_head; NULL != th; th = next) | ||
483 | { | ||
484 | next = th->next; | ||
485 | if (th->channel != ch) | ||
486 | continue; | ||
487 | /* Clients should have aborted their requests already. | ||
488 | * Management traffic should be ok, as clients can't cancel that */ | ||
489 | GNUNET_break (GNUNET_NO == th_is_payload (th)); | ||
490 | GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); | ||
491 | |||
492 | /* clean up request */ | ||
493 | if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task) | ||
494 | GNUNET_SCHEDULER_cancel (th->timeout_task); | ||
495 | GNUNET_free (th); | ||
496 | } | ||
497 | |||
498 | /* if there are no more pending requests with mesh service, cancel active request */ | ||
499 | /* Note: this should be unnecessary... */ | ||
500 | if ((0 == message_ready_size (h)) && (NULL != h->th)) | ||
501 | { | ||
502 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | ||
503 | h->th = NULL; | ||
504 | } | ||
505 | |||
506 | if (0 != ch->peer) | ||
507 | GNUNET_PEER_change_rc (ch->peer, -1); | ||
508 | GNUNET_free (ch); | ||
509 | return; | ||
510 | } | ||
511 | |||
512 | |||
513 | /** | ||
514 | * Notify client that the transmission has timed out | ||
515 | * | ||
516 | * @param cls closure | ||
517 | * @param tc task context | ||
518 | */ | ||
519 | static void | ||
520 | timeout_transmission (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
521 | { | ||
522 | struct GNUNET_MESH_TransmitHandle *th = cls; | ||
523 | struct GNUNET_MESH_Handle *mesh; | ||
524 | |||
525 | mesh = th->channel->mesh; | ||
526 | GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th); | ||
527 | th->channel->packet_size = 0; | ||
528 | if (GNUNET_YES == th_is_payload (th)) | ||
529 | th->notify (th->notify_cls, 0, NULL); | ||
530 | GNUNET_free (th); | ||
531 | if ((0 == message_ready_size (mesh)) && (NULL != mesh->th)) | ||
532 | { | ||
533 | /* nothing ready to transmit, no point in asking for transmission */ | ||
534 | GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th); | ||
535 | mesh->th = NULL; | ||
536 | } | ||
537 | } | ||
538 | |||
539 | |||
540 | /** | ||
541 | * Add a transmit handle to the transmission queue and set the | ||
542 | * timeout if needed. | ||
543 | * | ||
544 | * @param h mesh handle with the queue head and tail | ||
545 | * @param th handle to the packet to be transmitted | ||
546 | */ | ||
547 | static void | ||
548 | add_to_queue (struct GNUNET_MESH_Handle *h, | ||
549 | struct GNUNET_MESH_TransmitHandle *th) | ||
550 | { | ||
551 | GNUNET_CONTAINER_DLL_insert_tail (h->th_head, h->th_tail, th); | ||
552 | if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == th->timeout.abs_value_us) | ||
553 | return; | ||
554 | th->timeout_task = | ||
555 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining | ||
556 | (th->timeout), &timeout_transmission, th); | ||
557 | } | ||
558 | |||
559 | |||
560 | /** | ||
561 | * Auxiliary function to send an already constructed packet to the service. | ||
562 | * Takes care of creating a new queue element, copying the message and | ||
563 | * calling the tmt_rdy function if necessary. | ||
564 | * | ||
565 | * @param h mesh handle | ||
566 | * @param msg message to transmit | ||
567 | * @param channel channel this send is related to (NULL if N/A) | ||
568 | */ | ||
569 | static void | ||
570 | send_packet (struct GNUNET_MESH_Handle *h, | ||
571 | const struct GNUNET_MessageHeader *msg, | ||
572 | struct GNUNET_MESH_Channel *channel); | ||
573 | |||
574 | |||
575 | /** | ||
576 | * Send an ack on the channel to confirm the processing of a message. | ||
577 | * | ||
578 | * @param ch Channel on which to send the ACK. | ||
579 | */ | ||
580 | static void | ||
581 | send_ack (struct GNUNET_MESH_Channel *ch) | ||
582 | { | ||
583 | struct GNUNET_MESH_LocalAck msg; | ||
584 | |||
585 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK on channel %X\n", ch->chid); | ||
586 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK); | ||
587 | msg.header.size = htons (sizeof (msg)); | ||
588 | msg.channel_id = htonl (ch->chid); | ||
589 | |||
590 | send_packet (ch->mesh, &msg.header, ch); | ||
591 | return; | ||
592 | } | ||
593 | |||
594 | |||
595 | |||
596 | /** | ||
597 | * Reconnect callback: tries to reconnect again after a failer previous | ||
598 | * reconnecttion | ||
599 | * @param cls closure (mesh handle) | ||
600 | * @param tc task context | ||
601 | */ | ||
602 | static void | ||
603 | reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
604 | |||
605 | |||
606 | /** | ||
607 | * Send a connect packet to the service with the applications and types | ||
608 | * requested by the user. | ||
609 | * | ||
610 | * @param h The mesh handle. | ||
611 | * | ||
612 | */ | ||
613 | static void | ||
614 | send_connect (struct GNUNET_MESH_Handle *h) | ||
615 | { | ||
616 | size_t size; | ||
617 | |||
618 | size = sizeof (struct GNUNET_MESH_ClientConnect); | ||
619 | size += h->n_ports * sizeof (uint32_t); | ||
620 | { | ||
621 | char buf[size] GNUNET_ALIGN; | ||
622 | struct GNUNET_MESH_ClientConnect *msg; | ||
623 | uint32_t *ports; | ||
624 | uint16_t i; | ||
625 | |||
626 | /* build connection packet */ | ||
627 | msg = (struct GNUNET_MESH_ClientConnect *) buf; | ||
628 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); | ||
629 | msg->header.size = htons (size); | ||
630 | ports = (uint32_t *) &msg[1]; | ||
631 | for (i = 0; i < h->n_ports; i++) | ||
632 | { | ||
633 | ports[i] = htonl (h->ports[i]); | ||
634 | LOG (GNUNET_ERROR_TYPE_DEBUG, " port %u\n", | ||
635 | h->ports[i]); | ||
636 | } | ||
637 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
638 | "Sending %lu bytes long message with %u ports\n", | ||
639 | ntohs (msg->header.size), h->n_ports); | ||
640 | send_packet (h, &msg->header, NULL); | ||
641 | } | ||
642 | } | ||
643 | |||
644 | |||
645 | /** | ||
646 | * Reconnect to the service, retransmit all infomation to try to restore the | ||
647 | * original state. | ||
648 | * | ||
649 | * @param h handle to the mesh | ||
650 | * | ||
651 | * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...) | ||
652 | */ | ||
653 | static int | ||
654 | do_reconnect (struct GNUNET_MESH_Handle *h) | ||
655 | { | ||
656 | struct GNUNET_MESH_Channel *ch; | ||
657 | |||
658 | LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n"); | ||
659 | LOG (GNUNET_ERROR_TYPE_DEBUG, "******* RECONNECT *******\n"); | ||
660 | LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n"); | ||
661 | LOG (GNUNET_ERROR_TYPE_DEBUG, "******** on %p *******\n", h); | ||
662 | LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n"); | ||
663 | |||
664 | /* disconnect */ | ||
665 | if (NULL != h->th) | ||
666 | { | ||
667 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | ||
668 | h->th = NULL; | ||
669 | } | ||
670 | if (NULL != h->client) | ||
671 | { | ||
672 | GNUNET_CLIENT_disconnect (h->client); | ||
673 | } | ||
674 | |||
675 | /* connect again */ | ||
676 | h->client = GNUNET_CLIENT_connect ("mesh", h->cfg); | ||
677 | if (h->client == NULL) | ||
678 | { | ||
679 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time, | ||
680 | &reconnect_cbk, h); | ||
681 | h->reconnect_time = | ||
682 | GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, | ||
683 | GNUNET_TIME_relative_multiply | ||
684 | (h->reconnect_time, 2)); | ||
685 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Next retry in %s\n", | ||
686 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_time, | ||
687 | GNUNET_NO)); | ||
688 | GNUNET_break (0); | ||
689 | return GNUNET_NO; | ||
690 | } | ||
691 | else | ||
692 | { | ||
693 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; | ||
694 | } | ||
695 | send_connect (h); | ||
696 | /* Rebuild all channels */ | ||
697 | for (ch = h->channels_head; NULL != ch; ch = ch->next) | ||
698 | { | ||
699 | struct GNUNET_MESH_ChannelMessage tmsg; | ||
700 | uint32_t options; | ||
701 | |||
702 | if (ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) | ||
703 | { | ||
704 | /* Channel was created by service (incoming channel) */ | ||
705 | /* TODO: Notify service of missing channel, to request | ||
706 | * creator to recreate path (find a path to him via DHT?) | ||
707 | */ | ||
708 | continue; | ||
709 | } | ||
710 | ch->allow_send = GNUNET_NO; | ||
711 | tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE); | ||
712 | tmsg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage)); | ||
713 | tmsg.channel_id = htonl (ch->chid); | ||
714 | tmsg.port = htonl (ch->port); | ||
715 | GNUNET_PEER_resolve (ch->peer, &tmsg.peer); | ||
716 | |||
717 | options = 0; | ||
718 | if (GNUNET_YES == ch->nobuffer) | ||
719 | options |= GNUNET_MESH_OPTION_NOBUFFER; | ||
720 | |||
721 | if (GNUNET_YES == ch->reliable) | ||
722 | options |= GNUNET_MESH_OPTION_RELIABLE; | ||
723 | |||
724 | tmsg.opt = htonl (options); | ||
725 | send_packet (h, &tmsg.header, ch); | ||
726 | } | ||
727 | return GNUNET_YES; | ||
728 | } | ||
729 | |||
730 | /** | ||
731 | * Reconnect callback: tries to reconnect again after a failer previous | ||
732 | * reconnecttion | ||
733 | * @param cls closure (mesh handle) | ||
734 | * @param tc task context | ||
735 | */ | ||
736 | static void | ||
737 | reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
738 | { | ||
739 | struct GNUNET_MESH_Handle *h = cls; | ||
740 | |||
741 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
742 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
743 | return; | ||
744 | do_reconnect (h); | ||
745 | } | ||
746 | |||
747 | |||
748 | /** | ||
749 | * Reconnect to the service, retransmit all infomation to try to restore the | ||
750 | * original state. | ||
751 | * | ||
752 | * @param h handle to the mesh | ||
753 | * | ||
754 | * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...) | ||
755 | */ | ||
756 | static void | ||
757 | reconnect (struct GNUNET_MESH_Handle *h) | ||
758 | { | ||
759 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requested RECONNECT\n"); | ||
760 | h->in_receive = GNUNET_NO; | ||
761 | if (GNUNET_SCHEDULER_NO_TASK == h->reconnect_task) | ||
762 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time, | ||
763 | &reconnect_cbk, h); | ||
764 | } | ||
765 | |||
766 | |||
767 | /******************************************************************************/ | ||
768 | /*********************** RECEIVE HANDLERS ****************************/ | ||
769 | /******************************************************************************/ | ||
770 | |||
771 | /** | ||
772 | * Process the new channel notification and add it to the channels in the handle | ||
773 | * | ||
774 | * @param h The mesh handle | ||
775 | * @param msg A message with the details of the new incoming channel | ||
776 | */ | ||
777 | static void | ||
778 | process_channel_created (struct GNUNET_MESH_Handle *h, | ||
779 | const struct GNUNET_MESH_ChannelMessage *msg) | ||
780 | { | ||
781 | struct GNUNET_MESH_Channel *ch; | ||
782 | MESH_ChannelNumber chid; | ||
783 | uint32_t port; | ||
784 | |||
785 | chid = ntohl (msg->channel_id); | ||
786 | port = ntohl (msg->port); | ||
787 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming channel %X:%u\n", chid, port); | ||
788 | if (chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) | ||
789 | { | ||
790 | GNUNET_break (0); | ||
791 | return; | ||
792 | } | ||
793 | if (NULL != h->new_channel) | ||
794 | { | ||
795 | ch = create_channel (h, chid); | ||
796 | ch->allow_send = GNUNET_NO; | ||
797 | ch->peer = GNUNET_PEER_intern (&msg->peer); | ||
798 | ch->mesh = h; | ||
799 | ch->chid = chid; | ||
800 | ch->port = port; | ||
801 | if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER)) | ||
802 | ch->nobuffer = GNUNET_YES; | ||
803 | else | ||
804 | ch->nobuffer = GNUNET_NO; | ||
805 | |||
806 | if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE)) | ||
807 | ch->reliable = GNUNET_YES; | ||
808 | else | ||
809 | ch->reliable = GNUNET_NO; | ||
810 | |||
811 | if (GNUNET_YES == ch->reliable && | ||
812 | 0 != (msg->opt & GNUNET_MESH_OPTION_OOORDER)) | ||
813 | ch->ooorder = GNUNET_YES; | ||
814 | else | ||
815 | ch->ooorder = GNUNET_NO; | ||
816 | |||
817 | LOG (GNUNET_ERROR_TYPE_DEBUG, " created channel %p\n", ch); | ||
818 | ch->ctx = h->new_channel (h->cls, ch, &msg->peer, ch->port); | ||
819 | LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); | ||
820 | } | ||
821 | else | ||
822 | { | ||
823 | struct GNUNET_MESH_ChannelMessage d_msg; | ||
824 | |||
825 | LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming channels\n"); | ||
826 | |||
827 | d_msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY); | ||
828 | d_msg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage)); | ||
829 | d_msg.channel_id = msg->channel_id; | ||
830 | memset (&d_msg.peer, 0, sizeof (struct GNUNET_PeerIdentity)); | ||
831 | d_msg.port = 0; | ||
832 | d_msg.opt = 0; | ||
833 | |||
834 | send_packet (h, &d_msg.header, NULL); | ||
835 | } | ||
836 | return; | ||
837 | } | ||
838 | |||
839 | |||
840 | /** | ||
841 | * Process the channel destroy notification and free associated resources | ||
842 | * | ||
843 | * @param h The mesh handle | ||
844 | * @param msg A message with the details of the channel being destroyed | ||
845 | */ | ||
846 | static void | ||
847 | process_channel_destroy (struct GNUNET_MESH_Handle *h, | ||
848 | const struct GNUNET_MESH_ChannelMessage *msg) | ||
849 | { | ||
850 | struct GNUNET_MESH_Channel *ch; | ||
851 | MESH_ChannelNumber chid; | ||
852 | |||
853 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying channel from service\n"); | ||
854 | chid = ntohl (msg->channel_id); | ||
855 | ch = retrieve_channel (h, chid); | ||
856 | |||
857 | if (NULL == ch) | ||
858 | { | ||
859 | LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X unknown\n", chid); | ||
860 | return; | ||
861 | } | ||
862 | LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X destroyed\n", ch->chid); | ||
863 | destroy_channel (ch, GNUNET_YES); | ||
864 | } | ||
865 | |||
866 | |||
867 | /** | ||
868 | * Process the incoming data packets, call appropriate handlers. | ||
869 | * | ||
870 | * @param h The mesh handle | ||
871 | * @param message A message encapsulating the data | ||
872 | */ | ||
873 | static void | ||
874 | process_incoming_data (struct GNUNET_MESH_Handle *h, | ||
875 | const struct GNUNET_MessageHeader *message) | ||
876 | { | ||
877 | const struct GNUNET_MessageHeader *payload; | ||
878 | const struct GNUNET_MESH_MessageHandler *handler; | ||
879 | struct GNUNET_MESH_LocalData *dmsg; | ||
880 | struct GNUNET_MESH_Channel *ch; | ||
881 | unsigned int i; | ||
882 | uint16_t type; | ||
883 | |||
884 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n"); | ||
885 | |||
886 | dmsg = (struct GNUNET_MESH_LocalData *) message; | ||
887 | |||
888 | ch = retrieve_channel (h, ntohl (dmsg->id)); | ||
889 | payload = (struct GNUNET_MessageHeader *) &dmsg[1]; | ||
890 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n", | ||
891 | ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ? "fwd" : "bck", | ||
892 | GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)), ntohl (dmsg->id)); | ||
893 | if (NULL == ch) | ||
894 | { | ||
895 | /* Channel was ignored/destroyed, probably service didn't get it yet */ | ||
896 | LOG (GNUNET_ERROR_TYPE_DEBUG, " ignored!\n"); | ||
897 | return; | ||
898 | } | ||
899 | type = ntohs (payload->type); | ||
900 | LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %u\n", type); | ||
901 | for (i = 0; i < h->n_handlers; i++) | ||
902 | { | ||
903 | handler = &h->message_handlers[i]; | ||
904 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
905 | " checking handler for type %u\n", | ||
906 | handler->type); | ||
907 | if (handler->type == type) | ||
908 | { | ||
909 | if (GNUNET_OK != | ||
910 | handler->callback (h->cls, ch, &ch->ctx, payload)) | ||
911 | { | ||
912 | LOG (GNUNET_ERROR_TYPE_DEBUG, "callback caused disconnection\n"); | ||
913 | GNUNET_MESH_channel_destroy (ch); | ||
914 | return; | ||
915 | } | ||
916 | else | ||
917 | { | ||
918 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
919 | "callback completed successfully\n"); | ||
920 | } | ||
921 | } | ||
922 | } | ||
923 | } | ||
924 | |||
925 | |||
926 | /** | ||
927 | * Process a local ACK message, enabling the client to send | ||
928 | * more data to the service. | ||
929 | * | ||
930 | * @param h Mesh handle. | ||
931 | * @param message Message itself. | ||
932 | */ | ||
933 | static void | ||
934 | process_ack (struct GNUNET_MESH_Handle *h, | ||
935 | const struct GNUNET_MessageHeader *message) | ||
936 | { | ||
937 | struct GNUNET_MESH_LocalAck *msg; | ||
938 | struct GNUNET_MESH_Channel *ch; | ||
939 | MESH_ChannelNumber chid; | ||
940 | |||
941 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n"); | ||
942 | msg = (struct GNUNET_MESH_LocalAck *) message; | ||
943 | chid = ntohl (msg->channel_id); | ||
944 | ch = retrieve_channel (h, chid); | ||
945 | if (NULL == ch) | ||
946 | { | ||
947 | LOG (GNUNET_ERROR_TYPE_WARNING, "ACK on unknown channel %X\n", chid); | ||
948 | return; | ||
949 | } | ||
950 | LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X!\n", ch->chid); | ||
951 | ch->allow_send = GNUNET_YES; | ||
952 | if (NULL == h->th && 0 < ch->packet_size) | ||
953 | { | ||
954 | LOG (GNUNET_ERROR_TYPE_DEBUG, " tmt rdy was NULL, requesting!\n"); | ||
955 | h->th = | ||
956 | GNUNET_CLIENT_notify_transmit_ready (h->client, ch->packet_size, | ||
957 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
958 | GNUNET_YES, &send_callback, h); | ||
959 | } | ||
960 | } | ||
961 | |||
962 | |||
963 | /* | ||
964 | * Process a local reply about info on all channels, pass info to the user. | ||
965 | * | ||
966 | * @param h Mesh handle. | ||
967 | * @param message Message itself. | ||
968 | */ | ||
969 | // static void | ||
970 | // process_get_channels (struct GNUNET_MESH_Handle *h, | ||
971 | // const struct GNUNET_MessageHeader *message) | ||
972 | // { | ||
973 | // struct GNUNET_MESH_LocalMonitor *msg; | ||
974 | // | ||
975 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n"); | ||
976 | // | ||
977 | // if (NULL == h->channels_cb) | ||
978 | // { | ||
979 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); | ||
980 | // return; | ||
981 | // } | ||
982 | // | ||
983 | // msg = (struct GNUNET_MESH_LocalMonitor *) message; | ||
984 | // if (ntohs (message->size) != | ||
985 | // (sizeof (struct GNUNET_MESH_LocalMonitor) + | ||
986 | // sizeof (struct GNUNET_PeerIdentity))) | ||
987 | // { | ||
988 | // GNUNET_break_op (0); | ||
989 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
990 | // "Get channels message: size %hu - expected %u\n", | ||
991 | // ntohs (message->size), | ||
992 | // sizeof (struct GNUNET_MESH_LocalMonitor)); | ||
993 | // return; | ||
994 | // } | ||
995 | // h->channels_cb (h->channels_cls, | ||
996 | // ntohl (msg->channel_id), | ||
997 | // &msg->owner, | ||
998 | // &msg->destination); | ||
999 | // } | ||
1000 | |||
1001 | |||
1002 | |||
1003 | /* | ||
1004 | * Process a local monitor_channel reply, pass info to the user. | ||
1005 | * | ||
1006 | * @param h Mesh handle. | ||
1007 | * @param message Message itself. | ||
1008 | */ | ||
1009 | // static void | ||
1010 | // process_show_channel (struct GNUNET_MESH_Handle *h, | ||
1011 | // const struct GNUNET_MessageHeader *message) | ||
1012 | // { | ||
1013 | // struct GNUNET_MESH_LocalMonitor *msg; | ||
1014 | // size_t esize; | ||
1015 | // | ||
1016 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n"); | ||
1017 | // | ||
1018 | // if (NULL == h->channel_cb) | ||
1019 | // { | ||
1020 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); | ||
1021 | // return; | ||
1022 | // } | ||
1023 | // | ||
1024 | // /* Verify message sanity */ | ||
1025 | // msg = (struct GNUNET_MESH_LocalMonitor *) message; | ||
1026 | // esize = sizeof (struct GNUNET_MESH_LocalMonitor); | ||
1027 | // if (ntohs (message->size) != esize) | ||
1028 | // { | ||
1029 | // GNUNET_break_op (0); | ||
1030 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1031 | // "Show channel message: size %hu - expected %u\n", | ||
1032 | // ntohs (message->size), | ||
1033 | // esize); | ||
1034 | // | ||
1035 | // h->channel_cb (h->channel_cls, NULL, NULL); | ||
1036 | // h->channel_cb = NULL; | ||
1037 | // h->channel_cls = NULL; | ||
1038 | // | ||
1039 | // return; | ||
1040 | // } | ||
1041 | // | ||
1042 | // h->channel_cb (h->channel_cls, | ||
1043 | // &msg->destination, | ||
1044 | // &msg->owner); | ||
1045 | // } | ||
1046 | |||
1047 | |||
1048 | /** | ||
1049 | * Function to process all messages received from the service | ||
1050 | * | ||
1051 | * @param cls closure | ||
1052 | * @param msg message received, NULL on timeout or fatal error | ||
1053 | */ | ||
1054 | static void | ||
1055 | msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | ||
1056 | { | ||
1057 | struct GNUNET_MESH_Handle *h = cls; | ||
1058 | uint16_t type; | ||
1059 | |||
1060 | if (msg == NULL) | ||
1061 | { | ||
1062 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1063 | "Mesh service disconnected, reconnecting\n", h); | ||
1064 | reconnect (h); | ||
1065 | return; | ||
1066 | } | ||
1067 | type = ntohs (msg->type); | ||
1068 | LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); | ||
1069 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a message: %s\n", | ||
1070 | GNUNET_MESH_DEBUG_M2S (type)); | ||
1071 | switch (type) | ||
1072 | { | ||
1073 | /* Notify of a new incoming channel */ | ||
1074 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: | ||
1075 | process_channel_created (h, (struct GNUNET_MESH_ChannelMessage *) msg); | ||
1076 | break; | ||
1077 | /* Notify of a channel disconnection */ | ||
1078 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: | ||
1079 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_NACK: | ||
1080 | process_channel_destroy (h, (struct GNUNET_MESH_ChannelMessage *) msg); | ||
1081 | break; | ||
1082 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA: | ||
1083 | process_incoming_data (h, msg); | ||
1084 | break; | ||
1085 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: | ||
1086 | process_ack (h, msg); | ||
1087 | break; | ||
1088 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: DEPRECATED | ||
1089 | // process_get_channels (h, msg); | ||
1090 | // break; | ||
1091 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: DEPRECATED | ||
1092 | // process_show_channel (h, msg); | ||
1093 | // break; | ||
1094 | default: | ||
1095 | /* We shouldn't get any other packages, log and ignore */ | ||
1096 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1097 | "unsolicited message form service (type %s)\n", | ||
1098 | GNUNET_MESH_DEBUG_M2S (ntohs (msg->type))); | ||
1099 | } | ||
1100 | LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n"); | ||
1101 | if (GNUNET_YES == h->in_receive) | ||
1102 | { | ||
1103 | GNUNET_CLIENT_receive (h->client, &msg_received, h, | ||
1104 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1105 | } | ||
1106 | else | ||
1107 | { | ||
1108 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1109 | "in receive off, not calling CLIENT_receive\n"); | ||
1110 | } | ||
1111 | } | ||
1112 | |||
1113 | |||
1114 | /******************************************************************************/ | ||
1115 | /************************ SEND FUNCTIONS ****************************/ | ||
1116 | /******************************************************************************/ | ||
1117 | |||
1118 | /** | ||
1119 | * Function called to send a message to the service. | ||
1120 | * "buf" will be NULL and "size" zero if the socket was closed for writing in | ||
1121 | * the meantime. | ||
1122 | * | ||
1123 | * @param cls closure, the mesh handle | ||
1124 | * @param size number of bytes available in buf | ||
1125 | * @param buf where the callee should write the connect message | ||
1126 | * @return number of bytes written to buf | ||
1127 | */ | ||
1128 | static size_t | ||
1129 | send_callback (void *cls, size_t size, void *buf) | ||
1130 | { | ||
1131 | struct GNUNET_MESH_Handle *h = cls; | ||
1132 | struct GNUNET_MESH_TransmitHandle *th; | ||
1133 | struct GNUNET_MESH_TransmitHandle *next; | ||
1134 | struct GNUNET_MESH_Channel *ch; | ||
1135 | char *cbuf = buf; | ||
1136 | size_t tsize; | ||
1137 | size_t psize; | ||
1138 | size_t nsize; | ||
1139 | |||
1140 | LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); | ||
1141 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# Send packet() Buffer %u\n", size); | ||
1142 | if ((0 == size) || (NULL == buf)) | ||
1143 | { | ||
1144 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# Received NULL send callback on %p\n", h); | ||
1145 | reconnect (h); | ||
1146 | h->th = NULL; | ||
1147 | return 0; | ||
1148 | } | ||
1149 | tsize = 0; | ||
1150 | next = h->th_head; | ||
1151 | nsize = message_ready_size (h); | ||
1152 | while ((NULL != (th = next)) && (0 < nsize) && (size >= nsize)) | ||
1153 | { | ||
1154 | ch = th->channel; | ||
1155 | if (GNUNET_YES == th_is_payload (th)) | ||
1156 | { | ||
1157 | struct GNUNET_MESH_LocalData *dmsg; | ||
1158 | struct GNUNET_MessageHeader *mh; | ||
1159 | |||
1160 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload\n"); | ||
1161 | if (GNUNET_NO == ch->allow_send) | ||
1162 | { | ||
1163 | /* This channel is not ready to transmit yet, try next message */ | ||
1164 | next = th->next; | ||
1165 | continue; | ||
1166 | } | ||
1167 | ch->packet_size = 0; | ||
1168 | GNUNET_assert (size >= th->size); | ||
1169 | dmsg = (struct GNUNET_MESH_LocalData *) cbuf; | ||
1170 | mh = (struct GNUNET_MessageHeader *) &dmsg[1]; | ||
1171 | psize = th->notify (th->notify_cls, | ||
1172 | size - sizeof (struct GNUNET_MESH_LocalData), | ||
1173 | mh); | ||
1174 | if (psize > 0) | ||
1175 | { | ||
1176 | psize += sizeof (struct GNUNET_MESH_LocalData); | ||
1177 | GNUNET_assert (size >= psize); | ||
1178 | dmsg->header.size = htons (psize); | ||
1179 | dmsg->id = htonl (ch->chid); | ||
1180 | dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA); | ||
1181 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n", | ||
1182 | GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); | ||
1183 | ch->allow_send = GNUNET_NO; | ||
1184 | } | ||
1185 | else | ||
1186 | { | ||
1187 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1188 | "# callback returned size 0, " | ||
1189 | "application canceled transmission\n"); | ||
1190 | } | ||
1191 | } | ||
1192 | else | ||
1193 | { | ||
1194 | struct GNUNET_MessageHeader *mh = (struct GNUNET_MessageHeader *) &th[1]; | ||
1195 | |||
1196 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# mesh internal traffic, type %s\n", | ||
1197 | GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); | ||
1198 | memcpy (cbuf, &th[1], th->size); | ||
1199 | psize = th->size; | ||
1200 | } | ||
1201 | if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
1202 | GNUNET_SCHEDULER_cancel (th->timeout_task); | ||
1203 | GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); | ||
1204 | GNUNET_free (th); | ||
1205 | next = h->th_head; | ||
1206 | nsize = message_ready_size (h); | ||
1207 | cbuf += psize; | ||
1208 | size -= psize; | ||
1209 | tsize += psize; | ||
1210 | } | ||
1211 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# total size: %u\n", tsize); | ||
1212 | h->th = NULL; | ||
1213 | size = message_ready_size (h); | ||
1214 | if (0 != size) | ||
1215 | { | ||
1216 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# next size: %u\n", size); | ||
1217 | h->th = | ||
1218 | GNUNET_CLIENT_notify_transmit_ready (h->client, size, | ||
1219 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1220 | GNUNET_YES, &send_callback, h); | ||
1221 | } | ||
1222 | else | ||
1223 | { | ||
1224 | if (NULL != h->th_head) | ||
1225 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# can't transmit any more\n"); | ||
1226 | else | ||
1227 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# nothing left to transmit\n"); | ||
1228 | } | ||
1229 | if (GNUNET_NO == h->in_receive) | ||
1230 | { | ||
1231 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# start receiving from service\n"); | ||
1232 | h->in_receive = GNUNET_YES; | ||
1233 | GNUNET_CLIENT_receive (h->client, &msg_received, h, | ||
1234 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1235 | } | ||
1236 | LOG (GNUNET_ERROR_TYPE_DEBUG, "# Send packet() END\n"); | ||
1237 | return tsize; | ||
1238 | } | ||
1239 | |||
1240 | |||
1241 | /** | ||
1242 | * Auxiliary function to send an already constructed packet to the service. | ||
1243 | * Takes care of creating a new queue element, copying the message and | ||
1244 | * calling the tmt_rdy function if necessary. | ||
1245 | * | ||
1246 | * @param h mesh handle | ||
1247 | * @param msg message to transmit | ||
1248 | * @param channel channel this send is related to (NULL if N/A) | ||
1249 | */ | ||
1250 | static void | ||
1251 | send_packet (struct GNUNET_MESH_Handle *h, | ||
1252 | const struct GNUNET_MessageHeader *msg, | ||
1253 | struct GNUNET_MESH_Channel *channel) | ||
1254 | { | ||
1255 | struct GNUNET_MESH_TransmitHandle *th; | ||
1256 | size_t msize; | ||
1257 | |||
1258 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Sending message to service: %s\n", | ||
1259 | GNUNET_MESH_DEBUG_M2S(ntohs(msg->type))); | ||
1260 | msize = ntohs (msg->size); | ||
1261 | th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize); | ||
1262 | th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
1263 | th->size = msize; | ||
1264 | th->channel = channel; | ||
1265 | memcpy (&th[1], msg, msize); | ||
1266 | add_to_queue (h, th); | ||
1267 | LOG (GNUNET_ERROR_TYPE_DEBUG, " queued\n"); | ||
1268 | if (NULL != h->th) | ||
1269 | return; | ||
1270 | LOG (GNUNET_ERROR_TYPE_DEBUG, " calling ntfy tmt rdy for %u bytes\n", msize); | ||
1271 | h->th = | ||
1272 | GNUNET_CLIENT_notify_transmit_ready (h->client, msize, | ||
1273 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1274 | GNUNET_YES, &send_callback, h); | ||
1275 | } | ||
1276 | |||
1277 | |||
1278 | /******************************************************************************/ | ||
1279 | /********************** API CALL DEFINITIONS *************************/ | ||
1280 | /******************************************************************************/ | ||
1281 | |||
1282 | struct GNUNET_MESH_Handle * | ||
1283 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | ||
1284 | GNUNET_MESH_InboundChannelNotificationHandler new_channel, | ||
1285 | GNUNET_MESH_ChannelEndHandler cleaner, | ||
1286 | const struct GNUNET_MESH_MessageHandler *handlers, | ||
1287 | const uint32_t *ports) | ||
1288 | { | ||
1289 | struct GNUNET_MESH_Handle *h; | ||
1290 | |||
1291 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect()\n"); | ||
1292 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); | ||
1293 | LOG (GNUNET_ERROR_TYPE_DEBUG, " addr %p\n", h); | ||
1294 | h->cfg = cfg; | ||
1295 | h->new_channel = new_channel; | ||
1296 | h->cleaner = cleaner; | ||
1297 | h->client = GNUNET_CLIENT_connect ("mesh", cfg); | ||
1298 | if (h->client == NULL) | ||
1299 | { | ||
1300 | GNUNET_break (0); | ||
1301 | GNUNET_free (h); | ||
1302 | return NULL; | ||
1303 | } | ||
1304 | h->cls = cls; | ||
1305 | h->message_handlers = handlers; | ||
1306 | h->ports = ports; | ||
1307 | h->next_chid = GNUNET_MESH_LOCAL_CHANNEL_ID_CLI; | ||
1308 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; | ||
1309 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
1310 | |||
1311 | if (NULL != ports && ports[0] != 0 && NULL == new_channel) | ||
1312 | { | ||
1313 | GNUNET_break (0); | ||
1314 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1315 | "no new channel handler given, ports parameter is useless!!\n"); | ||
1316 | } | ||
1317 | if ((NULL == ports || ports[0] == 0) && NULL != new_channel) | ||
1318 | { | ||
1319 | GNUNET_break (0); | ||
1320 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1321 | "no ports given, new channel handler will never be called!!\n"); | ||
1322 | } | ||
1323 | /* count handlers */ | ||
1324 | for (h->n_handlers = 0; | ||
1325 | handlers && handlers[h->n_handlers].type; | ||
1326 | h->n_handlers++) ; | ||
1327 | for (h->n_ports = 0; | ||
1328 | ports && ports[h->n_ports]; | ||
1329 | h->n_ports++) ; | ||
1330 | send_connect (h); | ||
1331 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect() END\n"); | ||
1332 | return h; | ||
1333 | } | ||
1334 | |||
1335 | |||
1336 | void | ||
1337 | GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | ||
1338 | { | ||
1339 | struct GNUNET_MESH_Channel *ch; | ||
1340 | struct GNUNET_MESH_Channel *aux; | ||
1341 | struct GNUNET_MESH_TransmitHandle *th; | ||
1342 | |||
1343 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH DISCONNECT\n"); | ||
1344 | |||
1345 | ch = handle->channels_head; | ||
1346 | while (NULL != ch) | ||
1347 | { | ||
1348 | aux = ch->next; | ||
1349 | if (ch->chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) | ||
1350 | { | ||
1351 | GNUNET_break (0); | ||
1352 | LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X not destroyed\n", ch->chid); | ||
1353 | } | ||
1354 | destroy_channel (ch, GNUNET_YES); | ||
1355 | ch = aux; | ||
1356 | } | ||
1357 | while ( (th = handle->th_head) != NULL) | ||
1358 | { | ||
1359 | struct GNUNET_MessageHeader *msg; | ||
1360 | |||
1361 | /* Make sure it is an allowed packet (everything else should have been | ||
1362 | * already canceled). | ||
1363 | */ | ||
1364 | GNUNET_break (GNUNET_NO == th_is_payload (th)); | ||
1365 | msg = (struct GNUNET_MessageHeader *) &th[1]; | ||
1366 | switch (ntohs(msg->type)) | ||
1367 | { | ||
1368 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT: | ||
1369 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE: | ||
1370 | case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: | ||
1371 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: | ||
1372 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: | ||
1373 | break; | ||
1374 | default: | ||
1375 | GNUNET_break (0); | ||
1376 | LOG (GNUNET_ERROR_TYPE_ERROR, "unexpected msg %u\n", | ||
1377 | ntohs(msg->type)); | ||
1378 | } | ||
1379 | |||
1380 | GNUNET_CONTAINER_DLL_remove (handle->th_head, handle->th_tail, th); | ||
1381 | GNUNET_free (th); | ||
1382 | } | ||
1383 | |||
1384 | if (NULL != handle->th) | ||
1385 | { | ||
1386 | GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); | ||
1387 | handle->th = NULL; | ||
1388 | } | ||
1389 | if (NULL != handle->client) | ||
1390 | { | ||
1391 | GNUNET_CLIENT_disconnect (handle->client); | ||
1392 | handle->client = NULL; | ||
1393 | } | ||
1394 | if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task) | ||
1395 | { | ||
1396 | GNUNET_SCHEDULER_cancel(handle->reconnect_task); | ||
1397 | handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
1398 | } | ||
1399 | GNUNET_free (handle); | ||
1400 | } | ||
1401 | |||
1402 | |||
1403 | /** | ||
1404 | * Create a new channel towards a remote peer. | ||
1405 | * | ||
1406 | * If the destination port is not open by any peer or the destination peer | ||
1407 | * does not accept the channel, #GNUNET_MESH_ChannelEndHandler will be called | ||
1408 | * for this channel. | ||
1409 | * | ||
1410 | * @param h mesh handle | ||
1411 | * @param channel_ctx client's channel context to associate with the channel | ||
1412 | * @param peer peer identity the channel should go to | ||
1413 | * @param port Port number. | ||
1414 | * @param nobuffer Flag for disabling buffering on relay nodes. | ||
1415 | * @param reliable Flag for end-to-end reliability. | ||
1416 | * | ||
1417 | * @return handle to the channel | ||
1418 | */ | ||
1419 | struct GNUNET_MESH_Channel * | ||
1420 | GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h, | ||
1421 | void *channel_ctx, | ||
1422 | const struct GNUNET_PeerIdentity *peer, | ||
1423 | uint32_t port, | ||
1424 | int nobuffer, | ||
1425 | int reliable) | ||
1426 | { | ||
1427 | struct GNUNET_MESH_Channel *ch; | ||
1428 | struct GNUNET_MESH_ChannelMessage msg; | ||
1429 | |||
1430 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1431 | "Creating new channel to %s:%u\n", | ||
1432 | GNUNET_i2s (peer), port); | ||
1433 | ch = create_channel (h, 0); | ||
1434 | LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch); | ||
1435 | LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", ch->chid); | ||
1436 | ch->ctx = channel_ctx; | ||
1437 | ch->peer = GNUNET_PEER_intern (peer); | ||
1438 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE); | ||
1439 | msg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage)); | ||
1440 | msg.channel_id = htonl (ch->chid); | ||
1441 | msg.port = htonl (port); | ||
1442 | msg.peer = *peer; | ||
1443 | msg.opt = 0; | ||
1444 | if (GNUNET_YES == reliable) | ||
1445 | msg.opt |= GNUNET_MESH_OPTION_RELIABLE; | ||
1446 | if (GNUNET_YES == nobuffer) | ||
1447 | msg.opt |= GNUNET_MESH_OPTION_NOBUFFER; | ||
1448 | msg.opt = htonl (msg.opt); | ||
1449 | ch->allow_send = 0; | ||
1450 | send_packet (h, &msg.header, ch); | ||
1451 | return ch; | ||
1452 | } | ||
1453 | |||
1454 | |||
1455 | void | ||
1456 | GNUNET_MESH_channel_destroy (struct GNUNET_MESH_Channel *channel) | ||
1457 | { | ||
1458 | struct GNUNET_MESH_Handle *h; | ||
1459 | struct GNUNET_MESH_ChannelMessage msg; | ||
1460 | struct GNUNET_MESH_TransmitHandle *th; | ||
1461 | |||
1462 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying channel\n"); | ||
1463 | h = channel->mesh; | ||
1464 | |||
1465 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY); | ||
1466 | msg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage)); | ||
1467 | msg.channel_id = htonl (channel->chid); | ||
1468 | memset (&msg.peer, 0, sizeof (struct GNUNET_PeerIdentity)); | ||
1469 | msg.port = 0; | ||
1470 | msg.opt = 0; | ||
1471 | th = h->th_head; | ||
1472 | while (th != NULL) | ||
1473 | { | ||
1474 | struct GNUNET_MESH_TransmitHandle *aux; | ||
1475 | if (th->channel == channel) | ||
1476 | { | ||
1477 | aux = th->next; | ||
1478 | /* FIXME call the handler? */ | ||
1479 | if (GNUNET_YES == th_is_payload (th)) | ||
1480 | th->notify (th->notify_cls, 0, NULL); | ||
1481 | GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); | ||
1482 | GNUNET_free (th); | ||
1483 | th = aux; | ||
1484 | } | ||
1485 | else | ||
1486 | th = th->next; | ||
1487 | } | ||
1488 | |||
1489 | destroy_channel (channel, GNUNET_YES); | ||
1490 | send_packet (h, &msg.header, NULL); | ||
1491 | } | ||
1492 | |||
1493 | |||
1494 | /** | ||
1495 | * Get information about a channel. | ||
1496 | * | ||
1497 | * @param channel Channel handle. | ||
1498 | * @param option Query (GNUNET_MESH_OPTION_*). | ||
1499 | * @param ... dependant on option, currently not used | ||
1500 | * | ||
1501 | * @return Union with an answer to the query. | ||
1502 | */ | ||
1503 | const union GNUNET_MESH_ChannelInfo * | ||
1504 | GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel, | ||
1505 | enum MeshOption option, ...) | ||
1506 | { | ||
1507 | const union GNUNET_MESH_ChannelInfo *ret; | ||
1508 | |||
1509 | switch (option) | ||
1510 | { | ||
1511 | case GNUNET_MESH_OPTION_NOBUFFER: | ||
1512 | ret = (const union GNUNET_MESH_ChannelInfo *) &channel->nobuffer; | ||
1513 | break; | ||
1514 | case GNUNET_MESH_OPTION_RELIABLE: | ||
1515 | ret = (const union GNUNET_MESH_ChannelInfo *) &channel->reliable; | ||
1516 | break; | ||
1517 | case GNUNET_MESH_OPTION_OOORDER: | ||
1518 | ret = (const union GNUNET_MESH_ChannelInfo *) &channel->ooorder; | ||
1519 | break; | ||
1520 | case GNUNET_MESH_OPTION_PEER: | ||
1521 | ret = (const union GNUNET_MESH_ChannelInfo *) &channel->peer; | ||
1522 | break; | ||
1523 | default: | ||
1524 | GNUNET_break (0); | ||
1525 | return NULL; | ||
1526 | } | ||
1527 | |||
1528 | return ret; | ||
1529 | } | ||
1530 | |||
1531 | struct GNUNET_MESH_TransmitHandle * | ||
1532 | GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Channel *channel, int cork, | ||
1533 | struct GNUNET_TIME_Relative maxdelay, | ||
1534 | size_t notify_size, | ||
1535 | GNUNET_CONNECTION_TransmitReadyNotify notify, | ||
1536 | void *notify_cls) | ||
1537 | { | ||
1538 | struct GNUNET_MESH_TransmitHandle *th; | ||
1539 | |||
1540 | GNUNET_assert (NULL != channel); | ||
1541 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY\n"); | ||
1542 | LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->chid); | ||
1543 | LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send); | ||
1544 | if (channel->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV) | ||
1545 | LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n"); | ||
1546 | else | ||
1547 | LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n"); | ||
1548 | LOG (GNUNET_ERROR_TYPE_DEBUG, " payload size %u\n", notify_size); | ||
1549 | GNUNET_assert (NULL != notify); | ||
1550 | GNUNET_assert (0 == channel->packet_size); // Only one data packet allowed | ||
1551 | th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle)); | ||
1552 | th->channel = channel; | ||
1553 | th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); | ||
1554 | th->size = notify_size + sizeof (struct GNUNET_MESH_LocalData); | ||
1555 | channel->packet_size = th->size; | ||
1556 | LOG (GNUNET_ERROR_TYPE_DEBUG, " total size %u\n", th->size); | ||
1557 | th->notify = notify; | ||
1558 | th->notify_cls = notify_cls; | ||
1559 | add_to_queue (channel->mesh, th); | ||
1560 | if (NULL != channel->mesh->th) | ||
1561 | return th; | ||
1562 | if (GNUNET_NO == channel->allow_send) | ||
1563 | return th; | ||
1564 | LOG (GNUNET_ERROR_TYPE_DEBUG, " call client notify tmt rdy\n"); | ||
1565 | channel->mesh->th = | ||
1566 | GNUNET_CLIENT_notify_transmit_ready (channel->mesh->client, th->size, | ||
1567 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1568 | GNUNET_YES, &send_callback, | ||
1569 | channel->mesh); | ||
1570 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY END\n"); | ||
1571 | return th; | ||
1572 | } | ||
1573 | |||
1574 | |||
1575 | void | ||
1576 | GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th) | ||
1577 | { | ||
1578 | struct GNUNET_MESH_Handle *mesh; | ||
1579 | |||
1580 | th->channel->packet_size = 0; | ||
1581 | mesh = th->channel->mesh; | ||
1582 | if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
1583 | GNUNET_SCHEDULER_cancel (th->timeout_task); | ||
1584 | GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th); | ||
1585 | GNUNET_free (th); | ||
1586 | if ((0 == message_ready_size (mesh)) && (NULL != mesh->th)) | ||
1587 | { | ||
1588 | /* queue empty, no point in asking for transmission */ | ||
1589 | GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th); | ||
1590 | mesh->th = NULL; | ||
1591 | } | ||
1592 | } | ||
1593 | |||
1594 | void | ||
1595 | GNUNET_MESH_receive_done (struct GNUNET_MESH_Channel *channel) | ||
1596 | { | ||
1597 | send_ack (channel); | ||
1598 | } | ||
1599 | |||
1600 | |||
1601 | /** | ||
1602 | * Request information about the running mesh peer. | ||
1603 | * The callback will be called for every channel known to the service, | ||
1604 | * listing all active peers that blong to the channel. | ||
1605 | * | ||
1606 | * If called again on the same handle, it will overwrite the previous | ||
1607 | * callback and cls. To retrieve the cls, monitor_cancel must be | ||
1608 | * called first. | ||
1609 | * | ||
1610 | * WARNING: unstable API, likely to change in the future! | ||
1611 | * | ||
1612 | * @param h Handle to the mesh peer. | ||
1613 | * @param callback Function to call with the requested data. | ||
1614 | * @param callback_cls Closure for @c callback. | ||
1615 | */ | ||
1616 | void | ||
1617 | GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h, | ||
1618 | GNUNET_MESH_ChannelsCB callback, | ||
1619 | void *callback_cls) | ||
1620 | { | ||
1621 | struct GNUNET_MessageHeader msg; | ||
1622 | |||
1623 | msg.size = htons (sizeof (msg)); | ||
1624 | msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS); | ||
1625 | send_packet (h, &msg, NULL); | ||
1626 | h->channels_cb = callback; | ||
1627 | h->channels_cls = callback_cls; | ||
1628 | |||
1629 | return; | ||
1630 | } | ||
1631 | |||
1632 | |||
1633 | /** | ||
1634 | * Cancel a monitor request. The monitor callback will not be called. | ||
1635 | * | ||
1636 | * @param h Mesh handle. | ||
1637 | * | ||
1638 | * @return Closure given to GNUNET_MESH_monitor, if any. | ||
1639 | */ | ||
1640 | void * | ||
1641 | GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h) | ||
1642 | { | ||
1643 | void *cls; | ||
1644 | |||
1645 | cls = h->channels_cls; | ||
1646 | h->channels_cb = NULL; | ||
1647 | h->channels_cls = NULL; | ||
1648 | return cls; | ||
1649 | } | ||
1650 | |||
1651 | |||
1652 | /** | ||
1653 | * Request information about a specific channel of the running mesh peer. | ||
1654 | * | ||
1655 | * WARNING: unstable API, likely to change in the future! | ||
1656 | * FIXME Add destination option. | ||
1657 | * | ||
1658 | * @param h Handle to the mesh peer. | ||
1659 | * @param initiator ID of the owner of the channel. | ||
1660 | * @param channel_number Channel number. | ||
1661 | * @param callback Function to call with the requested data. | ||
1662 | * @param callback_cls Closure for @c callback. | ||
1663 | */ | ||
1664 | void | ||
1665 | GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h, | ||
1666 | struct GNUNET_PeerIdentity *initiator, | ||
1667 | unsigned int channel_number, | ||
1668 | GNUNET_MESH_ChannelCB callback, | ||
1669 | void *callback_cls) | ||
1670 | { | ||
1671 | struct GNUNET_MESH_LocalMonitor msg; | ||
1672 | |||
1673 | msg.header.size = htons (sizeof (msg)); | ||
1674 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL); | ||
1675 | msg.owner = *initiator; | ||
1676 | msg.channel_id = htonl (channel_number); | ||
1677 | msg.reserved = 0; | ||
1678 | send_packet (h, &msg.header, NULL); | ||
1679 | h->channel_cb = callback; | ||
1680 | h->channel_cls = callback_cls; | ||
1681 | |||
1682 | return; | ||
1683 | } | ||
1684 | |||
1685 | |||
1686 | /** | ||
1687 | * Function called to notify a client about the connection | ||
1688 | * begin ready to queue more data. "buf" will be | ||
1689 | * NULL and "size" zero if the connection was closed for | ||
1690 | * writing in the meantime. | ||
1691 | * | ||
1692 | * @param cls closure | ||
1693 | * @param size number of bytes available in buf | ||
1694 | * @param buf where the callee should write the message | ||
1695 | * @return number of bytes written to buf | ||
1696 | */ | ||
1697 | static size_t | ||
1698 | mesh_mq_ntr (void *cls, size_t size, | ||
1699 | void *buf) | ||
1700 | { | ||
1701 | struct GNUNET_MQ_Handle *mq = cls; | ||
1702 | struct MeshMQState *state = GNUNET_MQ_impl_state (mq); | ||
1703 | const struct GNUNET_MessageHeader *msg = GNUNET_MQ_impl_current (mq); | ||
1704 | uint16_t msize; | ||
1705 | |||
1706 | state->th = NULL; | ||
1707 | if (NULL == buf) | ||
1708 | { | ||
1709 | GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_WRITE); | ||
1710 | return 0; | ||
1711 | } | ||
1712 | msize = ntohs (msg->size); | ||
1713 | GNUNET_assert (msize <= size); | ||
1714 | memcpy (buf, msg, msize); | ||
1715 | GNUNET_MQ_impl_send_continue (mq); | ||
1716 | return msize; | ||
1717 | } | ||
1718 | |||
1719 | |||
1720 | /** | ||
1721 | * Signature of functions implementing the | ||
1722 | * sending functionality of a message queue. | ||
1723 | * | ||
1724 | * @param mq the message queue | ||
1725 | * @param msg the message to send | ||
1726 | * @param impl_state state of the implementation | ||
1727 | */ | ||
1728 | static void | ||
1729 | mesh_mq_send_impl (struct GNUNET_MQ_Handle *mq, | ||
1730 | const struct GNUNET_MessageHeader *msg, void *impl_state) | ||
1731 | { | ||
1732 | struct MeshMQState *state = impl_state; | ||
1733 | |||
1734 | GNUNET_assert (NULL == state->th); | ||
1735 | GNUNET_MQ_impl_send_commit (mq); | ||
1736 | state->th = | ||
1737 | GNUNET_MESH_notify_transmit_ready (state->channel, | ||
1738 | /* FIXME: add option for corking */ | ||
1739 | GNUNET_NO, | ||
1740 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1741 | ntohs (msg->size), | ||
1742 | mesh_mq_ntr, mq); | ||
1743 | |||
1744 | } | ||
1745 | |||
1746 | |||
1747 | /** | ||
1748 | * Signature of functions implementing the | ||
1749 | * destruction of a message queue. | ||
1750 | * Implementations must not free 'mq', but should | ||
1751 | * take care of 'impl_state'. | ||
1752 | * | ||
1753 | * @param mq the message queue to destroy | ||
1754 | * @param impl_state state of the implementation | ||
1755 | */ | ||
1756 | static void | ||
1757 | mesh_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | ||
1758 | { | ||
1759 | struct MeshMQState *state = impl_state; | ||
1760 | |||
1761 | if (NULL != state->th) | ||
1762 | GNUNET_MESH_notify_transmit_ready_cancel (state->th); | ||
1763 | |||
1764 | GNUNET_free (state); | ||
1765 | } | ||
1766 | |||
1767 | |||
1768 | /** | ||
1769 | * Create a message queue for a mesh channel. | ||
1770 | * The message queue can only be used to transmit messages, | ||
1771 | * not to receive them. | ||
1772 | * | ||
1773 | * @param channel the channel to create the message qeue for | ||
1774 | * @return a message queue to messages over the channel | ||
1775 | */ | ||
1776 | struct GNUNET_MQ_Handle * | ||
1777 | GNUNET_MESH_mq_create (struct GNUNET_MESH_Channel *channel) | ||
1778 | { | ||
1779 | struct GNUNET_MQ_Handle *mq; | ||
1780 | struct MeshMQState *state; | ||
1781 | |||
1782 | state = GNUNET_new (struct MeshMQState); | ||
1783 | state->channel = channel; | ||
1784 | |||
1785 | mq = GNUNET_MQ_queue_for_callbacks (mesh_mq_send_impl, | ||
1786 | mesh_mq_destroy_impl, | ||
1787 | NULL, /* FIXME: cancel impl. */ | ||
1788 | state, | ||
1789 | NULL, /* no msg handlers */ | ||
1790 | NULL, /* no err handlers */ | ||
1791 | NULL); /* no handler cls */ | ||
1792 | return mq; | ||
1793 | } | ||
1794 | |||
diff --git a/src/mesh/mesh_enc.h b/src/mesh/mesh_enc.h deleted file mode 100644 index 93a3a2e9e..000000000 --- a/src/mesh/mesh_enc.h +++ /dev/null | |||
@@ -1,259 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001 - 2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @author Bartlomiej Polot | ||
23 | * @file mesh/mesh_enc.h | ||
24 | */ | ||
25 | |||
26 | #ifndef MESH_H_ | ||
27 | #define MESH_H_ | ||
28 | |||
29 | #ifdef __cplusplus | ||
30 | extern "C" | ||
31 | { | ||
32 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
33 | } | ||
34 | #endif | ||
35 | #endif | ||
36 | |||
37 | #include <stdint.h> | ||
38 | |||
39 | #define MESH_DEBUG GNUNET_YES | ||
40 | |||
41 | #include "platform.h" | ||
42 | #include "gnunet_common.h" | ||
43 | #include "gnunet_util_lib.h" | ||
44 | #include "gnunet_peer_lib.h" | ||
45 | #include "gnunet_core_service.h" | ||
46 | #include "gnunet_protocols.h" | ||
47 | #include <gnunet_mesh_service.h> | ||
48 | |||
49 | /******************************************************************************/ | ||
50 | /************************** CONSTANTS ******************************/ | ||
51 | /******************************************************************************/ | ||
52 | |||
53 | #define GNUNET_MESH_LOCAL_CHANNEL_ID_CLI 0x80000000 | ||
54 | #define GNUNET_MESH_LOCAL_CHANNEL_ID_SERV 0xB0000000 | ||
55 | |||
56 | #define HIGH_PID 0xFFFF0000 | ||
57 | #define LOW_PID 0x0000FFFF | ||
58 | |||
59 | #define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID) | ||
60 | |||
61 | /******************************************************************************/ | ||
62 | /************************** MESSAGES ******************************/ | ||
63 | /******************************************************************************/ | ||
64 | |||
65 | GNUNET_NETWORK_STRUCT_BEGIN | ||
66 | |||
67 | /** | ||
68 | * Message for a client to register to the service | ||
69 | */ | ||
70 | struct GNUNET_MESH_ClientConnect | ||
71 | { | ||
72 | /** | ||
73 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT | ||
74 | * | ||
75 | * Size: sizeof(struct GNUNET_MESH_ClientConnect) + | ||
76 | * sizeof(MESH_ApplicationType) * applications + | ||
77 | * sizeof(uint16_t) * types | ||
78 | */ | ||
79 | struct GNUNET_MessageHeader header; | ||
80 | /* uint32_t list_ports[] */ | ||
81 | }; | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Type for channel numbering. | ||
86 | * - Local channel numbers given by the service (incoming) are >= 0xB0000000 | ||
87 | * - Local channel numbers given by the client (created) are >= 0x80000000 | ||
88 | * - Global channel numbers are < 0x80000000 | ||
89 | */ | ||
90 | typedef uint32_t MESH_ChannelNumber; | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Message for a client to create and destroy channels. | ||
95 | */ | ||
96 | struct GNUNET_MESH_ChannelMessage | ||
97 | { | ||
98 | /** | ||
99 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY] | ||
100 | * | ||
101 | * Size: sizeof(struct GNUNET_MESH_ChannelMessage) | ||
102 | */ | ||
103 | struct GNUNET_MessageHeader header; | ||
104 | |||
105 | /** | ||
106 | * ID of a channel controlled by this client. | ||
107 | */ | ||
108 | MESH_ChannelNumber channel_id GNUNET_PACKED; | ||
109 | |||
110 | /** | ||
111 | * Channel's peer | ||
112 | */ | ||
113 | struct GNUNET_PeerIdentity peer; | ||
114 | |||
115 | /** | ||
116 | * Port of the channel. | ||
117 | */ | ||
118 | uint32_t port GNUNET_PACKED; | ||
119 | |||
120 | /** | ||
121 | * Options. | ||
122 | */ | ||
123 | uint32_t opt GNUNET_PACKED; | ||
124 | }; | ||
125 | |||
126 | |||
127 | /** | ||
128 | * Message for mesh data traffic. | ||
129 | */ | ||
130 | struct GNUNET_MESH_LocalData | ||
131 | { | ||
132 | /** | ||
133 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA | ||
134 | */ | ||
135 | struct GNUNET_MessageHeader header; | ||
136 | |||
137 | /** | ||
138 | * ID of the channel | ||
139 | */ | ||
140 | uint32_t id GNUNET_PACKED; | ||
141 | |||
142 | /** | ||
143 | * Payload follows | ||
144 | */ | ||
145 | }; | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Message to allow the client send more data to the service | ||
150 | * (always service -> client). | ||
151 | */ | ||
152 | struct GNUNET_MESH_LocalAck | ||
153 | { | ||
154 | /** | ||
155 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK | ||
156 | */ | ||
157 | struct GNUNET_MessageHeader header; | ||
158 | |||
159 | /** | ||
160 | * ID of the channel allowed to send more data. | ||
161 | */ | ||
162 | MESH_ChannelNumber channel_id GNUNET_PACKED; | ||
163 | |||
164 | }; | ||
165 | |||
166 | |||
167 | /** | ||
168 | * Message to inform the client about channels in the service. | ||
169 | */ | ||
170 | struct GNUNET_MESH_LocalMonitor | ||
171 | { | ||
172 | /** | ||
173 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL] | ||
174 | */ | ||
175 | struct GNUNET_MessageHeader header; | ||
176 | |||
177 | /** | ||
178 | * ID of the channel allowed to send more data. | ||
179 | */ | ||
180 | MESH_ChannelNumber channel_id GNUNET_PACKED; | ||
181 | |||
182 | /** | ||
183 | * Alignment. | ||
184 | */ | ||
185 | uint32_t reserved GNUNET_PACKED; | ||
186 | |||
187 | /** | ||
188 | * ID of the owner of the channel (can be local peer). | ||
189 | */ | ||
190 | struct GNUNET_PeerIdentity owner; | ||
191 | |||
192 | /** | ||
193 | * ID of the destination of the channel (can be local peer). | ||
194 | */ | ||
195 | struct GNUNET_PeerIdentity destination; | ||
196 | }; | ||
197 | |||
198 | |||
199 | GNUNET_NETWORK_STRUCT_END | ||
200 | |||
201 | |||
202 | |||
203 | /** | ||
204 | * Check if one pid is bigger than other, accounting for overflow. | ||
205 | * | ||
206 | * @param bigger Argument that should be bigger. | ||
207 | * @param smaller Argument that should be smaller. | ||
208 | * | ||
209 | * @return True if bigger (arg1) has a higher value than smaller (arg 2). | ||
210 | */ | ||
211 | int | ||
212 | GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller); | ||
213 | |||
214 | |||
215 | /** | ||
216 | * Get the higher ACK value out of two values, taking in account overflow. | ||
217 | * | ||
218 | * @param a First ACK value. | ||
219 | * @param b Second ACK value. | ||
220 | * | ||
221 | * @return Highest ACK value from the two. | ||
222 | */ | ||
223 | uint32_t | ||
224 | GMC_max_pid (uint32_t a, uint32_t b); | ||
225 | |||
226 | |||
227 | /** | ||
228 | * Get the lower ACK value out of two values, taking in account overflow. | ||
229 | * | ||
230 | * @param a First ACK value. | ||
231 | * @param b Second ACK value. | ||
232 | * | ||
233 | * @return Lowest ACK value from the two. | ||
234 | */ | ||
235 | uint32_t | ||
236 | GMC_min_pid (uint32_t a, uint32_t b); | ||
237 | |||
238 | |||
239 | /** | ||
240 | * Convert a message type into a string to help debug | ||
241 | * Generated with: | ||
242 | * FIND: "#define ([^ ]+)[ ]*([0-9]+)" | ||
243 | * REPLACE: " case \2: return "\1"; break;" | ||
244 | * | ||
245 | * @param m Message type. | ||
246 | * | ||
247 | * @return Human readable string description. | ||
248 | */ | ||
249 | const char * | ||
250 | GNUNET_MESH_DEBUG_M2S (uint16_t m); | ||
251 | |||
252 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
253 | { | ||
254 | #endif | ||
255 | #ifdef __cplusplus | ||
256 | } | ||
257 | #endif | ||
258 | |||
259 | #endif | ||
diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index 2d708eb62..c36fa9f93 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h | |||
@@ -26,7 +26,13 @@ | |||
26 | #ifndef MESH_PROTOCOL_H_ | 26 | #ifndef MESH_PROTOCOL_H_ |
27 | #define MESH_PROTOCOL_H_ | 27 | #define MESH_PROTOCOL_H_ |
28 | 28 | ||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "mesh.h" | ||
32 | |||
29 | #ifdef __cplusplus | 33 | #ifdef __cplusplus |
34 | |||
35 | struct GNUNET_MESH_TunnelMessage; | ||
30 | extern "C" | 36 | extern "C" |
31 | { | 37 | { |
32 | #if 0 | 38 | #if 0 |
@@ -42,225 +48,375 @@ extern "C" | |||
42 | GNUNET_NETWORK_STRUCT_BEGIN | 48 | GNUNET_NETWORK_STRUCT_BEGIN |
43 | 49 | ||
44 | /** | 50 | /** |
45 | * Message for mesh path creation. | 51 | * Message for mesh connection creation. |
52 | * TODO onionify path, add random tunnel ID | ||
46 | */ | 53 | */ |
47 | struct GNUNET_MESH_CreateTunnel | 54 | struct GNUNET_MESH_ConnectionCreate |
48 | { | 55 | { |
49 | /** | 56 | /** |
50 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE | 57 | * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE |
51 | * | 58 | * |
52 | * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + | 59 | * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + |
53 | * path_length * sizeof (struct GNUNET_PeerIdentity) | 60 | * path_length * sizeof (struct GNUNET_PeerIdentity) |
54 | */ | 61 | */ |
55 | struct GNUNET_MessageHeader header; | 62 | struct GNUNET_MessageHeader header; |
56 | 63 | ||
57 | /** | 64 | /** |
58 | * Global id of the tunnel this path belongs to, | 65 | * ID of the connection |
59 | * unique in conjunction with the origin. | ||
60 | */ | ||
61 | uint32_t tid GNUNET_PACKED; | ||
62 | |||
63 | /** | ||
64 | * Tunnel options (GNUNET_MESH_OPTION_*). | ||
65 | */ | ||
66 | uint32_t opt GNUNET_PACKED; | ||
67 | |||
68 | /** | ||
69 | * Destination port. | ||
70 | */ | 66 | */ |
71 | uint32_t port GNUNET_PACKED; | 67 | struct GNUNET_HashCode cid; |
72 | 68 | ||
73 | /** | 69 | /** |
74 | * FIXME do not add the first hop | ||
75 | * path_length structs defining the *whole* path from the origin [0] to the | 70 | * path_length structs defining the *whole* path from the origin [0] to the |
76 | * final destination [path_length-1]. | 71 | * final destination [path_length-1]. |
77 | */ | 72 | */ |
78 | /* struct GNUNET_PeerIdentity peers[path_length]; */ | 73 | /* struct GNUNET_PeerIdentity peers[path_length]; */ |
79 | }; | 74 | }; |
80 | 75 | ||
81 | |||
82 | /** | 76 | /** |
83 | * Message for mesh data traffic. | 77 | * Message for ack'ing a connection |
84 | */ | 78 | */ |
85 | struct GNUNET_MESH_Data | 79 | struct GNUNET_MESH_ConnectionACK |
86 | { | 80 | { |
87 | /** | 81 | /** |
88 | * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST, | 82 | * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK |
89 | * GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN | ||
90 | */ | 83 | */ |
91 | struct GNUNET_MessageHeader header; | 84 | struct GNUNET_MessageHeader header; |
92 | 85 | ||
93 | /** | 86 | /** |
94 | * TID of the tunnel | 87 | * Always 0. |
95 | */ | 88 | */ |
96 | uint32_t tid GNUNET_PACKED; | 89 | uint32_t reserved GNUNET_PACKED; |
97 | 90 | ||
98 | /** | 91 | /** |
99 | * Number of hops to live | 92 | * ID of the connection. |
100 | */ | 93 | */ |
101 | uint32_t ttl GNUNET_PACKED; | 94 | struct GNUNET_HashCode cid; |
95 | |||
96 | /* TODO: signature */ | ||
97 | }; | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Message for encapsulation of a Key eXchange message in a connection. | ||
102 | */ | ||
103 | struct GNUNET_MESH_KX | ||
104 | { | ||
105 | /** | ||
106 | * Type: GNUNET_MESSAGE_TYPE_MESH_KX. | ||
107 | */ | ||
108 | struct GNUNET_MessageHeader header; | ||
102 | 109 | ||
103 | /** | 110 | /** |
104 | * ID of the packet | 111 | * Always 0. |
105 | */ | 112 | */ |
106 | uint32_t pid GNUNET_PACKED; | 113 | uint32_t reserved GNUNET_PACKED; |
107 | 114 | ||
108 | /** | 115 | /** |
109 | * OID of the tunnel | 116 | * ID of the connection. |
110 | */ | 117 | */ |
111 | struct GNUNET_PeerIdentity oid; | 118 | struct GNUNET_HashCode cid; |
119 | |||
120 | /* Specific KX message follows. */ | ||
121 | }; | ||
122 | |||
123 | |||
124 | /** | ||
125 | * Message transmitted with the signed ephemeral key of a peer. The | ||
126 | * session key is then derived from the two ephemeral keys (ECDHE). | ||
127 | * | ||
128 | * As far as possible, same as CORE's EphemeralKeyMessage. | ||
129 | */ | ||
130 | struct GNUNET_MESH_KX_Ephemeral | ||
131 | { | ||
112 | 132 | ||
113 | /** | 133 | /** |
114 | * Unique ID of the payload message | 134 | * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_EPHEMERAL. |
115 | */ | 135 | */ |
116 | uint32_t mid GNUNET_PACKED; | 136 | struct GNUNET_MessageHeader header; |
117 | 137 | ||
118 | /** | 138 | /** |
119 | * Payload follows | 139 | * Status of the sender (should be in "enum PeerStateMachine"), nbo. |
120 | */ | 140 | */ |
141 | int32_t sender_status GNUNET_PACKED; | ||
142 | |||
143 | /** | ||
144 | * An ECC signature of the 'origin' asserting the validity of | ||
145 | * the given ephemeral key. | ||
146 | */ | ||
147 | struct GNUNET_CRYPTO_EddsaSignature signature; | ||
148 | |||
149 | /** | ||
150 | * Information about what is being signed. | ||
151 | */ | ||
152 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
153 | |||
154 | /** | ||
155 | * At what time was this key created (beginning of validity). | ||
156 | */ | ||
157 | struct GNUNET_TIME_AbsoluteNBO creation_time; | ||
158 | |||
159 | /** | ||
160 | * When does the given ephemeral key expire (end of validity). | ||
161 | */ | ||
162 | struct GNUNET_TIME_AbsoluteNBO expiration_time; | ||
163 | |||
164 | /** | ||
165 | * Ephemeral public ECC key (always for NIST P-521) encoded in a format suitable | ||
166 | * for network transmission as created using 'gcry_sexp_sprint'. | ||
167 | */ | ||
168 | struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; | ||
169 | |||
170 | /** | ||
171 | * Public key of the signing peer (persistent version, not the ephemeral public key). | ||
172 | */ | ||
173 | struct GNUNET_PeerIdentity origin_identity; | ||
121 | }; | 174 | }; |
122 | 175 | ||
123 | 176 | ||
124 | /** | 177 | /** |
125 | * Message to acknowledge end-to-end data. | 178 | * We're sending an (encrypted) PING to the other peer to check if he |
179 | * can decrypt. The other peer should respond with a PONG with the | ||
180 | * same content, except this time encrypted with the receiver's key. | ||
126 | */ | 181 | */ |
127 | struct GNUNET_MESH_DataACK | 182 | struct GNUNET_MESH_KX_Ping |
128 | { | 183 | { |
129 | /** | 184 | /** |
130 | * Type: GNUNET_MESSAGE_TYPE_MESH_DATA_ACK | 185 | * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PING. |
131 | */ | 186 | */ |
132 | struct GNUNET_MessageHeader header; | 187 | struct GNUNET_MessageHeader header; |
133 | 188 | ||
134 | /** | 189 | /** |
135 | * TID of the tunnel | 190 | * Seed for the IV |
136 | */ | 191 | */ |
137 | uint32_t tid GNUNET_PACKED; | 192 | uint32_t iv GNUNET_PACKED; |
138 | 193 | ||
139 | /** | 194 | /** |
140 | * OID of the tunnel | 195 | * Intended target of the PING, used primarily to check |
196 | * that decryption actually worked. | ||
141 | */ | 197 | */ |
142 | struct GNUNET_PeerIdentity oid; | 198 | struct GNUNET_PeerIdentity target; |
143 | 199 | ||
144 | /** | 200 | /** |
145 | * Bitfield of already-received newer messages | 201 | * Random number chosen to make reply harder. |
146 | * pid + 1 @ LSB | ||
147 | * pid + 64 @ MSB | ||
148 | */ | 202 | */ |
149 | uint64_t futures GNUNET_PACKED; | 203 | uint32_t nonce GNUNET_PACKED; |
204 | }; | ||
205 | |||
150 | 206 | ||
207 | /** | ||
208 | * Response to a PING. Includes data from the original PING. | ||
209 | */ | ||
210 | struct GNUNET_MESH_KX_Pong | ||
211 | { | ||
151 | /** | 212 | /** |
152 | * Last message ID received. | 213 | * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PONG. |
153 | */ | 214 | */ |
154 | uint32_t mid GNUNET_PACKED; | 215 | struct GNUNET_MessageHeader header; |
216 | |||
217 | /** | ||
218 | * Seed for the IV | ||
219 | */ | ||
220 | uint32_t iv GNUNET_PACKED; | ||
221 | |||
222 | /** | ||
223 | * Same nonce as in the reve. | ||
224 | */ | ||
225 | uint32_t nonce GNUNET_PACKED; | ||
155 | }; | 226 | }; |
156 | 227 | ||
157 | 228 | ||
158 | /** | 229 | /** |
159 | * Message to acknowledge mesh data traffic. | 230 | * Tunnel(ed) message. |
160 | */ | 231 | */ |
161 | struct GNUNET_MESH_ACK | 232 | struct GNUNET_MESH_Encrypted |
233 | { | ||
234 | /** | ||
235 | * Type: GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED | ||
236 | */ | ||
237 | struct GNUNET_MessageHeader header; | ||
238 | |||
239 | /** | ||
240 | * Initialization Vector for payload encryption. | ||
241 | */ | ||
242 | uint32_t iv GNUNET_PACKED; | ||
243 | |||
244 | /** | ||
245 | * ID of the connection. | ||
246 | */ | ||
247 | struct GNUNET_HashCode cid; | ||
248 | |||
249 | /** | ||
250 | * ID of the packet (hop by hop). | ||
251 | */ | ||
252 | uint32_t pid GNUNET_PACKED; | ||
253 | |||
254 | /** | ||
255 | * Number of hops to live. | ||
256 | */ | ||
257 | uint32_t ttl GNUNET_PACKED; | ||
258 | |||
259 | /** | ||
260 | * Encrypted content follows. | ||
261 | */ | ||
262 | }; | ||
263 | |||
264 | struct GNUNET_MESH_ChannelCreate | ||
265 | { | ||
266 | /** | ||
267 | * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE | ||
268 | */ | ||
269 | struct GNUNET_MessageHeader header; | ||
270 | |||
271 | /** | ||
272 | * ID of the channel | ||
273 | */ | ||
274 | MESH_ChannelNumber chid GNUNET_PACKED; | ||
275 | |||
276 | /** | ||
277 | * Destination port. | ||
278 | */ | ||
279 | uint32_t port GNUNET_PACKED; | ||
280 | |||
281 | /** | ||
282 | * Channel options. | ||
283 | */ | ||
284 | uint32_t opt GNUNET_PACKED; | ||
285 | }; | ||
286 | |||
287 | struct GNUNET_MESH_ChannelManage | ||
288 | { | ||
289 | /** | ||
290 | * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_{ACK|NACK|DESTROY} | ||
291 | */ | ||
292 | struct GNUNET_MessageHeader header; | ||
293 | |||
294 | /** | ||
295 | * ID of the channel | ||
296 | */ | ||
297 | MESH_ChannelNumber chid GNUNET_PACKED; | ||
298 | }; | ||
299 | |||
300 | /** | ||
301 | * Message for mesh data traffic. | ||
302 | */ | ||
303 | struct GNUNET_MESH_Data | ||
162 | { | 304 | { |
163 | /** | 305 | /** |
164 | * Type: GNUNET_MESSAGE_TYPE_MESH_ACK | 306 | * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST, |
307 | * GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN | ||
165 | */ | 308 | */ |
166 | struct GNUNET_MessageHeader header; | 309 | struct GNUNET_MessageHeader header; |
167 | 310 | ||
168 | /** | 311 | /** |
169 | * TID of the tunnel | 312 | * Unique ID of the payload message |
170 | */ | 313 | */ |
171 | uint32_t tid GNUNET_PACKED; | 314 | uint32_t mid GNUNET_PACKED; |
172 | 315 | ||
173 | /** | 316 | /** |
174 | * OID of the tunnel | 317 | * ID of the channel |
175 | */ | 318 | */ |
176 | struct GNUNET_PeerIdentity oid; | 319 | MESH_ChannelNumber chid GNUNET_PACKED; |
177 | 320 | ||
178 | /** | 321 | /** |
179 | * Maximum packet ID authorized. | 322 | * Payload follows |
180 | */ | 323 | */ |
181 | uint32_t pid GNUNET_PACKED; | ||
182 | }; | 324 | }; |
183 | 325 | ||
184 | 326 | ||
185 | /** | 327 | /** |
186 | * Message to query a peer about its Flow Control status regarding a tunnel. | 328 | * Message to acknowledge end-to-end data. |
187 | */ | 329 | */ |
188 | struct GNUNET_MESH_Poll | 330 | struct GNUNET_MESH_DataACK |
189 | { | 331 | { |
190 | /** | 332 | /** |
191 | * Type: GNUNET_MESSAGE_TYPE_MESH_POLL | 333 | * Type: GNUNET_MESSAGE_TYPE_MESH_DATA_ACK |
192 | */ | 334 | */ |
193 | struct GNUNET_MessageHeader header; | 335 | struct GNUNET_MessageHeader header; |
194 | 336 | ||
195 | /** | 337 | /** |
196 | * TID of the tunnel | 338 | * ID of the channel |
197 | */ | 339 | */ |
198 | uint32_t tid GNUNET_PACKED; | 340 | MESH_ChannelNumber chid GNUNET_PACKED; |
199 | 341 | ||
200 | /** | 342 | /** |
201 | * OID of the tunnel | 343 | * Bitfield of already-received newer messages |
344 | * pid + 1 @ LSB | ||
345 | * pid + 64 @ MSB | ||
202 | */ | 346 | */ |
203 | struct GNUNET_PeerIdentity oid; | 347 | uint64_t futures GNUNET_PACKED; |
204 | 348 | ||
205 | /** | 349 | /** |
206 | * Last packet sent. | 350 | * Last message ID received. |
207 | */ | 351 | */ |
208 | uint32_t pid GNUNET_PACKED; | 352 | uint32_t mid GNUNET_PACKED; |
209 | }; | 353 | }; |
210 | 354 | ||
355 | |||
211 | /** | 356 | /** |
212 | * Message for ack'ing a path | 357 | * Message to acknowledge mesh encrypted traffic. |
213 | */ | 358 | */ |
214 | struct GNUNET_MESH_PathACK | 359 | struct GNUNET_MESH_ACK |
215 | { | 360 | { |
216 | /** | 361 | /** |
217 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_ACK | 362 | * Type: GNUNET_MESSAGE_TYPE_MESH_ACK |
218 | */ | 363 | */ |
219 | struct GNUNET_MessageHeader header; | 364 | struct GNUNET_MessageHeader header; |
220 | 365 | ||
221 | /** | 366 | /** |
222 | * TID of the tunnel | 367 | * Maximum packet ID authorized. |
223 | */ | 368 | */ |
224 | uint32_t tid GNUNET_PACKED; | 369 | uint32_t ack GNUNET_PACKED; |
225 | 370 | ||
226 | /** | 371 | /** |
227 | * OID of the tunnel | 372 | * ID of the connection. |
228 | */ | 373 | */ |
229 | struct GNUNET_PeerIdentity oid; | 374 | struct GNUNET_HashCode cid; |
375 | }; | ||
230 | 376 | ||
231 | /** | 377 | |
232 | * ID of the endpoint | 378 | /** |
233 | */ | 379 | * Message to query a peer about its Flow Control status regarding a tunnel. |
234 | struct GNUNET_PeerIdentity peer_id; | 380 | */ |
381 | struct GNUNET_MESH_Poll | ||
382 | { | ||
383 | /** | ||
384 | * Type: GNUNET_MESSAGE_TYPE_MESH_POLL | ||
385 | */ | ||
386 | struct GNUNET_MessageHeader header; | ||
387 | |||
388 | /** | ||
389 | * Last packet sent. | ||
390 | */ | ||
391 | uint32_t pid GNUNET_PACKED; | ||
235 | 392 | ||
236 | /** | 393 | /** |
237 | * Initial ACK value for payload. | 394 | * ID of the connection. |
238 | */ | 395 | */ |
239 | uint32_t ack GNUNET_PACKED; | 396 | struct GNUNET_HashCode cid; |
240 | 397 | ||
241 | /* TODO: signature */ | ||
242 | }; | 398 | }; |
243 | 399 | ||
244 | 400 | ||
245 | /** | 401 | /** |
246 | * Message for notifying a disconnection in a path | 402 | * Message for notifying a disconnection in a path |
247 | */ | 403 | */ |
248 | struct GNUNET_MESH_PathBroken | 404 | struct GNUNET_MESH_ConnectionBroken |
249 | { | 405 | { |
250 | /** | 406 | /** |
251 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN | 407 | * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN |
252 | */ | 408 | */ |
253 | struct GNUNET_MessageHeader header; | 409 | struct GNUNET_MessageHeader header; |
254 | 410 | ||
255 | /** | 411 | /** |
256 | * TID of the tunnel | 412 | * Always 0. |
257 | */ | 413 | */ |
258 | uint32_t tid GNUNET_PACKED; | 414 | uint32_t reserved GNUNET_PACKED; |
259 | 415 | ||
260 | /** | 416 | /** |
261 | * OID of the tunnel | 417 | * ID of the connection. |
262 | */ | 418 | */ |
263 | struct GNUNET_PeerIdentity oid; | 419 | struct GNUNET_HashCode cid; |
264 | 420 | ||
265 | /** | 421 | /** |
266 | * ID of the endpoint | 422 | * ID of the endpoint |
@@ -277,48 +433,48 @@ struct GNUNET_MESH_PathBroken | |||
277 | 433 | ||
278 | 434 | ||
279 | /** | 435 | /** |
280 | * Message to destroy a tunnel | 436 | * Message to destroy a connection. |
281 | */ | 437 | */ |
282 | struct GNUNET_MESH_TunnelDestroy | 438 | struct GNUNET_MESH_ConnectionDestroy |
283 | { | 439 | { |
284 | /** | 440 | /** |
285 | * Type: GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY | 441 | * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY |
286 | */ | 442 | */ |
287 | struct GNUNET_MessageHeader header; | 443 | struct GNUNET_MessageHeader header; |
288 | 444 | ||
289 | /** | 445 | /** |
290 | * TID of the tunnel | 446 | * Always 0. |
291 | */ | 447 | */ |
292 | uint32_t tid GNUNET_PACKED; | 448 | uint32_t reserved GNUNET_PACKED; |
293 | 449 | ||
294 | /** | 450 | /** |
295 | * OID of the tunnel | 451 | * ID of the connection. |
296 | */ | 452 | */ |
297 | struct GNUNET_PeerIdentity oid; | 453 | struct GNUNET_HashCode cid; |
298 | 454 | ||
299 | /* TODO: signature */ | 455 | /* TODO: signature */ |
300 | }; | 456 | }; |
301 | 457 | ||
302 | 458 | ||
303 | /** | 459 | /** |
304 | * Message to destroy a tunnel | 460 | * Message to keep a connection alive. |
305 | */ | 461 | */ |
306 | struct GNUNET_MESH_TunnelKeepAlive | 462 | struct GNUNET_MESH_ConnectionKeepAlive |
307 | { | 463 | { |
308 | /** | 464 | /** |
309 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_(FWD|BCK)_KEEPALIVE | 465 | * Type: GNUNET_MESSAGE_TYPE_MESH_(FWD|BCK)_KEEPALIVE |
310 | */ | 466 | */ |
311 | struct GNUNET_MessageHeader header; | 467 | struct GNUNET_MessageHeader header; |
312 | 468 | ||
313 | /** | 469 | /** |
314 | * TID of the tunnel | 470 | * Always 0. |
315 | */ | 471 | */ |
316 | uint32_t tid GNUNET_PACKED; | 472 | uint32_t reserved GNUNET_PACKED; |
317 | 473 | ||
318 | /** | 474 | /** |
319 | * OID of the tunnel | 475 | * ID of the connection. |
320 | */ | 476 | */ |
321 | struct GNUNET_PeerIdentity oid; | 477 | struct GNUNET_HashCode cid; |
322 | }; | 478 | }; |
323 | 479 | ||
324 | 480 | ||
diff --git a/src/mesh/mesh_protocol_enc.h b/src/mesh/mesh_protocol_enc.h deleted file mode 100644 index aa26a6237..000000000 --- a/src/mesh/mesh_protocol_enc.h +++ /dev/null | |||
@@ -1,493 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001 - 2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @author Bartlomiej Polot | ||
23 | * @file mesh/mesh_protocol_enc.h | ||
24 | */ | ||
25 | |||
26 | #ifndef MESH_PROTOCOL_ENC_H_ | ||
27 | #define MESH_PROTOCOL_ENC_H_ | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "mesh_enc.h" | ||
32 | |||
33 | #ifdef __cplusplus | ||
34 | |||
35 | struct GNUNET_MESH_TunnelMessage; | ||
36 | extern "C" | ||
37 | { | ||
38 | #if 0 | ||
39 | /* keep Emacsens' auto-indent happy */ | ||
40 | } | ||
41 | #endif | ||
42 | #endif | ||
43 | |||
44 | /******************************************************************************/ | ||
45 | /******************** MESH NETWORK MESSAGES **************************/ | ||
46 | /******************************************************************************/ | ||
47 | |||
48 | GNUNET_NETWORK_STRUCT_BEGIN | ||
49 | |||
50 | /** | ||
51 | * Message for mesh connection creation. | ||
52 | * TODO onionify path, add random tunnel ID | ||
53 | */ | ||
54 | struct GNUNET_MESH_ConnectionCreate | ||
55 | { | ||
56 | /** | ||
57 | * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE | ||
58 | * | ||
59 | * Size: sizeof(struct GNUNET_MESH_ManipulatePath) + | ||
60 | * path_length * sizeof (struct GNUNET_PeerIdentity) | ||
61 | */ | ||
62 | struct GNUNET_MessageHeader header; | ||
63 | |||
64 | /** | ||
65 | * ID of the connection | ||
66 | */ | ||
67 | struct GNUNET_HashCode cid; | ||
68 | |||
69 | /** | ||
70 | * path_length structs defining the *whole* path from the origin [0] to the | ||
71 | * final destination [path_length-1]. | ||
72 | */ | ||
73 | /* struct GNUNET_PeerIdentity peers[path_length]; */ | ||
74 | }; | ||
75 | |||
76 | /** | ||
77 | * Message for ack'ing a connection | ||
78 | */ | ||
79 | struct GNUNET_MESH_ConnectionACK | ||
80 | { | ||
81 | /** | ||
82 | * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK | ||
83 | */ | ||
84 | struct GNUNET_MessageHeader header; | ||
85 | |||
86 | /** | ||
87 | * Always 0. | ||
88 | */ | ||
89 | uint32_t reserved GNUNET_PACKED; | ||
90 | |||
91 | /** | ||
92 | * ID of the connection. | ||
93 | */ | ||
94 | struct GNUNET_HashCode cid; | ||
95 | |||
96 | /* TODO: signature */ | ||
97 | }; | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Message for encapsulation of a Key eXchange message in a connection. | ||
102 | */ | ||
103 | struct GNUNET_MESH_KX | ||
104 | { | ||
105 | /** | ||
106 | * Type: GNUNET_MESSAGE_TYPE_MESH_KX. | ||
107 | */ | ||
108 | struct GNUNET_MessageHeader header; | ||
109 | |||
110 | /** | ||
111 | * Always 0. | ||
112 | */ | ||
113 | uint32_t reserved GNUNET_PACKED; | ||
114 | |||
115 | /** | ||
116 | * ID of the connection. | ||
117 | */ | ||
118 | struct GNUNET_HashCode cid; | ||
119 | |||
120 | /* Specific KX message follows. */ | ||
121 | }; | ||
122 | |||
123 | |||
124 | /** | ||
125 | * Message transmitted with the signed ephemeral key of a peer. The | ||
126 | * session key is then derived from the two ephemeral keys (ECDHE). | ||
127 | * | ||
128 | * As far as possible, same as CORE's EphemeralKeyMessage. | ||
129 | */ | ||
130 | struct GNUNET_MESH_KX_Ephemeral | ||
131 | { | ||
132 | |||
133 | /** | ||
134 | * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_EPHEMERAL. | ||
135 | */ | ||
136 | struct GNUNET_MessageHeader header; | ||
137 | |||
138 | /** | ||
139 | * Status of the sender (should be in "enum PeerStateMachine"), nbo. | ||
140 | */ | ||
141 | int32_t sender_status GNUNET_PACKED; | ||
142 | |||
143 | /** | ||
144 | * An ECC signature of the 'origin' asserting the validity of | ||
145 | * the given ephemeral key. | ||
146 | */ | ||
147 | struct GNUNET_CRYPTO_EddsaSignature signature; | ||
148 | |||
149 | /** | ||
150 | * Information about what is being signed. | ||
151 | */ | ||
152 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
153 | |||
154 | /** | ||
155 | * At what time was this key created (beginning of validity). | ||
156 | */ | ||
157 | struct GNUNET_TIME_AbsoluteNBO creation_time; | ||
158 | |||
159 | /** | ||
160 | * When does the given ephemeral key expire (end of validity). | ||
161 | */ | ||
162 | struct GNUNET_TIME_AbsoluteNBO expiration_time; | ||
163 | |||
164 | /** | ||
165 | * Ephemeral public ECC key (always for NIST P-521) encoded in a format suitable | ||
166 | * for network transmission as created using 'gcry_sexp_sprint'. | ||
167 | */ | ||
168 | struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; | ||
169 | |||
170 | /** | ||
171 | * Public key of the signing peer (persistent version, not the ephemeral public key). | ||
172 | */ | ||
173 | struct GNUNET_PeerIdentity origin_identity; | ||
174 | }; | ||
175 | |||
176 | |||
177 | /** | ||
178 | * We're sending an (encrypted) PING to the other peer to check if he | ||
179 | * can decrypt. The other peer should respond with a PONG with the | ||
180 | * same content, except this time encrypted with the receiver's key. | ||
181 | */ | ||
182 | struct GNUNET_MESH_KX_Ping | ||
183 | { | ||
184 | /** | ||
185 | * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PING. | ||
186 | */ | ||
187 | struct GNUNET_MessageHeader header; | ||
188 | |||
189 | /** | ||
190 | * Seed for the IV | ||
191 | */ | ||
192 | uint32_t iv GNUNET_PACKED; | ||
193 | |||
194 | /** | ||
195 | * Intended target of the PING, used primarily to check | ||
196 | * that decryption actually worked. | ||
197 | */ | ||
198 | struct GNUNET_PeerIdentity target; | ||
199 | |||
200 | /** | ||
201 | * Random number chosen to make reply harder. | ||
202 | */ | ||
203 | uint32_t nonce GNUNET_PACKED; | ||
204 | }; | ||
205 | |||
206 | |||
207 | /** | ||
208 | * Response to a PING. Includes data from the original PING. | ||
209 | */ | ||
210 | struct GNUNET_MESH_KX_Pong | ||
211 | { | ||
212 | /** | ||
213 | * Message type is GNUNET_MESSAGE_TYPE_MESH_KX_PONG. | ||
214 | */ | ||
215 | struct GNUNET_MessageHeader header; | ||
216 | |||
217 | /** | ||
218 | * Seed for the IV | ||
219 | */ | ||
220 | uint32_t iv GNUNET_PACKED; | ||
221 | |||
222 | /** | ||
223 | * Same nonce as in the reve. | ||
224 | */ | ||
225 | uint32_t nonce GNUNET_PACKED; | ||
226 | }; | ||
227 | |||
228 | |||
229 | /** | ||
230 | * Tunnel(ed) message. | ||
231 | */ | ||
232 | struct GNUNET_MESH_Encrypted | ||
233 | { | ||
234 | /** | ||
235 | * Type: GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED | ||
236 | */ | ||
237 | struct GNUNET_MessageHeader header; | ||
238 | |||
239 | /** | ||
240 | * Initialization Vector for payload encryption. | ||
241 | */ | ||
242 | uint32_t iv GNUNET_PACKED; | ||
243 | |||
244 | /** | ||
245 | * ID of the connection. | ||
246 | */ | ||
247 | struct GNUNET_HashCode cid; | ||
248 | |||
249 | /** | ||
250 | * ID of the packet (hop by hop). | ||
251 | */ | ||
252 | uint32_t pid GNUNET_PACKED; | ||
253 | |||
254 | /** | ||
255 | * Number of hops to live. | ||
256 | */ | ||
257 | uint32_t ttl GNUNET_PACKED; | ||
258 | |||
259 | /** | ||
260 | * Encrypted content follows. | ||
261 | */ | ||
262 | }; | ||
263 | |||
264 | struct GNUNET_MESH_ChannelCreate | ||
265 | { | ||
266 | /** | ||
267 | * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE | ||
268 | */ | ||
269 | struct GNUNET_MessageHeader header; | ||
270 | |||
271 | /** | ||
272 | * ID of the channel | ||
273 | */ | ||
274 | MESH_ChannelNumber chid GNUNET_PACKED; | ||
275 | |||
276 | /** | ||
277 | * Destination port. | ||
278 | */ | ||
279 | uint32_t port GNUNET_PACKED; | ||
280 | |||
281 | /** | ||
282 | * Channel options. | ||
283 | */ | ||
284 | uint32_t opt GNUNET_PACKED; | ||
285 | }; | ||
286 | |||
287 | struct GNUNET_MESH_ChannelManage | ||
288 | { | ||
289 | /** | ||
290 | * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_{ACK|NACK|DESTROY} | ||
291 | */ | ||
292 | struct GNUNET_MessageHeader header; | ||
293 | |||
294 | /** | ||
295 | * ID of the channel | ||
296 | */ | ||
297 | MESH_ChannelNumber chid GNUNET_PACKED; | ||
298 | }; | ||
299 | |||
300 | /** | ||
301 | * Message for mesh data traffic. | ||
302 | */ | ||
303 | struct GNUNET_MESH_Data | ||
304 | { | ||
305 | /** | ||
306 | * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST, | ||
307 | * GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN | ||
308 | */ | ||
309 | struct GNUNET_MessageHeader header; | ||
310 | |||
311 | /** | ||
312 | * Unique ID of the payload message | ||
313 | */ | ||
314 | uint32_t mid GNUNET_PACKED; | ||
315 | |||
316 | /** | ||
317 | * ID of the channel | ||
318 | */ | ||
319 | MESH_ChannelNumber chid GNUNET_PACKED; | ||
320 | |||
321 | /** | ||
322 | * Payload follows | ||
323 | */ | ||
324 | }; | ||
325 | |||
326 | |||
327 | /** | ||
328 | * Message to acknowledge end-to-end data. | ||
329 | */ | ||
330 | struct GNUNET_MESH_DataACK | ||
331 | { | ||
332 | /** | ||
333 | * Type: GNUNET_MESSAGE_TYPE_MESH_DATA_ACK | ||
334 | */ | ||
335 | struct GNUNET_MessageHeader header; | ||
336 | |||
337 | /** | ||
338 | * ID of the channel | ||
339 | */ | ||
340 | MESH_ChannelNumber chid GNUNET_PACKED; | ||
341 | |||
342 | /** | ||
343 | * Bitfield of already-received newer messages | ||
344 | * pid + 1 @ LSB | ||
345 | * pid + 64 @ MSB | ||
346 | */ | ||
347 | uint64_t futures GNUNET_PACKED; | ||
348 | |||
349 | /** | ||
350 | * Last message ID received. | ||
351 | */ | ||
352 | uint32_t mid GNUNET_PACKED; | ||
353 | }; | ||
354 | |||
355 | |||
356 | /** | ||
357 | * Message to acknowledge mesh encrypted traffic. | ||
358 | */ | ||
359 | struct GNUNET_MESH_ACK | ||
360 | { | ||
361 | /** | ||
362 | * Type: GNUNET_MESSAGE_TYPE_MESH_ACK | ||
363 | */ | ||
364 | struct GNUNET_MessageHeader header; | ||
365 | |||
366 | /** | ||
367 | * Maximum packet ID authorized. | ||
368 | */ | ||
369 | uint32_t ack GNUNET_PACKED; | ||
370 | |||
371 | /** | ||
372 | * ID of the connection. | ||
373 | */ | ||
374 | struct GNUNET_HashCode cid; | ||
375 | }; | ||
376 | |||
377 | |||
378 | /** | ||
379 | * Message to query a peer about its Flow Control status regarding a tunnel. | ||
380 | */ | ||
381 | struct GNUNET_MESH_Poll | ||
382 | { | ||
383 | /** | ||
384 | * Type: GNUNET_MESSAGE_TYPE_MESH_POLL | ||
385 | */ | ||
386 | struct GNUNET_MessageHeader header; | ||
387 | |||
388 | /** | ||
389 | * Last packet sent. | ||
390 | */ | ||
391 | uint32_t pid GNUNET_PACKED; | ||
392 | |||
393 | /** | ||
394 | * ID of the connection. | ||
395 | */ | ||
396 | struct GNUNET_HashCode cid; | ||
397 | |||
398 | }; | ||
399 | |||
400 | |||
401 | /** | ||
402 | * Message for notifying a disconnection in a path | ||
403 | */ | ||
404 | struct GNUNET_MESH_ConnectionBroken | ||
405 | { | ||
406 | /** | ||
407 | * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN | ||
408 | */ | ||
409 | struct GNUNET_MessageHeader header; | ||
410 | |||
411 | /** | ||
412 | * Always 0. | ||
413 | */ | ||
414 | uint32_t reserved GNUNET_PACKED; | ||
415 | |||
416 | /** | ||
417 | * ID of the connection. | ||
418 | */ | ||
419 | struct GNUNET_HashCode cid; | ||
420 | |||
421 | /** | ||
422 | * ID of the endpoint | ||
423 | */ | ||
424 | struct GNUNET_PeerIdentity peer1; | ||
425 | |||
426 | /** | ||
427 | * ID of the endpoint | ||
428 | */ | ||
429 | struct GNUNET_PeerIdentity peer2; | ||
430 | |||
431 | /* TODO: signature */ | ||
432 | }; | ||
433 | |||
434 | |||
435 | /** | ||
436 | * Message to destroy a connection. | ||
437 | */ | ||
438 | struct GNUNET_MESH_ConnectionDestroy | ||
439 | { | ||
440 | /** | ||
441 | * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY | ||
442 | */ | ||
443 | struct GNUNET_MessageHeader header; | ||
444 | |||
445 | /** | ||
446 | * Always 0. | ||
447 | */ | ||
448 | uint32_t reserved GNUNET_PACKED; | ||
449 | |||
450 | /** | ||
451 | * ID of the connection. | ||
452 | */ | ||
453 | struct GNUNET_HashCode cid; | ||
454 | |||
455 | /* TODO: signature */ | ||
456 | }; | ||
457 | |||
458 | |||
459 | /** | ||
460 | * Message to keep a connection alive. | ||
461 | */ | ||
462 | struct GNUNET_MESH_ConnectionKeepAlive | ||
463 | { | ||
464 | /** | ||
465 | * Type: GNUNET_MESSAGE_TYPE_MESH_(FWD|BCK)_KEEPALIVE | ||
466 | */ | ||
467 | struct GNUNET_MessageHeader header; | ||
468 | |||
469 | /** | ||
470 | * Always 0. | ||
471 | */ | ||
472 | uint32_t reserved GNUNET_PACKED; | ||
473 | |||
474 | /** | ||
475 | * ID of the connection. | ||
476 | */ | ||
477 | struct GNUNET_HashCode cid; | ||
478 | }; | ||
479 | |||
480 | |||
481 | |||
482 | GNUNET_NETWORK_STRUCT_END | ||
483 | |||
484 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
485 | { | ||
486 | #endif | ||
487 | #ifdef __cplusplus | ||
488 | } | ||
489 | #endif | ||
490 | |||
491 | /* ifndef MESH_PROTOCOL_H */ | ||
492 | #endif | ||
493 | /* end of mesh_protocol.h */ | ||
diff --git a/src/mesh/mesh_test_lib.c b/src/mesh/mesh_test_lib.c index 022cee2f3..7ad888da8 100644 --- a/src/mesh/mesh_test_lib.c +++ b/src/mesh/mesh_test_lib.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_util_lib.h" | 26 | #include "gnunet_util_lib.h" |
27 | #include "mesh_test_lib.h" | 27 | #include "mesh_test_lib.h" |
28 | #include "gnunet_mesh_service_enc.h" | 28 | #include "gnunet_mesh_service.h" |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Test context for a MESH Test. | 31 | * Test context for a MESH Test. |
diff --git a/src/mesh/mesh_test_lib.h b/src/mesh/mesh_test_lib.h index 19625d2ab..96c7c60a4 100644 --- a/src/mesh/mesh_test_lib.h +++ b/src/mesh/mesh_test_lib.h | |||
@@ -34,7 +34,7 @@ extern "C" | |||
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #include "gnunet_testbed_service.h" | 36 | #include "gnunet_testbed_service.h" |
37 | #include "gnunet_mesh_service_enc.h" | 37 | #include "gnunet_mesh_service.h" |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Test context for a MESH Test. | 40 | * Test context for a MESH Test. |
diff --git a/src/mesh/test_mesh_local.c b/src/mesh/test_mesh_local.c index e5d9dd313..bdd603351 100644 --- a/src/mesh/test_mesh_local.c +++ b/src/mesh/test_mesh_local.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_dht_service.h" | 29 | #include "gnunet_dht_service.h" |
30 | #include "gnunet_testing_lib.h" | 30 | #include "gnunet_testing_lib.h" |
31 | #include "gnunet_mesh_service_enc.h" | 31 | #include "gnunet_mesh_service.h" |
32 | 32 | ||
33 | struct GNUNET_TESTING_Peer *me; | 33 | struct GNUNET_TESTING_Peer *me; |
34 | 34 | ||
diff --git a/src/mesh/test_mesh_single.c b/src/mesh/test_mesh_single.c index 9e850079f..ec91bf224 100644 --- a/src/mesh/test_mesh_single.c +++ b/src/mesh/test_mesh_single.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_dht_service.h" | 29 | #include "gnunet_dht_service.h" |
30 | #include "gnunet_testing_lib.h" | 30 | #include "gnunet_testing_lib.h" |
31 | #include "gnunet_mesh_service_enc.h" | 31 | #include "gnunet_mesh_service.h" |
32 | 32 | ||
33 | #define REPETITIONS 5 | 33 | #define REPETITIONS 5 |
34 | #define DATA_SIZE 35000 | 34 | #define DATA_SIZE 35000 |
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c index 439f6ec5c..cfebcaac8 100644 --- a/src/mesh/test_mesh_small.c +++ b/src/mesh/test_mesh_small.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "mesh_test_lib.h" | 27 | #include "mesh_test_lib.h" |
28 | #include "gnunet_mesh_service_enc.h" | 28 | #include "gnunet_mesh_service.h" |
29 | #include <gauger.h> | 29 | #include <gauger.h> |
30 | 30 | ||
31 | 31 | ||
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c index f10274328..6375406d9 100644 --- a/src/pt/gnunet-daemon-pt.c +++ b/src/pt/gnunet-daemon-pt.c | |||
@@ -51,7 +51,7 @@ | |||
51 | #define MAX_DNS_SIZE (8 * 1024) | 51 | #define MAX_DNS_SIZE (8 * 1024) |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * How many tunnels do we open at most at the same time? | 54 | * How many channels do we open at most at the same time? |
55 | */ | 55 | */ |
56 | #define MAX_OPEN_TUNNELS 4 | 56 | #define MAX_OPEN_TUNNELS 4 |
57 | 57 | ||
@@ -123,7 +123,7 @@ struct ReplyContext | |||
123 | 123 | ||
124 | /** | 124 | /** |
125 | * Handle to a peer that advertised that it is willing to serve | 125 | * Handle to a peer that advertised that it is willing to serve |
126 | * as a DNS exit. We try to keep a few tunnels open and a few | 126 | * as a DNS exit. We try to keep a few channels open and a few |
127 | * peers in reserve. | 127 | * peers in reserve. |
128 | */ | 128 | */ |
129 | struct MeshExit | 129 | struct MeshExit |
@@ -140,10 +140,10 @@ struct MeshExit | |||
140 | struct MeshExit *prev; | 140 | struct MeshExit *prev; |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * Tunnel we use for DNS requests over MESH, NULL if we did | 143 | * Channel we use for DNS requests over MESH, NULL if we did |
144 | * not initialze a tunnel to this peer yet. | 144 | * not initialze a channel to this peer yet. |
145 | */ | 145 | */ |
146 | struct GNUNET_MESH_Tunnel *mesh_tunnel; | 146 | struct GNUNET_MESH_Channel *mesh_channel; |
147 | 147 | ||
148 | /** | 148 | /** |
149 | * At what time did the peer's advertisement expire? | 149 | * At what time did the peer's advertisement expire? |
@@ -161,17 +161,17 @@ struct MeshExit | |||
161 | struct RequestContext *receive_queue_tail; | 161 | struct RequestContext *receive_queue_tail; |
162 | 162 | ||
163 | /** | 163 | /** |
164 | * Head of DLL of requests to be transmitted to a mesh_tunnel. | 164 | * Head of DLL of requests to be transmitted to a mesh_channel. |
165 | */ | 165 | */ |
166 | struct RequestContext *transmit_queue_head; | 166 | struct RequestContext *transmit_queue_head; |
167 | 167 | ||
168 | /** | 168 | /** |
169 | * Tail of DLL of requests to be transmitted to a mesh_tunnel. | 169 | * Tail of DLL of requests to be transmitted to a mesh_channel. |
170 | */ | 170 | */ |
171 | struct RequestContext *transmit_queue_tail; | 171 | struct RequestContext *transmit_queue_tail; |
172 | 172 | ||
173 | /** | 173 | /** |
174 | * Active transmission request for this tunnel (or NULL). | 174 | * Active transmission request for this channel (or NULL). |
175 | */ | 175 | */ |
176 | struct GNUNET_MESH_TransmitHandle *mesh_th; | 176 | struct GNUNET_MESH_TransmitHandle *mesh_th; |
177 | 177 | ||
@@ -181,12 +181,12 @@ struct MeshExit | |||
181 | struct GNUNET_PeerIdentity peer; | 181 | struct GNUNET_PeerIdentity peer; |
182 | 182 | ||
183 | /** | 183 | /** |
184 | * How many DNS requests did we transmit via this tunnel? | 184 | * How many DNS requests did we transmit via this channel? |
185 | */ | 185 | */ |
186 | unsigned int num_transmitted; | 186 | unsigned int num_transmitted; |
187 | 187 | ||
188 | /** | 188 | /** |
189 | * How many DNS requests were answered via this tunnel? | 189 | * How many DNS requests were answered via this channel? |
190 | */ | 190 | */ |
191 | unsigned int num_answered; | 191 | unsigned int num_answered; |
192 | 192 | ||
@@ -250,7 +250,7 @@ struct RequestContext | |||
250 | 250 | ||
251 | 251 | ||
252 | /** | 252 | /** |
253 | * Head of DLL of mesh exits. Mesh exits with an open tunnel are | 253 | * Head of DLL of mesh exits. Mesh exits with an open channel are |
254 | * always at the beginning (so we do not have to traverse the entire | 254 | * always at the beginning (so we do not have to traverse the entire |
255 | * list to find them). | 255 | * list to find them). |
256 | */ | 256 | */ |
@@ -312,14 +312,14 @@ static int ipv4_pt; | |||
312 | static int ipv6_pt; | 312 | static int ipv6_pt; |
313 | 313 | ||
314 | /** | 314 | /** |
315 | * Are we tunneling DNS queries? | 315 | * Are we channeling DNS queries? |
316 | */ | 316 | */ |
317 | static int dns_tunnel; | 317 | static int dns_channel; |
318 | 318 | ||
319 | /** | 319 | /** |
320 | * Number of DNS exit peers we currently have in the mesh tunnel. | 320 | * Number of DNS exit peers we currently have in the mesh channel. |
321 | * Used to see if using the mesh tunnel makes any sense right now, | 321 | * Used to see if using the mesh channel makes any sense right now, |
322 | * as well as to decide if we should open new tunnels. | 322 | * as well as to decide if we should open new channels. |
323 | */ | 323 | */ |
324 | static unsigned int dns_exit_available; | 324 | static unsigned int dns_exit_available; |
325 | 325 | ||
@@ -336,25 +336,25 @@ try_open_exit () | |||
336 | 336 | ||
337 | candidate_count = 0; | 337 | candidate_count = 0; |
338 | for (pos = exit_head; NULL != pos; pos = pos->next) | 338 | for (pos = exit_head; NULL != pos; pos = pos->next) |
339 | if (NULL == pos->mesh_tunnel) | 339 | if (NULL == pos->mesh_channel) |
340 | candidate_count++; | 340 | candidate_count++; |
341 | candidate_selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 341 | candidate_selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
342 | candidate_count); | 342 | candidate_count); |
343 | candidate_count = 0; | 343 | candidate_count = 0; |
344 | for (pos = exit_head; NULL != pos; pos = pos->next) | 344 | for (pos = exit_head; NULL != pos; pos = pos->next) |
345 | if (NULL == pos->mesh_tunnel) | 345 | if (NULL == pos->mesh_channel) |
346 | { | 346 | { |
347 | candidate_count++; | 347 | candidate_count++; |
348 | if (candidate_selected < candidate_count) | 348 | if (candidate_selected < candidate_count) |
349 | { | 349 | { |
350 | /* move to the head of the DLL */ | 350 | /* move to the head of the DLL */ |
351 | pos->mesh_tunnel = GNUNET_MESH_tunnel_create (mesh_handle, | 351 | pos->mesh_channel = GNUNET_MESH_channel_create (mesh_handle, |
352 | pos, | 352 | pos, |
353 | &pos->peer, | 353 | &pos->peer, |
354 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, | 354 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, |
355 | GNUNET_YES /* no buffer */, | 355 | GNUNET_YES /* no buffer */, |
356 | GNUNET_NO /* reliable */); | 356 | GNUNET_NO /* reliable */); |
357 | if (NULL == pos->mesh_tunnel) | 357 | if (NULL == pos->mesh_channel) |
358 | { | 358 | { |
359 | GNUNET_break (0); | 359 | GNUNET_break (0); |
360 | continue; | 360 | continue; |
@@ -375,15 +375,15 @@ try_open_exit () | |||
375 | 375 | ||
376 | /** | 376 | /** |
377 | * Compute the weight of the given exit. The higher the weight, | 377 | * Compute the weight of the given exit. The higher the weight, |
378 | * the more likely it will be that the tunnel will be chosen. | 378 | * the more likely it will be that the channel will be chosen. |
379 | * A weigt of zero means that we should close the tunnel as it | 379 | * A weigt of zero means that we should close the channel as it |
380 | * is so bad, that we should not use it. | 380 | * is so bad, that we should not use it. |
381 | * | 381 | * |
382 | * @param exit exit to calculate the weight for | 382 | * @param exit exit to calculate the weight for |
383 | * @return weight of the tunnel | 383 | * @return weight of the channel |
384 | */ | 384 | */ |
385 | static uint32_t | 385 | static uint32_t |
386 | get_tunnel_weight (struct MeshExit *exit) | 386 | get_channel_weight (struct MeshExit *exit) |
387 | { | 387 | { |
388 | uint32_t dropped; | 388 | uint32_t dropped; |
389 | uint32_t drop_percent; | 389 | uint32_t drop_percent; |
@@ -407,12 +407,12 @@ get_tunnel_weight (struct MeshExit *exit) | |||
407 | 407 | ||
408 | 408 | ||
409 | /** | 409 | /** |
410 | * Choose a mesh exit for a DNS request. We try to use a tunnel | 410 | * Choose a mesh exit for a DNS request. We try to use a channel |
411 | * that is reliable and currently available. All existing | 411 | * that is reliable and currently available. All existing |
412 | * tunnels are given a base weight of 1, plus a score relating | 412 | * channels are given a base weight of 1, plus a score relating |
413 | * to the total number of queries answered in relation to the | 413 | * to the total number of queries answered in relation to the |
414 | * total number of queries we sent to that tunnel. That | 414 | * total number of queries we sent to that channel. That |
415 | * score is doubled if the tunnel is currently idle. | 415 | * score is doubled if the channel is currently idle. |
416 | * | 416 | * |
417 | * @return NULL if no exit is known, otherwise the | 417 | * @return NULL if no exit is known, otherwise the |
418 | * exit that we should use to queue a message with | 418 | * exit that we should use to queue a message with |
@@ -423,22 +423,22 @@ choose_exit () | |||
423 | struct MeshExit *pos; | 423 | struct MeshExit *pos; |
424 | uint64_t total_transmitted; | 424 | uint64_t total_transmitted; |
425 | uint64_t selected_offset; | 425 | uint64_t selected_offset; |
426 | uint32_t tunnel_weight; | 426 | uint32_t channel_weight; |
427 | 427 | ||
428 | total_transmitted = 0; | 428 | total_transmitted = 0; |
429 | for (pos = exit_head; NULL != pos; pos = pos->next) | 429 | for (pos = exit_head; NULL != pos; pos = pos->next) |
430 | { | 430 | { |
431 | if (NULL == pos->mesh_tunnel) | 431 | if (NULL == pos->mesh_channel) |
432 | break; | 432 | break; |
433 | tunnel_weight = get_tunnel_weight (pos); | 433 | channel_weight = get_channel_weight (pos); |
434 | total_transmitted += tunnel_weight; | 434 | total_transmitted += channel_weight; |
435 | /* double weight for idle tunnels */ | 435 | /* double weight for idle channels */ |
436 | if (NULL == pos->mesh_th) | 436 | if (NULL == pos->mesh_th) |
437 | total_transmitted += tunnel_weight; | 437 | total_transmitted += channel_weight; |
438 | } | 438 | } |
439 | if (0 == total_transmitted) | 439 | if (0 == total_transmitted) |
440 | { | 440 | { |
441 | /* no tunnels available, or only a very bad one... */ | 441 | /* no channels available, or only a very bad one... */ |
442 | return exit_head; | 442 | return exit_head; |
443 | } | 443 | } |
444 | selected_offset = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 444 | selected_offset = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -446,13 +446,13 @@ choose_exit () | |||
446 | total_transmitted = 0; | 446 | total_transmitted = 0; |
447 | for (pos = exit_head; NULL != pos; pos = pos->next) | 447 | for (pos = exit_head; NULL != pos; pos = pos->next) |
448 | { | 448 | { |
449 | if (NULL == pos->mesh_tunnel) | 449 | if (NULL == pos->mesh_channel) |
450 | break; | 450 | break; |
451 | tunnel_weight = get_tunnel_weight (pos); | 451 | channel_weight = get_channel_weight (pos); |
452 | total_transmitted += tunnel_weight; | 452 | total_transmitted += channel_weight; |
453 | /* double weight for idle tunnels */ | 453 | /* double weight for idle channels */ |
454 | if (NULL == pos->mesh_th) | 454 | if (NULL == pos->mesh_th) |
455 | total_transmitted += tunnel_weight; | 455 | total_transmitted += channel_weight; |
456 | if (total_transmitted > selected_offset) | 456 | if (total_transmitted > selected_offset) |
457 | return pos; | 457 | return pos; |
458 | } | 458 | } |
@@ -561,7 +561,7 @@ vpn_allocation_callback (void *cls, | |||
561 | 561 | ||
562 | 562 | ||
563 | /** | 563 | /** |
564 | * Modify the given DNS record by asking VPN to create a tunnel | 564 | * Modify the given DNS record by asking VPN to create a channel |
565 | * to the given address. When done, continue with submitting | 565 | * to the given address. When done, continue with submitting |
566 | * other records from the request context ('submit_request' is | 566 | * other records from the request context ('submit_request' is |
567 | * our continuation). | 567 | * our continuation). |
@@ -696,7 +696,7 @@ work_test (const struct GNUNET_DNSPARSER_Record *ra, | |||
696 | /** | 696 | /** |
697 | * This function is called AFTER we got an IP address for a | 697 | * This function is called AFTER we got an IP address for a |
698 | * DNS request. Now, the PT daemon has the chance to substitute | 698 | * DNS request. Now, the PT daemon has the chance to substitute |
699 | * the IP address with one from the VPN range to tunnel requests | 699 | * the IP address with one from the VPN range to channel requests |
700 | * destined for this IP address via VPN and MESH. | 700 | * destined for this IP address via VPN and MESH. |
701 | * | 701 | * |
702 | * @param cls closure | 702 | * @param cls closure |
@@ -768,7 +768,7 @@ transmit_dns_request_to_mesh (void *cls, | |||
768 | mlen = rc->mlen; | 768 | mlen = rc->mlen; |
769 | if (mlen > size) | 769 | if (mlen > size) |
770 | { | 770 | { |
771 | exit->mesh_th = GNUNET_MESH_notify_transmit_ready (exit->mesh_tunnel, | 771 | exit->mesh_th = GNUNET_MESH_notify_transmit_ready (exit->mesh_channel, |
772 | GNUNET_NO, | 772 | GNUNET_NO, |
773 | TIMEOUT, | 773 | TIMEOUT, |
774 | mlen, | 774 | mlen, |
@@ -787,7 +787,7 @@ transmit_dns_request_to_mesh (void *cls, | |||
787 | rc); | 787 | rc); |
788 | rc = exit->transmit_queue_head; | 788 | rc = exit->transmit_queue_head; |
789 | if (NULL != rc) | 789 | if (NULL != rc) |
790 | exit->mesh_th = GNUNET_MESH_notify_transmit_ready (exit->mesh_tunnel, | 790 | exit->mesh_th = GNUNET_MESH_notify_transmit_ready (exit->mesh_channel, |
791 | GNUNET_NO, | 791 | GNUNET_NO, |
792 | TIMEOUT, | 792 | TIMEOUT, |
793 | rc->mlen, | 793 | rc->mlen, |
@@ -828,15 +828,15 @@ timeout_request (void *cls, | |||
828 | 1, GNUNET_NO); | 828 | 1, GNUNET_NO); |
829 | GNUNET_DNS_request_drop (rc->rh); | 829 | GNUNET_DNS_request_drop (rc->rh); |
830 | GNUNET_free (rc); | 830 | GNUNET_free (rc); |
831 | if ( (0 == get_tunnel_weight (exit)) && | 831 | if ( (0 == get_channel_weight (exit)) && |
832 | (NULL == exit->receive_queue_head) && | 832 | (NULL == exit->receive_queue_head) && |
833 | (NULL == exit->transmit_queue_head) ) | 833 | (NULL == exit->transmit_queue_head) ) |
834 | { | 834 | { |
835 | /* this straw broke the camel's back: this tunnel now has | 835 | /* this straw broke the camel's back: this channel now has |
836 | such a low score that it will not be used; close it! */ | 836 | such a low score that it will not be used; close it! */ |
837 | GNUNET_assert (NULL == exit->mesh_th); | 837 | GNUNET_assert (NULL == exit->mesh_th); |
838 | GNUNET_MESH_tunnel_destroy (exit->mesh_tunnel); | 838 | GNUNET_MESH_channel_destroy (exit->mesh_channel); |
839 | exit->mesh_tunnel = NULL; | 839 | exit->mesh_channel = NULL; |
840 | GNUNET_CONTAINER_DLL_remove (exit_head, | 840 | GNUNET_CONTAINER_DLL_remove (exit_head, |
841 | exit_tail, | 841 | exit_tail, |
842 | exit); | 842 | exit); |
@@ -845,7 +845,7 @@ timeout_request (void *cls, | |||
845 | exit); | 845 | exit); |
846 | /* go back to semi-innocent: mark as not great, but | 846 | /* go back to semi-innocent: mark as not great, but |
847 | avoid a prohibitively negative score (see | 847 | avoid a prohibitively negative score (see |
848 | #get_tunnel_weight, which checks for a certain | 848 | #get_channel_weight, which checks for a certain |
849 | minimum number of transmissions before making | 849 | minimum number of transmissions before making |
850 | up an opinion) */ | 850 | up an opinion) */ |
851 | exit->num_transmitted = 5; | 851 | exit->num_transmitted = 5; |
@@ -859,9 +859,9 @@ timeout_request (void *cls, | |||
859 | 859 | ||
860 | /** | 860 | /** |
861 | * This function is called *before* the DNS request has been | 861 | * This function is called *before* the DNS request has been |
862 | * given to a "local" DNS resolver. Tunneling for DNS requests | 862 | * given to a "local" DNS resolver. Channeling for DNS requests |
863 | * was enabled, so we now need to send the request via some MESH | 863 | * was enabled, so we now need to send the request via some MESH |
864 | * tunnel to a DNS EXIT for resolution. | 864 | * channel to a DNS EXIT for resolution. |
865 | * | 865 | * |
866 | * @param cls closure | 866 | * @param cls closure |
867 | * @param rh request handle to user for reply | 867 | * @param rh request handle to user for reply |
@@ -886,7 +886,7 @@ dns_pre_request_handler (void *cls, | |||
886 | if (0 == dns_exit_available) | 886 | if (0 == dns_exit_available) |
887 | { | 887 | { |
888 | GNUNET_STATISTICS_update (stats, | 888 | GNUNET_STATISTICS_update (stats, |
889 | gettext_noop ("# DNS requests dropped (DNS mesh tunnel down)"), | 889 | gettext_noop ("# DNS requests dropped (DNS mesh channel down)"), |
890 | 1, GNUNET_NO); | 890 | 1, GNUNET_NO); |
891 | GNUNET_DNS_request_drop (rh); | 891 | GNUNET_DNS_request_drop (rh); |
892 | return; | 892 | return; |
@@ -903,7 +903,7 @@ dns_pre_request_handler (void *cls, | |||
903 | mlen = sizeof (struct GNUNET_MessageHeader) + request_length; | 903 | mlen = sizeof (struct GNUNET_MessageHeader) + request_length; |
904 | exit = choose_exit (); | 904 | exit = choose_exit (); |
905 | GNUNET_assert (NULL != exit); | 905 | GNUNET_assert (NULL != exit); |
906 | GNUNET_assert (NULL != exit->mesh_tunnel); | 906 | GNUNET_assert (NULL != exit->mesh_channel); |
907 | rc = GNUNET_malloc (sizeof (struct RequestContext) + mlen); | 907 | rc = GNUNET_malloc (sizeof (struct RequestContext) + mlen); |
908 | rc->exit = exit; | 908 | rc->exit = exit; |
909 | rc->rh = rh; | 909 | rc->rh = rh; |
@@ -923,7 +923,7 @@ dns_pre_request_handler (void *cls, | |||
923 | exit->transmit_queue_tail, | 923 | exit->transmit_queue_tail, |
924 | rc); | 924 | rc); |
925 | if (NULL == exit->mesh_th) | 925 | if (NULL == exit->mesh_th) |
926 | exit->mesh_th = GNUNET_MESH_notify_transmit_ready (exit->mesh_tunnel, | 926 | exit->mesh_th = GNUNET_MESH_notify_transmit_ready (exit->mesh_channel, |
927 | GNUNET_NO, | 927 | GNUNET_NO, |
928 | TIMEOUT, | 928 | TIMEOUT, |
929 | mlen, | 929 | mlen, |
@@ -936,19 +936,19 @@ dns_pre_request_handler (void *cls, | |||
936 | * Process a request via mesh to perform a DNS query. | 936 | * Process a request via mesh to perform a DNS query. |
937 | * | 937 | * |
938 | * @param cls NULL | 938 | * @param cls NULL |
939 | * @param tunnel connection to the other end | 939 | * @param channel connection to the other end |
940 | * @param tunnel_ctx pointer to our `struct MeshExit` | 940 | * @param channel_ctx pointer to our `struct MeshExit` |
941 | * @param message the actual message | 941 | * @param message the actual message |
942 | * @return #GNUNET_OK to keep the connection open, | 942 | * @return #GNUNET_OK to keep the connection open, |
943 | * #GNUNET_SYSERR to close it (signal serious error) | 943 | * #GNUNET_SYSERR to close it (signal serious error) |
944 | */ | 944 | */ |
945 | static int | 945 | static int |
946 | receive_dns_response (void *cls, | 946 | receive_dns_response (void *cls, |
947 | struct GNUNET_MESH_Tunnel *tunnel, | 947 | struct GNUNET_MESH_Channel *channel, |
948 | void **tunnel_ctx, | 948 | void **channel_ctx, |
949 | const struct GNUNET_MessageHeader *message) | 949 | const struct GNUNET_MessageHeader *message) |
950 | { | 950 | { |
951 | struct MeshExit *exit = *tunnel_ctx; | 951 | struct MeshExit *exit = *channel_ctx; |
952 | struct GNUNET_TUN_DnsHeader dns; | 952 | struct GNUNET_TUN_DnsHeader dns; |
953 | size_t mlen; | 953 | size_t mlen; |
954 | struct RequestContext *rc; | 954 | struct RequestContext *rc; |
@@ -1049,10 +1049,10 @@ cleanup (void *cls, | |||
1049 | GNUNET_MESH_notify_transmit_ready_cancel (exit->mesh_th); | 1049 | GNUNET_MESH_notify_transmit_ready_cancel (exit->mesh_th); |
1050 | exit->mesh_th = NULL; | 1050 | exit->mesh_th = NULL; |
1051 | } | 1051 | } |
1052 | if (NULL != exit->mesh_tunnel) | 1052 | if (NULL != exit->mesh_channel) |
1053 | { | 1053 | { |
1054 | GNUNET_MESH_tunnel_destroy (exit->mesh_tunnel); | 1054 | GNUNET_MESH_channel_destroy (exit->mesh_channel); |
1055 | exit->mesh_tunnel = NULL; | 1055 | exit->mesh_channel = NULL; |
1056 | } | 1056 | } |
1057 | abort_all_requests (exit); | 1057 | abort_all_requests (exit); |
1058 | GNUNET_free (exit); | 1058 | GNUNET_free (exit); |
@@ -1091,22 +1091,22 @@ cleanup (void *cls, | |||
1091 | 1091 | ||
1092 | 1092 | ||
1093 | /** | 1093 | /** |
1094 | * Function called whenever a tunnel is destroyed. Should clean up | 1094 | * Function called whenever a channel is destroyed. Should clean up |
1095 | * the associated state and attempt to build a new one. | 1095 | * the associated state and attempt to build a new one. |
1096 | * | 1096 | * |
1097 | * It must NOT call #GNUNET_MESH_tunnel_destroy on the tunnel. | 1097 | * It must NOT call #GNUNET_MESH_channel_destroy on the channel. |
1098 | * | 1098 | * |
1099 | * @param cls closure (the `struct MeshExit` set from #GNUNET_MESH_connect) | 1099 | * @param cls closure (the `struct MeshExit` set from #GNUNET_MESH_connect) |
1100 | * @param tunnel connection to the other end (henceforth invalid) | 1100 | * @param channel connection to the other end (henceforth invalid) |
1101 | * @param tunnel_ctx place where local state associated | 1101 | * @param channel_ctx place where local state associated |
1102 | * with the tunnel is stored | 1102 | * with the channel is stored |
1103 | */ | 1103 | */ |
1104 | static void | 1104 | static void |
1105 | mesh_tunnel_end_cb (void *cls, | 1105 | mesh_channel_end_cb (void *cls, |
1106 | const struct GNUNET_MESH_Tunnel *tunnel, | 1106 | const struct GNUNET_MESH_Channel *channel, |
1107 | void *tunnel_ctx) | 1107 | void *channel_ctx) |
1108 | { | 1108 | { |
1109 | struct MeshExit *exit = tunnel_ctx; | 1109 | struct MeshExit *exit = channel_ctx; |
1110 | struct MeshExit *alt; | 1110 | struct MeshExit *alt; |
1111 | struct RequestContext *rc; | 1111 | struct RequestContext *rc; |
1112 | 1112 | ||
@@ -1115,14 +1115,14 @@ mesh_tunnel_end_cb (void *cls, | |||
1115 | GNUNET_MESH_notify_transmit_ready_cancel (exit->mesh_th); | 1115 | GNUNET_MESH_notify_transmit_ready_cancel (exit->mesh_th); |
1116 | exit->mesh_th = NULL; | 1116 | exit->mesh_th = NULL; |
1117 | } | 1117 | } |
1118 | exit->mesh_tunnel = NULL; | 1118 | exit->mesh_channel = NULL; |
1119 | dns_exit_available--; | 1119 | dns_exit_available--; |
1120 | /* open alternative tunnels */ | 1120 | /* open alternative channels */ |
1121 | try_open_exit (); | 1121 | try_open_exit (); |
1122 | if (NULL == exit->mesh_tunnel) | 1122 | if (NULL == exit->mesh_channel) |
1123 | { | 1123 | { |
1124 | /* our tunnel is now closed, move our requests to an alternative | 1124 | /* our channel is now closed, move our requests to an alternative |
1125 | tunnel */ | 1125 | channel */ |
1126 | alt = choose_exit (); | 1126 | alt = choose_exit (); |
1127 | while (NULL != (rc = exit->transmit_queue_head)) | 1127 | while (NULL != (rc = exit->transmit_queue_head)) |
1128 | { | 1128 | { |
@@ -1153,7 +1153,7 @@ mesh_tunnel_end_cb (void *cls, | |||
1153 | } | 1153 | } |
1154 | if ( (NULL == alt->mesh_th) && | 1154 | if ( (NULL == alt->mesh_th) && |
1155 | (NULL != (rc = alt->transmit_queue_head)) ) | 1155 | (NULL != (rc = alt->transmit_queue_head)) ) |
1156 | alt->mesh_th = GNUNET_MESH_notify_transmit_ready (alt->mesh_tunnel, | 1156 | alt->mesh_th = GNUNET_MESH_notify_transmit_ready (alt->mesh_channel, |
1157 | GNUNET_NO, | 1157 | GNUNET_NO, |
1158 | TIMEOUT, | 1158 | TIMEOUT, |
1159 | rc->mlen, | 1159 | rc->mlen, |
@@ -1164,7 +1164,7 @@ mesh_tunnel_end_cb (void *cls, | |||
1164 | 1164 | ||
1165 | /** | 1165 | /** |
1166 | * Function called whenever we find an advertisement for a | 1166 | * Function called whenever we find an advertisement for a |
1167 | * DNS exit in the DHT. If we don't have a mesh tunnel, | 1167 | * DNS exit in the DHT. If we don't have a mesh channel, |
1168 | * we should build one; otherwise, we should save the | 1168 | * we should build one; otherwise, we should save the |
1169 | * advertisement for later use. | 1169 | * advertisement for later use. |
1170 | * | 1170 | * |
@@ -1210,7 +1210,7 @@ handle_dht_result (void *cls, | |||
1210 | { | 1210 | { |
1211 | exit = GNUNET_new (struct MeshExit); | 1211 | exit = GNUNET_new (struct MeshExit); |
1212 | exit->peer = ad->peer; | 1212 | exit->peer = ad->peer; |
1213 | /* tunnel is closed, so insert at the end */ | 1213 | /* channel is closed, so insert at the end */ |
1214 | GNUNET_CONTAINER_DLL_insert_tail (exit_head, | 1214 | GNUNET_CONTAINER_DLL_insert_tail (exit_head, |
1215 | exit_tail, | 1215 | exit_tail, |
1216 | exit); | 1216 | exit); |
@@ -1241,8 +1241,8 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
1241 | stats = GNUNET_STATISTICS_create ("pt", cfg); | 1241 | stats = GNUNET_STATISTICS_create ("pt", cfg); |
1242 | ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_IPV4"); | 1242 | ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_IPV4"); |
1243 | ipv6_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_IPV6"); | 1243 | ipv6_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_IPV6"); |
1244 | dns_tunnel = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_DNS"); | 1244 | dns_channel = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_DNS"); |
1245 | if (! (ipv4_pt || ipv6_pt || dns_tunnel)) | 1245 | if (! (ipv4_pt || ipv6_pt || dns_channel)) |
1246 | { | 1246 | { |
1247 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1247 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1248 | _("No useful service enabled. Exiting.\n")); | 1248 | _("No useful service enabled. Exiting.\n")); |
@@ -1274,7 +1274,7 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
1274 | return; | 1274 | return; |
1275 | } | 1275 | } |
1276 | } | 1276 | } |
1277 | if (dns_tunnel) | 1277 | if (dns_channel) |
1278 | { | 1278 | { |
1279 | static struct GNUNET_MESH_MessageHandler mesh_handlers[] = { | 1279 | static struct GNUNET_MESH_MessageHandler mesh_handlers[] = { |
1280 | {&receive_dns_response, GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET, 0}, | 1280 | {&receive_dns_response, GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET, 0}, |
@@ -1294,7 +1294,7 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
1294 | return; | 1294 | return; |
1295 | } | 1295 | } |
1296 | mesh_handle = GNUNET_MESH_connect (cfg, NULL, NULL, | 1296 | mesh_handle = GNUNET_MESH_connect (cfg, NULL, NULL, |
1297 | &mesh_tunnel_end_cb, | 1297 | &mesh_channel_end_cb, |
1298 | mesh_handlers, NULL); | 1298 | mesh_handlers, NULL); |
1299 | if (NULL == mesh_handle) | 1299 | if (NULL == mesh_handle) |
1300 | { | 1300 | { |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index 47e1697e3..b6c8e6077 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -203,9 +203,9 @@ struct ServiceSession | |||
203 | struct GNUNET_SERVER_TransmitHandle * client_transmit_handle; | 203 | struct GNUNET_SERVER_TransmitHandle * client_transmit_handle; |
204 | 204 | ||
205 | /** | 205 | /** |
206 | * tunnel-handle associated with our mesh handle | 206 | * channel-handle associated with our mesh handle |
207 | */ | 207 | */ |
208 | struct GNUNET_MESH_Tunnel * tunnel; | 208 | struct GNUNET_MESH_Channel * channel; |
209 | 209 | ||
210 | /** | 210 | /** |
211 | * Handle to a task that sends a msg to the our client | 211 | * Handle to a task that sends a msg to the our client |
@@ -783,10 +783,10 @@ handle_client_disconnect (void *cls, | |||
783 | 783 | ||
784 | if (!(session->role == BOB && session->state == FINALIZED)) { | 784 | if (!(session->role == BOB && session->state == FINALIZED)) { |
785 | //we MUST terminate any client message underway | 785 | //we MUST terminate any client message underway |
786 | if (session->service_transmit_handle && session->tunnel) | 786 | if (session->service_transmit_handle && session->channel) |
787 | GNUNET_MESH_notify_transmit_ready_cancel (session->service_transmit_handle); | 787 | GNUNET_MESH_notify_transmit_ready_cancel (session->service_transmit_handle); |
788 | if (session->tunnel && session->state == WAITING_FOR_SERVICE_RESPONSE) | 788 | if (session->channel && session->state == WAITING_FOR_SERVICE_RESPONSE) |
789 | GNUNET_MESH_tunnel_destroy (session->tunnel); | 789 | GNUNET_MESH_channel_destroy (session->channel); |
790 | } | 790 | } |
791 | if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) { | 791 | if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) { |
792 | GNUNET_SCHEDULER_cancel (session->client_notification_task); | 792 | GNUNET_SCHEDULER_cancel (session->client_notification_task); |
@@ -1014,7 +1014,7 @@ prepare_service_response_multipart (void *cls) | |||
1014 | session->transferred += todo_count; | 1014 | session->transferred += todo_count; |
1015 | session->msg = (struct GNUNET_MessageHeader *) msg; | 1015 | session->msg = (struct GNUNET_MessageHeader *) msg; |
1016 | session->service_transmit_handle = | 1016 | session->service_transmit_handle = |
1017 | GNUNET_MESH_notify_transmit_ready (session->tunnel, | 1017 | GNUNET_MESH_notify_transmit_ready (session->channel, |
1018 | GNUNET_YES, | 1018 | GNUNET_YES, |
1019 | GNUNET_TIME_UNIT_FOREVER_REL, | 1019 | GNUNET_TIME_UNIT_FOREVER_REL, |
1020 | msg_length, | 1020 | msg_length, |
@@ -1152,7 +1152,7 @@ prepare_service_response (gcry_mpi_t s, | |||
1152 | 1152 | ||
1153 | session->msg = (struct GNUNET_MessageHeader *) msg; | 1153 | session->msg = (struct GNUNET_MessageHeader *) msg; |
1154 | session->service_transmit_handle = | 1154 | session->service_transmit_handle = |
1155 | GNUNET_MESH_notify_transmit_ready (session->tunnel, | 1155 | GNUNET_MESH_notify_transmit_ready (session->channel, |
1156 | GNUNET_YES, | 1156 | GNUNET_YES, |
1157 | GNUNET_TIME_UNIT_FOREVER_REL, | 1157 | GNUNET_TIME_UNIT_FOREVER_REL, |
1158 | msg_length, | 1158 | msg_length, |
@@ -1476,13 +1476,13 @@ prepare_service_request_multipart (void *cls) | |||
1476 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); | 1476 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); |
1477 | 1477 | ||
1478 | //transmit via mesh messaging | 1478 | //transmit via mesh messaging |
1479 | session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->tunnel, GNUNET_YES, | 1479 | session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->channel, GNUNET_YES, |
1480 | GNUNET_TIME_UNIT_FOREVER_REL, | 1480 | GNUNET_TIME_UNIT_FOREVER_REL, |
1481 | msg_length, | 1481 | msg_length, |
1482 | &do_send_message, | 1482 | &do_send_message, |
1483 | session); | 1483 | session); |
1484 | if (!session->service_transmit_handle) { | 1484 | if (!session->service_transmit_handle) { |
1485 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-request multipart message to tunnel!\n")); | 1485 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-request multipart message to channel!\n")); |
1486 | GNUNET_free (msg); | 1486 | GNUNET_free (msg); |
1487 | session->msg = NULL; | 1487 | session->msg = NULL; |
1488 | session->client_notification_task = | 1488 | session->client_notification_task = |
@@ -1522,7 +1522,7 @@ prepare_service_request (void *cls, | |||
1522 | 1522 | ||
1523 | session->service_request_task = GNUNET_SCHEDULER_NO_TASK; | 1523 | session->service_request_task = GNUNET_SCHEDULER_NO_TASK; |
1524 | 1524 | ||
1525 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Successfully created new tunnel to peer (%s)!\n"), GNUNET_i2s (&session->peer)); | 1525 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Successfully created new channel to peer (%s)!\n"), GNUNET_i2s (&session->peer)); |
1526 | 1526 | ||
1527 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_service_request) | 1527 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_service_request) |
1528 | +session->mask_length | 1528 | +session->mask_length |
@@ -1603,13 +1603,13 @@ prepare_service_request (void *cls, | |||
1603 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); | 1603 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); |
1604 | 1604 | ||
1605 | //transmit via mesh messaging | 1605 | //transmit via mesh messaging |
1606 | session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->tunnel, GNUNET_YES, | 1606 | session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->channel, GNUNET_YES, |
1607 | GNUNET_TIME_UNIT_FOREVER_REL, | 1607 | GNUNET_TIME_UNIT_FOREVER_REL, |
1608 | msg_length, | 1608 | msg_length, |
1609 | &do_send_message, | 1609 | &do_send_message, |
1610 | session); | 1610 | session); |
1611 | if (!session->service_transmit_handle) { | 1611 | if (!session->service_transmit_handle) { |
1612 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to tunnel!\n")); | 1612 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to channel!\n")); |
1613 | GNUNET_free (msg); | 1613 | GNUNET_free (msg); |
1614 | session->msg = NULL; | 1614 | session->msg = NULL; |
1615 | session->client_notification_task = | 1615 | session->client_notification_task = |
@@ -1710,7 +1710,7 @@ handle_client_request (void *cls, | |||
1710 | 1710 | ||
1711 | if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) { | 1711 | if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) { |
1712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1713 | _ ("Got client-request-session with key %s, preparing tunnel to remote service.\n"), | 1713 | _ ("Got client-request-session with key %s, preparing channel to remote service.\n"), |
1714 | GNUNET_h2s (&session->key)); | 1714 | GNUNET_h2s (&session->key)); |
1715 | 1715 | ||
1716 | session->role = ALICE; | 1716 | session->role = ALICE; |
@@ -1746,15 +1746,15 @@ handle_client_request (void *cls, | |||
1746 | // get our peer ID | 1746 | // get our peer ID |
1747 | memcpy (&session->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); | 1747 | memcpy (&session->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); |
1748 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1748 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1749 | _ ("Creating new tunnel for session with key %s.\n"), | 1749 | _ ("Creating new channel for session with key %s.\n"), |
1750 | GNUNET_h2s (&session->key)); | 1750 | GNUNET_h2s (&session->key)); |
1751 | session->tunnel = GNUNET_MESH_tunnel_create (my_mesh, session, | 1751 | session->channel = GNUNET_MESH_channel_create (my_mesh, session, |
1752 | &session->peer, | 1752 | &session->peer, |
1753 | GNUNET_APPLICATION_TYPE_SCALARPRODUCT, | 1753 | GNUNET_APPLICATION_TYPE_SCALARPRODUCT, |
1754 | GNUNET_NO, | 1754 | GNUNET_NO, |
1755 | GNUNET_YES); | 1755 | GNUNET_YES); |
1756 | //prepare_service_request, tunnel_peer_disconnect_handler, | 1756 | //prepare_service_request, channel_peer_disconnect_handler, |
1757 | if (!session->tunnel) { | 1757 | if (!session->channel) { |
1758 | GNUNET_break (0); | 1758 | GNUNET_break (0); |
1759 | GNUNET_free (session->vector); | 1759 | GNUNET_free (session->vector); |
1760 | GNUNET_free (session); | 1760 | GNUNET_free (session); |
@@ -1809,26 +1809,26 @@ handle_client_request (void *cls, | |||
1809 | 1809 | ||
1810 | 1810 | ||
1811 | /** | 1811 | /** |
1812 | * Function called for inbound tunnels. | 1812 | * Function called for inbound channels. |
1813 | * | 1813 | * |
1814 | * @param cls closure | 1814 | * @param cls closure |
1815 | * @param tunnel new handle to the tunnel | 1815 | * @param channel new handle to the channel |
1816 | * @param initiator peer that started the tunnel | 1816 | * @param initiator peer that started the channel |
1817 | * @param port unused | 1817 | * @param port unused |
1818 | * @return session associated with the tunnel | 1818 | * @return session associated with the channel |
1819 | */ | 1819 | */ |
1820 | static void * | 1820 | static void * |
1821 | tunnel_incoming_handler (void *cls, | 1821 | channel_incoming_handler (void *cls, |
1822 | struct GNUNET_MESH_Tunnel *tunnel, | 1822 | struct GNUNET_MESH_Channel *channel, |
1823 | const struct GNUNET_PeerIdentity *initiator, | 1823 | const struct GNUNET_PeerIdentity *initiator, |
1824 | uint32_t port) | 1824 | uint32_t port) |
1825 | { | 1825 | { |
1826 | struct ServiceSession * c = GNUNET_new (struct ServiceSession); | 1826 | struct ServiceSession * c = GNUNET_new (struct ServiceSession); |
1827 | 1827 | ||
1828 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("New incoming tunnel from peer %s.\n"), GNUNET_i2s (initiator)); | 1828 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("New incoming channel from peer %s.\n"), GNUNET_i2s (initiator)); |
1829 | 1829 | ||
1830 | c->peer = *initiator; | 1830 | c->peer = *initiator; |
1831 | c->tunnel = tunnel; | 1831 | c->channel = channel; |
1832 | c->role = BOB; | 1832 | c->role = BOB; |
1833 | c->state = WAITING_FOR_SERVICE_REQUEST; | 1833 | c->state = WAITING_FOR_SERVICE_REQUEST; |
1834 | return c; | 1834 | return c; |
@@ -1836,22 +1836,22 @@ tunnel_incoming_handler (void *cls, | |||
1836 | 1836 | ||
1837 | 1837 | ||
1838 | /** | 1838 | /** |
1839 | * Function called whenever a tunnel is destroyed. Should clean up | 1839 | * Function called whenever a channel is destroyed. Should clean up |
1840 | * any associated state. | 1840 | * any associated state. |
1841 | * | 1841 | * |
1842 | * It must NOT call GNUNET_MESH_tunnel_destroy on the tunnel. | 1842 | * It must NOT call GNUNET_MESH_channel_destroy on the channel. |
1843 | * | 1843 | * |
1844 | * @param cls closure (set from GNUNET_MESH_connect) | 1844 | * @param cls closure (set from GNUNET_MESH_connect) |
1845 | * @param tunnel connection to the other end (henceforth invalid) | 1845 | * @param channel connection to the other end (henceforth invalid) |
1846 | * @param tunnel_ctx place where local state associated | 1846 | * @param channel_ctx place where local state associated |
1847 | * with the tunnel is stored | 1847 | * with the channel is stored |
1848 | */ | 1848 | */ |
1849 | static void | 1849 | static void |
1850 | tunnel_destruction_handler (void *cls, | 1850 | channel_destruction_handler (void *cls, |
1851 | const struct GNUNET_MESH_Tunnel *tunnel, | 1851 | const struct GNUNET_MESH_Channel *channel, |
1852 | void *tunnel_ctx) | 1852 | void *channel_ctx) |
1853 | { | 1853 | { |
1854 | struct ServiceSession * session = tunnel_ctx; | 1854 | struct ServiceSession * session = channel_ctx; |
1855 | struct ServiceSession * client_session; | 1855 | struct ServiceSession * client_session; |
1856 | struct ServiceSession * curr; | 1856 | struct ServiceSession * curr; |
1857 | 1857 | ||
@@ -1863,7 +1863,7 @@ tunnel_destruction_handler (void *cls, | |||
1863 | // as we have only one peer connected in each session, just remove the session | 1863 | // as we have only one peer connected in each session, just remove the session |
1864 | 1864 | ||
1865 | if ((SERVICE_RESPONSE_RECEIVED > session->state) && (!do_shutdown)) { | 1865 | if ((SERVICE_RESPONSE_RECEIVED > session->state) && (!do_shutdown)) { |
1866 | session->tunnel = NULL; | 1866 | session->channel = NULL; |
1867 | // if this happened before we received the answer, we must terminate the session | 1867 | // if this happened before we received the answer, we must terminate the session |
1868 | session->client_notification_task = | 1868 | session->client_notification_task = |
1869 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1869 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
@@ -1985,16 +1985,16 @@ compute_scalar_product (struct ServiceSession * session) | |||
1985 | * Handle a multipart-chunk of a request from another service to calculate a scalarproduct with us. | 1985 | * Handle a multipart-chunk of a request from another service to calculate a scalarproduct with us. |
1986 | * | 1986 | * |
1987 | * @param cls closure (set from #GNUNET_MESH_connect) | 1987 | * @param cls closure (set from #GNUNET_MESH_connect) |
1988 | * @param tunnel connection to the other end | 1988 | * @param channel connection to the other end |
1989 | * @param tunnel_ctx place to store local state associated with the tunnel | 1989 | * @param channel_ctx place to store local state associated with the channel |
1990 | * @param message the actual message | 1990 | * @param message the actual message |
1991 | * @return #GNUNET_OK to keep the connection open, | 1991 | * @return #GNUNET_OK to keep the connection open, |
1992 | * #GNUNET_SYSERR to close it (signal serious error) | 1992 | * #GNUNET_SYSERR to close it (signal serious error) |
1993 | */ | 1993 | */ |
1994 | static int | 1994 | static int |
1995 | handle_service_request_multipart (void *cls, | 1995 | handle_service_request_multipart (void *cls, |
1996 | struct GNUNET_MESH_Tunnel * tunnel, | 1996 | struct GNUNET_MESH_Channel * channel, |
1997 | void **tunnel_ctx, | 1997 | void **channel_ctx, |
1998 | const struct GNUNET_MessageHeader * message) | 1998 | const struct GNUNET_MessageHeader * message) |
1999 | { | 1999 | { |
2000 | struct ServiceSession * session; | 2000 | struct ServiceSession * session; |
@@ -2007,7 +2007,7 @@ handle_service_request_multipart (void *cls, | |||
2007 | int32_t i = -1; | 2007 | int32_t i = -1; |
2008 | 2008 | ||
2009 | // are we in the correct state? | 2009 | // are we in the correct state? |
2010 | session = (struct ServiceSession *) * tunnel_ctx; | 2010 | session = (struct ServiceSession *) * channel_ctx; |
2011 | if ((BOB != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) { | 2011 | if ((BOB != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) { |
2012 | goto except; | 2012 | goto except; |
2013 | } | 2013 | } |
@@ -2077,16 +2077,16 @@ except: | |||
2077 | * Handle a request from another service to calculate a scalarproduct with us. | 2077 | * Handle a request from another service to calculate a scalarproduct with us. |
2078 | * | 2078 | * |
2079 | * @param cls closure (set from #GNUNET_MESH_connect) | 2079 | * @param cls closure (set from #GNUNET_MESH_connect) |
2080 | * @param tunnel connection to the other end | 2080 | * @param channel connection to the other end |
2081 | * @param tunnel_ctx place to store local state associated with the tunnel | 2081 | * @param channel_ctx place to store local state associated with the channel |
2082 | * @param message the actual message | 2082 | * @param message the actual message |
2083 | * @return #GNUNET_OK to keep the connection open, | 2083 | * @return #GNUNET_OK to keep the connection open, |
2084 | * #GNUNET_SYSERR to close it (signal serious error) | 2084 | * #GNUNET_SYSERR to close it (signal serious error) |
2085 | */ | 2085 | */ |
2086 | static int | 2086 | static int |
2087 | handle_service_request (void *cls, | 2087 | handle_service_request (void *cls, |
2088 | struct GNUNET_MESH_Tunnel * tunnel, | 2088 | struct GNUNET_MESH_Channel * channel, |
2089 | void **tunnel_ctx, | 2089 | void **channel_ctx, |
2090 | const struct GNUNET_MessageHeader * message) | 2090 | const struct GNUNET_MessageHeader * message) |
2091 | { | 2091 | { |
2092 | struct ServiceSession * session; | 2092 | struct ServiceSession * session; |
@@ -2102,7 +2102,7 @@ handle_service_request (void *cls, | |||
2102 | int32_t i = -1; | 2102 | int32_t i = -1; |
2103 | enum SessionState needed_state; | 2103 | enum SessionState needed_state; |
2104 | 2104 | ||
2105 | session = (struct ServiceSession *) * tunnel_ctx; | 2105 | session = (struct ServiceSession *) * channel_ctx; |
2106 | if (WAITING_FOR_SERVICE_REQUEST != session->state) { | 2106 | if (WAITING_FOR_SERVICE_REQUEST != session->state) { |
2107 | goto invalid_msg; | 2107 | goto invalid_msg; |
2108 | } | 2108 | } |
@@ -2147,7 +2147,7 @@ handle_service_request (void *cls, | |||
2147 | session->total = element_count; | 2147 | session->total = element_count; |
2148 | session->used = used_elements; | 2148 | session->used = used_elements; |
2149 | session->transferred = contained_elements; | 2149 | session->transferred = contained_elements; |
2150 | session->tunnel = tunnel; | 2150 | session->channel = channel; |
2151 | 2151 | ||
2152 | // session key | 2152 | // session key |
2153 | memcpy (&session->key, &msg->key, sizeof (struct GNUNET_HashCode)); | 2153 | memcpy (&session->key, &msg->key, sizeof (struct GNUNET_HashCode)); |
@@ -2226,16 +2226,16 @@ invalid_msg: | |||
2226 | * Handle a multipart chunk of a response we got from another service we wanted to calculate a scalarproduct with. | 2226 | * Handle a multipart chunk of a response we got from another service we wanted to calculate a scalarproduct with. |
2227 | * | 2227 | * |
2228 | * @param cls closure (set from #GNUNET_MESH_connect) | 2228 | * @param cls closure (set from #GNUNET_MESH_connect) |
2229 | * @param tunnel connection to the other end | 2229 | * @param channel connection to the other end |
2230 | * @param tunnel_ctx place to store local state associated with the tunnel | 2230 | * @param channel_ctx place to store local state associated with the channel |
2231 | * @param message the actual message | 2231 | * @param message the actual message |
2232 | * @return #GNUNET_OK to keep the connection open, | 2232 | * @return #GNUNET_OK to keep the connection open, |
2233 | * #GNUNET_SYSERR to close it (signal serious error) | 2233 | * #GNUNET_SYSERR to close it (signal serious error) |
2234 | */ | 2234 | */ |
2235 | static int | 2235 | static int |
2236 | handle_service_response_multipart (void *cls, | 2236 | handle_service_response_multipart (void *cls, |
2237 | struct GNUNET_MESH_Tunnel * tunnel, | 2237 | struct GNUNET_MESH_Channel * channel, |
2238 | void **tunnel_ctx, | 2238 | void **channel_ctx, |
2239 | const struct GNUNET_MessageHeader * message) | 2239 | const struct GNUNET_MessageHeader * message) |
2240 | { | 2240 | { |
2241 | struct ServiceSession * session; | 2241 | struct ServiceSession * session; |
@@ -2250,7 +2250,7 @@ handle_service_response_multipart (void *cls, | |||
2250 | 2250 | ||
2251 | GNUNET_assert (NULL != message); | 2251 | GNUNET_assert (NULL != message); |
2252 | // are we in the correct state? | 2252 | // are we in the correct state? |
2253 | session = (struct ServiceSession *) * tunnel_ctx; | 2253 | session = (struct ServiceSession *) * channel_ctx; |
2254 | if ((ALICE != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) { | 2254 | if ((ALICE != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) { |
2255 | goto invalid_msg; | 2255 | goto invalid_msg; |
2256 | } | 2256 | } |
@@ -2295,13 +2295,13 @@ invalid_msg: | |||
2295 | // send message with product to client | 2295 | // send message with product to client |
2296 | if (ALICE == session->role){ | 2296 | if (ALICE == session->role){ |
2297 | session->state = FINALIZED; | 2297 | session->state = FINALIZED; |
2298 | session->tunnel = NULL; | 2298 | session->channel = NULL; |
2299 | session->client_notification_task = | 2299 | session->client_notification_task = |
2300 | GNUNET_SCHEDULER_add_now (&prepare_client_response, | 2300 | GNUNET_SCHEDULER_add_now (&prepare_client_response, |
2301 | session); | 2301 | session); |
2302 | } | 2302 | } |
2303 | // the tunnel has done its job, terminate our connection and the tunnel | 2303 | // the channel has done its job, terminate our connection and the channel |
2304 | // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler | 2304 | // the peer will be notified that the channel was destroyed via channel_destruction_handler |
2305 | // just close the connection, as recommended by Christian | 2305 | // just close the connection, as recommended by Christian |
2306 | return GNUNET_SYSERR; | 2306 | return GNUNET_SYSERR; |
2307 | } | 2307 | } |
@@ -2311,16 +2311,16 @@ invalid_msg: | |||
2311 | * Handle a response we got from another service we wanted to calculate a scalarproduct with. | 2311 | * Handle a response we got from another service we wanted to calculate a scalarproduct with. |
2312 | * | 2312 | * |
2313 | * @param cls closure (set from #GNUNET_MESH_connect) | 2313 | * @param cls closure (set from #GNUNET_MESH_connect) |
2314 | * @param tunnel connection to the other end | 2314 | * @param channel connection to the other end |
2315 | * @param tunnel_ctx place to store local state associated with the tunnel | 2315 | * @param channel_ctx place to store local state associated with the channel |
2316 | * @param message the actual message | 2316 | * @param message the actual message |
2317 | * @return #GNUNET_OK to keep the connection open, | 2317 | * @return #GNUNET_OK to keep the connection open, |
2318 | * #GNUNET_SYSERR to close it (we are done) | 2318 | * #GNUNET_SYSERR to close it (we are done) |
2319 | */ | 2319 | */ |
2320 | static int | 2320 | static int |
2321 | handle_service_response (void *cls, | 2321 | handle_service_response (void *cls, |
2322 | struct GNUNET_MESH_Tunnel * tunnel, | 2322 | struct GNUNET_MESH_Channel * channel, |
2323 | void **tunnel_ctx, | 2323 | void **channel_ctx, |
2324 | const struct GNUNET_MessageHeader * message) | 2324 | const struct GNUNET_MessageHeader * message) |
2325 | { | 2325 | { |
2326 | struct ServiceSession * session; | 2326 | struct ServiceSession * session; |
@@ -2334,7 +2334,7 @@ handle_service_response (void *cls, | |||
2334 | int rc; | 2334 | int rc; |
2335 | 2335 | ||
2336 | GNUNET_assert (NULL != message); | 2336 | GNUNET_assert (NULL != message); |
2337 | session = (struct ServiceSession *) * tunnel_ctx; | 2337 | session = (struct ServiceSession *) * channel_ctx; |
2338 | // are we in the correct state? | 2338 | // are we in the correct state? |
2339 | if (WAITING_FOR_SERVICE_RESPONSE != session->state) { | 2339 | if (WAITING_FOR_SERVICE_RESPONSE != session->state) { |
2340 | goto invalid_msg; | 2340 | goto invalid_msg; |
@@ -2399,13 +2399,13 @@ invalid_msg: | |||
2399 | // send message with product to client | 2399 | // send message with product to client |
2400 | if (ALICE == session->role){ | 2400 | if (ALICE == session->role){ |
2401 | session->state = FINALIZED; | 2401 | session->state = FINALIZED; |
2402 | session->tunnel = NULL; | 2402 | session->channel = NULL; |
2403 | session->client_notification_task = | 2403 | session->client_notification_task = |
2404 | GNUNET_SCHEDULER_add_now (&prepare_client_response, | 2404 | GNUNET_SCHEDULER_add_now (&prepare_client_response, |
2405 | session); | 2405 | session); |
2406 | } | 2406 | } |
2407 | // the tunnel has done its job, terminate our connection and the tunnel | 2407 | // the channel has done its job, terminate our connection and the channel |
2408 | // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler | 2408 | // the peer will be notified that the channel was destroyed via channel_destruction_handler |
2409 | // just close the connection, as recommended by Christian | 2409 | // just close the connection, as recommended by Christian |
2410 | return GNUNET_SYSERR; | 2410 | return GNUNET_SYSERR; |
2411 | } | 2411 | } |
@@ -2426,11 +2426,11 @@ shutdown_task (void *cls, | |||
2426 | 2426 | ||
2427 | do_shutdown = GNUNET_YES; | 2427 | do_shutdown = GNUNET_YES; |
2428 | 2428 | ||
2429 | // terminate all owned open tunnels. | 2429 | // terminate all owned open channels. |
2430 | for (session = from_client_head; NULL != session; session = session->next) { | 2430 | for (session = from_client_head; NULL != session; session = session->next) { |
2431 | if ((FINALIZED != session->state) && (NULL != session->tunnel)) { | 2431 | if ((FINALIZED != session->state) && (NULL != session->channel)) { |
2432 | GNUNET_MESH_tunnel_destroy (session->tunnel); | 2432 | GNUNET_MESH_channel_destroy (session->channel); |
2433 | session->tunnel = NULL; | 2433 | session->channel = NULL; |
2434 | } | 2434 | } |
2435 | if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) { | 2435 | if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) { |
2436 | GNUNET_SCHEDULER_cancel (session->client_notification_task); | 2436 | GNUNET_SCHEDULER_cancel (session->client_notification_task); |
@@ -2446,9 +2446,9 @@ shutdown_task (void *cls, | |||
2446 | } | 2446 | } |
2447 | } | 2447 | } |
2448 | for (session = from_service_head; NULL != session; session = session->next) | 2448 | for (session = from_service_head; NULL != session; session = session->next) |
2449 | if (NULL != session->tunnel) { | 2449 | if (NULL != session->channel) { |
2450 | GNUNET_MESH_tunnel_destroy (session->tunnel); | 2450 | GNUNET_MESH_channel_destroy (session->channel); |
2451 | session->tunnel = NULL; | 2451 | session->channel = NULL; |
2452 | } | 2452 | } |
2453 | 2453 | ||
2454 | if (my_mesh) { | 2454 | if (my_mesh) { |
@@ -2498,8 +2498,8 @@ run (void *cls, | |||
2498 | GNUNET_CRYPTO_get_peer_identity (c, | 2498 | GNUNET_CRYPTO_get_peer_identity (c, |
2499 | &me)); | 2499 | &me)); |
2500 | my_mesh = GNUNET_MESH_connect (c, NULL, | 2500 | my_mesh = GNUNET_MESH_connect (c, NULL, |
2501 | &tunnel_incoming_handler, | 2501 | &channel_incoming_handler, |
2502 | &tunnel_destruction_handler, | 2502 | &channel_destruction_handler, |
2503 | mesh_handlers, ports); | 2503 | mesh_handlers, ports); |
2504 | if (!my_mesh) { | 2504 | if (!my_mesh) { |
2505 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to MESH failed\n")); | 2505 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to MESH failed\n")); |
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 1a2b0cc31..d4c347d48 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c | |||
@@ -316,16 +316,16 @@ _GSS_operation_destroy (struct Operation *op) | |||
316 | op->mq = NULL; | 316 | op->mq = NULL; |
317 | } | 317 | } |
318 | 318 | ||
319 | if (NULL != op->tunnel) | 319 | if (NULL != op->channel) |
320 | { | 320 | { |
321 | GNUNET_MESH_tunnel_destroy (op->tunnel); | 321 | GNUNET_MESH_channel_destroy (op->channel); |
322 | op->tunnel = NULL; | 322 | op->channel = NULL; |
323 | } | 323 | } |
324 | 324 | ||
325 | collect_generation_garbage (set); | 325 | collect_generation_garbage (set); |
326 | 326 | ||
327 | /* We rely on the tunnel end handler to free 'op'. When 'op->tunnel' was NULL, | 327 | /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL, |
328 | * there was a tunnel end handler that will free 'op' on the call stack. */ | 328 | * there was a channel end handler that will free 'op' on the call stack. */ |
329 | } | 329 | } |
330 | 330 | ||
331 | 331 | ||
@@ -362,7 +362,7 @@ set_destroy (struct Set *set) | |||
362 | { | 362 | { |
363 | /* If the client is not dead yet, destroy it. | 363 | /* If the client is not dead yet, destroy it. |
364 | * The client's destroy callback will destroy the set again. | 364 | * The client's destroy callback will destroy the set again. |
365 | * We do this so that the tunnel end handler still has a valid set handle | 365 | * We do this so that the channel end handler still has a valid set handle |
366 | * to destroy. */ | 366 | * to destroy. */ |
367 | if (NULL != set->client) | 367 | if (NULL != set->client) |
368 | { | 368 | { |
@@ -532,8 +532,8 @@ incoming_suggest (struct Operation *incoming, struct Listener *listener) | |||
532 | * | 532 | * |
533 | * @param op the operation state | 533 | * @param op the operation state |
534 | * @param mh the received message | 534 | * @param mh the received message |
535 | * @return GNUNET_OK if the tunnel should be kept alive, | 535 | * @return GNUNET_OK if the channel should be kept alive, |
536 | * GNUNET_SYSERR to destroy the tunnel | 536 | * GNUNET_SYSERR to destroy the channel |
537 | */ | 537 | */ |
538 | static int | 538 | static int |
539 | handle_incoming_msg (struct Operation *op, | 539 | handle_incoming_msg (struct Operation *op, |
@@ -805,8 +805,8 @@ handle_client_reject (void *cls, | |||
805 | } | 805 | } |
806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer request rejected by client\n"); | 806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer request rejected by client\n"); |
807 | 807 | ||
808 | GNUNET_MESH_tunnel_destroy (incoming->tunnel); | 808 | GNUNET_MESH_channel_destroy (incoming->channel); |
809 | //tunnel destruction handler called immediately upon destruction | 809 | //channel destruction handler called immediately upon destruction |
810 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 810 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
811 | } | 811 | } |
812 | 812 | ||
@@ -935,12 +935,12 @@ handle_client_evaluate (void *cls, | |||
935 | op->vt = set->vt; | 935 | op->vt = set->vt; |
936 | GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); | 936 | GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); |
937 | 937 | ||
938 | op->tunnel = GNUNET_MESH_tunnel_create (mesh, op, &msg->target_peer, | 938 | op->channel = GNUNET_MESH_channel_create (mesh, op, &msg->target_peer, |
939 | GNUNET_APPLICATION_TYPE_SET, | 939 | GNUNET_APPLICATION_TYPE_SET, |
940 | GNUNET_YES, | 940 | GNUNET_YES, |
941 | GNUNET_YES); | 941 | GNUNET_YES); |
942 | 942 | ||
943 | op->mq = GNUNET_MESH_mq_create (op->tunnel); | 943 | op->mq = GNUNET_MESH_mq_create (op->channel); |
944 | 944 | ||
945 | set->vt->evaluate (op); | 945 | set->vt->evaluate (op); |
946 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 946 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -1111,7 +1111,7 @@ shutdown_task (void *cls, | |||
1111 | while (NULL != sets_head) | 1111 | while (NULL != sets_head) |
1112 | set_destroy (sets_head); | 1112 | set_destroy (sets_head); |
1113 | 1113 | ||
1114 | /* it's important to destroy mesh at the end, as all tunnels | 1114 | /* it's important to destroy mesh at the end, as all channels |
1115 | * must be destroyed before the mesh handle! */ | 1115 | * must be destroyed before the mesh handle! */ |
1116 | if (NULL != mesh) | 1116 | if (NULL != mesh) |
1117 | { | 1117 | { |
@@ -1127,9 +1127,9 @@ shutdown_task (void *cls, | |||
1127 | * Timeout happens iff: | 1127 | * Timeout happens iff: |
1128 | * - we suggested an operation to our listener, | 1128 | * - we suggested an operation to our listener, |
1129 | * but did not receive a response in time | 1129 | * but did not receive a response in time |
1130 | * - we got the tunnel from a peer but no GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST | 1130 | * - we got the channel from a peer but no GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST |
1131 | * - shutdown (obviously) | 1131 | * - shutdown (obviously) |
1132 | * @param cls tunnel context | 1132 | * @param cls channel context |
1133 | * @param tc context information (why was this task triggered now) | 1133 | * @param tc context information (why was this task triggered now) |
1134 | */ | 1134 | */ |
1135 | static void | 1135 | static void |
@@ -1150,16 +1150,16 @@ incoming_timeout_cb (void *cls, | |||
1150 | 1150 | ||
1151 | /** | 1151 | /** |
1152 | * Terminates an incoming operation in case we have not yet received an | 1152 | * Terminates an incoming operation in case we have not yet received an |
1153 | * operation request. Called by the tunnel destruction handler. | 1153 | * operation request. Called by the channel destruction handler. |
1154 | * | 1154 | * |
1155 | * @param op the tunnel context | 1155 | * @param op the channel context |
1156 | */ | 1156 | */ |
1157 | static void | 1157 | static void |
1158 | handle_incoming_disconnect (struct Operation *op) | 1158 | handle_incoming_disconnect (struct Operation *op) |
1159 | { | 1159 | { |
1160 | GNUNET_assert (GNUNET_YES == op->is_incoming); | 1160 | GNUNET_assert (GNUNET_YES == op->is_incoming); |
1161 | 1161 | ||
1162 | if (NULL == op->tunnel) | 1162 | if (NULL == op->channel) |
1163 | return; | 1163 | return; |
1164 | 1164 | ||
1165 | incoming_destroy (op); | 1165 | incoming_destroy (op); |
@@ -1167,25 +1167,25 @@ handle_incoming_disconnect (struct Operation *op) | |||
1167 | 1167 | ||
1168 | 1168 | ||
1169 | /** | 1169 | /** |
1170 | * Method called whenever another peer has added us to a tunnel | 1170 | * Method called whenever another peer has added us to a channel |
1171 | * the other peer initiated. | 1171 | * the other peer initiated. |
1172 | * Only called (once) upon reception of data with a message type which was | 1172 | * Only called (once) upon reception of data with a message type which was |
1173 | * subscribed to in GNUNET_MESH_connect. | 1173 | * subscribed to in GNUNET_MESH_connect. |
1174 | * | 1174 | * |
1175 | * The tunnel context represents the operation itself and gets added to a DLL, | 1175 | * The channel context represents the operation itself and gets added to a DLL, |
1176 | * from where it gets looked up when our local listener client responds | 1176 | * from where it gets looked up when our local listener client responds |
1177 | * to a proposed/suggested operation or connects and associates with this operation. | 1177 | * to a proposed/suggested operation or connects and associates with this operation. |
1178 | * | 1178 | * |
1179 | * @param cls closure | 1179 | * @param cls closure |
1180 | * @param tunnel new handle to the tunnel | 1180 | * @param channel new handle to the channel |
1181 | * @param initiator peer that started the tunnel | 1181 | * @param initiator peer that started the channel |
1182 | * @param port Port this tunnel is for. | 1182 | * @param port Port this channel is for. |
1183 | * @return initial tunnel context for the tunnel | 1183 | * @return initial channel context for the channel |
1184 | * (can be NULL -- that's not an error) | 1184 | * (can be NULL -- that's not an error) |
1185 | */ | 1185 | */ |
1186 | static void * | 1186 | static void * |
1187 | tunnel_new_cb (void *cls, | 1187 | channel_new_cb (void *cls, |
1188 | struct GNUNET_MESH_Tunnel *tunnel, | 1188 | struct GNUNET_MESH_Channel *channel, |
1189 | const struct GNUNET_PeerIdentity *initiator, | 1189 | const struct GNUNET_PeerIdentity *initiator, |
1190 | uint32_t port) | 1190 | uint32_t port) |
1191 | { | 1191 | { |
@@ -1195,15 +1195,15 @@ tunnel_new_cb (void *cls, | |||
1195 | .peer_disconnect = handle_incoming_disconnect | 1195 | .peer_disconnect = handle_incoming_disconnect |
1196 | }; | 1196 | }; |
1197 | 1197 | ||
1198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new incoming tunnel\n"); | 1198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new incoming channel\n"); |
1199 | 1199 | ||
1200 | GNUNET_assert (port == GNUNET_APPLICATION_TYPE_SET); | 1200 | GNUNET_assert (port == GNUNET_APPLICATION_TYPE_SET); |
1201 | incoming = GNUNET_new (struct Operation); | 1201 | incoming = GNUNET_new (struct Operation); |
1202 | incoming->is_incoming = GNUNET_YES; | 1202 | incoming->is_incoming = GNUNET_YES; |
1203 | incoming->state = GNUNET_new (struct OperationState); | 1203 | incoming->state = GNUNET_new (struct OperationState); |
1204 | incoming->state->peer = *initiator; | 1204 | incoming->state->peer = *initiator; |
1205 | incoming->tunnel = tunnel; | 1205 | incoming->channel = channel; |
1206 | incoming->mq = GNUNET_MESH_mq_create (incoming->tunnel); | 1206 | incoming->mq = GNUNET_MESH_mq_create (incoming->channel); |
1207 | incoming->vt = &incoming_vt; | 1207 | incoming->vt = &incoming_vt; |
1208 | incoming->state->timeout_task = | 1208 | incoming->state->timeout_task = |
1209 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, incoming_timeout_cb, incoming); | 1209 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, incoming_timeout_cb, incoming); |
@@ -1214,72 +1214,72 @@ tunnel_new_cb (void *cls, | |||
1214 | 1214 | ||
1215 | 1215 | ||
1216 | /** | 1216 | /** |
1217 | * Function called whenever a tunnel is destroyed. Should clean up | 1217 | * Function called whenever a channel is destroyed. Should clean up |
1218 | * any associated state. | 1218 | * any associated state. |
1219 | * GNUNET_MESH_tunnel_destroy. It must NOT call GNUNET_MESH_tunnel_destroy on | 1219 | * GNUNET_MESH_channel_destroy. It must NOT call GNUNET_MESH_channel_destroy on |
1220 | * the tunnel. | 1220 | * the channel. |
1221 | * | 1221 | * |
1222 | * The peer_disconnect function is part of a a virtual table set initially either | 1222 | * The peer_disconnect function is part of a a virtual table set initially either |
1223 | * when a peer creates a new tunnel with us (tunnel_new_cb), or once we create | 1223 | * when a peer creates a new channel with us (channel_new_cb), or once we create |
1224 | * a new tunnel ourselves (evaluate). | 1224 | * a new channel ourselves (evaluate). |
1225 | * | 1225 | * |
1226 | * Once we know the exact type of operation (union/intersection), the vt is | 1226 | * Once we know the exact type of operation (union/intersection), the vt is |
1227 | * replaced with an operation specific instance (_GSS_[op]_vt). | 1227 | * replaced with an operation specific instance (_GSS_[op]_vt). |
1228 | * | 1228 | * |
1229 | * @param cls closure (set from GNUNET_MESH_connect) | 1229 | * @param cls closure (set from GNUNET_MESH_connect) |
1230 | * @param tunnel connection to the other end (henceforth invalid) | 1230 | * @param channel connection to the other end (henceforth invalid) |
1231 | * @param tunnel_ctx place where local state associated | 1231 | * @param channel_ctx place where local state associated |
1232 | * with the tunnel is stored | 1232 | * with the channel is stored |
1233 | */ | 1233 | */ |
1234 | static void | 1234 | static void |
1235 | tunnel_end_cb (void *cls, | 1235 | channel_end_cb (void *cls, |
1236 | const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx) | 1236 | const struct GNUNET_MESH_Channel *channel, void *channel_ctx) |
1237 | { | 1237 | { |
1238 | struct Operation *op = tunnel_ctx; | 1238 | struct Operation *op = channel_ctx; |
1239 | 1239 | ||
1240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel end cb called\n"); | 1240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel end cb called\n"); |
1241 | 1241 | ||
1242 | op->tunnel = NULL; | 1242 | op->channel = NULL; |
1243 | 1243 | ||
1244 | if (NULL != op->vt) | 1244 | if (NULL != op->vt) |
1245 | op->vt->peer_disconnect (op); | 1245 | op->vt->peer_disconnect (op); |
1246 | /* mesh will never call us with the context again! */ | 1246 | /* mesh will never call us with the context again! */ |
1247 | GNUNET_free (tunnel_ctx); | 1247 | GNUNET_free (channel_ctx); |
1248 | } | 1248 | } |
1249 | 1249 | ||
1250 | 1250 | ||
1251 | /** | 1251 | /** |
1252 | * Functions with this signature are called whenever any message is | 1252 | * Functions with this signature are called whenever any message is |
1253 | * received via the mesh tunnel. | 1253 | * received via the mesh channel. |
1254 | * | 1254 | * |
1255 | * The msg_handler is a virtual table set in initially either when a peer | 1255 | * The msg_handler is a virtual table set in initially either when a peer |
1256 | * creates a new tunnel with us (tunnel_new_cb), or once we create a new tunnel | 1256 | * creates a new channel with us (channel_new_cb), or once we create a new channel |
1257 | * ourselves (evaluate). | 1257 | * ourselves (evaluate). |
1258 | * | 1258 | * |
1259 | * Once we know the exact type of operation (union/intersection), the vt is | 1259 | * Once we know the exact type of operation (union/intersection), the vt is |
1260 | * replaced with an operation specific instance (_GSS_[op]_vt). | 1260 | * replaced with an operation specific instance (_GSS_[op]_vt). |
1261 | * | 1261 | * |
1262 | * @param cls Closure (set from GNUNET_MESH_connect). | 1262 | * @param cls Closure (set from GNUNET_MESH_connect). |
1263 | * @param tunnel Connection to the other end. | 1263 | * @param channel Connection to the other end. |
1264 | * @param tunnel_ctx Place to store local state associated with the tunnel. | 1264 | * @param channel_ctx Place to store local state associated with the channel. |
1265 | * @param message The actual message. | 1265 | * @param message The actual message. |
1266 | * | 1266 | * |
1267 | * @return GNUNET_OK to keep the tunnel open, | 1267 | * @return GNUNET_OK to keep the channel open, |
1268 | * GNUNET_SYSERR to close it (signal serious error). | 1268 | * GNUNET_SYSERR to close it (signal serious error). |
1269 | */ | 1269 | */ |
1270 | static int | 1270 | static int |
1271 | dispatch_p2p_message (void *cls, | 1271 | dispatch_p2p_message (void *cls, |
1272 | struct GNUNET_MESH_Tunnel *tunnel, | 1272 | struct GNUNET_MESH_Channel *channel, |
1273 | void **tunnel_ctx, | 1273 | void **channel_ctx, |
1274 | const struct GNUNET_MessageHeader *message) | 1274 | const struct GNUNET_MessageHeader *message) |
1275 | { | 1275 | { |
1276 | struct Operation *op = *tunnel_ctx; | 1276 | struct Operation *op = *channel_ctx; |
1277 | int ret; | 1277 | int ret; |
1278 | 1278 | ||
1279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "dispatching mesh message (type: %u)\n", | 1279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "dispatching mesh message (type: %u)\n", |
1280 | ntohs (message->type)); | 1280 | ntohs (message->type)); |
1281 | /* do this before the handler, as the handler might kill the tunnel */ | 1281 | /* do this before the handler, as the handler might kill the channel */ |
1282 | GNUNET_MESH_receive_done (tunnel); | 1282 | GNUNET_MESH_receive_done (channel); |
1283 | ret = op->vt->msg_handler (op, message); | 1283 | ret = op->vt->msg_handler (op, message); |
1284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled mesh message (type: %u)\n", | 1284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled mesh message (type: %u)\n", |
1285 | ntohs (message->type)); | 1285 | ntohs (message->type)); |
@@ -1336,7 +1336,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1336 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 1336 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
1337 | GNUNET_SERVER_add_handlers (server, server_handlers); | 1337 | GNUNET_SERVER_add_handlers (server, server_handlers); |
1338 | 1338 | ||
1339 | mesh = GNUNET_MESH_connect (cfg, NULL, tunnel_new_cb, tunnel_end_cb, | 1339 | mesh = GNUNET_MESH_connect (cfg, NULL, channel_new_cb, channel_end_cb, |
1340 | mesh_handlers, mesh_ports); | 1340 | mesh_handlers, mesh_ports); |
1341 | if (NULL == mesh) | 1341 | if (NULL == mesh) |
1342 | { | 1342 | { |
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h index dd6e91da8..62e8cbc87 100644 --- a/src/set/gnunet-service-set.h +++ b/src/set/gnunet-service-set.h | |||
@@ -296,7 +296,7 @@ struct Operation | |||
296 | /** | 296 | /** |
297 | * Tunnel to the peer. | 297 | * Tunnel to the peer. |
298 | */ | 298 | */ |
299 | struct GNUNET_MESH_Tunnel *tunnel; | 299 | struct GNUNET_MESH_Channel *channel; |
300 | 300 | ||
301 | /** | 301 | /** |
302 | * Message queue for the tunnel. | 302 | * Message queue for the tunnel. |
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index edb70f5e0..eebdcac55 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -27,8 +27,8 @@ | |||
27 | * @author Christian Grothoff | 27 | * @author Christian Grothoff |
28 | * | 28 | * |
29 | * TODO: | 29 | * TODO: |
30 | * - keep multiple peers/mesh tunnels ready as alternative exits / | 30 | * - keep multiple peers/mesh channels ready as alternative exits / |
31 | * detect & recover from tunnel-to-exit failure gracefully | 31 | * detect & recover from channel-to-exit failure gracefully |
32 | */ | 32 | */ |
33 | #include "platform.h" | 33 | #include "platform.h" |
34 | #include "gnunet_util_lib.h" | 34 | #include "gnunet_util_lib.h" |
@@ -51,45 +51,45 @@ | |||
51 | 51 | ||
52 | 52 | ||
53 | /** | 53 | /** |
54 | * State we keep for each of our tunnels. | 54 | * State we keep for each of our channels. |
55 | */ | 55 | */ |
56 | struct TunnelState; | 56 | struct ChannelState; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Information we track for each IP address to determine which tunnel | 59 | * Information we track for each IP address to determine which channel |
60 | * to send the traffic over to the destination. | 60 | * to send the traffic over to the destination. |
61 | */ | 61 | */ |
62 | struct DestinationEntry; | 62 | struct DestinationEntry; |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * List of tunnels we keep for each destination port for a given | 65 | * List of channels we keep for each destination port for a given |
66 | * destination entry. | 66 | * destination entry. |
67 | */ | 67 | */ |
68 | struct DestinationTunnel | 68 | struct DestinationChannel |
69 | { | 69 | { |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * Kept in a DLL. | 72 | * Kept in a DLL. |
73 | */ | 73 | */ |
74 | struct DestinationTunnel *next; | 74 | struct DestinationChannel *next; |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * Kept in a DLL. | 77 | * Kept in a DLL. |
78 | */ | 78 | */ |
79 | struct DestinationTunnel *prev; | 79 | struct DestinationChannel *prev; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Destination entry list this `struct DestinationTunnel` belongs with. | 82 | * Destination entry list this `struct DestinationChannel` belongs with. |
83 | */ | 83 | */ |
84 | struct DestinationEntry *destination; | 84 | struct DestinationEntry *destination; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * Pre-allocated tunnel for this destination, or NULL for none. | 87 | * Pre-allocated channel for this destination, or NULL for none. |
88 | */ | 88 | */ |
89 | struct TunnelState *ts; | 89 | struct ChannelState *ts; |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Destination port this tunnel state is used for. | 92 | * Destination port this channel state is used for. |
93 | */ | 93 | */ |
94 | uint16_t destination_port; | 94 | uint16_t destination_port; |
95 | 95 | ||
@@ -97,7 +97,7 @@ struct DestinationTunnel | |||
97 | 97 | ||
98 | 98 | ||
99 | /** | 99 | /** |
100 | * Information we track for each IP address to determine which tunnel | 100 | * Information we track for each IP address to determine which channel |
101 | * to send the traffic over to the destination. | 101 | * to send the traffic over to the destination. |
102 | */ | 102 | */ |
103 | struct DestinationEntry | 103 | struct DestinationEntry |
@@ -110,14 +110,14 @@ struct DestinationEntry | |||
110 | struct GNUNET_HashCode key; | 110 | struct GNUNET_HashCode key; |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * Head of DLL of tunnels associated with this destination. | 113 | * Head of DLL of channels associated with this destination. |
114 | */ | 114 | */ |
115 | struct DestinationTunnel *dt_head; | 115 | struct DestinationChannel *dt_head; |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Tail of DLL of tunnels associated with this destination. | 118 | * Tail of DLL of channels associated with this destination. |
119 | */ | 119 | */ |
120 | struct DestinationTunnel *dt_tail; | 120 | struct DestinationChannel *dt_tail; |
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Entry for this entry in the destination_heap. | 123 | * Entry for this entry in the destination_heap. |
@@ -125,8 +125,8 @@ struct DestinationEntry | |||
125 | struct GNUNET_CONTAINER_HeapNode *heap_node; | 125 | struct GNUNET_CONTAINER_HeapNode *heap_node; |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * #GNUNET_NO if this is a tunnel to an Internet-exit, | 128 | * #GNUNET_NO if this is a channel to an Internet-exit, |
129 | * #GNUNET_YES if this tunnel is to a service. | 129 | * #GNUNET_YES if this channel is to a service. |
130 | */ | 130 | */ |
131 | int is_service; | 131 | int is_service; |
132 | 132 | ||
@@ -139,7 +139,7 @@ struct DestinationEntry | |||
139 | struct | 139 | struct |
140 | { | 140 | { |
141 | /** | 141 | /** |
142 | * The description of the service (only used for service tunnels). | 142 | * The description of the service (only used for service channels). |
143 | */ | 143 | */ |
144 | struct GNUNET_HashCode service_descriptor; | 144 | struct GNUNET_HashCode service_descriptor; |
145 | 145 | ||
@@ -159,7 +159,7 @@ struct DestinationEntry | |||
159 | int af; | 159 | int af; |
160 | 160 | ||
161 | /** | 161 | /** |
162 | * IP address of the ultimate destination (only used for exit tunnels). | 162 | * IP address of the ultimate destination (only used for exit channels). |
163 | */ | 163 | */ |
164 | union | 164 | union |
165 | { | 165 | { |
@@ -182,19 +182,19 @@ struct DestinationEntry | |||
182 | 182 | ||
183 | 183 | ||
184 | /** | 184 | /** |
185 | * A messages we have in queue for a particular tunnel. | 185 | * A messages we have in queue for a particular channel. |
186 | */ | 186 | */ |
187 | struct TunnelMessageQueueEntry | 187 | struct ChannelMessageQueueEntry |
188 | { | 188 | { |
189 | /** | 189 | /** |
190 | * This is a doubly-linked list. | 190 | * This is a doubly-linked list. |
191 | */ | 191 | */ |
192 | struct TunnelMessageQueueEntry *next; | 192 | struct ChannelMessageQueueEntry *next; |
193 | 193 | ||
194 | /** | 194 | /** |
195 | * This is a doubly-linked list. | 195 | * This is a doubly-linked list. |
196 | */ | 196 | */ |
197 | struct TunnelMessageQueueEntry *prev; | 197 | struct ChannelMessageQueueEntry *prev; |
198 | 198 | ||
199 | /** | 199 | /** |
200 | * Number of bytes in 'msg'. | 200 | * Number of bytes in 'msg'. |
@@ -209,16 +209,16 @@ struct TunnelMessageQueueEntry | |||
209 | 209 | ||
210 | 210 | ||
211 | /** | 211 | /** |
212 | * State we keep for each of our tunnels. | 212 | * State we keep for each of our channels. |
213 | */ | 213 | */ |
214 | struct TunnelState | 214 | struct ChannelState |
215 | { | 215 | { |
216 | 216 | ||
217 | /** | 217 | /** |
218 | * Information about the tunnel to use, NULL if no tunnel | 218 | * Information about the channel to use, NULL if no channel |
219 | * is available right now. | 219 | * is available right now. |
220 | */ | 220 | */ |
221 | struct GNUNET_MESH_Tunnel *tunnel; | 221 | struct GNUNET_MESH_Channel *channel; |
222 | 222 | ||
223 | /** | 223 | /** |
224 | * Active query with REGEX to locate exit. | 224 | * Active query with REGEX to locate exit. |
@@ -231,29 +231,29 @@ struct TunnelState | |||
231 | struct GNUNET_MESH_TransmitHandle *th; | 231 | struct GNUNET_MESH_TransmitHandle *th; |
232 | 232 | ||
233 | /** | 233 | /** |
234 | * Entry for this entry in the tunnel_heap, NULL as long as this | 234 | * Entry for this entry in the channel_heap, NULL as long as this |
235 | * tunnel state is not fully bound. | 235 | * channel state is not fully bound. |
236 | */ | 236 | */ |
237 | struct GNUNET_CONTAINER_HeapNode *heap_node; | 237 | struct GNUNET_CONTAINER_HeapNode *heap_node; |
238 | 238 | ||
239 | /** | 239 | /** |
240 | * Head of list of messages scheduled for transmission. | 240 | * Head of list of messages scheduled for transmission. |
241 | */ | 241 | */ |
242 | struct TunnelMessageQueueEntry *tmq_head; | 242 | struct ChannelMessageQueueEntry *tmq_head; |
243 | 243 | ||
244 | /** | 244 | /** |
245 | * Tail of list of messages scheduled for transmission. | 245 | * Tail of list of messages scheduled for transmission. |
246 | */ | 246 | */ |
247 | struct TunnelMessageQueueEntry *tmq_tail; | 247 | struct ChannelMessageQueueEntry *tmq_tail; |
248 | 248 | ||
249 | /** | 249 | /** |
250 | * Destination entry that has a pointer to this tunnel state; | 250 | * Destination entry that has a pointer to this channel state; |
251 | * NULL if this tunnel state is in the tunnel map. | 251 | * NULL if this channel state is in the channel map. |
252 | */ | 252 | */ |
253 | struct DestinationTunnel *destination_container; | 253 | struct DestinationChannel *destination_container; |
254 | 254 | ||
255 | /** | 255 | /** |
256 | * Destination to which this tunnel leads. Note that | 256 | * Destination to which this channel leads. Note that |
257 | * this struct is NOT in the destination_map (but a | 257 | * this struct is NOT in the destination_map (but a |
258 | * local copy) and that the 'heap_node' should always | 258 | * local copy) and that the 'heap_node' should always |
259 | * be NULL. | 259 | * be NULL. |
@@ -261,7 +261,7 @@ struct TunnelState | |||
261 | struct DestinationEntry destination; | 261 | struct DestinationEntry destination; |
262 | 262 | ||
263 | /** | 263 | /** |
264 | * Addess family used for this tunnel on the local TUN interface. | 264 | * Addess family used for this channel on the local TUN interface. |
265 | */ | 265 | */ |
266 | int af; | 266 | int af; |
267 | 267 | ||
@@ -294,7 +294,7 @@ struct TunnelState | |||
294 | 294 | ||
295 | /** | 295 | /** |
296 | * Destination IP address used by the source on our end (this is the IP | 296 | * Destination IP address used by the source on our end (this is the IP |
297 | * that we pick freely within the VPN's tunnel IP range). | 297 | * that we pick freely within the VPN's channel IP range). |
298 | */ | 298 | */ |
299 | union | 299 | union |
300 | { | 300 | { |
@@ -340,7 +340,7 @@ static struct GNUNET_MESH_Handle *mesh_handle; | |||
340 | 340 | ||
341 | /** | 341 | /** |
342 | * Map from IP address to destination information (possibly with a | 342 | * Map from IP address to destination information (possibly with a |
343 | * MESH tunnel handle for fast setup). | 343 | * MESH channel handle for fast setup). |
344 | */ | 344 | */ |
345 | static struct GNUNET_CONTAINER_MultiHashMap *destination_map; | 345 | static struct GNUNET_CONTAINER_MultiHashMap *destination_map; |
346 | 346 | ||
@@ -351,15 +351,15 @@ static struct GNUNET_CONTAINER_Heap *destination_heap; | |||
351 | 351 | ||
352 | /** | 352 | /** |
353 | * Map from source and destination address (IP+port) to connection | 353 | * Map from source and destination address (IP+port) to connection |
354 | * information (mostly with the respective MESH tunnel handle). | 354 | * information (mostly with the respective MESH channel handle). |
355 | */ | 355 | */ |
356 | static struct GNUNET_CONTAINER_MultiHashMap *tunnel_map; | 356 | static struct GNUNET_CONTAINER_MultiHashMap *channel_map; |
357 | 357 | ||
358 | /** | 358 | /** |
359 | * Min-Heap sorted by activity time to expire old mappings; values are | 359 | * Min-Heap sorted by activity time to expire old mappings; values are |
360 | * of type 'struct TunnelState'. | 360 | * of type 'struct ChannelState'. |
361 | */ | 361 | */ |
362 | static struct GNUNET_CONTAINER_Heap *tunnel_heap; | 362 | static struct GNUNET_CONTAINER_Heap *channel_heap; |
363 | 363 | ||
364 | /** | 364 | /** |
365 | * Statistics. | 365 | * Statistics. |
@@ -393,10 +393,10 @@ static struct GNUNET_SERVER_NotificationContext *nc; | |||
393 | static unsigned long long max_destination_mappings; | 393 | static unsigned long long max_destination_mappings; |
394 | 394 | ||
395 | /** | 395 | /** |
396 | * If there are more than this number of open tunnels, old ones | 396 | * If there are more than this number of open channels, old ones |
397 | * will be removed | 397 | * will be removed |
398 | */ | 398 | */ |
399 | static unsigned long long max_tunnel_mappings; | 399 | static unsigned long long max_channel_mappings; |
400 | 400 | ||
401 | 401 | ||
402 | /** | 402 | /** |
@@ -433,7 +433,7 @@ get_destination_key_from_ip (int af, | |||
433 | 433 | ||
434 | /** | 434 | /** |
435 | * Compute the key under which we would store an entry in the | 435 | * Compute the key under which we would store an entry in the |
436 | * tunnel_map for the given socket address pair. | 436 | * channel_map for the given socket address pair. |
437 | * | 437 | * |
438 | * @param af address family (AF_INET or AF_INET6) | 438 | * @param af address family (AF_INET or AF_INET6) |
439 | * @param protocol IPPROTO_TCP or IPPROTO_UDP | 439 | * @param protocol IPPROTO_TCP or IPPROTO_UDP |
@@ -444,7 +444,7 @@ get_destination_key_from_ip (int af, | |||
444 | * @param key where to store the key | 444 | * @param key where to store the key |
445 | */ | 445 | */ |
446 | static void | 446 | static void |
447 | get_tunnel_key_from_ips (int af, | 447 | get_channel_key_from_ips (int af, |
448 | uint8_t protocol, | 448 | uint8_t protocol, |
449 | const void *source_ip, | 449 | const void *source_ip, |
450 | uint16_t source_port, | 450 | uint16_t source_port, |
@@ -533,21 +533,21 @@ send_client_reply (struct GNUNET_SERVER_Client *client, | |||
533 | 533 | ||
534 | 534 | ||
535 | /** | 535 | /** |
536 | * Free resources associated with a tunnel state. | 536 | * Free resources associated with a channel state. |
537 | * | 537 | * |
538 | * @param ts state to free | 538 | * @param ts state to free |
539 | */ | 539 | */ |
540 | static void | 540 | static void |
541 | free_tunnel_state (struct TunnelState *ts) | 541 | free_channel_state (struct ChannelState *ts) |
542 | { | 542 | { |
543 | struct GNUNET_HashCode key; | 543 | struct GNUNET_HashCode key; |
544 | struct TunnelMessageQueueEntry *tnq; | 544 | struct ChannelMessageQueueEntry *tnq; |
545 | struct GNUNET_MESH_Tunnel *tunnel; | 545 | struct GNUNET_MESH_Channel *channel; |
546 | 546 | ||
547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
548 | "Cleaning up tunnel state\n"); | 548 | "Cleaning up channel state\n"); |
549 | GNUNET_STATISTICS_update (stats, | 549 | GNUNET_STATISTICS_update (stats, |
550 | gettext_noop ("# Active tunnels"), | 550 | gettext_noop ("# Active channels"), |
551 | -1, GNUNET_NO); | 551 | -1, GNUNET_NO); |
552 | while (NULL != (tnq = ts->tmq_head)) | 552 | while (NULL != (tnq = ts->tmq_head)) |
553 | { | 553 | { |
@@ -564,10 +564,10 @@ free_tunnel_state (struct TunnelState *ts) | |||
564 | ts->th = NULL; | 564 | ts->th = NULL; |
565 | } | 565 | } |
566 | GNUNET_assert (NULL == ts->destination.heap_node); | 566 | GNUNET_assert (NULL == ts->destination.heap_node); |
567 | if (NULL != (tunnel = ts->tunnel)) | 567 | if (NULL != (channel = ts->channel)) |
568 | { | 568 | { |
569 | ts->tunnel = NULL; | 569 | ts->channel = NULL; |
570 | GNUNET_MESH_tunnel_destroy (tunnel); | 570 | GNUNET_MESH_channel_destroy (channel); |
571 | } | 571 | } |
572 | if (NULL != ts->search) | 572 | if (NULL != ts->search) |
573 | { | 573 | { |
@@ -578,7 +578,7 @@ free_tunnel_state (struct TunnelState *ts) | |||
578 | { | 578 | { |
579 | GNUNET_CONTAINER_heap_remove_node (ts->heap_node); | 579 | GNUNET_CONTAINER_heap_remove_node (ts->heap_node); |
580 | ts->heap_node = NULL; | 580 | ts->heap_node = NULL; |
581 | get_tunnel_key_from_ips (ts->af, | 581 | get_channel_key_from_ips (ts->af, |
582 | ts->protocol, | 582 | ts->protocol, |
583 | &ts->source_ip, | 583 | &ts->source_ip, |
584 | ts->source_port, | 584 | ts->source_port, |
@@ -586,7 +586,7 @@ free_tunnel_state (struct TunnelState *ts) | |||
586 | ts->destination_port, | 586 | ts->destination_port, |
587 | &key); | 587 | &key); |
588 | GNUNET_assert (GNUNET_YES == | 588 | GNUNET_assert (GNUNET_YES == |
589 | GNUNET_CONTAINER_multihashmap_remove (tunnel_map, | 589 | GNUNET_CONTAINER_multihashmap_remove (channel_map, |
590 | &key, | 590 | &key, |
591 | ts)); | 591 | ts)); |
592 | } | 592 | } |
@@ -603,7 +603,7 @@ free_tunnel_state (struct TunnelState *ts) | |||
603 | /** | 603 | /** |
604 | * Send a message from the message queue via mesh. | 604 | * Send a message from the message queue via mesh. |
605 | * | 605 | * |
606 | * @param cls the `struct TunnelState` with the message queue | 606 | * @param cls the `struct ChannelState` with the message queue |
607 | * @param size number of bytes available in @a buf | 607 | * @param size number of bytes available in @a buf |
608 | * @param buf where to copy the message | 608 | * @param buf where to copy the message |
609 | * @return number of bytes copied to @a buf | 609 | * @return number of bytes copied to @a buf |
@@ -611,8 +611,8 @@ free_tunnel_state (struct TunnelState *ts) | |||
611 | static size_t | 611 | static size_t |
612 | send_to_peer_notify_callback (void *cls, size_t size, void *buf) | 612 | send_to_peer_notify_callback (void *cls, size_t size, void *buf) |
613 | { | 613 | { |
614 | struct TunnelState *ts = cls; | 614 | struct ChannelState *ts = cls; |
615 | struct TunnelMessageQueueEntry *tnq; | 615 | struct ChannelMessageQueueEntry *tnq; |
616 | size_t ret; | 616 | size_t ret; |
617 | 617 | ||
618 | ts->th = NULL; | 618 | ts->th = NULL; |
@@ -622,7 +622,7 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
622 | GNUNET_assert (NULL != tnq); | 622 | GNUNET_assert (NULL != tnq); |
623 | GNUNET_assert (size >= tnq->len); | 623 | GNUNET_assert (size >= tnq->len); |
624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
625 | "Sending %u bytes via mesh tunnel\n", | 625 | "Sending %u bytes via mesh channel\n", |
626 | tnq->len); | 626 | tnq->len); |
627 | GNUNET_CONTAINER_DLL_remove (ts->tmq_head, | 627 | GNUNET_CONTAINER_DLL_remove (ts->tmq_head, |
628 | ts->tmq_tail, | 628 | ts->tmq_tail, |
@@ -632,7 +632,7 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
632 | ret = tnq->len; | 632 | ret = tnq->len; |
633 | GNUNET_free (tnq); | 633 | GNUNET_free (tnq); |
634 | if (NULL != (tnq = ts->tmq_head)) | 634 | if (NULL != (tnq = ts->tmq_head)) |
635 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, | 635 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->channel, |
636 | GNUNET_NO /* cork */, | 636 | GNUNET_NO /* cork */, |
637 | GNUNET_TIME_UNIT_FOREVER_REL, | 637 | GNUNET_TIME_UNIT_FOREVER_REL, |
638 | tnq->len, | 638 | tnq->len, |
@@ -646,27 +646,27 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
646 | 646 | ||
647 | 647 | ||
648 | /** | 648 | /** |
649 | * Add the given message to the given tunnel and trigger the | 649 | * Add the given message to the given channel and trigger the |
650 | * transmission process. | 650 | * transmission process. |
651 | * | 651 | * |
652 | * @param tnq message to queue | 652 | * @param tnq message to queue |
653 | * @param ts tunnel to queue the message for | 653 | * @param ts channel to queue the message for |
654 | */ | 654 | */ |
655 | static void | 655 | static void |
656 | send_to_tunnel (struct TunnelMessageQueueEntry *tnq, | 656 | send_to_channel (struct ChannelMessageQueueEntry *tnq, |
657 | struct TunnelState *ts) | 657 | struct ChannelState *ts) |
658 | { | 658 | { |
659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
660 | "Queueing %u bytes for transmission via mesh tunnel\n", | 660 | "Queueing %u bytes for transmission via mesh channel\n", |
661 | tnq->len); | 661 | tnq->len); |
662 | GNUNET_assert (NULL != ts->tunnel); | 662 | GNUNET_assert (NULL != ts->channel); |
663 | GNUNET_CONTAINER_DLL_insert_tail (ts->tmq_head, | 663 | GNUNET_CONTAINER_DLL_insert_tail (ts->tmq_head, |
664 | ts->tmq_tail, | 664 | ts->tmq_tail, |
665 | tnq); | 665 | tnq); |
666 | ts->tmq_length++; | 666 | ts->tmq_length++; |
667 | if (ts->tmq_length > MAX_MESSAGE_QUEUE_SIZE) | 667 | if (ts->tmq_length > MAX_MESSAGE_QUEUE_SIZE) |
668 | { | 668 | { |
669 | struct TunnelMessageQueueEntry *dq; | 669 | struct ChannelMessageQueueEntry *dq; |
670 | 670 | ||
671 | dq = ts->tmq_head; | 671 | dq = ts->tmq_head; |
672 | GNUNET_assert (dq != tnq); | 672 | GNUNET_assert (dq != tnq); |
@@ -683,7 +683,7 @@ send_to_tunnel (struct TunnelMessageQueueEntry *tnq, | |||
683 | GNUNET_free (dq); | 683 | GNUNET_free (dq); |
684 | } | 684 | } |
685 | if (NULL == ts->th) | 685 | if (NULL == ts->th) |
686 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, | 686 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->channel, |
687 | GNUNET_NO /* cork */, | 687 | GNUNET_NO /* cork */, |
688 | GNUNET_TIME_UNIT_FOREVER_REL, | 688 | GNUNET_TIME_UNIT_FOREVER_REL, |
689 | tnq->len, | 689 | tnq->len, |
@@ -695,7 +695,7 @@ send_to_tunnel (struct TunnelMessageQueueEntry *tnq, | |||
695 | /** | 695 | /** |
696 | * Regex has found a potential exit peer for us; consider using it. | 696 | * Regex has found a potential exit peer for us; consider using it. |
697 | * | 697 | * |
698 | * @param cls the 'struct TunnelState' | 698 | * @param cls the 'struct ChannelState' |
699 | * @param id Peer providing a regex that matches the string. | 699 | * @param id Peer providing a regex that matches the string. |
700 | * @param get_path Path of the get request. | 700 | * @param get_path Path of the get request. |
701 | * @param get_path_length Lenght of @a get_path. | 701 | * @param get_path_length Lenght of @a get_path. |
@@ -710,7 +710,7 @@ handle_regex_result (void *cls, | |||
710 | const struct GNUNET_PeerIdentity *put_path, | 710 | const struct GNUNET_PeerIdentity *put_path, |
711 | unsigned int put_path_length) | 711 | unsigned int put_path_length) |
712 | { | 712 | { |
713 | struct TunnelState *ts = cls; | 713 | struct ChannelState *ts = cls; |
714 | unsigned int apptype; | 714 | unsigned int apptype; |
715 | 715 | ||
716 | GNUNET_REGEX_search_cancel (ts->search); | 716 | GNUNET_REGEX_search_cancel (ts->search); |
@@ -727,7 +727,7 @@ handle_regex_result (void *cls, | |||
727 | GNUNET_break (0); | 727 | GNUNET_break (0); |
728 | return; | 728 | return; |
729 | } | 729 | } |
730 | ts->tunnel = GNUNET_MESH_tunnel_create (mesh_handle, | 730 | ts->channel = GNUNET_MESH_channel_create (mesh_handle, |
731 | ts, | 731 | ts, |
732 | id, | 732 | id, |
733 | apptype, | 733 | apptype, |
@@ -737,21 +737,21 @@ handle_regex_result (void *cls, | |||
737 | 737 | ||
738 | 738 | ||
739 | /** | 739 | /** |
740 | * Initialize the given destination entry's mesh tunnel. | 740 | * Initialize the given destination entry's mesh channel. |
741 | * | 741 | * |
742 | * @param dt destination tunnel for which we need to setup a tunnel | 742 | * @param dt destination channel for which we need to setup a channel |
743 | * @param client_af address family of the address returned to the client | 743 | * @param client_af address family of the address returned to the client |
744 | * @return tunnel state of the tunnel that was created | 744 | * @return channel state of the channel that was created |
745 | */ | 745 | */ |
746 | static struct TunnelState * | 746 | static struct ChannelState * |
747 | create_tunnel_to_destination (struct DestinationTunnel *dt, | 747 | create_channel_to_destination (struct DestinationChannel *dt, |
748 | int client_af) | 748 | int client_af) |
749 | { | 749 | { |
750 | struct TunnelState *ts; | 750 | struct ChannelState *ts; |
751 | unsigned int apptype; | 751 | unsigned int apptype; |
752 | 752 | ||
753 | GNUNET_STATISTICS_update (stats, | 753 | GNUNET_STATISTICS_update (stats, |
754 | gettext_noop ("# Mesh tunnels created"), | 754 | gettext_noop ("# Mesh channels created"), |
755 | 1, GNUNET_NO); | 755 | 1, GNUNET_NO); |
756 | GNUNET_assert (NULL == dt->ts); | 756 | GNUNET_assert (NULL == dt->ts); |
757 | switch (client_af) | 757 | switch (client_af) |
@@ -766,7 +766,7 @@ create_tunnel_to_destination (struct DestinationTunnel *dt, | |||
766 | GNUNET_break (0); | 766 | GNUNET_break (0); |
767 | return NULL; | 767 | return NULL; |
768 | } | 768 | } |
769 | ts = GNUNET_new (struct TunnelState); | 769 | ts = GNUNET_new (struct ChannelState); |
770 | ts->af = client_af; | 770 | ts->af = client_af; |
771 | ts->destination = *dt->destination; | 771 | ts->destination = *dt->destination; |
772 | ts->destination.heap_node = NULL; /* copy is NOT in destination heap */ | 772 | ts->destination.heap_node = NULL; /* copy is NOT in destination heap */ |
@@ -774,21 +774,21 @@ create_tunnel_to_destination (struct DestinationTunnel *dt, | |||
774 | ts->destination_container = dt; /* we are referenced from dt */ | 774 | ts->destination_container = dt; /* we are referenced from dt */ |
775 | if (dt->destination->is_service) | 775 | if (dt->destination->is_service) |
776 | { | 776 | { |
777 | ts->tunnel = GNUNET_MESH_tunnel_create (mesh_handle, | 777 | ts->channel = GNUNET_MESH_channel_create (mesh_handle, |
778 | ts, | 778 | ts, |
779 | &dt->destination->details.service_destination.target, | 779 | &dt->destination->details.service_destination.target, |
780 | apptype, | 780 | apptype, |
781 | GNUNET_YES, | 781 | GNUNET_YES, |
782 | GNUNET_NO); | 782 | GNUNET_NO); |
783 | if (NULL == ts->tunnel) | 783 | if (NULL == ts->channel) |
784 | { | 784 | { |
785 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 785 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
786 | _("Failed to setup mesh tunnel!\n")); | 786 | _("Failed to setup mesh channel!\n")); |
787 | GNUNET_free (ts); | 787 | GNUNET_free (ts); |
788 | return NULL; | 788 | return NULL; |
789 | } | 789 | } |
790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
791 | "Creating tunnel to peer %s offering service %s\n", | 791 | "Creating channel to peer %s offering service %s\n", |
792 | GNUNET_i2s (&dt->destination->details.service_destination.target), | 792 | GNUNET_i2s (&dt->destination->details.service_destination.target), |
793 | GNUNET_h2s (&dt->destination->details.service_destination.service_descriptor)); | 793 | GNUNET_h2s (&dt->destination->details.service_destination.service_descriptor)); |
794 | } | 794 | } |
@@ -841,20 +841,20 @@ create_tunnel_to_destination (struct DestinationTunnel *dt, | |||
841 | 841 | ||
842 | 842 | ||
843 | /** | 843 | /** |
844 | * We have too many active tunnels. Clean up the oldest tunnel. | 844 | * We have too many active channels. Clean up the oldest channel. |
845 | * | 845 | * |
846 | * @param except tunnel that must NOT be cleaned up, even if it is the oldest | 846 | * @param except channel that must NOT be cleaned up, even if it is the oldest |
847 | */ | 847 | */ |
848 | static void | 848 | static void |
849 | expire_tunnel (struct TunnelState *except) | 849 | expire_channel (struct ChannelState *except) |
850 | { | 850 | { |
851 | struct TunnelState *ts; | 851 | struct ChannelState *ts; |
852 | 852 | ||
853 | ts = GNUNET_CONTAINER_heap_peek (tunnel_heap); | 853 | ts = GNUNET_CONTAINER_heap_peek (channel_heap); |
854 | GNUNET_assert (NULL != ts); | 854 | GNUNET_assert (NULL != ts); |
855 | if (except == ts) | 855 | if (except == ts) |
856 | return; /* can't do this */ | 856 | return; /* can't do this */ |
857 | free_tunnel_state (ts); | 857 | free_channel_state (ts); |
858 | } | 858 | } |
859 | 859 | ||
860 | 860 | ||
@@ -879,15 +879,15 @@ route_packet (struct DestinationEntry *destination, | |||
879 | size_t payload_length) | 879 | size_t payload_length) |
880 | { | 880 | { |
881 | struct GNUNET_HashCode key; | 881 | struct GNUNET_HashCode key; |
882 | struct TunnelState *ts; | 882 | struct ChannelState *ts; |
883 | struct TunnelMessageQueueEntry *tnq; | 883 | struct ChannelMessageQueueEntry *tnq; |
884 | size_t alen; | 884 | size_t alen; |
885 | size_t mlen; | 885 | size_t mlen; |
886 | int is_new; | 886 | int is_new; |
887 | const struct GNUNET_TUN_UdpHeader *udp; | 887 | const struct GNUNET_TUN_UdpHeader *udp; |
888 | const struct GNUNET_TUN_TcpHeader *tcp; | 888 | const struct GNUNET_TUN_TcpHeader *tcp; |
889 | const struct GNUNET_TUN_IcmpHeader *icmp; | 889 | const struct GNUNET_TUN_IcmpHeader *icmp; |
890 | struct DestinationTunnel *dt; | 890 | struct DestinationChannel *dt; |
891 | uint16_t source_port; | 891 | uint16_t source_port; |
892 | uint16_t destination_port; | 892 | uint16_t destination_port; |
893 | 893 | ||
@@ -911,7 +911,7 @@ route_packet (struct DestinationEntry *destination, | |||
911 | } | 911 | } |
912 | source_port = ntohs (udp->source_port); | 912 | source_port = ntohs (udp->source_port); |
913 | destination_port = ntohs (udp->destination_port); | 913 | destination_port = ntohs (udp->destination_port); |
914 | get_tunnel_key_from_ips (af, | 914 | get_channel_key_from_ips (af, |
915 | IPPROTO_UDP, | 915 | IPPROTO_UDP, |
916 | source_ip, | 916 | source_ip, |
917 | source_port, | 917 | source_port, |
@@ -938,7 +938,7 @@ route_packet (struct DestinationEntry *destination, | |||
938 | } | 938 | } |
939 | source_port = ntohs (tcp->source_port); | 939 | source_port = ntohs (tcp->source_port); |
940 | destination_port = ntohs (tcp->destination_port); | 940 | destination_port = ntohs (tcp->destination_port); |
941 | get_tunnel_key_from_ips (af, | 941 | get_channel_key_from_ips (af, |
942 | IPPROTO_TCP, | 942 | IPPROTO_TCP, |
943 | source_ip, | 943 | source_ip, |
944 | source_port, | 944 | source_port, |
@@ -966,7 +966,7 @@ route_packet (struct DestinationEntry *destination, | |||
966 | icmp = payload; | 966 | icmp = payload; |
967 | source_port = 0; | 967 | source_port = 0; |
968 | destination_port = 0; | 968 | destination_port = 0; |
969 | get_tunnel_key_from_ips (af, | 969 | get_channel_key_from_ips (af, |
970 | protocol, | 970 | protocol, |
971 | source_ip, | 971 | source_ip, |
972 | 0, | 972 | 0, |
@@ -1037,7 +1037,7 @@ route_packet (struct DestinationEntry *destination, | |||
1037 | } | 1037 | } |
1038 | if (NULL == dt) | 1038 | if (NULL == dt) |
1039 | { | 1039 | { |
1040 | dt = GNUNET_new (struct DestinationTunnel); | 1040 | dt = GNUNET_new (struct DestinationChannel); |
1041 | dt->destination = destination; | 1041 | dt->destination = destination; |
1042 | GNUNET_CONTAINER_DLL_insert (destination->dt_head, | 1042 | GNUNET_CONTAINER_DLL_insert (destination->dt_head, |
1043 | destination->dt_tail, | 1043 | destination->dt_tail, |
@@ -1045,23 +1045,23 @@ route_packet (struct DestinationEntry *destination, | |||
1045 | dt->destination_port = destination_port; | 1045 | dt->destination_port = destination_port; |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | /* see if we have an existing tunnel for this destination */ | 1048 | /* see if we have an existing channel for this destination */ |
1049 | ts = GNUNET_CONTAINER_multihashmap_get (tunnel_map, | 1049 | ts = GNUNET_CONTAINER_multihashmap_get (channel_map, |
1050 | &key); | 1050 | &key); |
1051 | if (NULL == ts) | 1051 | if (NULL == ts) |
1052 | { | 1052 | { |
1053 | /* need to either use the existing tunnel from the destination (if still | 1053 | /* need to either use the existing channel from the destination (if still |
1054 | available) or create a fresh one */ | 1054 | available) or create a fresh one */ |
1055 | is_new = GNUNET_YES; | 1055 | is_new = GNUNET_YES; |
1056 | if (NULL == dt->ts) | 1056 | if (NULL == dt->ts) |
1057 | ts = create_tunnel_to_destination (dt, af); | 1057 | ts = create_channel_to_destination (dt, af); |
1058 | else | 1058 | else |
1059 | ts = dt->ts; | 1059 | ts = dt->ts; |
1060 | if (NULL == ts) | 1060 | if (NULL == ts) |
1061 | return; | 1061 | return; |
1062 | dt->ts = NULL; | 1062 | dt->ts = NULL; |
1063 | ts->destination_container = NULL; /* no longer 'contained' */ | 1063 | ts->destination_container = NULL; /* no longer 'contained' */ |
1064 | /* now bind existing "unbound" tunnel to our IP/port tuple */ | 1064 | /* now bind existing "unbound" channel to our IP/port tuple */ |
1065 | ts->protocol = protocol; | 1065 | ts->protocol = protocol; |
1066 | ts->af = af; | 1066 | ts->af = af; |
1067 | if (AF_INET == af) | 1067 | if (AF_INET == af) |
@@ -1076,30 +1076,30 @@ route_packet (struct DestinationEntry *destination, | |||
1076 | } | 1076 | } |
1077 | ts->source_port = source_port; | 1077 | ts->source_port = source_port; |
1078 | ts->destination_port = destination_port; | 1078 | ts->destination_port = destination_port; |
1079 | ts->heap_node = GNUNET_CONTAINER_heap_insert (tunnel_heap, | 1079 | ts->heap_node = GNUNET_CONTAINER_heap_insert (channel_heap, |
1080 | ts, | 1080 | ts, |
1081 | GNUNET_TIME_absolute_get ().abs_value_us); | 1081 | GNUNET_TIME_absolute_get ().abs_value_us); |
1082 | GNUNET_assert (GNUNET_YES == | 1082 | GNUNET_assert (GNUNET_YES == |
1083 | GNUNET_CONTAINER_multihashmap_put (tunnel_map, | 1083 | GNUNET_CONTAINER_multihashmap_put (channel_map, |
1084 | &key, | 1084 | &key, |
1085 | ts, | 1085 | ts, |
1086 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1086 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1087 | GNUNET_STATISTICS_update (stats, | 1087 | GNUNET_STATISTICS_update (stats, |
1088 | gettext_noop ("# Active tunnels"), | 1088 | gettext_noop ("# Active channels"), |
1089 | 1, GNUNET_NO); | 1089 | 1, GNUNET_NO); |
1090 | while (GNUNET_CONTAINER_multihashmap_size (tunnel_map) > max_tunnel_mappings) | 1090 | while (GNUNET_CONTAINER_multihashmap_size (channel_map) > max_channel_mappings) |
1091 | expire_tunnel (ts); | 1091 | expire_channel (ts); |
1092 | } | 1092 | } |
1093 | else | 1093 | else |
1094 | { | 1094 | { |
1095 | is_new = GNUNET_NO; | 1095 | is_new = GNUNET_NO; |
1096 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, | 1096 | GNUNET_CONTAINER_heap_update_cost (channel_heap, |
1097 | ts->heap_node, | 1097 | ts->heap_node, |
1098 | GNUNET_TIME_absolute_get ().abs_value_us); | 1098 | GNUNET_TIME_absolute_get ().abs_value_us); |
1099 | } | 1099 | } |
1100 | GNUNET_assert (NULL != ts->tunnel); | 1100 | GNUNET_assert (NULL != ts->channel); |
1101 | 1101 | ||
1102 | /* send via tunnel */ | 1102 | /* send via channel */ |
1103 | switch (protocol) | 1103 | switch (protocol) |
1104 | { | 1104 | { |
1105 | case IPPROTO_UDP: | 1105 | case IPPROTO_UDP: |
@@ -1114,7 +1114,7 @@ route_packet (struct DestinationEntry *destination, | |||
1114 | GNUNET_break (0); | 1114 | GNUNET_break (0); |
1115 | return; | 1115 | return; |
1116 | } | 1116 | } |
1117 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 1117 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueueEntry) + mlen); |
1118 | tnq->len = mlen; | 1118 | tnq->len = mlen; |
1119 | tnq->msg = &tnq[1]; | 1119 | tnq->msg = &tnq[1]; |
1120 | usm = (struct GNUNET_EXIT_UdpServiceMessage *) &tnq[1]; | 1120 | usm = (struct GNUNET_EXIT_UdpServiceMessage *) &tnq[1]; |
@@ -1143,7 +1143,7 @@ route_packet (struct DestinationEntry *destination, | |||
1143 | GNUNET_break (0); | 1143 | GNUNET_break (0); |
1144 | return; | 1144 | return; |
1145 | } | 1145 | } |
1146 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 1146 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueueEntry) + mlen); |
1147 | tnq->len = mlen; | 1147 | tnq->len = mlen; |
1148 | tnq->msg = &tnq[1]; | 1148 | tnq->msg = &tnq[1]; |
1149 | uim = (struct GNUNET_EXIT_UdpInternetMessage *) &tnq[1]; | 1149 | uim = (struct GNUNET_EXIT_UdpInternetMessage *) &tnq[1]; |
@@ -1186,7 +1186,7 @@ route_packet (struct DestinationEntry *destination, | |||
1186 | GNUNET_break (0); | 1186 | GNUNET_break (0); |
1187 | return; | 1187 | return; |
1188 | } | 1188 | } |
1189 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 1189 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueueEntry) + mlen); |
1190 | tnq->len = mlen; | 1190 | tnq->len = mlen; |
1191 | tnq->msg = &tnq[1]; | 1191 | tnq->msg = &tnq[1]; |
1192 | tsm = (struct GNUNET_EXIT_TcpServiceStartMessage *) &tnq[1]; | 1192 | tsm = (struct GNUNET_EXIT_TcpServiceStartMessage *) &tnq[1]; |
@@ -1213,7 +1213,7 @@ route_packet (struct DestinationEntry *destination, | |||
1213 | GNUNET_break (0); | 1213 | GNUNET_break (0); |
1214 | return; | 1214 | return; |
1215 | } | 1215 | } |
1216 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 1216 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueueEntry) + mlen); |
1217 | tnq->len = mlen; | 1217 | tnq->len = mlen; |
1218 | tnq->msg = &tnq[1]; | 1218 | tnq->msg = &tnq[1]; |
1219 | tim = (struct GNUNET_EXIT_TcpInternetStartMessage *) &tnq[1]; | 1219 | tim = (struct GNUNET_EXIT_TcpInternetStartMessage *) &tnq[1]; |
@@ -1252,7 +1252,7 @@ route_packet (struct DestinationEntry *destination, | |||
1252 | GNUNET_break (0); | 1252 | GNUNET_break (0); |
1253 | return; | 1253 | return; |
1254 | } | 1254 | } |
1255 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 1255 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueueEntry) + mlen); |
1256 | tnq->len = mlen; | 1256 | tnq->len = mlen; |
1257 | tnq->msg = &tnq[1]; | 1257 | tnq->msg = &tnq[1]; |
1258 | tdm = (struct GNUNET_EXIT_TcpDataMessage *) &tnq[1]; | 1258 | tdm = (struct GNUNET_EXIT_TcpDataMessage *) &tnq[1]; |
@@ -1278,7 +1278,7 @@ route_packet (struct DestinationEntry *destination, | |||
1278 | GNUNET_break (0); | 1278 | GNUNET_break (0); |
1279 | return; | 1279 | return; |
1280 | } | 1280 | } |
1281 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 1281 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueueEntry) + mlen); |
1282 | tnq->msg = &tnq[1]; | 1282 | tnq->msg = &tnq[1]; |
1283 | ism = (struct GNUNET_EXIT_IcmpServiceMessage *) &tnq[1]; | 1283 | ism = (struct GNUNET_EXIT_IcmpServiceMessage *) &tnq[1]; |
1284 | ism->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE); | 1284 | ism->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE); |
@@ -1360,7 +1360,7 @@ route_packet (struct DestinationEntry *destination, | |||
1360 | GNUNET_break (0); | 1360 | GNUNET_break (0); |
1361 | return; | 1361 | return; |
1362 | } | 1362 | } |
1363 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 1363 | tnq = GNUNET_malloc (sizeof (struct ChannelMessageQueueEntry) + mlen); |
1364 | tnq->msg = &tnq[1]; | 1364 | tnq->msg = &tnq[1]; |
1365 | iim = (struct GNUNET_EXIT_IcmpInternetMessage *) &tnq[1]; | 1365 | iim = (struct GNUNET_EXIT_IcmpInternetMessage *) &tnq[1]; |
1366 | iim->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); | 1366 | iim->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); |
@@ -1505,19 +1505,19 @@ route_packet (struct DestinationEntry *destination, | |||
1505 | GNUNET_assert (0); | 1505 | GNUNET_assert (0); |
1506 | break; | 1506 | break; |
1507 | } | 1507 | } |
1508 | send_to_tunnel (tnq, ts); | 1508 | send_to_channel (tnq, ts); |
1509 | } | 1509 | } |
1510 | 1510 | ||
1511 | 1511 | ||
1512 | /** | 1512 | /** |
1513 | * Receive packets from the helper-process (someone send to the local | 1513 | * Receive packets from the helper-process (someone send to the local |
1514 | * virtual tunnel interface). Find the destination mapping, and if it | 1514 | * virtual channel interface). Find the destination mapping, and if it |
1515 | * exists, identify the correct MESH tunnel (or possibly create it) | 1515 | * exists, identify the correct MESH channel (or possibly create it) |
1516 | * and forward the packet. | 1516 | * and forward the packet. |
1517 | * | 1517 | * |
1518 | * @param cls closure, NULL | 1518 | * @param cls closure, NULL |
1519 | * @param client NULL | 1519 | * @param client NULL |
1520 | * @param message message we got from the client (VPN tunnel interface) | 1520 | * @param message message we got from the client (VPN channel interface) |
1521 | */ | 1521 | */ |
1522 | static int | 1522 | static int |
1523 | message_token (void *cls, | 1523 | message_token (void *cls, |
@@ -1633,15 +1633,15 @@ message_token (void *cls, | |||
1633 | 1633 | ||
1634 | /** | 1634 | /** |
1635 | * Synthesize a plausible ICMP payload for an ICMP error | 1635 | * Synthesize a plausible ICMP payload for an ICMP error |
1636 | * response on the given tunnel. | 1636 | * response on the given channel. |
1637 | * | 1637 | * |
1638 | * @param ts tunnel information | 1638 | * @param ts channel information |
1639 | * @param ipp IPv4 header to fill in (ICMP payload) | 1639 | * @param ipp IPv4 header to fill in (ICMP payload) |
1640 | * @param udp "UDP" header to fill in (ICMP payload); might actually | 1640 | * @param udp "UDP" header to fill in (ICMP payload); might actually |
1641 | * also be the first 8 bytes of the TCP header | 1641 | * also be the first 8 bytes of the TCP header |
1642 | */ | 1642 | */ |
1643 | static void | 1643 | static void |
1644 | make_up_icmpv4_payload (struct TunnelState *ts, | 1644 | make_up_icmpv4_payload (struct ChannelState *ts, |
1645 | struct GNUNET_TUN_IPv4Header *ipp, | 1645 | struct GNUNET_TUN_IPv4Header *ipp, |
1646 | struct GNUNET_TUN_UdpHeader *udp) | 1646 | struct GNUNET_TUN_UdpHeader *udp) |
1647 | { | 1647 | { |
@@ -1659,15 +1659,15 @@ make_up_icmpv4_payload (struct TunnelState *ts, | |||
1659 | 1659 | ||
1660 | /** | 1660 | /** |
1661 | * Synthesize a plausible ICMP payload for an ICMP error | 1661 | * Synthesize a plausible ICMP payload for an ICMP error |
1662 | * response on the given tunnel. | 1662 | * response on the given channel. |
1663 | * | 1663 | * |
1664 | * @param ts tunnel information | 1664 | * @param ts channel information |
1665 | * @param ipp IPv6 header to fill in (ICMP payload) | 1665 | * @param ipp IPv6 header to fill in (ICMP payload) |
1666 | * @param udp "UDP" header to fill in (ICMP payload); might actually | 1666 | * @param udp "UDP" header to fill in (ICMP payload); might actually |
1667 | * also be the first 8 bytes of the TCP header | 1667 | * also be the first 8 bytes of the TCP header |
1668 | */ | 1668 | */ |
1669 | static void | 1669 | static void |
1670 | make_up_icmpv6_payload (struct TunnelState *ts, | 1670 | make_up_icmpv6_payload (struct ChannelState *ts, |
1671 | struct GNUNET_TUN_IPv6Header *ipp, | 1671 | struct GNUNET_TUN_IPv6Header *ipp, |
1672 | struct GNUNET_TUN_UdpHeader *udp) | 1672 | struct GNUNET_TUN_UdpHeader *udp) |
1673 | { | 1673 | { |
@@ -1684,23 +1684,23 @@ make_up_icmpv6_payload (struct TunnelState *ts, | |||
1684 | 1684 | ||
1685 | 1685 | ||
1686 | /** | 1686 | /** |
1687 | * We got an ICMP packet back from the MESH tunnel. Pass it on to the | 1687 | * We got an ICMP packet back from the MESH channel. Pass it on to the |
1688 | * local virtual interface via the helper. | 1688 | * local virtual interface via the helper. |
1689 | * | 1689 | * |
1690 | * @param cls closure, NULL | 1690 | * @param cls closure, NULL |
1691 | * @param tunnel connection to the other end | 1691 | * @param channel connection to the other end |
1692 | * @param tunnel_ctx pointer to our 'struct TunnelState *' | 1692 | * @param channel_ctx pointer to our 'struct ChannelState *' |
1693 | * @param message the actual message | 1693 | * @param message the actual message |
1694 | * @return #GNUNET_OK to keep the connection open, | 1694 | * @return #GNUNET_OK to keep the connection open, |
1695 | * #GNUNET_SYSERR to close it (signal serious error) | 1695 | * #GNUNET_SYSERR to close it (signal serious error) |
1696 | */ | 1696 | */ |
1697 | static int | 1697 | static int |
1698 | receive_icmp_back (void *cls, | 1698 | receive_icmp_back (void *cls, |
1699 | struct GNUNET_MESH_Tunnel *tunnel, | 1699 | struct GNUNET_MESH_Channel *channel, |
1700 | void **tunnel_ctx, | 1700 | void **channel_ctx, |
1701 | const struct GNUNET_MessageHeader *message) | 1701 | const struct GNUNET_MessageHeader *message) |
1702 | { | 1702 | { |
1703 | struct TunnelState *ts = *tunnel_ctx; | 1703 | struct ChannelState *ts = *channel_ctx; |
1704 | const struct GNUNET_EXIT_IcmpToVPNMessage *i2v; | 1704 | const struct GNUNET_EXIT_IcmpToVPNMessage *i2v; |
1705 | size_t mlen; | 1705 | size_t mlen; |
1706 | 1706 | ||
@@ -2015,7 +2015,7 @@ receive_icmp_back (void *cls, | |||
2015 | default: | 2015 | default: |
2016 | GNUNET_assert (0); | 2016 | GNUNET_assert (0); |
2017 | } | 2017 | } |
2018 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, | 2018 | GNUNET_CONTAINER_heap_update_cost (channel_heap, |
2019 | ts->heap_node, | 2019 | ts->heap_node, |
2020 | GNUNET_TIME_absolute_get ().abs_value_us); | 2020 | GNUNET_TIME_absolute_get ().abs_value_us); |
2021 | return GNUNET_OK; | 2021 | return GNUNET_OK; |
@@ -2023,23 +2023,23 @@ receive_icmp_back (void *cls, | |||
2023 | 2023 | ||
2024 | 2024 | ||
2025 | /** | 2025 | /** |
2026 | * We got a UDP packet back from the MESH tunnel. Pass it on to the | 2026 | * We got a UDP packet back from the MESH channel. Pass it on to the |
2027 | * local virtual interface via the helper. | 2027 | * local virtual interface via the helper. |
2028 | * | 2028 | * |
2029 | * @param cls closure, NULL | 2029 | * @param cls closure, NULL |
2030 | * @param tunnel connection to the other end | 2030 | * @param channel connection to the other end |
2031 | * @param tunnel_ctx pointer to our 'struct TunnelState *' | 2031 | * @param channel_ctx pointer to our 'struct ChannelState *' |
2032 | * @param message the actual message | 2032 | * @param message the actual message |
2033 | * @return #GNUNET_OK to keep the connection open, | 2033 | * @return #GNUNET_OK to keep the connection open, |
2034 | * #GNUNET_SYSERR to close it (signal serious error) | 2034 | * #GNUNET_SYSERR to close it (signal serious error) |
2035 | */ | 2035 | */ |
2036 | static int | 2036 | static int |
2037 | receive_udp_back (void *cls, | 2037 | receive_udp_back (void *cls, |
2038 | struct GNUNET_MESH_Tunnel *tunnel, | 2038 | struct GNUNET_MESH_Channel *channel, |
2039 | void **tunnel_ctx, | 2039 | void **channel_ctx, |
2040 | const struct GNUNET_MessageHeader *message) | 2040 | const struct GNUNET_MessageHeader *message) |
2041 | { | 2041 | { |
2042 | struct TunnelState *ts = *tunnel_ctx; | 2042 | struct ChannelState *ts = *channel_ctx; |
2043 | const struct GNUNET_EXIT_UdpReplyMessage *reply; | 2043 | const struct GNUNET_EXIT_UdpReplyMessage *reply; |
2044 | size_t mlen; | 2044 | size_t mlen; |
2045 | 2045 | ||
@@ -2170,7 +2170,7 @@ receive_udp_back (void *cls, | |||
2170 | default: | 2170 | default: |
2171 | GNUNET_assert (0); | 2171 | GNUNET_assert (0); |
2172 | } | 2172 | } |
2173 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, | 2173 | GNUNET_CONTAINER_heap_update_cost (channel_heap, |
2174 | ts->heap_node, | 2174 | ts->heap_node, |
2175 | GNUNET_TIME_absolute_get ().abs_value_us); | 2175 | GNUNET_TIME_absolute_get ().abs_value_us); |
2176 | return GNUNET_OK; | 2176 | return GNUNET_OK; |
@@ -2178,23 +2178,23 @@ receive_udp_back (void *cls, | |||
2178 | 2178 | ||
2179 | 2179 | ||
2180 | /** | 2180 | /** |
2181 | * We got a TCP packet back from the MESH tunnel. Pass it on to the | 2181 | * We got a TCP packet back from the MESH channel. Pass it on to the |
2182 | * local virtual interface via the helper. | 2182 | * local virtual interface via the helper. |
2183 | * | 2183 | * |
2184 | * @param cls closure, NULL | 2184 | * @param cls closure, NULL |
2185 | * @param tunnel connection to the other end | 2185 | * @param channel connection to the other end |
2186 | * @param tunnel_ctx pointer to our `struct TunnelState *` | 2186 | * @param channel_ctx pointer to our `struct ChannelState *` |
2187 | * @param message the actual message | 2187 | * @param message the actual message |
2188 | * @return #GNUNET_OK to keep the connection open, | 2188 | * @return #GNUNET_OK to keep the connection open, |
2189 | * #GNUNET_SYSERR to close it (signal serious error) | 2189 | * #GNUNET_SYSERR to close it (signal serious error) |
2190 | */ | 2190 | */ |
2191 | static int | 2191 | static int |
2192 | receive_tcp_back (void *cls, | 2192 | receive_tcp_back (void *cls, |
2193 | struct GNUNET_MESH_Tunnel *tunnel, | 2193 | struct GNUNET_MESH_Channel *channel, |
2194 | void **tunnel_ctx, | 2194 | void **channel_ctx, |
2195 | const struct GNUNET_MessageHeader *message) | 2195 | const struct GNUNET_MessageHeader *message) |
2196 | { | 2196 | { |
2197 | struct TunnelState *ts = *tunnel_ctx; | 2197 | struct ChannelState *ts = *channel_ctx; |
2198 | const struct GNUNET_EXIT_TcpDataMessage *data; | 2198 | const struct GNUNET_EXIT_TcpDataMessage *data; |
2199 | size_t mlen; | 2199 | size_t mlen; |
2200 | 2200 | ||
@@ -2312,7 +2312,7 @@ receive_tcp_back (void *cls, | |||
2312 | } | 2312 | } |
2313 | break; | 2313 | break; |
2314 | } | 2314 | } |
2315 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, | 2315 | GNUNET_CONTAINER_heap_update_cost (channel_heap, |
2316 | ts->heap_node, | 2316 | ts->heap_node, |
2317 | GNUNET_TIME_absolute_get ().abs_value_us); | 2317 | GNUNET_TIME_absolute_get ().abs_value_us); |
2318 | return GNUNET_OK; | 2318 | return GNUNET_OK; |
@@ -2320,7 +2320,7 @@ receive_tcp_back (void *cls, | |||
2320 | 2320 | ||
2321 | 2321 | ||
2322 | /** | 2322 | /** |
2323 | * Allocate an IPv4 address from the range of the tunnel | 2323 | * Allocate an IPv4 address from the range of the channel |
2324 | * for a new redirection. | 2324 | * for a new redirection. |
2325 | * | 2325 | * |
2326 | * @param v4 where to store the address | 2326 | * @param v4 where to store the address |
@@ -2371,7 +2371,7 @@ allocate_v4_address (struct in_addr *v4) | |||
2371 | 2371 | ||
2372 | 2372 | ||
2373 | /** | 2373 | /** |
2374 | * Allocate an IPv6 address from the range of the tunnel | 2374 | * Allocate an IPv6 address from the range of the channel |
2375 | * for a new redirection. | 2375 | * for a new redirection. |
2376 | * | 2376 | * |
2377 | * @param v6 where to store the address | 2377 | * @param v6 where to store the address |
@@ -2441,7 +2441,7 @@ allocate_v6_address (struct in6_addr *v6) | |||
2441 | static void | 2441 | static void |
2442 | free_destination_entry (struct DestinationEntry *de) | 2442 | free_destination_entry (struct DestinationEntry *de) |
2443 | { | 2443 | { |
2444 | struct DestinationTunnel *dt; | 2444 | struct DestinationChannel *dt; |
2445 | 2445 | ||
2446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2447 | "Cleaning up destination entry\n"); | 2447 | "Cleaning up destination entry\n"); |
@@ -2452,7 +2452,7 @@ free_destination_entry (struct DestinationEntry *de) | |||
2452 | { | 2452 | { |
2453 | if (NULL != dt->ts) | 2453 | if (NULL != dt->ts) |
2454 | { | 2454 | { |
2455 | free_tunnel_state (dt->ts); | 2455 | free_channel_state (dt->ts); |
2456 | GNUNET_assert (NULL == dt->ts); | 2456 | GNUNET_assert (NULL == dt->ts); |
2457 | } | 2457 | } |
2458 | GNUNET_CONTAINER_DLL_remove (de->dt_head, | 2458 | GNUNET_CONTAINER_DLL_remove (de->dt_head, |
@@ -2691,8 +2691,8 @@ service_redirect_to_service (void *cls, | |||
2691 | void *addr; | 2691 | void *addr; |
2692 | struct DestinationEntry *de; | 2692 | struct DestinationEntry *de; |
2693 | struct GNUNET_HashCode key; | 2693 | struct GNUNET_HashCode key; |
2694 | struct TunnelState *ts; | 2694 | struct ChannelState *ts; |
2695 | struct DestinationTunnel *dt; | 2695 | struct DestinationChannel *dt; |
2696 | 2696 | ||
2697 | /* parse request */ | 2697 | /* parse request */ |
2698 | msg = (const struct RedirectToServiceRequestMessage *) message; | 2698 | msg = (const struct RedirectToServiceRequestMessage *) message; |
@@ -2749,12 +2749,12 @@ service_redirect_to_service (void *cls, | |||
2749 | while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) | 2749 | while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) |
2750 | expire_destination (de); | 2750 | expire_destination (de); |
2751 | 2751 | ||
2752 | dt = GNUNET_new (struct DestinationTunnel); | 2752 | dt = GNUNET_new (struct DestinationChannel); |
2753 | dt->destination = de; | 2753 | dt->destination = de; |
2754 | GNUNET_CONTAINER_DLL_insert (de->dt_head, | 2754 | GNUNET_CONTAINER_DLL_insert (de->dt_head, |
2755 | de->dt_tail, | 2755 | de->dt_tail, |
2756 | dt); | 2756 | dt); |
2757 | ts = create_tunnel_to_destination (dt, | 2757 | ts = create_channel_to_destination (dt, |
2758 | result_af); | 2758 | result_af); |
2759 | switch (result_af) | 2759 | switch (result_af) |
2760 | { | 2760 | { |
@@ -2773,23 +2773,23 @@ service_redirect_to_service (void *cls, | |||
2773 | 2773 | ||
2774 | 2774 | ||
2775 | /** | 2775 | /** |
2776 | * Function called whenever a tunnel is destroyed. Should clean up | 2776 | * Function called whenever a channel is destroyed. Should clean up |
2777 | * any associated state. | 2777 | * any associated state. |
2778 | * | 2778 | * |
2779 | * @param cls closure (set from #GNUNET_MESH_connect) | 2779 | * @param cls closure (set from #GNUNET_MESH_connect) |
2780 | * @param tunnel connection to the other end (henceforth invalid) | 2780 | * @param channel connection to the other end (henceforth invalid) |
2781 | * @param tunnel_ctx place where local state associated | 2781 | * @param channel_ctx place where local state associated |
2782 | * with the tunnel is stored (our `struct TunnelState`) | 2782 | * with the channel is stored (our `struct ChannelState`) |
2783 | */ | 2783 | */ |
2784 | static void | 2784 | static void |
2785 | tunnel_cleaner (void *cls, | 2785 | channel_cleaner (void *cls, |
2786 | const struct GNUNET_MESH_Tunnel *tunnel, | 2786 | const struct GNUNET_MESH_Channel *channel, |
2787 | void *tunnel_ctx) | 2787 | void *channel_ctx) |
2788 | { | 2788 | { |
2789 | struct TunnelState *ts = tunnel_ctx; | 2789 | struct ChannelState *ts = channel_ctx; |
2790 | 2790 | ||
2791 | ts->tunnel = NULL; /* we must not call GNUNET_MESH_tunnel_destroy() anymore */ | 2791 | ts->channel = NULL; /* we must not call GNUNET_MESH_channel_destroy() anymore */ |
2792 | free_tunnel_state (ts); | 2792 | free_channel_state (ts); |
2793 | } | 2793 | } |
2794 | 2794 | ||
2795 | 2795 | ||
@@ -2814,21 +2814,21 @@ cleanup_destination (void *cls, | |||
2814 | 2814 | ||
2815 | 2815 | ||
2816 | /** | 2816 | /** |
2817 | * Free memory occupied by an entry in the tunnel map. | 2817 | * Free memory occupied by an entry in the channel map. |
2818 | * | 2818 | * |
2819 | * @param cls unused | 2819 | * @param cls unused |
2820 | * @param key unused | 2820 | * @param key unused |
2821 | * @param value a `struct TunnelState *` | 2821 | * @param value a `struct ChannelState *` |
2822 | * @return #GNUNET_OK (continue to iterate) | 2822 | * @return #GNUNET_OK (continue to iterate) |
2823 | */ | 2823 | */ |
2824 | static int | 2824 | static int |
2825 | cleanup_tunnel (void *cls, | 2825 | cleanup_channel (void *cls, |
2826 | const struct GNUNET_HashCode *key, | 2826 | const struct GNUNET_HashCode *key, |
2827 | void *value) | 2827 | void *value) |
2828 | { | 2828 | { |
2829 | struct TunnelState *ts = value; | 2829 | struct ChannelState *ts = value; |
2830 | 2830 | ||
2831 | free_tunnel_state (ts); | 2831 | free_channel_state (ts); |
2832 | return GNUNET_OK; | 2832 | return GNUNET_OK; |
2833 | } | 2833 | } |
2834 | 2834 | ||
@@ -2860,18 +2860,18 @@ cleanup (void *cls, | |||
2860 | GNUNET_CONTAINER_heap_destroy (destination_heap); | 2860 | GNUNET_CONTAINER_heap_destroy (destination_heap); |
2861 | destination_heap = NULL; | 2861 | destination_heap = NULL; |
2862 | } | 2862 | } |
2863 | if (NULL != tunnel_map) | 2863 | if (NULL != channel_map) |
2864 | { | 2864 | { |
2865 | GNUNET_CONTAINER_multihashmap_iterate (tunnel_map, | 2865 | GNUNET_CONTAINER_multihashmap_iterate (channel_map, |
2866 | &cleanup_tunnel, | 2866 | &cleanup_channel, |
2867 | NULL); | 2867 | NULL); |
2868 | GNUNET_CONTAINER_multihashmap_destroy (tunnel_map); | 2868 | GNUNET_CONTAINER_multihashmap_destroy (channel_map); |
2869 | tunnel_map = NULL; | 2869 | channel_map = NULL; |
2870 | } | 2870 | } |
2871 | if (NULL != tunnel_heap) | 2871 | if (NULL != channel_heap) |
2872 | { | 2872 | { |
2873 | GNUNET_CONTAINER_heap_destroy (tunnel_heap); | 2873 | GNUNET_CONTAINER_heap_destroy (channel_heap); |
2874 | tunnel_heap = NULL; | 2874 | channel_heap = NULL; |
2875 | } | 2875 | } |
2876 | if (NULL != mesh_handle) | 2876 | if (NULL != mesh_handle) |
2877 | { | 2877 | { |
@@ -2954,13 +2954,13 @@ run (void *cls, | |||
2954 | max_destination_mappings = 200; | 2954 | max_destination_mappings = 200; |
2955 | if (GNUNET_OK != | 2955 | if (GNUNET_OK != |
2956 | GNUNET_CONFIGURATION_get_value_number (cfg, "VPN", "MAX_TUNNELS", | 2956 | GNUNET_CONFIGURATION_get_value_number (cfg, "VPN", "MAX_TUNNELS", |
2957 | &max_tunnel_mappings)) | 2957 | &max_channel_mappings)) |
2958 | max_tunnel_mappings = 200; | 2958 | max_channel_mappings = 200; |
2959 | 2959 | ||
2960 | destination_map = GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2, GNUNET_NO); | 2960 | destination_map = GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2, GNUNET_NO); |
2961 | destination_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2961 | destination_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2962 | tunnel_map = GNUNET_CONTAINER_multihashmap_create (max_tunnel_mappings * 2, GNUNET_NO); | 2962 | channel_map = GNUNET_CONTAINER_multihashmap_create (max_channel_mappings * 2, GNUNET_NO); |
2963 | tunnel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2963 | channel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2964 | 2964 | ||
2965 | 2965 | ||
2966 | vpn_argv[0] = GNUNET_strdup ("vpn-gnunet"); | 2966 | vpn_argv[0] = GNUNET_strdup ("vpn-gnunet"); |
@@ -3058,7 +3058,7 @@ run (void *cls, | |||
3058 | mesh_handle = | 3058 | mesh_handle = |
3059 | GNUNET_MESH_connect (cfg_, NULL, | 3059 | GNUNET_MESH_connect (cfg_, NULL, |
3060 | NULL, | 3060 | NULL, |
3061 | &tunnel_cleaner, | 3061 | &channel_cleaner, |
3062 | mesh_handlers, | 3062 | mesh_handlers, |
3063 | NULL); | 3063 | NULL); |
3064 | helper_handle = GNUNET_HELPER_start (GNUNET_NO, | 3064 | helper_handle = GNUNET_HELPER_start (GNUNET_NO, |