aboutsummaryrefslogtreecommitdiff
path: root/src/rps/rps_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/rps_api.c')
-rw-r--r--src/rps/rps_api.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index b055f6265..b52e9da51 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -40,12 +40,7 @@ struct GNUNET_RPS_Handle
40 /** 40 /**
41 * The handle to the client configuration. 41 * The handle to the client configuration.
42 */ 42 */
43 struct GNUNET_CONFIGURATION_Handle *cfg; 43 const struct GNUNET_CONFIGURATION_Handle *cfg;
44
45 /**
46 * The connection to the client.
47 */
48 struct GNUNET_CLIENT_Connection *conn;
49 44
50 /** 45 /**
51 * The message queue to the client. 46 * The message queue to the client.
@@ -214,6 +209,8 @@ mq_error_handler (void *cls,
214static void 209static void
215reconnect (struct GNUNET_RPS_Handle *h) 210reconnect (struct GNUNET_RPS_Handle *h)
216{ 211{
212 struct GNUNET_CLIENT_Connection *conn;
213
217 GNUNET_MQ_hd_var_size (reply, 214 GNUNET_MQ_hd_var_size (reply,
218 GNUNET_MESSAGE_TYPE_RPS_CS_REPLY, 215 GNUNET_MESSAGE_TYPE_RPS_CS_REPLY,
219 struct GNUNET_RPS_CS_ReplyMessage); 216 struct GNUNET_RPS_CS_ReplyMessage);
@@ -224,11 +221,10 @@ reconnect (struct GNUNET_RPS_Handle *h)
224 221
225 if (NULL != h->mq) 222 if (NULL != h->mq)
226 GNUNET_MQ_destroy (h->mq); 223 GNUNET_MQ_destroy (h->mq);
227 if (NULL != h->conn) 224 conn = GNUNET_CLIENT_connect ("rps", h->cfg);
228 GNUNET_CLIENT_disconnect (h->conn); 225 if (NULL == conn)
229 h->conn = GNUNET_CLIENT_connect ("rps", h->cfg); 226 return;
230 GNUNET_assert (NULL != h->conn); 227 h->mq = GNUNET_MQ_queue_for_connection_client (conn,
231 h->mq = GNUNET_MQ_queue_for_connection_client (h->conn,
232 mq_handlers, 228 mq_handlers,
233 &mq_error_handler, 229 &mq_error_handler,
234 h); 230 h);
@@ -241,15 +237,19 @@ reconnect (struct GNUNET_RPS_Handle *h)
241 * @param cfg configuration to use 237 * @param cfg configuration to use
242 * @return a handle to the service 238 * @return a handle to the service
243 */ 239 */
244 struct GNUNET_RPS_Handle * 240struct GNUNET_RPS_Handle *
245GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) 241GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
246{ 242{
247 struct GNUNET_RPS_Handle *h; 243 struct GNUNET_RPS_Handle *h;
248 //struct GNUNET_RPS_Request_Handle *rh;
249 244
250 h = GNUNET_new(struct GNUNET_RPS_Handle); 245 h = GNUNET_new (struct GNUNET_RPS_Handle);
251 h->cfg = GNUNET_CONFIGURATION_dup (cfg); 246 h->cfg = cfg;
252 reconnect (h); 247 reconnect (h);
248 if (NULL == h->mq)
249 {
250 GNUNET_free (h);
251 return NULL;
252 }
253 h->req_handlers = GNUNET_CONTAINER_multihashmap32_create (4); 253 h->req_handlers = GNUNET_CONTAINER_multihashmap32_create (4);
254 return h; 254 return h;
255} 255}
@@ -264,7 +264,7 @@ GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
264 * @param cls closure given to the callback 264 * @param cls closure given to the callback
265 * @return a handle to cancel this request 265 * @return a handle to cancel this request
266 */ 266 */
267 struct GNUNET_RPS_Request_Handle * 267struct GNUNET_RPS_Request_Handle *
268GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, 268GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
269 uint32_t num_req_peers, 269 uint32_t num_req_peers,
270 GNUNET_RPS_NotifyReadyCB ready_cb, 270 GNUNET_RPS_NotifyReadyCB ready_cb,
@@ -304,7 +304,7 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
304 * @param n number of peers to seed 304 * @param n number of peers to seed
305 * @param ids the ids of the peers seeded 305 * @param ids the ids of the peers seeded
306 */ 306 */
307 void 307void
308GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, 308GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
309 uint32_t n, 309 uint32_t n,
310 const struct GNUNET_PeerIdentity *ids) 310 const struct GNUNET_PeerIdentity *ids)
@@ -375,7 +375,7 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
375 * if @type is 2 the last id is the id of the 375 * if @type is 2 the last id is the id of the
376 * peer to be isolated from the rest 376 * peer to be isolated from the rest
377 */ 377 */
378 void 378void
379GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, 379GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
380 uint32_t type, 380 uint32_t type,
381 uint32_t num_peers, 381 uint32_t num_peers,
@@ -456,7 +456,7 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
456 * 456 *
457 * @param rh request handle of request to cancle 457 * @param rh request handle of request to cancle
458 */ 458 */
459 void 459void
460GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh) 460GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
461{ 461{
462 struct GNUNET_RPS_Handle *h; 462 struct GNUNET_RPS_Handle *h;
@@ -482,12 +482,9 @@ GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
482 * 482 *
483 * @param h the handle to the rps service 483 * @param h the handle to the rps service
484 */ 484 */
485 void 485void
486GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h) 486GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
487{ 487{
488 if (NULL != h->conn)
489 GNUNET_CLIENT_disconnect (h->conn);
490 GNUNET_CONFIGURATION_destroy (h->cfg);
491 GNUNET_MQ_destroy (h->mq); 488 GNUNET_MQ_destroy (h->mq);
492 if (0 < GNUNET_CONTAINER_multihashmap32_size (h->req_handlers)) 489 if (0 < GNUNET_CONTAINER_multihashmap32_size (h->req_handlers))
493 LOG (GNUNET_ERROR_TYPE_WARNING, 490 LOG (GNUNET_ERROR_TYPE_WARNING,