aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-03-27 12:41:01 +0000
committerJulius Bünger <buenger@mytum.de>2015-03-27 12:41:01 +0000
commitb18ef62fd8970e1bfb2b3958cee855e2b732d94b (patch)
tree3a5b80496f5d4dfa426b23e368120ebb8e44bcba /src
parent56b7edba342e4f753ab19042446f9b50668a10fe (diff)
downloadgnunet-b18ef62fd8970e1bfb2b3958cee855e2b732d94b.tar.gz
gnunet-b18ef62fd8970e1bfb2b3958cee855e2b732d94b.zip
-several fixes in api
Diffstat (limited to 'src')
-rw-r--r--src/rps/Makefile.am5
-rw-r--r--src/rps/rps_api.c45
2 files changed, 30 insertions, 20 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am
index ff177d743..76f935723 100644
--- a/src/rps/Makefile.am
+++ b/src/rps/Makefile.am
@@ -58,9 +58,10 @@ gnunet_service_rps_LDADD = \
58 58
59if HAVE_TESTING 59if HAVE_TESTING
60check_PROGRAMS = \ 60check_PROGRAMS = \
61 test_rps_multipeer \
62 test_rps_malicious_1 \ 61 test_rps_malicious_1 \
63 test_rps_malicious_2 62 test_rps_malicious_2 \
63 test_rps_seed_request \
64 test_rps_single_req
64endif 65endif
65 66
66ld_rps_test_lib = \ 67ld_rps_test_lib = \
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index c46851fe9..16bcb9ec0 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -62,12 +62,12 @@ struct GNUNET_RPS_Request_Handle
62 /** 62 /**
63 * The client issuing the request. 63 * The client issuing the request.
64 */ 64 */
65 struct GNUNET_RPS_Handle *h; 65 struct GNUNET_RPS_Handle *rps_handle;
66 66
67 /** 67 /**
68 * The nuber of the request. 68 * The id of the request.
69 */ 69 */
70 uint64_t n; 70 uint32_t id;
71 71
72 /** 72 /**
73 * The callback to be called when we receive an answer. 73 * The callback to be called when we receive an answer.
@@ -133,12 +133,15 @@ handle_reply (void *cls,
133 133
134 /* Give the peers back */ 134 /* Give the peers back */
135 msg = (struct GNUNET_RPS_CS_ReplyMessage *) message; 135 msg = (struct GNUNET_RPS_CS_ReplyMessage *) message;
136 peers = (struct GNUNET_PeerIdentity *) &msg[1];
137 rh = &req_handlers[msg->n];
138 rh->ready_cb((rh)->ready_cb_cls, msg->num_peers, peers); // FIXME? ntohl ()
139 136
140 /* Disconnect */ 137 LOG (GNUNET_ERROR_TYPE_DEBUG,
141 //GNUNET_CLIENT_disconnect(pack->service_conn); 138 "Service replied with %" PRIu32 " peers for id %" PRIu32 "\n",
139 ntohl (msg->num_peers),
140 ntohl (msg->id));
141
142 peers = (struct GNUNET_PeerIdentity *) &msg[1];
143 rh = &req_handlers[ntohl (msg->id)];
144 rh->ready_cb((rh)->ready_cb_cls, ntohl (msg->num_peers), peers);
142} 145}
143 146
144 147
@@ -196,14 +199,15 @@ GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
196/** 199/**
197 * Request n random peers. 200 * Request n random peers.
198 * 201 *
199 * @param h handle to the rps service 202 * @param rps_handle handle to the rps service
200 * @param n number of peers we want to receive 203 * @param num_req_peers number of peers we want to receive
201 * @param ready_cb the callback called when the peers are available 204 * @param ready_cb the callback called when the peers are available
202 * @param cls closure given to the callback 205 * @param cls closure given to the callback
203 * @return a handle to cancel this request 206 * @return a handle to cancel this request
204 */ 207 */
205 struct GNUNET_RPS_Request_Handle * 208 struct GNUNET_RPS_Request_Handle *
206GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n, 209GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
210 uint32_t num_req_peers,
207 GNUNET_RPS_NotifyReadyCB ready_cb, 211 GNUNET_RPS_NotifyReadyCB ready_cb,
208 void *cls) 212 void *cls)
209{ 213{
@@ -213,18 +217,23 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
213 217
214 // assert func != NULL 218 // assert func != NULL
215 rh = GNUNET_new (struct GNUNET_RPS_Request_Handle); 219 rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
216 rh->h = h; 220 rh->rps_handle = rps_handle;
217 rh->n = req_handlers_size; // TODO ntoh 221 rh->id = req_handlers_size; // TODO ntoh
218 rh->ready_cb = ready_cb; 222 rh->ready_cb = ready_cb;
219 rh->ready_cb_cls = cls; 223 rh->ready_cb_cls = cls;
220 224
225 LOG (GNUNET_ERROR_TYPE_DEBUG,
226 "Requesting %" PRIu32 " peers with id %" PRIu32 "\n",
227 num_req_peers,
228 rh->id);
229
221 GNUNET_array_append (req_handlers, req_handlers_size, *rh); 230 GNUNET_array_append (req_handlers, req_handlers_size, *rh);
222 //memcpy(&req_handlers[req_handlers_size-1], rh, sizeof(struct GNUNET_RPS_Request_Handle)); 231 //memcpy(&req_handlers[req_handlers_size-1], rh, sizeof(struct GNUNET_RPS_Request_Handle));
223 232
224 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST); 233 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST);
225 msg->num_peers = htonl (n); 234 msg->num_peers = htonl (num_req_peers);
226 msg->n = rh->n; 235 msg->id = htonl (rh->id);
227 GNUNET_MQ_send (h->mq, ev); 236 GNUNET_MQ_send (rps_handle->mq, ev);
228 return rh; 237 return rh;
229} 238}
230 239
@@ -250,7 +259,7 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
250 unsigned int i; 259 unsigned int i;
251 260
252 LOG (GNUNET_ERROR_TYPE_DEBUG, 261 LOG (GNUNET_ERROR_TYPE_DEBUG,
253 "Client wants to seed %" PRIX32 " peers:\n", 262 "Client wants to seed %" PRIu32 " peers:\n",
254 n); 263 n);
255 for (i = 0 ; i < n ; i++) 264 for (i = 0 ; i < n ; i++)
256 LOG (GNUNET_ERROR_TYPE_DEBUG, 265 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -322,7 +331,7 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
322 unsigned int i; 331 unsigned int i;
323 332
324 LOG (GNUNET_ERROR_TYPE_DEBUG, 333 LOG (GNUNET_ERROR_TYPE_DEBUG,
325 "Client turns malicious (type %" PRIu32 ") with %" PRIX32 " other peers:\n", 334 "Client turns malicious (type %" PRIu32 ") with %" PRIu32 " other peers:\n",
326 type, 335 type,
327 num_peers); 336 num_peers);
328 for (i = 0 ; i < num_peers ; i++) 337 for (i = 0 ; i < num_peers ; i++)