aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-03-12 18:00:39 +0100
committerChristian Grothoff <christian@grothoff.org>2017-03-12 18:00:39 +0100
commit67f859104e0c89afc8263bb49173a5e9835d2c24 (patch)
tree94f863c0fde505ed6681e591afebe1c51501b713 /src/set
parenta2ac01f46c4d57034b5d40201b29701ff95b456a (diff)
downloadgnunet-67f859104e0c89afc8263bb49173a5e9835d2c24.tar.gz
gnunet-67f859104e0c89afc8263bb49173a5e9835d2c24.zip
de-duplicate operation types
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set.c46
-rw-r--r--src/set/gnunet-service-set.h30
-rw-r--r--src/set/gnunet-service-set_intersection.c6
-rw-r--r--src/set/gnunet-service-set_union.c16
4 files changed, 33 insertions, 65 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;
161static struct Set * 161static struct Set *
162set_get (struct GNUNET_SERVICE_Client *client) 162set_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)
180static struct Listener * 178static struct Listener *
181listener_get (struct GNUNET_SERVICE_Client *client) 179listener_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)
199static struct Operation * 197static struct Operation *
200get_incoming (uint32_t id) 198get_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}
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index c981430ef..86313d179 100644
--- a/src/set/gnunet-service-set.h
+++ b/src/set/gnunet-service-set.h
@@ -345,27 +345,6 @@ struct Listener;
345 345
346 346
347/** 347/**
348 * Possible set operations.
349 */
350enum OperationType {
351 /**
352 * Operation type unknown.
353 */
354 OT_UNKNOWN = 0,
355
356 /**
357 * We are performing a union.
358 */
359 OT_UNION,
360
361 /**
362 * We are performing an intersection.
363 */
364 OT_INTERSECTION
365};
366
367
368/**
369 * Operation context used to execute a set operation. 348 * Operation context used to execute a set operation.
370 */ 349 */
371struct Operation 350struct Operation
@@ -429,9 +408,9 @@ struct Operation
429 struct GNUNET_SCHEDULER_Task *timeout_task; 408 struct GNUNET_SCHEDULER_Task *timeout_task;
430 409
431 /** 410 /**
432 * What type of operation is this? 411 * The type of the operation.
433 */ 412 */
434 enum OperationType type; 413 enum GNUNET_SET_OperationType operation;
435 414
436 /** 415 /**
437 * Unique request id for the request from a remote peer, sent to the 416 * Unique request id for the request from a remote peer, sent to the
@@ -589,11 +568,6 @@ struct Set
589 struct Operation *ops_tail; 568 struct Operation *ops_tail;
590 569
591 /** 570 /**
592 * What type of operation is this set for?
593 */
594 enum OperationType type;
595
596 /**
597 * Current generation, that is, number of previously executed 571 * Current generation, that is, number of previously executed
598 * operations and lazy copies on the underlying set content. 572 * operations and lazy copies on the underlying set content.
599 */ 573 */
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c
index bb369a81f..8307672b9 100644
--- a/src/set/gnunet-service-set_intersection.c
+++ b/src/set/gnunet-service-set_intersection.c
@@ -677,7 +677,7 @@ check_intersection_p2p_bf (void *cls,
677{ 677{
678 struct Operation *op = cls; 678 struct Operation *op = cls;
679 679
680 if (OT_INTERSECTION != op->type) 680 if (GNUNET_SET_OPERATION_INTERSECTION != op->operation)
681 { 681 {
682 GNUNET_break_op (0); 682 GNUNET_break_op (0);
683 return GNUNET_SYSERR; 683 return GNUNET_SYSERR;
@@ -869,7 +869,7 @@ handle_intersection_p2p_element_info (void *cls,
869{ 869{
870 struct Operation *op = cls; 870 struct Operation *op = cls;
871 871
872 if (OT_INTERSECTION != op->type) 872 if (GNUNET_SET_OPERATION_INTERSECTION != op->operation)
873 { 873 {
874 GNUNET_break_op (0); 874 GNUNET_break_op (0);
875 fail_intersection_operation(op); 875 fail_intersection_operation(op);
@@ -970,7 +970,7 @@ handle_intersection_p2p_done (void *cls,
970{ 970{
971 struct Operation *op = cls; 971 struct Operation *op = cls;
972 972
973 if (OT_INTERSECTION != op->type) 973 if (GNUNET_SET_OPERATION_INTERSECTION != op->operation)
974 { 974 {
975 GNUNET_break_op (0); 975 GNUNET_break_op (0);
976 fail_intersection_operation(op); 976 fail_intersection_operation(op);
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index 1ff3d7716..9eaf12fef 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -1211,7 +1211,7 @@ check_union_p2p_ibf (void *cls,
1211 struct Operation *op = cls; 1211 struct Operation *op = cls;
1212 unsigned int buckets_in_message; 1212 unsigned int buckets_in_message;
1213 1213
1214 if (OT_UNION != op->type) 1214 if (GNUNET_SET_OPERATION_UNION != op->operation)
1215 { 1215 {
1216 GNUNET_break_op (0); 1216 GNUNET_break_op (0);
1217 return GNUNET_SYSERR; 1217 return GNUNET_SYSERR;
@@ -1447,7 +1447,7 @@ check_union_p2p_elements (void *cls,
1447{ 1447{
1448 struct Operation *op = cls; 1448 struct Operation *op = cls;
1449 1449
1450 if (OT_UNION != op->type) 1450 if (GNUNET_SET_OPERATION_UNION != op->operation)
1451 { 1451 {
1452 GNUNET_break_op (0); 1452 GNUNET_break_op (0);
1453 return GNUNET_SYSERR; 1453 return GNUNET_SYSERR;
@@ -1575,7 +1575,7 @@ check_union_p2p_full_element (void *cls,
1575{ 1575{
1576 struct Operation *op = cls; 1576 struct Operation *op = cls;
1577 1577
1578 if (OT_UNION != op->type) 1578 if (GNUNET_SET_OPERATION_UNION != op->operation)
1579 { 1579 {
1580 GNUNET_break_op (0); 1580 GNUNET_break_op (0);
1581 return GNUNET_SYSERR; 1581 return GNUNET_SYSERR;
@@ -1690,7 +1690,7 @@ check_union_p2p_inquiry (void *cls,
1690 struct Operation *op = cls; 1690 struct Operation *op = cls;
1691 unsigned int num_keys; 1691 unsigned int num_keys;
1692 1692
1693 if (OT_UNION != op->type) 1693 if (GNUNET_SET_OPERATION_UNION != op->operation)
1694 { 1694 {
1695 GNUNET_break_op (0); 1695 GNUNET_break_op (0);
1696 return GNUNET_SYSERR; 1696 return GNUNET_SYSERR;
@@ -1790,7 +1790,7 @@ handle_union_p2p_request_full (void *cls,
1790 1790
1791 LOG (GNUNET_ERROR_TYPE_INFO, 1791 LOG (GNUNET_ERROR_TYPE_INFO,
1792 "Received request for full set transmission\n"); 1792 "Received request for full set transmission\n");
1793 if (OT_UNION != op->type) 1793 if (GNUNET_SET_OPERATION_UNION != op->operation)
1794 { 1794 {
1795 GNUNET_break_op (0); 1795 GNUNET_break_op (0);
1796 fail_union_operation (op); 1796 fail_union_operation (op);
@@ -1880,7 +1880,7 @@ check_union_p2p_demand (void *cls,
1880 struct Operation *op = cls; 1880 struct Operation *op = cls;
1881 unsigned int num_hashes; 1881 unsigned int num_hashes;
1882 1882
1883 if (OT_UNION != op->type) 1883 if (GNUNET_SET_OPERATION_UNION != op->operation)
1884 { 1884 {
1885 GNUNET_break_op (0); 1885 GNUNET_break_op (0);
1886 return GNUNET_SYSERR; 1886 return GNUNET_SYSERR;
@@ -1984,7 +1984,7 @@ check_union_p2p_offer (void *cls,
1984 struct Operation *op = cls; 1984 struct Operation *op = cls;
1985 unsigned int num_hashes; 1985 unsigned int num_hashes;
1986 1986
1987 if (OT_UNION != op->type) 1987 if (GNUNET_SET_OPERATION_UNION != op->operation)
1988 { 1988 {
1989 GNUNET_break_op (0); 1989 GNUNET_break_op (0);
1990 return GNUNET_SYSERR; 1990 return GNUNET_SYSERR;
@@ -2079,7 +2079,7 @@ handle_union_p2p_done (void *cls,
2079{ 2079{
2080 struct Operation *op = cls; 2080 struct Operation *op = cls;
2081 2081
2082 if (OT_UNION != op->type) 2082 if (GNUNET_SET_OPERATION_UNION != op->operation)
2083 { 2083 {
2084 GNUNET_break_op (0); 2084 GNUNET_break_op (0);
2085 fail_union_operation (op); 2085 fail_union_operation (op);