aboutsummaryrefslogtreecommitdiff
path: root/src/set
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-11-27 10:31:36 +0000
committerChristian Grothoff <christian@grothoff.org>2014-11-27 10:31:36 +0000
commit68ac96f244a53f6a5dcdd939183d3904f43e4984 (patch)
tree0722829255a4a83293f26a810524b7921cd88a84 /src/set
parent47c52147dac6bc423b43aa8e2721585df893440b (diff)
downloadgnunet-68ac96f244a53f6a5dcdd939183d3904f43e4984.tar.gz
gnunet-68ac96f244a53f6a5dcdd939183d3904f43e4984.zip
remove additional variant of operation state
Diffstat (limited to 'src/set')
-rw-r--r--src/set/gnunet-service-set.c119
-rw-r--r--src/set/gnunet-service-set.h23
-rw-r--r--src/set/gnunet-service-set_intersection.c3
-rw-r--r--src/set/gnunet-service-set_union.c18
4 files changed, 72 insertions, 91 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index b050cb465..0fc2e4d6a 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -28,36 +28,6 @@
28 28
29 29
30/** 30/**
31 * State of an operation where the peer has connected to us, but is not yet
32 * evaluating a set operation. Once the peer has sent a concrete request, and
33 * the client has accepted or rejected it, this information will be deleted
34 * and replaced by the real set operation state.
35 */
36struct OperationState
37{
38 /**
39 * The identity of the requesting peer. Needs to
40 * be stored here as the op spec might not have been created yet.
41 */
42 struct GNUNET_PeerIdentity peer;
43
44 /**
45 * Timeout task, if the incoming peer has not been accepted
46 * after the timeout, it will be disconnected.
47 */
48 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
49
50 /**
51 * Unique request id for the request from a remote peer, sent to the
52 * client, which will accept or reject the request. Set to '0' iff
53 * the request has not been suggested yet.
54 */
55 uint32_t suggest_id;
56
57};
58
59
60/**
61 * A listener is inhabited by a client, and waits for evaluation 31 * A listener is inhabited by a client, and waits for evaluation
62 * requests from remote peers. 32 * requests from remote peers.
63 */ 33 */
@@ -199,7 +169,7 @@ get_incoming (uint32_t id)
199 struct Operation *op; 169 struct Operation *op;
200 170
201 for (op = incoming_head; NULL != op; op = op->next) 171 for (op = incoming_head; NULL != op; op = op->next)
202 if (op->state->suggest_id == id) 172 if (op->suggest_id == id)
203 { 173 {
204 // FIXME: remove this assertion once the corresponding bug is gone! 174 // FIXME: remove this assertion once the corresponding bug is gone!
205 GNUNET_assert (GNUNET_YES == op->is_incoming); 175 GNUNET_assert (GNUNET_YES == op->is_incoming);
@@ -498,16 +468,13 @@ incoming_destroy (struct Operation *incoming)
498 GNUNET_CONTAINER_DLL_remove (incoming_head, 468 GNUNET_CONTAINER_DLL_remove (incoming_head,
499 incoming_tail, 469 incoming_tail,
500 incoming); 470 incoming);
501 if (GNUNET_SCHEDULER_NO_TASK != incoming->state->timeout_task) 471 if (GNUNET_SCHEDULER_NO_TASK != incoming->timeout_task)
502 { 472 {
503 GNUNET_SCHEDULER_cancel (incoming->state->timeout_task); 473 GNUNET_SCHEDULER_cancel (incoming->timeout_task);
504 incoming->state->timeout_task = GNUNET_SCHEDULER_NO_TASK; 474 incoming->timeout_task = GNUNET_SCHEDULER_NO_TASK;
505 } 475 }
506 GNUNET_assert (NULL != incoming->state);
507 GNUNET_free (incoming->state);
508 /* make sure that the tunnel end handler will not destroy us again */ 476 /* make sure that the tunnel end handler will not destroy us again */
509 incoming->vt = NULL; 477 incoming->vt = NULL;
510 incoming->state = NULL;
511 if (NULL != incoming->mq) 478 if (NULL != incoming->mq)
512 { 479 {
513 GNUNET_MQ_destroy (incoming->mq); 480 GNUNET_MQ_destroy (incoming->mq);
@@ -544,7 +511,6 @@ listener_get_by_target (enum GNUNET_SET_OperationType op,
544} 511}
545 512
546 513
547// ----------------------
548/** 514/**
549 * Suggest the given request to the listener. The listening client can 515 * Suggest the given request to the listener. The listening client can
550 * then accept or reject the remote request. 516 * then accept or reject the remote request.
@@ -560,35 +526,34 @@ incoming_suggest (struct Operation *incoming,
560 struct GNUNET_SET_RequestMessage *cmsg; 526 struct GNUNET_SET_RequestMessage *cmsg;
561 527
562 GNUNET_assert (GNUNET_YES == incoming->is_incoming); 528 GNUNET_assert (GNUNET_YES == incoming->is_incoming);
563 GNUNET_assert (NULL != incoming->state);
564 GNUNET_assert (NULL != incoming->spec); 529 GNUNET_assert (NULL != incoming->spec);
565 GNUNET_assert (0 == incoming->state->suggest_id); 530 GNUNET_assert (0 == incoming->suggest_id);
566 incoming->state->suggest_id = suggest_id++; 531 incoming->suggest_id = suggest_id++;
567 532 if (0 == suggest_id)
568 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != incoming->state->timeout_task); 533 suggest_id++;
569 GNUNET_SCHEDULER_cancel (incoming->state->timeout_task); 534 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != incoming->timeout_task);
570 incoming->state->timeout_task = GNUNET_SCHEDULER_NO_TASK; 535 GNUNET_SCHEDULER_cancel (incoming->timeout_task);
571 536 incoming->timeout_task = GNUNET_SCHEDULER_NO_TASK;
572 mqm = GNUNET_MQ_msg_nested_mh (cmsg, 537 mqm = GNUNET_MQ_msg_nested_mh (cmsg,
573 GNUNET_MESSAGE_TYPE_SET_REQUEST, 538 GNUNET_MESSAGE_TYPE_SET_REQUEST,
574 incoming->spec->context_msg); 539 incoming->spec->context_msg);
575 GNUNET_assert (NULL != mqm); 540 GNUNET_assert (NULL != mqm);
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
577 "suggesting request with accept id %u\n", 542 "suggesting request with accept id %u\n",
578 incoming->state->suggest_id); 543 incoming->suggest_id);
579 cmsg->accept_id = htonl (incoming->state->suggest_id); 544 cmsg->accept_id = htonl (incoming->suggest_id);
580 cmsg->peer_id = incoming->spec->peer; 545 cmsg->peer_id = incoming->spec->peer;
581 GNUNET_MQ_send (listener->client_mq, mqm); 546 GNUNET_MQ_send (listener->client_mq, mqm);
582} 547}
583 548
584 549
585/** 550/**
586 * Handle a request for a set operation from 551 * Handle a request for a set operation from another peer.
587 * another peer.
588 * 552 *
589 * This msg is expected as the first and only msg handled through the 553 * This msg is expected as the first and only msg handled through the
590 * non-operation bound virtual table, acceptance of this operation replaces 554 * non-operation bound virtual table, acceptance of this operation replaces
591 * our virtual table and subsequent msgs would be routed differently. 555 * our virtual table and subsequent msgs would be routed differently (as
556 * we then know what type of operation this is).
592 * 557 *
593 * @param op the operation state 558 * @param op the operation state
594 * @param mh the received message 559 * @param mh the received message
@@ -605,23 +570,19 @@ handle_incoming_msg (struct Operation *op,
605 570
606 msg = (const struct OperationRequestMessage *) mh; 571 msg = (const struct OperationRequestMessage *) mh;
607 GNUNET_assert (GNUNET_YES == op->is_incoming); 572 GNUNET_assert (GNUNET_YES == op->is_incoming);
608
609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
610 "got op request\n");
611
612 if (GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST != ntohs (mh->type)) 573 if (GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST != ntohs (mh->type))
613 { 574 {
614 GNUNET_break_op (0); 575 GNUNET_break_op (0);
615 return GNUNET_SYSERR; 576 return GNUNET_SYSERR;
616 } 577 }
617
618 /* double operation request */ 578 /* double operation request */
619 if (NULL != op->spec) 579 if (NULL != op->spec)
620 { 580 {
621 GNUNET_break_op (0); 581 GNUNET_break_op (0);
622 return GNUNET_SYSERR; 582 return GNUNET_SYSERR;
623 } 583 }
624 584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
585 "Got op request\n");
625 spec = GNUNET_new (struct OperationSpecification); 586 spec = GNUNET_new (struct OperationSpecification);
626 spec->context_msg = GNUNET_MQ_extract_nested_mh (msg); 587 spec->context_msg = GNUNET_MQ_extract_nested_mh (msg);
627 // for simplicity we just backup the context msg instead of rebuilding it later on 588 // for simplicity we just backup the context msg instead of rebuilding it later on
@@ -631,7 +592,7 @@ handle_incoming_msg (struct Operation *op,
631 spec->app_id = msg->app_id; 592 spec->app_id = msg->app_id;
632 spec->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 593 spec->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
633 UINT32_MAX); 594 UINT32_MAX);
634 spec->peer = op->state->peer; 595 spec->peer = op->peer;
635 spec->remote_element_count = ntohl (msg->element_count); 596 spec->remote_element_count = ntohl (msg->element_count);
636 597
637 op->spec = spec; 598 op->spec = spec;
@@ -844,10 +805,10 @@ handle_client_listen (void *cls,
844 "considering (op: %u, app: %s, suggest: %u)\n", 805 "considering (op: %u, app: %s, suggest: %u)\n",
845 op->spec->operation, 806 op->spec->operation,
846 GNUNET_h2s (&op->spec->app_id), 807 GNUNET_h2s (&op->spec->app_id),
847 op->state->suggest_id); 808 op->suggest_id);
848 809
849 /* don't consider the incoming request if it has been already suggested to a listener */ 810 /* don't consider the incoming request if it has been already suggested to a listener */
850 if (0 != op->state->suggest_id) 811 if (0 != op->suggest_id)
851 continue; 812 continue;
852 if (listener->operation != op->spec->operation) 813 if (listener->operation != op->spec->operation)
853 continue; 814 continue;
@@ -1188,9 +1149,6 @@ handle_client_accept (void *cls,
1188 1149
1189 GNUNET_assert (GNUNET_YES == op->is_incoming); 1150 GNUNET_assert (GNUNET_YES == op->is_incoming);
1190 op->is_incoming = GNUNET_NO; 1151 op->is_incoming = GNUNET_NO;
1191 GNUNET_assert (NULL != op->state);
1192 GNUNET_free (op->state);
1193 op->state = NULL;
1194 GNUNET_CONTAINER_DLL_remove (incoming_head, 1152 GNUNET_CONTAINER_DLL_remove (incoming_head,
1195 incoming_tail, 1153 incoming_tail,
1196 op); 1154 op);
@@ -1259,7 +1217,7 @@ incoming_timeout_cb (void *cls,
1259{ 1217{
1260 struct Operation *incoming = cls; 1218 struct Operation *incoming = cls;
1261 1219
1262 incoming->state->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1220 incoming->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1263 GNUNET_assert (GNUNET_YES == incoming->is_incoming); 1221 GNUNET_assert (GNUNET_YES == incoming->is_incoming);
1264 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1222 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1265 return; 1223 return;
@@ -1288,10 +1246,10 @@ handle_incoming_disconnect (struct Operation *op)
1288 1246
1289 1247
1290/** 1248/**
1291 * Method called whenever another peer has added us to a channel 1249 * Method called whenever another peer has added us to a channel the
1292 * the other peer initiated. 1250 * other peer initiated. Only called (once) upon reception of data
1293 * Only called (once) upon reception of data with a message type which was 1251 * with a message type which was subscribed to in
1294 * subscribed to in GNUNET_CADET_connect(). 1252 * GNUNET_CADET_connect().
1295 * 1253 *
1296 * The channel context represents the operation itself and gets added to a DLL, 1254 * The channel context represents the operation itself and gets added to a DLL,
1297 * from where it gets looked up when our local listener client responds 1255 * from where it gets looked up when our local listener client responds
@@ -1307,18 +1265,16 @@ handle_incoming_disconnect (struct Operation *op)
1307 */ 1265 */
1308static void * 1266static void *
1309channel_new_cb (void *cls, 1267channel_new_cb (void *cls,
1310 struct GNUNET_CADET_Channel *channel, 1268 struct GNUNET_CADET_Channel *channel,
1311 const struct GNUNET_PeerIdentity *initiator, 1269 const struct GNUNET_PeerIdentity *initiator,
1312 uint32_t port, enum GNUNET_CADET_ChannelOption options) 1270 uint32_t port,
1271 enum GNUNET_CADET_ChannelOption options)
1313{ 1272{
1314 struct Operation *incoming;
1315 static const struct SetVT incoming_vt = { 1273 static const struct SetVT incoming_vt = {
1316 .msg_handler = handle_incoming_msg, 1274 .msg_handler = &handle_incoming_msg,
1317 .peer_disconnect = handle_incoming_disconnect 1275 .peer_disconnect = &handle_incoming_disconnect
1318 }; 1276 };
1319 1277 struct Operation *incoming;
1320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1321 "new incoming channel\n");
1322 1278
1323 if (GNUNET_APPLICATION_TYPE_SET != port) 1279 if (GNUNET_APPLICATION_TYPE_SET != port)
1324 { 1280 {
@@ -1326,22 +1282,21 @@ channel_new_cb (void *cls,
1326 GNUNET_CADET_channel_destroy (channel); 1282 GNUNET_CADET_channel_destroy (channel);
1327 return NULL; 1283 return NULL;
1328 } 1284 }
1329 1285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1286 "new incoming channel\n");
1330 incoming = GNUNET_new (struct Operation); 1287 incoming = GNUNET_new (struct Operation);
1331 incoming->is_incoming = GNUNET_YES; 1288 incoming->is_incoming = GNUNET_YES;
1332 incoming->state = GNUNET_new (struct OperationState); 1289 incoming->peer = *initiator;
1333 incoming->state->peer = *initiator;
1334 incoming->channel = channel; 1290 incoming->channel = channel;
1335 incoming->mq = GNUNET_CADET_mq_create (incoming->channel); 1291 incoming->mq = GNUNET_CADET_mq_create (incoming->channel);
1336 incoming->vt = &incoming_vt; 1292 incoming->vt = &incoming_vt;
1337 incoming->state->timeout_task = 1293 incoming->timeout_task =
1338 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1294 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1339 &incoming_timeout_cb, 1295 &incoming_timeout_cb,
1340 incoming); 1296 incoming);
1341 GNUNET_CONTAINER_DLL_insert_tail (incoming_head, 1297 GNUNET_CONTAINER_DLL_insert_tail (incoming_head,
1342 incoming_tail, 1298 incoming_tail,
1343 incoming); 1299 incoming);
1344
1345 return incoming; 1300 return incoming;
1346} 1301}
1347 1302
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index c226611ff..834f78780 100644
--- a/src/set/gnunet-service-set.h
+++ b/src/set/gnunet-service-set.h
@@ -326,7 +326,9 @@ struct Operation
326 struct OperationSpecification *spec; 326 struct OperationSpecification *spec;
327 327
328 /** 328 /**
329 * Operation-specific operation state. 329 * Operation-specific operation state. Note that the exact
330 * type depends on this being a union or intersection operation
331 * (and thus on @e vt).
330 */ 332 */
331 struct OperationState *state; 333 struct OperationState *state;
332 334
@@ -341,6 +343,25 @@ struct Operation
341 struct Operation *prev; 343 struct Operation *prev;
342 344
343 /** 345 /**
346 * The identity of the requesting peer. Needs to
347 * be stored here as the op spec might not have been created yet.
348 */
349 struct GNUNET_PeerIdentity peer;
350
351 /**
352 * Timeout task, if the incoming peer has not been accepted
353 * after the timeout, it will be disconnected.
354 */
355 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
356
357 /**
358 * Unique request id for the request from a remote peer, sent to the
359 * client, which will accept or reject the request. Set to '0' iff
360 * the request has not been suggested yet.
361 */
362 uint32_t suggest_id;
363
364 /**
344 * #GNUNET_YES if this is not a "real" set operation yet, and we still 365 * #GNUNET_YES if this is not a "real" set operation yet, and we still
345 * need to wait for the other peer to give us more details. 366 * need to wait for the other peer to give us more details.
346 */ 367 */
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c
index 4a252f4be..70c3fb450 100644
--- a/src/set/gnunet-service-set_intersection.c
+++ b/src/set/gnunet-service-set_intersection.c
@@ -69,8 +69,7 @@ enum IntersectionOperationPhase
69 69
70 70
71/** 71/**
72 * State of an evaluate operation 72 * State of an evaluate operation with another peer.
73 * with another peer.
74 */ 73 */
75struct OperationState 74struct OperationState
76{ 75{
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index 10ad1c545..c00728015 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -73,6 +73,7 @@ enum UnionOperationPhase
73 * We sent the request message, and expect a strata estimator 73 * We sent the request message, and expect a strata estimator
74 */ 74 */
75 PHASE_EXPECT_SE, 75 PHASE_EXPECT_SE,
76
76 /** 77 /**
77 * We sent the strata estimator, and expect an IBF. This phase is entered once 78 * We sent the strata estimator, and expect an IBF. This phase is entered once
78 * upon initialization and later via PHASE_EXPECT_ELEMENTS_AND_REQUESTS. 79 * upon initialization and later via PHASE_EXPECT_ELEMENTS_AND_REQUESTS.
@@ -80,10 +81,12 @@ enum UnionOperationPhase
80 * After receiving the complete IBF, we enter PHASE_EXPECT_ELEMENTS 81 * After receiving the complete IBF, we enter PHASE_EXPECT_ELEMENTS
81 */ 82 */
82 PHASE_EXPECT_IBF, 83 PHASE_EXPECT_IBF,
84
83 /** 85 /**
84 * Continuation for multi part IBFs. 86 * Continuation for multi part IBFs.
85 */ 87 */
86 PHASE_EXPECT_IBF_CONT, 88 PHASE_EXPECT_IBF_CONT,
89
87 /** 90 /**
88 * We are sending request and elements, 91 * We are sending request and elements,
89 * and thus only expect elements from the other peer. 92 * and thus only expect elements from the other peer.
@@ -93,6 +96,7 @@ enum UnionOperationPhase
93 * The remote peer is in PHASE_EXPECT_ELEMENTS_AND_REQUESTS 96 * The remote peer is in PHASE_EXPECT_ELEMENTS_AND_REQUESTS
94 */ 97 */
95 PHASE_EXPECT_ELEMENTS, 98 PHASE_EXPECT_ELEMENTS,
99
96 /** 100 /**
97 * We are expecting elements and requests, and send 101 * We are expecting elements and requests, and send
98 * requested elements back to the other peer. 102 * requested elements back to the other peer.
@@ -105,6 +109,7 @@ enum UnionOperationPhase
105 * PHASE_EXPECT_ELEMENTS 109 * PHASE_EXPECT_ELEMENTS
106 */ 110 */
107 PHASE_EXPECT_ELEMENTS_AND_REQUESTS, 111 PHASE_EXPECT_ELEMENTS_AND_REQUESTS,
112
108 /** 113 /**
109 * The protocol is over. 114 * The protocol is over.
110 * Results may still have to be sent to the client. 115 * Results may still have to be sent to the client.
@@ -114,15 +119,10 @@ enum UnionOperationPhase
114 119
115 120
116/** 121/**
117 * State of an evaluate operation 122 * State of an evaluate operation with another peer.
118 * with another peer.
119 */ 123 */
120struct OperationState 124struct OperationState
121{ 125{
122 /**
123 * Number of ibf buckets received
124 */
125 unsigned int ibf_buckets_received;
126 126
127 /** 127 /**
128 * Copy of the set's strata estimator at the time of 128 * Copy of the set's strata estimator at the time of
@@ -161,6 +161,12 @@ struct OperationState
161 * Did we send the client that we are done? 161 * Did we send the client that we are done?
162 */ 162 */
163 int client_done_sent; 163 int client_done_sent;
164
165 /**
166 * Number of ibf buckets received
167 */
168 unsigned int ibf_buckets_received;
169
164}; 170};
165 171
166 172