diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 205 |
1 files changed, 87 insertions, 118 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index de1a71680..974953ea0 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -95,7 +95,7 @@ struct ReplyCls | |||
95 | /** | 95 | /** |
96 | * The client handle to send the reply to | 96 | * The client handle to send the reply to |
97 | */ | 97 | */ |
98 | struct GNUNET_SERVER_Client *client; | 98 | struct ClientContext *cli_ctx; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | 101 | ||
@@ -124,7 +124,7 @@ struct ClientContext | |||
124 | /** | 124 | /** |
125 | * The client handle to send the reply to | 125 | * The client handle to send the reply to |
126 | */ | 126 | */ |
127 | struct GNUNET_SERVER_Client *client; | 127 | struct GNUNET_SERVICE_Client *client; |
128 | }; | 128 | }; |
129 | 129 | ||
130 | /** | 130 | /** |
@@ -797,11 +797,14 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
797 | { | 797 | { |
798 | if (GNUNET_NO == check_sending_channel_needed (peer)) | 798 | if (GNUNET_NO == check_sending_channel_needed (peer)) |
799 | { | 799 | { |
800 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
801 | "Going to remove send channel to peer %s\n", | ||
802 | GNUNET_i2s (peer)); | ||
800 | #ifdef ENABLE_MALICIOUS | 803 | #ifdef ENABLE_MALICIOUS |
801 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer)) | 804 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer)) |
802 | Peers_destroy_sending_channel (peer); | 805 | (void) Peers_destroy_sending_channel (peer); |
803 | #else /* ENABLE_MALICIOUS */ | 806 | #else /* ENABLE_MALICIOUS */ |
804 | Peers_destroy_sending_channel (peer); | 807 | (void) Peers_destroy_sending_channel (peer); |
805 | #endif /* ENABLE_MALICIOUS */ | 808 | #endif /* ENABLE_MALICIOUS */ |
806 | } | 809 | } |
807 | 810 | ||
@@ -916,8 +919,7 @@ destroy_reply_cls (struct ReplyCls *rep_cls) | |||
916 | { | 919 | { |
917 | struct ClientContext *cli_ctx; | 920 | struct ClientContext *cli_ctx; |
918 | 921 | ||
919 | cli_ctx = GNUNET_SERVER_client_get_user_context (rep_cls->client, | 922 | cli_ctx = rep_cls->cli_ctx; |
920 | struct ClientContext); | ||
921 | GNUNET_assert (NULL != cli_ctx); | 923 | GNUNET_assert (NULL != cli_ctx); |
922 | GNUNET_CONTAINER_DLL_remove (cli_ctx->rep_cls_head, | 924 | GNUNET_CONTAINER_DLL_remove (cli_ctx->rep_cls_head, |
923 | cli_ctx->rep_cls_tail, | 925 | cli_ctx->rep_cls_tail, |
@@ -994,10 +996,10 @@ client_respond (void *cls, | |||
994 | struct GNUNET_PeerIdentity *peer_ids, | 996 | struct GNUNET_PeerIdentity *peer_ids, |
995 | uint32_t num_peers) | 997 | uint32_t num_peers) |
996 | { | 998 | { |
999 | struct ReplyCls *reply_cls = cls; | ||
997 | uint32_t i; | 1000 | uint32_t i; |
998 | struct GNUNET_MQ_Envelope *ev; | 1001 | struct GNUNET_MQ_Envelope *ev; |
999 | struct GNUNET_RPS_CS_ReplyMessage *out_msg; | 1002 | struct GNUNET_RPS_CS_ReplyMessage *out_msg; |
1000 | struct ReplyCls *reply_cls = (struct ReplyCls *) cls; | ||
1001 | uint32_t size_needed; | 1003 | uint32_t size_needed; |
1002 | struct ClientContext *cli_ctx; | 1004 | struct ClientContext *cli_ctx; |
1003 | 1005 | ||
@@ -1029,8 +1031,7 @@ client_respond (void *cls, | |||
1029 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 1031 | num_peers * sizeof (struct GNUNET_PeerIdentity)); |
1030 | GNUNET_free (peer_ids); | 1032 | GNUNET_free (peer_ids); |
1031 | 1033 | ||
1032 | cli_ctx = GNUNET_SERVER_client_get_user_context (reply_cls->client, | 1034 | cli_ctx = reply_cls->cli_ctx; |
1033 | struct ClientContext); | ||
1034 | GNUNET_assert (NULL != cli_ctx); | 1035 | GNUNET_assert (NULL != cli_ctx); |
1035 | destroy_reply_cls (reply_cls); | 1036 | destroy_reply_cls (reply_cls); |
1036 | GNUNET_MQ_send (cli_ctx->mq, ev); | 1037 | GNUNET_MQ_send (cli_ctx->mq, ev); |
@@ -1046,17 +1047,13 @@ client_respond (void *cls, | |||
1046 | */ | 1047 | */ |
1047 | static void | 1048 | static void |
1048 | handle_client_request (void *cls, | 1049 | handle_client_request (void *cls, |
1049 | struct GNUNET_SERVER_Client *client, | 1050 | const struct GNUNET_RPS_CS_RequestMessage *msg) |
1050 | const struct GNUNET_MessageHeader *message) | ||
1051 | { | 1051 | { |
1052 | struct GNUNET_RPS_CS_RequestMessage *msg; | 1052 | struct ClientContext *cli_ctx = cls; |
1053 | uint32_t num_peers; | 1053 | uint32_t num_peers; |
1054 | uint32_t size_needed; | 1054 | uint32_t size_needed; |
1055 | struct ReplyCls *reply_cls; | 1055 | struct ReplyCls *reply_cls; |
1056 | uint32_t i; | 1056 | uint32_t i; |
1057 | struct ClientContext *cli_ctx; | ||
1058 | |||
1059 | msg = (struct GNUNET_RPS_CS_RequestMessage *) message; | ||
1060 | 1057 | ||
1061 | num_peers = ntohl (msg->num_peers); | 1058 | num_peers = ntohl (msg->num_peers); |
1062 | size_needed = sizeof (struct GNUNET_RPS_CS_RequestMessage) + | 1059 | size_needed = sizeof (struct GNUNET_RPS_CS_RequestMessage) + |
@@ -1066,7 +1063,7 @@ handle_client_request (void *cls, | |||
1066 | { | 1063 | { |
1067 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1064 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1068 | "Message received from client has size larger than expected\n"); | 1065 | "Message received from client has size larger than expected\n"); |
1069 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1066 | GNUNET_SERVICE_client_drop (cli_ctx->client); |
1070 | return; | 1067 | return; |
1071 | } | 1068 | } |
1072 | 1069 | ||
@@ -1079,19 +1076,17 @@ handle_client_request (void *cls, | |||
1079 | 1076 | ||
1080 | reply_cls = GNUNET_new (struct ReplyCls); | 1077 | reply_cls = GNUNET_new (struct ReplyCls); |
1081 | reply_cls->id = ntohl (msg->id); | 1078 | reply_cls->id = ntohl (msg->id); |
1082 | reply_cls->client = client; | 1079 | reply_cls->cli_ctx = cli_ctx; |
1083 | reply_cls->req_handle = RPS_sampler_get_n_rand_peers (client_sampler, | 1080 | reply_cls->req_handle = RPS_sampler_get_n_rand_peers (client_sampler, |
1084 | client_respond, | 1081 | client_respond, |
1085 | reply_cls, | 1082 | reply_cls, |
1086 | num_peers); | 1083 | num_peers); |
1087 | 1084 | ||
1088 | cli_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientContext); | ||
1089 | GNUNET_assert (NULL != cli_ctx); | 1085 | GNUNET_assert (NULL != cli_ctx); |
1090 | GNUNET_CONTAINER_DLL_insert (cli_ctx->rep_cls_head, | 1086 | GNUNET_CONTAINER_DLL_insert (cli_ctx->rep_cls_head, |
1091 | cli_ctx->rep_cls_tail, | 1087 | cli_ctx->rep_cls_tail, |
1092 | reply_cls); | 1088 | reply_cls); |
1093 | GNUNET_SERVER_receive_done (client, | 1089 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
1094 | GNUNET_OK); | ||
1095 | } | 1090 | } |
1096 | 1091 | ||
1097 | 1092 | ||
@@ -1104,15 +1099,11 @@ handle_client_request (void *cls, | |||
1104 | */ | 1099 | */ |
1105 | static void | 1100 | static void |
1106 | handle_client_request_cancel (void *cls, | 1101 | handle_client_request_cancel (void *cls, |
1107 | struct GNUNET_SERVER_Client *client, | 1102 | const struct GNUNET_RPS_CS_RequestCancelMessage *msg) |
1108 | const struct GNUNET_MessageHeader *message) | ||
1109 | { | 1103 | { |
1110 | struct GNUNET_RPS_CS_RequestCancelMessage *msg = | 1104 | struct ClientContext *cli_ctx = cls; |
1111 | (struct GNUNET_RPS_CS_RequestCancelMessage *) message; | ||
1112 | struct ClientContext *cli_ctx; | ||
1113 | struct ReplyCls *rep_cls; | 1105 | struct ReplyCls *rep_cls; |
1114 | 1106 | ||
1115 | cli_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientContext); | ||
1116 | GNUNET_assert (NULL != cli_ctx); | 1107 | GNUNET_assert (NULL != cli_ctx); |
1117 | GNUNET_assert (NULL != cli_ctx->rep_cls_head); | 1108 | GNUNET_assert (NULL != cli_ctx->rep_cls_head); |
1118 | rep_cls = cli_ctx->rep_cls_head; | 1109 | rep_cls = cli_ctx->rep_cls_head; |
@@ -1125,8 +1116,7 @@ handle_client_request_cancel (void *cls, | |||
1125 | GNUNET_assert (rep_cls->id == ntohl (msg->id)); | 1116 | GNUNET_assert (rep_cls->id == ntohl (msg->id)); |
1126 | RPS_sampler_request_cancel (rep_cls->req_handle); | 1117 | RPS_sampler_request_cancel (rep_cls->req_handle); |
1127 | destroy_reply_cls (rep_cls); | 1118 | destroy_reply_cls (rep_cls); |
1128 | GNUNET_SERVER_receive_done (client, | 1119 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
1129 | GNUNET_OK); | ||
1130 | } | 1120 | } |
1131 | 1121 | ||
1132 | 1122 | ||
@@ -1139,9 +1129,9 @@ handle_client_request_cancel (void *cls, | |||
1139 | */ | 1129 | */ |
1140 | static void | 1130 | static void |
1141 | handle_client_seed (void *cls, | 1131 | handle_client_seed (void *cls, |
1142 | struct GNUNET_SERVER_Client *client, | ||
1143 | const struct GNUNET_MessageHeader *message) | 1132 | const struct GNUNET_MessageHeader *message) |
1144 | { | 1133 | { |
1134 | struct ClientContext *cli_ctx = cls; | ||
1145 | struct GNUNET_RPS_CS_SeedMessage *in_msg; | 1135 | struct GNUNET_RPS_CS_SeedMessage *in_msg; |
1146 | struct GNUNET_PeerIdentity *peers; | 1136 | struct GNUNET_PeerIdentity *peers; |
1147 | uint32_t num_peers; | 1137 | uint32_t num_peers; |
@@ -1149,8 +1139,7 @@ handle_client_seed (void *cls, | |||
1149 | 1139 | ||
1150 | if (sizeof (struct GNUNET_RPS_CS_SeedMessage) > ntohs (message->size)) | 1140 | if (sizeof (struct GNUNET_RPS_CS_SeedMessage) > ntohs (message->size)) |
1151 | { | 1141 | { |
1152 | GNUNET_SERVER_receive_done (client, | 1142 | GNUNET_SERVICE_client_drop (cli_ctx->client); |
1153 | GNUNET_SYSERR); | ||
1154 | GNUNET_break_op (0); | 1143 | GNUNET_break_op (0); |
1155 | return; | 1144 | return; |
1156 | } | 1145 | } |
@@ -1165,8 +1154,7 @@ handle_client_seed (void *cls, | |||
1165 | sizeof (struct GNUNET_PeerIdentity) != num_peers) | 1154 | sizeof (struct GNUNET_PeerIdentity) != num_peers) |
1166 | { | 1155 | { |
1167 | GNUNET_break_op (0); | 1156 | GNUNET_break_op (0); |
1168 | GNUNET_SERVER_receive_done (client, | 1157 | GNUNET_SERVICE_client_drop (cli_ctx->client); |
1169 | GNUNET_SYSERR); | ||
1170 | return; | 1158 | return; |
1171 | } | 1159 | } |
1172 | 1160 | ||
@@ -1189,8 +1177,7 @@ handle_client_seed (void *cls, | |||
1189 | 1177 | ||
1190 | ////GNUNET_free (peers); | 1178 | ////GNUNET_free (peers); |
1191 | 1179 | ||
1192 | GNUNET_SERVER_receive_done (client, | 1180 | GNUNET_SERVICE_client_drop (cli_ctx->client); |
1193 | GNUNET_OK); | ||
1194 | } | 1181 | } |
1195 | 1182 | ||
1196 | /** | 1183 | /** |
@@ -1579,9 +1566,9 @@ do_mal_round (void *cls); | |||
1579 | */ | 1566 | */ |
1580 | static void | 1567 | static void |
1581 | handle_client_act_malicious (void *cls, | 1568 | handle_client_act_malicious (void *cls, |
1582 | struct GNUNET_SERVER_Client *client, | ||
1583 | const struct GNUNET_MessageHeader *msg) | 1569 | const struct GNUNET_MessageHeader *msg) |
1584 | { | 1570 | { |
1571 | struct ClientContext *cli_ctx = cls; | ||
1585 | struct GNUNET_RPS_CS_ActMaliciousMessage *in_msg; | 1572 | struct GNUNET_RPS_CS_ActMaliciousMessage *in_msg; |
1586 | struct GNUNET_PeerIdentity *peers; | 1573 | struct GNUNET_PeerIdentity *peers; |
1587 | uint32_t num_mal_peers_sent; | 1574 | uint32_t num_mal_peers_sent; |
@@ -1590,7 +1577,7 @@ handle_client_act_malicious (void *cls, | |||
1590 | /* Check for protocol violation */ | 1577 | /* Check for protocol violation */ |
1591 | if (sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage) > ntohs (msg->size)) | 1578 | if (sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage) > ntohs (msg->size)) |
1592 | { | 1579 | { |
1593 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1580 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
1594 | GNUNET_break_op (0); | 1581 | GNUNET_break_op (0); |
1595 | } | 1582 | } |
1596 | 1583 | ||
@@ -1603,7 +1590,7 @@ handle_client_act_malicious (void *cls, | |||
1603 | ntohl (in_msg->num_peers), | 1590 | ntohl (in_msg->num_peers), |
1604 | (ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) / | 1591 | (ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) / |
1605 | sizeof (struct GNUNET_PeerIdentity)); | 1592 | sizeof (struct GNUNET_PeerIdentity)); |
1606 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1593 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
1607 | GNUNET_break_op (0); | 1594 | GNUNET_break_op (0); |
1608 | } | 1595 | } |
1609 | 1596 | ||
@@ -1694,9 +1681,9 @@ handle_client_act_malicious (void *cls, | |||
1694 | else | 1681 | else |
1695 | { | 1682 | { |
1696 | GNUNET_break (0); | 1683 | GNUNET_break (0); |
1697 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1684 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
1698 | } | 1685 | } |
1699 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1686 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
1700 | } | 1687 | } |
1701 | 1688 | ||
1702 | 1689 | ||
@@ -2052,10 +2039,6 @@ do_round (void *cls) | |||
2052 | } | 2039 | } |
2053 | 2040 | ||
2054 | 2041 | ||
2055 | static void | ||
2056 | rps_start (struct GNUNET_SERVER_Handle *server); | ||
2057 | |||
2058 | |||
2059 | /** | 2042 | /** |
2060 | * This is called from GNUNET_CADET_get_peers(). | 2043 | * This is called from GNUNET_CADET_get_peers(). |
2061 | * | 2044 | * |
@@ -2160,7 +2143,6 @@ shutdown_task (void *cls) | |||
2160 | GNUNET_free (reply_cls); | 2143 | GNUNET_free (reply_cls); |
2161 | } | 2144 | } |
2162 | GNUNET_MQ_destroy (client_ctx->mq); | 2145 | GNUNET_MQ_destroy (client_ctx->mq); |
2163 | GNUNET_SERVER_client_disconnect (client_ctx->client); | ||
2164 | GNUNET_CONTAINER_DLL_remove (cli_ctx_head, cli_ctx_tail, client_ctx); | 2146 | GNUNET_CONTAINER_DLL_remove (cli_ctx_head, cli_ctx_tail, client_ctx); |
2165 | GNUNET_free (client_ctx); | 2147 | GNUNET_free (client_ctx); |
2166 | } | 2148 | } |
@@ -2200,42 +2182,48 @@ shutdown_task (void *cls) | |||
2200 | 2182 | ||
2201 | 2183 | ||
2202 | /** | 2184 | /** |
2203 | * @brief Get informed about a connecting client. | 2185 | * Handle client connecting to the service. |
2204 | * | 2186 | * |
2205 | * @param cls unused | 2187 | * @param cls NULL |
2206 | * @param client the client that connects | 2188 | * @param client the new client |
2207 | */ | 2189 | * @param mq the message queue of @a client |
2208 | static void | 2190 | * @return @a client |
2209 | handle_client_connect (void *cls, | 2191 | */ |
2210 | struct GNUNET_SERVER_Client *client) | 2192 | static void * |
2193 | client_connect_cb (void *cls, | ||
2194 | struct GNUNET_SERVICE_Client *client, | ||
2195 | struct GNUNET_MQ_Handle *mq) | ||
2211 | { | 2196 | { |
2212 | struct ClientContext *cli_ctx; | 2197 | struct ClientContext *cli_ctx; |
2213 | 2198 | ||
2214 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2199 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2215 | "Client connected\n"); | 2200 | "Client connected\n"); |
2216 | if (NULL == client) | 2201 | if (NULL == client) |
2217 | return; /* Server was destroyed before a client connected. Shutting down */ | 2202 | return client; /* Server was destroyed before a client connected. Shutting down */ |
2218 | cli_ctx = GNUNET_new (struct ClientContext); | 2203 | cli_ctx = GNUNET_new (struct ClientContext); |
2219 | cli_ctx->mq = GNUNET_MQ_queue_for_server_client (client); | 2204 | cli_ctx->mq = GNUNET_SERVICE_client_get_mq (client); |
2220 | cli_ctx->client = client; | 2205 | cli_ctx->client = client; |
2221 | GNUNET_SERVER_client_set_user_context (client, cli_ctx); | ||
2222 | GNUNET_CONTAINER_DLL_insert (cli_ctx_head, | 2206 | GNUNET_CONTAINER_DLL_insert (cli_ctx_head, |
2223 | cli_ctx_tail, | 2207 | cli_ctx_tail, |
2224 | cli_ctx); | 2208 | cli_ctx); |
2209 | return cli_ctx; | ||
2225 | } | 2210 | } |
2226 | 2211 | ||
2227 | /** | 2212 | /** |
2228 | * A client disconnected. Remove all of its data structure entries. | 2213 | * Callback called when a client disconnected from the service |
2229 | * | 2214 | * |
2230 | * @param cls closure, NULL | 2215 | * @param cls closure for the service |
2231 | * @param client identification of the client | 2216 | * @param c the client that disconnected |
2217 | * @param internal_cls should be equal to @a c | ||
2232 | */ | 2218 | */ |
2233 | static void | 2219 | static void |
2234 | handle_client_disconnect (void *cls, | 2220 | client_disconnect_cb (void *cls, |
2235 | struct GNUNET_SERVER_Client *client) | 2221 | struct GNUNET_SERVICE_Client *client, |
2222 | void *internal_cls) | ||
2236 | { | 2223 | { |
2237 | struct ClientContext *cli_ctx; | 2224 | struct ClientContext *cli_ctx = internal_cls; |
2238 | 2225 | ||
2226 | GNUNET_assert (client == cli_ctx->client); | ||
2239 | if (NULL == client) | 2227 | if (NULL == client) |
2240 | {/* shutdown task */ | 2228 | {/* shutdown task */ |
2241 | while (NULL != cli_ctx_head) | 2229 | while (NULL != cli_ctx_head) |
@@ -2243,58 +2231,22 @@ handle_client_disconnect (void *cls, | |||
2243 | } | 2231 | } |
2244 | else | 2232 | else |
2245 | { | 2233 | { |
2246 | cli_ctx = GNUNET_SERVER_client_get_user_context (client, struct ClientContext); | ||
2247 | destroy_cli_ctx (cli_ctx); | 2234 | destroy_cli_ctx (cli_ctx); |
2248 | } | 2235 | } |
2249 | } | 2236 | } |
2250 | 2237 | ||
2251 | 2238 | ||
2252 | /** | 2239 | /** |
2253 | * Actually start the service. | 2240 | * Handle random peer sampling clients. |
2254 | */ | ||
2255 | static void | ||
2256 | rps_start (struct GNUNET_SERVER_Handle *server) | ||
2257 | { | ||
2258 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
2259 | {&handle_client_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST, | ||
2260 | sizeof (struct GNUNET_RPS_CS_RequestMessage)}, | ||
2261 | {&handle_client_request_cancel, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST_CANCEL, | ||
2262 | sizeof (struct GNUNET_RPS_CS_RequestCancelMessage)}, | ||
2263 | {&handle_client_seed, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_SEED, 0}, | ||
2264 | #ifdef ENABLE_MALICIOUS | ||
2265 | {&handle_client_act_malicious, NULL, GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS , 0}, | ||
2266 | #endif /* ENABLE_MALICIOUS */ | ||
2267 | {NULL, NULL, 0, 0} | ||
2268 | }; | ||
2269 | |||
2270 | GNUNET_SERVER_add_handlers (server, handlers); | ||
2271 | GNUNET_SERVER_connect_notify (server, | ||
2272 | &handle_client_connect, | ||
2273 | NULL); | ||
2274 | GNUNET_SERVER_disconnect_notify (server, | ||
2275 | &handle_client_disconnect, | ||
2276 | NULL); | ||
2277 | LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); | ||
2278 | |||
2279 | |||
2280 | do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL); | ||
2281 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n"); | ||
2282 | |||
2283 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
2284 | } | ||
2285 | |||
2286 | |||
2287 | /** | ||
2288 | * Process statistics requests. | ||
2289 | * | 2241 | * |
2290 | * @param cls closure | 2242 | * @param cls closure |
2291 | * @param server the initialized server | ||
2292 | * @param c configuration to use | 2243 | * @param c configuration to use |
2244 | * @param service the initialized service | ||
2293 | */ | 2245 | */ |
2294 | static void | 2246 | static void |
2295 | run (void *cls, | 2247 | run (void *cls, |
2296 | struct GNUNET_SERVER_Handle *server, | 2248 | const struct GNUNET_CONFIGURATION_Handle *c, |
2297 | const struct GNUNET_CONFIGURATION_Handle *c) | 2249 | struct GNUNET_SERVICE_Handle *service) |
2298 | { | 2250 | { |
2299 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | 2251 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { |
2300 | {&handle_peer_check , GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, | 2252 | {&handle_peer_check , GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, |
@@ -2440,26 +2392,43 @@ run (void *cls, | |||
2440 | process_peerinfo_peers, | 2392 | process_peerinfo_peers, |
2441 | NULL); | 2393 | NULL); |
2442 | 2394 | ||
2443 | rps_start (server); | 2395 | LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); |
2396 | |||
2397 | do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL); | ||
2398 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n"); | ||
2399 | |||
2400 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
2444 | } | 2401 | } |
2445 | 2402 | ||
2446 | 2403 | ||
2447 | /** | 2404 | /** |
2448 | * The main function for the rps service. | 2405 | * Define "main" method using service macro. |
2449 | * | 2406 | */ |
2450 | * @param argc number of arguments from the command line | 2407 | GNUNET_SERVICE_MAIN |
2451 | * @param argv command line arguments | 2408 | ("rps", |
2452 | * @return 0 ok, 1 on error | 2409 | GNUNET_SERVICE_OPTION_NONE, |
2453 | */ | 2410 | &run, |
2454 | int | 2411 | &client_connect_cb, |
2455 | main (int argc, char *const *argv) | 2412 | &client_disconnect_cb, |
2456 | { | 2413 | NULL, |
2457 | return (GNUNET_OK == | 2414 | GNUNET_MQ_hd_fixed_size (client_request, |
2458 | GNUNET_SERVICE_run (argc, | 2415 | GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST, |
2459 | argv, | 2416 | struct GNUNET_RPS_CS_RequestMessage, |
2460 | "rps", | 2417 | NULL), |
2461 | GNUNET_SERVICE_OPTION_NONE, | 2418 | GNUNET_MQ_hd_fixed_size (client_request_cancel, |
2462 | &run, NULL)) ? 0 : 1; | 2419 | GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST_CANCEL, |
2463 | } | 2420 | struct GNUNET_RPS_CS_RequestCancelMessage, |
2421 | NULL), | ||
2422 | GNUNET_MQ_hd_fixed_size (client_seed, | ||
2423 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED, | ||
2424 | struct GNUNET_MessageHeader, | ||
2425 | NULL), | ||
2426 | #ifdef ENABLE_MALICIOUS | ||
2427 | GNUNET_MQ_hd_fixed_size (client_act_malicious, | ||
2428 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS, | ||
2429 | struct GNUNET_MessageHeader, | ||
2430 | NULL), | ||
2431 | #endif /* ENABLE_MALICIOUS */ | ||
2432 | GNUNET_MQ_handler_end()); | ||
2464 | 2433 | ||
2465 | /* end of gnunet-service-rps.c */ | 2434 | /* end of gnunet-service-rps.c */ |