rps_api.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C)
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file rps/rps_api.c
  18. * @brief API for rps
  19. * @author Julius Bünger
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. #include "rps.h"
  24. #include "gnunet_rps_service.h"
  25. #include "rps-sampler_client.h"
  26. #include "gnunet_nse_service.h"
  27. #include <inttypes.h>
  28. #define LOG(kind, ...) GNUNET_log_from (kind, "rps-api", __VA_ARGS__)
  29. /**
  30. * Handle for a request to get peers from biased stream of ids
  31. */
  32. struct GNUNET_RPS_StreamRequestHandle
  33. {
  34. /**
  35. * The client issuing the request.
  36. */
  37. struct GNUNET_RPS_Handle *rps_handle;
  38. /**
  39. * The callback to be called when we receive an answer.
  40. */
  41. GNUNET_RPS_NotifyReadyCB ready_cb;
  42. /**
  43. * The closure for the callback.
  44. */
  45. void *ready_cb_cls;
  46. /**
  47. * @brief Scheduler task for scheduled callback
  48. */
  49. struct GNUNET_SCHEDULER_Task *callback_task;
  50. /**
  51. * @brief Next element of the DLL
  52. */
  53. struct GNUNET_RPS_StreamRequestHandle *next;
  54. /**
  55. * @brief Previous element of the DLL
  56. */
  57. struct GNUNET_RPS_StreamRequestHandle *prev;
  58. };
  59. /**
  60. * Handler to handle requests from a client.
  61. */
  62. struct GNUNET_RPS_Handle
  63. {
  64. /**
  65. * The handle to the client configuration.
  66. */
  67. const struct GNUNET_CONFIGURATION_Handle *cfg;
  68. /**
  69. * The message queue to the client.
  70. */
  71. struct GNUNET_MQ_Handle *mq;
  72. /**
  73. * @brief Callback called on each update of the view
  74. */
  75. GNUNET_RPS_NotifyReadyCB view_update_cb;
  76. /**
  77. * @brief Closure to each requested update of the view
  78. */
  79. void *view_update_cls;
  80. /**
  81. * @brief Closure to each requested peer from the biased stream
  82. */
  83. void *stream_input_cls;
  84. /**
  85. * @brief Head of the DLL of stream requests
  86. */
  87. struct GNUNET_RPS_StreamRequestHandle *stream_requests_head;
  88. /**
  89. * @brief Tail of the DLL of stream requests
  90. */
  91. struct GNUNET_RPS_StreamRequestHandle *stream_requests_tail;
  92. /**
  93. * @brief Handle to nse service
  94. */
  95. struct GNUNET_NSE_Handle *nse;
  96. /**
  97. * @brief Pointer to the head element in DLL of request handles
  98. */
  99. struct GNUNET_RPS_Request_Handle *rh_head;
  100. /**
  101. * @brief Pointer to the tail element in DLL of request handles
  102. */
  103. struct GNUNET_RPS_Request_Handle *rh_tail;
  104. /**
  105. * @brief Pointer to the head element in DLL of single request handles
  106. */
  107. struct GNUNET_RPS_Request_Handle_Single_Info *rhs_head;
  108. /**
  109. * @brief Pointer to the tail element in DLL of single request handles
  110. */
  111. struct GNUNET_RPS_Request_Handle_Single_Info *rhs_tail;
  112. /**
  113. * @brief The desired probability with which we want to have observed all
  114. * peers.
  115. */
  116. float desired_probability;
  117. /**
  118. * @brief A factor that catches the 'bias' of a random stream of peer ids.
  119. *
  120. * As introduced by Brahms: Factor between the number of unique ids in a
  121. * truly random stream and number of unique ids in the gossip stream.
  122. */
  123. float deficiency_factor;
  124. };
  125. /**
  126. * Handler for a single request from a client.
  127. */
  128. struct GNUNET_RPS_Request_Handle
  129. {
  130. /**
  131. * The client issuing the request.
  132. */
  133. struct GNUNET_RPS_Handle *rps_handle;
  134. /**
  135. * The number of requested peers.
  136. */
  137. uint32_t num_requests;
  138. /**
  139. * @brief The Sampler for the client request
  140. */
  141. struct RPS_Sampler *sampler;
  142. /**
  143. * @brief Request handle of the request to the sampler - needed to cancel the request
  144. */
  145. struct RPS_SamplerRequestHandle *sampler_rh;
  146. /**
  147. * @brief Request handle of the request of the biased stream of peers -
  148. * needed to cancel the request
  149. */
  150. struct GNUNET_RPS_StreamRequestHandle *srh;
  151. /**
  152. * The callback to be called when we receive an answer.
  153. */
  154. GNUNET_RPS_NotifyReadyCB ready_cb;
  155. /**
  156. * The closure for the callback.
  157. */
  158. void *ready_cb_cls;
  159. /**
  160. * @brief Pointer to next element in DLL
  161. */
  162. struct GNUNET_RPS_Request_Handle *next;
  163. /**
  164. * @brief Pointer to previous element in DLL
  165. */
  166. struct GNUNET_RPS_Request_Handle *prev;
  167. };
  168. /**
  169. * Handler for a single request from a client.
  170. */
  171. struct GNUNET_RPS_Request_Handle_Single_Info
  172. {
  173. /**
  174. * The client issuing the request.
  175. */
  176. struct GNUNET_RPS_Handle *rps_handle;
  177. /**
  178. * @brief The Sampler for the client request
  179. */
  180. struct RPS_Sampler *sampler;
  181. /**
  182. * @brief Request handle of the request to the sampler - needed to cancel the request
  183. */
  184. struct RPS_SamplerRequestHandleSingleInfo *sampler_rh;
  185. /**
  186. * @brief Request handle of the request of the biased stream of peers -
  187. * needed to cancel the request
  188. */
  189. struct GNUNET_RPS_StreamRequestHandle *srh;
  190. /**
  191. * The callback to be called when we receive an answer.
  192. */
  193. GNUNET_RPS_NotifyReadySingleInfoCB ready_cb;
  194. /**
  195. * The closure for the callback.
  196. */
  197. void *ready_cb_cls;
  198. /**
  199. * @brief Pointer to next element in DLL
  200. */
  201. struct GNUNET_RPS_Request_Handle_Single_Info *next;
  202. /**
  203. * @brief Pointer to previous element in DLL
  204. */
  205. struct GNUNET_RPS_Request_Handle_Single_Info *prev;
  206. };
  207. /**
  208. * Struct used to pack the callback, its closure (provided by the caller)
  209. * and the connection handler to the service to pass it to a callback function.
  210. */
  211. struct cb_cls_pack
  212. {
  213. /**
  214. * Callback provided by the client
  215. */
  216. GNUNET_RPS_NotifyReadyCB cb;
  217. /**
  218. * Closure provided by the client
  219. */
  220. void *cls;
  221. /**
  222. * Handle to the service connection
  223. */
  224. struct GNUNET_CLIENT_Connection *service_conn;
  225. };
  226. /**
  227. * @brief Peers received from the biased stream to be passed to all
  228. * srh_handlers
  229. */
  230. static struct GNUNET_PeerIdentity *srh_callback_peers;
  231. /**
  232. * @brief Number of peers in the biased stream that are to be passed to all
  233. * srh_handlers
  234. */
  235. static uint64_t srh_callback_num_peers;
  236. /**
  237. * @brief Create a new handle for a stream request
  238. *
  239. * @param rps_handle The rps handle
  240. * @param num_peers The number of desired peers
  241. * @param ready_cb The callback to be called, once all peers are ready
  242. * @param cls The colsure to provide to the callback
  243. *
  244. * @return The handle to the stream request
  245. */
  246. static struct GNUNET_RPS_StreamRequestHandle *
  247. new_stream_request (struct GNUNET_RPS_Handle *rps_handle,
  248. GNUNET_RPS_NotifyReadyCB ready_cb,
  249. void *cls)
  250. {
  251. struct GNUNET_RPS_StreamRequestHandle *srh;
  252. srh = GNUNET_new (struct GNUNET_RPS_StreamRequestHandle);
  253. srh->rps_handle = rps_handle;
  254. srh->ready_cb = ready_cb;
  255. srh->ready_cb_cls = cls;
  256. GNUNET_CONTAINER_DLL_insert (rps_handle->stream_requests_head,
  257. rps_handle->stream_requests_tail,
  258. srh);
  259. return srh;
  260. }
  261. /**
  262. * @brief Remove the given stream request from the list of requests and memory
  263. *
  264. * @param srh The request to be removed
  265. */
  266. static void
  267. remove_stream_request (struct GNUNET_RPS_StreamRequestHandle *srh)
  268. {
  269. struct GNUNET_RPS_Handle *rps_handle = srh->rps_handle;
  270. GNUNET_assert (NULL != srh);
  271. if (NULL != srh->callback_task)
  272. {
  273. GNUNET_SCHEDULER_cancel (srh->callback_task);
  274. srh->callback_task = NULL;
  275. }
  276. GNUNET_CONTAINER_DLL_remove (rps_handle->stream_requests_head,
  277. rps_handle->stream_requests_tail,
  278. srh);
  279. GNUNET_free (srh);
  280. }
  281. /**
  282. * @brief Called once the sampler has collected all requested peers.
  283. *
  284. * Calls the callback provided by the client with the corresponding cls.
  285. *
  286. * @param peers The array of @a num_peers that has been returned.
  287. * @param num_peers The number of peers that have been returned
  288. * @param cls The #GNUNET_RPS_Request_Handle
  289. */
  290. static void
  291. peers_ready_cb (const struct GNUNET_PeerIdentity *peers,
  292. uint32_t num_peers,
  293. void *cls)
  294. {
  295. struct GNUNET_RPS_Request_Handle *rh = cls;
  296. rh->sampler_rh = NULL;
  297. rh->ready_cb (rh->ready_cb_cls,
  298. num_peers,
  299. peers);
  300. GNUNET_RPS_request_cancel (rh);
  301. }
  302. /**
  303. * @brief Called once the sampler has collected the requested peer.
  304. *
  305. * Calls the callback provided by the client with the corresponding cls.
  306. *
  307. * @param peers The array of @a num_peers that has been returned.
  308. * @param num_peers The number of peers that have been returned
  309. * @param cls The #GNUNET_RPS_Request_Handle
  310. * @param probability Probability with which all IDs have been observed
  311. * @param num_observed Number of observed IDs
  312. */
  313. static void
  314. peer_info_ready_cb (const struct GNUNET_PeerIdentity *peers,
  315. void *cls,
  316. double probability,
  317. uint32_t num_observed)
  318. {
  319. struct GNUNET_RPS_Request_Handle_Single_Info *rh = cls;
  320. rh->sampler_rh = NULL;
  321. rh->ready_cb (rh->ready_cb_cls,
  322. peers,
  323. probability,
  324. num_observed);
  325. GNUNET_RPS_request_single_info_cancel (rh);
  326. }
  327. /**
  328. * @brief Callback to collect the peers from the biased stream and put those
  329. * into the sampler.
  330. *
  331. * @param cls The #GNUNET_RPS_Request_Handle
  332. * @param num_peers The number of peer that have been returned
  333. * @param peers The array of @a num_peers that have been returned
  334. */
  335. static void
  336. collect_peers_cb (void *cls,
  337. uint64_t num_peers,
  338. const struct GNUNET_PeerIdentity *peers)
  339. {
  340. struct GNUNET_RPS_Request_Handle *rh = cls;
  341. LOG (GNUNET_ERROR_TYPE_DEBUG,
  342. "Service sent %" PRIu64 " peers from stream\n",
  343. num_peers);
  344. for (uint64_t i = 0; i < num_peers; i++)
  345. {
  346. RPS_sampler_update (rh->sampler, &peers[i]);
  347. }
  348. }
  349. /**
  350. * @brief Callback to collect the peers from the biased stream and put those
  351. * into the sampler.
  352. *
  353. * This version is for the modified #GNUNET_RPS_Request_Handle_Single_Info
  354. *
  355. * @param cls The #GNUNET_RPS_Request_Handle
  356. * @param num_peers The number of peer that have been returned
  357. * @param peers The array of @a num_peers that have been returned
  358. */
  359. static void
  360. collect_peers_info_cb (void *cls,
  361. uint64_t num_peers,
  362. const struct GNUNET_PeerIdentity *peers)
  363. {
  364. struct GNUNET_RPS_Request_Handle_Single_Info *rhs = cls;
  365. LOG (GNUNET_ERROR_TYPE_DEBUG,
  366. "Service sent %" PRIu64 " peers from stream\n",
  367. num_peers);
  368. for (uint64_t i = 0; i < num_peers; i++)
  369. {
  370. RPS_sampler_update (rhs->sampler, &peers[i]);
  371. }
  372. }
  373. /* Get internals for debugging/profiling purposes */
  374. /**
  375. * Request updates of view
  376. *
  377. * @param rps_handle handle to the rps service
  378. * @param num_req_peers number of peers we want to receive
  379. * (0 for infinite updates)
  380. * @param cls a closure that will be given to the callback
  381. * @param ready_cb the callback called when the peers are available
  382. */
  383. void
  384. GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
  385. uint32_t num_updates,
  386. GNUNET_RPS_NotifyReadyCB view_update_cb,
  387. void *cls)
  388. {
  389. struct GNUNET_MQ_Envelope *ev;
  390. struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg;
  391. LOG (GNUNET_ERROR_TYPE_DEBUG,
  392. "Client requests %" PRIu32 " view updates\n",
  393. num_updates);
  394. rps_handle->view_update_cb = view_update_cb;
  395. rps_handle->view_update_cls = cls;
  396. ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST);
  397. msg->num_updates = htonl (num_updates);
  398. GNUNET_MQ_send (rps_handle->mq, ev);
  399. }
  400. void
  401. GNUNET_RPS_view_request_cancel (struct GNUNET_RPS_Handle *rps_handle)
  402. {
  403. struct GNUNET_MQ_Envelope *ev;
  404. GNUNET_assert (NULL != rps_handle->view_update_cb);
  405. rps_handle->view_update_cb = NULL;
  406. ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL);
  407. GNUNET_MQ_send (rps_handle->mq, ev);
  408. }
  409. /**
  410. * Request biased stream of peers that are being put into the sampler
  411. *
  412. * @param rps_handle handle to the rps service
  413. * @param cls a closure that will be given to the callback
  414. * @param ready_cb the callback called when the peers are available
  415. */
  416. struct GNUNET_RPS_StreamRequestHandle *
  417. GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle,
  418. GNUNET_RPS_NotifyReadyCB stream_input_cb,
  419. void *cls)
  420. {
  421. struct GNUNET_RPS_StreamRequestHandle *srh;
  422. struct GNUNET_MQ_Envelope *ev;
  423. struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg;
  424. srh = new_stream_request (rps_handle,
  425. stream_input_cb,
  426. cls);
  427. LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n");
  428. ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST);
  429. GNUNET_MQ_send (rps_handle->mq, ev);
  430. return srh;
  431. }
  432. /**
  433. * This function is called, when the service updates the view.
  434. * It verifies that @a msg is well-formed.
  435. *
  436. * @param cls the closure
  437. * @param msg the message
  438. * @return #GNUNET_OK if @a msg is well-formed
  439. */
  440. static int
  441. check_view_update (void *cls,
  442. const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
  443. {
  444. uint16_t msize = ntohs (msg->header.size);
  445. uint32_t num_peers = ntohl (msg->num_peers);
  446. (void) cls;
  447. msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_ViewReply);
  448. if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
  449. (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
  450. {
  451. GNUNET_break (0);
  452. return GNUNET_SYSERR;
  453. }
  454. return GNUNET_OK;
  455. }
  456. /**
  457. * This function is called, when the service updated its view.
  458. * It calls the callback the caller provided
  459. * and disconnects afterwards.
  460. *
  461. * @param msg the message
  462. */
  463. static void
  464. handle_view_update (void *cls,
  465. const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
  466. {
  467. struct GNUNET_RPS_Handle *h = cls;
  468. struct GNUNET_PeerIdentity *peers;
  469. /* Give the peers back */
  470. LOG (GNUNET_ERROR_TYPE_DEBUG,
  471. "New view of %" PRIu32 " peers:\n",
  472. ntohl (msg->num_peers));
  473. peers = (struct GNUNET_PeerIdentity *) &msg[1];
  474. GNUNET_assert (NULL != h);
  475. GNUNET_assert (NULL != h->view_update_cb);
  476. h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers);
  477. }
  478. /**
  479. * @brief Send message to service that this client does not want to receive
  480. * further updates from the biased peer stream
  481. *
  482. * @param rps_handle The handle representing the service to the client
  483. */
  484. static void
  485. cancel_stream (struct GNUNET_RPS_Handle *rps_handle)
  486. {
  487. struct GNUNET_MQ_Envelope *ev;
  488. ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL);
  489. GNUNET_MQ_send (rps_handle->mq, ev);
  490. }
  491. /**
  492. * @brief Cancel a specific request for updates from the biased peer stream
  493. *
  494. * @param srh The request handle to cancel
  495. */
  496. void
  497. GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh)
  498. {
  499. struct GNUNET_RPS_Handle *rps_handle;
  500. rps_handle = srh->rps_handle;
  501. remove_stream_request (srh);
  502. if (NULL == rps_handle->stream_requests_head)
  503. cancel_stream (rps_handle);
  504. }
  505. /**
  506. * This function is called, when the service sends another peer from the biased
  507. * stream.
  508. * It calls the callback the caller provided
  509. * and disconnects afterwards.
  510. *
  511. * TODO merge with check_view_update
  512. *
  513. * @param msg the message
  514. */
  515. static int
  516. check_stream_input (void *cls,
  517. const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
  518. {
  519. uint16_t msize = ntohs (msg->header.size);
  520. uint32_t num_peers = ntohl (msg->num_peers);
  521. (void) cls;
  522. msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_StreamReply);
  523. if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
  524. (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
  525. {
  526. GNUNET_break (0);
  527. return GNUNET_SYSERR;
  528. }
  529. return GNUNET_OK;
  530. }
  531. /**
  532. * @brief Called by the scheduler to call the callbacks of the srh handlers
  533. *
  534. * @param cls Stream request handle
  535. */
  536. static void
  537. srh_callback_scheduled (void *cls)
  538. {
  539. struct GNUNET_RPS_StreamRequestHandle *srh = cls;
  540. srh->callback_task = NULL;
  541. srh->ready_cb (srh->ready_cb_cls,
  542. srh_callback_num_peers,
  543. srh_callback_peers);
  544. }
  545. /**
  546. * This function is called, when the service sends another peer from the biased
  547. * stream.
  548. * It calls the callback the caller provided
  549. * and disconnects afterwards.
  550. *
  551. * @param msg the message
  552. */
  553. static void
  554. handle_stream_input (void *cls,
  555. const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
  556. {
  557. struct GNUNET_RPS_Handle *h = cls;
  558. // const struct GNUNET_PeerIdentity *peers;
  559. uint64_t num_peers;
  560. struct GNUNET_RPS_StreamRequestHandle *srh_iter;
  561. struct GNUNET_RPS_StreamRequestHandle *srh_next;
  562. // peers = (struct GNUNET_PeerIdentity *) &msg[1];
  563. num_peers = ntohl (msg->num_peers);
  564. srh_callback_num_peers = num_peers;
  565. GNUNET_free (srh_callback_peers);
  566. srh_callback_peers = GNUNET_new_array (num_peers,
  567. struct GNUNET_PeerIdentity);
  568. GNUNET_memcpy (srh_callback_peers,
  569. &msg[1],
  570. num_peers * sizeof(struct GNUNET_PeerIdentity));
  571. LOG (GNUNET_ERROR_TYPE_DEBUG,
  572. "Received %" PRIu64 " peer(s) from stream input.\n",
  573. num_peers);
  574. for (srh_iter = h->stream_requests_head;
  575. NULL != srh_iter;
  576. srh_iter = srh_next)
  577. {
  578. LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n");
  579. /* Store next pointer - srh might be removed/freed in callback */
  580. srh_next = srh_iter->next;
  581. if (NULL != srh_iter->callback_task)
  582. GNUNET_SCHEDULER_cancel (srh_iter->callback_task);
  583. srh_iter->callback_task =
  584. GNUNET_SCHEDULER_add_now (&srh_callback_scheduled,
  585. srh_iter);
  586. }
  587. if (NULL == h->stream_requests_head)
  588. {
  589. cancel_stream (h);
  590. }
  591. }
  592. /**
  593. * Reconnect to the service
  594. */
  595. static void
  596. reconnect (struct GNUNET_RPS_Handle *h);
  597. /**
  598. * Error handler for mq.
  599. *
  600. * This function is called when mq encounters an error.
  601. * Until now mq doesn't provide useful error messages.
  602. *
  603. * @param cls the closure
  604. * @param error error code without specyfied meaning
  605. */
  606. static void
  607. mq_error_handler (void *cls,
  608. enum GNUNET_MQ_Error error)
  609. {
  610. struct GNUNET_RPS_Handle *h = cls;
  611. // TODO LOG
  612. LOG (GNUNET_ERROR_TYPE_WARNING,
  613. "Problem with message queue. error: %i\n\
  614. 1: READ,\n\
  615. 2: WRITE,\n\
  616. 4: TIMEOUT\n",
  617. // TODO: write GNUNET_MQ_strerror (error)
  618. error);
  619. reconnect (h);
  620. /* Resend all pending request as the service destroyed its knowledge
  621. * about them */
  622. }
  623. /**
  624. * @brief Create the hash value from the share value that defines the sub
  625. * (-group)
  626. *
  627. * @param share_val Share value
  628. * @param hash[out] Pointer to the location in which the hash will be stored.
  629. */
  630. static void
  631. hash_from_share_val (const char *share_val,
  632. struct GNUNET_HashCode *hash)
  633. {
  634. GNUNET_CRYPTO_kdf (hash,
  635. sizeof(struct GNUNET_HashCode),
  636. "rps",
  637. strlen ("rps"),
  638. share_val,
  639. strlen (share_val),
  640. NULL, 0);
  641. }
  642. /**
  643. * @brief Callback for network size estimate - called with new estimates about
  644. * the network size, updates all samplers with the new estimate
  645. *
  646. * Implements #GNUNET_NSE_Callback
  647. *
  648. * @param cls the rps handle
  649. * @param timestamp unused
  650. * @param logestimate the estimate
  651. * @param std_dev the standard distribution
  652. */
  653. static void
  654. nse_cb (void *cls,
  655. struct GNUNET_TIME_Absolute timestamp,
  656. double logestimate,
  657. double std_dev)
  658. {
  659. struct GNUNET_RPS_Handle *h = cls;
  660. (void) timestamp;
  661. (void) std_dev;
  662. for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head;
  663. NULL != rh_iter && NULL != rh_iter->next;
  664. rh_iter = rh_iter->next)
  665. {
  666. RPS_sampler_update_with_nw_size (rh_iter->sampler,
  667. GNUNET_NSE_log_estimate_to_n (
  668. logestimate));
  669. }
  670. for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head;
  671. NULL != rhs_iter && NULL != rhs_iter->next;
  672. rhs_iter = rhs_iter->next)
  673. {
  674. RPS_sampler_update_with_nw_size (rhs_iter->sampler,
  675. GNUNET_NSE_log_estimate_to_n (
  676. logestimate));
  677. }
  678. }
  679. /**
  680. * Reconnect to the service
  681. */
  682. static void
  683. reconnect (struct GNUNET_RPS_Handle *h)
  684. {
  685. struct GNUNET_MQ_MessageHandler mq_handlers[] = {
  686. GNUNET_MQ_hd_var_size (view_update,
  687. GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY,
  688. struct GNUNET_RPS_CS_DEBUG_ViewReply,
  689. h),
  690. GNUNET_MQ_hd_var_size (stream_input,
  691. GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY,
  692. struct GNUNET_RPS_CS_DEBUG_StreamReply,
  693. h),
  694. GNUNET_MQ_handler_end ()
  695. };
  696. if (NULL != h->mq)
  697. GNUNET_MQ_destroy (h->mq);
  698. h->mq = GNUNET_CLIENT_connect (h->cfg,
  699. "rps",
  700. mq_handlers,
  701. &mq_error_handler,
  702. h);
  703. if (NULL != h->nse)
  704. GNUNET_NSE_disconnect (h->nse);
  705. h->nse = GNUNET_NSE_connect (h->cfg, &nse_cb, h);
  706. }
  707. /**
  708. * Connect to the rps service
  709. *
  710. * @param cfg configuration to use
  711. * @return a handle to the service, NULL on error
  712. */
  713. struct GNUNET_RPS_Handle *
  714. GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
  715. {
  716. struct GNUNET_RPS_Handle *h;
  717. h = GNUNET_new (struct GNUNET_RPS_Handle);
  718. h->cfg = cfg;
  719. if (GNUNET_OK !=
  720. GNUNET_CONFIGURATION_get_value_float (cfg,
  721. "RPS",
  722. "DESIRED_PROBABILITY",
  723. &h->desired_probability))
  724. {
  725. GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
  726. "RPS", "DESIRED_PROBABILITY");
  727. GNUNET_free (h);
  728. return NULL;
  729. }
  730. if ((0 > h->desired_probability) ||
  731. (1 < h->desired_probability) )
  732. {
  733. LOG (GNUNET_ERROR_TYPE_ERROR,
  734. "The desired probability must be in the interval [0;1]\n");
  735. GNUNET_free (h);
  736. return NULL;
  737. }
  738. if (GNUNET_OK !=
  739. GNUNET_CONFIGURATION_get_value_float (cfg,
  740. "RPS",
  741. "DEFICIENCY_FACTOR",
  742. &h->deficiency_factor))
  743. {
  744. GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
  745. "RPS", "DEFICIENCY_FACTOR");
  746. GNUNET_free (h);
  747. return NULL;
  748. }
  749. if ((0 > h->desired_probability) ||
  750. (1 < h->desired_probability) )
  751. {
  752. LOG (GNUNET_ERROR_TYPE_ERROR,
  753. "The deficiency factor must be in the interval [0;1]\n");
  754. GNUNET_free (h);
  755. return NULL;
  756. }
  757. reconnect (h);
  758. if (NULL == h->mq)
  759. {
  760. GNUNET_free (h);
  761. return NULL;
  762. }
  763. return h;
  764. }
  765. /**
  766. * @brief Start a sub with the given shared value
  767. *
  768. * @param h Handle to rps
  769. * @param shared_value The shared value that defines the members of the sub (-gorup)
  770. */
  771. void
  772. GNUNET_RPS_sub_start (struct GNUNET_RPS_Handle *h,
  773. const char *shared_value)
  774. {
  775. struct GNUNET_RPS_CS_SubStartMessage *msg;
  776. struct GNUNET_MQ_Envelope *ev;
  777. ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START);
  778. hash_from_share_val (shared_value, &msg->hash);
  779. msg->round_interval = GNUNET_TIME_relative_hton ( // TODO read from config!
  780. GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30));
  781. GNUNET_assert (0 != msg->round_interval.rel_value_us__);
  782. GNUNET_MQ_send (h->mq, ev);
  783. }
  784. /**
  785. * @brief Stop a sub with the given shared value
  786. *
  787. * @param h Handle to rps
  788. * @param shared_value The shared value that defines the members of the sub (-gorup)
  789. */
  790. void
  791. GNUNET_RPS_sub_stop (struct GNUNET_RPS_Handle *h,
  792. const char *shared_value)
  793. {
  794. struct GNUNET_RPS_CS_SubStopMessage *msg;
  795. struct GNUNET_MQ_Envelope *ev;
  796. ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP);
  797. hash_from_share_val (shared_value, &msg->hash);
  798. GNUNET_MQ_send (h->mq, ev);
  799. }
  800. /**
  801. * Request n random peers.
  802. *
  803. * @param rps_handle handle to the rps service
  804. * @param num_req_peers number of peers we want to receive
  805. * @param ready_cb the callback called when the peers are available
  806. * @param cls closure given to the callback
  807. * @return a handle to cancel this request
  808. */
  809. struct GNUNET_RPS_Request_Handle *
  810. GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
  811. uint32_t num_req_peers,
  812. GNUNET_RPS_NotifyReadyCB ready_cb,
  813. void *cls)
  814. {
  815. struct GNUNET_RPS_Request_Handle *rh;
  816. LOG (GNUNET_ERROR_TYPE_INFO,
  817. "Client requested %" PRIu32 " peers\n",
  818. num_req_peers);
  819. rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
  820. rh->rps_handle = rps_handle;
  821. rh->num_requests = num_req_peers;
  822. rh->sampler = RPS_sampler_mod_init (num_req_peers,
  823. GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff
  824. RPS_sampler_set_desired_probability (rh->sampler,
  825. rps_handle->desired_probability);
  826. RPS_sampler_set_deficiency_factor (rh->sampler,
  827. rps_handle->deficiency_factor);
  828. rh->sampler_rh = RPS_sampler_get_n_rand_peers (rh->sampler,
  829. num_req_peers,
  830. peers_ready_cb,
  831. rh);
  832. rh->srh = GNUNET_RPS_stream_request (rps_handle,
  833. collect_peers_cb,
  834. rh); /* cls */
  835. rh->ready_cb = ready_cb;
  836. rh->ready_cb_cls = cls;
  837. GNUNET_CONTAINER_DLL_insert (rps_handle->rh_head,
  838. rps_handle->rh_tail,
  839. rh);
  840. return rh;
  841. }
  842. /**
  843. * Request one random peer, getting additional information.
  844. *
  845. * @param rps_handle handle to the rps service
  846. * @param ready_cb the callback called when the peers are available
  847. * @param cls closure given to the callback
  848. * @return a handle to cancel this request
  849. */
  850. struct GNUNET_RPS_Request_Handle_Single_Info *
  851. GNUNET_RPS_request_peer_info (struct GNUNET_RPS_Handle *rps_handle,
  852. GNUNET_RPS_NotifyReadySingleInfoCB ready_cb,
  853. void *cls)
  854. {
  855. struct GNUNET_RPS_Request_Handle_Single_Info *rhs;
  856. uint32_t num_req_peers = 1;
  857. LOG (GNUNET_ERROR_TYPE_INFO,
  858. "Client requested peer with additional info\n");
  859. rhs = GNUNET_new (struct GNUNET_RPS_Request_Handle_Single_Info);
  860. rhs->rps_handle = rps_handle;
  861. rhs->sampler = RPS_sampler_mod_init (num_req_peers,
  862. GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff
  863. RPS_sampler_set_desired_probability (rhs->sampler,
  864. rps_handle->desired_probability);
  865. RPS_sampler_set_deficiency_factor (rhs->sampler,
  866. rps_handle->deficiency_factor);
  867. rhs->sampler_rh = RPS_sampler_get_rand_peer_info (rhs->sampler,
  868. peer_info_ready_cb,
  869. rhs);
  870. rhs->srh = GNUNET_RPS_stream_request (rps_handle,
  871. collect_peers_info_cb,
  872. rhs); /* cls */
  873. rhs->ready_cb = ready_cb;
  874. rhs->ready_cb_cls = cls;
  875. GNUNET_CONTAINER_DLL_insert (rps_handle->rhs_head,
  876. rps_handle->rhs_tail,
  877. rhs);
  878. return rhs;
  879. }
  880. /**
  881. * Seed rps service with peerIDs.
  882. *
  883. * @param h handle to the rps service
  884. * @param n number of peers to seed
  885. * @param ids the ids of the peers seeded
  886. */
  887. void
  888. GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
  889. uint32_t n,
  890. const struct GNUNET_PeerIdentity *ids)
  891. {
  892. size_t size_needed;
  893. uint32_t num_peers_max;
  894. const struct GNUNET_PeerIdentity *tmp_peer_pointer;
  895. struct GNUNET_MQ_Envelope *ev;
  896. struct GNUNET_RPS_CS_SeedMessage *msg;
  897. LOG (GNUNET_ERROR_TYPE_DEBUG,
  898. "Client wants to seed %" PRIu32 " peers:\n",
  899. n);
  900. for (unsigned int i = 0; i < n; i++)
  901. LOG (GNUNET_ERROR_TYPE_DEBUG,
  902. "%u. peer: %s\n",
  903. i,
  904. GNUNET_i2s (&ids[i]));
  905. /* The actual size the message occupies */
  906. size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
  907. + n * sizeof(struct GNUNET_PeerIdentity);
  908. /* The number of peers that fits in one message together with
  909. * the respective header */
  910. num_peers_max = (GNUNET_MAX_MESSAGE_SIZE
  911. - sizeof(struct GNUNET_RPS_CS_SeedMessage))
  912. / sizeof(struct GNUNET_PeerIdentity);
  913. tmp_peer_pointer = ids;
  914. while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
  915. {
  916. ev = GNUNET_MQ_msg_extra (msg,
  917. num_peers_max * sizeof(struct
  918. GNUNET_PeerIdentity),
  919. GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
  920. msg->num_peers = htonl (num_peers_max);
  921. GNUNET_memcpy (&msg[1],
  922. tmp_peer_pointer,
  923. num_peers_max * sizeof(struct GNUNET_PeerIdentity));
  924. GNUNET_MQ_send (h->mq,
  925. ev);
  926. n -= num_peers_max;
  927. size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
  928. + n * sizeof(struct GNUNET_PeerIdentity);
  929. /* Set pointer to beginning of next block of num_peers_max peers */
  930. tmp_peer_pointer = &ids[num_peers_max];
  931. }
  932. ev = GNUNET_MQ_msg_extra (msg,
  933. n * sizeof(struct GNUNET_PeerIdentity),
  934. GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
  935. msg->num_peers = htonl (n);
  936. GNUNET_memcpy (&msg[1],
  937. tmp_peer_pointer,
  938. n * sizeof(struct GNUNET_PeerIdentity));
  939. GNUNET_MQ_send (h->mq,
  940. ev);
  941. }
  942. #if ENABLE_MALICIOUS
  943. /**
  944. * Turn RPS service to act malicious.
  945. *
  946. * @param h handle to the rps service
  947. * @param type which type of malicious peer to turn to.
  948. * 0 Don't act malicious at all
  949. * 1 Try to maximise representation
  950. * 2 Try to partition the network
  951. * (isolate one peer from the rest)
  952. * @param n number of @a ids
  953. * @param ids the ids of the malicious peers
  954. * if @type is 2 the last id is the id of the
  955. * peer to be isolated from the rest
  956. */
  957. void
  958. GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
  959. uint32_t type,
  960. uint32_t num_peers,
  961. const struct GNUNET_PeerIdentity *peer_ids,
  962. const struct GNUNET_PeerIdentity *target_peer)
  963. {
  964. size_t size_needed;
  965. uint32_t num_peers_max;
  966. const struct GNUNET_PeerIdentity *tmp_peer_pointer;
  967. struct GNUNET_MQ_Envelope *ev;
  968. struct GNUNET_RPS_CS_ActMaliciousMessage *msg;
  969. unsigned int i;
  970. LOG (GNUNET_ERROR_TYPE_DEBUG,
  971. "Client turns malicious (type %" PRIu32 ") with %" PRIu32
  972. " other peers:\n",
  973. type,
  974. num_peers);
  975. for (i = 0; i < num_peers; i++)
  976. LOG (GNUNET_ERROR_TYPE_DEBUG,
  977. "%u. peer: %s\n",
  978. i,
  979. GNUNET_i2s (&peer_ids[i]));
  980. /* The actual size the message would occupy */
  981. size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
  982. + num_peers * sizeof(struct GNUNET_PeerIdentity);
  983. /* The number of peers that fit in one message together with
  984. * the respective header */
  985. num_peers_max = (GNUNET_MAX_MESSAGE_SIZE
  986. - sizeof(struct GNUNET_RPS_CS_SeedMessage))
  987. / sizeof(struct GNUNET_PeerIdentity);
  988. tmp_peer_pointer = peer_ids;
  989. while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
  990. {
  991. LOG (GNUNET_ERROR_TYPE_DEBUG,
  992. "Too many peers to send at once, sending %" PRIu32
  993. " (all we can so far)\n",
  994. num_peers_max);
  995. ev = GNUNET_MQ_msg_extra (msg,
  996. num_peers_max * sizeof(struct
  997. GNUNET_PeerIdentity),
  998. GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
  999. msg->type = htonl (type);
  1000. msg->num_peers = htonl (num_peers_max);
  1001. if ((2 == type) ||
  1002. (3 == type))
  1003. msg->attacked_peer = peer_ids[num_peers];
  1004. GNUNET_memcpy (&msg[1],
  1005. tmp_peer_pointer,
  1006. num_peers_max * sizeof(struct GNUNET_PeerIdentity));
  1007. GNUNET_MQ_send (h->mq, ev);
  1008. num_peers -= num_peers_max;
  1009. size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
  1010. + num_peers * sizeof(struct GNUNET_PeerIdentity);
  1011. /* Set pointer to beginning of next block of num_peers_max peers */
  1012. tmp_peer_pointer = &peer_ids[num_peers_max];
  1013. }
  1014. ev = GNUNET_MQ_msg_extra (msg,
  1015. num_peers * sizeof(struct GNUNET_PeerIdentity),
  1016. GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
  1017. msg->type = htonl (type);
  1018. msg->num_peers = htonl (num_peers);
  1019. if ((2 == type) ||
  1020. (3 == type))
  1021. msg->attacked_peer = *target_peer;
  1022. GNUNET_memcpy (&msg[1],
  1023. tmp_peer_pointer,
  1024. num_peers * sizeof(struct GNUNET_PeerIdentity));
  1025. GNUNET_MQ_send (h->mq, ev);
  1026. }
  1027. #endif /* ENABLE_MALICIOUS */
  1028. /**
  1029. * Cancel an issued request.
  1030. *
  1031. * @param rh request handle of request to cancel
  1032. */
  1033. void
  1034. GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
  1035. {
  1036. struct GNUNET_RPS_Handle *h;
  1037. h = rh->rps_handle;
  1038. GNUNET_assert (NULL != rh);
  1039. GNUNET_assert (NULL != rh->srh);
  1040. GNUNET_assert (h == rh->srh->rps_handle);
  1041. GNUNET_RPS_stream_cancel (rh->srh);
  1042. rh->srh = NULL;
  1043. if (NULL == h->stream_requests_head)
  1044. cancel_stream (h);
  1045. if (NULL != rh->sampler_rh)
  1046. {
  1047. RPS_sampler_request_cancel (rh->sampler_rh);
  1048. }
  1049. RPS_sampler_destroy (rh->sampler);
  1050. rh->sampler = NULL;
  1051. GNUNET_CONTAINER_DLL_remove (h->rh_head,
  1052. h->rh_tail,
  1053. rh);
  1054. GNUNET_free (rh);
  1055. }
  1056. /**
  1057. * Cancel an issued single info request.
  1058. *
  1059. * @param rhs request handle of request to cancel
  1060. */
  1061. void
  1062. GNUNET_RPS_request_single_info_cancel (
  1063. struct GNUNET_RPS_Request_Handle_Single_Info *rhs)
  1064. {
  1065. struct GNUNET_RPS_Handle *h;
  1066. h = rhs->rps_handle;
  1067. GNUNET_assert (NULL != rhs);
  1068. GNUNET_assert (NULL != rhs->srh);
  1069. GNUNET_assert (h == rhs->srh->rps_handle);
  1070. GNUNET_RPS_stream_cancel (rhs->srh);
  1071. rhs->srh = NULL;
  1072. if (NULL == h->stream_requests_head)
  1073. cancel_stream (h);
  1074. if (NULL != rhs->sampler_rh)
  1075. {
  1076. RPS_sampler_request_single_info_cancel (rhs->sampler_rh);
  1077. }
  1078. RPS_sampler_destroy (rhs->sampler);
  1079. rhs->sampler = NULL;
  1080. GNUNET_CONTAINER_DLL_remove (h->rhs_head,
  1081. h->rhs_tail,
  1082. rhs);
  1083. GNUNET_free (rhs);
  1084. }
  1085. /**
  1086. * Disconnect from the rps service
  1087. *
  1088. * @param h the handle to the rps service
  1089. */
  1090. void
  1091. GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
  1092. {
  1093. if (NULL != h->stream_requests_head)
  1094. {
  1095. struct GNUNET_RPS_StreamRequestHandle *srh_next;
  1096. LOG (GNUNET_ERROR_TYPE_WARNING,
  1097. "Still waiting for replies\n");
  1098. for (struct GNUNET_RPS_StreamRequestHandle *srh_iter =
  1099. h->stream_requests_head;
  1100. NULL != srh_iter;
  1101. srh_iter = srh_next)
  1102. {
  1103. srh_next = srh_iter->next;
  1104. GNUNET_RPS_stream_cancel (srh_iter);
  1105. }
  1106. }
  1107. if (NULL != h->rh_head)
  1108. {
  1109. LOG (GNUNET_ERROR_TYPE_WARNING,
  1110. "Not all requests were cancelled!\n");
  1111. for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head;
  1112. h->rh_head != NULL;
  1113. rh_iter = h->rh_head)
  1114. {
  1115. GNUNET_RPS_request_cancel (rh_iter);
  1116. }
  1117. }
  1118. if (NULL != h->rhs_head)
  1119. {
  1120. LOG (GNUNET_ERROR_TYPE_WARNING,
  1121. "Not all requests were cancelled!\n");
  1122. for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head;
  1123. h->rhs_head != NULL;
  1124. rhs_iter = h->rhs_head)
  1125. {
  1126. GNUNET_RPS_request_single_info_cancel (rhs_iter);
  1127. }
  1128. }
  1129. if (NULL != srh_callback_peers)
  1130. {
  1131. GNUNET_free (srh_callback_peers);
  1132. srh_callback_peers = NULL;
  1133. }
  1134. if (NULL != h->view_update_cb)
  1135. {
  1136. LOG (GNUNET_ERROR_TYPE_WARNING,
  1137. "Still waiting for view updates\n");
  1138. GNUNET_RPS_view_request_cancel (h);
  1139. }
  1140. if (NULL != h->nse)
  1141. GNUNET_NSE_disconnect (h->nse);
  1142. GNUNET_MQ_destroy (h->mq);
  1143. GNUNET_free (h);
  1144. }
  1145. /* end of rps_api.c */