diff options
author | Julius Bünger <buenger@mytum.de> | 2015-01-13 10:20:32 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-01-13 10:20:32 +0000 |
commit | f5b01ce67749faebc26be6c1cb1b064f8c02655e (patch) | |
tree | 066e97b6b285679fae45a9c5357fb8f3844109d5 /src/rps | |
parent | 0f649608b4d8c3f82fd1f240bc0d28c2713c7699 (diff) | |
download | gnunet-f5b01ce67749faebc26be6c1cb1b064f8c02655e.tar.gz gnunet-f5b01ce67749faebc26be6c1cb1b064f8c02655e.zip |
implemented seeding
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 51 | ||||
-rw-r--r-- | src/rps/rps.h | 7 | ||||
-rw-r--r-- | src/rps/rps_api.c | 39 |
3 files changed, 75 insertions, 22 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 2a2af94f4..0896e126b 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -190,7 +190,7 @@ static unsigned int sampler_size; | |||
190 | * The size of sampler we need to be able to satisfy the client's need of | 190 | * The size of sampler we need to be able to satisfy the client's need of |
191 | * random peers. | 191 | * random peers. |
192 | */ | 192 | */ |
193 | static unsigned int sampler_size_client_need; | 193 | //static unsigned int sampler_size_client_need; |
194 | 194 | ||
195 | 195 | ||
196 | /** | 196 | /** |
@@ -526,8 +526,7 @@ nse_callback(void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimat | |||
526 | * @param message the actual message | 526 | * @param message the actual message |
527 | */ | 527 | */ |
528 | static void | 528 | static void |
529 | // TODO rename | 529 | handle_client_request (void *cls, |
530 | handle_cs_request (void *cls, | ||
531 | struct GNUNET_SERVER_Client *client, | 530 | struct GNUNET_SERVER_Client *client, |
532 | const struct GNUNET_MessageHeader *message) | 531 | const struct GNUNET_MessageHeader *message) |
533 | { | 532 | { |
@@ -595,6 +594,49 @@ handle_cs_request (void *cls, | |||
595 | GNUNET_OK); | 594 | GNUNET_OK); |
596 | } | 595 | } |
597 | 596 | ||
597 | |||
598 | /** | ||
599 | * Handle seed from the client. | ||
600 | * | ||
601 | * @param cls closure | ||
602 | * @param client identification of the client | ||
603 | * @param message the actual message | ||
604 | */ | ||
605 | static void | ||
606 | handle_client_seed (void *cls, | ||
607 | struct GNUNET_SERVER_Client *client, | ||
608 | const struct GNUNET_MessageHeader *message) | ||
609 | { | ||
610 | struct GNUNET_RPS_CS_SeedMessage *in_msg; | ||
611 | struct GNUNET_PeerIdentity *peers; | ||
612 | uint64_t i; | ||
613 | |||
614 | if (sizeof (struct GNUNET_RPS_CS_SeedMessage) < ntohs (message->size)) | ||
615 | { | ||
616 | GNUNET_break_op (0); | ||
617 | GNUNET_SERVER_receive_done (client, | ||
618 | GNUNET_SYSERR); | ||
619 | } | ||
620 | in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message; | ||
621 | if (ntohs (message->size) - sizeof (struct GNUNET_RPS_CS_SeedMessage) / | ||
622 | sizeof (struct GNUNET_PeerIdentity) != GNUNET_ntohll (in_msg->num_peers)) | ||
623 | { | ||
624 | GNUNET_break_op (0); | ||
625 | GNUNET_SERVER_receive_done (client, | ||
626 | GNUNET_SYSERR); | ||
627 | } | ||
628 | |||
629 | in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message; | ||
630 | peers = (struct GNUNET_PeerIdentity *) &message[1]; | ||
631 | |||
632 | for ( i = 0 ; i < GNUNET_ntohll (in_msg->num_peers) ; i++ ) | ||
633 | RPS_sampler_update_list (&peers[i]); | ||
634 | |||
635 | GNUNET_SERVER_receive_done (client, | ||
636 | GNUNET_OK); | ||
637 | } | ||
638 | |||
639 | |||
598 | /** | 640 | /** |
599 | * Handle a PUSH message from another peer. | 641 | * Handle a PUSH message from another peer. |
600 | * | 642 | * |
@@ -1100,8 +1142,9 @@ static void | |||
1100 | rps_start (struct GNUNET_SERVER_Handle *server) | 1142 | rps_start (struct GNUNET_SERVER_Handle *server) |
1101 | { | 1143 | { |
1102 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1144 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1103 | {&handle_cs_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST, | 1145 | {&handle_client_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST, |
1104 | sizeof (struct GNUNET_RPS_CS_RequestMessage)}, | 1146 | sizeof (struct GNUNET_RPS_CS_RequestMessage)}, |
1147 | {&handle_client_seed, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_SEED, 0}, | ||
1105 | {NULL, NULL, 0, 0} | 1148 | {NULL, NULL, 0, 0} |
1106 | }; | 1149 | }; |
1107 | 1150 | ||
diff --git a/src/rps/rps.h b/src/rps/rps.h index 77ce2f18f..3ba0cffcf 100644 --- a/src/rps/rps.h +++ b/src/rps/rps.h | |||
@@ -150,12 +150,9 @@ struct GNUNET_RPS_CS_SeedMessage | |||
150 | /** | 150 | /** |
151 | * Number of peers | 151 | * Number of peers |
152 | */ | 152 | */ |
153 | uint64_t n; | 153 | uint64_t num_peers; |
154 | 154 | ||
155 | /** | 155 | /* Followed by num_peers * GNUNET_PeerIdentity */ |
156 | * Peers | ||
157 | */ | ||
158 | struct GNUNET_PeerIdentity ids; | ||
159 | }; | 156 | }; |
160 | 157 | ||
161 | GNUNET_NETWORK_STRUCT_END | 158 | GNUNET_NETWORK_STRUCT_END |
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index ee00db911..9d6183103 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c | |||
@@ -108,8 +108,6 @@ struct cb_cls_pack | |||
108 | }; | 108 | }; |
109 | 109 | ||
110 | 110 | ||
111 | |||
112 | |||
113 | /** | 111 | /** |
114 | * This function is called, when the service replies to our request. | 112 | * This function is called, when the service replies to our request. |
115 | * It calls the callback the caller gave us with the provided closure | 113 | * It calls the callback the caller gave us with the provided closure |
@@ -141,9 +139,16 @@ handle_reply (void *cls, | |||
141 | } | 139 | } |
142 | 140 | ||
143 | /** | 141 | /** |
142 | * Error handler for mq. | ||
143 | * | ||
144 | * This function is called whan mq encounters an error. | ||
145 | * Until now mq doesn't provide useful error messages. | ||
146 | * | ||
147 | * @param cls the closure | ||
148 | * @param error error code without specyfied meaning | ||
144 | */ | 149 | */ |
145 | static void | 150 | static void |
146 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | 151 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
147 | { | 152 | { |
148 | //TODO LOG | 153 | //TODO LOG |
149 | } | 154 | } |
@@ -155,7 +160,7 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
155 | * @return a handle to the service | 160 | * @return a handle to the service |
156 | */ | 161 | */ |
157 | struct GNUNET_RPS_Handle * | 162 | struct GNUNET_RPS_Handle * |
158 | GNUNET_RPS_connect( const struct GNUNET_CONFIGURATION_Handle *cfg ) | 163 | GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
159 | { | 164 | { |
160 | struct GNUNET_RPS_Handle *h; | 165 | struct GNUNET_RPS_Handle *h; |
161 | //struct GNUNET_RPS_Request_Handle *rh; | 166 | //struct GNUNET_RPS_Request_Handle *rh; |
@@ -197,19 +202,19 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint64_t n, | |||
197 | struct GNUNET_RPS_CS_RequestMessage *msg; | 202 | struct GNUNET_RPS_CS_RequestMessage *msg; |
198 | 203 | ||
199 | // assert func != NULL | 204 | // assert func != NULL |
200 | rh = GNUNET_new(struct GNUNET_RPS_Request_Handle); | 205 | rh = GNUNET_new (struct GNUNET_RPS_Request_Handle); |
201 | rh->h = h; | 206 | rh->h = h; |
202 | rh->n = req_handlers_size; // TODO ntoh | 207 | rh->n = req_handlers_size; // TODO ntoh |
203 | rh->ready_cb = ready_cb; | 208 | rh->ready_cb = ready_cb; |
204 | rh->ready_cb_cls = cls; | 209 | rh->ready_cb_cls = cls; |
205 | 210 | ||
206 | GNUNET_array_append(req_handlers, req_handlers_size, *rh); | 211 | GNUNET_array_append (req_handlers, req_handlers_size, *rh); |
207 | //memcpy(&req_handlers[req_handlers_size-1], rh, sizeof(struct GNUNET_RPS_Request_Handle)); | 212 | //memcpy(&req_handlers[req_handlers_size-1], rh, sizeof(struct GNUNET_RPS_Request_Handle)); |
208 | 213 | ||
209 | ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST); | 214 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST); |
210 | msg->num_peers = GNUNET_htonll(n); | 215 | msg->num_peers = GNUNET_htonll (n); |
211 | msg->n = rh->n; | 216 | msg->n = rh->n; |
212 | GNUNET_MQ_send(h->mq, ev); | 217 | GNUNET_MQ_send (h->mq, ev); |
213 | return rh; | 218 | return rh; |
214 | } | 219 | } |
215 | 220 | ||
@@ -222,8 +227,16 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint64_t n, | |||
222 | */ | 227 | */ |
223 | void | 228 | void |
224 | GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint64_t n, | 229 | GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint64_t n, |
225 | struct GNUNET_PeerIdentity * ids) | 230 | const struct GNUNET_PeerIdentity * ids) |
226 | { | 231 | { |
232 | struct GNUNET_MQ_Envelope *ev; | ||
233 | struct GNUNET_RPS_CS_SeedMessage *msg; | ||
234 | |||
235 | ev = GNUNET_MQ_msg_extra (msg, n * sizeof (struct GNUNET_PeerIdentity), | ||
236 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED); | ||
237 | msg->num_peers = GNUNET_htonll (n); | ||
238 | memcpy (&msg[1], ids, n * sizeof (struct GNUNET_PeerIdentity)); | ||
239 | GNUNET_MQ_send (h->mq, ev); | ||
227 | } | 240 | } |
228 | 241 | ||
229 | /** | 242 | /** |
@@ -232,7 +245,7 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint64_t n, | |||
232 | * @param rh request handle of request to cancle | 245 | * @param rh request handle of request to cancle |
233 | */ | 246 | */ |
234 | void | 247 | void |
235 | GNUNET_RPS_request_cancel ( struct GNUNET_RPS_Request_Handle *rh ) | 248 | GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh) |
236 | { | 249 | { |
237 | // TODO | 250 | // TODO |
238 | } | 251 | } |
@@ -243,10 +256,10 @@ GNUNET_RPS_request_cancel ( struct GNUNET_RPS_Request_Handle *rh ) | |||
243 | * @param h the handle to the rps service | 256 | * @param h the handle to the rps service |
244 | */ | 257 | */ |
245 | void | 258 | void |
246 | GNUNET_RPS_disconnect ( struct GNUNET_RPS_Handle *h ) | 259 | GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h) |
247 | { | 260 | { |
248 | if ( NULL != h->conn ) { | 261 | if ( NULL != h->conn ) { |
249 | GNUNET_CLIENT_disconnect(h->conn); | 262 | GNUNET_CLIENT_disconnect (h->conn); |
250 | } | 263 | } |
251 | } | 264 | } |
252 | 265 | ||