diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-05 20:00:36 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-05 20:00:36 +0000 |
commit | cf6e2bdb1b9a5aedc4f090df853814b9df817e03 (patch) | |
tree | 1f6a40d73e445b7d034260603231c106add5f95b | |
parent | de45e0bc600497ea4049642532ee940711b816a5 (diff) | |
download | gnunet-cf6e2bdb1b9a5aedc4f090df853814b9df817e03.tar.gz gnunet-cf6e2bdb1b9a5aedc4f090df853814b9df817e03.zip |
WiP
-rw-r--r-- | src/mesh/mesh_api_new.c | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index 73d1eba56..817c5fb3e 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * TODO: | 23 | * TODO: |
24 | * - callbacks to client missing on certain events | 24 | * - callbacks to client missing on certain events |
25 | * - processing messages from service is incomplete | 25 | * - processing messages from service is incomplete |
26 | * - Check priorities to cancel traffic data | ||
26 | * | 27 | * |
27 | * STRUCTURE: | 28 | * STRUCTURE: |
28 | * - CONSTANTS | 29 | * - CONSTANTS |
@@ -49,6 +50,7 @@ extern "C" | |||
49 | #include "mesh.h" | 50 | #include "mesh.h" |
50 | #include "mesh_protocol.h" | 51 | #include "mesh_protocol.h" |
51 | 52 | ||
53 | #define DEBUG GNUNET_YES | ||
52 | 54 | ||
53 | /******************************************************************************/ | 55 | /******************************************************************************/ |
54 | /************************ DATA STRUCTURES ****************************/ | 56 | /************************ DATA STRUCTURES ****************************/ |
@@ -76,13 +78,6 @@ struct GNUNET_MESH_TransmitHandle | |||
76 | struct GNUNET_MESH_Tunnel *tunnel; | 78 | struct GNUNET_MESH_Tunnel *tunnel; |
77 | 79 | ||
78 | /** | 80 | /** |
79 | * Data itself, currently points to the end of this struct if | ||
80 | * we have a message already, NULL if the message is to be | ||
81 | * obtained from the callback. | ||
82 | */ | ||
83 | const struct GNUNET_MessageHeader *data; | ||
84 | |||
85 | /** | ||
86 | * Callback to obtain the message to transmit, or NULL if we | 81 | * Callback to obtain the message to transmit, or NULL if we |
87 | * got the message in 'data'. Notice that messages built | 82 | * got the message in 'data'. Notice that messages built |
88 | * by 'notify' need to be encapsulated with information about | 83 | * by 'notify' need to be encapsulated with information about |
@@ -366,8 +361,11 @@ create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) | |||
366 | 361 | ||
367 | 362 | ||
368 | /** | 363 | /** |
369 | * Get the tunnel handler for the tunnel specified by id from the given handle | 364 | * Destroy the specified tunnel. |
370 | * @param h Mesh handle | 365 | * - Destroys all peers, calling the disconnect callback on each if needed |
366 | * - Cancels all outgoing traffic for that tunnel, calling respective notifys | ||
367 | * - Calls cleaner if tunnel was inbound | ||
368 | * - Frees all memory used | ||
371 | * @param tid ID of the wanted tunnel | 369 | * @param tid ID of the wanted tunnel |
372 | * @return handle to the required tunnel or NULL if not found | 370 | * @return handle to the required tunnel or NULL if not found |
373 | */ | 371 | */ |
@@ -376,12 +374,32 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t) | |||
376 | { | 374 | { |
377 | struct GNUNET_MESH_Handle *h; | 375 | struct GNUNET_MESH_Handle *h; |
378 | struct GNUNET_PeerIdentity pi; | 376 | struct GNUNET_PeerIdentity pi; |
377 | struct GNUNET_MESH_TransmitHandle *th; | ||
378 | struct GNUNET_MESH_TransmitHandle *aux; | ||
379 | unsigned int i; | 379 | unsigned int i; |
380 | 380 | ||
381 | if (NULL == t) | 381 | if (NULL == t) |
382 | { | 382 | { |
383 | GNUNET_break (0); | 383 | if (th->tunnel == t) |
384 | return; | 384 | { |
385 | aux = th->next; | ||
386 | GNUNET_CONTAINER_DLL_remove(h->th_head, h->th_tail, th); | ||
387 | if (NULL == h->th_head && NULL != h->th) | ||
388 | { | ||
389 | GNUNET_CLIENT_notify_transmit_ready_cancel(h->th); | ||
390 | h->th = NULL; | ||
391 | } | ||
392 | if (NULL != th->notify) | ||
393 | th->notify(th->notify_cls, 0, NULL); | ||
394 | if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task) | ||
395 | GNUNET_SCHEDULER_cancel(th->timeout_task); | ||
396 | GNUNET_free (th); | ||
397 | th = aux; | ||
398 | } | ||
399 | else | ||
400 | { | ||
401 | th = th->next; | ||
402 | } | ||
385 | } | 403 | } |
386 | h = t->mesh; | 404 | h = t->mesh; |
387 | /* TODO remove data packets from queue */ | 405 | /* TODO remove data packets from queue */ |
@@ -396,14 +414,14 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t) | |||
396 | GNUNET_PEER_change_rc (t->peers[i]->id, -1); | 414 | GNUNET_PEER_change_rc (t->peers[i]->id, -1); |
397 | GNUNET_free (t->peers[i]); | 415 | GNUNET_free (t->peers[i]); |
398 | } | 416 | } |
417 | if (t->npeers > 0) | ||
418 | GNUNET_free (t->peers); | ||
399 | if (NULL != h->cleaner && 0 != t->owner) | 419 | if (NULL != h->cleaner && 0 != t->owner) |
400 | h->cleaner (h->cls, t, t->ctx); | 420 | h->cleaner (h->cls, t, t->ctx); |
401 | if (0 != t->owner) | 421 | if (0 != t->owner) |
402 | GNUNET_PEER_change_rc (t->owner, -1); | 422 | GNUNET_PEER_change_rc (t->owner, -1); |
403 | if (0 != t->napps && t->apps) | 423 | if (0 != t->napps && t->apps) |
404 | GNUNET_free (t->apps); | 424 | GNUNET_free (t->apps); |
405 | if (t->npeers > 0) | ||
406 | GNUNET_free (t->peers); | ||
407 | GNUNET_free (t); | 425 | GNUNET_free (t); |
408 | return; | 426 | return; |
409 | } | 427 | } |
@@ -900,13 +918,14 @@ send_callback (void *cls, size_t size, void *buf) | |||
900 | tsize = 0; | 918 | tsize = 0; |
901 | while ((NULL != (th = h->th_head)) && (size >= th->size)) | 919 | while ((NULL != (th = h->th_head)) && (size >= th->size)) |
902 | { | 920 | { |
921 | #if DEBUG | ||
903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: type: %u\n", | 922 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: type: %u\n", |
904 | ntohs (th->data->type)); | 923 | ntohs (((struct GNUNET_MessageHeader *)&th[1])->type)); |
905 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n", | 924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n", |
906 | ntohs (th->data->size)); | 925 | ntohs (((struct GNUNET_MessageHeader *)&th[1])->size)); |
907 | if (NULL == th->data) | 926 | #endif |
927 | if (NULL != th->notify) | ||
908 | { | 928 | { |
909 | GNUNET_assert (NULL != th->notify); | ||
910 | if (th->target == 0) | 929 | if (th->target == 0) |
911 | { | 930 | { |
912 | /* multicast */ | 931 | /* multicast */ |
@@ -920,7 +939,7 @@ send_callback (void *cls, size_t size, void *buf) | |||
920 | mc.header.size = htons (sizeof (mc) + th->size); | 939 | mc.header.size = htons (sizeof (mc) + th->size); |
921 | mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); | 940 | mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); |
922 | mc.tid = htonl (th->tunnel->tid); | 941 | mc.tid = htonl (th->tunnel->tid); |
923 | memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */ | 942 | memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */ |
924 | memcpy (cbuf, &mc, sizeof (mc)); | 943 | memcpy (cbuf, &mc, sizeof (mc)); |
925 | psize = th->size + sizeof (mc); | 944 | psize = th->size + sizeof (mc); |
926 | } | 945 | } |
@@ -947,7 +966,7 @@ send_callback (void *cls, size_t size, void *buf) | |||
947 | } | 966 | } |
948 | else | 967 | else |
949 | { | 968 | { |
950 | memcpy (cbuf, th->data, th->size); | 969 | memcpy (cbuf, &th[1], th->size); |
951 | psize = th->size; | 970 | psize = th->size; |
952 | } | 971 | } |
953 | if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 972 | if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -997,7 +1016,6 @@ send_packet (struct GNUNET_MESH_Handle *h, | |||
997 | th->priority = UINT32_MAX; | 1016 | th->priority = UINT32_MAX; |
998 | th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 1017 | th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
999 | th->size = msize; | 1018 | th->size = msize; |
1000 | th->data = (void *) &th[1]; | ||
1001 | memcpy (&th[1], msg, msize); | 1019 | memcpy (&th[1], msg, msize); |
1002 | add_to_queue (h, th); | 1020 | add_to_queue (h, th); |
1003 | if (NULL != h->th) | 1021 | if (NULL != h->th) |
@@ -1325,6 +1343,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | |||
1325 | struct GNUNET_MESH_TransmitHandle *th; | 1343 | struct GNUNET_MESH_TransmitHandle *th; |
1326 | size_t overhead; | 1344 | size_t overhead; |
1327 | 1345 | ||
1346 | GNUNET_assert(NULL != notify); | ||
1328 | if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && | 1347 | if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && |
1329 | tunnel->npackets > 0) | 1348 | tunnel->npackets > 0) |
1330 | return NULL; /* queue full */ | 1349 | return NULL; /* queue full */ |