diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-12 18:00:39 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-12 18:00:39 +0100 |
commit | 67f859104e0c89afc8263bb49173a5e9835d2c24 (patch) | |
tree | 94f863c0fde505ed6681e591afebe1c51501b713 /src/set/gnunet-service-set.c | |
parent | a2ac01f46c4d57034b5d40201b29701ff95b456a (diff) | |
download | gnunet-67f859104e0c89afc8263bb49173a5e9835d2c24.tar.gz gnunet-67f859104e0c89afc8263bb49173a5e9835d2c24.zip |
de-duplicate operation types
Diffstat (limited to 'src/set/gnunet-service-set.c')
-rw-r--r-- | src/set/gnunet-service-set.c | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 8f1506c6a..b80c1f2fd 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c | |||
@@ -161,9 +161,7 @@ struct GNUNET_STATISTICS_Handle *_GSS_statistics; | |||
161 | static struct Set * | 161 | static struct Set * |
162 | set_get (struct GNUNET_SERVICE_Client *client) | 162 | set_get (struct GNUNET_SERVICE_Client *client) |
163 | { | 163 | { |
164 | struct Set *set; | 164 | for (struct Set *set = sets_head; NULL != set; set = set->next) |
165 | |||
166 | for (set = sets_head; NULL != set; set = set->next) | ||
167 | if (set->client == client) | 165 | if (set->client == client) |
168 | return set; | 166 | return set; |
169 | return NULL; | 167 | return NULL; |
@@ -180,9 +178,9 @@ set_get (struct GNUNET_SERVICE_Client *client) | |||
180 | static struct Listener * | 178 | static struct Listener * |
181 | listener_get (struct GNUNET_SERVICE_Client *client) | 179 | listener_get (struct GNUNET_SERVICE_Client *client) |
182 | { | 180 | { |
183 | struct Listener *listener; | 181 | for (struct Listener *listener = listeners_head; |
184 | 182 | NULL != listener; | |
185 | for (listener = listeners_head; NULL != listener; listener = listener->next) | 183 | listener = listener->next) |
186 | if (listener->client == client) | 184 | if (listener->client == client) |
187 | return listener; | 185 | return listener; |
188 | return NULL; | 186 | return NULL; |
@@ -199,9 +197,7 @@ listener_get (struct GNUNET_SERVICE_Client *client) | |||
199 | static struct Operation * | 197 | static struct Operation * |
200 | get_incoming (uint32_t id) | 198 | get_incoming (uint32_t id) |
201 | { | 199 | { |
202 | struct Operation *op; | 200 | for (struct Operation *op = incoming_head; NULL != op; op = op->next) |
203 | |||
204 | for (op = incoming_head; NULL != op; op = op->next) | ||
205 | if (op->suggest_id == id) | 201 | if (op->suggest_id == id) |
206 | { | 202 | { |
207 | GNUNET_assert (GNUNET_YES == op->is_incoming); | 203 | GNUNET_assert (GNUNET_YES == op->is_incoming); |
@@ -1117,11 +1113,9 @@ handle_client_create_set (void *cls, | |||
1117 | { | 1113 | { |
1118 | case GNUNET_SET_OPERATION_INTERSECTION: | 1114 | case GNUNET_SET_OPERATION_INTERSECTION: |
1119 | set->vt = _GSS_intersection_vt (); | 1115 | set->vt = _GSS_intersection_vt (); |
1120 | set->type = OT_INTERSECTION; | ||
1121 | break; | 1116 | break; |
1122 | case GNUNET_SET_OPERATION_UNION: | 1117 | case GNUNET_SET_OPERATION_UNION: |
1123 | set->vt = _GSS_union_vt (); | 1118 | set->vt = _GSS_union_vt (); |
1124 | set->type = OT_UNION; | ||
1125 | break; | 1119 | break; |
1126 | default: | 1120 | default: |
1127 | GNUNET_free (set); | 1121 | GNUNET_free (set); |
@@ -1129,7 +1123,7 @@ handle_client_create_set (void *cls, | |||
1129 | GNUNET_SERVICE_client_drop (client); | 1123 | GNUNET_SERVICE_client_drop (client); |
1130 | return; | 1124 | return; |
1131 | } | 1125 | } |
1132 | set->operation = ntohl (msg->operation); | 1126 | set->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); |
1133 | set->state = set->vt->create (); | 1127 | set->state = set->vt->create (); |
1134 | if (NULL == set->state) | 1128 | if (NULL == set->state) |
1135 | { | 1129 | { |
@@ -1446,9 +1440,12 @@ handle_client_reject (void *cls, | |||
1446 | incoming = get_incoming (ntohl (msg->accept_reject_id)); | 1440 | incoming = get_incoming (ntohl (msg->accept_reject_id)); |
1447 | if (NULL == incoming) | 1441 | if (NULL == incoming) |
1448 | { | 1442 | { |
1449 | /* no matching incoming operation for this reject */ | 1443 | /* no matching incoming operation for this reject; |
1450 | GNUNET_break (0); | 1444 | could be that the other peer already disconnected... */ |
1451 | GNUNET_SERVICE_client_drop (client); | 1445 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1446 | "Client rejected unknown operation %u\n", | ||
1447 | (unsigned int) ntohl (msg->accept_reject_id)); | ||
1448 | GNUNET_SERVICE_client_continue (client); | ||
1452 | return; | 1449 | return; |
1453 | } | 1450 | } |
1454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1496,7 +1493,6 @@ handle_client_mutation (void *cls, | |||
1496 | GNUNET_SERVICE_client_drop (client); | 1493 | GNUNET_SERVICE_client_drop (client); |
1497 | return; | 1494 | return; |
1498 | } | 1495 | } |
1499 | |||
1500 | GNUNET_SERVICE_client_continue (client); | 1496 | GNUNET_SERVICE_client_continue (client); |
1501 | 1497 | ||
1502 | if (0 != set->content->iterator_count) | 1498 | if (0 != set->content->iterator_count) |
@@ -1505,7 +1501,6 @@ handle_client_mutation (void *cls, | |||
1505 | 1501 | ||
1506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1507 | "Scheduling mutation on set\n"); | 1503 | "Scheduling mutation on set\n"); |
1508 | |||
1509 | pm = GNUNET_new (struct PendingMutation); | 1504 | pm = GNUNET_new (struct PendingMutation); |
1510 | pm->mutation_message = GNUNET_copy_message (m); | 1505 | pm->mutation_message = GNUNET_copy_message (m); |
1511 | pm->set = set; | 1506 | pm->set = set; |
@@ -1514,7 +1509,10 @@ handle_client_mutation (void *cls, | |||
1514 | pm); | 1509 | pm); |
1515 | return; | 1510 | return; |
1516 | } | 1511 | } |
1517 | execute_mutation (set, m); | 1512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1513 | "Executing mutation on set\n"); | ||
1514 | execute_mutation (set, | ||
1515 | m); | ||
1518 | } | 1516 | } |
1519 | 1517 | ||
1520 | 1518 | ||
@@ -1531,8 +1529,8 @@ advance_generation (struct Set *set) | |||
1531 | 1529 | ||
1532 | if (set->current_generation == set->content->latest_generation) | 1530 | if (set->current_generation == set->content->latest_generation) |
1533 | { | 1531 | { |
1534 | set->content->latest_generation += 1; | 1532 | set->content->latest_generation++; |
1535 | set->current_generation += 1; | 1533 | set->current_generation++; |
1536 | return; | 1534 | return; |
1537 | } | 1535 | } |
1538 | 1536 | ||
@@ -1540,10 +1538,8 @@ advance_generation (struct Set *set) | |||
1540 | 1538 | ||
1541 | r.start = set->current_generation + 1; | 1539 | r.start = set->current_generation + 1; |
1542 | r.end = set->content->latest_generation + 1; | 1540 | r.end = set->content->latest_generation + 1; |
1543 | |||
1544 | set->content->latest_generation = r.end; | 1541 | set->content->latest_generation = r.end; |
1545 | set->current_generation = r.end; | 1542 | set->current_generation = r.end; |
1546 | |||
1547 | GNUNET_array_append (set->excluded_generations, | 1543 | GNUNET_array_append (set->excluded_generations, |
1548 | set->excluded_generations_size, | 1544 | set->excluded_generations_size, |
1549 | r); | 1545 | r); |
@@ -1678,7 +1674,7 @@ handle_client_evaluate (void *cls, | |||
1678 | // mutations won't interfer with the running operation. | 1674 | // mutations won't interfer with the running operation. |
1679 | op->generation_created = set->current_generation; | 1675 | op->generation_created = set->current_generation; |
1680 | advance_generation (set); | 1676 | advance_generation (set); |
1681 | op->type = set->type; | 1677 | op->operation = set->operation; |
1682 | op->vt = set->vt; | 1678 | op->vt = set->vt; |
1683 | GNUNET_CONTAINER_DLL_insert (set->ops_head, | 1679 | GNUNET_CONTAINER_DLL_insert (set->ops_head, |
1684 | set->ops_tail, | 1680 | set->ops_tail, |
@@ -1847,11 +1843,9 @@ handle_client_copy_lazy_connect (void *cls, | |||
1847 | { | 1843 | { |
1848 | case GNUNET_SET_OPERATION_INTERSECTION: | 1844 | case GNUNET_SET_OPERATION_INTERSECTION: |
1849 | set->vt = _GSS_intersection_vt (); | 1845 | set->vt = _GSS_intersection_vt (); |
1850 | set->type = OT_INTERSECTION; | ||
1851 | break; | 1846 | break; |
1852 | case GNUNET_SET_OPERATION_UNION: | 1847 | case GNUNET_SET_OPERATION_UNION: |
1853 | set->vt = _GSS_union_vt (); | 1848 | set->vt = _GSS_union_vt (); |
1854 | set->type = OT_UNION; | ||
1855 | break; | 1849 | break; |
1856 | default: | 1850 | default: |
1857 | GNUNET_assert (0); | 1851 | GNUNET_assert (0); |
@@ -2020,7 +2014,7 @@ handle_client_accept (void *cls, | |||
2020 | advance_generation (set); | 2014 | advance_generation (set); |
2021 | 2015 | ||
2022 | op->vt = set->vt; | 2016 | op->vt = set->vt; |
2023 | op->type = set->type; | 2017 | op->operation = set->operation; |
2024 | op->vt->accept (op); | 2018 | op->vt->accept (op); |
2025 | GNUNET_SERVICE_client_continue (client); | 2019 | GNUNET_SERVICE_client_continue (client); |
2026 | } | 2020 | } |