diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/Makefile.am | 4 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 50 | ||||
-rw-r--r-- | src/mesh/mesh_api_new.c | 591 | ||||
-rw-r--r-- | src/mesh/test_mesh_api.c | 49 | ||||
-rw-r--r-- | src/mesh/test_mesh_small.c | 370 | ||||
-rw-r--r-- | src/mesh/test_mesh_small.conf | 4 |
6 files changed, 636 insertions, 432 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index 70c0dc150..1131c07c6 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am | |||
@@ -9,6 +9,8 @@ if USE_COVERAGE | |||
9 | XLIB = -lgcov | 9 | XLIB = -lgcov |
10 | endif | 10 | endif |
11 | 11 | ||
12 | AM_CLFAGS = -g | ||
13 | |||
12 | bin_PROGRAMS = \ | 14 | bin_PROGRAMS = \ |
13 | gnunet-service-mesh | 15 | gnunet-service-mesh |
14 | 16 | ||
@@ -67,7 +69,7 @@ test_mesh_small_DEPENDENCIES = \ | |||
67 | libgnunetmeshnew.la | 69 | libgnunetmeshnew.la |
68 | 70 | ||
69 | if ENABLE_TEST_RUN | 71 | if ENABLE_TEST_RUN |
70 | TESTS = test_mesh_api | 72 | TESTS = test_mesh_small |
71 | endif | 73 | endif |
72 | 74 | ||
73 | EXTRA_DIST = \ | 75 | EXTRA_DIST = \ |
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 338def09a..a5c9b131a 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -55,7 +55,7 @@ | |||
55 | #include "mesh_protocol.h" | 55 | #include "mesh_protocol.h" |
56 | #include "gnunet_dht_service.h" | 56 | #include "gnunet_dht_service.h" |
57 | 57 | ||
58 | #define MESH_DEBUG 0 | 58 | #define MESH_DEBUG GNUNET_YES |
59 | 59 | ||
60 | #if MESH_DEBUG | 60 | #if MESH_DEBUG |
61 | /** | 61 | /** |
@@ -70,7 +70,7 @@ mesh_debug (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
70 | { | 70 | { |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s", s); | 73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s", s); |
74 | } | 74 | } |
75 | #endif | 75 | #endif |
76 | 76 | ||
@@ -462,6 +462,7 @@ GNUNET_SCHEDULER_TaskIdentifier announce_applications_task; | |||
462 | */ | 462 | */ |
463 | GNUNET_SCHEDULER_TaskIdentifier announce_id_task; | 463 | GNUNET_SCHEDULER_TaskIdentifier announce_id_task; |
464 | 464 | ||
465 | |||
465 | /******************************************************************************/ | 466 | /******************************************************************************/ |
466 | /****************** GENERAL HELPER FUNCTIONS ************************/ | 467 | /****************** GENERAL HELPER FUNCTIONS ************************/ |
467 | /******************************************************************************/ | 468 | /******************************************************************************/ |
@@ -818,7 +819,7 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
818 | GNUNET_PEER_resolve (myid, &id); | 819 | GNUNET_PEER_resolve (myid, &id); |
819 | for (i = 0; i < n_applications; i++) | 820 | for (i = 0; i < n_applications; i++) |
820 | { | 821 | { |
821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting PUT for app %d\n", | 822 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for app %d\n", |
822 | applications[i]); | 823 | applications[i]); |
823 | *p = htonl (applications[i]); | 824 | *p = htonl (applications[i]); |
824 | GNUNET_CRYPTO_hash (buffer, 12, &hash); | 825 | GNUNET_CRYPTO_hash (buffer, 12, &hash); |
@@ -829,7 +830,7 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
829 | APP_ANNOUNCE_TIME), | 830 | APP_ANNOUNCE_TIME), |
830 | APP_ANNOUNCE_TIME, | 831 | APP_ANNOUNCE_TIME, |
831 | #if MESH_DEBUG | 832 | #if MESH_DEBUG |
832 | &mesh_debug, "DHT_put for app completed\n"); | 833 | &mesh_debug, "MESH: DHT_put for app completed\n"); |
833 | #else | 834 | #else |
834 | NULL, NULL); | 835 | NULL, NULL); |
835 | #endif | 836 | #endif |
@@ -909,7 +910,7 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf) | |||
909 | 910 | ||
910 | if (0 == size && NULL == buf) | 911 | if (0 == size && NULL == buf) |
911 | { | 912 | { |
912 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n"); | 913 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Retransmitting create path\n"); |
913 | GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); | 914 | GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); |
914 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, | 915 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, |
915 | GNUNET_TIME_UNIT_FOREVER_REL, &id, | 916 | GNUNET_TIME_UNIT_FOREVER_REL, &id, |
@@ -1293,7 +1294,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1293 | struct MeshPeerInfo *orig_peer_info; | 1294 | struct MeshPeerInfo *orig_peer_info; |
1294 | struct MeshTunnel *t; | 1295 | struct MeshTunnel *t; |
1295 | 1296 | ||
1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a MESH path create msg\n"); | 1297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Received a MESH path create msg\n"); |
1297 | size = ntohs (message->size); | 1298 | size = ntohs (message->size); |
1298 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) | 1299 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) |
1299 | { | 1300 | { |
@@ -1324,7 +1325,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1324 | 1325 | ||
1325 | if (NULL == t) | 1326 | if (NULL == t) |
1326 | { | 1327 | { |
1327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tunnel\n"); | 1328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating tunnel\n"); |
1328 | t = GNUNET_malloc (sizeof (struct MeshTunnel)); | 1329 | t = GNUNET_malloc (sizeof (struct MeshTunnel)); |
1329 | t->id.oid = GNUNET_PEER_intern (pi); | 1330 | t->id.oid = GNUNET_PEER_intern (pi); |
1330 | t->id.tid = tid; | 1331 | t->id.tid = tid; |
@@ -1993,7 +1994,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
1993 | unsigned int i; | 1994 | unsigned int i; |
1994 | unsigned int j; | 1995 | unsigned int j; |
1995 | 1996 | ||
1996 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected\n"); | 1997 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: client disconnected\n"); |
1997 | c = clients; | 1998 | c = clients; |
1998 | while (NULL != c) | 1999 | while (NULL != c) |
1999 | { | 2000 | { |
@@ -2044,12 +2045,12 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
2044 | } | 2045 | } |
2045 | else | 2046 | else |
2046 | { | 2047 | { |
2047 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... searching\n"); | 2048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... searching\n"); |
2048 | c = c->next; | 2049 | c = c->next; |
2049 | } | 2050 | } |
2050 | } | 2051 | } |
2051 | 2052 | ||
2052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " done!\n"); | 2053 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: done!\n"); |
2053 | return; | 2054 | return; |
2054 | } | 2055 | } |
2055 | 2056 | ||
@@ -2074,7 +2075,7 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
2074 | uint16_t j; | 2075 | uint16_t j; |
2075 | int known; | 2076 | int known; |
2076 | 2077 | ||
2077 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected\n"); | 2078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: new client connected\n"); |
2078 | /* Check data sanity */ | 2079 | /* Check data sanity */ |
2079 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); | 2080 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); |
2080 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; | 2081 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; |
@@ -2136,7 +2137,7 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
2136 | } | 2137 | } |
2137 | } | 2138 | } |
2138 | } | 2139 | } |
2139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u+%u subscriptions\n", | 2140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: client has %u+%u subscriptions\n", |
2140 | c->type_counter, c->app_counter); | 2141 | c->type_counter, c->app_counter); |
2141 | 2142 | ||
2142 | GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c); | 2143 | GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c); |
@@ -2704,7 +2705,7 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
2704 | const struct GNUNET_PeerIdentity *identity, | 2705 | const struct GNUNET_PeerIdentity *identity, |
2705 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 2706 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
2706 | { | 2707 | { |
2707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n"); | 2708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Core init\n"); |
2708 | core_handle = server; | 2709 | core_handle = server; |
2709 | myid = GNUNET_PEER_intern (identity); | 2710 | myid = GNUNET_PEER_intern (identity); |
2710 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); | 2711 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); |
@@ -2726,11 +2727,11 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2726 | struct MeshPeerInfo *peer_info; | 2727 | struct MeshPeerInfo *peer_info; |
2727 | struct MeshPath *path; | 2728 | struct MeshPath *path; |
2728 | 2729 | ||
2729 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer connected\n"); | 2730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); |
2730 | peer_info = get_peer_info (peer); | 2731 | peer_info = get_peer_info (peer); |
2731 | if (myid == peer_info->id) | 2732 | if (myid == peer_info->id) |
2732 | { | 2733 | { |
2733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (self)\n"); | 2734 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (self)\n"); |
2734 | } | 2735 | } |
2735 | path = GNUNET_malloc (sizeof (struct MeshPath)); | 2736 | path = GNUNET_malloc (sizeof (struct MeshPath)); |
2736 | path->length = 2; | 2737 | path->length = 2; |
@@ -2753,7 +2754,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
2753 | struct MeshPeerInfo *pi; | 2754 | struct MeshPeerInfo *pi; |
2754 | unsigned int i; | 2755 | unsigned int i; |
2755 | 2756 | ||
2756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer disconnected\n"); | 2757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer disconnected\n"); |
2757 | pi = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); | 2758 | pi = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
2758 | if (!pi) | 2759 | if (!pi) |
2759 | { | 2760 | { |
@@ -2771,7 +2772,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
2771 | } | 2772 | } |
2772 | if (myid == pi->id) | 2773 | if (myid == pi->id) |
2773 | { | 2774 | { |
2774 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (self)\n"); | 2775 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (self)\n"); |
2775 | } | 2776 | } |
2776 | return; | 2777 | return; |
2777 | } | 2778 | } |
@@ -2790,7 +2791,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
2790 | static void | 2791 | static void |
2791 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2792 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2792 | { | 2793 | { |
2793 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); | 2794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shutting down\n"); |
2794 | if (core_handle != NULL) | 2795 | if (core_handle != NULL) |
2795 | { | 2796 | { |
2796 | GNUNET_CORE_disconnect (core_handle); | 2797 | GNUNET_CORE_disconnect (core_handle); |
@@ -2806,7 +2807,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2806 | GNUNET_SERVER_notification_context_destroy (nc); | 2807 | GNUNET_SERVER_notification_context_destroy (nc); |
2807 | nc = NULL; | 2808 | nc = NULL; |
2808 | } | 2809 | } |
2809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n"); | 2810 | if (0 != announce_id_task) { |
2811 | GNUNET_SCHEDULER_cancel(announce_id_task); | ||
2812 | announce_id_task = 0; | ||
2813 | } | ||
2814 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: shut down\n"); | ||
2810 | } | 2815 | } |
2811 | 2816 | ||
2812 | /** | 2817 | /** |
@@ -2820,7 +2825,7 @@ static void | |||
2820 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 2825 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
2821 | const struct GNUNET_CONFIGURATION_Handle *c) | 2826 | const struct GNUNET_CONFIGURATION_Handle *c) |
2822 | { | 2827 | { |
2823 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n"); | 2828 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: starting to run\n"); |
2824 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 2829 | GNUNET_SERVER_add_handlers (server, plugin_handlers); |
2825 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 2830 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
2826 | server_handle = server; | 2831 | server_handle = server; |
@@ -2868,7 +2873,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2868 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 2873 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
2869 | NULL); | 2874 | NULL); |
2870 | 2875 | ||
2871 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of run()\n"); | 2876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: end of run()\n"); |
2872 | } | 2877 | } |
2873 | 2878 | ||
2874 | /** | 2879 | /** |
@@ -2883,10 +2888,11 @@ main (int argc, char *const *argv) | |||
2883 | { | 2888 | { |
2884 | int ret; | 2889 | int ret; |
2885 | 2890 | ||
2891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: main()\n"); | ||
2886 | ret = | 2892 | ret = |
2887 | (GNUNET_OK == | 2893 | (GNUNET_OK == |
2888 | GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run, | 2894 | GNUNET_SERVICE_run (argc, argv, "mesh", GNUNET_SERVICE_OPTION_NONE, &run, |
2889 | NULL)) ? 0 : 1; | 2895 | NULL)) ? 0 : 1; |
2890 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of main()\n"); | 2896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: main() END\n"); |
2891 | return ret; | 2897 | return ret; |
2892 | } | 2898 | } |
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index f765aca1c..e2455fac5 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c | |||
@@ -26,8 +26,9 @@ | |||
26 | * STRUCTURE: | 26 | * STRUCTURE: |
27 | * - CONSTANTS | 27 | * - CONSTANTS |
28 | * - DATA STRUCTURES | 28 | * - DATA STRUCTURES |
29 | * - SEND CALLBACKS | 29 | * - AUXILIARY FUNCTIONS |
30 | * - RECEIVE HANDLERS | 30 | * - RECEIVE HANDLERS |
31 | * - SEND CALLBACKS | ||
31 | * - API CALL DEFINITIONS | 32 | * - API CALL DEFINITIONS |
32 | */ | 33 | */ |
33 | 34 | ||
@@ -185,6 +186,207 @@ retrieve_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) | |||
185 | } | 186 | } |
186 | 187 | ||
187 | 188 | ||
189 | |||
190 | /******************************************************************************/ | ||
191 | /*********************** RECEIVE HANDLERS ****************************/ | ||
192 | /******************************************************************************/ | ||
193 | |||
194 | /** | ||
195 | * Process the new tunnel notification and add it to the tunnels in the handle | ||
196 | * | ||
197 | * @param h The mesh handle | ||
198 | * @param msg A message with the details of the new incoming tunnel | ||
199 | */ | ||
200 | static void | ||
201 | process_tunnel_create (struct GNUNET_MESH_Handle *h, | ||
202 | const struct GNUNET_MESH_TunnelMessage *msg) | ||
203 | { | ||
204 | struct GNUNET_MESH_Tunnel *t; | ||
205 | MESH_TunnelNumber tid; | ||
206 | |||
207 | tid = ntohl (msg->tunnel_id); | ||
208 | if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK) | ||
209 | { | ||
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
211 | "MESH: received an incoming tunnel with tid in local range (%X)\n", | ||
212 | tid); | ||
213 | GNUNET_break_op (0); | ||
214 | return; //FIXME abort? reconnect? | ||
215 | } | ||
216 | t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); | ||
217 | t->cls = h->cls; | ||
218 | t->mesh = h; | ||
219 | t->tid = tid; | ||
220 | |||
221 | return; | ||
222 | } | ||
223 | |||
224 | |||
225 | /** | ||
226 | * Process the new peer event and notify the upper level of it | ||
227 | * | ||
228 | * @param h The mesh handle | ||
229 | * @param msg A message with the details of the peer event | ||
230 | */ | ||
231 | static void | ||
232 | process_peer_event (struct GNUNET_MESH_Handle *h, | ||
233 | const struct GNUNET_MESH_PeerControl *msg) | ||
234 | { | ||
235 | struct GNUNET_MESH_Tunnel *t; | ||
236 | uint16_t size; | ||
237 | |||
238 | size = ntohs (msg->header.size); | ||
239 | if (size != sizeof (struct GNUNET_MESH_PeerControl)) | ||
240 | { | ||
241 | GNUNET_break_op (0); | ||
242 | return; | ||
243 | } | ||
244 | t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); | ||
245 | if (NULL == t) | ||
246 | { | ||
247 | GNUNET_break_op (0); | ||
248 | return; | ||
249 | } | ||
250 | if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type) | ||
251 | { | ||
252 | if (NULL != t->connect_handler) | ||
253 | { | ||
254 | t->connect_handler (t->cls, &msg->peer, NULL); /* FIXME atsi */ | ||
255 | } | ||
256 | } | ||
257 | else | ||
258 | { | ||
259 | if (NULL != t->disconnect_handler) | ||
260 | { | ||
261 | t->disconnect_handler (t->cls, &msg->peer); | ||
262 | } | ||
263 | } | ||
264 | } | ||
265 | |||
266 | |||
267 | /** | ||
268 | * Process the incoming data packets | ||
269 | * | ||
270 | * @param h The mesh handle | ||
271 | * @param msh A message encapsulating the data | ||
272 | */ | ||
273 | static void | ||
274 | process_incoming_data (struct GNUNET_MESH_Handle *h, | ||
275 | const struct GNUNET_MessageHeader *message) | ||
276 | { | ||
277 | const struct GNUNET_MessageHeader *payload; | ||
278 | const struct GNUNET_MESH_MessageHandler *handler; | ||
279 | const struct GNUNET_PeerIdentity *peer; | ||
280 | struct GNUNET_MESH_Unicast *ucast; | ||
281 | struct GNUNET_MESH_Multicast *mcast; | ||
282 | struct GNUNET_MESH_ToOrigin *to_orig; | ||
283 | struct GNUNET_MESH_Tunnel *t; | ||
284 | uint16_t type; | ||
285 | int i; | ||
286 | |||
287 | type = ntohs (message->type); | ||
288 | switch (type) | ||
289 | { | ||
290 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
291 | ucast = (struct GNUNET_MESH_Unicast *) message; | ||
292 | t = retrieve_tunnel (h, ntohl (ucast->tid)); | ||
293 | payload = (struct GNUNET_MessageHeader *) &ucast[1]; | ||
294 | peer = &ucast->oid; | ||
295 | break; | ||
296 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: | ||
297 | mcast = (struct GNUNET_MESH_Multicast *) message; | ||
298 | t = retrieve_tunnel (h, ntohl (mcast->tid)); | ||
299 | payload = (struct GNUNET_MessageHeader *) &mcast[1]; | ||
300 | peer = &mcast->oid; | ||
301 | break; | ||
302 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
303 | to_orig = (struct GNUNET_MESH_ToOrigin *) message; | ||
304 | t = retrieve_tunnel (h, ntohl (to_orig->tid)); | ||
305 | payload = (struct GNUNET_MessageHeader *) &to_orig[1]; | ||
306 | peer = &to_orig->sender; | ||
307 | break; | ||
308 | default: | ||
309 | GNUNET_break_op (0); | ||
310 | return; | ||
311 | } | ||
312 | if (NULL == t) | ||
313 | { | ||
314 | GNUNET_break_op (0); | ||
315 | return; | ||
316 | } | ||
317 | for (i = 0; i < h->n_handlers; i++) | ||
318 | { | ||
319 | handler = &h->message_handlers[i]; | ||
320 | if (handler->type == type) | ||
321 | { | ||
322 | if (GNUNET_OK == handler->callback (h->cls, t, NULL, /* FIXME ctx */ | ||
323 | peer, payload, NULL)) /* FIXME atsi */ | ||
324 | { | ||
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
326 | "MESH: callback completed successfully\n"); | ||
327 | } | ||
328 | else | ||
329 | { | ||
330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
331 | "MESH: callback caused disconnection\n"); | ||
332 | GNUNET_MESH_disconnect (h); | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | return; | ||
337 | } | ||
338 | |||
339 | |||
340 | /** | ||
341 | * Function to process all messages received from the service | ||
342 | * | ||
343 | * @param cls closure | ||
344 | * @param msg message received, NULL on timeout or fatal error | ||
345 | */ | ||
346 | static void | ||
347 | msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | ||
348 | { | ||
349 | struct GNUNET_MESH_Handle *h = cls; | ||
350 | |||
351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
352 | "mesh: received a message from MESH\n"); | ||
353 | if (msg == NULL) | ||
354 | { | ||
355 | GNUNET_break_op (0); | ||
356 | return; | ||
357 | } | ||
358 | |||
359 | switch (ntohs (msg->type)) | ||
360 | { | ||
361 | /* Notify of a new incoming tunnel */ | ||
362 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE: | ||
363 | process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg); | ||
364 | break; | ||
365 | /* Notify of a new peer or a peer disconnect in the tunnel */ | ||
366 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED: | ||
367 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED: | ||
368 | process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg); | ||
369 | break; | ||
370 | /* Notify of a new data packet in the tunnel */ | ||
371 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
372 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: | ||
373 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
374 | process_incoming_data (h, msg); | ||
375 | break; | ||
376 | /* We shouldn't get any other packages, log and ignore */ | ||
377 | default: | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
379 | "MESH: unsolicited message form service (type %d)\n", | ||
380 | ntohs (msg->type)); | ||
381 | } | ||
382 | |||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: message processed\n"); | ||
384 | GNUNET_CLIENT_receive (h->client, &msg_received, h, | ||
385 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
386 | return; | ||
387 | } | ||
388 | |||
389 | |||
188 | /******************************************************************************/ | 390 | /******************************************************************************/ |
189 | /************************ SEND CALLBACKS ****************************/ | 391 | /************************ SEND CALLBACKS ****************************/ |
190 | /******************************************************************************/ | 392 | /******************************************************************************/ |
@@ -204,62 +406,67 @@ retrieve_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) | |||
204 | static size_t | 406 | static size_t |
205 | send_connect_packet (void *cls, size_t size, void *buf) | 407 | send_connect_packet (void *cls, size_t size, void *buf) |
206 | { | 408 | { |
207 | struct GNUNET_MESH_Handle *h = cls; | 409 | struct GNUNET_MESH_Handle *h = cls; |
208 | struct GNUNET_MESH_ClientConnect *msg; | 410 | struct GNUNET_MESH_ClientConnect *msg; |
209 | uint16_t *types; | 411 | GNUNET_MESH_ApplicationType *apps; |
210 | uint16_t ntypes; | 412 | uint16_t napps; |
211 | GNUNET_MESH_ApplicationType *apps; | 413 | uint16_t *types; |
212 | uint16_t napps; | 414 | uint16_t ntypes; |
213 | 415 | ||
214 | h->th = NULL; | 416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
215 | if (0 == size || buf == NULL) | 417 | "mesh: Send connect packet()\n", size); |
216 | { | 418 | h->th = NULL; |
217 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 419 | if (0 == size || NULL == buf) |
218 | "Send connect packet: buffer size 0 or buffer invalid\n"); | 420 | { |
219 | // FIXME: disconnect, reconnect, retry! | 421 | // FIXME: disconnect, reconnect, retry? |
220 | return 0; | 422 | return 0; |
221 | } | 423 | } |
222 | if (sizeof (struct GNUNET_MessageHeader) > size) | 424 | if (sizeof (struct GNUNET_MessageHeader) > size) |
223 | { | 425 | { |
224 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 426 | GNUNET_break(0); |
225 | "Send connect packet: buffer size too small\n"); | 427 | // FIXME: disconnect, reconnect, retry! |
226 | // FIXME: disconnect, reconnect, retry! | 428 | return 0; |
227 | return 0; | 429 | } |
228 | } | 430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 431 | "mesh: Send connect packet: %lu bytes buffer\n", size); |
230 | "Send connect packet: %lu bytes buffer\n", size); | 432 | msg = (struct GNUNET_MESH_ClientConnect *) buf; |
231 | msg = (struct GNUNET_MESH_ClientConnect *) buf; | 433 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); |
232 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); | ||
233 | 434 | ||
234 | for (ntypes = 0, types = NULL; ntypes < h->n_handlers; ntypes++) | 435 | for (ntypes = 0, types = NULL; ntypes < h->n_handlers; ntypes++) |
235 | { | 436 | { |
236 | types = GNUNET_realloc (types, sizeof (uint16_t) * (ntypes + 1)); | 437 | types = GNUNET_realloc (types, sizeof (uint16_t) * (ntypes + 1)); |
237 | types[ntypes] = h->message_handlers[ntypes].type; | 438 | types[ntypes] = h->message_handlers[ntypes].type; |
238 | } | 439 | } |
239 | 440 | ||
240 | for (napps = 0, apps = NULL; napps < h->n_applications; napps++) | 441 | for (napps = 0, apps = NULL; napps < h->n_applications; napps++) |
241 | { | 442 | { |
242 | apps = | 443 | apps = |
243 | GNUNET_realloc (apps, | 444 | GNUNET_realloc (apps, |
244 | sizeof (GNUNET_MESH_ApplicationType) * (napps + 1)); | 445 | sizeof (GNUNET_MESH_ApplicationType) * (napps + 1)); |
245 | apps[napps] = h->applications[napps]; | 446 | apps[napps] = h->applications[napps]; |
246 | } | 447 | } |
247 | 448 | ||
248 | msg->header.size = | 449 | msg->header.size = |
249 | htons (sizeof (struct GNUNET_MESH_ClientConnect) + | 450 | htons (sizeof (struct GNUNET_MESH_ClientConnect) + |
250 | sizeof (uint16_t) * ntypes + | 451 | sizeof (uint16_t) * ntypes + |
251 | sizeof (GNUNET_MESH_ApplicationType) * napps); | 452 | sizeof (GNUNET_MESH_ApplicationType) * napps); |
252 | 453 | ||
253 | memcpy (&msg[1], types, sizeof (uint16_t) * ntypes); | 454 | memcpy (&msg[1], types, sizeof (uint16_t) * ntypes); |
254 | memcpy (&msg[1] + sizeof (uint16_t) * ntypes, apps, | 455 | memcpy (&msg[1] + sizeof (uint16_t) * ntypes, apps, |
255 | sizeof (GNUNET_MESH_ApplicationType) * napps); | 456 | sizeof (GNUNET_MESH_ApplicationType) * napps); |
256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
257 | "Sent %lu bytes long message %d types and %d apps\n", | 458 | "mesh: Sent %lu bytes long message %d types and %d apps\n", |
258 | ntohs (msg->header.size), ntypes, napps); | 459 | ntohs (msg->header.size), ntypes, napps); |
259 | msg->applications = htons (napps); | 460 | msg->applications = htons (napps); |
260 | msg->types = htons (ntypes); | 461 | msg->types = htons (ntypes); |
462 | |||
463 | /* start listening */ | ||
464 | GNUNET_CLIENT_receive (h->client, &msg_received, h, | ||
465 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
467 | "mesh: Send connect packet() END\n", size); | ||
261 | 468 | ||
262 | return ntohs (msg->header.size); | 469 | return ntohs (msg->header.size); |
263 | } | 470 | } |
264 | 471 | ||
265 | 472 | ||
@@ -285,22 +492,19 @@ send_tunnel_create_packet (void *cls, size_t size, void *buf) | |||
285 | h->th = NULL; | 492 | h->th = NULL; |
286 | if (0 == size || buf == NULL) | 493 | if (0 == size || buf == NULL) |
287 | { | 494 | { |
288 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 495 | // FIXME: disconnect, reconnect, retry? |
289 | "Send connect packet: buffer size 0 or buffer invalid\n"); | ||
290 | // FIXME: disconnect, reconnect, retry! | ||
291 | return 0; | 496 | return 0; |
292 | } | 497 | } |
293 | if (sizeof (struct GNUNET_MessageHeader) > size) | 498 | if (sizeof (struct GNUNET_MESH_TunnelMessage) > size) |
294 | { | 499 | { |
295 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 500 | GNUNET_break(0); |
296 | "Send connect packet: buffer size too small\n"); | 501 | // FIXME: disconnect, reconnect, retry? |
297 | // FIXME: disconnect, reconnect, retry! | ||
298 | return 0; | 502 | return 0; |
299 | } | 503 | } |
300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
301 | "Send connect packet: %lu bytes buffer\n", size); | 505 | "Send create tunnel packet: %lu bytes buffer\n", size); |
302 | msg = (struct GNUNET_MESH_TunnelMessage *) buf; | 506 | msg = (struct GNUNET_MESH_TunnelMessage *) buf; |
303 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); | 507 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); |
304 | 508 | ||
305 | msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 509 | msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); |
306 | msg->tunnel_id = htonl (t->tid); | 510 | msg->tunnel_id = htonl (t->tid); |
@@ -308,207 +512,56 @@ send_tunnel_create_packet (void *cls, size_t size, void *buf) | |||
308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %lu bytes long message\n", | 512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %lu bytes long message\n", |
309 | ntohs (msg->header.size)); | 513 | ntohs (msg->header.size)); |
310 | 514 | ||
311 | return ntohs (msg->header.size); | 515 | return sizeof (struct GNUNET_MESH_TunnelMessage); |
312 | } | 516 | } |
313 | 517 | ||
314 | 518 | ||
315 | /******************************************************************************/ | ||
316 | /*********************** RECEIVE HANDLERS ****************************/ | ||
317 | /******************************************************************************/ | ||
318 | |||
319 | /** | 519 | /** |
320 | * Process the new tunnel notification and add it to the tunnels in the handle | 520 | * Function called to send a destroy tunnel message, specifying the tunnel |
321 | * | 521 | * number chosen by the client. |
322 | * @param h The mesh handle | 522 | * "buf" will be NULL and "size" zero if the socket was closed for |
323 | * @param msg A message with the details of the new incoming tunnel | 523 | * writing in the meantime. |
324 | */ | 524 | * |
325 | static void | 525 | * @param cls closure, the tunnel handle |
326 | process_tunnel_create (struct GNUNET_MESH_Handle *h, | 526 | * @param size number of bytes available in buf |
327 | const struct GNUNET_MESH_TunnelMessage *msg) | 527 | * @param buf where the callee should write the create tunnel message |
328 | { | 528 | * @return number of bytes written to buf |
329 | struct GNUNET_MESH_Tunnel *t; | ||
330 | MESH_TunnelNumber tid; | ||
331 | |||
332 | tid = ntohl (msg->tunnel_id); | ||
333 | if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK) | ||
334 | { | ||
335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
336 | "MESH: received an incoming tunnel with tid in local range (%X)\n", | ||
337 | tid); | ||
338 | GNUNET_break_op (0); | ||
339 | return; //FIXME abort? reconnect? | ||
340 | } | ||
341 | t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); | ||
342 | t->cls = h->cls; | ||
343 | t->mesh = h; | ||
344 | t->tid = tid; | ||
345 | |||
346 | return; | ||
347 | } | ||
348 | |||
349 | |||
350 | /** | ||
351 | * Process the new peer event and notify the upper level of it | ||
352 | * | ||
353 | * @param h The mesh handle | ||
354 | * @param msg A message with the details of the peer event | ||
355 | */ | 529 | */ |
356 | static void | 530 | static size_t |
357 | process_peer_event (struct GNUNET_MESH_Handle *h, | 531 | send_tunnel_destroy_packet (void *cls, size_t size, void *buf) |
358 | const struct GNUNET_MESH_PeerControl *msg) | ||
359 | { | 532 | { |
360 | struct GNUNET_MESH_Tunnel *t; | 533 | struct GNUNET_MESH_Tunnel *t = cls; |
361 | uint16_t size; | 534 | struct GNUNET_MESH_Handle *h; |
535 | struct GNUNET_MESH_TunnelMessage *msg; | ||
362 | 536 | ||
363 | size = ntohs (msg->header.size); | 537 | h = t->mesh; |
364 | if (size != sizeof (struct GNUNET_MESH_PeerControl)) | 538 | h->th = NULL; |
365 | { | 539 | if (0 == size || buf == NULL) |
366 | GNUNET_break_op (0); | ||
367 | return; | ||
368 | } | ||
369 | t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); | ||
370 | if (NULL == t) | ||
371 | { | ||
372 | GNUNET_break_op (0); | ||
373 | return; | ||
374 | } | ||
375 | if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type) | ||
376 | { | ||
377 | if (NULL != t->connect_handler) | ||
378 | { | 540 | { |
379 | t->connect_handler (t->cls, &msg->peer, NULL); /* FIXME atsi */ | 541 | return 0; |
380 | } | 542 | } |
381 | } | 543 | if (sizeof (struct GNUNET_MESH_TunnelMessage) > size) |
382 | else | ||
383 | { | ||
384 | if (NULL != t->disconnect_handler) | ||
385 | { | 544 | { |
386 | t->disconnect_handler (t->cls, &msg->peer); | 545 | GNUNET_break(0); |
546 | // FIXME: disconnect, reconnect, retry! | ||
547 | return 0; | ||
387 | } | 548 | } |
388 | } | 549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
389 | } | 550 | "Send tunnel destroy packet: %lu bytes buffer\n", size); |
551 | msg = (struct GNUNET_MESH_TunnelMessage *) buf; | ||
552 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); | ||
390 | 553 | ||
554 | msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | ||
555 | msg->tunnel_id = htonl (t->tid); | ||
391 | 556 | ||
392 | /** | 557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %lu bytes long message\n", |
393 | * Process the incoming data packets | 558 | ntohs (msg->header.size)); |
394 | * | 559 | GNUNET_free(t); |
395 | * @param h The mesh handle | ||
396 | * @param msh A message encapsulating the data | ||
397 | */ | ||
398 | static void | ||
399 | process_incoming_data (struct GNUNET_MESH_Handle *h, | ||
400 | const struct GNUNET_MessageHeader *message) | ||
401 | { | ||
402 | const struct GNUNET_MessageHeader *payload; | ||
403 | const struct GNUNET_MESH_MessageHandler *handler; | ||
404 | const struct GNUNET_PeerIdentity *peer; | ||
405 | struct GNUNET_MESH_Unicast *ucast; | ||
406 | struct GNUNET_MESH_Multicast *mcast; | ||
407 | struct GNUNET_MESH_ToOrigin *to_orig; | ||
408 | struct GNUNET_MESH_Tunnel *t; | ||
409 | uint16_t type; | ||
410 | int i; | ||
411 | 560 | ||
412 | type = ntohs (message->type); | 561 | return sizeof (struct GNUNET_MESH_TunnelMessage); |
413 | switch (type) | ||
414 | { | ||
415 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
416 | ucast = (struct GNUNET_MESH_Unicast *) message; | ||
417 | t = retrieve_tunnel (h, ntohl (ucast->tid)); | ||
418 | payload = (struct GNUNET_MessageHeader *) &ucast[1]; | ||
419 | peer = &ucast->oid; | ||
420 | break; | ||
421 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: | ||
422 | mcast = (struct GNUNET_MESH_Multicast *) message; | ||
423 | t = retrieve_tunnel (h, ntohl (mcast->tid)); | ||
424 | payload = (struct GNUNET_MessageHeader *) &mcast[1]; | ||
425 | peer = &mcast->oid; | ||
426 | break; | ||
427 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
428 | to_orig = (struct GNUNET_MESH_ToOrigin *) message; | ||
429 | t = retrieve_tunnel (h, ntohl (to_orig->tid)); | ||
430 | payload = (struct GNUNET_MessageHeader *) &to_orig[1]; | ||
431 | peer = &to_orig->sender; | ||
432 | break; | ||
433 | default: | ||
434 | GNUNET_break_op (0); | ||
435 | return; | ||
436 | } | ||
437 | if (NULL == t) | ||
438 | { | ||
439 | GNUNET_break_op (0); | ||
440 | return; | ||
441 | } | ||
442 | for (i = 0; i < h->n_handlers; i++) | ||
443 | { | ||
444 | handler = &h->message_handlers[i]; | ||
445 | if (handler->type == type) | ||
446 | { | ||
447 | if (GNUNET_OK == handler->callback (h->cls, t, NULL, /* FIXME ctx */ | ||
448 | peer, payload, NULL)) /* FIXME atsi */ | ||
449 | { | ||
450 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
451 | "MESH: callback completed successfully\n"); | ||
452 | } | ||
453 | else | ||
454 | { | ||
455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
456 | "MESH: callback caused disconnection\n"); | ||
457 | GNUNET_MESH_disconnect (h); | ||
458 | } | ||
459 | } | ||
460 | } | ||
461 | return; | ||
462 | } | 562 | } |
463 | 563 | ||
464 | 564 | ||
465 | /** | ||
466 | * Function to process all messages received from the service | ||
467 | * | ||
468 | * @param cls closure | ||
469 | * @param msg message received, NULL on timeout or fatal error | ||
470 | */ | ||
471 | static void | ||
472 | msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | ||
473 | { | ||
474 | struct GNUNET_MESH_Handle *h = cls; | ||
475 | |||
476 | if (msg == NULL) | ||
477 | { | ||
478 | GNUNET_break_op (0); | ||
479 | return; | ||
480 | } | ||
481 | |||
482 | switch (ntohs (msg->type)) | ||
483 | { | ||
484 | /* Notify of a new incoming tunnel */ | ||
485 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE: | ||
486 | process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg); | ||
487 | break; | ||
488 | /* Notify of a new peer or a peer disconnect in the tunnel */ | ||
489 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED: | ||
490 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED: | ||
491 | process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg); | ||
492 | break; | ||
493 | /* Notify of a new data packet in the tunnel */ | ||
494 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | ||
495 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: | ||
496 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | ||
497 | process_incoming_data (h, msg); | ||
498 | break; | ||
499 | /* We shouldn't get any other packages, log and ignore */ | ||
500 | default: | ||
501 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
502 | "MESH: unsolicited message form service (type %d)\n", | ||
503 | ntohs (msg->type)); | ||
504 | } | ||
505 | |||
506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received a message from mesh\n"); | ||
507 | GNUNET_CLIENT_receive (h->client, &msg_received, h, | ||
508 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
509 | return; | ||
510 | } | ||
511 | |||
512 | /******************************************************************************/ | 565 | /******************************************************************************/ |
513 | /********************** API CALL DEFINITIONS *************************/ | 566 | /********************** API CALL DEFINITIONS *************************/ |
514 | /******************************************************************************/ | 567 | /******************************************************************************/ |
@@ -534,17 +587,17 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
534 | const struct GNUNET_MESH_MessageHandler *handlers, | 587 | const struct GNUNET_MESH_MessageHandler *handlers, |
535 | const GNUNET_MESH_ApplicationType *stypes) | 588 | const GNUNET_MESH_ApplicationType *stypes) |
536 | { | 589 | { |
537 | struct GNUNET_MESH_Handle *h; | 590 | struct GNUNET_MESH_Handle *h; |
538 | size_t size; | 591 | size_t size; |
539 | 592 | ||
593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n"); | ||
540 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); | 594 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); |
541 | 595 | ||
542 | h->cleaner = cleaner; | 596 | h->cleaner = cleaner; |
543 | h->client = GNUNET_CLIENT_connect ("mesh", cfg); | 597 | h->client = GNUNET_CLIENT_connect ("mesh", cfg); |
544 | GNUNET_CLIENT_receive (h->client, &msg_received, h, | ||
545 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
546 | if (h->client == NULL) | 598 | if (h->client == NULL) |
547 | { | 599 | { |
600 | GNUNET_break(0); | ||
548 | GNUNET_free (h); | 601 | GNUNET_free (h); |
549 | return NULL; | 602 | return NULL; |
550 | } | 603 | } |
@@ -561,11 +614,18 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
561 | size += h->n_handlers * sizeof (uint16_t); | 614 | size += h->n_handlers * sizeof (uint16_t); |
562 | size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); | 615 | size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); |
563 | 616 | ||
617 | if (NULL != h->th) { | ||
618 | /* FIXME implement queue system instead */ | ||
619 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
620 | "mesh: overwriting th of mesh\n"); | ||
621 | GNUNET_CLIENT_notify_transmit_ready_cancel(h->th); | ||
622 | } | ||
564 | h->th = | 623 | h->th = |
565 | GNUNET_CLIENT_notify_transmit_ready (h->client, size, | 624 | GNUNET_CLIENT_notify_transmit_ready (h->client, size, |
566 | GNUNET_TIME_UNIT_FOREVER_REL, | 625 | GNUNET_TIME_UNIT_FOREVER_REL, |
567 | GNUNET_YES, &send_connect_packet, | 626 | GNUNET_YES, &send_connect_packet, |
568 | (void *) h); | 627 | (void *) h); |
628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n"); | ||
569 | 629 | ||
570 | return h; | 630 | return h; |
571 | } | 631 | } |
@@ -608,7 +668,7 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | |||
608 | { | 668 | { |
609 | struct GNUNET_MESH_Tunnel *tunnel; | 669 | struct GNUNET_MESH_Tunnel *tunnel; |
610 | 670 | ||
611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating new tunnel\n"); | 671 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Creating new tunnel\n"); |
612 | tunnel = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); | 672 | tunnel = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); |
613 | 673 | ||
614 | tunnel->connect_handler = connect_handler; | 674 | tunnel->connect_handler = connect_handler; |
@@ -617,7 +677,12 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | |||
617 | tunnel->mesh = h; | 677 | tunnel->mesh = h; |
618 | tunnel->tid = h->next_tid++; | 678 | tunnel->tid = h->next_tid++; |
619 | h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; // keep in range | 679 | h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; // keep in range |
620 | 680 | if (NULL != h->th) { | |
681 | /* FIXME implement queue system instead */ | ||
682 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
683 | "mesh: overwriting th of mesh\n"); | ||
684 | GNUNET_CLIENT_notify_transmit_ready_cancel(h->th); | ||
685 | } | ||
621 | h->th = | 686 | h->th = |
622 | GNUNET_CLIENT_notify_transmit_ready (h->client, | 687 | GNUNET_CLIENT_notify_transmit_ready (h->client, |
623 | sizeof (struct | 688 | sizeof (struct |
@@ -632,6 +697,32 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | |||
632 | 697 | ||
633 | 698 | ||
634 | /** | 699 | /** |
700 | * Destroy an existing tunnel. | ||
701 | * | ||
702 | * @param tun tunnel handle | ||
703 | */ | ||
704 | void | ||
705 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun) | ||
706 | { | ||
707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); | ||
708 | if (NULL != tun->mesh->th) { | ||
709 | /* FIXME implement queue system instead */ | ||
710 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
711 | "mesh: overwriting th of mesh\n"); | ||
712 | GNUNET_CLIENT_notify_transmit_ready_cancel(tun->mesh->th); | ||
713 | } | ||
714 | tun->mesh->th = GNUNET_CLIENT_notify_transmit_ready ( | ||
715 | tun->mesh->client, | ||
716 | sizeof (struct | ||
717 | GNUNET_MESH_TunnelMessage), | ||
718 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
719 | GNUNET_YES, | ||
720 | &send_tunnel_destroy_packet, | ||
721 | (void *) tun); | ||
722 | } | ||
723 | |||
724 | |||
725 | /** | ||
635 | * Request that a peer should be added to the tunnel. The existing | 726 | * Request that a peer should be added to the tunnel. The existing |
636 | * connect handler will be called ONCE with either success or failure. | 727 | * connect handler will be called ONCE with either success or failure. |
637 | * | 728 | * |
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c index c5f0e9f0f..af6b5e3e7 100644 --- a/src/mesh/test_mesh_api.c +++ b/src/mesh/test_mesh_api.c | |||
@@ -67,25 +67,33 @@ static struct GNUNET_MESH_MessageHandler handlers[] = { {&callback, 1, 0}, | |||
67 | static void | 67 | static void |
68 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 68 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
69 | { | 69 | { |
70 | fprintf(stderr, "++++++++ STARTING SHUTDOWN\n"); | ||
71 | fprintf(stderr, "+++++++++ ABORT TASK\n"); | ||
70 | if (0 != abort_task) | 72 | if (0 != abort_task) |
71 | { | 73 | { |
72 | GNUNET_SCHEDULER_cancel (abort_task); | 74 | GNUNET_SCHEDULER_cancel (abort_task); |
73 | } | 75 | } |
76 | fprintf(stderr, "+++++++++ DISCONNECT MESH\n"); | ||
74 | if (NULL != mesh) | 77 | if (NULL != mesh) |
75 | { | 78 | { |
76 | GNUNET_MESH_disconnect (mesh); | 79 | GNUNET_MESH_disconnect (mesh); |
77 | } | 80 | } |
81 | fprintf(stderr, "+++++++++ KILL PROCESS\n"); | ||
78 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | 82 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) |
79 | { | 83 | { |
80 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 84 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
81 | } | 85 | } |
86 | fprintf(stderr, "+++++++++ WAIT\n"); | ||
82 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); | 87 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); |
88 | fprintf(stderr, "+++++++++ PROCESS CLOSE\n"); | ||
83 | GNUNET_OS_process_close (arm_pid); | 89 | GNUNET_OS_process_close (arm_pid); |
90 | fprintf(stderr, "++++++++ END SHUTDOWN\n"); | ||
84 | } | 91 | } |
85 | 92 | ||
86 | static void | 93 | static void |
87 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 94 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
88 | { | 95 | { |
96 | fprintf(stderr, "++++++++ STARTING ABORT\n"); | ||
89 | if (0 != test_task) | 97 | if (0 != test_task) |
90 | { | 98 | { |
91 | GNUNET_SCHEDULER_cancel (test_task); | 99 | GNUNET_SCHEDULER_cancel (test_task); |
@@ -93,19 +101,18 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
93 | result = GNUNET_SYSERR; | 101 | result = GNUNET_SYSERR; |
94 | abort_task = 0; | 102 | abort_task = 0; |
95 | do_shutdown (cls, tc); | 103 | do_shutdown (cls, tc); |
104 | fprintf(stderr, "++++++++ END ABORT\n"); | ||
96 | } | 105 | } |
97 | 106 | ||
98 | static void | 107 | static void |
99 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 108 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
100 | { | 109 | { |
101 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 110 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
102 | GNUNET_MESH_ApplicationType app[3]; | 111 | static const GNUNET_MESH_ApplicationType app[] = {1,2,3,0}; |
103 | 112 | ||
113 | fprintf(stderr, "++++++++ STARTING TEST\n"); | ||
104 | test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; | 114 | test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; |
105 | app[0] = (GNUNET_MESH_ApplicationType) 1; | 115 | mesh = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, app); |
106 | app[1] = (GNUNET_MESH_ApplicationType) 2; | ||
107 | app[2] = (GNUNET_MESH_ApplicationType) 0; | ||
108 | mesh = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, &app); | ||
109 | if (NULL == mesh) | 116 | if (NULL == mesh) |
110 | { | 117 | { |
111 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n"); | 118 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n"); |
@@ -116,9 +123,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n"); | 123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n"); |
117 | } | 124 | } |
118 | 125 | ||
119 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 126 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3), &do_shutdown, NULL); |
120 | (GNUNET_TIME_UNIT_SECONDS, 1), &do_shutdown, | 127 | fprintf(stderr, "++++++++ END TEST\n"); |
121 | NULL); | ||
122 | } | 128 | } |
123 | 129 | ||
124 | 130 | ||
@@ -126,6 +132,14 @@ static void | |||
126 | run (void *cls, char *const *args, const char *cfgfile, | 132 | run (void *cls, char *const *args, const char *cfgfile, |
127 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 133 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
128 | { | 134 | { |
135 | fprintf(stderr, "++++++++ STARTING RUN\n"); | ||
136 | GNUNET_log_setup ("test_mesh_small", | ||
137 | #if VERBOSE | ||
138 | "DEBUG", | ||
139 | #else | ||
140 | "WARNING", | ||
141 | #endif | ||
142 | NULL); | ||
129 | arm_pid = | 143 | arm_pid = |
130 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 144 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
131 | "gnunet-service-arm", | 145 | "gnunet-service-arm", |
@@ -138,11 +152,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
138 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 152 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
139 | (GNUNET_TIME_UNIT_SECONDS, 20), &do_abort, | 153 | (GNUNET_TIME_UNIT_SECONDS, 20), &do_abort, |
140 | NULL); | 154 | NULL); |
141 | test_task = | 155 | test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &test, (void *)cfg); |
142 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 156 | // GNUNET_SCHEDULER_add_now (&test, (void *)cfg); |
143 | (GNUNET_TIME_UNIT_SECONDS, 1), &test, | ||
144 | (void *) cfg); | ||
145 | 157 | ||
158 | fprintf(stderr, "++++++++ END RUN\n"); | ||
146 | } | 159 | } |
147 | 160 | ||
148 | 161 | ||
@@ -150,7 +163,6 @@ int | |||
150 | main (int argc, char *argv[]) | 163 | main (int argc, char *argv[]) |
151 | { | 164 | { |
152 | int ret; | 165 | int ret; |
153 | |||
154 | char *const argv2[] = { "test-mesh-api", | 166 | char *const argv2[] = { "test-mesh-api", |
155 | "-c", "test_mesh.conf", | 167 | "-c", "test_mesh.conf", |
156 | #if VERBOSE | 168 | #if VERBOSE |
@@ -161,13 +173,8 @@ main (int argc, char *argv[]) | |||
161 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 173 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
162 | GNUNET_GETOPT_OPTION_END | 174 | GNUNET_GETOPT_OPTION_END |
163 | }; | 175 | }; |
164 | GNUNET_log_setup ("test-mesh-api", | 176 | |
165 | #if VERBOSE | 177 | fprintf(stderr, "++++++++ STARTING TEST_API\n"); |
166 | "DEBUG", | ||
167 | #else | ||
168 | "WARNING", | ||
169 | #endif | ||
170 | NULL); | ||
171 | ret = | 178 | ret = |
172 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 179 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, |
173 | "test-mesh-api", "nohelp", options, &run, NULL); | 180 | "test-mesh-api", "nohelp", options, &run, NULL); |
@@ -183,5 +190,7 @@ main (int argc, char *argv[]) | |||
183 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n"); | 190 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n"); |
184 | return 1; | 191 | return 1; |
185 | } | 192 | } |
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n"); | ||
194 | fprintf(stderr, "++++++++ END TEST_API\n"); | ||
186 | return 0; | 195 | return 0; |
187 | } | 196 | } |
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c index 0fd6b0813..30b2d8aef 100644 --- a/src/mesh/test_mesh_small.c +++ b/src/mesh/test_mesh_small.c | |||
@@ -24,9 +24,10 @@ | |||
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_testing_lib.h" | 26 | #include "gnunet_testing_lib.h" |
27 | #include "gnunet_mesh_service.h" | 27 | #include "gnunet_mesh_service_new.h" |
28 | 28 | ||
29 | #define VERBOSE GNUNET_NO | 29 | #define VERBOSE GNUNET_YES |
30 | #define REMOVE_DIR GNUNET_YES | ||
30 | 31 | ||
31 | struct MeshPeer | 32 | struct MeshPeer |
32 | { | 33 | { |
@@ -179,37 +180,105 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
179 | if (data_file != NULL) | 180 | if (data_file != NULL) |
180 | GNUNET_DISK_file_close (data_file); | 181 | GNUNET_DISK_file_close (data_file); |
181 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 182 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
183 | GNUNET_CONFIGURATION_destroy(testing_cfg); | ||
182 | } | 184 | } |
183 | 185 | ||
184 | 186 | ||
187 | /** | ||
188 | * Handlers, for diverse services | ||
189 | */ | ||
190 | static struct GNUNET_MESH_MessageHandler handlers[] = { | ||
191 | // {&callback, 1, 0}, | ||
192 | {NULL, 0, 0} | ||
193 | }; | ||
194 | |||
195 | |||
196 | /** | ||
197 | * Function called whenever an inbound tunnel is destroyed. Should clean up | ||
198 | * any associated state. | ||
199 | * | ||
200 | * @param cls closure (set from GNUNET_MESH_connect) | ||
201 | * @param tunnel connection to the other end (henceforth invalid) | ||
202 | * @param tunnel_ctx place where local state associated | ||
203 | * with the tunnel is stored | ||
204 | */ | ||
205 | static void | ||
206 | tunnel_cleaner (void *cls, | ||
207 | const struct GNUNET_MESH_Tunnel * tunnel, | ||
208 | void **tunnel_ctx) | ||
209 | { | ||
210 | #if VERBOSE | ||
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
212 | "tunnel disconnected\n"); | ||
213 | #endif | ||
214 | return; | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | * Method called whenever a tunnel falls apart. | ||
219 | * | ||
220 | * @param cls closure | ||
221 | * @param peer peer identity the tunnel stopped working with | ||
222 | */ | ||
223 | static void | ||
224 | dh (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
225 | { | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
227 | "peer disconnected\n"); | ||
228 | return; | ||
229 | } | ||
230 | |||
231 | |||
232 | /** | ||
233 | * Method called whenever a tunnel is established. | ||
234 | * | ||
235 | * @param cls closure | ||
236 | * @param peer peer identity the tunnel was created to, NULL on timeout | ||
237 | * @param atsi performance data for the connection | ||
238 | */ | ||
239 | static void | ||
240 | ch (void *cls, | ||
241 | const struct GNUNET_PeerIdentity * peer, | ||
242 | const struct GNUNET_TRANSPORT_ATS_Information * atsi) | ||
243 | { | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
245 | "peer connected\n"); | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | |||
250 | /** | ||
251 | * connect_mesh_service: connect to the mesh service of one of the peers | ||
252 | * | ||
253 | */ | ||
185 | static void | 254 | static void |
186 | connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 255 | connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
187 | { | 256 | { |
188 | // struct NSEPeer *current_peer; | 257 | struct GNUNET_TESTING_Daemon *d; |
189 | unsigned int i; | 258 | struct GNUNET_MESH_Handle *h; |
259 | struct GNUNET_MESH_Tunnel *t; | ||
260 | GNUNET_MESH_ApplicationType app; | ||
261 | |||
262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
263 | "connect_mesh_service\n"); | ||
264 | |||
265 | d = GNUNET_TESTING_daemon_get(pg, 1); | ||
266 | app = (GNUNET_MESH_ApplicationType) 0; | ||
190 | 267 | ||
191 | #if VERBOSE | 268 | #if VERBOSE |
192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to mesh service of peers\n"); | 269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
270 | "connecting to mesh service of peer %s\n", | ||
271 | GNUNET_i2s(&d->id)); | ||
193 | #endif | 272 | #endif |
194 | for (i = 0; i < num_peers; i++) | 273 | h = GNUNET_MESH_connect(d->cfg, NULL, &tunnel_cleaner, handlers, &app); |
195 | { | ||
196 | // if ((connection_limit > 0) && (i % (num_peers / connection_limit) != 0)) | ||
197 | continue; | ||
198 | #if VERBOSE | 274 | #if VERBOSE |
199 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
200 | "test_mesh_small: connecting to mesh service of peer %d\n", i); | 276 | "connected to mesh service of peer %s\n", |
277 | GNUNET_i2s(&d->id)); | ||
201 | #endif | 278 | #endif |
202 | /* current_peer = GNUNET_malloc(sizeof(struct NSEPeer)); | 279 | t = GNUNET_MESH_tunnel_create(h, &ch, &dh, NULL); |
203 | current_peer->daemon = GNUNET_TESTING_daemon_get(pg, i); | 280 | GNUNET_MESH_tunnel_destroy(t); |
204 | if (GNUNET_YES == GNUNET_TESTING_daemon_running(GNUNET_TESTING_daemon_get(pg, i))) | 281 | GNUNET_MESH_disconnect(h); |
205 | { | ||
206 | current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg, | ||
207 | &handle_estimate, | ||
208 | current_peer); | ||
209 | GNUNET_assert(current_peer->nse_handle != NULL); | ||
210 | } | ||
211 | GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);*/ | ||
212 | } | ||
213 | } | 282 | } |
214 | 283 | ||
215 | 284 | ||
@@ -412,39 +481,46 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
412 | } | 481 | } |
413 | 482 | ||
414 | 483 | ||
484 | /** | ||
485 | * peergroup_ready: start test when all peers are connected | ||
486 | * @param cls closure | ||
487 | * @param emsg error message | ||
488 | */ | ||
415 | static void | 489 | static void |
416 | my_cb (void *cls, const char *emsg) | 490 | peergroup_ready (void *cls, const char *emsg) |
417 | { | 491 | { |
418 | char *buf; | 492 | char *buf; |
419 | int buf_len; | 493 | int buf_len; |
494 | |||
495 | if (emsg != NULL) | ||
496 | { | ||
497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
498 | "Peergroup callback called with error, aborting test!\n"); | ||
499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); | ||
500 | ok = 1; | ||
501 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
502 | return; | ||
503 | } | ||
420 | 504 | ||
421 | if (emsg != NULL) | ||
422 | { | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
424 | "Peergroup callback called with error, aborting test!\n"); | ||
425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); | ||
426 | ok = 1; | ||
427 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
428 | return; | ||
429 | } | ||
430 | #if VERBOSE | 505 | #if VERBOSE |
431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n"); | 506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n"); |
432 | #endif | 507 | #endif |
433 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n", | ||
434 | total_connections); | ||
435 | if (data_file != NULL) | ||
436 | { | ||
437 | buf = NULL; | ||
438 | buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections); | ||
439 | if (buf_len > 0) | ||
440 | GNUNET_DISK_file_write (data_file, buf, buf_len); | ||
441 | GNUNET_free (buf); | ||
442 | } | ||
443 | peers_running = GNUNET_TESTING_daemons_running (pg); | ||
444 | 508 | ||
445 | GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); | 509 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n", |
446 | disconnect_task = | 510 | total_connections); |
447 | GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); | 511 | if (data_file != NULL) |
512 | { | ||
513 | buf = NULL; | ||
514 | buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections); | ||
515 | if (buf_len > 0) | ||
516 | GNUNET_DISK_file_write (data_file, buf, buf_len); | ||
517 | GNUNET_free (buf); | ||
518 | } | ||
519 | peers_running = GNUNET_TESTING_daemons_running (pg); | ||
520 | |||
521 | GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); | ||
522 | disconnect_task = | ||
523 | GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); | ||
448 | 524 | ||
449 | } | 525 | } |
450 | 526 | ||
@@ -476,97 +552,121 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, | |||
476 | } | 552 | } |
477 | 553 | ||
478 | 554 | ||
555 | /** | ||
556 | * run: load configuration options and schedule test to run (start peergroup) | ||
557 | * @param cls closure | ||
558 | * @param args argv | ||
559 | * @param cfgfile configuration file name (can be NULL) | ||
560 | * @param cfg configuration handle | ||
561 | */ | ||
479 | static void | 562 | static void |
480 | run (void *cls, char *const *args, const char *cfgfile, | 563 | run (void *cls, char *const *args, const char *cfgfile, |
481 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 564 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
482 | { | 565 | { |
483 | char *temp_str; | 566 | char *temp_str; |
484 | unsigned long long temp_wait; | 567 | unsigned long long temp_wait; |
485 | struct GNUNET_TESTING_Host *hosts; | 568 | struct GNUNET_TESTING_Host *hosts; |
486 | 569 | ||
487 | ok = 1; | 570 | ok = 1; |
488 | testing_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg; // GNUNET_CONFIGURATION_create(); | 571 | testing_cfg = GNUNET_CONFIGURATION_dup(cfg); |
572 | |||
573 | GNUNET_log_setup ("test_mesh_small", | ||
489 | #if VERBOSE | 574 | #if VERBOSE |
490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); | 575 | "DEBUG", |
491 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", | 576 | #else |
492 | "use_progressbars", "YES"); | 577 | "WARNING", |
493 | #endif | 578 | #endif |
494 | if (GNUNET_OK != | 579 | NULL); |
495 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", | ||
496 | "num_peers", &num_peers)) | ||
497 | { | ||
498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
499 | "Option TESTING:NUM_PEERS is required!\n"); | ||
500 | return; | ||
501 | } | ||
502 | 580 | ||
503 | if (GNUNET_OK != | 581 | #if VERBOSE |
504 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", | 582 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); |
505 | "wait_time", &temp_wait)) | 583 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", |
506 | { | 584 | "use_progressbars", "YES"); |
507 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 585 | #endif |
508 | "Option nsetest_mesh_small:wait_time is required!\n"); | ||
509 | return; | ||
510 | } | ||
511 | 586 | ||
512 | if (GNUNET_OK != | 587 | if (GNUNET_OK != |
513 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing", | 588 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", |
514 | "topology_output_file", | 589 | "num_peers", &num_peers)) |
515 | &topology_file)) | 590 | { |
516 | { | 591 | GNUNET_CONFIGURATION_load(testing_cfg, "test_mesh_small.conf"); |
517 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 592 | if (GNUNET_OK != |
518 | "Option test_mesh_small:topology_output_file is required!\n"); | 593 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", |
519 | return; | 594 | "num_peers", &num_peers)) |
520 | } | 595 | { |
596 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
597 | "Option TESTING:NUM_PEERS is required!\n"); | ||
598 | return; | ||
599 | } | ||
600 | } | ||
521 | 601 | ||
522 | if (GNUNET_OK != | 602 | if (GNUNET_OK != |
523 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small", | 603 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", |
524 | "data_output_file", | 604 | "wait_time", &temp_wait)) |
525 | &data_filename)) | 605 | { |
526 | { | 606 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
527 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 607 | "Option nsetest_mesh_small:wait_time is required!\n"); |
528 | "Option test_mesh_small:data_output_file is required!\n"); | 608 | return; |
529 | return; | 609 | } |
530 | } | ||
531 | 610 | ||
532 | data_file = | 611 | if (GNUNET_OK != |
533 | GNUNET_DISK_file_open (data_filename, | 612 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing", |
534 | GNUNET_DISK_OPEN_READWRITE | | 613 | "topology_output_file", |
535 | GNUNET_DISK_OPEN_CREATE, | 614 | &topology_file)) |
536 | GNUNET_DISK_PERM_USER_READ | | 615 | { |
537 | GNUNET_DISK_PERM_USER_WRITE); | 616 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
538 | if (data_file == NULL) | 617 | "Option test_mesh_small:topology_output_file is required!\n"); |
539 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | 618 | return; |
540 | data_filename); | 619 | } |
541 | GNUNET_free (data_filename); | 620 | |
542 | 621 | if (GNUNET_OK != | |
543 | wait_time = | 622 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small", |
544 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); | 623 | "data_output_file", |
545 | 624 | &data_filename)) | |
546 | if (GNUNET_YES == | 625 | { |
547 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", | 626 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
548 | "output_file", &temp_str)) | 627 | "Option test_mesh_small:data_output_file is required!\n"); |
549 | { | 628 | return; |
550 | output_file = | 629 | } |
551 | GNUNET_DISK_file_open (temp_str, | ||
552 | GNUNET_DISK_OPEN_READWRITE | | ||
553 | GNUNET_DISK_OPEN_CREATE, | ||
554 | GNUNET_DISK_PERM_USER_READ | | ||
555 | GNUNET_DISK_PERM_USER_WRITE); | ||
556 | if (output_file == NULL) | ||
557 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | ||
558 | temp_str); | ||
559 | } | ||
560 | GNUNET_free_non_null (temp_str); | ||
561 | 630 | ||
562 | hosts = GNUNET_TESTING_hosts_load (testing_cfg); | 631 | data_file = GNUNET_DISK_file_open (data_filename, |
632 | GNUNET_DISK_OPEN_READWRITE | | ||
633 | GNUNET_DISK_OPEN_CREATE, | ||
634 | GNUNET_DISK_PERM_USER_READ | | ||
635 | GNUNET_DISK_PERM_USER_WRITE); | ||
636 | if (data_file == NULL) { | ||
637 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
638 | "Failed to open %s for output!\n", | ||
639 | data_filename); | ||
640 | GNUNET_free (data_filename); | ||
641 | } | ||
642 | |||
643 | wait_time = | ||
644 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); | ||
563 | 645 | ||
564 | pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT, | 646 | if (GNUNET_YES == |
565 | &connect_cb, &my_cb, NULL, hosts); | 647 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", |
566 | GNUNET_assert (pg != NULL); | 648 | "output_file", &temp_str)) |
567 | shutdown_handle = | 649 | { |
568 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (), | 650 | output_file = GNUNET_DISK_file_open (temp_str, |
569 | &shutdown_task, NULL); | 651 | GNUNET_DISK_OPEN_READWRITE | |
652 | GNUNET_DISK_OPEN_CREATE, | ||
653 | GNUNET_DISK_PERM_USER_READ | | ||
654 | GNUNET_DISK_PERM_USER_WRITE); | ||
655 | if (output_file == NULL) | ||
656 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
657 | "Failed to open %s for output!\n", | ||
658 | temp_str); | ||
659 | } | ||
660 | GNUNET_free_non_null (temp_str); | ||
661 | |||
662 | hosts = GNUNET_TESTING_hosts_load (testing_cfg); | ||
663 | |||
664 | pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT, | ||
665 | &connect_cb, &peergroup_ready, NULL, hosts); | ||
666 | GNUNET_assert (pg != NULL); | ||
667 | shutdown_handle = GNUNET_SCHEDULER_add_delayed ( | ||
668 | GNUNET_TIME_relative_get_forever (), | ||
669 | &shutdown_task, NULL); | ||
570 | } | 670 | } |
571 | 671 | ||
572 | 672 | ||
@@ -582,23 +682,19 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
582 | }; | 682 | }; |
583 | 683 | ||
584 | 684 | ||
685 | /** | ||
686 | * Main: start test | ||
687 | */ | ||
585 | int | 688 | int |
586 | main (int argc, char *argv[]) | 689 | main (int argc, char *argv[]) |
587 | { | 690 | { |
588 | GNUNET_log_setup ("test_mesh_small", | 691 | GNUNET_PROGRAM_run (argc, argv, "test_mesh_small", |
589 | #if VERBOSE | ||
590 | "DEBUG", | ||
591 | #else | ||
592 | "WARNING", | ||
593 | #endif | ||
594 | NULL); | ||
595 | GNUNET_PROGRAM_run (argc, argv, "test_mesh_small", | ||
596 | gettext_noop ("Test mesh in a small network."), options, | 692 | gettext_noop ("Test mesh in a small network."), options, |
597 | &run, NULL); | 693 | &run, NULL); |
598 | #if REMOVE_DIR | 694 | #if REMOVE_DIR |
599 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); | 695 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); |
600 | #endif | 696 | #endif |
601 | return ok; | 697 | return ok; |
602 | } | 698 | } |
603 | 699 | ||
604 | /* end of test_mesh_small.c */ | 700 | /* end of test_mesh_small.c */ |
diff --git a/src/mesh/test_mesh_small.conf b/src/mesh/test_mesh_small.conf index 7c33c5652..d016e1dea 100644 --- a/src/mesh/test_mesh_small.conf +++ b/src/mesh/test_mesh_small.conf | |||
@@ -114,7 +114,7 @@ CONNECT_TOPOLOGY = RING | |||
114 | F2F = NO | 114 | F2F = NO |
115 | CONNECT_TIMEOUT = 60 | 115 | CONNECT_TIMEOUT = 60 |
116 | CONNECT_ATTEMPTS = 3 | 116 | CONNECT_ATTEMPTS = 3 |
117 | #DEBUG = YES | 117 | DEBUG = YES |
118 | HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat | 118 | HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat |
119 | MAX_CONCURRENT_SSH = 10 | 119 | MAX_CONCURRENT_SSH = 10 |
120 | USE_PROGRESSBARS = YES | 120 | USE_PROGRESSBARS = YES |
@@ -128,6 +128,6 @@ MAX_OUTSTANDING_CONNECTIONS = 75 | |||
128 | DELETE_FILES = YES | 128 | DELETE_FILES = YES |
129 | 129 | ||
130 | [test_mesh_small] | 130 | [test_mesh_small] |
131 | WAIT_TIME = 10 | 131 | WAIT_TIME = 2 |
132 | CONNECTION_LIMIT = 10 | 132 | CONNECTION_LIMIT = 10 |
133 | DATA_OUTPUT_FILE=data_output \ No newline at end of file | 133 | DATA_OUTPUT_FILE=data_output \ No newline at end of file |