aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mesh/Makefile.am2
-rw-r--r--src/mesh/gnunet-service-mesh.c94
-rw-r--r--src/mesh/mesh.h8
-rw-r--r--src/mesh/mesh_api_new.c25
-rw-r--r--src/mesh/test_mesh.conf2
-rw-r--r--src/mesh/test_mesh_local.c147
6 files changed, 171 insertions, 107 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am
index f49b3e326..0c7d598d4 100644
--- a/src/mesh/Makefile.am
+++ b/src/mesh/Makefile.am
@@ -77,7 +77,7 @@ test_mesh_small_DEPENDENCIES = \
77 libgnunetmeshnew.la 77 libgnunetmeshnew.la
78 78
79if ENABLE_TEST_RUN 79if ENABLE_TEST_RUN
80TESTS = test_mesh_api test_mesh_local 80TESTS = test_mesh_api
81endif 81endif
82 82
83EXTRA_DIST = \ 83EXTRA_DIST = \
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 6ca5b3bec..9734fe4d9 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -82,11 +82,11 @@ mesh_debug (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
82 300) 82 300)
83#define APP_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\ 83#define APP_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\
84 GNUNET_TIME_UNIT_SECONDS,\ 84 GNUNET_TIME_UNIT_SECONDS,\
85 60) 85 5)
86 86
87#define ID_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\ 87#define ID_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\
88 GNUNET_TIME_UNIT_SECONDS,\ 88 GNUNET_TIME_UNIT_SECONDS,\
89 300) 89 5)
90 90
91 91
92 92
@@ -833,10 +833,12 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
833 announce_applications_task = GNUNET_SCHEDULER_NO_TASK; 833 announce_applications_task = GNUNET_SCHEDULER_NO_TASK;
834 return; 834 return;
835 } 835 }
836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for %u apps\n",
837 n_apps);
836 p = (unsigned int *) &buffer[8]; 838 p = (unsigned int *) &buffer[8];
837 for (i = 0; i < n_apps; i++) 839 for (i = 0; i < n_apps; i++)
838 { 840 {
839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for app %d\n", 841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for app %u\n",
840 applications[i]); 842 applications[i]);
841 *p = htonl (applications[i]); 843 *p = htonl (applications[i]);
842 GNUNET_CRYPTO_hash (buffer, 12, &hash); 844 GNUNET_CRYPTO_hash (buffer, 12, &hash);
@@ -847,7 +849,7 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
847 APP_ANNOUNCE_TIME), 849 APP_ANNOUNCE_TIME),
848 APP_ANNOUNCE_TIME, 850 APP_ANNOUNCE_TIME,
849#if MESH_DEBUG 851#if MESH_DEBUG
850 &mesh_debug, "MESH: DHT_put for apps completed\n"); 852 &mesh_debug, "DHT_put for apps completed\n");
851#else 853#else
852 NULL, NULL); 854 NULL, NULL);
853#endif 855#endif
@@ -2018,7 +2020,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
2018 c = c->next; 2020 c = c->next;
2019 continue; 2021 continue;
2020 } 2022 }
2021 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " matching client found, cleaning\n"); 2023 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n");
2022 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry, c); 2024 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry, c);
2023 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); 2025 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
2024 if (0 != c->app_counter) 2026 if (0 != c->app_counter)
@@ -2072,8 +2074,10 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
2072{ 2074{
2073 struct GNUNET_MESH_ClientConnect *cc_msg; 2075 struct GNUNET_MESH_ClientConnect *cc_msg;
2074 struct MeshClient *c; 2076 struct MeshClient *c;
2077 GNUNET_MESH_ApplicationType *a;
2075 unsigned int size; 2078 unsigned int size;
2076 uint16_t types; 2079 uint16_t types;
2080 uint16_t *t;
2077 uint16_t apps; 2081 uint16_t apps;
2078 uint16_t i; 2082 uint16_t i;
2079 uint16_t j; 2083 uint16_t j;
@@ -2096,45 +2100,52 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
2096 /* Create new client structure */ 2100 /* Create new client structure */
2097 c = GNUNET_malloc (sizeof (struct MeshClient)); 2101 c = GNUNET_malloc (sizeof (struct MeshClient));
2098 c->handle = client; 2102 c->handle = client;
2099 if (types != 0) 2103 a = (GNUNET_MESH_ApplicationType *) &cc_msg[1];
2100 { 2104 if (apps > 0)
2101 c->type_counter = types;
2102 c->types = GNUNET_malloc (types * sizeof (uint16_t));
2103 memcpy (c->types, &message[1], types * sizeof (uint16_t));
2104 }
2105 if (apps != 0)
2106 { 2105 {
2107 c->app_counter = apps; 2106 c->app_counter = apps;
2108 c->apps = GNUNET_malloc (apps * sizeof (GNUNET_MESH_ApplicationType)); 2107 c->apps = GNUNET_malloc (apps * sizeof(GNUNET_MESH_ApplicationType));
2109 memcpy (c->apps, &message[1] + types * sizeof (uint16_t), 2108 for (i = 0; i < apps; i++)
2110 apps * sizeof (GNUNET_MESH_ApplicationType));
2111 }
2112 for (i = 0; i < apps; i++)
2113 {
2114 known = GNUNET_NO;
2115 for (j = 0; i < n_apps; j++)
2116 { 2109 {
2117 if (c->apps[i] == applications[j]) 2110 c->apps[i] = ntohl(a[i]);
2111 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: app %u\n", c->apps[i]);
2112 known = GNUNET_NO;
2113 for (j = 0; i < n_apps; j++)
2118 { 2114 {
2119 known = GNUNET_YES; 2115 if (c->apps[i] == applications[j])
2120 applications_rc[j]++; 2116 {
2121 break; 2117 known = GNUNET_YES;
2118 applications_rc[j]++;
2119 break;
2120 }
2122 } 2121 }
2123 } 2122 if (!known)
2124 if (!known)
2125 {
2126 /* Register previously unknown application */
2127 GNUNET_array_append (applications, n_apps, c->apps[i]);
2128 n_apps--;
2129 GNUNET_array_append (applications_rc, n_apps, 1);
2130 if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task)
2131 { 2123 {
2132 announce_applications_task = 2124 /* Register previously unknown application */
2133 GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME, 2125 GNUNET_array_append (applications, n_apps, c->apps[i]);
2134 &announce_applications, NULL); 2126 n_apps--;
2127 GNUNET_array_append (applications_rc, n_apps, 1);
2128 if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task)
2129 {
2130 announce_applications_task =
2131 GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME,
2132 &announce_applications, NULL);
2133 }
2134 /* TODO: if any client was looking for *type*, notify peer found */
2135 } 2135 }
2136 } 2136 }
2137 } 2137 }
2138 if (types > 0)
2139 {
2140 t = (uint16_t *) &a[apps];
2141 c->type_counter = types;
2142 c->types = GNUNET_malloc (types * sizeof (uint16_t));
2143 for (i =0; i < types; i++)
2144 {
2145 c->types[i] = ntohs(t[i]);
2146 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: type %hu\n", c->types[i]);
2147 }
2148 }
2138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2139 "MESH: client has %u+%u subscriptions\n", c->type_counter, 2150 "MESH: client has %u+%u subscriptions\n", c->type_counter,
2140 c->app_counter); 2151 c->app_counter);
@@ -2439,6 +2450,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2439 uint32_t *p; 2450 uint32_t *p;
2440 unsigned int i; 2451 unsigned int i;
2441 2452
2453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got connect by type request\n");
2442 /* Sanity check for client registration */ 2454 /* Sanity check for client registration */
2443 if (NULL == (c = retrieve_client (client))) 2455 if (NULL == (c = retrieve_client (client)))
2444 { 2456 {
@@ -2449,7 +2461,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2449 2461
2450 connect_msg = (struct GNUNET_MESH_ConnectPeerByType *) message; 2462 connect_msg = (struct GNUNET_MESH_ConnectPeerByType *) message;
2451 /* Sanity check for message size */ 2463 /* Sanity check for message size */
2452 if (sizeof (struct GNUNET_MESH_PeerControl) != 2464 if (sizeof (struct GNUNET_MESH_ConnectPeerByType) !=
2453 ntohs (connect_msg->header.size)) 2465 ntohs (connect_msg->header.size))
2454 { 2466 {
2455 GNUNET_break (0); 2467 GNUNET_break (0);
@@ -2477,6 +2489,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2477 2489
2478 /* Do WE have the service? */ 2490 /* Do WE have the service? */
2479 type = ntohl (connect_msg->type); 2491 type = ntohl (connect_msg->type);
2492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type requested: %u\n", type);
2480 for (i = 0; i < n_apps; i++) 2493 for (i = 0; i < n_apps; i++)
2481 { 2494 {
2482 if (applications[i] == type) 2495 if (applications[i] == type)
@@ -2486,6 +2499,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2486 */ 2499 */
2487 struct GNUNET_MESH_PeerControl pc; 2500 struct GNUNET_MESH_PeerControl pc;
2488 2501
2502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: available locally\n");
2489 pc.peer = my_full_id; 2503 pc.peer = my_full_id;
2490 GNUNET_CONTAINER_multihashmap_put (t->peers, &pc.peer.hashPubKey, 2504 GNUNET_CONTAINER_multihashmap_put (t->peers, &pc.peer.hashPubKey,
2491 get_peer_info (&pc.peer), 2505 get_peer_info (&pc.peer),
@@ -2493,7 +2507,13 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2493 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 2507 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
2494 pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); 2508 pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
2495 pc.tunnel_id = htonl (t->local_tid); 2509 pc.tunnel_id = htonl (t->local_tid);
2496 GNUNET_SERVER_notification_context_unicast (nc, client, NULL, GNUNET_NO); 2510 pc.peer = my_full_id;
2511 GNUNET_SERVER_notification_context_unicast (nc, /* context */
2512 client, /* dest */
2513 &pc.header, /* msg */
2514 GNUNET_NO); /* can drop? */
2515 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2516 return;
2497 } 2517 }
2498 } 2518 }
2499 /* Ok, lets find a peer offering the service */ 2519 /* Ok, lets find a peer offering the service */
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h
index ca615f4e7..62bcf6782 100644
--- a/src/mesh/mesh.h
+++ b/src/mesh/mesh.h
@@ -84,14 +84,14 @@ struct GNUNET_MESH_ClientConnect
84 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT 84 * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
85 * 85 *
86 * Size: sizeof(struct GNUNET_MESH_ClientConnect) + 86 * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
87 * sizeof(uint16_t) * types + 87 * sizeof(MESH_ApplicationType) * applications +
88 * sizeof(MESH_ApplicationType) * applications 88 * sizeof(uint16_t) * types
89 */ 89 */
90 struct GNUNET_MessageHeader header; 90 struct GNUNET_MessageHeader header;
91 uint16_t types GNUNET_PACKED;
92 uint16_t applications GNUNET_PACKED; 91 uint16_t applications GNUNET_PACKED;
93 /* uint16_t list_types[types] */ 92 uint16_t types GNUNET_PACKED;
94 /* uint16_t list_apps[applications] */ 93 /* uint16_t list_apps[applications] */
94 /* uint16_t list_types[types] */
95}; 95};
96 96
97 97
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index ad8026d4a..f026575da 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -593,6 +593,11 @@ reconnect (struct GNUNET_MESH_Handle *h)
593 struct GNUNET_MESH_Tunnel *t; 593 struct GNUNET_MESH_Tunnel *t;
594 unsigned int i; 594 unsigned int i;
595 595
596#if DEBUG
597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: ******* RECONNECT *******\n");
599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
600#endif
596 h->in_receive = GNUNET_NO; 601 h->in_receive = GNUNET_NO;
597 /* disconnect */ 602 /* disconnect */
598 if (NULL != h->th) 603 if (NULL != h->th)
@@ -1132,17 +1137,18 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1132 return NULL; 1137 return NULL;
1133 } 1138 }
1134 h->cls = cls; 1139 h->cls = cls;
1135 h->message_handlers = handlers; 1140 /* FIXME memdup? */
1136 h->applications = stypes; 1141 h->applications = stypes;
1142 h->message_handlers = handlers;
1137 h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; 1143 h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
1138 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; 1144 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
1139 1145
1140 /* count handlers and apps, calculate size */ 1146 /* count handlers and apps, calculate size */
1141 for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
1142 for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ; 1147 for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ;
1148 for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
1143 size = sizeof (struct GNUNET_MESH_ClientConnect); 1149 size = sizeof (struct GNUNET_MESH_ClientConnect);
1144 size += h->n_handlers * sizeof (uint16_t);
1145 size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); 1150 size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType);
1151 size += h->n_handlers * sizeof (uint16_t);
1146 1152
1147 { 1153 {
1148 char buf[size]; 1154 char buf[size];
@@ -1151,12 +1157,15 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1151 msg = (struct GNUNET_MESH_ClientConnect *) buf; 1157 msg = (struct GNUNET_MESH_ClientConnect *) buf;
1152 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); 1158 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
1153 msg->header.size = htons (size); 1159 msg->header.size = htons (size);
1154 types = (uint16_t *) & msg[1]; 1160 apps = (GNUNET_MESH_ApplicationType *) &msg[1];
1155 for (ntypes = 0; ntypes < h->n_handlers; ntypes++)
1156 types[ntypes] = h->message_handlers[ntypes].type;
1157 apps = (GNUNET_MESH_ApplicationType *) &types[ntypes];
1158 for (napps = 0; napps < h->n_applications; napps++) 1161 for (napps = 0; napps < h->n_applications; napps++)
1159 apps[napps] = h->applications[napps]; 1162 {
1163 apps[napps] = htonl(h->applications[napps]);
1164 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "mesh: app %u\n", h->applications[napps]);
1165 }
1166 types = (uint16_t *) &apps[napps];
1167 for (ntypes = 0; ntypes < h->n_handlers; ntypes++)
1168 types[ntypes] = htons(h->message_handlers[ntypes].type);
1160 msg->applications = htons (napps); 1169 msg->applications = htons (napps);
1161 msg->types = htons (ntypes); 1170 msg->types = htons (ntypes);
1162#if DEBUG 1171#if DEBUG
diff --git a/src/mesh/test_mesh.conf b/src/mesh/test_mesh.conf
index 6563073bc..e89e2bee2 100644
--- a/src/mesh/test_mesh.conf
+++ b/src/mesh/test_mesh.conf
@@ -10,6 +10,8 @@ AUTOSTART = YES
10ACCEPT_FROM = 127.0.0.1; 10ACCEPT_FROM = 127.0.0.1;
11HOSTNAME = localhost 11HOSTNAME = localhost
12PORT = 10511 12PORT = 10511
13#PREFIX = valgrind --leak-check=full
14#PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args
13 15
14[dht] 16[dht]
15DEBUG = NO 17DEBUG = NO
diff --git a/src/mesh/test_mesh_local.c b/src/mesh/test_mesh_local.c
index 58ccad5e0..6b5b2159b 100644
--- a/src/mesh/test_mesh_local.c
+++ b/src/mesh/test_mesh_local.c
@@ -35,15 +35,62 @@
35static struct GNUNET_OS_Process *arm_pid; 35static struct GNUNET_OS_Process *arm_pid;
36static struct GNUNET_MESH_Handle *mesh_peer_1; 36static struct GNUNET_MESH_Handle *mesh_peer_1;
37static struct GNUNET_MESH_Handle *mesh_peer_2; 37static struct GNUNET_MESH_Handle *mesh_peer_2;
38static struct GNUNET_MESH_Tunnel *t_1; 38static struct GNUNET_MESH_Tunnel *t;
39 39
40// static struct GNUNET_MESH_Tunnel *t_2;
41static int result; 40static int result;
42static GNUNET_SCHEDULER_TaskIdentifier abort_task; 41static GNUNET_SCHEDULER_TaskIdentifier abort_task;
43static GNUNET_SCHEDULER_TaskIdentifier test_task; 42static GNUNET_SCHEDULER_TaskIdentifier test_task;
44 43
45 44
46/** 45/**
46 * Shutdown nicely
47 */
48static void
49do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
50{
51 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n");
52 if (0 != abort_task)
53 {
54 GNUNET_SCHEDULER_cancel (abort_task);
55 }
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: D1\n");
57 if (NULL != mesh_peer_1)
58 {
59 GNUNET_MESH_disconnect (mesh_peer_1);
60 }
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: D2\n");
62 if (NULL != mesh_peer_2)
63 {
64 GNUNET_MESH_disconnect (mesh_peer_2);
65 }
66 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: arm\n");
67 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
68 {
69 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
70 }
71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
72 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
73 GNUNET_OS_process_close (arm_pid);
74}
75
76
77/**
78 * Something went wrong and timed out. Kill everything and set error flag
79 */
80static void
81do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
82{
83 if (0 != test_task)
84 {
85 GNUNET_SCHEDULER_cancel (test_task);
86 }
87 result = GNUNET_SYSERR;
88 abort_task = 0;
89 do_shutdown (cls, tc);
90}
91
92
93/**
47 * Function is called whenever a message is received. 94 * Function is called whenever a message is received.
48 * 95 *
49 * @param cls closure (set from GNUNET_MESH_connect) 96 * @param cls closure (set from GNUNET_MESH_connect)
@@ -62,6 +109,9 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
62 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 109 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
63{ 110{
64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Data callback\n"); 111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Data callback\n");
112 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
113 (GNUNET_TIME_UNIT_SECONDS, 2), &do_shutdown,
114 NULL);
65 return GNUNET_OK; 115 return GNUNET_OK;
66} 116}
67 117
@@ -121,67 +171,49 @@ inbound_end (void *cls,
121 171
122 172
123/** 173/**
124 * Handler array for traffic received on peer1 174 * Method called whenever a peer has disconnected from the tunnel.
175 *
176 * @param cls closure
177 * @param peer peer identity the tunnel stopped working with
125 */ 178 */
126static struct GNUNET_MESH_MessageHandler handlers1[] = { 179static void peer_conected (
127 {&data_callback, 1, 0}, 180 void *cls,
128 {NULL, 0, 0} 181 const struct GNUNET_PeerIdentity * peer)
129}; 182{
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer connected\n");
184}
130 185
131 186
132/** 187/**
133 * Handler array for traffic received on peer2 (none expected) 188 * Method called whenever a peer has connected to the tunnel.
189 *
190 * @param cls closure
191 * @param peer peer identity the tunnel was created to, NULL on timeout
192 * @param atsi performance data for the connection
134 */ 193 */
135static struct GNUNET_MESH_MessageHandler handlers2[] = { {NULL, 0, 0} }; 194static void peer_disconnected (
136 195 void *cls,
196 const struct GNUNET_PeerIdentity * peer,
197 const struct GNUNET_TRANSPORT_ATS_Information * atsi)
198{
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer disconnected\n");
200}
137 201
138 202
139/** 203/**
140 * Shutdown nicely 204 * Handler array for traffic received on peer1
141 */ 205 */
142static void 206static struct GNUNET_MESH_MessageHandler handlers1[] = {
143do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 207 {&data_callback, 1, 0},
144{ 208 {NULL, 0, 0}
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n"); 209};
146 if (0 != abort_task)
147 {
148 GNUNET_SCHEDULER_cancel (abort_task);
149 }
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: D1\n");
151 if (NULL != mesh_peer_1)
152 {
153 GNUNET_MESH_disconnect (mesh_peer_1);
154 }
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: D2\n");
156 if (NULL != mesh_peer_2)
157 {
158 GNUNET_MESH_disconnect (mesh_peer_2);
159 }
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: arm\n");
161 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
162 {
163 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
164 }
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
166 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
167 GNUNET_OS_process_close (arm_pid);
168}
169 210
170 211
171/** 212/**
172 * Something went wrong and timed out. Kill everything and set error flag 213 * Handler array for traffic received on peer2 (none expected)
173 */ 214 */
174static void 215static struct GNUNET_MESH_MessageHandler handlers2[] = { {NULL, 0, 0} };
175do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 216
176{
177 if (0 != test_task)
178 {
179 GNUNET_SCHEDULER_cancel (test_task);
180 }
181 result = GNUNET_SYSERR;
182 abort_task = 0;
183 do_shutdown (cls, tc);
184}
185 217
186 218
187/** 219/**
@@ -191,8 +223,7 @@ static void
191test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 223test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
192{ 224{
193 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 225 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
194 static const GNUNET_MESH_ApplicationType app1[] = 226 static const GNUNET_MESH_ApplicationType app1[] = { 1, 0 };
195 { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
196 static const GNUNET_MESH_ApplicationType app2[] = { 0 }; 227 static const GNUNET_MESH_ApplicationType app2[] = { 0 };
197 228
198 test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; 229 test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
@@ -221,12 +252,14 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: YAY! CONNECTED TO MESH :D\n"); 252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: YAY! CONNECTED TO MESH :D\n");
222 } 253 }
223 254
224 t_1 = GNUNET_MESH_tunnel_create (mesh_peer_1, NULL, NULL, NULL, (void *) 1); 255 t = GNUNET_MESH_tunnel_create (mesh_peer_2,
225// t_2 = GNUNET_MESH_tunnel_create (mesh_peer_2, NULL, NULL, NULL, 2); 256 NULL,
257 &peer_conected,
258 &peer_disconnected,
259 (void *) 2);
260 GNUNET_MESH_peer_request_connect_by_type(t, 1);
261
226 262
227 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
228 (GNUNET_TIME_UNIT_SECONDS, 2), &do_shutdown,
229 NULL);
230} 263}
231 264
232 265