diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-05-10 09:49:09 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-05-10 09:49:09 +0000 |
commit | 1582b76198cd7764922d80b8d7610e5c51cfbad0 (patch) | |
tree | e82f0da0a94124edb81e98fa0c0476479a46ffe5 | |
parent | 714190bb8feb1933a4e5bf4f06944f91a6a19c92 (diff) | |
download | gnunet-1582b76198cd7764922d80b8d7610e5c51cfbad0.tar.gz gnunet-1582b76198cd7764922d80b8d7610e5c51cfbad0.zip |
- remove one indirection level (no multicast ref counter)
-rw-r--r-- | src/mesh/gnunet-service-mesh-new.c | 78 |
1 files changed, 20 insertions, 58 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c index 82d551b82..d51c4b8dc 100644 --- a/src/mesh/gnunet-service-mesh-new.c +++ b/src/mesh/gnunet-service-mesh-new.c | |||
@@ -109,28 +109,6 @@ struct MeshClient; | |||
109 | 109 | ||
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Struct representing a piece of data being sent to other peers | ||
113 | */ | ||
114 | struct MeshData | ||
115 | { | ||
116 | /** Tunnel it belongs to. */ | ||
117 | struct MeshTunnel *t; | ||
118 | |||
119 | /** How many remaining neighbors still hav't got it. */ | ||
120 | unsigned int reference_counter; | ||
121 | |||
122 | /** How many remaining neighbors we need to send this to. */ | ||
123 | unsigned int total_out; | ||
124 | |||
125 | /** Size of the data. */ | ||
126 | size_t data_len; | ||
127 | |||
128 | /** Data itself */ | ||
129 | void *data; | ||
130 | }; | ||
131 | |||
132 | |||
133 | /** | ||
134 | * Struct containing info about a queued transmission to this peer | 112 | * Struct containing info about a queued transmission to this peer |
135 | */ | 113 | */ |
136 | struct MeshPeerQueue | 114 | struct MeshPeerQueue |
@@ -187,8 +165,14 @@ struct MeshTransmissionDescriptor | |||
187 | /** Ultimate destination of the packet */ | 165 | /** Ultimate destination of the packet */ |
188 | GNUNET_PEER_Id destination; | 166 | GNUNET_PEER_Id destination; |
189 | 167 | ||
190 | /** Data descriptor */ | 168 | /** Tunnel it belongs to. */ |
191 | struct MeshData* mesh_data; | 169 | struct MeshTunnel *t; |
170 | |||
171 | /** Size of the data. */ | ||
172 | size_t data_len; | ||
173 | |||
174 | /** Data itself */ | ||
175 | void *data; | ||
192 | }; | 176 | }; |
193 | 177 | ||
194 | 178 | ||
@@ -1006,23 +990,6 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1006 | /****************** GENERAL HELPER FUNCTIONS ************************/ | 990 | /****************** GENERAL HELPER FUNCTIONS ************************/ |
1007 | /******************************************************************************/ | 991 | /******************************************************************************/ |
1008 | 992 | ||
1009 | /** | ||
1010 | * Decrements the reference counter and frees all resources if needed | ||
1011 | * | ||
1012 | * @param mesh_data Data Descriptor used in a multicast message. | ||
1013 | * Freed no longer needed (last message). | ||
1014 | */ | ||
1015 | static void | ||
1016 | data_descriptor_decrement_rc (struct MeshData *mesh_data) | ||
1017 | { | ||
1018 | if (0 == --(mesh_data->reference_counter)) | ||
1019 | { | ||
1020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Last copy!\n"); | ||
1021 | GNUNET_free (mesh_data->data); | ||
1022 | GNUNET_free (mesh_data); | ||
1023 | } | ||
1024 | } | ||
1025 | |||
1026 | 993 | ||
1027 | /** | 994 | /** |
1028 | * Check if client has registered with the service and has not disconnected | 995 | * Check if client has registered with the service and has not disconnected |
@@ -1477,8 +1444,7 @@ send_core_data_raw (void *cls, size_t size, void *buf) | |||
1477 | size_t total_size; | 1444 | size_t total_size; |
1478 | 1445 | ||
1479 | GNUNET_assert (NULL != info); | 1446 | GNUNET_assert (NULL != info); |
1480 | GNUNET_assert (NULL != info->mesh_data); | 1447 | msg = (struct GNUNET_MessageHeader *) info->data; |
1481 | msg = (struct GNUNET_MessageHeader *) info->mesh_data->data; | ||
1482 | total_size = ntohs (msg->size); | 1448 | total_size = ntohs (msg->size); |
1483 | 1449 | ||
1484 | if (total_size > size) | 1450 | if (total_size > size) |
@@ -1487,7 +1453,7 @@ send_core_data_raw (void *cls, size_t size, void *buf) | |||
1487 | return 0; | 1453 | return 0; |
1488 | } | 1454 | } |
1489 | memcpy (buf, msg, total_size); | 1455 | memcpy (buf, msg, total_size); |
1490 | data_descriptor_decrement_rc (info->mesh_data); | 1456 | GNUNET_free (info->data); |
1491 | GNUNET_free (info); | 1457 | GNUNET_free (info); |
1492 | return total_size; | 1458 | return total_size; |
1493 | } | 1459 | } |
@@ -1516,9 +1482,8 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
1516 | 1482 | ||
1517 | size = ntohs (message->size); | 1483 | size = ntohs (message->size); |
1518 | info = GNUNET_malloc (sizeof (struct MeshTransmissionDescriptor)); | 1484 | info = GNUNET_malloc (sizeof (struct MeshTransmissionDescriptor)); |
1519 | info->mesh_data = GNUNET_malloc (sizeof (struct MeshData)); | 1485 | info->data = GNUNET_malloc (size); |
1520 | info->mesh_data->data = GNUNET_malloc (size); | 1486 | memcpy (info->data, message, size); |
1521 | memcpy (info->mesh_data->data, message, size); | ||
1522 | type = ntohs(message->type); | 1487 | type = ntohs(message->type); |
1523 | switch (type) | 1488 | switch (type) |
1524 | { | 1489 | { |
@@ -1526,17 +1491,15 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
1526 | struct GNUNET_MESH_ToOrigin *to; | 1491 | struct GNUNET_MESH_ToOrigin *to; |
1527 | 1492 | ||
1528 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | 1493 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: |
1529 | m = (struct GNUNET_MESH_Unicast *) info->mesh_data->data; | 1494 | m = (struct GNUNET_MESH_Unicast *) info->data; |
1530 | m->ttl = htonl (ntohl (m->ttl) - 1); | 1495 | m->ttl = htonl (ntohl (m->ttl) - 1); |
1531 | break; | 1496 | break; |
1532 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | 1497 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: |
1533 | to = (struct GNUNET_MESH_ToOrigin *) info->mesh_data->data; | 1498 | to = (struct GNUNET_MESH_ToOrigin *) info->data; |
1534 | t->bck_pid++; | 1499 | t->bck_pid++; |
1535 | to->pid = htonl(t->bck_pid); | 1500 | to->pid = htonl(t->bck_pid); |
1536 | } | 1501 | } |
1537 | info->mesh_data->data_len = size; | 1502 | info->data_len = size; |
1538 | info->mesh_data->reference_counter = 1; | ||
1539 | info->mesh_data->total_out = 1; | ||
1540 | neighbor = peer_get (peer); | 1503 | neighbor = peer_get (peer); |
1541 | for (p = neighbor->path_head; NULL != p; p = p->next) | 1504 | for (p = neighbor->path_head; NULL != p; p = p->next) |
1542 | { | 1505 | { |
@@ -1575,8 +1538,7 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
1575 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1538 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1576 | " no direct connection to %s\n", | 1539 | " no direct connection to %s\n", |
1577 | GNUNET_i2s (peer)); | 1540 | GNUNET_i2s (peer)); |
1578 | GNUNET_free (info->mesh_data->data); | 1541 | GNUNET_free (info->data); |
1579 | GNUNET_free (info->mesh_data); | ||
1580 | GNUNET_free (info); | 1542 | GNUNET_free (info); |
1581 | return; | 1543 | return; |
1582 | } | 1544 | } |
@@ -3298,7 +3260,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf) | |||
3298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Multicast callback.\n"); | 3260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Multicast callback.\n"); |
3299 | GNUNET_assert (NULL != info); | 3261 | GNUNET_assert (NULL != info); |
3300 | GNUNET_assert (NULL != info->peer); | 3262 | GNUNET_assert (NULL != info->peer); |
3301 | total_size = info->mesh_data->data_len; | 3263 | total_size = info->data_len; |
3302 | GNUNET_assert (total_size < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 3264 | GNUNET_assert (total_size < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
3303 | 3265 | ||
3304 | if (total_size > size) | 3266 | if (total_size > size) |
@@ -3307,7 +3269,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf) | |||
3307 | return 0; | 3269 | return 0; |
3308 | } | 3270 | } |
3309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " copying data...\n"); | 3271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " copying data...\n"); |
3310 | memcpy (buf, info->mesh_data->data, total_size); | 3272 | memcpy (buf, info->data, total_size); |
3311 | #if MESH_DEBUG | 3273 | #if MESH_DEBUG |
3312 | { | 3274 | { |
3313 | struct GNUNET_MessageHeader *mh; | 3275 | struct GNUNET_MessageHeader *mh; |
@@ -3317,7 +3279,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf) | |||
3317 | GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); | 3279 | GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); |
3318 | } | 3280 | } |
3319 | #endif | 3281 | #endif |
3320 | data_descriptor_decrement_rc (info->mesh_data); | 3282 | GNUNET_free (info->data); |
3321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "freeing info...\n"); | 3283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "freeing info...\n"); |
3322 | GNUNET_free (info); | 3284 | GNUNET_free (info); |
3323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "return %u\n", total_size); | 3285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "return %u\n", total_size); |
@@ -3392,7 +3354,7 @@ queue_destroy (struct MeshPeerQueue *queue, int clear_cls) | |||
3392 | " type %s\n", | 3354 | " type %s\n", |
3393 | GNUNET_MESH_DEBUG_M2S(queue->type)); | 3355 | GNUNET_MESH_DEBUG_M2S(queue->type)); |
3394 | dd = queue->cls; | 3356 | dd = queue->cls; |
3395 | data_descriptor_decrement_rc (dd->mesh_data); | 3357 | GNUNET_free (dd->data); |
3396 | break; | 3358 | break; |
3397 | case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: | 3359 | case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE: |
3398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type create path\n"); | 3360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type create path\n"); |