aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2016-10-04 19:44:37 +0000
committerJulius Bünger <buenger@mytum.de>2016-10-04 19:44:37 +0000
commitc406330a6fb8a11e37ceb9d7bbe45dc2e0e9aa13 (patch)
tree7aabed8a6319e35b93df9a71e1a37e790469f08a /src/rps
parentf251b09db8434fd448c3f7dbf359a21a7f92b0e8 (diff)
downloadgnunet-c406330a6fb8a11e37ceb9d7bbe45dc2e0e9aa13.tar.gz
gnunet-c406330a6fb8a11e37ceb9d7bbe45dc2e0e9aa13.zip
-rps api: resend requests after reconnect
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/rps_api.c76
1 files changed, 69 insertions, 7 deletions
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index 012b36832..3d2f37359 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -75,6 +75,11 @@ struct GNUNET_RPS_Request_Handle
75 uint32_t id; 75 uint32_t id;
76 76
77 /** 77 /**
78 * The number of requested peers.
79 */
80 uint32_t num_peers;
81
82 /**
78 * The callback to be called when we receive an answer. 83 * The callback to be called when we receive an answer.
79 */ 84 */
80 GNUNET_RPS_NotifyReadyCB ready_cb; 85 GNUNET_RPS_NotifyReadyCB ready_cb;
@@ -108,6 +113,64 @@ struct cb_cls_pack
108 struct GNUNET_CLIENT_Connection *service_conn; 113 struct GNUNET_CLIENT_Connection *service_conn;
109}; 114};
110 115
116/**
117 * @brief Send a request to the service.
118 *
119 * @param h rps handle
120 * @param id id of the request
121 * @param num_req_peers number of peers
122 */
123void
124send_request (const struct GNUNET_RPS_Handle *h,
125 uint32_t id,
126 uint32_t num_req_peers)
127{
128 struct GNUNET_MQ_Envelope *ev;
129 struct GNUNET_RPS_CS_RequestMessage *msg;
130
131 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST);
132 msg->num_peers = htonl (num_req_peers);
133 msg->id = htonl (id);
134 GNUNET_MQ_send (h->mq, ev);
135}
136
137/**
138 * @brief Iterator function over pending requests
139 *
140 * Implements #GNUNET_CONTAINER_HashMapIterator32
141 *
142 * @param cls rps handle
143 * @param key id of the request
144 * @param value request handle
145 *
146 * @return GNUNET_YES to continue iteration
147 */
148int
149resend_requests_iterator (void *cls, uint32_t key, void *value)
150{
151 const struct GNUNET_RPS_Handle *h = cls;
152 const struct GNUNET_RPS_Request_Handle *req_handle = value;
153
154 send_request (h, req_handle->id, req_handle->num_peers);
155 return GNUNET_YES; /* continue iterating */
156}
157
158/**
159 * @brief Resend all pending requests
160 *
161 * This is used to resend all pending requests after the client
162 * reconnected to the service, because the service cancels all
163 * pending requests after reconnection.
164 *
165 * @param h rps handle
166 */
167void
168resend_requests (struct GNUNET_RPS_Handle *h)
169{
170 GNUNET_CONTAINER_multihashmap32_iterate (h->req_handlers,
171 resend_requests_iterator,
172 h);
173}
111 174
112 175
113/** 176/**
@@ -165,6 +228,7 @@ handle_reply (void *cls,
165 GNUNET_CONTAINER_multihashmap32_contains (h->req_handlers, id)); 228 GNUNET_CONTAINER_multihashmap32_contains (h->req_handlers, id));
166 rh = GNUNET_CONTAINER_multihashmap32_get (h->req_handlers, id); 229 rh = GNUNET_CONTAINER_multihashmap32_get (h->req_handlers, id);
167 GNUNET_assert (NULL != rh); 230 GNUNET_assert (NULL != rh);
231 GNUNET_assert (rh->num_peers == ntohl (msg->num_peers));
168 GNUNET_CONTAINER_multihashmap32_remove_all (h->req_handlers, id); 232 GNUNET_CONTAINER_multihashmap32_remove_all (h->req_handlers, id);
169 rh->ready_cb (rh->ready_cb_cls, 233 rh->ready_cb (rh->ready_cb_cls,
170 ntohl (msg->num_peers), 234 ntohl (msg->num_peers),
@@ -200,6 +264,9 @@ mq_error_handler (void *cls,
200 4: TIMEOUT\n", 264 4: TIMEOUT\n",
201 error); 265 error);
202 reconnect (h); 266 reconnect (h);
267 /* Resend all pending request as the service destroyed its knowledge
268 * about them */
269 resend_requests (h);
203} 270}
204 271
205 272
@@ -267,13 +334,11 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
267 void *cls) 334 void *cls)
268{ 335{
269 struct GNUNET_RPS_Request_Handle *rh; 336 struct GNUNET_RPS_Request_Handle *rh;
270 struct GNUNET_MQ_Envelope *ev;
271 struct GNUNET_RPS_CS_RequestMessage *msg;
272 337
273 // assert func != NULL
274 rh = GNUNET_new (struct GNUNET_RPS_Request_Handle); 338 rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
275 rh->rps_handle = rps_handle; 339 rh->rps_handle = rps_handle;
276 rh->id = rps_handle->current_request_id++; 340 rh->id = rps_handle->current_request_id++;
341 rh->num_peers = num_req_peers;
277 rh->ready_cb = ready_cb; 342 rh->ready_cb = ready_cb;
278 rh->ready_cb_cls = cls; 343 rh->ready_cb_cls = cls;
279 344
@@ -285,10 +350,7 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
285 GNUNET_CONTAINER_multihashmap32_put (rps_handle->req_handlers, rh->id, rh, 350 GNUNET_CONTAINER_multihashmap32_put (rps_handle->req_handlers, rh->id, rh,
286 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 351 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
287 352
288 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST); 353 send_request (rps_handle, rh->id, num_req_peers);
289 msg->num_peers = htonl (num_req_peers);
290 msg->id = htonl (rh->id);
291 GNUNET_MQ_send (rps_handle->mq, ev);
292 return rh; 354 return rh;
293} 355}
294 356