diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-08-08 11:27:12 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-08-08 11:27:12 +0000 |
commit | 42e009e9502926f3c88f97c5b8e990b07dcd3a30 (patch) | |
tree | b45ef738ec8955d822b2ab14254e6bbec51e14ac /src/mesh | |
parent | 8fb4207fa8cd3781fd30fc5ba04f9ba199f8f297 (diff) | |
download | gnunet-42e009e9502926f3c88f97c5b8e990b07dcd3a30.tar.gz gnunet-42e009e9502926f3c88f97c5b8e990b07dcd3a30.zip |
- use struct fc instaed of pointer
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index 1a6e77d54..79ab83ac6 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -505,12 +505,12 @@ struct MeshConnection | |||
505 | /** | 505 | /** |
506 | * Flow control information for traffic fwd. | 506 | * Flow control information for traffic fwd. |
507 | */ | 507 | */ |
508 | struct MeshFlowControl *fwd_fc; | 508 | struct MeshFlowControl fwd_fc; |
509 | 509 | ||
510 | /** | 510 | /** |
511 | * Flow control information for traffic bck. | 511 | * Flow control information for traffic bck. |
512 | */ | 512 | */ |
513 | struct MeshFlowControl *bck_fc; | 513 | struct MeshFlowControl bck_fc; |
514 | 514 | ||
515 | /** | 515 | /** |
516 | * Connection number. | 516 | * Connection number. |
@@ -1395,7 +1395,7 @@ tunnel_get_connection (struct MeshTunnel2 *t, int fwd) | |||
1395 | { | 1395 | { |
1396 | if (MESH_CONNECTION_READY == c->state) | 1396 | if (MESH_CONNECTION_READY == c->state) |
1397 | { | 1397 | { |
1398 | fc = fwd ? c->fwd_fc : c->bck_fc; | 1398 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
1399 | if (NULL == fc) | 1399 | if (NULL == fc) |
1400 | { | 1400 | { |
1401 | GNUNET_break (0); | 1401 | GNUNET_break (0); |
@@ -1983,7 +1983,7 @@ connection_unlock_queue (struct MeshConnection *c, int fwd) | |||
1983 | size_t size; | 1983 | size_t size; |
1984 | 1984 | ||
1985 | peer = fwd ? connection_get_next_hop(c) : connection_get_prev_hop(c); | 1985 | peer = fwd ? connection_get_next_hop(c) : connection_get_prev_hop(c); |
1986 | fc = fwd ? c->fwd_fc : c->bck_fc; | 1986 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
1987 | 1987 | ||
1988 | if (NULL != fc->core_transmit) | 1988 | if (NULL != fc->core_transmit) |
1989 | return; /* Already unlocked */ | 1989 | return; /* Already unlocked */ |
@@ -2023,7 +2023,7 @@ connection_cancel_queues (struct MeshConnection *c, int fwd) | |||
2023 | GNUNET_break (0); | 2023 | GNUNET_break (0); |
2024 | return; | 2024 | return; |
2025 | } | 2025 | } |
2026 | fc = fwd ? c->fwd_fc : c->bck_fc; | 2026 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
2027 | for (q = fc->queue_head; NULL != q; q = next) | 2027 | for (q = fc->queue_head; NULL != q; q = next) |
2028 | { | 2028 | { |
2029 | next = q->next; | 2029 | next = q->next; |
@@ -2288,7 +2288,7 @@ connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2288 | msg.header.size = htons (sizeof (msg)); | 2288 | msg.header.size = htons (sizeof (msg)); |
2289 | msg.pid = htonl (fc->last_pid_sent); | 2289 | msg.pid = htonl (fc->last_pid_sent); |
2290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** pid (%u)!\n", fc->last_pid_sent); | 2290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** pid (%u)!\n", fc->last_pid_sent); |
2291 | send_prebuilt_message_connection (&msg.header, c, NULL, fc == c->fwd_fc); | 2291 | send_prebuilt_message_connection (&msg.header, c, NULL, fc == &c->fwd_fc); |
2292 | fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); | 2292 | fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); |
2293 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, | 2293 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, |
2294 | &connection_poll, fc); | 2294 | &connection_poll, fc); |
@@ -2661,8 +2661,8 @@ connection_send_ack (struct MeshConnection *c, int fwd) | |||
2661 | uint32_t ack; | 2661 | uint32_t ack; |
2662 | int delta; | 2662 | int delta; |
2663 | 2663 | ||
2664 | next_fc = fwd ? c->fwd_fc : c->bck_fc; | 2664 | next_fc = fwd ? &c->fwd_fc : &c->bck_fc; |
2665 | prev_fc = fwd ? c->bck_fc : c->fwd_fc; | 2665 | prev_fc = fwd ? &c->bck_fc : &c->fwd_fc; |
2666 | 2666 | ||
2667 | /* Check if we need to transmit the ACK */ | 2667 | /* Check if we need to transmit the ACK */ |
2668 | if (prev_fc->last_ack_sent - prev_fc->last_pid_recv > 3) | 2668 | if (prev_fc->last_ack_sent - prev_fc->last_pid_recv > 3) |
@@ -3128,7 +3128,7 @@ channel_retransmit_message (void *cls, | |||
3128 | payload = (struct GNUNET_MESH_Data *) ©[1]; | 3128 | payload = (struct GNUNET_MESH_Data *) ©[1]; |
3129 | fwd = (rel == ch->fwd_rel); | 3129 | fwd = (rel == ch->fwd_rel); |
3130 | c = tunnel_get_connection (ch->t, fwd); | 3130 | c = tunnel_get_connection (ch->t, fwd); |
3131 | fc = fwd ? c->fwd_fc : c->bck_fc; | 3131 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
3132 | for (q = fc->queue_head; NULL != q; q = q->next) | 3132 | for (q = fc->queue_head; NULL != q; q = q->next) |
3133 | { | 3133 | { |
3134 | if (ntohs (payload->header.type) == q->type && ch == q->ch) | 3134 | if (ntohs (payload->header.type) == q->type && ch == q->ch) |
@@ -3401,6 +3401,24 @@ tunnel_add_connection (struct MeshTunnel2 *t, struct MeshConnection *c) | |||
3401 | 3401 | ||
3402 | 3402 | ||
3403 | /** | 3403 | /** |
3404 | * Initialize a Flow Control structure to the initial state. | ||
3405 | * | ||
3406 | * @param fc Flow Control structure to initialize. | ||
3407 | */ | ||
3408 | static void | ||
3409 | fc_init (struct MeshFlowControl *fc) | ||
3410 | { | ||
3411 | fc->last_pid_sent = (uint32_t) -1; /* Next (expected) = 0 */ | ||
3412 | fc->last_pid_recv = (uint32_t) -1; | ||
3413 | fc->last_ack_sent = (uint32_t) -1; /* No traffic allowed yet */ | ||
3414 | fc->last_ack_recv = (uint32_t) -1; | ||
3415 | fc->poll_task = GNUNET_SCHEDULER_NO_TASK; | ||
3416 | fc->poll_time = GNUNET_TIME_UNIT_SECONDS; | ||
3417 | fc->queue_n = 0; | ||
3418 | } | ||
3419 | |||
3420 | |||
3421 | /** | ||
3404 | * Create a connection. | 3422 | * Create a connection. |
3405 | * | 3423 | * |
3406 | * @param tid Tunnel ID. | 3424 | * @param tid Tunnel ID. |
@@ -3425,6 +3443,8 @@ connection_new (struct GNUNET_HashCode *tid, uint32_t cid) | |||
3425 | 3443 | ||
3426 | c = GNUNET_new (struct MeshConnection); | 3444 | c = GNUNET_new (struct MeshConnection); |
3427 | c->id = cid; | 3445 | c->id = cid; |
3446 | fc_init (&c->fwd_fc); | ||
3447 | fc_init (&c->bck_fc); | ||
3428 | tunnel_add_connection (t, c); | 3448 | tunnel_add_connection (t, c); |
3429 | 3449 | ||
3430 | return c; | 3450 | return c; |
@@ -3550,24 +3570,6 @@ tunnel_destroy_if_empty (struct MeshTunnel2 *t) | |||
3550 | 3570 | ||
3551 | 3571 | ||
3552 | /** | 3572 | /** |
3553 | * Initialize a Flow Control structure to the initial state. | ||
3554 | * | ||
3555 | * @param fc Flow Control structure to initialize. | ||
3556 | */ | ||
3557 | static void | ||
3558 | fc_init (struct MeshFlowControl *fc) | ||
3559 | { | ||
3560 | fc->last_pid_sent = (uint32_t) -1; /* Next (expected) = 0 */ | ||
3561 | fc->last_pid_recv = (uint32_t) -1; | ||
3562 | fc->last_ack_sent = (uint32_t) -1; /* No traffic allowed yet */ | ||
3563 | fc->last_ack_recv = (uint32_t) -1; | ||
3564 | fc->poll_task = GNUNET_SCHEDULER_NO_TASK; | ||
3565 | fc->poll_time = GNUNET_TIME_UNIT_SECONDS; | ||
3566 | fc->queue_n = 0; | ||
3567 | } | ||
3568 | |||
3569 | |||
3570 | /** | ||
3571 | * Destroy a channel and free all resources. | 3573 | * Destroy a channel and free all resources. |
3572 | * | 3574 | * |
3573 | * @param ch Channel to destroy. | 3575 | * @param ch Channel to destroy. |
@@ -3859,7 +3861,7 @@ queue_destroy (struct MeshPeerQueue *queue, int clear_cls) | |||
3859 | int fwd; | 3861 | int fwd; |
3860 | 3862 | ||
3861 | fwd = (queue->peer == connection_get_next_hop (queue->c)); | 3863 | fwd = (queue->peer == connection_get_next_hop (queue->c)); |
3862 | fc = fwd ? queue->c->fwd_fc : queue->c->bck_fc; | 3864 | fc = fwd ? &queue->c->fwd_fc : &queue->c->bck_fc; |
3863 | 3865 | ||
3864 | if (GNUNET_YES == clear_cls) | 3866 | if (GNUNET_YES == clear_cls) |
3865 | { | 3867 | { |
@@ -3915,7 +3917,7 @@ queue_send (void *cls, size_t size, void *buf) | |||
3915 | 3917 | ||
3916 | c = queue->c; | 3918 | c = queue->c; |
3917 | fwd = (queue->peer == connection_get_next_hop (c)); | 3919 | fwd = (queue->peer == connection_get_next_hop (c)); |
3918 | fc = fwd ? c->fwd_fc : c->bck_fc; | 3920 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
3919 | 3921 | ||
3920 | if (NULL == fc) | 3922 | if (NULL == fc) |
3921 | { | 3923 | { |
@@ -4100,7 +4102,7 @@ queue_add (void *cls, uint16_t type, size_t size, | |||
4100 | int fwd; | 4102 | int fwd; |
4101 | 4103 | ||
4102 | fwd = (dst == connection_get_next_hop (c)); | 4104 | fwd = (dst == connection_get_next_hop (c)); |
4103 | fc = fwd ? c->fwd_fc : c->bck_fc; | 4105 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
4104 | 4106 | ||
4105 | if (NULL == fc) | 4107 | if (NULL == fc) |
4106 | { | 4108 | { |
@@ -4697,7 +4699,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer, | |||
4697 | return GNUNET_OK; | 4699 | return GNUNET_OK; |
4698 | } | 4700 | } |
4699 | t = c->t; | 4701 | t = c->t; |
4700 | fc = fwd ? c->fwd_fc : c->bck_fc; | 4702 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
4701 | 4703 | ||
4702 | /* Check if origin is as expected */ | 4704 | /* Check if origin is as expected */ |
4703 | neighbor = fwd ? connection_get_prev_hop (c) : connection_get_next_hop (c); | 4705 | neighbor = fwd ? connection_get_prev_hop (c) : connection_get_next_hop (c); |
@@ -4880,12 +4882,12 @@ handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4880 | if (connection_get_next_hop (c)->id == id) | 4882 | if (connection_get_next_hop (c)->id == id) |
4881 | { | 4883 | { |
4882 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); | 4884 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); |
4883 | fc = c->fwd_fc; | 4885 | fc = &c->fwd_fc; |
4884 | } | 4886 | } |
4885 | else if (connection_get_prev_hop (c)->id == id) | 4887 | else if (connection_get_prev_hop (c)->id == id) |
4886 | { | 4888 | { |
4887 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); | 4889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); |
4888 | fc = c->bck_fc; | 4890 | fc = &c->bck_fc; |
4889 | } | 4891 | } |
4890 | else | 4892 | else |
4891 | { | 4893 | { |
@@ -4903,7 +4905,7 @@ handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4903 | } | 4905 | } |
4904 | 4906 | ||
4905 | fc->last_ack_recv = ack; | 4907 | fc->last_ack_recv = ack; |
4906 | connection_unlock_queue (c, fc == c->fwd_fc); | 4908 | connection_unlock_queue (c, fc == &c->fwd_fc); |
4907 | 4909 | ||
4908 | return GNUNET_OK; | 4910 | return GNUNET_OK; |
4909 | } | 4911 | } |
@@ -4949,12 +4951,12 @@ handle_mesh_poll (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4949 | if (connection_get_next_hop (c)->id == id) | 4951 | if (connection_get_next_hop (c)->id == id) |
4950 | { | 4952 | { |
4951 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); | 4953 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); |
4952 | fc = c->fwd_fc; | 4954 | fc = &c->fwd_fc; |
4953 | } | 4955 | } |
4954 | else if (connection_get_prev_hop (c)->id == id) | 4956 | else if (connection_get_prev_hop (c)->id == id) |
4955 | { | 4957 | { |
4956 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); | 4958 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); |
4957 | fc = c->bck_fc; | 4959 | fc = &c->bck_fc; |
4958 | } | 4960 | } |
4959 | else | 4961 | else |
4960 | { | 4962 | { |
@@ -4966,7 +4968,7 @@ handle_mesh_poll (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " PID %u, OLD %u\n", | 4968 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " PID %u, OLD %u\n", |
4967 | pid, fc->last_pid_recv); | 4969 | pid, fc->last_pid_recv); |
4968 | fc->last_pid_recv = pid; | 4970 | fc->last_pid_recv = pid; |
4969 | connection_send_ack (c, fc == c->fwd_fc); | 4971 | connection_send_ack (c, fc == &c->fwd_fc); |
4970 | 4972 | ||
4971 | return GNUNET_OK; | 4973 | return GNUNET_OK; |
4972 | } | 4974 | } |