diff options
author | Julius Bünger <buenger@mytum.de> | 2015-03-27 12:40:47 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-03-27 12:40:47 +0000 |
commit | b19785784087d703576eb7ffd57ce24e2a462e31 (patch) | |
tree | 14372e0b585f736806cc9ef66dfa584f14bde6b1 /src | |
parent | 591481d3f75d691858f2dc07c7f3ea3374f5d60d (diff) | |
download | gnunet-b19785784087d703576eb7ffd57ce24e2a462e31.tar.gz gnunet-b19785784087d703576eb7ffd57ce24e2a462e31.zip |
-fixed handling of client requests
Diffstat (limited to 'src')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index b3151a567..b8f87a39a 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -354,6 +354,24 @@ uint32_t pending_pull_reply_list_size; | |||
354 | uint32_t num_hist_update_tasks; | 354 | uint32_t num_hist_update_tasks; |
355 | 355 | ||
356 | 356 | ||
357 | /** | ||
358 | * Closure used to pass the client and the id to the callback | ||
359 | * that replies to a client's request | ||
360 | */ | ||
361 | struct ReplyCls | ||
362 | { | ||
363 | /** | ||
364 | * The identifier of the request | ||
365 | */ | ||
366 | uint32_t id; | ||
367 | |||
368 | /** | ||
369 | * The client handle to send the reply to | ||
370 | */ | ||
371 | struct GNUNET_SERVER_Client *client; | ||
372 | }; | ||
373 | |||
374 | |||
357 | #ifdef ENABLE_MALICIOUS | 375 | #ifdef ENABLE_MALICIOUS |
358 | /** | 376 | /** |
359 | * Type of malicious peer | 377 | * Type of malicious peer |
@@ -1167,16 +1185,17 @@ nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp, | |||
1167 | * Sends those to the requesting client. | 1185 | * Sends those to the requesting client. |
1168 | */ | 1186 | */ |
1169 | void client_respond (void *cls, | 1187 | void client_respond (void *cls, |
1170 | struct GNUNET_PeerIdentity *ids, uint32_t num_peers) | 1188 | struct GNUNET_PeerIdentity *peer_ids, uint32_t num_peers) |
1171 | { | 1189 | { |
1172 | LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler returned %" PRIu32 " peers\n", num_peers); | ||
1173 | struct GNUNET_MQ_Envelope *ev; | 1190 | struct GNUNET_MQ_Envelope *ev; |
1174 | struct GNUNET_RPS_CS_ReplyMessage *out_msg; | 1191 | struct GNUNET_RPS_CS_ReplyMessage *out_msg; |
1175 | struct GNUNET_SERVER_Client *client; | 1192 | struct ReplyCls *reply_cls = (struct ReplyCls *) cls; |
1176 | uint32_t size_needed; | 1193 | uint32_t size_needed; |
1177 | struct client_ctx *cli_ctx; | 1194 | struct client_ctx *cli_ctx; |
1178 | 1195 | ||
1179 | client = (struct GNUNET_SERVER_Client *) cls; | 1196 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1197 | "sampler returned %" PRIu32 " peers\n", | ||
1198 | num_peers); | ||
1180 | 1199 | ||
1181 | size_needed = sizeof (struct GNUNET_RPS_CS_ReplyMessage) + | 1200 | size_needed = sizeof (struct GNUNET_RPS_CS_ReplyMessage) + |
1182 | num_peers * sizeof (struct GNUNET_PeerIdentity); | 1201 | num_peers * sizeof (struct GNUNET_PeerIdentity); |
@@ -1187,19 +1206,22 @@ void client_respond (void *cls, | |||
1187 | num_peers * sizeof (struct GNUNET_PeerIdentity), | 1206 | num_peers * sizeof (struct GNUNET_PeerIdentity), |
1188 | GNUNET_MESSAGE_TYPE_RPS_CS_REPLY); | 1207 | GNUNET_MESSAGE_TYPE_RPS_CS_REPLY); |
1189 | out_msg->num_peers = htonl (num_peers); | 1208 | out_msg->num_peers = htonl (num_peers); |
1209 | out_msg->id = htonl (reply_cls->id); | ||
1190 | 1210 | ||
1191 | memcpy (&out_msg[1], | 1211 | memcpy (&out_msg[1], |
1192 | ids, | 1212 | peer_ids, |
1193 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 1213 | num_peers * sizeof (struct GNUNET_PeerIdentity)); |
1194 | GNUNET_free (ids); | 1214 | GNUNET_free (peer_ids); |
1195 | 1215 | ||
1196 | cli_ctx = GNUNET_SERVER_client_get_user_context (client, struct client_ctx); | 1216 | cli_ctx = GNUNET_SERVER_client_get_user_context (reply_cls->client, struct client_ctx); |
1197 | if (NULL == cli_ctx) { | 1217 | if (NULL == cli_ctx) { |
1198 | cli_ctx = GNUNET_new (struct client_ctx); | 1218 | cli_ctx = GNUNET_new (struct client_ctx); |
1199 | cli_ctx->mq = GNUNET_MQ_queue_for_server_client (client); | 1219 | cli_ctx->mq = GNUNET_MQ_queue_for_server_client (reply_cls->client); |
1200 | GNUNET_SERVER_client_set_user_context (client, cli_ctx); | 1220 | GNUNET_SERVER_client_set_user_context (reply_cls->client, cli_ctx); |
1201 | } | 1221 | } |
1202 | 1222 | ||
1223 | GNUNET_free (reply_cls); | ||
1224 | |||
1203 | GNUNET_MQ_send (cli_ctx->mq, ev); | 1225 | GNUNET_MQ_send (cli_ctx->mq, ev); |
1204 | } | 1226 | } |
1205 | 1227 | ||
@@ -1219,6 +1241,7 @@ handle_client_request (void *cls, | |||
1219 | struct GNUNET_RPS_CS_RequestMessage *msg; | 1241 | struct GNUNET_RPS_CS_RequestMessage *msg; |
1220 | uint32_t num_peers; | 1242 | uint32_t num_peers; |
1221 | uint32_t size_needed; | 1243 | uint32_t size_needed; |
1244 | struct ReplyCls *reply_cls; | ||
1222 | uint32_t i; | 1245 | uint32_t i; |
1223 | 1246 | ||
1224 | msg = (struct GNUNET_RPS_CS_RequestMessage *) message; | 1247 | msg = (struct GNUNET_RPS_CS_RequestMessage *) message; |
@@ -1236,10 +1259,19 @@ handle_client_request (void *cls, | |||
1236 | for (i = 0 ; i < num_peers ; i++) | 1259 | for (i = 0 ; i < num_peers ; i++) |
1237 | est_request_rate(); | 1260 | est_request_rate(); |
1238 | 1261 | ||
1239 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested %" PRIu32 " random peer(s).\n", num_peers); | 1262 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1263 | "Client requested %" PRIu32 " random peer(s).\n", | ||
1264 | num_peers); | ||
1265 | |||
1266 | reply_cls = GNUNET_new (struct ReplyCls); | ||
1267 | reply_cls->id = ntohl (msg->id); | ||
1268 | reply_cls->client = client; | ||
1240 | 1269 | ||
1241 | RPS_sampler_get_n_rand_peers (client_sampler, client_respond, | 1270 | RPS_sampler_get_n_rand_peers (client_sampler, |
1242 | client, num_peers, GNUNET_YES); | 1271 | client_respond, |
1272 | reply_cls, | ||
1273 | num_peers, | ||
1274 | GNUNET_YES); | ||
1243 | 1275 | ||
1244 | GNUNET_SERVER_receive_done (client, | 1276 | GNUNET_SERVER_receive_done (client, |
1245 | GNUNET_OK); | 1277 | GNUNET_OK); |
@@ -1288,8 +1320,6 @@ handle_client_seed (void *cls, | |||
1288 | "Client seeded peers:\n"); | 1320 | "Client seeded peers:\n"); |
1289 | print_peer_list (peers, num_peers); | 1321 | print_peer_list (peers, num_peers); |
1290 | 1322 | ||
1291 | // TODO check for validity of ids | ||
1292 | |||
1293 | for (i = 0 ; i < num_peers ; i++) | 1323 | for (i = 0 ; i < num_peers ; i++) |
1294 | { | 1324 | { |
1295 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1325 | LOG (GNUNET_ERROR_TYPE_DEBUG, |