diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-08-01 18:51:26 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-08-01 18:51:26 +0000 |
commit | b20f6248dd60dfb02539cdff90e2c37b6cf03d6b (patch) | |
tree | 779d29a7ccce758c3d9ae6520ce9cba5478d4a04 /src | |
parent | 61faae19d6cc81ac2ad9177c3dc8a07706632afc (diff) | |
download | gnunet-b20f6248dd60dfb02539cdff90e2c37b6cf03d6b.tar.gz gnunet-b20f6248dd60dfb02539cdff90e2c37b6cf03d6b.zip |
- refactor
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 125 |
1 files changed, 65 insertions, 60 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index 53032b5c8..ce8cde724 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -364,7 +364,7 @@ struct MeshChannelReliability | |||
364 | /** | 364 | /** |
365 | * Channel this is about. | 365 | * Channel this is about. |
366 | */ | 366 | */ |
367 | struct MeshChannel *t; | 367 | struct MeshChannel *ch; |
368 | 368 | ||
369 | /** | 369 | /** |
370 | * DLL of messages sent and not yet ACK'd. | 370 | * DLL of messages sent and not yet ACK'd. |
@@ -1183,14 +1183,19 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1183 | * | 1183 | * |
1184 | * @param c Connection. | 1184 | * @param c Connection. |
1185 | * | 1185 | * |
1186 | * @return Short ID of the previous peer. | 1186 | * @return Previous peer in the connection. |
1187 | */ | 1187 | */ |
1188 | GNUNET_PEER_Id | 1188 | static struct MeshPeer * |
1189 | connection_get_prev_hop (struct MeshConnection *c) | 1189 | connection_get_prev_hop (struct MeshConnection *c) |
1190 | { | 1190 | { |
1191 | GNUNET_PEER_Id id; | ||
1192 | |||
1191 | if (0 == c->own_pos || c->path->length < 2) | 1193 | if (0 == c->own_pos || c->path->length < 2) |
1192 | return c->path->peers[0]; | 1194 | id = c->path->peers[0]; |
1193 | return c->path->peers[c->own_pos - 1]; | 1195 | else |
1196 | id = c->path->peers[c->own_pos - 1]; | ||
1197 | |||
1198 | return peer_get_short (id); | ||
1194 | } | 1199 | } |
1195 | 1200 | ||
1196 | 1201 | ||
@@ -1199,14 +1204,19 @@ connection_get_prev_hop (struct MeshConnection *c) | |||
1199 | * | 1204 | * |
1200 | * @param c Connection. | 1205 | * @param c Connection. |
1201 | * | 1206 | * |
1202 | * @return Short ID of the next peer. | 1207 | * @return Next peer in the connection. |
1203 | */ | 1208 | */ |
1204 | GNUNET_PEER_Id | 1209 | static struct MeshPeer * |
1205 | connection_get_next_hop (struct MeshConnection *c) | 1210 | connection_get_next_hop (struct MeshConnection *c) |
1206 | { | 1211 | { |
1212 | GNUNET_PEER_Id id; | ||
1213 | |||
1207 | if ((c->path->length - 1) == c->own_pos || c->path->length < 2) | 1214 | if ((c->path->length - 1) == c->own_pos || c->path->length < 2) |
1208 | return c->path->peers[c->path->length - 1]; | 1215 | id = c->path->peers[c->path->length - 1]; |
1209 | return c->path->peers[c->own_pos + 1]; | 1216 | else |
1217 | id = c->path->peers[c->own_pos + 1]; | ||
1218 | |||
1219 | return peer_get_short (id); | ||
1210 | } | 1220 | } |
1211 | 1221 | ||
1212 | 1222 | ||
@@ -1346,29 +1356,27 @@ tunnel_get_connection (struct MeshTunnel2 *t, int fwd) | |||
1346 | { | 1356 | { |
1347 | struct MeshConnection *c; | 1357 | struct MeshConnection *c; |
1348 | struct MeshConnection *best; | 1358 | struct MeshConnection *best; |
1349 | struct MeshPeer *neighbor; | 1359 | struct MeshPeer *peer; |
1350 | GNUNET_PEER_Id id; | ||
1351 | unsigned int lowest_q; | 1360 | unsigned int lowest_q; |
1352 | 1361 | ||
1353 | 1362 | ||
1354 | neighbor = NULL; | 1363 | peer = NULL; |
1355 | best = NULL; | 1364 | best = NULL; |
1356 | lowest_q = UINT_MAX; | 1365 | lowest_q = UINT_MAX; |
1357 | for (c = t->connection_head; NULL != c; c = c->next) | 1366 | for (c = t->connection_head; NULL != c; c = c->next) |
1358 | { | 1367 | { |
1359 | if (MESH_CONNECTION_READY == c->state) | 1368 | if (MESH_CONNECTION_READY == c->state) |
1360 | { | 1369 | { |
1361 | id = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c); | 1370 | peer = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c); |
1362 | neighbor = peer_get_short (id); | 1371 | if (NULL == peer->fc) |
1363 | if (NULL == neighbor->fc) | ||
1364 | { | 1372 | { |
1365 | GNUNET_break (0); | 1373 | GNUNET_break (0); |
1366 | continue; | 1374 | continue; |
1367 | } | 1375 | } |
1368 | if (neighbor->fc->queue_n < lowest_q) | 1376 | if (peer->fc->queue_n < lowest_q) |
1369 | { | 1377 | { |
1370 | best = c; | 1378 | best = c; |
1371 | lowest_q = neighbor->fc->queue_n; | 1379 | lowest_q = peer->fc->queue_n; |
1372 | } | 1380 | } |
1373 | } | 1381 | } |
1374 | } | 1382 | } |
@@ -1392,13 +1400,11 @@ send_prebuilt_message_connection (const struct GNUNET_MessageHeader *message, | |||
1392 | int fwd) | 1400 | int fwd) |
1393 | { | 1401 | { |
1394 | struct MeshPeer *neighbor; | 1402 | struct MeshPeer *neighbor; |
1395 | GNUNET_PEER_Id id; | ||
1396 | void *data; | 1403 | void *data; |
1397 | size_t size; | 1404 | size_t size; |
1398 | uint16_t type; | 1405 | uint16_t type; |
1399 | 1406 | ||
1400 | id = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c); | 1407 | neighbor = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c); |
1401 | neighbor = peer_get_short (id); | ||
1402 | if (NULL == neighbor) | 1408 | if (NULL == neighbor) |
1403 | { | 1409 | { |
1404 | GNUNET_break (0); | 1410 | GNUNET_break (0); |
@@ -1520,7 +1526,7 @@ send_connection_create (struct MeshConnection *connection) | |||
1520 | 1526 | ||
1521 | t = connection->t; | 1527 | t = connection->t; |
1522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n"); | 1528 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n"); |
1523 | neighbor = peer_get_short (connection_get_next_hop (connection)); | 1529 | neighbor = connection_get_next_hop (connection); |
1524 | queue_add (connection, | 1530 | queue_add (connection, |
1525 | GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, | 1531 | GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, |
1526 | sizeof (struct GNUNET_MESH_ConnectionCreate) + | 1532 | sizeof (struct GNUNET_MESH_ConnectionCreate) + |
@@ -1550,7 +1556,7 @@ send_connection_ack (struct MeshConnection *connection) | |||
1550 | 1556 | ||
1551 | t = connection->t; | 1557 | t = connection->t; |
1552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send connection ack\n"); | 1558 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send connection ack\n"); |
1553 | neighbor = peer_get_short (connection_get_prev_hop (connection)); | 1559 | neighbor = connection_get_prev_hop (connection); |
1554 | queue_add (connection, | 1560 | queue_add (connection, |
1555 | GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, | 1561 | GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, |
1556 | sizeof (struct GNUNET_MESH_ConnectionACK), | 1562 | sizeof (struct GNUNET_MESH_ConnectionACK), |
@@ -2660,14 +2666,11 @@ connection_send_ack (struct MeshConnection *c, int fwd) | |||
2660 | struct MeshFlowControl *prev_fc; | 2666 | struct MeshFlowControl *prev_fc; |
2661 | struct MeshPeer *next; | 2667 | struct MeshPeer *next; |
2662 | struct MeshPeer *prev; | 2668 | struct MeshPeer *prev; |
2663 | GNUNET_PEER_Id id; | ||
2664 | uint32_t ack; | 2669 | uint32_t ack; |
2665 | int delta; | 2670 | int delta; |
2666 | 2671 | ||
2667 | id = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c); | 2672 | next = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c); |
2668 | next = peer_get_short (id); | 2673 | prev = fwd ? connection_get_prev_hop (c) : connection_get_next_hop (c); |
2669 | id = fwd ? connection_get_prev_hop (c) : connection_get_next_hop (c); | ||
2670 | prev = peer_get_short (id); | ||
2671 | next_fc = next->fc; | 2674 | next_fc = next->fc; |
2672 | prev_fc = prev->fc; | 2675 | prev_fc = prev->fc; |
2673 | 2676 | ||
@@ -2861,20 +2864,26 @@ channel_send_client_data (struct MeshChannel *ch, | |||
2861 | 2864 | ||
2862 | /** | 2865 | /** |
2863 | * Send up to 64 buffered messages to the client for in order delivery. | 2866 | * Send up to 64 buffered messages to the client for in order delivery. |
2864 | * | 2867 | * |
2865 | * @param t Tunnel on which to empty the message buffer. | 2868 | * @param ch Channel on which to empty the message buffer. |
2866 | * @param c Client to send to. | 2869 | * @param c Client to send to. |
2867 | * @param rel Reliability structure to corresponding peer. | 2870 | * @param rel Reliability structure to corresponding peer. |
2868 | * If rel == t->bck_rel, this is FWD data. | 2871 | * If rel == bck_rel, this is FWD data. |
2869 | */ | 2872 | */ |
2870 | static void | 2873 | static void |
2871 | tunnel_send_client_buffered_data (struct MeshTunnel *t, struct MeshClient *c, | 2874 | channel_send_client_buffered_data (struct MeshChannel *ch, |
2872 | struct MeshChannelReliability *rel) | 2875 | struct MeshClient *c, |
2876 | struct MeshChannelReliability *rel) | ||
2873 | { | 2877 | { |
2874 | ; | ||
2875 | struct MeshReliableMessage *copy; | 2878 | struct MeshReliableMessage *copy; |
2876 | struct MeshReliableMessage *next; | 2879 | struct MeshReliableMessage *next; |
2877 | 2880 | ||
2881 | if (GNUNET_NO == ch->reliable) | ||
2882 | { | ||
2883 | GNUNET_break (0); | ||
2884 | return; | ||
2885 | } | ||
2886 | |||
2878 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n"); | 2887 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n"); |
2879 | for (copy = rel->head_recv; NULL != copy; copy = next) | 2888 | for (copy = rel->head_recv; NULL != copy; copy = next) |
2880 | { | 2889 | { |
@@ -2886,7 +2895,7 @@ tunnel_send_client_buffered_data (struct MeshTunnel *t, struct MeshClient *c, | |||
2886 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2895 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2887 | " have %u! now expecting %u\n", | 2896 | " have %u! now expecting %u\n", |
2888 | copy->mid, rel->mid_recv + 1); | 2897 | copy->mid, rel->mid_recv + 1); |
2889 | tunnel_send_client_data (t, msg, (rel == t->bck_rel)); | 2898 | channel_send_client_data (ch, msg, (rel == ch->bck_rel)); |
2890 | rel->mid_recv++; | 2899 | rel->mid_recv++; |
2891 | GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy); | 2900 | GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy); |
2892 | GNUNET_free (copy); | 2901 | GNUNET_free (copy); |
@@ -2907,15 +2916,13 @@ tunnel_send_client_buffered_data (struct MeshTunnel *t, struct MeshClient *c, | |||
2907 | /** | 2916 | /** |
2908 | * We have received a message out of order, buffer it until we receive | 2917 | * We have received a message out of order, buffer it until we receive |
2909 | * the missing one and we can feed the rest to the client. | 2918 | * the missing one and we can feed the rest to the client. |
2910 | * | 2919 | * |
2911 | * @param t Tunnel to add to. | ||
2912 | * @param msg Message to buffer. | 2920 | * @param msg Message to buffer. |
2913 | * @param rel Reliability data to the corresponding direction. | 2921 | * @param rel Reliability data to the corresponding direction. |
2914 | */ | 2922 | */ |
2915 | static void | 2923 | static void |
2916 | tunnel_add_buffered_data (struct MeshTunnel *t, | 2924 | channel_rel_add_buffered_data (const struct GNUNET_MESH_Data *msg, |
2917 | const struct GNUNET_MESH_Data *msg, | 2925 | struct MeshChannelReliability *rel) |
2918 | struct MeshChannelReliability *rel) | ||
2919 | { | 2926 | { |
2920 | struct MeshReliableMessage *copy; | 2927 | struct MeshReliableMessage *copy; |
2921 | struct MeshReliableMessage *prev; | 2928 | struct MeshReliableMessage *prev; |
@@ -2958,7 +2965,7 @@ tunnel_add_buffered_data (struct MeshTunnel *t, | |||
2958 | * @param copy Message that is no longer needed: remote peer got it. | 2965 | * @param copy Message that is no longer needed: remote peer got it. |
2959 | */ | 2966 | */ |
2960 | static void | 2967 | static void |
2961 | tunnel_free_reliable_message (struct MeshReliableMessage *copy) | 2968 | rel_message_free (struct MeshReliableMessage *copy) |
2962 | { | 2969 | { |
2963 | struct MeshChannelReliability *rel; | 2970 | struct MeshChannelReliability *rel; |
2964 | struct GNUNET_TIME_Relative time; | 2971 | struct GNUNET_TIME_Relative time; |
@@ -2990,7 +2997,7 @@ tunnel_free_reliable_message (struct MeshReliableMessage *copy) | |||
2990 | * @param rel Reliability data for a channel. | 2997 | * @param rel Reliability data for a channel. |
2991 | */ | 2998 | */ |
2992 | static void | 2999 | static void |
2993 | channel_free_reliable_all (struct MeshChannelReliability *rel) | 3000 | channel_rel_free_all (struct MeshChannelReliability *rel) |
2994 | { | 3001 | { |
2995 | struct MeshReliableMessage *copy; | 3002 | struct MeshReliableMessage *copy; |
2996 | struct MeshReliableMessage *next; | 3003 | struct MeshReliableMessage *next; |
@@ -3019,14 +3026,12 @@ channel_free_reliable_all (struct MeshChannelReliability *rel) | |||
3019 | /** | 3026 | /** |
3020 | * Mark future messages as ACK'd. | 3027 | * Mark future messages as ACK'd. |
3021 | * | 3028 | * |
3022 | * @param t Tunnel whose sent buffer to clean. | ||
3023 | * @param msg DataACK message with a bitfield of future ACK'd messages. | ||
3024 | * @param rel Reliability data. | 3029 | * @param rel Reliability data. |
3030 | * @param msg DataACK message with a bitfield of future ACK'd messages. | ||
3025 | */ | 3031 | */ |
3026 | static void | 3032 | static void |
3027 | tunnel_free_sent_reliable (struct MeshTunnel *t, | 3033 | channel_rel_free_sent (struct MeshChannelReliability *rel, |
3028 | const struct GNUNET_MESH_DataACK *msg, | 3034 | const struct GNUNET_MESH_DataACK *msg) |
3029 | struct MeshChannelReliability *rel) | ||
3030 | { | 3035 | { |
3031 | struct MeshReliableMessage *copy; | 3036 | struct MeshReliableMessage *copy; |
3032 | struct MeshReliableMessage *next; | 3037 | struct MeshReliableMessage *next; |
@@ -3082,7 +3087,7 @@ tunnel_free_sent_reliable (struct MeshTunnel *t, | |||
3082 | 3087 | ||
3083 | /* Now copy->mid == target, free it */ | 3088 | /* Now copy->mid == target, free it */ |
3084 | next = copy->next; | 3089 | next = copy->next; |
3085 | tunnel_free_reliable_message (copy); | 3090 | rel_message_free (copy); |
3086 | copy = next; | 3091 | copy = next; |
3087 | } | 3092 | } |
3088 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "free_sent_reliable END\n"); | 3093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "free_sent_reliable END\n"); |
@@ -3096,23 +3101,23 @@ tunnel_free_sent_reliable (struct MeshTunnel *t, | |||
3096 | * @param tc TaskContext. | 3101 | * @param tc TaskContext. |
3097 | */ | 3102 | */ |
3098 | static void | 3103 | static void |
3099 | tunnel_retransmit_message (void *cls, | 3104 | channel_retransmit_message (void *cls, |
3100 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 3105 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
3101 | { | 3106 | { |
3102 | struct MeshChannelReliability *rel = cls; | 3107 | struct MeshChannelReliability *rel = cls; |
3103 | struct MeshReliableMessage *copy; | 3108 | struct MeshReliableMessage *copy; |
3104 | struct MeshFlowControl *fc; | ||
3105 | struct MeshPeerQueue *q; | 3109 | struct MeshPeerQueue *q; |
3106 | struct MeshPeer *pi; | 3110 | struct MeshPeer *pi; |
3107 | struct MeshTunnel *t; | 3111 | struct MeshChannel *ch; |
3112 | struct MeshConnection *c; | ||
3108 | struct GNUNET_MESH_Data *payload; | 3113 | struct GNUNET_MESH_Data *payload; |
3109 | GNUNET_PEER_Id hop; | 3114 | int fwd; |
3110 | 3115 | ||
3111 | rel->retry_task = GNUNET_SCHEDULER_NO_TASK; | 3116 | rel->retry_task = GNUNET_SCHEDULER_NO_TASK; |
3112 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 3117 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
3113 | return; | 3118 | return; |
3114 | 3119 | ||
3115 | t = rel->t; | 3120 | ch = rel->ch; |
3116 | copy = rel->head_sent; | 3121 | copy = rel->head_sent; |
3117 | if (NULL == copy) | 3122 | if (NULL == copy) |
3118 | { | 3123 | { |
@@ -3122,10 +3127,10 @@ tunnel_retransmit_message (void *cls, | |||
3122 | 3127 | ||
3123 | /* Search the message to be retransmitted in the outgoing queue */ | 3128 | /* Search the message to be retransmitted in the outgoing queue */ |
3124 | payload = (struct GNUNET_MESH_Data *) ©[1]; | 3129 | payload = (struct GNUNET_MESH_Data *) ©[1]; |
3125 | hop = rel == t->fwd_rel ? t->next_hop : t->prev_hop; | 3130 | fwd = (rel == ch->fwd_rel); |
3126 | fc = rel == t->fwd_rel ? &t->prev_fc : &t->next_fc; | 3131 | c = tunnel_get_connection(ch->t, fwd); |
3127 | pi = peer_get_short (hop); | 3132 | pi = connection_get_next_hop (c); |
3128 | for (q = pi->queue_head; NULL != q; q = q->next) | 3133 | for (q = pi->fc->queue_head; NULL != q; q = q->next) |
3129 | { | 3134 | { |
3130 | if (ntohs (payload->header.type) == q->type) | 3135 | if (ntohs (payload->header.type) == q->type) |
3131 | { | 3136 | { |
@@ -3144,7 +3149,7 @@ tunnel_retransmit_message (void *cls, | |||
3144 | fc->last_ack_sent++; | 3149 | fc->last_ack_sent++; |
3145 | fc->last_pid_recv++; | 3150 | fc->last_pid_recv++; |
3146 | payload->pid = htonl (fc->last_pid_recv); | 3151 | payload->pid = htonl (fc->last_pid_recv); |
3147 | send_prebuilt_message (&payload->header, hop, t); | 3152 | send_prebuilt_message_channel (&payload->header, hop, t); |
3148 | GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO); | 3153 | GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO); |
3149 | } | 3154 | } |
3150 | else | 3155 | else |
@@ -3465,8 +3470,8 @@ channel_destroy (struct MeshChannel *ch) | |||
3465 | 3470 | ||
3466 | if (GNUNET_YES == ch->reliable) | 3471 | if (GNUNET_YES == ch->reliable) |
3467 | { | 3472 | { |
3468 | channel_free_reliable_all (ch->fwd_rel); | 3473 | channel_rel_free_all (ch->fwd_rel); |
3469 | channel_free_reliable_all (ch->bck_rel); | 3474 | channel_rel_free_all (ch->bck_rel); |
3470 | } | 3475 | } |
3471 | 3476 | ||
3472 | GNUNET_free (ch); | 3477 | GNUNET_free (ch); |