aboutsummaryrefslogtreecommitdiff
path: root/src/set/set_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set/set_api.c')
-rw-r--r--src/set/set_api.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/set/set_api.c b/src/set/set_api.c
index 2ea002231..775e390de 100644
--- a/src/set/set_api.c
+++ b/src/set/set_api.c
@@ -30,6 +30,7 @@
30#include "gnunet_set_service.h" 30#include "gnunet_set_service.h"
31#include "set.h" 31#include "set.h"
32#include "mq.h" 32#include "mq.h"
33#include <inttypes.h>
33 34
34 35
35#define LOG(kind,...) GNUNET_log_from (kind, "set-api",__VA_ARGS__) 36#define LOG(kind,...) GNUNET_log_from (kind, "set-api",__VA_ARGS__)
@@ -49,7 +50,7 @@ struct GNUNET_SET_Handle
49 */ 50 */
50struct GNUNET_SET_Request 51struct GNUNET_SET_Request
51{ 52{
52 uint32_t request_id; 53 uint32_t accept_id;
53 int accepted; 54 int accepted;
54}; 55};
55 56
@@ -98,20 +99,23 @@ handle_result (void *cls, const struct GNUNET_MessageHeader *mh)
98 } 99 }
99 100
100 oh = GNUNET_MQ_assoc_get (set->mq, ntohl (msg->request_id)); 101 oh = GNUNET_MQ_assoc_get (set->mq, ntohl (msg->request_id));
101 GNUNET_break (NULL != oh); 102 GNUNET_assert (NULL != oh);
102 if (GNUNET_SCHEDULER_NO_TASK != oh->timeout_task) 103 /* status is not STATUS_OK => there's no attached element,
103 { 104 * and this is the last result message we get */
104 GNUNET_SCHEDULER_cancel (oh->timeout_task);
105 oh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
106 }
107 if (htons (msg->result_status) != GNUNET_SET_STATUS_OK) 105 if (htons (msg->result_status) != GNUNET_SET_STATUS_OK)
108 { 106 {
107 if (GNUNET_SCHEDULER_NO_TASK != oh->timeout_task)
108 {
109 GNUNET_SCHEDULER_cancel (oh->timeout_task);
110 oh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
111 }
112 GNUNET_MQ_assoc_remove (set->mq, ntohl (msg->request_id));
109 if (NULL != oh->result_cb) 113 if (NULL != oh->result_cb)
110 oh->result_cb (oh->result_cls, NULL, htons (msg->result_status)); 114 oh->result_cb (oh->result_cls, NULL, htons (msg->result_status));
111 GNUNET_MQ_assoc_remove (set->mq, ntohl (msg->request_id));
112 GNUNET_free (oh); 115 GNUNET_free (oh);
113 return; 116 return;
114 } 117 }
118
115 e.data = &msg[1]; 119 e.data = &msg[1];
116 e.size = ntohs (mh->size) - sizeof (struct ResultMessage); 120 e.size = ntohs (mh->size) - sizeof (struct ResultMessage);
117 e.type = msg->element_type; 121 e.type = msg->element_type;
@@ -133,18 +137,25 @@ handle_request (void *cls, const struct GNUNET_MessageHeader *mh)
133 struct GNUNET_SET_Request *req; 137 struct GNUNET_SET_Request *req;
134 138
135 req = GNUNET_new (struct GNUNET_SET_Request); 139 req = GNUNET_new (struct GNUNET_SET_Request);
136 req->request_id = ntohl (msg->request_id); 140 req->accept_id = ntohl (msg->accept_id);
141 /* calling GNUNET_SET_accept in the listen cb will set req->accepted */
137 lh->listen_cb (lh->listen_cls, &msg->peer_id, &mh[1], req); 142 lh->listen_cb (lh->listen_cls, &msg->peer_id, &mh[1], req);
143
138 if (GNUNET_NO == req->accepted) 144 if (GNUNET_NO == req->accepted)
139 { 145 {
140 struct GNUNET_MQ_Message *mqm; 146 struct GNUNET_MQ_Message *mqm;
141 struct AcceptMessage *amsg; 147 struct AcceptMessage *amsg;
142 148
143 mqm = GNUNET_MQ_msg (amsg, GNUNET_MESSAGE_TYPE_SET_ACCEPT); 149 mqm = GNUNET_MQ_msg (amsg, GNUNET_MESSAGE_TYPE_SET_ACCEPT);
144 amsg->request_id = msg->request_id; 150 /* no request id, as we refused */
151 amsg->request_id = htonl (0);
152 amsg->accept_id = msg->accept_id;
145 GNUNET_MQ_send (lh->mq, mqm); 153 GNUNET_MQ_send (lh->mq, mqm);
146 GNUNET_free (req); 154 GNUNET_free (req);
147 } 155 }
156
157 /* the accept-case is handled in GNUNET_SET_accept,
158 * as we have the accept message available there */
148} 159}
149 160
150 161
@@ -173,7 +184,7 @@ GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
173 184
174 set = GNUNET_new (struct GNUNET_SET_Handle); 185 set = GNUNET_new (struct GNUNET_SET_Handle);
175 set->client = GNUNET_CLIENT_connect ("set", cfg); 186 set->client = GNUNET_CLIENT_connect ("set", cfg);
176 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set client created\n"); 187 LOG (GNUNET_ERROR_TYPE_INFO, "set client created\n");
177 GNUNET_assert (NULL != set->client); 188 GNUNET_assert (NULL != set->client);
178 set->mq = GNUNET_MQ_queue_for_connection_client (set->client, mq_handlers, set); 189 set->mq = GNUNET_MQ_queue_for_connection_client (set->client, mq_handlers, set);
179 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_CREATE); 190 mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_CREATE);
@@ -377,12 +388,9 @@ GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
377void 388void
378GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) 389GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh)
379{ 390{
380 GNUNET_MQ_destroy (lh->mq);
381 lh->mq = NULL;
382 GNUNET_CLIENT_disconnect (lh->client); 391 GNUNET_CLIENT_disconnect (lh->client);
383 lh->client = NULL; 392 GNUNET_MQ_destroy (lh->mq);
384 lh->listen_cb = NULL; 393 GNUNET_free (lh);
385 lh->listen_cls = NULL;
386} 394}
387 395
388 396
@@ -420,8 +428,8 @@ GNUNET_SET_accept (struct GNUNET_SET_Request *request,
420 oh->set = set; 428 oh->set = set;
421 429
422 mqm = GNUNET_MQ_msg (msg , GNUNET_MESSAGE_TYPE_SET_ACCEPT); 430 mqm = GNUNET_MQ_msg (msg , GNUNET_MESSAGE_TYPE_SET_ACCEPT);
423 msg->request_id = htonl (request->request_id); 431 msg->request_id = htonl (GNUNET_MQ_assoc_add (set->mq, NULL, oh));
424 msg->accepted = 1; 432 msg->accept_id = htonl (request->accept_id);
425 GNUNET_MQ_send (set->mq, mqm); 433 GNUNET_MQ_send (set->mq, mqm);
426 434
427 oh->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, operation_timeout_task, oh); 435 oh->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, operation_timeout_task, oh);