diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-08-03 19:09:38 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-08-03 19:09:38 +0000 |
commit | e8a32f22c8bceb389a3a6ad053d9d1043e9fa5d8 (patch) | |
tree | a76d9e445b0d6b6a366efed1abbffa75bdb99f18 /src/mesh | |
parent | dd759398ffd8f369b2fabd56ea7d6270c2ea8847 (diff) | |
download | gnunet-e8a32f22c8bceb389a3a6ad053d9d1043e9fa5d8.tar.gz gnunet-e8a32f22c8bceb389a3a6ad053d9d1043e9fa5d8.zip |
Fix some FIXMEs
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 176 |
1 files changed, 89 insertions, 87 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index ef1389960..e1ee58ed9 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -38,7 +38,9 @@ | |||
38 | * - partial disconnect reporting -- same as error reporting? | 38 | * - partial disconnect reporting -- same as error reporting? |
39 | * - add vs create? change vs. keep-alive? same msg or different ones? -- thinking... | 39 | * - add vs create? change vs. keep-alive? same msg or different ones? -- thinking... |
40 | * - speed requirement specification (change?) in mesh API -- API call | 40 | * - speed requirement specification (change?) in mesh API -- API call |
41 | * - add ping message (connection confirmation, others?) | 41 | * - add ping message |
42 | * - add connection confirmation message | ||
43 | * - handle trnsmt_rdy return values | ||
42 | */ | 44 | */ |
43 | 45 | ||
44 | #include "platform.h" | 46 | #include "platform.h" |
@@ -52,7 +54,9 @@ | |||
52 | #include "mesh_protocol.h" | 54 | #include "mesh_protocol.h" |
53 | #include "gnunet_dht_service.h" | 55 | #include "gnunet_dht_service.h" |
54 | 56 | ||
55 | #define REFRESH_PATH_TIME GNUNET_TIME_relative_multiply(\ | 57 | |
58 | #define CORE_QUEUE_SIZE 10 | ||
59 | #define REFRESH_PATH_TIME GNUNET_TIME_relative_multiply(\ | ||
56 | GNUNET_TIME_UNIT_SECONDS,\ | 60 | GNUNET_TIME_UNIT_SECONDS,\ |
57 | 300) | 61 | 300) |
58 | 62 | ||
@@ -125,33 +129,38 @@ struct MeshPeerInfo | |||
125 | /** | 129 | /** |
126 | * ID of the peer | 130 | * ID of the peer |
127 | */ | 131 | */ |
128 | GNUNET_PEER_Id id; | 132 | GNUNET_PEER_Id id; |
129 | 133 | ||
130 | /** | 134 | /** |
131 | * Is the peer reachable? Is the peer even connected? | 135 | * Is the peer reachable? Is the peer even connected? |
132 | */ | 136 | */ |
133 | enum MeshPeerState state; | 137 | enum MeshPeerState state; |
134 | 138 | ||
135 | /** | 139 | /** |
136 | * Last time we heard from this peer | 140 | * Last time we heard from this peer |
137 | */ | 141 | */ |
138 | struct GNUNET_TIME_Absolute last_contact; | 142 | struct GNUNET_TIME_Absolute last_contact; |
139 | 143 | ||
140 | /** | 144 | /** |
141 | * Number of attempts to reconnect so far | 145 | * Number of attempts to reconnect so far |
142 | */ | 146 | */ |
143 | int n_reconnect_attempts; | 147 | int n_reconnect_attempts; |
144 | 148 | ||
145 | /** | 149 | /** |
146 | * Paths to reach the peer | 150 | * Paths to reach the peer |
147 | */ | 151 | */ |
148 | struct MeshPath *path; | 152 | struct MeshPath *path; |
149 | struct MeshPath *path_tail; | 153 | struct MeshPath *path_tail; |
150 | 154 | ||
151 | /** | 155 | /** |
152 | * Handle to stop the DHT search for a path to this peer | 156 | * Handle to stop the DHT search for a path to this peer |
153 | */ | 157 | */ |
154 | struct GNUNET_DHT_GetHandle *dhtget; | 158 | struct GNUNET_DHT_GetHandle *dhtget; |
159 | |||
160 | /** | ||
161 | * Handles to stop queued transmissions for this peer | ||
162 | */ | ||
163 | struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE]; | ||
155 | }; | 164 | }; |
156 | 165 | ||
157 | 166 | ||
@@ -720,24 +729,7 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf) | |||
720 | 729 | ||
721 | 730 | ||
722 | /** | 731 | /** |
723 | * FIXME / COMMENT | 732 | * TODO: build msg and use raw? |
724 | * There are several options to send a "data to origin" or similar packet. | ||
725 | * The core callback function needs to know at least: ID of tunnel and the | ||
726 | * data itself, so one parameter (cls) is not enough. | ||
727 | * 1. Build the message inside the original funtction, call core_ntfy_trnsmt_rdy | ||
728 | * passing the created message as cls | ||
729 | * - # memcpy: 2 (function X: to message struct, callback: from cls to buf) | ||
730 | * - Very messy, original function becomes huge and ugly | ||
731 | * (see "handle_mesh_path_create" for example) | ||
732 | * 2. Create a helper function to build the packet, then call | ||
733 | * core_ntfy_trnsmt_rdy with message as cls. | ||
734 | * - # memcpy: 2 (in helper function data->msg and in callback cls->buf) | ||
735 | * 3. Define new container, pass container with pointers | ||
736 | * - # memcpy = 1 (in callback, cls->buf) | ||
737 | * - Noise: extra containers defined per type of message | ||
738 | * 4. Define a generic container with all possible fields, pass container | ||
739 | * - # memcpy = 1 (in callback, cls->buf) | ||
740 | * - Slight memory waste in malloc'ing the container with extra fields | ||
741 | */ | 733 | */ |
742 | struct MeshDataDescriptor | 734 | struct MeshDataDescriptor |
743 | { | 735 | { |
@@ -747,14 +739,22 @@ struct MeshDataDescriptor | |||
747 | /** Ultimate destination of the packet */ | 739 | /** Ultimate destination of the packet */ |
748 | GNUNET_PEER_Id destination; | 740 | GNUNET_PEER_Id destination; |
749 | 741 | ||
750 | /** Pointer to the data to transmit */ | 742 | /** Number of identical messages sent to different hops (multicast) */ |
751 | void *data; | 743 | unsigned int copies; |
752 | 744 | ||
753 | /** Size of the data */ | 745 | /** Size of the data */ |
754 | size_t size; | 746 | size_t size; |
755 | 747 | ||
756 | /** Client that asked for the transmission */ | 748 | /** Client that asked for the transmission, if any */ |
757 | struct GNUNET_SERVER_Client *client; | 749 | struct GNUNET_SERVER_Client *client; |
750 | |||
751 | /** Who was this message directed to */ | ||
752 | struct MeshPeerInfo *peer; | ||
753 | |||
754 | /** Which handler was used to request the transmission */ | ||
755 | unsigned int handler_n; | ||
756 | |||
757 | /* Data at the end */ | ||
758 | }; | 758 | }; |
759 | 759 | ||
760 | /** | 760 | /** |
@@ -788,8 +788,8 @@ send_core_data_to_origin (void *cls, size_t size, void *buf) | |||
788 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN); | 788 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN); |
789 | GNUNET_PEER_resolve(info->origin->oid, &msg->oid); | 789 | GNUNET_PEER_resolve(info->origin->oid, &msg->oid); |
790 | msg->tid = htonl(info->origin->tid); | 790 | msg->tid = htonl(info->origin->tid); |
791 | if (0 != info->size && NULL != info->data) { | 791 | if (0 != info->size) { |
792 | memcpy(&msg[1], info->data, info->size); | 792 | memcpy(&msg[1], &info[1], info->size); |
793 | } | 793 | } |
794 | if (NULL != info->client) { | 794 | if (NULL != info->client) { |
795 | GNUNET_SERVER_receive_done(info->client, GNUNET_OK); | 795 | GNUNET_SERVER_receive_done(info->client, GNUNET_OK); |
@@ -831,8 +831,8 @@ send_core_data_to_peer (void *cls, size_t size, void *buf) | |||
831 | GNUNET_PEER_resolve(info->origin->oid, &msg->oid); | 831 | GNUNET_PEER_resolve(info->origin->oid, &msg->oid); |
832 | GNUNET_PEER_resolve(info->destination, &msg->destination); | 832 | GNUNET_PEER_resolve(info->destination, &msg->destination); |
833 | msg->tid = htonl(info->origin->tid); | 833 | msg->tid = htonl(info->origin->tid); |
834 | if (0 != info->size && NULL != info->data) { | 834 | if (0 != info->size) { |
835 | memcpy(&msg[1], info->data, info->size); | 835 | memcpy(&msg[1], &info[1], info->size); |
836 | } | 836 | } |
837 | if (NULL != info->client) { | 837 | if (NULL != info->client) { |
838 | GNUNET_SERVER_receive_done(info->client, GNUNET_OK); | 838 | GNUNET_SERVER_receive_done(info->client, GNUNET_OK); |
@@ -854,25 +854,36 @@ send_core_data_to_peer (void *cls, size_t size, void *buf) | |||
854 | * @return number of bytes written to buf | 854 | * @return number of bytes written to buf |
855 | */ | 855 | */ |
856 | static size_t | 856 | static size_t |
857 | send_core_data_raw (void *cls, size_t size, void *buf) | 857 | send_core_data_multicast (void *cls, size_t size, void *buf) |
858 | { | 858 | { |
859 | struct GNUNET_MessageHeader *msg = cls; | 859 | struct MeshDataDescriptor *info = cls; |
860 | size_t total_size; | 860 | struct GNUNET_MESH_DataMessageMulticast *msg = buf; |
861 | 861 | size_t total_size; | |
862 | GNUNET_assert(NULL != msg); | ||
863 | total_size = ntohs(msg->size); | ||
864 | 862 | ||
863 | GNUNET_assert(NULL != info); | ||
864 | total_size = info->size + sizeof(struct GNUNET_MESH_DataMessageMulticast); | ||
865 | GNUNET_assert(total_size < GNUNET_SERVER_MAX_MESSAGE_SIZE); | ||
866 | |||
865 | if (total_size > size) { | 867 | if (total_size > size) { |
866 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 868 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
867 | "not enough buffer to send data futher\n"); | 869 | "not enough buffer to send data futher\n"); |
868 | return 0; | 870 | return 0; |
869 | } | 871 | } |
870 | memcpy(buf, msg, total_size); | 872 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_DATA_MULTICAST); |
873 | msg->header.size = htons(total_size); | ||
874 | GNUNET_PEER_resolve(info->origin->oid, &msg->oid); | ||
875 | msg->tid = htonl(info->origin->tid); | ||
876 | memcpy(&msg[1], &info[1], total_size); | ||
877 | if (0 == --info->copies) { | ||
878 | if (NULL != info->client) { | ||
879 | GNUNET_SERVER_receive_done(info->client, GNUNET_OK); | ||
880 | } | ||
881 | GNUNET_free(info); | ||
882 | } | ||
871 | return total_size; | 883 | return total_size; |
872 | } | 884 | } |
873 | 885 | ||
874 | 886 | ||
875 | #if LATER | ||
876 | /** | 887 | /** |
877 | * Function called to notify a client about the socket | 888 | * Function called to notify a client about the socket |
878 | * being ready to queue more data. "buf" will be | 889 | * being ready to queue more data. "buf" will be |
@@ -885,24 +896,24 @@ send_core_data_raw (void *cls, size_t size, void *buf) | |||
885 | * @return number of bytes written to buf | 896 | * @return number of bytes written to buf |
886 | */ | 897 | */ |
887 | static size_t | 898 | static size_t |
888 | send_core_data_multicast (void *cls, size_t size, void *buf) | 899 | send_core_data_raw (void *cls, size_t size, void *buf) |
889 | { | 900 | { |
890 | struct GNUNET_MESH_DataMessageFromOrigin *msg = cls; | 901 | struct GNUNET_MessageHeader *msg = cls; |
891 | size_t total_size; | 902 | size_t total_size; |
892 | 903 | ||
893 | GNUNET_assert(NULL != msg); | 904 | GNUNET_assert(NULL != msg); |
894 | total_size = ntohs(msg->header.size); | 905 | total_size = ntohs(msg->size); |
895 | 906 | ||
896 | if (total_size > size) { | 907 | if (total_size > size) { |
897 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 908 | GNUNET_break(0); |
898 | "not enough buffer to send data futher\n"); | ||
899 | return 0; | 909 | return 0; |
900 | } | 910 | } |
901 | memcpy(msg, buf, total_size); | 911 | memcpy(buf, msg, total_size); |
902 | return total_size; | 912 | return total_size; |
903 | } | 913 | } |
904 | 914 | ||
905 | 915 | ||
916 | #if LATER | ||
906 | /** | 917 | /** |
907 | * Send another peer a notification to destroy a tunnel | 918 | * Send another peer a notification to destroy a tunnel |
908 | * @param cls The tunnel to destroy | 919 | * @param cls The tunnel to destroy |
@@ -1114,28 +1125,21 @@ handle_mesh_path_create (void *cls, | |||
1114 | return 0; | 1125 | return 0; |
1115 | } | 1126 | } |
1116 | if (own_pos == size - 1) { /* it is for us! */ | 1127 | if (own_pos == size - 1) { /* it is for us! */ |
1117 | add_path_to_origin(orig_peer_info, path); /* inverts path! */ | 1128 | // struct MeshDataDescriptor *info; |
1118 | GNUNET_PEER_resolve(get_first_hop(path), &id); /* path is inverted :) */ | 1129 | |
1119 | /* FIXME / COMMENT | 1130 | /* FIXME: implement real dedicated ACK */ |
1120 | * is it ok to declare variables this way? | 1131 | // add_path_to_origin(orig_peer_info, path); /* inverts path! */ |
1121 | * (style, best practices, etc) | 1132 | // GNUNET_PEER_resolve(get_first_hop(path), &id); /* path is inverted :) */ |
1122 | * This variable is short lived and completely irrelevant for the rest | 1133 | // info = GNUNET_malloc(sizeof(struct MeshDataDescriptor)); |
1123 | * of the function | 1134 | // info->origin = &t->id; |
1124 | */ | 1135 | // GNUNET_CORE_notify_transmit_ready(core_handle, |
1125 | struct MeshDataDescriptor *info = | 1136 | // 0, |
1126 | GNUNET_malloc(sizeof(struct MeshDataDescriptor )); | 1137 | // 0, |
1127 | info->origin = &t->id; | 1138 | // GNUNET_TIME_UNIT_FOREVER_REL, |
1128 | info->data = NULL; | 1139 | // &id, |
1129 | info->size = 0; | 1140 | // sizeof(struct GNUNET_MessageHeader), |
1130 | info->client = NULL; | 1141 | // &send_core_data_to_origin, |
1131 | GNUNET_CORE_notify_transmit_ready(core_handle, | 1142 | // info); |
1132 | 0, | ||
1133 | 0, | ||
1134 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1135 | &id, | ||
1136 | sizeof(struct GNUNET_MessageHeader), | ||
1137 | &send_core_data_to_origin, | ||
1138 | info); | ||
1139 | } else { | 1143 | } else { |
1140 | add_path_to_peer(dest_peer_info, path); | 1144 | add_path_to_peer(dest_peer_info, path); |
1141 | GNUNET_PEER_resolve(get_first_hop(path), &id); | 1145 | GNUNET_PEER_resolve(get_first_hop(path), &id); |
@@ -1196,9 +1200,7 @@ handle_mesh_data_unicast (void *cls, | |||
1196 | if (NULL == pi) { | 1200 | if (NULL == pi) { |
1197 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1201 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1198 | "got invalid data from origin packet: wrong destination\n"); | 1202 | "got invalid data from origin packet: wrong destination\n"); |
1199 | /* TODO are we so nice to try to deliver it anyway? maybe we missed | 1203 | /* TODO maybe feedback, log to statistics |
1200 | * a Create_Path packet that added the peer but we have it in the | ||
1201 | * _global_ peer pool anyway... | ||
1202 | */ | 1204 | */ |
1203 | return GNUNET_OK; | 1205 | return GNUNET_OK; |
1204 | } | 1206 | } |
@@ -1251,9 +1253,8 @@ handle_mesh_data_multicast (void *cls, | |||
1251 | 1253 | ||
1252 | size = ntohs(message->size); | 1254 | size = ntohs(message->size); |
1253 | if (size < sizeof(struct GNUNET_MESH_DataMessageMulticast)) { | 1255 | if (size < sizeof(struct GNUNET_MESH_DataMessageMulticast)) { |
1254 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1256 | GNUNET_break_op (0); |
1255 | "got multicast packet: too short\n"); | 1257 | return GNUNET_OK; |
1256 | return GNUNET_OK; // FIXME maybe SYSERR? peer misbehaving? | ||
1257 | } | 1258 | } |
1258 | msg = (struct GNUNET_MESH_DataMessageMulticast *) message; | 1259 | msg = (struct GNUNET_MESH_DataMessageMulticast *) message; |
1259 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); | 1260 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); |
@@ -1295,8 +1296,7 @@ handle_mesh_data_to_orig (void *cls, | |||
1295 | 1296 | ||
1296 | size = ntohs(message->size); | 1297 | size = ntohs(message->size); |
1297 | if (size < sizeof(struct GNUNET_MESH_DataMessageToOrigin)) { | 1298 | if (size < sizeof(struct GNUNET_MESH_DataMessageToOrigin)) { |
1298 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1299 | GNUNET_break_op (0); |
1299 | "got invalid data to origin packet: too short\n"); | ||
1300 | return GNUNET_OK; // FIXME maybe SYSERR? peer misbehaving? | 1300 | return GNUNET_OK; // FIXME maybe SYSERR? peer misbehaving? |
1301 | } | 1301 | } |
1302 | msg = (struct GNUNET_MESH_DataMessageToOrigin *) message; | 1302 | msg = (struct GNUNET_MESH_DataMessageToOrigin *) message; |
@@ -1311,8 +1311,8 @@ handle_mesh_data_to_orig (void *cls, | |||
1311 | 1311 | ||
1312 | if (t->id.oid == myid) { | 1312 | if (t->id.oid == myid) { |
1313 | if (NULL == t->client) { | 1313 | if (NULL == t->client) { |
1314 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1314 | /* got data packet for ownerless tunnel */ |
1315 | "got data packet for ownerless tunnel\n"); | 1315 | GNUNET_break (0); |
1316 | return GNUNET_OK; | 1316 | return GNUNET_OK; |
1317 | } | 1317 | } |
1318 | // TODO retransmit to client owner | 1318 | // TODO retransmit to client owner |
@@ -1320,8 +1320,8 @@ handle_mesh_data_to_orig (void *cls, | |||
1320 | } | 1320 | } |
1321 | peer_info = get_peer_info(&msg->oid); | 1321 | peer_info = get_peer_info(&msg->oid); |
1322 | if (NULL == peer_info) { | 1322 | if (NULL == peer_info) { |
1323 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1323 | /* unknown origin of tunnel */ |
1324 | "unknown origin of tunnel\n"); | 1324 | GNUNET_break (0); |
1325 | return GNUNET_OK; | 1325 | return GNUNET_OK; |
1326 | } | 1326 | } |
1327 | GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id); | 1327 | GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id); |
@@ -1969,6 +1969,7 @@ handle_local_network_traffic (void *cls, | |||
1969 | struct GNUNET_PeerIdentity next_hop; | 1969 | struct GNUNET_PeerIdentity next_hop; |
1970 | struct MeshDataDescriptor *info; | 1970 | struct MeshDataDescriptor *info; |
1971 | MESH_TunnelNumber tid; | 1971 | MESH_TunnelNumber tid; |
1972 | size_t data_size; | ||
1972 | 1973 | ||
1973 | /* Sanity check for client registration */ | 1974 | /* Sanity check for client registration */ |
1974 | if (NULL == (c = retrieve_client(client))) { | 1975 | if (NULL == (c = retrieve_client(client))) { |
@@ -2014,11 +2015,12 @@ handle_local_network_traffic (void *cls, | |||
2014 | return; | 2015 | return; |
2015 | } | 2016 | } |
2016 | GNUNET_PEER_resolve(get_first_hop(pi->path), &next_hop); | 2017 | GNUNET_PEER_resolve(get_first_hop(pi->path), &next_hop); |
2017 | info = GNUNET_malloc(sizeof(struct MeshDataDescriptor)); | 2018 | data_size = ntohs(message->size) - sizeof(struct GNUNET_MESH_Data); |
2018 | info->data = &data_msg[1]; | 2019 | info = GNUNET_malloc(sizeof(struct MeshDataDescriptor) + data_size); |
2020 | memcpy(&info[1], &data_msg[1], data_size); | ||
2019 | info->destination = pi->id; | 2021 | info->destination = pi->id; |
2020 | info->origin = &t->id; | 2022 | info->origin = &t->id; |
2021 | info->size = ntohs(data_msg->header.size) - sizeof(struct GNUNET_MESH_Data); | 2023 | info->size = data_size; |
2022 | info->client = client; | 2024 | info->client = client; |
2023 | GNUNET_CORE_notify_transmit_ready(core_handle, | 2025 | GNUNET_CORE_notify_transmit_ready(core_handle, |
2024 | 0, | 2026 | 0, |
@@ -2236,7 +2238,7 @@ run (void *cls, | |||
2236 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 2238 | GNUNET_SERVER_add_handlers (server, plugin_handlers); |
2237 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 2239 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
2238 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | 2240 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ |
2239 | 1, /* queue size */ | 2241 | CORE_QUEUE_SIZE, /* queue size */ |
2240 | NULL, /* Closure passed to MESH functions */ | 2242 | NULL, /* Closure passed to MESH functions */ |
2241 | &core_init, /* Call core_init once connected */ | 2243 | &core_init, /* Call core_init once connected */ |
2242 | &core_connect, /* Handle connects */ | 2244 | &core_connect, /* Handle connects */ |