aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-05-12 14:01:29 +0000
committerChristian Grothoff <christian@grothoff.org>2011-05-12 14:01:29 +0000
commitd75e6e4273b1bb43b5ca9f6b207c10fc824efbae (patch)
tree4b2548eabb82b8a00df676558125640fe72eac3c /src
parentd95d14541ab481ad4697a432b5598535af07804c (diff)
downloadgnunet-d75e6e4273b1bb43b5ca9f6b207c10fc824efbae.tar.gz
gnunet-d75e6e4273b1bb43b5ca9f6b207c10fc824efbae.zip
fixes
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh.c26
-rw-r--r--src/mesh/mesh_api_new.c42
-rw-r--r--src/mesh/test_mesh_api.c34
3 files changed, 76 insertions, 26 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index d545d8dd3..f07465ae2 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -1297,6 +1297,27 @@ core_disconnect (void *cls,
1297/******************************************************************************/ 1297/******************************************************************************/
1298 1298
1299/** 1299/**
1300 * Task run during shutdown.
1301 *
1302 * @param cls unused
1303 * @param tc unused
1304 */
1305static void
1306shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1307{
1308 if (core_handle != NULL)
1309 {
1310 GNUNET_CORE_disconnect (core_handle);
1311 core_handle = NULL;
1312 }
1313 if (dht_handle != NULL)
1314 {
1315 GNUNET_DHT_disconnect (dht_handle);
1316 dht_handle = NULL;
1317 }
1318}
1319
1320/**
1300 * Process mesh requests. 1321 * Process mesh requests.
1301 * 1322 *
1302 * @param cls closure 1323 * @param cls closure
@@ -1331,6 +1352,11 @@ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 4 ********\n");
1331 if (dht_handle == NULL) { 1352 if (dht_handle == NULL) {
1332 GNUNET_break(0); 1353 GNUNET_break(0);
1333 } 1354 }
1355
1356 /* Scheduled the task to clean up when shutdown is called */
1357 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1358 &shutdown_task, NULL);
1359
1334} 1360}
1335 1361
1336/** 1362/**
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index ca68279ed..989b526ae 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -76,6 +76,9 @@ struct GNUNET_MESH_Handle {
76 */ 76 */
77 GNUNET_MESH_TunnelEndHandler *cleaner; 77 GNUNET_MESH_TunnelEndHandler *cleaner;
78 78
79
80 struct GNUNET_CLIENT_TransmitHandle *th;
81
79 /** 82 /**
80 * Closure for all the handlers given by the client 83 * Closure for all the handlers given by the client
81 */ 84 */
@@ -127,26 +130,28 @@ struct GNUNET_MESH_TransmitHandle {
127 * @param buf where the callee should write the message 130 * @param buf where the callee should write the message
128 * @return number of bytes written to buf 131 * @return number of bytes written to buf
129 */ 132 */
130size_t 133static size_t
131send_connect_packet (void *cls, size_t size, void *buf) { 134send_connect_packet (void *cls, size_t size, void *buf) {
132 struct GNUNET_MESH_Handle *h; 135 struct GNUNET_MESH_Handle *h = cls;
133 struct GNUNET_MESH_ClientConnect *msg; 136 struct GNUNET_MESH_ClientConnect *msg;
134 uint16_t *types; 137 uint16_t *types;
135 int ntypes; 138 int ntypes;
136 GNUNET_MESH_ApplicationType *apps; 139 GNUNET_MESH_ApplicationType *apps;
137 int napps; 140 int napps;
138 141
139 if(0 == size || buf == NULL) { 142 h->th = NULL;
143 if (0 == size || buf == NULL) {
140 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer invalid\n"); 144 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer invalid\n");
145 // FIXME: disconnect, reconnect, retry!
141 return 0; 146 return 0;
142 } 147 }
143 if(sizeof(struct GNUNET_MessageHeader) > size) { 148 if (sizeof(struct GNUNET_MessageHeader) > size) {
144 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too small\n"); 149 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too small\n");
150 // FIXME: disconnect, reconnect, retry!
145 return 0; 151 return 0;
146 } 152 }
147 153
148 msg = (struct GNUNET_MESH_ClientConnect *) buf; 154 msg = (struct GNUNET_MESH_ClientConnect *) buf;
149 h = (struct GNUNET_MESH_Handle *) cls;
150 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT; 155 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
151 156
152 for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) { 157 for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
@@ -219,7 +224,8 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
219 void *cls, 224 void *cls,
220 GNUNET_MESH_TunnelEndHandler cleaner, 225 GNUNET_MESH_TunnelEndHandler cleaner,
221 const struct GNUNET_MESH_MessageHandler *handlers, 226 const struct GNUNET_MESH_MessageHandler *handlers,
222 const GNUNET_MESH_ApplicationType *stypes) { 227 const GNUNET_MESH_ApplicationType *stypes)
228{
223 struct GNUNET_MESH_Handle *h; 229 struct GNUNET_MESH_Handle *h;
224 size_t size; 230 size_t size;
225 231
@@ -247,12 +253,12 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
247 size += h->n_handlers * sizeof(uint16_t); 253 size += h->n_handlers * sizeof(uint16_t);
248 size += h->n_applications * sizeof(GNUNET_MESH_ApplicationType); 254 size += h->n_applications * sizeof(GNUNET_MESH_ApplicationType);
249 255
250 GNUNET_CLIENT_notify_transmit_ready(h->mesh, 256 h->th = GNUNET_CLIENT_notify_transmit_ready(h->mesh,
251 size, 257 size,
252 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 258 GNUNET_TIME_UNIT_FOREVER_REL,
253 GNUNET_NO, 259 GNUNET_YES,
254 &send_connect_packet, 260 &send_connect_packet,
255 (void *)h); 261 (void *)h);
256 262
257 return h; 263 return h;
258} 264}
@@ -263,10 +269,14 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
263 * 269 *
264 * @param handle connection to mesh to disconnect 270 * @param handle connection to mesh to disconnect
265 */ 271 */
266void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) { 272void
267 273GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
268 GNUNET_free(handle); 274{
269 return; 275 if (NULL != handle->th)
276 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
277 if (NULL != handle->mesh)
278 GNUNET_CLIENT_disconnect (handle->mesh, GNUNET_NO);
279 GNUNET_free(handle);
270} 280}
271 281
272 282
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c
index 00212eb49..5f988f555 100644
--- a/src/mesh/test_mesh_api.c
+++ b/src/mesh/test_mesh_api.c
@@ -7,16 +7,31 @@ static struct GNUNET_MESH_MessageHandler handlers[] = {
7 {NULL, 0, 0} 7 {NULL, 0, 0}
8}; 8};
9 9
10static struct GNUNET_OS_Process *arm_pid;
11
12static struct GNUNET_MESH_Handle *mesh;
13
14static struct GNUNET_DHT_Handle *dht;
15
16static void
17 do_shutdown (void *cls,
18 const struct GNUNET_SCHEDULER_TaskContext *tc)
19{
20 if (NULL != mesh)
21 GNUNET_MESH_disconnect (mesh);
22 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
23 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
24 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
25 GNUNET_OS_process_close (arm_pid);
26}
27
10 28
11static void 29static void
12run (void *cls, 30run (void *cls,
13 char *const *args, 31 char *const *args,
14 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { 32 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) {
15 struct GNUNET_OS_Process *arm_pid;
16 struct GNUNET_MESH_Handle *mesh;
17 struct GNUNET_DHT_Handle *dht;
18 GNUNET_MESH_ApplicationType app; 33 GNUNET_MESH_ApplicationType app;
19 char buffer[2048]; 34 // char buffer[2048];
20 35
21 36
22 arm_pid = GNUNET_OS_start_process (NULL, NULL, 37 arm_pid = GNUNET_OS_start_process (NULL, NULL,
@@ -41,16 +56,15 @@ run (void *cls,
41 } 56 }
42 57
43 /* do real test work here */ 58 /* do real test work here */
44 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) 59 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
45 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 60 &do_shutdown,
46 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); 61 NULL);
47 GNUNET_OS_process_close (arm_pid);
48
49 return;
50} 62}
51 63
52 64
53 65
66
67
54int main (int argc, char *argv[]) { 68int main (int argc, char *argv[]) {
55 int ret; 69 int ret;
56 char *const argv2[] = {"test-mesh-api", 70 char *const argv2[] = {"test-mesh-api",