diff options
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 905 |
1 files changed, 392 insertions, 513 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index c0a7852e0..a5113e52b 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -342,7 +342,7 @@ struct MeshPathInfo | |||
342 | * Path itself | 342 | * Path itself |
343 | */ | 343 | */ |
344 | struct MeshPeerPath *path; | 344 | struct MeshPeerPath *path; |
345 | 345 | ||
346 | /** | 346 | /** |
347 | * Position in peer's transmit queue | 347 | * Position in peer's transmit queue |
348 | */ | 348 | */ |
@@ -479,7 +479,7 @@ static struct GNUNET_PeerIdentity my_full_id; | |||
479 | /** | 479 | /** |
480 | * Own private key | 480 | * Own private key |
481 | */ | 481 | */ |
482 | static struct GNUNET_CRYPTO_RsaPrivateKey* my_private_key; | 482 | static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; |
483 | 483 | ||
484 | /** | 484 | /** |
485 | * Own public key. | 485 | * Own public key. |
@@ -546,12 +546,9 @@ static int | |||
546 | announce_application (void *cls, const GNUNET_HashCode * key, void *value) | 546 | announce_application (void *cls, const GNUNET_HashCode * key, void *value) |
547 | { | 547 | { |
548 | /* FIXME are hashes in multihash map equal on all aquitectures? */ | 548 | /* FIXME are hashes in multihash map equal on all aquitectures? */ |
549 | GNUNET_DHT_put (dht_handle, | 549 | GNUNET_DHT_put (dht_handle, key, 10U, |
550 | key, | ||
551 | 10U, | ||
552 | GNUNET_DHT_RO_RECORD_ROUTE | | 550 | GNUNET_DHT_RO_RECORD_ROUTE | |
553 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 551 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_BLOCK_TYPE_TEST, |
554 | GNUNET_BLOCK_TYPE_TEST, | ||
555 | sizeof (struct GNUNET_PeerIdentity), | 552 | sizeof (struct GNUNET_PeerIdentity), |
556 | (const char *) &my_full_id, | 553 | (const char *) &my_full_id, |
557 | #if MESH_DEBUG | 554 | #if MESH_DEBUG |
@@ -620,11 +617,10 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
620 | GNUNET_DHT_put (dht_handle, /* DHT handle */ | 617 | GNUNET_DHT_put (dht_handle, /* DHT handle */ |
621 | &my_full_id.hashPubKey, /* Key to use */ | 618 | &my_full_id.hashPubKey, /* Key to use */ |
622 | 10U, /* Replication level */ | 619 | 10U, /* Replication level */ |
623 | GNUNET_DHT_RO_RECORD_ROUTE | | 620 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ |
624 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ | ||
625 | GNUNET_BLOCK_TYPE_TEST, /* Block type */ | 621 | GNUNET_BLOCK_TYPE_TEST, /* Block type */ |
626 | sizeof(my_full_id), /* Size of the data */ | 622 | sizeof (my_full_id), /* Size of the data */ |
627 | (char *)&my_full_id, /* Data itself */ | 623 | (char *) &my_full_id, /* Data itself */ |
628 | GNUNET_TIME_absolute_get_forever (), /* Data expiration */ | 624 | GNUNET_TIME_absolute_get_forever (), /* Data expiration */ |
629 | GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ | 625 | GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ |
630 | #if MESH_DEBUG_DHT | 626 | #if MESH_DEBUG_DHT |
@@ -656,8 +652,8 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
656 | const struct GNUNET_PeerIdentity *get_path, | 652 | const struct GNUNET_PeerIdentity *get_path, |
657 | unsigned int get_path_length, | 653 | unsigned int get_path_length, |
658 | const struct GNUNET_PeerIdentity *put_path, | 654 | const struct GNUNET_PeerIdentity *put_path, |
659 | unsigned int put_path_length, | 655 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
660 | enum GNUNET_BLOCK_Type type, size_t size, const void *data); | 656 | size_t size, const void *data); |
661 | 657 | ||
662 | 658 | ||
663 | /******************************************************************************/ | 659 | /******************************************************************************/ |
@@ -711,12 +707,12 @@ client_is_subscribed (uint16_t message_type, struct MeshClient *c) | |||
711 | * Allow a client to send more data after transmitting a multicast message | 707 | * Allow a client to send more data after transmitting a multicast message |
712 | * which some neighbor has not yet accepted altough a reasonable time has | 708 | * which some neighbor has not yet accepted altough a reasonable time has |
713 | * passed. | 709 | * passed. |
714 | * | 710 | * |
715 | * @param cls Closure (DataDescriptor containing the task identifier) | 711 | * @param cls Closure (DataDescriptor containing the task identifier) |
716 | * @param tc Task Context | 712 | * @param tc Task Context |
717 | */ | 713 | */ |
718 | static void | 714 | static void |
719 | client_allow_send(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 715 | client_allow_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
720 | { | 716 | { |
721 | struct MeshDataDescriptor *info = cls; | 717 | struct MeshDataDescriptor *info = cls; |
722 | 718 | ||
@@ -728,7 +724,7 @@ client_allow_send(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
728 | *(info->copies)); | 724 | *(info->copies)); |
729 | #endif | 725 | #endif |
730 | *(info->timeout_task) = GNUNET_SCHEDULER_NO_TASK; | 726 | *(info->timeout_task) = GNUNET_SCHEDULER_NO_TASK; |
731 | GNUNET_SERVER_receive_done(info->client, GNUNET_OK); | 727 | GNUNET_SERVER_receive_done (info->client, GNUNET_OK); |
732 | } | 728 | } |
733 | 729 | ||
734 | 730 | ||
@@ -756,8 +752,7 @@ tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid); | |||
756 | * 0 if the tunnel remained unaffected. | 752 | * 0 if the tunnel remained unaffected. |
757 | */ | 753 | */ |
758 | static GNUNET_PEER_Id | 754 | static GNUNET_PEER_Id |
759 | tunnel_notify_connection_broken (struct MeshTunnel *t, | 755 | tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1, |
760 | GNUNET_PEER_Id p1, | ||
761 | GNUNET_PEER_Id p2); | 756 | GNUNET_PEER_Id p2); |
762 | 757 | ||
763 | 758 | ||
@@ -777,39 +772,39 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg, | |||
777 | MESH_TunnelNumber *tid; | 772 | MESH_TunnelNumber *tid; |
778 | unsigned int count; | 773 | unsigned int count; |
779 | uint16_t type; | 774 | uint16_t type; |
780 | char cbuf[htons(msg->size)]; | 775 | char cbuf[htons (msg->size)]; |
781 | 776 | ||
782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Sending to clients...\n"); | 777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Sending to clients...\n"); |
783 | type = ntohs (payload->type); | 778 | type = ntohs (payload->type); |
784 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message of type %u\n", type); | 779 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message of type %u\n", type); |
785 | 780 | ||
786 | memcpy (cbuf, msg, sizeof(cbuf)); | 781 | memcpy (cbuf, msg, sizeof (cbuf)); |
787 | switch (htons(msg->type)) | 782 | switch (htons (msg->type)) |
788 | { | 783 | { |
789 | struct GNUNET_MESH_Unicast *uc; | 784 | struct GNUNET_MESH_Unicast *uc; |
790 | struct GNUNET_MESH_Multicast *mc; | 785 | struct GNUNET_MESH_Multicast *mc; |
791 | struct GNUNET_MESH_ToOrigin *to; | 786 | struct GNUNET_MESH_ToOrigin *to; |
792 | 787 | ||
793 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | 788 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: |
794 | uc = (struct GNUNET_MESH_Unicast *) cbuf; | 789 | uc = (struct GNUNET_MESH_Unicast *) cbuf; |
795 | tid = &uc->tid; | 790 | tid = &uc->tid; |
796 | oid = &uc->oid; | 791 | oid = &uc->oid; |
797 | break; | 792 | break; |
798 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: | 793 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: |
799 | mc = (struct GNUNET_MESH_Multicast *) cbuf; | 794 | mc = (struct GNUNET_MESH_Multicast *) cbuf; |
800 | tid = &mc->tid; | 795 | tid = &mc->tid; |
801 | oid = &mc->oid; | 796 | oid = &mc->oid; |
802 | break; | 797 | break; |
803 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | 798 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: |
804 | to = (struct GNUNET_MESH_ToOrigin *) cbuf; | 799 | to = (struct GNUNET_MESH_ToOrigin *) cbuf; |
805 | tid = &to->tid; | 800 | tid = &to->tid; |
806 | oid = &to->oid; | 801 | oid = &to->oid; |
807 | break; | 802 | break; |
808 | default: | 803 | default: |
809 | GNUNET_break (0); | 804 | GNUNET_break (0); |
810 | return 0; | 805 | return 0; |
811 | } | 806 | } |
812 | t = tunnel_get (oid, ntohl(*tid)); | 807 | t = tunnel_get (oid, ntohl (*tid)); |
813 | if (NULL == t) | 808 | if (NULL == t) |
814 | { | 809 | { |
815 | GNUNET_break (0); | 810 | GNUNET_break (0); |
@@ -823,11 +818,9 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg, | |||
823 | { | 818 | { |
824 | count++; | 819 | count++; |
825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending\n"); | 820 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending\n"); |
826 | GNUNET_SERVER_notification_context_unicast ( | 821 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, |
827 | nc, | 822 | (struct GNUNET_MessageHeader |
828 | c->handle, | 823 | *) cbuf, GNUNET_YES); |
829 | (struct GNUNET_MessageHeader *) cbuf, | ||
830 | GNUNET_YES); | ||
831 | } | 824 | } |
832 | } | 825 | } |
833 | return count; | 826 | return count; |
@@ -837,7 +830,7 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg, | |||
837 | /** | 830 | /** |
838 | * Notify the client that owns the tunnel that a peer has connected to it | 831 | * Notify the client that owns the tunnel that a peer has connected to it |
839 | * (the requested path to it has been confirmed). | 832 | * (the requested path to it has been confirmed). |
840 | * | 833 | * |
841 | * @param t Tunnel whose owner to notify | 834 | * @param t Tunnel whose owner to notify |
842 | * @param id Short id of the peer that has connected | 835 | * @param id Short id of the peer that has connected |
843 | */ | 836 | */ |
@@ -850,26 +843,26 @@ send_client_peer_connected (const struct MeshTunnel *t, const GNUNET_PEER_Id id) | |||
850 | pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); | 843 | pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); |
851 | pc.tunnel_id = htonl (t->local_tid); | 844 | pc.tunnel_id = htonl (t->local_tid); |
852 | GNUNET_PEER_resolve (id, &pc.peer); | 845 | GNUNET_PEER_resolve (id, &pc.peer); |
853 | GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, | 846 | GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, &pc.header, |
854 | &pc.header, GNUNET_NO); | 847 | GNUNET_NO); |
855 | } | 848 | } |
856 | 849 | ||
857 | 850 | ||
858 | /** | 851 | /** |
859 | * Notify all clients (not depending on registration status) that the incoming | 852 | * Notify all clients (not depending on registration status) that the incoming |
860 | * tunnel is no longer valid. | 853 | * tunnel is no longer valid. |
861 | * | 854 | * |
862 | * @param t Tunnel that was destroyed. | 855 | * @param t Tunnel that was destroyed. |
863 | */ | 856 | */ |
864 | static void | 857 | static void |
865 | send_clients_tunnel_destroy (struct MeshTunnel *t) | 858 | send_clients_tunnel_destroy (struct MeshTunnel *t) |
866 | { | 859 | { |
867 | struct GNUNET_MESH_TunnelMessage msg; | 860 | struct GNUNET_MESH_TunnelMessage msg; |
868 | 861 | ||
869 | msg.header.size = htons (sizeof (msg)); | 862 | msg.header.size = htons (sizeof (msg)); |
870 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); | 863 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); |
871 | msg.tunnel_id = htonl (t->local_tid); | 864 | msg.tunnel_id = htonl (t->local_tid); |
872 | GNUNET_SERVER_notification_context_broadcast(nc, &msg.header, GNUNET_NO); | 865 | GNUNET_SERVER_notification_context_broadcast (nc, &msg.header, GNUNET_NO); |
873 | } | 866 | } |
874 | 867 | ||
875 | 868 | ||
@@ -906,7 +899,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf); | |||
906 | 899 | ||
907 | /** | 900 | /** |
908 | * Decrements the reference counter and frees all resources if needed | 901 | * Decrements the reference counter and frees all resources if needed |
909 | * | 902 | * |
910 | * @param dd Data Descriptor used in a multicast message | 903 | * @param dd Data Descriptor used in a multicast message |
911 | */ | 904 | */ |
912 | static void | 905 | static void |
@@ -922,7 +915,7 @@ data_descriptor_decrement_multicast (struct MeshDataDescriptor *dd) | |||
922 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
923 | "MESH: cancelling client timeout (%u)...\n", | 916 | "MESH: cancelling client timeout (%u)...\n", |
924 | *(dd->timeout_task)); | 917 | *(dd->timeout_task)); |
925 | GNUNET_SCHEDULER_cancel(*(dd->timeout_task)); | 918 | GNUNET_SCHEDULER_cancel (*(dd->timeout_task)); |
926 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client...\n"); | 919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client...\n"); |
927 | GNUNET_SERVER_receive_done (dd->client, GNUNET_OK); | 920 | GNUNET_SERVER_receive_done (dd->client, GNUNET_OK); |
928 | } | 921 | } |
@@ -937,12 +930,12 @@ data_descriptor_decrement_multicast (struct MeshDataDescriptor *dd) | |||
937 | /** | 930 | /** |
938 | * Cancel a core transmission that was already requested and free all resources | 931 | * Cancel a core transmission that was already requested and free all resources |
939 | * associated to the request. | 932 | * associated to the request. |
940 | * | 933 | * |
941 | * @param peer PeeInfo of the peer whose transmission is cancelled. | 934 | * @param peer PeeInfo of the peer whose transmission is cancelled. |
942 | * @param i Position of the transmission to be cancelled. | 935 | * @param i Position of the transmission to be cancelled. |
943 | */ | 936 | */ |
944 | static void | 937 | static void |
945 | peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i) | 938 | peer_info_cancel_transmission (struct MeshPeerInfo *peer, unsigned int i) |
946 | { | 939 | { |
947 | if (NULL != peer->core_transmit[i]) | 940 | if (NULL != peer->core_transmit[i]) |
948 | { | 941 | { |
@@ -956,36 +949,34 @@ peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i) | |||
956 | GNUNET_PEER_resolve (peer->id, &id); | 949 | GNUNET_PEER_resolve (peer->id, &id); |
957 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
958 | "MESH: Cancelling data transmission at %s [%u]\n", | 951 | "MESH: Cancelling data transmission at %s [%u]\n", |
959 | GNUNET_i2s (&id), | 952 | GNUNET_i2s (&id), i); |
960 | i); | 953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: message type %u\n", |
961 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
962 | "MESH: message type %u\n", | ||
963 | peer->types[i]); | 954 | peer->types[i]); |
964 | } | 955 | } |
965 | #endif | 956 | #endif |
966 | /* TODO: notify that tranmission has failed */ | 957 | /* TODO: notify that tranmission has failed */ |
967 | switch (peer->types[i]) | 958 | switch (peer->types[i]) |
968 | { | 959 | { |
969 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: | 960 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: |
970 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | 961 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: |
971 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | 962 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: |
972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n"); | 963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type payload\n"); |
973 | dd = peer->infos[i]; | 964 | dd = peer->infos[i]; |
974 | data_descriptor_decrement_multicast (dd); | 965 | data_descriptor_decrement_multicast (dd); |
975 | break; | 966 | break; |
976 | case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: | 967 | case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: |
977 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n"); | 968 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type create path\n"); |
978 | path_info = peer->infos[i]; | 969 | path_info = peer->infos[i]; |
979 | path_destroy(path_info->path); | 970 | path_destroy (path_info->path); |
980 | break; | 971 | break; |
981 | default: | 972 | default: |
982 | GNUNET_break (0); | 973 | GNUNET_break (0); |
983 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n"); | 974 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type unknown!\n"); |
984 | } | 975 | } |
985 | GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit[i]); | 976 | GNUNET_CORE_notify_transmit_ready_cancel (peer->core_transmit[i]); |
986 | peer->core_transmit[i] = NULL; | 977 | peer->core_transmit[i] = NULL; |
987 | GNUNET_free (peer->infos[i]); | 978 | GNUNET_free (peer->infos[i]); |
988 | } | 979 | } |
989 | } | 980 | } |
990 | 981 | ||
991 | 982 | ||
@@ -1008,7 +999,7 @@ peer_info_transmit_slot (struct MeshPeerInfo *peer) | |||
1008 | { | 999 | { |
1009 | /* All positions are taken! Overwriting! */ | 1000 | /* All positions are taken! Overwriting! */ |
1010 | GNUNET_break (0); | 1001 | GNUNET_break (0); |
1011 | peer_info_cancel_transmission(peer, 0); | 1002 | peer_info_cancel_transmission (peer, 0); |
1012 | return 0; | 1003 | return 0; |
1013 | } | 1004 | } |
1014 | } | 1005 | } |
@@ -1056,8 +1047,8 @@ peer_info_get_short (const GNUNET_PEER_Id peer) | |||
1056 | { | 1047 | { |
1057 | struct GNUNET_PeerIdentity id; | 1048 | struct GNUNET_PeerIdentity id; |
1058 | 1049 | ||
1059 | GNUNET_PEER_resolve(peer, &id); | 1050 | GNUNET_PEER_resolve (peer, &id); |
1060 | return peer_info_get(&id); | 1051 | return peer_info_get (&id); |
1061 | } | 1052 | } |
1062 | 1053 | ||
1063 | 1054 | ||
@@ -1072,7 +1063,7 @@ peer_info_get_short (const GNUNET_PEER_Id peer) | |||
1072 | * @return always GNUNET_YES, to keep iterating | 1063 | * @return always GNUNET_YES, to keep iterating |
1073 | */ | 1064 | */ |
1074 | static int | 1065 | static int |
1075 | peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value) | 1066 | peer_info_delete_tunnel (void *cls, const GNUNET_HashCode * key, void *value) |
1076 | { | 1067 | { |
1077 | struct MeshTunnel *t = cls; | 1068 | struct MeshTunnel *t = cls; |
1078 | struct MeshPeerInfo *peer = value; | 1069 | struct MeshPeerInfo *peer = value; |
@@ -1080,9 +1071,8 @@ peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value) | |||
1080 | 1071 | ||
1081 | for (i = 0; i < peer->ntunnels; i++) | 1072 | for (i = 0; i < peer->ntunnels; i++) |
1082 | { | 1073 | { |
1083 | if (0 == memcmp(&peer->tunnels[i]->id, | 1074 | if (0 == |
1084 | &t->id, | 1075 | memcmp (&peer->tunnels[i]->id, &t->id, sizeof (struct MESH_TunnelID))) |
1085 | sizeof(struct MESH_TunnelID))) | ||
1086 | { | 1076 | { |
1087 | peer->ntunnels--; | 1077 | peer->ntunnels--; |
1088 | peer->tunnels[i] = peer->tunnels[peer->ntunnels]; | 1078 | peer->tunnels[i] = peer->tunnels[peer->ntunnels]; |
@@ -1095,12 +1085,12 @@ peer_info_delete_tunnel (void* cls, const GNUNET_HashCode* key, void* value) | |||
1095 | 1085 | ||
1096 | 1086 | ||
1097 | /** | 1087 | /** |
1098 | * Core callback to write a | 1088 | * Core callback to write a |
1099 | * | 1089 | * |
1100 | * @param cls Closure (MeshDataDescriptor with data in "data" member). | 1090 | * @param cls Closure (MeshDataDescriptor with data in "data" member). |
1101 | * @param size Number of bytes available in buf. | 1091 | * @param size Number of bytes available in buf. |
1102 | * @param buf Where the to write the message. | 1092 | * @param buf Where the to write the message. |
1103 | * | 1093 | * |
1104 | * @return number of bytes written to buf | 1094 | * @return number of bytes written to buf |
1105 | */ | 1095 | */ |
1106 | static size_t | 1096 | static size_t |
@@ -1121,15 +1111,10 @@ send_core_data_raw (void *cls, size_t size, void *buf) | |||
1121 | 1111 | ||
1122 | GNUNET_PEER_resolve (info->peer->id, &id); | 1112 | GNUNET_PEER_resolve (info->peer->id, &id); |
1123 | info->peer->core_transmit[info->handler_n] = | 1113 | info->peer->core_transmit[info->handler_n] = |
1124 | GNUNET_CORE_notify_transmit_ready(core_handle, | 1114 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100, |
1125 | 0, | 1115 | GNUNET_TIME_UNIT_FOREVER_REL, &id, |
1126 | 100, | 1116 | size, &send_core_data_raw, info); |
1127 | GNUNET_TIME_UNIT_FOREVER_REL, | 1117 | return 0; |
1128 | &id, | ||
1129 | size, | ||
1130 | &send_core_data_raw, | ||
1131 | info); | ||
1132 | return 0; | ||
1133 | } | 1118 | } |
1134 | info->peer->core_transmit[info->handler_n] = NULL; | 1119 | info->peer->core_transmit[info->handler_n] = NULL; |
1135 | memcpy (buf, msg, total_size); | 1120 | memcpy (buf, msg, total_size); |
@@ -1181,14 +1166,9 @@ send_message (const struct GNUNET_MessageHeader *message, | |||
1181 | neighbor->types[i] = GNUNET_MESSAGE_TYPE_MESH_UNICAST; | 1166 | neighbor->types[i] = GNUNET_MESSAGE_TYPE_MESH_UNICAST; |
1182 | neighbor->infos[i] = info; | 1167 | neighbor->infos[i] = info; |
1183 | neighbor->core_transmit[i] = | 1168 | neighbor->core_transmit[i] = |
1184 | GNUNET_CORE_notify_transmit_ready(core_handle, | 1169 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100, |
1185 | 0, | 1170 | GNUNET_TIME_UNIT_FOREVER_REL, peer, |
1186 | 100, | 1171 | size, &send_core_data_raw, info); |
1187 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1188 | peer, | ||
1189 | size, | ||
1190 | &send_core_data_raw, | ||
1191 | info); | ||
1192 | 1172 | ||
1193 | } | 1173 | } |
1194 | 1174 | ||
@@ -1196,14 +1176,13 @@ send_message (const struct GNUNET_MessageHeader *message, | |||
1196 | /** | 1176 | /** |
1197 | * Sends a CREATE PATH message for a path to a peer, properly registrating | 1177 | * Sends a CREATE PATH message for a path to a peer, properly registrating |
1198 | * all used resources. | 1178 | * all used resources. |
1199 | * | 1179 | * |
1200 | * @param peer PeerInfo of the final peer for whom this path is being created. | 1180 | * @param peer PeerInfo of the final peer for whom this path is being created. |
1201 | * @param p Path itself. | 1181 | * @param p Path itself. |
1202 | * @param t Tunnel for which the path is created. | 1182 | * @param t Tunnel for which the path is created. |
1203 | */ | 1183 | */ |
1204 | static void | 1184 | static void |
1205 | send_create_path (struct MeshPeerInfo *peer, | 1185 | send_create_path (struct MeshPeerInfo *peer, struct MeshPeerPath *p, |
1206 | struct MeshPeerPath *p, | ||
1207 | struct MeshTunnel *t) | 1186 | struct MeshTunnel *t) |
1208 | { | 1187 | { |
1209 | struct GNUNET_PeerIdentity id; | 1188 | struct GNUNET_PeerIdentity id; |
@@ -1213,7 +1192,7 @@ send_create_path (struct MeshPeerInfo *peer, | |||
1213 | 1192 | ||
1214 | if (NULL == p) | 1193 | if (NULL == p) |
1215 | { | 1194 | { |
1216 | p = tree_get_path_to_peer(t->tree, peer->id); | 1195 | p = tree_get_path_to_peer (t->tree, peer->id); |
1217 | if (NULL == p) | 1196 | if (NULL == p) |
1218 | { | 1197 | { |
1219 | GNUNET_break (0); | 1198 | GNUNET_break (0); |
@@ -1227,37 +1206,34 @@ send_create_path (struct MeshPeerInfo *peer, | |||
1227 | } | 1206 | } |
1228 | if (i >= p->length - 1) | 1207 | if (i >= p->length - 1) |
1229 | { | 1208 | { |
1230 | path_destroy(p); | 1209 | path_destroy (p); |
1231 | GNUNET_break (0); | 1210 | GNUNET_break (0); |
1232 | return; | 1211 | return; |
1233 | } | 1212 | } |
1234 | GNUNET_PEER_resolve(p->peers[i + 1], &id); | 1213 | GNUNET_PEER_resolve (p->peers[i + 1], &id); |
1235 | 1214 | ||
1236 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); | 1215 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); |
1237 | path_info->path = p; | 1216 | path_info->path = p; |
1238 | path_info->t = t; | 1217 | path_info->t = t; |
1239 | neighbor = peer_info_get(&id); | 1218 | neighbor = peer_info_get (&id); |
1240 | path_info->peer = neighbor; | 1219 | path_info->peer = neighbor; |
1241 | path_info->pos = peer_info_transmit_slot(neighbor); | 1220 | path_info->pos = peer_info_transmit_slot (neighbor); |
1242 | neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; | 1221 | neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; |
1243 | neighbor->infos[path_info->pos] = path_info; | 1222 | neighbor->infos[path_info->pos] = path_info; |
1244 | neighbor->core_transmit[path_info->pos] = | 1223 | neighbor->core_transmit[path_info->pos] = GNUNET_CORE_notify_transmit_ready (core_handle, /* handle */ |
1245 | GNUNET_CORE_notify_transmit_ready ( | 1224 | 0, /* cork */ |
1246 | core_handle, /* handle */ | 1225 | 0, /* priority */ |
1247 | 0, /* cork */ | 1226 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
1248 | 0, /* priority */ | 1227 | &id, /* target */ |
1249 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 1228 | sizeof (struct GNUNET_MESH_ManipulatePath) + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */ |
1250 | &id, /* target */ | 1229 | &send_core_create_path, /* callback */ |
1251 | sizeof (struct GNUNET_MESH_ManipulatePath) | 1230 | path_info); /* cls */ |
1252 | + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */ | ||
1253 | &send_core_create_path, /* callback */ | ||
1254 | path_info); /* cls */ | ||
1255 | } | 1231 | } |
1256 | 1232 | ||
1257 | 1233 | ||
1258 | /** | 1234 | /** |
1259 | * Sends a DESTROY PATH message to free resources for a path in a tunnel | 1235 | * Sends a DESTROY PATH message to free resources for a path in a tunnel |
1260 | * | 1236 | * |
1261 | * @param t Tunnel whose path to destroy. | 1237 | * @param t Tunnel whose path to destroy. |
1262 | * @param destination Short ID of the peer to whom the path to destroy. | 1238 | * @param destination Short ID of the peer to whom the path to destroy. |
1263 | */ | 1239 | */ |
@@ -1267,7 +1243,7 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination) | |||
1267 | struct MeshPeerPath *p; | 1243 | struct MeshPeerPath *p; |
1268 | size_t size; | 1244 | size_t size; |
1269 | 1245 | ||
1270 | p = tree_get_path_to_peer(t->tree, destination); | 1246 | p = tree_get_path_to_peer (t->tree, destination); |
1271 | if (NULL == p) | 1247 | if (NULL == p) |
1272 | { | 1248 | { |
1273 | GNUNET_break (0); | 1249 | GNUNET_break (0); |
@@ -1288,9 +1264,9 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination) | |||
1288 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | 1264 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; |
1289 | for (i = 0; i < p->length; i++) | 1265 | for (i = 0; i < p->length; i++) |
1290 | { | 1266 | { |
1291 | GNUNET_PEER_resolve(p->peers[i], &pi[i]); | 1267 | GNUNET_PEER_resolve (p->peers[i], &pi[i]); |
1292 | } | 1268 | } |
1293 | send_message (&msg->header, path_get_first_hop(t->tree, destination)); | 1269 | send_message (&msg->header, path_get_first_hop (t->tree, destination)); |
1294 | } | 1270 | } |
1295 | path_destroy (p); | 1271 | path_destroy (p); |
1296 | } | 1272 | } |
@@ -1299,7 +1275,7 @@ send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination) | |||
1299 | /** | 1275 | /** |
1300 | * Try to establish a new connection to this peer. | 1276 | * Try to establish a new connection to this peer. |
1301 | * Use the best path for the given tunnel. | 1277 | * Use the best path for the given tunnel. |
1302 | * If the peer doesn't have any path to it yet, try to get one. | 1278 | * If the peer doesn't have any path to it yet, try to get one. |
1303 | * If the peer already has some path, send a CREATE PATH towards it. | 1279 | * If the peer already has some path, send a CREATE PATH towards it. |
1304 | * | 1280 | * |
1305 | * @param peer PeerInfo of the peer. | 1281 | * @param peer PeerInfo of the peer. |
@@ -1313,7 +1289,7 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t) | |||
1313 | 1289 | ||
1314 | if (NULL != peer->path_head) | 1290 | if (NULL != peer->path_head) |
1315 | { | 1291 | { |
1316 | p = tree_get_path_to_peer(t->tree, peer->id); | 1292 | p = tree_get_path_to_peer (t->tree, peer->id); |
1317 | if (NULL == p) | 1293 | if (NULL == p) |
1318 | { | 1294 | { |
1319 | GNUNET_break (0); | 1295 | GNUNET_break (0); |
@@ -1322,38 +1298,33 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t) | |||
1322 | 1298 | ||
1323 | if (p->length > 1) | 1299 | if (p->length > 1) |
1324 | { | 1300 | { |
1325 | send_create_path(peer, p, t); | 1301 | send_create_path (peer, p, t); |
1326 | } | 1302 | } |
1327 | else | 1303 | else |
1328 | { | 1304 | { |
1329 | path_destroy(p); | 1305 | path_destroy (p); |
1330 | send_client_peer_connected(t, myid); | 1306 | send_client_peer_connected (t, myid); |
1331 | } | 1307 | } |
1332 | } | 1308 | } |
1333 | else if (NULL == peer->dhtget) | 1309 | else if (NULL == peer->dhtget) |
1334 | { | 1310 | { |
1335 | struct GNUNET_PeerIdentity id; | 1311 | struct GNUNET_PeerIdentity id; |
1336 | 1312 | ||
1337 | GNUNET_PEER_resolve(peer->id, &id); | 1313 | GNUNET_PEER_resolve (peer->id, &id); |
1338 | path_info = GNUNET_malloc(sizeof(struct MeshPathInfo)); | 1314 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); |
1339 | path_info->peer = peer; | 1315 | path_info->peer = peer; |
1340 | path_info->t = t; | 1316 | path_info->t = t; |
1341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1342 | "MESH: Starting DHT GET for peer %s\n", | 1318 | "MESH: Starting DHT GET for peer %s\n", GNUNET_i2s (&id)); |
1343 | GNUNET_i2s (&id)); | ||
1344 | peer->dhtgetcls = path_info; | 1319 | peer->dhtgetcls = path_info; |
1345 | peer->dhtget = | 1320 | peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ |
1346 | GNUNET_DHT_get_start(dht_handle, /* handle */ | 1321 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
1347 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 1322 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
1348 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 1323 | &id.hashPubKey, /* key to search */ |
1349 | &id.hashPubKey, /* key to search */ | 1324 | 4, /* replication level */ |
1350 | 4, /* replication level */ | 1325 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ |
1351 | GNUNET_DHT_RO_RECORD_ROUTE | | 1326 | 0, /* xquery bits */ |
1352 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 1327 | &dht_get_id_handler, path_info); |
1353 | NULL, /* xquery */ | ||
1354 | 0, /* xquery bits */ | ||
1355 | &dht_get_id_handler, | ||
1356 | path_info); | ||
1357 | } | 1328 | } |
1358 | /* Otherwise, there is no path but the DHT get is already started. */ | 1329 | /* Otherwise, there is no path but the DHT get is already started. */ |
1359 | } | 1330 | } |
@@ -1384,9 +1355,9 @@ peer_info_connect_task (void *cls, | |||
1384 | 1355 | ||
1385 | /** | 1356 | /** |
1386 | * Destroy the peer_info and free any allocated resources linked to it | 1357 | * Destroy the peer_info and free any allocated resources linked to it |
1387 | * | 1358 | * |
1388 | * @param pi The peer_info to destroy. | 1359 | * @param pi The peer_info to destroy. |
1389 | * | 1360 | * |
1390 | * @return GNUNET_OK on success | 1361 | * @return GNUNET_OK on success |
1391 | */ | 1362 | */ |
1392 | static int | 1363 | static int |
@@ -1401,21 +1372,20 @@ peer_info_destroy (struct MeshPeerInfo *pi) | |||
1401 | GNUNET_PEER_change_rc (pi->id, -1); | 1372 | GNUNET_PEER_change_rc (pi->id, -1); |
1402 | 1373 | ||
1403 | if (GNUNET_YES != | 1374 | if (GNUNET_YES != |
1404 | GNUNET_CONTAINER_multihashmap_remove (peers,&id.hashPubKey, pi)) | 1375 | GNUNET_CONTAINER_multihashmap_remove (peers, &id.hashPubKey, pi)) |
1405 | { | 1376 | { |
1406 | GNUNET_break (0); | 1377 | GNUNET_break (0); |
1407 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1378 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1408 | "MESH: removing peer %s, not in hashmap\n", | 1379 | "MESH: removing peer %s, not in hashmap\n", GNUNET_i2s (&id)); |
1409 | GNUNET_i2s (&id)); | ||
1410 | } | 1380 | } |
1411 | if (NULL != pi->dhtget) | 1381 | if (NULL != pi->dhtget) |
1412 | { | 1382 | { |
1413 | GNUNET_DHT_get_stop(pi->dhtget); | 1383 | GNUNET_DHT_get_stop (pi->dhtget); |
1414 | GNUNET_free (pi->dhtgetcls); | 1384 | GNUNET_free (pi->dhtgetcls); |
1415 | } | 1385 | } |
1416 | for (i = 0; i < CORE_QUEUE_SIZE; i++) | 1386 | for (i = 0; i < CORE_QUEUE_SIZE; i++) |
1417 | { | 1387 | { |
1418 | peer_info_cancel_transmission(pi, i); | 1388 | peer_info_cancel_transmission (pi, i); |
1419 | } | 1389 | } |
1420 | p = pi->path_head; | 1390 | p = pi->path_head; |
1421 | while (NULL != p) | 1391 | while (NULL != p) |
@@ -1442,8 +1412,7 @@ peer_info_destroy (struct MeshPeerInfo *pi) | |||
1442 | * TODO: optimize (see below) | 1412 | * TODO: optimize (see below) |
1443 | */ | 1413 | */ |
1444 | static void | 1414 | static void |
1445 | peer_info_remove_path (struct MeshPeerInfo *peer, | 1415 | peer_info_remove_path (struct MeshPeerInfo *peer, GNUNET_PEER_Id p1, |
1446 | GNUNET_PEER_Id p1, | ||
1447 | GNUNET_PEER_Id p2) | 1416 | GNUNET_PEER_Id p2) |
1448 | { | 1417 | { |
1449 | struct MeshPeerPath *p; | 1418 | struct MeshPeerPath *p; |
@@ -1486,16 +1455,16 @@ peer_info_remove_path (struct MeshPeerInfo *peer, | |||
1486 | * Some of them might already have a path to reach them that does not | 1455 | * Some of them might already have a path to reach them that does not |
1487 | * involve p1 and p2. Adding all anew might render in a better tree than | 1456 | * involve p1 and p2. Adding all anew might render in a better tree than |
1488 | * the trivial immediate fix. | 1457 | * the trivial immediate fix. |
1489 | * | 1458 | * |
1490 | * Trivial immiediate fix: try to reconnect to the disconnected node. All | 1459 | * Trivial immiediate fix: try to reconnect to the disconnected node. All |
1491 | * its children will be reachable trough him. | 1460 | * its children will be reachable trough him. |
1492 | */ | 1461 | */ |
1493 | peer_d = peer_info_get_short(d); | 1462 | peer_d = peer_info_get_short (d); |
1494 | best = UINT_MAX; | 1463 | best = UINT_MAX; |
1495 | aux = NULL; | 1464 | aux = NULL; |
1496 | for (p = peer_d->path_head; NULL != p; p = p->next) | 1465 | for (p = peer_d->path_head; NULL != p; p = p->next) |
1497 | { | 1466 | { |
1498 | if ((cost = path_get_cost(peer->tunnels[i]->tree, p)) < best) | 1467 | if ((cost = path_get_cost (peer->tunnels[i]->tree, p)) < best) |
1499 | { | 1468 | { |
1500 | best = cost; | 1469 | best = cost; |
1501 | aux = p; | 1470 | aux = p; |
@@ -1504,7 +1473,7 @@ peer_info_remove_path (struct MeshPeerInfo *peer, | |||
1504 | if (NULL != aux) | 1473 | if (NULL != aux) |
1505 | { | 1474 | { |
1506 | /* No callback, as peer will be already disconnected */ | 1475 | /* No callback, as peer will be already disconnected */ |
1507 | tree_add_path(peer->tunnels[i]->tree, aux, NULL, NULL); | 1476 | tree_add_path (peer->tunnels[i]->tree, aux, NULL, NULL); |
1508 | } | 1477 | } |
1509 | else | 1478 | else |
1510 | { | 1479 | { |
@@ -1524,8 +1493,7 @@ peer_info_remove_path (struct MeshPeerInfo *peer, | |||
1524 | * @param trusted Do we trust that this path is real? | 1493 | * @param trusted Do we trust that this path is real? |
1525 | */ | 1494 | */ |
1526 | void | 1495 | void |
1527 | peer_info_add_path (struct MeshPeerInfo *peer_info, | 1496 | peer_info_add_path (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path, |
1528 | struct MeshPeerPath *path, | ||
1529 | int trusted) | 1497 | int trusted) |
1530 | { | 1498 | { |
1531 | struct MeshPeerPath *aux; | 1499 | struct MeshPeerPath *aux; |
@@ -1549,28 +1517,24 @@ peer_info_add_path (struct MeshPeerInfo *peer_info, | |||
1549 | { | 1517 | { |
1550 | if (path->peers[l] == myid) | 1518 | if (path->peers[l] == myid) |
1551 | { | 1519 | { |
1552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shortening path by %u\n", l); |
1553 | "MESH: shortening path by %u\n", | 1521 | for (l2 = 0; l2 < path->length - l - 1; l2++) |
1554 | l); | ||
1555 | for (l2 = 0; l2 < path->length - l - 1 ; l2++) | ||
1556 | { | 1522 | { |
1557 | path->peers[l2] = path->peers[l + l2]; | 1523 | path->peers[l2] = path->peers[l + l2]; |
1558 | } | 1524 | } |
1559 | path->length -= l; | 1525 | path->length -= l; |
1560 | l = 1; | 1526 | l = 1; |
1561 | path->peers = GNUNET_realloc (path->peers, | 1527 | path->peers = |
1562 | path->length * sizeof (GNUNET_PEER_Id)); | 1528 | GNUNET_realloc (path->peers, path->length * sizeof (GNUNET_PEER_Id)); |
1563 | } | 1529 | } |
1564 | } | 1530 | } |
1565 | #if MESH_DEBUG | 1531 | #if MESH_DEBUG |
1566 | { | 1532 | { |
1567 | struct GNUNET_PeerIdentity id; | 1533 | struct GNUNET_PeerIdentity id; |
1568 | 1534 | ||
1569 | GNUNET_PEER_resolve (peer_info->id, &id); | 1535 | GNUNET_PEER_resolve (peer_info->id, &id); |
1570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: adding path [%u] to peer %s\n", |
1571 | "MESH: adding path [%u] to peer %s\n", | 1537 | path->length, GNUNET_i2s (&id)); |
1572 | path->length, | ||
1573 | GNUNET_i2s (&id)); | ||
1574 | } | 1538 | } |
1575 | #endif | 1539 | #endif |
1576 | l = path_get_length (path); | 1540 | l = path_get_length (path); |
@@ -1587,22 +1551,19 @@ peer_info_add_path (struct MeshPeerInfo *peer_info, | |||
1587 | if (l2 > l) | 1551 | if (l2 > l) |
1588 | { | 1552 | { |
1589 | GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head, | 1553 | GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head, |
1590 | peer_info->path_tail, | 1554 | peer_info->path_tail, aux, path); |
1591 | aux, | ||
1592 | path); | ||
1593 | return; | 1555 | return; |
1594 | } | 1556 | } |
1595 | else | 1557 | else |
1596 | { | 1558 | { |
1597 | if (l2 == l && memcmp(path->peers, aux->peers, l) == 0) | 1559 | if (l2 == l && memcmp (path->peers, aux->peers, l) == 0) |
1598 | { | 1560 | { |
1599 | path_destroy(path); | 1561 | path_destroy (path); |
1600 | return; | 1562 | return; |
1601 | } | 1563 | } |
1602 | } | 1564 | } |
1603 | } | 1565 | } |
1604 | GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, | 1566 | GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, peer_info->path_tail, |
1605 | peer_info->path_tail, | ||
1606 | path); | 1567 | path); |
1607 | return; | 1568 | return; |
1608 | } | 1569 | } |
@@ -1620,10 +1581,9 @@ peer_info_add_path (struct MeshPeerInfo *peer_info, | |||
1620 | */ | 1581 | */ |
1621 | static void | 1582 | static void |
1622 | peer_info_add_path_to_origin (struct MeshPeerInfo *peer_info, | 1583 | peer_info_add_path_to_origin (struct MeshPeerInfo *peer_info, |
1623 | struct MeshPeerPath *path, | 1584 | struct MeshPeerPath *path, int trusted) |
1624 | int trusted) | ||
1625 | { | 1585 | { |
1626 | path_invert(path); | 1586 | path_invert (path); |
1627 | peer_info_add_path (peer_info, path, trusted); | 1587 | peer_info_add_path (peer_info, path, trusted); |
1628 | } | 1588 | } |
1629 | 1589 | ||
@@ -1646,29 +1606,28 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
1646 | 1606 | ||
1647 | p = path_new (1); | 1607 | p = path_new (1); |
1648 | p->peers[0] = myid; | 1608 | p->peers[0] = myid; |
1649 | GNUNET_PEER_change_rc(myid, 1); | 1609 | GNUNET_PEER_change_rc (myid, 1); |
1650 | i = get_path_length; | 1610 | i = get_path_length; |
1651 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); | 1611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); |
1652 | for (i--; i >= 0; i--) | 1612 | for (i--; i >= 0; i--) |
1653 | { | 1613 | { |
1654 | id = GNUNET_PEER_intern (&get_path[i]); | 1614 | id = GNUNET_PEER_intern (&get_path[i]); |
1655 | if (p->length > 0 && id == p->peers[p->length - 1]) | 1615 | if (p->length > 0 && id == p->peers[p->length - 1]) |
1656 | { | 1616 | { |
1657 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); | 1617 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); |
1658 | GNUNET_PEER_change_rc(id, -1); | 1618 | GNUNET_PEER_change_rc (id, -1); |
1659 | } | 1619 | } |
1660 | else | 1620 | else |
1661 | { | 1621 | { |
1662 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from GET: %s.\n", |
1663 | "MESH: Adding from GET: %s.\n", | 1623 | GNUNET_i2s (&get_path[i])); |
1664 | GNUNET_i2s(&get_path[i])); | ||
1665 | p->length++; | 1624 | p->length++; |
1666 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | 1625 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); |
1667 | p->peers[p->length - 1] = id; | 1626 | p->peers[p->length - 1] = id; |
1668 | } | 1627 | } |
1669 | } | 1628 | } |
1670 | i = put_path_length; | 1629 | i = put_path_length; |
1671 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i); | 1630 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i); |
1672 | for (i--; i >= 0; i--) | 1631 | for (i--; i >= 0; i--) |
1673 | { | 1632 | { |
1674 | id = GNUNET_PEER_intern (&put_path[i]); | 1633 | id = GNUNET_PEER_intern (&put_path[i]); |
@@ -1682,14 +1641,13 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
1682 | } | 1641 | } |
1683 | if (p->length > 0 && id == p->peers[p->length - 1]) | 1642 | if (p->length > 0 && id == p->peers[p->length - 1]) |
1684 | { | 1643 | { |
1685 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); | 1644 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); |
1686 | GNUNET_PEER_change_rc(id, -1); | 1645 | GNUNET_PEER_change_rc (id, -1); |
1687 | } | 1646 | } |
1688 | else | 1647 | else |
1689 | { | 1648 | { |
1690 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1649 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Adding from PUT: %s.\n", |
1691 | "MESH: Adding from PUT: %s.\n", | 1650 | GNUNET_i2s (&put_path[i])); |
1692 | GNUNET_i2s(&put_path[i])); | ||
1693 | p->length++; | 1651 | p->length++; |
1694 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | 1652 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); |
1695 | p->peers[p->length - 1] = id; | 1653 | p->peers[p->length - 1] = id; |
@@ -1697,25 +1655,20 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
1697 | } | 1655 | } |
1698 | #if MESH_DEBUG | 1656 | #if MESH_DEBUG |
1699 | if (get_path_length > 0) | 1657 | if (get_path_length > 0) |
1700 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1658 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of GET: %s)\n", |
1701 | "MESH: (first of GET: %s)\n", | 1659 | GNUNET_i2s (&get_path[0])); |
1702 | GNUNET_i2s(&get_path[0])); | ||
1703 | if (put_path_length > 0) | 1660 | if (put_path_length > 0) |
1704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1661 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of PUT: %s)\n", |
1705 | "MESH: (first of PUT: %s)\n", | 1662 | GNUNET_i2s (&put_path[0])); |
1706 | GNUNET_i2s(&put_path[0])); | 1663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: In total: %d hops\n", |
1707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1708 | "MESH: In total: %d hops\n", | ||
1709 | p->length); | 1664 | p->length); |
1710 | for (i = 0; i < p->length; i++) | 1665 | for (i = 0; i < p->length; i++) |
1711 | { | 1666 | { |
1712 | struct GNUNET_PeerIdentity peer_id; | 1667 | struct GNUNET_PeerIdentity peer_id; |
1713 | 1668 | ||
1714 | GNUNET_PEER_resolve(p->peers[i], &peer_id); | 1669 | GNUNET_PEER_resolve (p->peers[i], &peer_id); |
1715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1670 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %u: %s\n", p->peers[i], |
1716 | "MESH: %u: %s\n", | 1671 | GNUNET_i2s (&peer_id)); |
1717 | p->peers[i], | ||
1718 | GNUNET_i2s(&peer_id)); | ||
1719 | } | 1672 | } |
1720 | #endif | 1673 | #endif |
1721 | return p; | 1674 | return p; |
@@ -1831,6 +1784,7 @@ notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id) | |||
1831 | if (NULL != t->client && NULL != nc) | 1784 | if (NULL != t->client && NULL != nc) |
1832 | { | 1785 | { |
1833 | struct GNUNET_MESH_PeerControl msg; | 1786 | struct GNUNET_MESH_PeerControl msg; |
1787 | |||
1834 | msg.header.size = htons (sizeof (msg)); | 1788 | msg.header.size = htons (sizeof (msg)); |
1835 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL); | 1789 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL); |
1836 | msg.tunnel_id = htonl (t->local_tid); | 1790 | msg.tunnel_id = htonl (t->local_tid); |
@@ -1838,11 +1792,11 @@ notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id) | |||
1838 | GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, | 1792 | GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, |
1839 | &msg.header, GNUNET_NO); | 1793 | &msg.header, GNUNET_NO); |
1840 | } | 1794 | } |
1841 | peer = peer_info_get_short(peer_id); | 1795 | peer = peer_info_get_short (peer_id); |
1842 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); | 1796 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); |
1843 | path_info->peer = peer; | 1797 | path_info->peer = peer; |
1844 | path_info->t = t; | 1798 | path_info->t = t; |
1845 | GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info); | 1799 | GNUNET_SCHEDULER_add_now (&peer_info_connect_task, path_info); |
1846 | } | 1800 | } |
1847 | 1801 | ||
1848 | 1802 | ||
@@ -1864,23 +1818,22 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
1864 | unsigned int best_cost; | 1818 | unsigned int best_cost; |
1865 | unsigned int cost; | 1819 | unsigned int cost; |
1866 | 1820 | ||
1867 | GNUNET_PEER_resolve(peer->id, &id); | 1821 | GNUNET_PEER_resolve (peer->id, &id); |
1868 | if (GNUNET_NO == | 1822 | if (GNUNET_NO == |
1869 | GNUNET_CONTAINER_multihashmap_contains(t->peers, &id.hashPubKey)) | 1823 | GNUNET_CONTAINER_multihashmap_contains (t->peers, &id.hashPubKey)) |
1870 | { | 1824 | { |
1871 | t->peers_total++; | 1825 | t->peers_total++; |
1872 | GNUNET_array_append (peer->tunnels, peer->ntunnels, t); | 1826 | GNUNET_array_append (peer->tunnels, peer->ntunnels, t); |
1873 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( | 1827 | GNUNET_assert (GNUNET_OK == |
1874 | t->peers, | 1828 | GNUNET_CONTAINER_multihashmap_put (t->peers, &id.hashPubKey, |
1875 | &id.hashPubKey, | 1829 | peer, |
1876 | peer, | 1830 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
1877 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | ||
1878 | } | 1831 | } |
1879 | 1832 | ||
1880 | if (NULL != (p = peer->path_head)) | 1833 | if (NULL != (p = peer->path_head)) |
1881 | { | 1834 | { |
1882 | best_p = p; | 1835 | best_p = p; |
1883 | best_cost = path_get_cost(t->tree, p); | 1836 | best_cost = path_get_cost (t->tree, p); |
1884 | while (NULL != p) | 1837 | while (NULL != p) |
1885 | { | 1838 | { |
1886 | if ((cost = path_get_cost (t->tree, p)) < best_cost) | 1839 | if ((cost = path_get_cost (t->tree, p)) < best_cost) |
@@ -1898,7 +1851,7 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
1898 | else | 1851 | else |
1899 | { | 1852 | { |
1900 | /* Start a DHT get if necessary */ | 1853 | /* Start a DHT get if necessary */ |
1901 | peer_info_connect(peer, t); | 1854 | peer_info_connect (peer, t); |
1902 | } | 1855 | } |
1903 | } | 1856 | } |
1904 | 1857 | ||
@@ -1913,22 +1866,19 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
1913 | * | 1866 | * |
1914 | */ | 1867 | */ |
1915 | static void | 1868 | static void |
1916 | tunnel_add_path (struct MeshTunnel *t, | 1869 | tunnel_add_path (struct MeshTunnel *t, struct MeshPeerPath *p, |
1917 | struct MeshPeerPath *p, | ||
1918 | unsigned int own_pos) | 1870 | unsigned int own_pos) |
1919 | { | 1871 | { |
1920 | struct GNUNET_PeerIdentity id; | 1872 | struct GNUNET_PeerIdentity id; |
1921 | 1873 | ||
1922 | GNUNET_assert (0 != own_pos); | 1874 | GNUNET_assert (0 != own_pos); |
1923 | tree_add_path(t->tree, p, NULL, NULL); | 1875 | tree_add_path (t->tree, p, NULL, NULL); |
1924 | if (tree_get_me (t->tree) == 0) | 1876 | if (tree_get_me (t->tree) == 0) |
1925 | tree_set_me (t->tree, p->peers[own_pos]); | 1877 | tree_set_me (t->tree, p->peers[own_pos]); |
1926 | if (own_pos < p->length - 1) | 1878 | if (own_pos < p->length - 1) |
1927 | { | 1879 | { |
1928 | GNUNET_PEER_resolve (p->peers[own_pos + 1], &id); | 1880 | GNUNET_PEER_resolve (p->peers[own_pos + 1], &id); |
1929 | tree_update_first_hops(t->tree, | 1881 | tree_update_first_hops (t->tree, tree_get_me (t->tree), &id); |
1930 | tree_get_me (t->tree), | ||
1931 | &id); | ||
1932 | } | 1882 | } |
1933 | } | 1883 | } |
1934 | 1884 | ||
@@ -1947,24 +1897,21 @@ tunnel_add_path (struct MeshTunnel *t, | |||
1947 | * 0 if the tunnel remained unaffected. | 1897 | * 0 if the tunnel remained unaffected. |
1948 | */ | 1898 | */ |
1949 | static GNUNET_PEER_Id | 1899 | static GNUNET_PEER_Id |
1950 | tunnel_notify_connection_broken (struct MeshTunnel *t, | 1900 | tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1, |
1951 | GNUNET_PEER_Id p1, | ||
1952 | GNUNET_PEER_Id p2) | 1901 | GNUNET_PEER_Id p2) |
1953 | { | 1902 | { |
1954 | GNUNET_PEER_Id pid; | 1903 | GNUNET_PEER_Id pid; |
1955 | 1904 | ||
1956 | pid = tree_notify_connection_broken (t->tree, | 1905 | pid = |
1957 | p1, | 1906 | tree_notify_connection_broken (t->tree, p1, p2, ¬ify_peer_disconnected, |
1958 | p2, | 1907 | t); |
1959 | ¬ify_peer_disconnected, | ||
1960 | t); | ||
1961 | if (myid != p1 && myid != p2) | 1908 | if (myid != p1 && myid != p2) |
1962 | { | 1909 | { |
1963 | return pid; | 1910 | return pid; |
1964 | } | 1911 | } |
1965 | if (pid != myid) | 1912 | if (pid != myid) |
1966 | { | 1913 | { |
1967 | if (tree_get_predecessor(t->tree) != 0) | 1914 | if (tree_get_predecessor (t->tree) != 0) |
1968 | { | 1915 | { |
1969 | /* We are the peer still connected, notify owner of the disconnection. */ | 1916 | /* We are the peer still connected, notify owner of the disconnection. */ |
1970 | struct GNUNET_MESH_PathBroken msg; | 1917 | struct GNUNET_MESH_PathBroken msg; |
@@ -2002,8 +1949,7 @@ struct MeshMulticastData | |||
2002 | * Send a multicast packet to a neighbor. | 1949 | * Send a multicast packet to a neighbor. |
2003 | */ | 1950 | */ |
2004 | static void | 1951 | static void |
2005 | tunnel_send_multicast_iterator (void *cls, | 1952 | tunnel_send_multicast_iterator (void *cls, GNUNET_PEER_Id neighbor_id) |
2006 | GNUNET_PEER_Id neighbor_id) | ||
2007 | { | 1953 | { |
2008 | struct MeshMulticastData *mdata = cls; | 1954 | struct MeshMulticastData *mdata = cls; |
2009 | struct MeshDataDescriptor *info; | 1955 | struct MeshDataDescriptor *info; |
@@ -2025,24 +1971,20 @@ tunnel_send_multicast_iterator (void *cls, | |||
2025 | info->destination = neighbor_id; | 1971 | info->destination = neighbor_id; |
2026 | GNUNET_PEER_resolve (neighbor_id, &neighbor); | 1972 | GNUNET_PEER_resolve (neighbor_id, &neighbor); |
2027 | #if MESH_DEBUG | 1973 | #if MESH_DEBUG |
2028 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1974 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: sending to %s...\n", |
2029 | "MESH: sending to %s...\n", | 1975 | GNUNET_i2s (&neighbor)); |
2030 | GNUNET_i2s (&neighbor)); | ||
2031 | #endif | 1976 | #endif |
2032 | info->peer = peer_info_get(&neighbor); | 1977 | info->peer = peer_info_get (&neighbor); |
2033 | GNUNET_assert (NULL != info->peer); | 1978 | GNUNET_assert (NULL != info->peer); |
2034 | i = peer_info_transmit_slot(info->peer); | 1979 | i = peer_info_transmit_slot (info->peer); |
2035 | info->handler_n = i; | 1980 | info->handler_n = i; |
2036 | info->peer->infos[i] = info; | 1981 | info->peer->infos[i] = info; |
2037 | info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST; | 1982 | info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST; |
2038 | info->peer->core_transmit[i] = | 1983 | info->peer->core_transmit[i] = |
2039 | GNUNET_CORE_notify_transmit_ready (core_handle, | 1984 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, |
2040 | 0, | 1985 | GNUNET_TIME_UNIT_FOREVER_REL, |
2041 | 0, | 1986 | &neighbor, info->size, |
2042 | GNUNET_TIME_UNIT_FOREVER_REL, | 1987 | &send_core_data_multicast, info); |
2043 | &neighbor, | ||
2044 | info->size, | ||
2045 | &send_core_data_multicast, info); | ||
2046 | } | 1988 | } |
2047 | 1989 | ||
2048 | /** | 1990 | /** |
@@ -2072,9 +2014,9 @@ tunnel_send_multicast (struct MeshTunnel *t, | |||
2072 | if (NULL != t->client) | 2014 | if (NULL != t->client) |
2073 | { | 2015 | { |
2074 | mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier)); | 2016 | mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier)); |
2075 | *(mdata->task) = GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, | 2017 | *(mdata->task) = |
2076 | &client_allow_send, | 2018 | GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, &client_allow_send, |
2077 | t->client->handle); | 2019 | t->client->handle); |
2078 | } | 2020 | } |
2079 | 2021 | ||
2080 | tree_iterate_children (t->tree, &tunnel_send_multicast_iterator, mdata); | 2022 | tree_iterate_children (t->tree, &tunnel_send_multicast_iterator, mdata); |
@@ -2140,11 +2082,9 @@ tunnel_destroy (struct MeshTunnel *t) | |||
2140 | { | 2082 | { |
2141 | struct GNUNET_PeerIdentity id; | 2083 | struct GNUNET_PeerIdentity id; |
2142 | 2084 | ||
2143 | GNUNET_PEER_resolve(t->id.oid, &id); | 2085 | GNUNET_PEER_resolve (t->id.oid, &id); |
2144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2086 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: destroying tunnel %s [%x]\n", |
2145 | "MESH: destroying tunnel %s [%x]\n", | 2087 | GNUNET_i2s (&id), t->id.tid); |
2146 | GNUNET_i2s (&id), | ||
2147 | t->id.tid); | ||
2148 | if (NULL != c) | 2088 | if (NULL != c) |
2149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id); | 2089 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id); |
2150 | } | 2090 | } |
@@ -2166,12 +2106,13 @@ tunnel_destroy (struct MeshTunnel *t) | |||
2166 | { | 2106 | { |
2167 | GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); | 2107 | GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); |
2168 | GNUNET_break (GNUNET_YES == | 2108 | GNUNET_break (GNUNET_YES == |
2169 | GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, t)); | 2109 | GNUNET_CONTAINER_multihashmap_remove (incoming_tunnels, &hash, |
2110 | t)); | ||
2170 | } | 2111 | } |
2171 | if (NULL != t->peers) | 2112 | if (NULL != t->peers) |
2172 | { | 2113 | { |
2173 | GNUNET_CONTAINER_multihashmap_iterate(t->peers, | 2114 | GNUNET_CONTAINER_multihashmap_iterate (t->peers, &peer_info_delete_tunnel, |
2174 | &peer_info_delete_tunnel, t); | 2115 | t); |
2175 | GNUNET_CONTAINER_multihashmap_destroy (t->peers); | 2116 | GNUNET_CONTAINER_multihashmap_destroy (t->peers); |
2176 | } | 2117 | } |
2177 | q = t->queue_head; | 2118 | q = t->queue_head; |
@@ -2184,13 +2125,13 @@ tunnel_destroy (struct MeshTunnel *t) | |||
2184 | q = qn; | 2125 | q = qn; |
2185 | /* TODO cancel core transmit ready in case it was active */ | 2126 | /* TODO cancel core transmit ready in case it was active */ |
2186 | } | 2127 | } |
2187 | tree_destroy(t->tree); | 2128 | tree_destroy (t->tree); |
2188 | if (NULL != t->dht_get_type) | 2129 | if (NULL != t->dht_get_type) |
2189 | GNUNET_DHT_get_stop(t->dht_get_type); | 2130 | GNUNET_DHT_get_stop (t->dht_get_type); |
2190 | if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) | 2131 | if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) |
2191 | GNUNET_SCHEDULER_cancel(t->timeout_task); | 2132 | GNUNET_SCHEDULER_cancel (t->timeout_task); |
2192 | if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task) | 2133 | if (GNUNET_SCHEDULER_NO_TASK != t->path_refresh_task) |
2193 | GNUNET_SCHEDULER_cancel(t->path_refresh_task); | 2134 | GNUNET_SCHEDULER_cancel (t->path_refresh_task); |
2194 | GNUNET_free (t); | 2135 | GNUNET_free (t); |
2195 | return r; | 2136 | return r; |
2196 | } | 2137 | } |
@@ -2205,8 +2146,7 @@ tunnel_destroy (struct MeshTunnel *t) | |||
2205 | * @param p Peer which should be removed. | 2146 | * @param p Peer which should be removed. |
2206 | */ | 2147 | */ |
2207 | static void | 2148 | static void |
2208 | tunnel_delete_peer (struct MeshTunnel *t, | 2149 | tunnel_delete_peer (struct MeshTunnel *t, GNUNET_PEER_Id peer) |
2209 | GNUNET_PEER_Id peer) | ||
2210 | { | 2150 | { |
2211 | if (GNUNET_NO == tree_del_peer (t->tree, peer, NULL, NULL)) | 2151 | if (GNUNET_NO == tree_del_peer (t->tree, peer, NULL, NULL)) |
2212 | tunnel_destroy (t); | 2152 | tunnel_destroy (t); |
@@ -2216,11 +2156,11 @@ tunnel_delete_peer (struct MeshTunnel *t, | |||
2216 | /** | 2156 | /** |
2217 | * tunnel_destroy_iterator: iterator for deleting each tunnel that belongs to a | 2157 | * tunnel_destroy_iterator: iterator for deleting each tunnel that belongs to a |
2218 | * client when the client disconnects. | 2158 | * client when the client disconnects. |
2219 | * | 2159 | * |
2220 | * @param cls closure (client that is disconnecting) | 2160 | * @param cls closure (client that is disconnecting) |
2221 | * @param key the hash of the local tunnel id (used to access the hashmap) | 2161 | * @param key the hash of the local tunnel id (used to access the hashmap) |
2222 | * @param value the value stored at the key (tunnel to destroy) | 2162 | * @param value the value stored at the key (tunnel to destroy) |
2223 | * | 2163 | * |
2224 | * @return GNUNET_OK on success | 2164 | * @return GNUNET_OK on success |
2225 | */ | 2165 | */ |
2226 | static int | 2166 | static int |
@@ -2261,10 +2201,9 @@ tunnel_reset_timeout (struct MeshTunnel *t) | |||
2261 | { | 2201 | { |
2262 | if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) | 2202 | if (GNUNET_SCHEDULER_NO_TASK != t->timeout_task) |
2263 | GNUNET_SCHEDULER_cancel (t->timeout_task); | 2203 | GNUNET_SCHEDULER_cancel (t->timeout_task); |
2264 | t->timeout_task = GNUNET_SCHEDULER_add_delayed ( | 2204 | t->timeout_task = |
2265 | GNUNET_TIME_relative_multiply(REFRESH_PATH_TIME, 4), | 2205 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
2266 | &tunnel_timeout, | 2206 | (REFRESH_PATH_TIME, 4), &tunnel_timeout, t); |
2267 | t); | ||
2268 | } | 2207 | } |
2269 | 2208 | ||
2270 | 2209 | ||
@@ -2295,8 +2234,7 @@ send_core_create_path (void *cls, size_t size, void *buf) | |||
2295 | size_t size_needed; | 2234 | size_t size_needed; |
2296 | int i; | 2235 | int i; |
2297 | 2236 | ||
2298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATE PATH sending...\n"); |
2299 | "MESH: CREATE PATH sending...\n"); | ||
2300 | size_needed = | 2238 | size_needed = |
2301 | sizeof (struct GNUNET_MESH_ManipulatePath) + | 2239 | sizeof (struct GNUNET_MESH_ManipulatePath) + |
2302 | p->length * sizeof (struct GNUNET_PeerIdentity); | 2240 | p->length * sizeof (struct GNUNET_PeerIdentity); |
@@ -2305,15 +2243,15 @@ send_core_create_path (void *cls, size_t size, void *buf) | |||
2305 | { | 2243 | { |
2306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: create path retransmit!\n"); | 2244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: create path retransmit!\n"); |
2307 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: buf: %p\n", buf); | 2245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: buf: %p\n", buf); |
2308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n", | 2246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: size: (%u/%u)\n", size, |
2309 | size, size_needed); | 2247 | size_needed); |
2310 | info->peer->core_transmit[info->pos] = | 2248 | info->peer->core_transmit[info->pos] = |
2311 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, | 2249 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, |
2312 | GNUNET_TIME_UNIT_FOREVER_REL, | 2250 | GNUNET_TIME_UNIT_FOREVER_REL, |
2313 | path_get_first_hop (t->tree, peer->id), | 2251 | path_get_first_hop (t->tree, |
2314 | size_needed, | 2252 | peer->id), |
2315 | &send_core_create_path, | 2253 | size_needed, &send_core_create_path, |
2316 | info); | 2254 | info); |
2317 | return 0; | 2255 | return 0; |
2318 | } | 2256 | } |
2319 | info->peer->core_transmit[info->pos] = NULL; | 2257 | info->peer->core_transmit[info->pos] = NULL; |
@@ -2324,8 +2262,7 @@ send_core_create_path (void *cls, size_t size, void *buf) | |||
2324 | GNUNET_PEER_resolve (peer->id, &id); | 2262 | GNUNET_PEER_resolve (peer->id, &id); |
2325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2326 | "MESH: setting core_transmit %s [%u] to NULL\n", | 2264 | "MESH: setting core_transmit %s [%u] to NULL\n", |
2327 | GNUNET_i2s (&id), | 2265 | GNUNET_i2s (&id), info->pos); |
2328 | info->pos); | ||
2329 | } | 2266 | } |
2330 | #endif | 2267 | #endif |
2331 | msg = (struct GNUNET_MESH_ManipulatePath *) buf; | 2268 | msg = (struct GNUNET_MESH_ManipulatePath *) buf; |
@@ -2343,8 +2280,7 @@ send_core_create_path (void *cls, size_t size, void *buf) | |||
2343 | GNUNET_free (info); | 2280 | GNUNET_free (info); |
2344 | 2281 | ||
2345 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2346 | "MESH: CREATE PATH (%u bytes long) sent!\n", | 2283 | "MESH: CREATE PATH (%u bytes long) sent!\n", size_needed); |
2347 | size_needed); | ||
2348 | return size_needed; | 2284 | return size_needed; |
2349 | } | 2285 | } |
2350 | 2286 | ||
@@ -2358,7 +2294,7 @@ send_core_create_path (void *cls, size_t size, void *buf) | |||
2358 | * @param cls closure (data itself) | 2294 | * @param cls closure (data itself) |
2359 | * @param size number of bytes available in buf | 2295 | * @param size number of bytes available in buf |
2360 | * @param buf where the callee should write the message | 2296 | * @param buf where the callee should write the message |
2361 | * | 2297 | * |
2362 | * @return number of bytes written to buf | 2298 | * @return number of bytes written to buf |
2363 | */ | 2299 | */ |
2364 | static size_t | 2300 | static size_t |
@@ -2379,18 +2315,14 @@ send_core_data_multicast (void *cls, size_t size, void *buf) | |||
2379 | struct GNUNET_PeerIdentity id; | 2315 | struct GNUNET_PeerIdentity id; |
2380 | 2316 | ||
2381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2382 | "MESH: Multicast: retransmitting... (%u/%u)\n", | 2318 | "MESH: Multicast: retransmitting... (%u/%u)\n", size, |
2383 | size, total_size); | 2319 | total_size); |
2384 | GNUNET_PEER_resolve(info->peer->id, &id); | 2320 | GNUNET_PEER_resolve (info->peer->id, &id); |
2385 | info->peer->core_transmit[info->handler_n] = | 2321 | info->peer->core_transmit[info->handler_n] = |
2386 | GNUNET_CORE_notify_transmit_ready (core_handle, | 2322 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, |
2387 | 0, | 2323 | GNUNET_TIME_UNIT_FOREVER_REL, &id, |
2388 | 0, | 2324 | total_size, |
2389 | GNUNET_TIME_UNIT_FOREVER_REL, | 2325 | &send_core_data_multicast, info); |
2390 | &id, | ||
2391 | total_size, | ||
2392 | &send_core_data_multicast, | ||
2393 | info); | ||
2394 | return 0; | 2326 | return 0; |
2395 | } | 2327 | } |
2396 | info->peer->core_transmit[info->handler_n] = NULL; | 2328 | info->peer->core_transmit[info->handler_n] = NULL; |
@@ -2408,16 +2340,13 @@ send_core_data_multicast (void *cls, size_t size, void *buf) | |||
2408 | mc = (struct GNUNET_MESH_Multicast *) mh; | 2340 | mc = (struct GNUNET_MESH_Multicast *) mh; |
2409 | mh = (struct GNUNET_MessageHeader *) &mc[1]; | 2341 | mh = (struct GNUNET_MessageHeader *) &mc[1]; |
2410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2411 | "MESH: multicast, payload type %u\n", | 2343 | "MESH: multicast, payload type %u\n", ntohs (mh->type)); |
2412 | ntohs (mh->type)); | ||
2413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2414 | "MESH: multicast, payload size %u\n", | 2345 | "MESH: multicast, payload size %u\n", ntohs (mh->size)); |
2415 | ntohs (mh->size)); | ||
2416 | } | 2346 | } |
2417 | else | 2347 | else |
2418 | { | 2348 | { |
2419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type %u\n", |
2420 | "MESH: type %u\n", | ||
2421 | ntohs (mh->type)); | 2350 | ntohs (mh->type)); |
2422 | } | 2351 | } |
2423 | } | 2352 | } |
@@ -2483,7 +2412,7 @@ send_core_path_ack (void *cls, size_t size, void *buf) | |||
2483 | * @param peer peer identity this notification is about | 2412 | * @param peer peer identity this notification is about |
2484 | * @param atsi performance data | 2413 | * @param atsi performance data |
2485 | * @param atsi_count number of records in 'atsi' | 2414 | * @param atsi_count number of records in 'atsi' |
2486 | * | 2415 | * |
2487 | * @return GNUNET_OK to keep the connection open, | 2416 | * @return GNUNET_OK to keep the connection open, |
2488 | * GNUNET_SYSERR to close it (signal serious error) | 2417 | * GNUNET_SYSERR to close it (signal serious error) |
2489 | */ | 2418 | */ |
@@ -2491,7 +2420,7 @@ static int | |||
2491 | handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | 2420 | handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, |
2492 | const struct GNUNET_MessageHeader *message, | 2421 | const struct GNUNET_MessageHeader *message, |
2493 | const struct GNUNET_ATS_Information *atsi, | 2422 | const struct GNUNET_ATS_Information *atsi, |
2494 | unsigned int atsi_count) | 2423 | unsigned int atsi_count) |
2495 | { | 2424 | { |
2496 | unsigned int own_pos; | 2425 | unsigned int own_pos; |
2497 | uint16_t size; | 2426 | uint16_t size; |
@@ -2507,7 +2436,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2507 | 2436 | ||
2508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2509 | "MESH: Received a path create msg [%s]\n", | 2438 | "MESH: Received a path create msg [%s]\n", |
2510 | GNUNET_i2s(&my_full_id)); | 2439 | GNUNET_i2s (&my_full_id)); |
2511 | size = ntohs (message->size); | 2440 | size = ntohs (message->size); |
2512 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) | 2441 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) |
2513 | { | 2442 | { |
@@ -2527,18 +2456,14 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2527 | GNUNET_break_op (0); | 2456 | GNUNET_break_op (0); |
2528 | return GNUNET_OK; | 2457 | return GNUNET_OK; |
2529 | } | 2458 | } |
2530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2459 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size); |
2531 | "MESH: path has %u hops.\n", | ||
2532 | size); | ||
2533 | msg = (struct GNUNET_MESH_ManipulatePath *) message; | 2460 | msg = (struct GNUNET_MESH_ManipulatePath *) message; |
2534 | 2461 | ||
2535 | tid = ntohl (msg->tid); | 2462 | tid = ntohl (msg->tid); |
2536 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | 2463 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; |
2537 | t = tunnel_get (pi, tid); | 2464 | t = tunnel_get (pi, tid); |
2538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2539 | "MESH: path is for tunnel %s [%X].\n", | 2466 | "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi), tid); |
2540 | GNUNET_i2s(pi), | ||
2541 | tid); | ||
2542 | if (NULL == t) | 2467 | if (NULL == t) |
2543 | { | 2468 | { |
2544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n"); | 2469 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n"); |
@@ -2549,15 +2474,12 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2549 | next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | 2474 | next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; |
2550 | t->local_tid = next_local_tid++; | 2475 | t->local_tid = next_local_tid++; |
2551 | next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | 2476 | next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; |
2552 | t->tree = tree_new(t->id.oid); | 2477 | t->tree = tree_new (t->id.oid); |
2553 | 2478 | ||
2554 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); | 2479 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); |
2555 | if (GNUNET_OK != | 2480 | if (GNUNET_OK != |
2556 | GNUNET_CONTAINER_multihashmap_put ( | 2481 | GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t, |
2557 | tunnels, | 2482 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
2558 | &hash, | ||
2559 | t, | ||
2560 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
2561 | { | 2483 | { |
2562 | tunnel_destroy (t); | 2484 | tunnel_destroy (t); |
2563 | GNUNET_break (0); | 2485 | GNUNET_break (0); |
@@ -2566,11 +2488,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2566 | tunnel_reset_timeout (t); | 2488 | tunnel_reset_timeout (t); |
2567 | GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); | 2489 | GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); |
2568 | if (GNUNET_OK != | 2490 | if (GNUNET_OK != |
2569 | GNUNET_CONTAINER_multihashmap_put ( | 2491 | GNUNET_CONTAINER_multihashmap_put (incoming_tunnels, &hash, t, |
2570 | incoming_tunnels, | 2492 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
2571 | &hash, | ||
2572 | t, | ||
2573 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
2574 | { | 2493 | { |
2575 | tunnel_destroy (t); | 2494 | tunnel_destroy (t); |
2576 | GNUNET_break (0); | 2495 | GNUNET_break (0); |
@@ -2604,15 +2523,13 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2604 | own_pos = 0; | 2523 | own_pos = 0; |
2605 | for (i = 0; i < size; i++) | 2524 | for (i = 0; i < size; i++) |
2606 | { | 2525 | { |
2607 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2526 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n", |
2608 | "MESH: ... adding %s\n", | 2527 | GNUNET_i2s (&pi[i])); |
2609 | GNUNET_i2s(&pi[i])); | ||
2610 | path->peers[i] = GNUNET_PEER_intern (&pi[i]); | 2528 | path->peers[i] = GNUNET_PEER_intern (&pi[i]); |
2611 | if (path->peers[i] == myid) | 2529 | if (path->peers[i] == myid) |
2612 | own_pos = i; | 2530 | own_pos = i; |
2613 | } | 2531 | } |
2614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos); |
2615 | "MESH: Own position: %u\n", own_pos); | ||
2616 | if (own_pos == 0) | 2533 | if (own_pos == 0) |
2617 | { | 2534 | { |
2618 | /* cannot be self, must be 'not found' */ | 2535 | /* cannot be self, must be 'not found' */ |
@@ -2630,22 +2547,22 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2630 | struct MeshDataDescriptor *info; | 2547 | struct MeshDataDescriptor *info; |
2631 | unsigned int j; | 2548 | unsigned int j; |
2632 | 2549 | ||
2633 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: It's for us!\n"); |
2634 | "MESH: It's for us!\n"); | ||
2635 | peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO); | 2551 | peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO); |
2636 | if (NULL == t->peers) | 2552 | if (NULL == t->peers) |
2637 | t->peers = GNUNET_CONTAINER_multihashmap_create(4); | 2553 | t->peers = GNUNET_CONTAINER_multihashmap_create (4); |
2638 | GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( | 2554 | GNUNET_break (GNUNET_OK == |
2639 | t->peers, | 2555 | GNUNET_CONTAINER_multihashmap_put (t->peers, |
2640 | &my_full_id.hashPubKey, | 2556 | &my_full_id.hashPubKey, |
2641 | peer_info_get(&my_full_id), | 2557 | peer_info_get |
2642 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 2558 | (&my_full_id), |
2559 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | ||
2643 | /* FIXME use send_message */ | 2560 | /* FIXME use send_message */ |
2644 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); | 2561 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); |
2645 | info->origin = &t->id; | 2562 | info->origin = &t->id; |
2646 | info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); | 2563 | info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
2647 | GNUNET_assert (NULL != info->peer); | 2564 | GNUNET_assert (NULL != info->peer); |
2648 | j = peer_info_transmit_slot(info->peer); | 2565 | j = peer_info_transmit_slot (info->peer); |
2649 | info->handler_n = j; | 2566 | info->handler_n = j; |
2650 | info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK; | 2567 | info->peer->types[j] = GNUNET_MESSAGE_TYPE_MESH_PATH_ACK; |
2651 | info->peer->infos[j] = info; | 2568 | info->peer->infos[j] = info; |
@@ -2654,24 +2571,23 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2654 | GNUNET_TIME_UNIT_FOREVER_REL, peer, | 2571 | GNUNET_TIME_UNIT_FOREVER_REL, peer, |
2655 | sizeof (struct GNUNET_MESH_PathACK), | 2572 | sizeof (struct GNUNET_MESH_PathACK), |
2656 | &send_core_path_ack, info); | 2573 | &send_core_path_ack, info); |
2657 | cmsg.header.size = htons(sizeof(cmsg)); | 2574 | cmsg.header.size = htons (sizeof (cmsg)); |
2658 | cmsg.header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); | 2575 | cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); |
2659 | GNUNET_PEER_resolve(t->id.oid, &cmsg.peer); | 2576 | GNUNET_PEER_resolve (t->id.oid, &cmsg.peer); |
2660 | cmsg.tunnel_id = htonl(t->local_tid); | 2577 | cmsg.tunnel_id = htonl (t->local_tid); |
2661 | GNUNET_SERVER_notification_context_broadcast(nc, &cmsg.header, GNUNET_NO); | 2578 | GNUNET_SERVER_notification_context_broadcast (nc, &cmsg.header, GNUNET_NO); |
2662 | } | 2579 | } |
2663 | else | 2580 | else |
2664 | { | 2581 | { |
2665 | struct MeshPeerPath *path2; | 2582 | struct MeshPeerPath *path2; |
2666 | 2583 | ||
2667 | /* It's for somebody else! Retransmit. */ | 2584 | /* It's for somebody else! Retransmit. */ |
2668 | path2 = path_duplicate(path); | 2585 | path2 = path_duplicate (path); |
2669 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Retransmitting.\n"); |
2670 | "MESH: Retransmitting.\n"); | 2587 | peer_info_add_path (dest_peer_info, path2, GNUNET_NO); |
2671 | peer_info_add_path(dest_peer_info, path2, GNUNET_NO); | 2588 | path2 = path_duplicate (path); |
2672 | path2 = path_duplicate(path); | 2589 | peer_info_add_path_to_origin (orig_peer_info, path2, GNUNET_NO); |
2673 | peer_info_add_path_to_origin(orig_peer_info, path2, GNUNET_NO); | 2590 | send_create_path (dest_peer_info, path, t); |
2674 | send_create_path(dest_peer_info, path, t); | ||
2675 | } | 2591 | } |
2676 | return GNUNET_OK; | 2592 | return GNUNET_OK; |
2677 | } | 2593 | } |
@@ -2693,7 +2609,7 @@ static int | |||
2693 | handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | 2609 | handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, |
2694 | const struct GNUNET_MessageHeader *message, | 2610 | const struct GNUNET_MessageHeader *message, |
2695 | const struct GNUNET_ATS_Information *atsi, | 2611 | const struct GNUNET_ATS_Information *atsi, |
2696 | unsigned int atsi_count) | 2612 | unsigned int atsi_count) |
2697 | { | 2613 | { |
2698 | struct GNUNET_MESH_ManipulatePath *msg; | 2614 | struct GNUNET_MESH_ManipulatePath *msg; |
2699 | struct GNUNET_PeerIdentity *pi; | 2615 | struct GNUNET_PeerIdentity *pi; |
@@ -2704,8 +2620,7 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2704 | size_t size; | 2620 | size_t size; |
2705 | 2621 | ||
2706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2707 | "MESH: Received a PATH DESTROY msg from %s\n", | 2623 | "MESH: Received a PATH DESTROY msg from %s\n", GNUNET_i2s (peer)); |
2708 | GNUNET_i2s(peer)); | ||
2709 | size = ntohs (message->size); | 2624 | size = ntohs (message->size); |
2710 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) | 2625 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) |
2711 | { | 2626 | { |
@@ -2725,15 +2640,12 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2725 | GNUNET_break_op (0); | 2640 | GNUNET_break_op (0); |
2726 | return GNUNET_OK; | 2641 | return GNUNET_OK; |
2727 | } | 2642 | } |
2728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2643 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: path has %u hops.\n", size); |
2729 | "MESH: path has %u hops.\n", | ||
2730 | size); | ||
2731 | 2644 | ||
2732 | msg = (struct GNUNET_MESH_ManipulatePath *) message; | 2645 | msg = (struct GNUNET_MESH_ManipulatePath *) message; |
2733 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | 2646 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; |
2734 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2647 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2735 | "MESH: path is for tunnel %s [%X].\n", | 2648 | "MESH: path is for tunnel %s [%X].\n", GNUNET_i2s (pi), |
2736 | GNUNET_i2s(pi), | ||
2737 | msg->tid); | 2649 | msg->tid); |
2738 | t = tunnel_get (pi, ntohl (msg->tid)); | 2650 | t = tunnel_get (pi, ntohl (msg->tid)); |
2739 | if (NULL == t) | 2651 | if (NULL == t) |
@@ -2747,15 +2659,13 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2747 | own_pos = 0; | 2659 | own_pos = 0; |
2748 | for (i = 0; i < size; i++) | 2660 | for (i = 0; i < size; i++) |
2749 | { | 2661 | { |
2750 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2662 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... adding %s\n", |
2751 | "MESH: ... adding %s\n", | 2663 | GNUNET_i2s (&pi[i])); |
2752 | GNUNET_i2s(&pi[i])); | ||
2753 | path->peers[i] = GNUNET_PEER_intern (&pi[i]); | 2664 | path->peers[i] = GNUNET_PEER_intern (&pi[i]); |
2754 | if (path->peers[i] == myid) | 2665 | if (path->peers[i] == myid) |
2755 | own_pos = i; | 2666 | own_pos = i; |
2756 | } | 2667 | } |
2757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Own position: %u\n", own_pos); |
2758 | "MESH: Own position: %u\n", own_pos); | ||
2759 | if (own_pos < path->length - 1) | 2669 | if (own_pos < path->length - 1) |
2760 | send_message (message, &pi[own_pos + 1]); | 2670 | send_message (message, &pi[own_pos + 1]); |
2761 | tunnel_delete_peer (t, path->peers[path->length - 1]); | 2671 | tunnel_delete_peer (t, path->peers[path->length - 1]); |
@@ -2778,32 +2688,28 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2778 | */ | 2688 | */ |
2779 | static int | 2689 | static int |
2780 | handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer, | 2690 | handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer, |
2781 | const struct GNUNET_MessageHeader *message, | 2691 | const struct GNUNET_MessageHeader *message, |
2782 | const struct GNUNET_ATS_Information *atsi, | 2692 | const struct GNUNET_ATS_Information *atsi, |
2783 | unsigned int atsi_count) | 2693 | unsigned int atsi_count) |
2784 | { | 2694 | { |
2785 | struct GNUNET_MESH_PathBroken *msg; | 2695 | struct GNUNET_MESH_PathBroken *msg; |
2786 | struct MeshTunnel *t; | 2696 | struct MeshTunnel *t; |
2787 | 2697 | ||
2788 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2698 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2789 | "MESH: Received a PATH BROKEN msg from %s\n", | 2699 | "MESH: Received a PATH BROKEN msg from %s\n", GNUNET_i2s (peer)); |
2790 | GNUNET_i2s(peer)); | ||
2791 | msg = (struct GNUNET_MESH_PathBroken *) message; | 2700 | msg = (struct GNUNET_MESH_PathBroken *) message; |
2792 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n", |
2793 | "MESH: regarding %s\n", | 2702 | GNUNET_i2s (&msg->peer1)); |
2794 | GNUNET_i2s(&msg->peer1)); | 2703 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: regarding %s\n", |
2795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2704 | GNUNET_i2s (&msg->peer2)); |
2796 | "MESH: regarding %s\n", | 2705 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); |
2797 | GNUNET_i2s(&msg->peer2)); | ||
2798 | t = tunnel_get(&msg->oid, ntohl (msg->tid)); | ||
2799 | if (NULL == t) | 2706 | if (NULL == t) |
2800 | { | 2707 | { |
2801 | GNUNET_break_op (0); | 2708 | GNUNET_break_op (0); |
2802 | return GNUNET_OK; | 2709 | return GNUNET_OK; |
2803 | } | 2710 | } |
2804 | tunnel_notify_connection_broken(t, | 2711 | tunnel_notify_connection_broken (t, GNUNET_PEER_search (&msg->peer1), |
2805 | GNUNET_PEER_search(&msg->peer1), | 2712 | GNUNET_PEER_search (&msg->peer2)); |
2806 | GNUNET_PEER_search(&msg->peer2)); | ||
2807 | return GNUNET_OK; | 2713 | return GNUNET_OK; |
2808 | 2714 | ||
2809 | } | 2715 | } |
@@ -2825,19 +2731,16 @@ static int | |||
2825 | handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | 2731 | handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, |
2826 | const struct GNUNET_MessageHeader *message, | 2732 | const struct GNUNET_MessageHeader *message, |
2827 | const struct GNUNET_ATS_Information *atsi, | 2733 | const struct GNUNET_ATS_Information *atsi, |
2828 | unsigned int atsi_count) | 2734 | unsigned int atsi_count) |
2829 | { | 2735 | { |
2830 | struct GNUNET_MESH_TunnelDestroy *msg; | 2736 | struct GNUNET_MESH_TunnelDestroy *msg; |
2831 | struct MeshTunnel *t; | 2737 | struct MeshTunnel *t; |
2832 | 2738 | ||
2833 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2834 | "MESH: Got a TUNNEL DESTROY packet from %s\n", | 2740 | "MESH: Got a TUNNEL DESTROY packet from %s\n", GNUNET_i2s (peer)); |
2835 | GNUNET_i2s (peer)); | ||
2836 | msg = (struct GNUNET_MESH_TunnelDestroy *) message; | 2741 | msg = (struct GNUNET_MESH_TunnelDestroy *) message; |
2837 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for tunnel %s [%u]\n", |
2838 | "MESH: for tunnel %s [%u]\n", | 2743 | GNUNET_i2s (&msg->oid), ntohl (msg->tid)); |
2839 | GNUNET_i2s (&msg->oid), | ||
2840 | ntohl (msg->tid)); | ||
2841 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | 2744 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); |
2842 | if (NULL == t) | 2745 | if (NULL == t) |
2843 | { | 2746 | { |
@@ -2878,15 +2781,14 @@ static int | |||
2878 | handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, | 2781 | handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, |
2879 | const struct GNUNET_MessageHeader *message, | 2782 | const struct GNUNET_MessageHeader *message, |
2880 | const struct GNUNET_ATS_Information *atsi, | 2783 | const struct GNUNET_ATS_Information *atsi, |
2881 | unsigned int atsi_count) | 2784 | unsigned int atsi_count) |
2882 | { | 2785 | { |
2883 | struct GNUNET_MESH_Unicast *msg; | 2786 | struct GNUNET_MESH_Unicast *msg; |
2884 | struct MeshTunnel *t; | 2787 | struct MeshTunnel *t; |
2885 | GNUNET_PEER_Id pid; | 2788 | GNUNET_PEER_Id pid; |
2886 | size_t size; | 2789 | size_t size; |
2887 | 2790 | ||
2888 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a unicast packet from %s\n", |
2889 | "MESH: got a unicast packet from %s\n", | ||
2890 | GNUNET_i2s (peer)); | 2792 | GNUNET_i2s (peer)); |
2891 | size = ntohs (message->size); | 2793 | size = ntohs (message->size); |
2892 | if (size < | 2794 | if (size < |
@@ -2897,8 +2799,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2897 | return GNUNET_OK; | 2799 | return GNUNET_OK; |
2898 | } | 2800 | } |
2899 | msg = (struct GNUNET_MESH_Unicast *) message; | 2801 | msg = (struct GNUNET_MESH_Unicast *) message; |
2900 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n", |
2901 | "MESH: of type %u\n", | ||
2902 | ntohs (msg[1].header.type)); | 2803 | ntohs (msg[1].header.type)); |
2903 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | 2804 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); |
2904 | if (NULL == t) | 2805 | if (NULL == t) |
@@ -2908,7 +2809,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2908 | return GNUNET_OK; | 2809 | return GNUNET_OK; |
2909 | } | 2810 | } |
2910 | tunnel_reset_timeout (t); | 2811 | tunnel_reset_timeout (t); |
2911 | pid = GNUNET_PEER_search(&msg->destination); | 2812 | pid = GNUNET_PEER_search (&msg->destination); |
2912 | if (pid == myid) | 2813 | if (pid == myid) |
2913 | { | 2814 | { |
2914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2918,7 +2819,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2918 | } | 2819 | } |
2919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2820 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2920 | "MESH: not for us, retransmitting...\n"); | 2821 | "MESH: not for us, retransmitting...\n"); |
2921 | send_message (message, path_get_first_hop(t->tree, pid)); | 2822 | send_message (message, path_get_first_hop (t->tree, pid)); |
2922 | return GNUNET_OK; | 2823 | return GNUNET_OK; |
2923 | } | 2824 | } |
2924 | 2825 | ||
@@ -2940,14 +2841,13 @@ static int | |||
2940 | handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | 2841 | handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, |
2941 | const struct GNUNET_MessageHeader *message, | 2842 | const struct GNUNET_MessageHeader *message, |
2942 | const struct GNUNET_ATS_Information *atsi, | 2843 | const struct GNUNET_ATS_Information *atsi, |
2943 | unsigned int atsi_count) | 2844 | unsigned int atsi_count) |
2944 | { | 2845 | { |
2945 | struct GNUNET_MESH_Multicast *msg; | 2846 | struct GNUNET_MESH_Multicast *msg; |
2946 | struct MeshTunnel *t; | 2847 | struct MeshTunnel *t; |
2947 | size_t size; | 2848 | size_t size; |
2948 | 2849 | ||
2949 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a multicast packet from %s\n", |
2950 | "MESH: got a multicast packet from %s\n", | ||
2951 | GNUNET_i2s (peer)); | 2851 | GNUNET_i2s (peer)); |
2952 | size = ntohs (message->size); | 2852 | size = ntohs (message->size); |
2953 | if (sizeof (struct GNUNET_MESH_Multicast) + | 2853 | if (sizeof (struct GNUNET_MESH_Multicast) + |
@@ -2973,7 +2873,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2973 | { | 2873 | { |
2974 | send_subscribed_clients (message, &msg[1].header); | 2874 | send_subscribed_clients (message, &msg[1].header); |
2975 | } | 2875 | } |
2976 | tunnel_send_multicast(t, message); | 2876 | tunnel_send_multicast (t, message); |
2977 | return GNUNET_OK; | 2877 | return GNUNET_OK; |
2978 | } | 2878 | } |
2979 | 2879 | ||
@@ -2994,7 +2894,7 @@ static int | |||
2994 | handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, | 2894 | handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, |
2995 | const struct GNUNET_MessageHeader *message, | 2895 | const struct GNUNET_MessageHeader *message, |
2996 | const struct GNUNET_ATS_Information *atsi, | 2896 | const struct GNUNET_ATS_Information *atsi, |
2997 | unsigned int atsi_count) | 2897 | unsigned int atsi_count) |
2998 | { | 2898 | { |
2999 | struct GNUNET_MESH_ToOrigin *msg; | 2899 | struct GNUNET_MESH_ToOrigin *msg; |
3000 | struct GNUNET_PeerIdentity id; | 2900 | struct GNUNET_PeerIdentity id; |
@@ -3002,8 +2902,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3002 | struct MeshTunnel *t; | 2902 | struct MeshTunnel *t; |
3003 | size_t size; | 2903 | size_t size; |
3004 | 2904 | ||
3005 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2905 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got a ToOrigin packet from %s\n", |
3006 | "MESH: got a ToOrigin packet from %s\n", | ||
3007 | GNUNET_i2s (peer)); | 2906 | GNUNET_i2s (peer)); |
3008 | size = ntohs (message->size); | 2907 | size = ntohs (message->size); |
3009 | if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */ | 2908 | if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */ |
@@ -3013,8 +2912,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3013 | return GNUNET_OK; | 2912 | return GNUNET_OK; |
3014 | } | 2913 | } |
3015 | msg = (struct GNUNET_MESH_ToOrigin *) message; | 2914 | msg = (struct GNUNET_MESH_ToOrigin *) message; |
3016 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: of type %u\n", |
3017 | "MESH: of type %u\n", | ||
3018 | ntohs (msg[1].header.type)); | 2916 | ntohs (msg[1].header.type)); |
3019 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | 2917 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); |
3020 | 2918 | ||
@@ -3035,8 +2933,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3035 | if (NULL == t->client) | 2933 | if (NULL == t->client) |
3036 | { | 2934 | { |
3037 | /* got data packet for ownerless tunnel */ | 2935 | /* got data packet for ownerless tunnel */ |
3038 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2936 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: no clients!\n"); |
3039 | "MESH: no clients!\n"); | ||
3040 | GNUNET_break_op (0); | 2937 | GNUNET_break_op (0); |
3041 | return GNUNET_OK; | 2938 | return GNUNET_OK; |
3042 | } | 2939 | } |
@@ -3044,10 +2941,8 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3044 | memcpy (cbuf, message, size); | 2941 | memcpy (cbuf, message, size); |
3045 | copy = (struct GNUNET_MESH_ToOrigin *) cbuf; | 2942 | copy = (struct GNUNET_MESH_ToOrigin *) cbuf; |
3046 | copy->tid = htonl (t->local_tid); | 2943 | copy->tid = htonl (t->local_tid); |
3047 | GNUNET_SERVER_notification_context_unicast (nc, | 2944 | GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, |
3048 | t->client->handle, | 2945 | ©->header, GNUNET_YES); |
3049 | ©->header, | ||
3050 | GNUNET_YES); | ||
3051 | return GNUNET_OK; | 2946 | return GNUNET_OK; |
3052 | } | 2947 | } |
3053 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2948 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -3060,7 +2955,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3060 | GNUNET_break (0); | 2955 | GNUNET_break (0); |
3061 | return GNUNET_OK; | 2956 | return GNUNET_OK; |
3062 | } | 2957 | } |
3063 | GNUNET_PEER_resolve (tree_get_predecessor(t->tree), &id); | 2958 | GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id); |
3064 | send_message (message, &id); | 2959 | send_message (message, &id); |
3065 | 2960 | ||
3066 | return GNUNET_OK; | 2961 | return GNUNET_OK; |
@@ -3083,16 +2978,15 @@ static int | |||
3083 | handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | 2978 | handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, |
3084 | const struct GNUNET_MessageHeader *message, | 2979 | const struct GNUNET_MessageHeader *message, |
3085 | const struct GNUNET_ATS_Information *atsi, | 2980 | const struct GNUNET_ATS_Information *atsi, |
3086 | unsigned int atsi_count) | 2981 | unsigned int atsi_count) |
3087 | { | 2982 | { |
3088 | struct GNUNET_MESH_PathACK *msg; | 2983 | struct GNUNET_MESH_PathACK *msg; |
3089 | struct GNUNET_PeerIdentity id; | 2984 | struct GNUNET_PeerIdentity id; |
3090 | struct MeshPeerInfo *peer_info; | 2985 | struct MeshPeerInfo *peer_info; |
3091 | struct MeshTunnel *t; | 2986 | struct MeshTunnel *t; |
3092 | 2987 | ||
3093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2988 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Received a path ACK msg [%s]\n", |
3094 | "MESH: Received a path ACK msg [%s]\n", | 2989 | GNUNET_i2s (&my_full_id)); |
3095 | GNUNET_i2s(&my_full_id)); | ||
3096 | msg = (struct GNUNET_MESH_PathACK *) message; | 2990 | msg = (struct GNUNET_MESH_PathACK *) message; |
3097 | t = tunnel_get (&msg->oid, msg->tid); | 2991 | t = tunnel_get (&msg->oid, msg->tid); |
3098 | if (NULL == t) | 2992 | if (NULL == t) |
@@ -3116,14 +3010,14 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3116 | t->dht_get_type = NULL; | 3010 | t->dht_get_type = NULL; |
3117 | } | 3011 | } |
3118 | peer_info = peer_info_get (&msg->peer_id); | 3012 | peer_info = peer_info_get (&msg->peer_id); |
3119 | tree_set_status(t->tree, peer_info->id, MESH_PEER_READY); | 3013 | tree_set_status (t->tree, peer_info->id, MESH_PEER_READY); |
3120 | send_client_peer_connected(t, peer_info->id); | 3014 | send_client_peer_connected (t, peer_info->id); |
3121 | return GNUNET_OK; | 3015 | return GNUNET_OK; |
3122 | } | 3016 | } |
3123 | 3017 | ||
3124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3018 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3125 | "MESH: not for us, retransmitting...\n"); | 3019 | "MESH: not for us, retransmitting...\n"); |
3126 | GNUNET_PEER_resolve(tree_get_predecessor(t->tree), &id); | 3020 | GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id); |
3127 | peer_info = peer_info_get (&msg->oid); | 3021 | peer_info = peer_info_get (&msg->oid); |
3128 | if (NULL == peer_info) | 3022 | if (NULL == peer_info) |
3129 | { | 3023 | { |
@@ -3143,13 +3037,13 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
3143 | {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, | 3037 | {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, |
3144 | {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0}, | 3038 | {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0}, |
3145 | {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, | 3039 | {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, |
3146 | sizeof (struct GNUNET_MESH_PathBroken)}, | 3040 | sizeof (struct GNUNET_MESH_PathBroken)}, |
3147 | {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0}, | 3041 | {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0}, |
3148 | {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, | 3042 | {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, |
3149 | {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, | 3043 | {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, |
3150 | {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, | 3044 | {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, |
3151 | {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, | 3045 | {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, |
3152 | sizeof (struct GNUNET_MESH_PathACK)}, | 3046 | sizeof (struct GNUNET_MESH_PathACK)}, |
3153 | {NULL, 0, 0} | 3047 | {NULL, 0, 0} |
3154 | }; | 3048 | }; |
3155 | 3049 | ||
@@ -3161,18 +3055,19 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
3161 | 3055 | ||
3162 | /** | 3056 | /** |
3163 | * deregister_app: iterator for removing each application registered by a client | 3057 | * deregister_app: iterator for removing each application registered by a client |
3164 | * | 3058 | * |
3165 | * @param cls closure | 3059 | * @param cls closure |
3166 | * @param key the hash of the application id (used to access the hashmap) | 3060 | * @param key the hash of the application id (used to access the hashmap) |
3167 | * @param value the value stored at the key (client) | 3061 | * @param value the value stored at the key (client) |
3168 | * | 3062 | * |
3169 | * @return GNUNET_OK on success | 3063 | * @return GNUNET_OK on success |
3170 | */ | 3064 | */ |
3171 | static int | 3065 | static int |
3172 | deregister_app (void *cls, const GNUNET_HashCode * key, void *value) | 3066 | deregister_app (void *cls, const GNUNET_HashCode * key, void *value) |
3173 | { | 3067 | { |
3174 | GNUNET_break (GNUNET_YES == | 3068 | GNUNET_break (GNUNET_YES == |
3175 | GNUNET_CONTAINER_multihashmap_remove (applications, key, value)); | 3069 | GNUNET_CONTAINER_multihashmap_remove (applications, key, |
3070 | value)); | ||
3176 | return GNUNET_OK; | 3071 | return GNUNET_OK; |
3177 | } | 3072 | } |
3178 | 3073 | ||
@@ -3230,8 +3125,9 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3230 | struct MeshTunnel *t = cls; | 3125 | struct MeshTunnel *t = cls; |
3231 | struct GNUNET_MessageHeader *payload; | 3126 | struct GNUNET_MessageHeader *payload; |
3232 | struct GNUNET_MESH_Multicast *msg; | 3127 | struct GNUNET_MESH_Multicast *msg; |
3233 | size_t size = sizeof(struct GNUNET_MESH_Multicast) + | 3128 | size_t size = |
3234 | sizeof(struct GNUNET_MessageHeader); | 3129 | sizeof (struct GNUNET_MESH_Multicast) + |
3130 | sizeof (struct GNUNET_MessageHeader); | ||
3235 | char cbuf[size]; | 3131 | char cbuf[size]; |
3236 | 3132 | ||
3237 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 3133 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
@@ -3241,16 +3137,15 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3241 | t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK; | 3137 | t->path_refresh_task = GNUNET_SCHEDULER_NO_TASK; |
3242 | 3138 | ||
3243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3244 | "MESH: sending keepalive for tunnel %d\n", | 3140 | "MESH: sending keepalive for tunnel %d\n", t->id.tid); |
3245 | t->id.tid); | ||
3246 | 3141 | ||
3247 | msg = (struct GNUNET_MESH_Multicast *) cbuf; | 3142 | msg = (struct GNUNET_MESH_Multicast *) cbuf; |
3248 | msg->header.size = htons (size); | 3143 | msg->header.size = htons (size); |
3249 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); | 3144 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); |
3250 | msg->oid = my_full_id; | 3145 | msg->oid = my_full_id; |
3251 | msg->tid = htonl(t->id.tid); | 3146 | msg->tid = htonl (t->id.tid); |
3252 | payload = (struct GNUNET_MessageHeader *) &msg[1]; | 3147 | payload = (struct GNUNET_MessageHeader *) &msg[1]; |
3253 | payload->size = htons (sizeof(struct GNUNET_MessageHeader)); | 3148 | payload->size = htons (sizeof (struct GNUNET_MessageHeader)); |
3254 | payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE); | 3149 | payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE); |
3255 | tunnel_send_multicast (t, &msg->header); | 3150 | tunnel_send_multicast (t, &msg->header); |
3256 | 3151 | ||
@@ -3280,30 +3175,27 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
3280 | const struct GNUNET_PeerIdentity *get_path, | 3175 | const struct GNUNET_PeerIdentity *get_path, |
3281 | unsigned int get_path_length, | 3176 | unsigned int get_path_length, |
3282 | const struct GNUNET_PeerIdentity *put_path, | 3177 | const struct GNUNET_PeerIdentity *put_path, |
3283 | unsigned int put_path_length, | 3178 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
3284 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) | 3179 | size_t size, const void *data) |
3285 | { | 3180 | { |
3286 | struct MeshPathInfo *path_info = cls; | 3181 | struct MeshPathInfo *path_info = cls; |
3287 | struct MeshPeerPath *p; | 3182 | struct MeshPeerPath *p; |
3288 | struct GNUNET_PeerIdentity pi; | 3183 | struct GNUNET_PeerIdentity pi; |
3289 | int i; | 3184 | int i; |
3290 | 3185 | ||
3291 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got results from DHT!\n"); |
3292 | "MESH: Got results from DHT!\n"); | ||
3293 | GNUNET_PEER_resolve (path_info->peer->id, &pi); | 3187 | GNUNET_PEER_resolve (path_info->peer->id, &pi); |
3294 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", GNUNET_i2s (&pi)); |
3295 | "MESH: for %s\n", | ||
3296 | GNUNET_i2s(&pi)); | ||
3297 | // GNUNET_DHT_get_stop(path_info->peer->dhtget); | 3189 | // GNUNET_DHT_get_stop(path_info->peer->dhtget); |
3298 | // path_info->peer->dhtget = NULL; | 3190 | // path_info->peer->dhtget = NULL; |
3299 | 3191 | ||
3300 | p = path_build_from_dht (get_path, get_path_length, | 3192 | p = path_build_from_dht (get_path, get_path_length, put_path, |
3301 | put_path, put_path_length); | 3193 | put_path_length); |
3302 | peer_info_add_path (path_info->peer, p, GNUNET_NO); | 3194 | peer_info_add_path (path_info->peer, p, GNUNET_NO); |
3303 | for (i = 0; i < path_info->peer->ntunnels; i++) | 3195 | for (i = 0; i < path_info->peer->ntunnels; i++) |
3304 | { | 3196 | { |
3305 | tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer); | 3197 | tunnel_add_peer (path_info->peer->tunnels[i], path_info->peer); |
3306 | peer_info_connect(path_info->peer, path_info->t); | 3198 | peer_info_connect (path_info->peer, path_info->t); |
3307 | } | 3199 | } |
3308 | // GNUNET_free (path_info); | 3200 | // GNUNET_free (path_info); |
3309 | 3201 | ||
@@ -3327,11 +3219,10 @@ static void | |||
3327 | dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, | 3219 | dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, |
3328 | const GNUNET_HashCode * key, | 3220 | const GNUNET_HashCode * key, |
3329 | const struct GNUNET_PeerIdentity *get_path, | 3221 | const struct GNUNET_PeerIdentity *get_path, |
3330 | unsigned int get_path_length, | 3222 | unsigned int get_path_length, |
3331 | const struct GNUNET_PeerIdentity *put_path, | 3223 | const struct GNUNET_PeerIdentity *put_path, |
3332 | unsigned int put_path_length, | 3224 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, |
3333 | enum GNUNET_BLOCK_Type type, size_t size, | 3225 | size_t size, const void *data) |
3334 | const void *data) | ||
3335 | { | 3226 | { |
3336 | const struct GNUNET_PeerIdentity *pi = data; | 3227 | const struct GNUNET_PeerIdentity *pi = data; |
3337 | struct MeshTunnel *t = cls; | 3228 | struct MeshTunnel *t = cls; |
@@ -3345,16 +3236,14 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
3345 | } | 3236 | } |
3346 | GNUNET_assert (NULL != t->client); | 3237 | GNUNET_assert (NULL != t->client); |
3347 | peer_info = peer_info_get (pi); | 3238 | peer_info = peer_info_get (pi); |
3348 | (void) GNUNET_CONTAINER_multihashmap_put ( | 3239 | (void) GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, |
3349 | t->peers, | 3240 | peer_info, |
3350 | &pi->hashPubKey, | 3241 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
3351 | peer_info, | 3242 | |
3352 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 3243 | p = path_build_from_dht (get_path, get_path_length, put_path, |
3353 | 3244 | put_path_length); | |
3354 | p = path_build_from_dht (get_path, get_path_length, | ||
3355 | put_path, put_path_length); | ||
3356 | peer_info_add_path (peer_info, p, GNUNET_NO); | 3245 | peer_info_add_path (peer_info, p, GNUNET_NO); |
3357 | tunnel_add_peer(t, peer_info); | 3246 | tunnel_add_peer (t, peer_info); |
3358 | peer_info_connect (peer_info, t); | 3247 | peer_info_connect (peer_info, t); |
3359 | } | 3248 | } |
3360 | 3249 | ||
@@ -3397,8 +3286,7 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
3397 | if (NULL != c->tunnels) | 3286 | if (NULL != c->tunnels) |
3398 | { | 3287 | { |
3399 | GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, | 3288 | GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, |
3400 | &tunnel_destroy_iterator, | 3289 | &tunnel_destroy_iterator, c); |
3401 | c); | ||
3402 | GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); | 3290 | GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); |
3403 | } | 3291 | } |
3404 | 3292 | ||
@@ -3467,7 +3355,8 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
3467 | #if MESH_DEBUG | 3355 | #if MESH_DEBUG |
3468 | c->id = next_client_id++; | 3356 | c->id = next_client_id++; |
3469 | #endif | 3357 | #endif |
3470 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id, c); | 3358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id, |
3359 | c); | ||
3471 | c->handle = client; | 3360 | c->handle = client; |
3472 | GNUNET_SERVER_client_keep (client); | 3361 | GNUNET_SERVER_client_keep (client); |
3473 | a = (GNUNET_MESH_ApplicationType *) &cc_msg[1]; | 3362 | a = (GNUNET_MESH_ApplicationType *) &cc_msg[1]; |
@@ -3589,20 +3478,16 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
3589 | t->id.oid = myid; | 3478 | t->id.oid = myid; |
3590 | t->local_tid = ntohl (t_msg->tunnel_id); | 3479 | t->local_tid = ntohl (t_msg->tunnel_id); |
3591 | #if MESH_DEBUG | 3480 | #if MESH_DEBUG |
3592 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATED TUNNEL %s [%x] (%x)\n", |
3593 | "MESH: CREATED TUNNEL %s [%x] (%x)\n", | 3482 | GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid); |
3594 | GNUNET_i2s (&my_full_id), | ||
3595 | t->id.tid, | ||
3596 | t->local_tid); | ||
3597 | #endif | 3483 | #endif |
3598 | t->client = c; | 3484 | t->client = c; |
3599 | t->peers = GNUNET_CONTAINER_multihashmap_create (32); | 3485 | t->peers = GNUNET_CONTAINER_multihashmap_create (32); |
3600 | 3486 | ||
3601 | GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); | 3487 | GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); |
3602 | if (GNUNET_OK != | 3488 | if (GNUNET_OK != |
3603 | GNUNET_CONTAINER_multihashmap_put ( | 3489 | GNUNET_CONTAINER_multihashmap_put (c->tunnels, &hash, t, |
3604 | c->tunnels, &hash, t, | 3490 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
3605 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
3606 | { | 3491 | { |
3607 | GNUNET_break (0); | 3492 | GNUNET_break (0); |
3608 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 3493 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
@@ -3611,16 +3496,15 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
3611 | 3496 | ||
3612 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); | 3497 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); |
3613 | if (GNUNET_OK != | 3498 | if (GNUNET_OK != |
3614 | GNUNET_CONTAINER_multihashmap_put ( | 3499 | GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t, |
3615 | tunnels, &hash, t, | 3500 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
3616 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
3617 | { | 3501 | { |
3618 | GNUNET_break (0); | 3502 | GNUNET_break (0); |
3619 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 3503 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3620 | return; | 3504 | return; |
3621 | } | 3505 | } |
3622 | t->tree = tree_new (myid); | 3506 | t->tree = tree_new (myid); |
3623 | tree_set_me(t->tree, myid); | 3507 | tree_set_me (t->tree, myid); |
3624 | 3508 | ||
3625 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3509 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3626 | return; | 3510 | return; |
@@ -3673,11 +3557,11 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client, | |||
3673 | GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash); | 3557 | GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash); |
3674 | t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash); | 3558 | t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash); |
3675 | GNUNET_assert (GNUNET_YES == | 3559 | GNUNET_assert (GNUNET_YES == |
3676 | GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t)); | 3560 | GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t)); |
3677 | 3561 | ||
3678 | t->client = NULL; | 3562 | t->client = NULL; |
3679 | tunnel_send_destroy (t); | 3563 | tunnel_send_destroy (t); |
3680 | tunnel_destroy(t); | 3564 | tunnel_destroy (t); |
3681 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3565 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3682 | return; | 3566 | return; |
3683 | } | 3567 | } |
@@ -3700,7 +3584,7 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client, | |||
3700 | struct MeshTunnel *t; | 3584 | struct MeshTunnel *t; |
3701 | MESH_TunnelNumber tid; | 3585 | MESH_TunnelNumber tid; |
3702 | 3586 | ||
3703 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n"); | 3587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n"); |
3704 | /* Sanity check for client registration */ | 3588 | /* Sanity check for client registration */ |
3705 | if (NULL == (c = client_get (client))) | 3589 | if (NULL == (c = client_get (client))) |
3706 | { | 3590 | { |
@@ -3735,12 +3619,12 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client, | |||
3735 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 3619 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3736 | return; | 3620 | return; |
3737 | } | 3621 | } |
3738 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", | 3622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", |
3739 | GNUNET_i2s(&peer_msg->peer)); | 3623 | GNUNET_i2s (&peer_msg->peer)); |
3740 | peer_info = peer_info_get (&peer_msg->peer); | 3624 | peer_info = peer_info_get (&peer_msg->peer); |
3741 | 3625 | ||
3742 | tunnel_add_peer(t, peer_info); | 3626 | tunnel_add_peer (t, peer_info); |
3743 | peer_info_connect(peer_info, t); | 3627 | peer_info_connect (peer_info, t); |
3744 | 3628 | ||
3745 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3629 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3746 | return; | 3630 | return; |
@@ -3800,12 +3684,11 @@ handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client, | |||
3800 | return; | 3684 | return; |
3801 | } | 3685 | } |
3802 | 3686 | ||
3803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3687 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: for peer %s\n", |
3804 | "MESH: for peer %s\n", | 3688 | GNUNET_i2s (&peer_msg->peer)); |
3805 | GNUNET_i2s(&peer_msg->peer)); | ||
3806 | /* Is the peer in the tunnel? */ | 3689 | /* Is the peer in the tunnel? */ |
3807 | peer_info = GNUNET_CONTAINER_multihashmap_get(t->peers, | 3690 | peer_info = |
3808 | &peer_msg->peer.hashPubKey); | 3691 | GNUNET_CONTAINER_multihashmap_get (t->peers, &peer_msg->peer.hashPubKey); |
3809 | if (NULL == peer_info) | 3692 | if (NULL == peer_info) |
3810 | { | 3693 | { |
3811 | GNUNET_break (0); | 3694 | GNUNET_break (0); |
@@ -3818,7 +3701,7 @@ handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client, | |||
3818 | &peer_msg->peer.hashPubKey); | 3701 | &peer_msg->peer.hashPubKey); |
3819 | 3702 | ||
3820 | send_destroy_path (t, peer_info->id); | 3703 | send_destroy_path (t, peer_info->id); |
3821 | tunnel_delete_peer(t, peer_info->id); | 3704 | tunnel_delete_peer (t, peer_info->id); |
3822 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3705 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3823 | return; | 3706 | return; |
3824 | } | 3707 | } |
@@ -3894,7 +3777,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
3894 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 3777 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
3895 | 3778 | ||
3896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n"); | 3779 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n"); |
3897 | send_client_peer_connected(t, myid); | 3780 | send_client_peer_connected (t, myid); |
3898 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n"); | 3781 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n"); |
3899 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3782 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3900 | return; | 3783 | return; |
@@ -3907,14 +3790,10 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
3907 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n", | 3790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n", |
3908 | GNUNET_h2s (&hash)); | 3791 | GNUNET_h2s (&hash)); |
3909 | t->dht_get_type = | 3792 | t->dht_get_type = |
3910 | GNUNET_DHT_get_start (dht_handle, | 3793 | GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, |
3911 | GNUNET_TIME_UNIT_FOREVER_REL, | 3794 | GNUNET_BLOCK_TYPE_TEST, &hash, 10U, |
3912 | GNUNET_BLOCK_TYPE_TEST, | ||
3913 | &hash, | ||
3914 | 10U, | ||
3915 | GNUNET_DHT_RO_RECORD_ROUTE | | 3795 | GNUNET_DHT_RO_RECORD_ROUTE | |
3916 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 3796 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, 0, |
3917 | NULL, 0, | ||
3918 | &dht_get_type_handler, t); | 3797 | &dht_get_type_handler, t); |
3919 | 3798 | ||
3920 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3799 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -3972,8 +3851,7 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client, | |||
3972 | } | 3851 | } |
3973 | 3852 | ||
3974 | /* Is it a local tunnel? Then, does client own the tunnel? */ | 3853 | /* Is it a local tunnel? Then, does client own the tunnel? */ |
3975 | if (NULL != t->client && | 3854 | if (NULL != t->client && NULL != t->client->handle && |
3976 | NULL != t->client->handle && | ||
3977 | t->client->handle != client) | 3855 | t->client->handle != client) |
3978 | { | 3856 | { |
3979 | GNUNET_break (0); | 3857 | GNUNET_break (0); |
@@ -4074,7 +3952,7 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client, | |||
4074 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 3952 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
4075 | return; | 3953 | return; |
4076 | } | 3954 | } |
4077 | GNUNET_PEER_resolve(t->id.oid, &id); | 3955 | GNUNET_PEER_resolve (t->id.oid, &id); |
4078 | 3956 | ||
4079 | /* Ok, everything is correct, send the message | 3957 | /* Ok, everything is correct, send the message |
4080 | * (pretend we got it from a mesh peer) | 3958 | * (pretend we got it from a mesh peer) |
@@ -4153,16 +4031,16 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client, | |||
4153 | } | 4031 | } |
4154 | 4032 | ||
4155 | { | 4033 | { |
4156 | char buf[ntohs(message->size)]; | 4034 | char buf[ntohs (message->size)]; |
4157 | struct GNUNET_MESH_Multicast *copy; | 4035 | struct GNUNET_MESH_Multicast *copy; |
4158 | 4036 | ||
4159 | copy = (struct GNUNET_MESH_Multicast *)buf; | 4037 | copy = (struct GNUNET_MESH_Multicast *) buf; |
4160 | memcpy(buf, message, ntohs(message->size)); | 4038 | memcpy (buf, message, ntohs (message->size)); |
4161 | copy->oid = my_full_id; | 4039 | copy->oid = my_full_id; |
4162 | copy->tid = htonl(t->id.tid); | 4040 | copy->tid = htonl (t->id.tid); |
4163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4164 | "MESH: calling generic handler...\n"); | 4042 | "MESH: calling generic handler...\n"); |
4165 | handle_mesh_data_multicast(client, &my_full_id, ©->header, NULL, 0); | 4043 | handle_mesh_data_multicast (client, &my_full_id, ©->header, NULL, 0); |
4166 | } | 4044 | } |
4167 | 4045 | ||
4168 | /* receive done gets called when last copy is sent to a neighbor */ | 4046 | /* receive done gets called when last copy is sent to a neighbor */ |
@@ -4213,10 +4091,11 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
4213 | { | 4091 | { |
4214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n"); | 4092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n"); |
4215 | core_handle = server; | 4093 | core_handle = server; |
4216 | if (0 != memcmp(identity, &my_full_id, sizeof(my_full_id)) || NULL == server) | 4094 | if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)) || |
4095 | NULL == server) | ||
4217 | { | 4096 | { |
4218 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n")); | 4097 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("MESH: Wrong CORE service\n")); |
4219 | GNUNET_SCHEDULER_shutdown(); | 4098 | GNUNET_SCHEDULER_shutdown (); |
4220 | } | 4099 | } |
4221 | return; | 4100 | return; |
4222 | } | 4101 | } |
@@ -4240,7 +4119,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4240 | #if MESH_DEBUG_CONNECTION | 4119 | #if MESH_DEBUG_CONNECTION |
4241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); | 4120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); |
4242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", | 4121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", |
4243 | GNUNET_i2s(&my_full_id)); | 4122 | GNUNET_i2s (&my_full_id)); |
4244 | #endif | 4123 | #endif |
4245 | peer_info = peer_info_get (peer); | 4124 | peer_info = peer_info_get (peer); |
4246 | if (myid == peer_info->id) | 4125 | if (myid == peer_info->id) |
@@ -4253,15 +4132,14 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4253 | #if MESH_DEBUG_CONNECTION | 4132 | #if MESH_DEBUG_CONNECTION |
4254 | else | 4133 | else |
4255 | { | 4134 | { |
4256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", | 4135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", GNUNET_i2s (peer)); |
4257 | GNUNET_i2s(peer)); | ||
4258 | } | 4136 | } |
4259 | #endif | 4137 | #endif |
4260 | path = path_new (2); | 4138 | path = path_new (2); |
4261 | path->peers[0] = myid; | 4139 | path->peers[0] = myid; |
4262 | path->peers[1] = peer_info->id; | 4140 | path->peers[1] = peer_info->id; |
4263 | GNUNET_PEER_change_rc(myid, 1); | 4141 | GNUNET_PEER_change_rc (myid, 1); |
4264 | GNUNET_PEER_change_rc(peer_info->id, 1); | 4142 | GNUNET_PEER_change_rc (peer_info->id, 1); |
4265 | peer_info_add_path (peer_info, path, GNUNET_YES); | 4143 | peer_info_add_path (peer_info, path, GNUNET_YES); |
4266 | return; | 4144 | return; |
4267 | } | 4145 | } |
@@ -4290,7 +4168,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
4290 | for (i = 0; i < CORE_QUEUE_SIZE; i++) | 4168 | for (i = 0; i < CORE_QUEUE_SIZE; i++) |
4291 | { | 4169 | { |
4292 | /* TODO: notify that the transmission failed */ | 4170 | /* TODO: notify that the transmission failed */ |
4293 | peer_info_cancel_transmission(pi, i); | 4171 | peer_info_cancel_transmission (pi, i); |
4294 | } | 4172 | } |
4295 | peer_info_remove_path (pi, pi->id, myid); | 4173 | peer_info_remove_path (pi, pi->id, myid); |
4296 | #if MESH_DEBUG_CONNECTION | 4174 | #if MESH_DEBUG_CONNECTION |
@@ -4320,7 +4198,8 @@ static int | |||
4320 | shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value) | 4198 | shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value) |
4321 | { | 4199 | { |
4322 | struct MeshTunnel *t = value; | 4200 | struct MeshTunnel *t = value; |
4323 | tunnel_destroy(t); | 4201 | |
4202 | tunnel_destroy (t); | ||
4324 | return GNUNET_YES; | 4203 | return GNUNET_YES; |
4325 | } | 4204 | } |
4326 | 4205 | ||
@@ -4337,6 +4216,7 @@ static int | |||
4337 | shutdown_peer (void *cls, const GNUNET_HashCode * key, void *value) | 4216 | shutdown_peer (void *cls, const GNUNET_HashCode * key, void *value) |
4338 | { | 4217 | { |
4339 | struct MeshPeerInfo *p = value; | 4218 | struct MeshPeerInfo *p = value; |
4219 | |||
4340 | peer_info_destroy (p); | 4220 | peer_info_destroy (p); |
4341 | return GNUNET_YES; | 4221 | return GNUNET_YES; |
4342 | } | 4222 | } |
@@ -4357,8 +4237,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
4357 | GNUNET_CORE_disconnect (core_handle); | 4237 | GNUNET_CORE_disconnect (core_handle); |
4358 | core_handle = NULL; | 4238 | core_handle = NULL; |
4359 | } | 4239 | } |
4360 | GNUNET_CONTAINER_multihashmap_iterate(tunnels, &shutdown_tunnel, NULL); | 4240 | GNUNET_CONTAINER_multihashmap_iterate (tunnels, &shutdown_tunnel, NULL); |
4361 | GNUNET_CONTAINER_multihashmap_iterate(peers, &shutdown_peer, NULL); | 4241 | GNUNET_CONTAINER_multihashmap_iterate (peers, &shutdown_peer, NULL); |
4362 | if (dht_handle != NULL) | 4242 | if (dht_handle != NULL) |
4363 | { | 4243 | { |
4364 | GNUNET_DHT_disconnect (dht_handle); | 4244 | GNUNET_DHT_disconnect (dht_handle); |
@@ -4414,8 +4294,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
4414 | } | 4294 | } |
4415 | 4295 | ||
4416 | if (GNUNET_OK != | 4296 | if (GNUNET_OK != |
4417 | GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", | 4297 | GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY", |
4418 | &keyfile)) | 4298 | &keyfile)) |
4419 | { | 4299 | { |
4420 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 4300 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
4421 | _ | 4301 | _ |
@@ -4463,8 +4343,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
4463 | nc = GNUNET_SERVER_notification_context_create (server_handle, | 4343 | nc = GNUNET_SERVER_notification_context_create (server_handle, |
4464 | LOCAL_QUEUE_SIZE); | 4344 | LOCAL_QUEUE_SIZE); |
4465 | GNUNET_SERVER_disconnect_notify (server_handle, | 4345 | GNUNET_SERVER_disconnect_notify (server_handle, |
4466 | &handle_local_client_disconnect, | 4346 | &handle_local_client_disconnect, NULL); |
4467 | NULL); | ||
4468 | 4347 | ||
4469 | 4348 | ||
4470 | clients = NULL; | 4349 | clients = NULL; |
@@ -4477,11 +4356,11 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
4477 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); | 4356 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); |
4478 | 4357 | ||
4479 | /* Create a peer_info for the local peer */ | 4358 | /* Create a peer_info for the local peer */ |
4480 | peer = peer_info_get(&my_full_id); | 4359 | peer = peer_info_get (&my_full_id); |
4481 | p = path_new (1); | 4360 | p = path_new (1); |
4482 | p->peers[0] = myid; | 4361 | p->peers[0] = myid; |
4483 | GNUNET_PEER_change_rc (myid, 1); | 4362 | GNUNET_PEER_change_rc (myid, 1); |
4484 | peer_info_add_path(peer, p, GNUNET_YES); | 4363 | peer_info_add_path (peer, p, GNUNET_YES); |
4485 | 4364 | ||
4486 | /* Scheduled the task to clean up when shutdown is called */ | 4365 | /* Scheduled the task to clean up when shutdown is called */ |
4487 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 4366 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |