diff options
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 222 |
1 files changed, 100 insertions, 122 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index adcfe7d02..0a4543b30 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -217,6 +217,11 @@ static struct GNUNET_NSE_Handle *nse; | |||
217 | static struct GNUNET_CADET_Handle *cadet_handle; | 217 | static struct GNUNET_CADET_Handle *cadet_handle; |
218 | 218 | ||
219 | /** | 219 | /** |
220 | * @brief Port to communicate to other peers. | ||
221 | */ | ||
222 | static struct GNUNET_CADET_Port *cadet_port; | ||
223 | |||
224 | /** | ||
220 | * Handler to PEERINFO. | 225 | * Handler to PEERINFO. |
221 | */ | 226 | */ |
222 | static struct GNUNET_PEERINFO_Handle *peerinfo_handle; | 227 | static struct GNUNET_PEERINFO_Handle *peerinfo_handle; |
@@ -838,14 +843,10 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
838 | */ | 843 | */ |
839 | static void | 844 | static void |
840 | cleanup_destroyed_channel (void *cls, | 845 | cleanup_destroyed_channel (void *cls, |
841 | const struct GNUNET_CADET_Channel *channel, | 846 | const struct GNUNET_CADET_Channel *channel) |
842 | void *channel_ctx) | ||
843 | { | 847 | { |
844 | struct GNUNET_PeerIdentity *peer; | 848 | struct GNUNET_PeerIdentity *peer = cls; |
845 | 849 | uint32_t *channel_flag; | |
846 | peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info ( | ||
847 | (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER); | ||
848 | // FIXME wait for cadet to change this function | ||
849 | 850 | ||
850 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 851 | if (GNUNET_NO == Peers_check_peer_known (peer)) |
851 | { /* We don't know a context to that peer */ | 852 | { /* We don't know a context to that peer */ |
@@ -858,7 +859,7 @@ cleanup_destroyed_channel (void *cls, | |||
858 | if (GNUNET_YES == Peers_check_peer_flag (peer, Peers_TO_DESTROY)) | 859 | if (GNUNET_YES == Peers_check_peer_flag (peer, Peers_TO_DESTROY)) |
859 | { /* We are in the middle of removing that peer from our knowledge. In this | 860 | { /* We are in the middle of removing that peer from our knowledge. In this |
860 | case simply make sure that the channels are cleaned. */ | 861 | case simply make sure that the channels are cleaned. */ |
861 | Peers_cleanup_destroyed_channel (cls, channel, channel_ctx); | 862 | Peers_cleanup_destroyed_channel (cls, channel); |
862 | to_file (file_name_view_log, | 863 | to_file (file_name_view_log, |
863 | "-%s\t(cleanup channel, ourself)", | 864 | "-%s\t(cleanup channel, ourself)", |
864 | GNUNET_i2s_full (peer)); | 865 | GNUNET_i2s_full (peer)); |
@@ -872,16 +873,17 @@ cleanup_destroyed_channel (void *cls, | |||
872 | * - ourselves -> cleaning send channel -> clean context | 873 | * - ourselves -> cleaning send channel -> clean context |
873 | * - other peer -> peer probably went down -> remove | 874 | * - other peer -> peer probably went down -> remove |
874 | */ | 875 | */ |
875 | if (GNUNET_YES == Peers_check_channel_flag (channel_ctx, Peers_CHANNEL_CLEAN)) | 876 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); |
877 | if (GNUNET_YES == Peers_check_channel_flag (channel_flag, Peers_CHANNEL_CLEAN)) | ||
876 | { /* We are about to clean the sending channel. Clean the respective | 878 | { /* We are about to clean the sending channel. Clean the respective |
877 | * context */ | 879 | * context */ |
878 | Peers_cleanup_destroyed_channel (cls, channel, channel_ctx); | 880 | Peers_cleanup_destroyed_channel (cls, channel); |
879 | return; | 881 | return; |
880 | } | 882 | } |
881 | else | 883 | else |
882 | { /* Other peer destroyed our sending channel that he is supposed to keep | 884 | { /* Other peer destroyed our sending channel that he is supposed to keep |
883 | * open. It probably went down. Remove it from our knowledge. */ | 885 | * open. It probably went down. Remove it from our knowledge. */ |
884 | Peers_cleanup_destroyed_channel (cls, channel, channel_ctx); | 886 | Peers_cleanup_destroyed_channel (cls, channel); |
885 | remove_peer (peer); | 887 | remove_peer (peer); |
886 | return; | 888 | return; |
887 | } | 889 | } |
@@ -893,17 +895,18 @@ cleanup_destroyed_channel (void *cls, | |||
893 | * - ourselves -> peer tried to establish channel twice -> clean context | 895 | * - ourselves -> peer tried to establish channel twice -> clean context |
894 | * - other peer -> peer doesn't want to send us data -> clean | 896 | * - other peer -> peer doesn't want to send us data -> clean |
895 | */ | 897 | */ |
898 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING); | ||
896 | if (GNUNET_YES == | 899 | if (GNUNET_YES == |
897 | Peers_check_channel_flag (channel_ctx, Peers_CHANNEL_ESTABLISHED_TWICE)) | 900 | Peers_check_channel_flag (channel_flag, Peers_CHANNEL_ESTABLISHED_TWICE)) |
898 | { /* Other peer tried to establish a channel to us twice. We do not accept | 901 | { /* Other peer tried to establish a channel to us twice. We do not accept |
899 | * that. Clean the context. */ | 902 | * that. Clean the context. */ |
900 | Peers_cleanup_destroyed_channel (cls, channel, channel_ctx); | 903 | Peers_cleanup_destroyed_channel (cls, channel); |
901 | return; | 904 | return; |
902 | } | 905 | } |
903 | else | 906 | else |
904 | { /* Other peer doesn't want to send us data anymore. We are free to clean | 907 | { /* Other peer doesn't want to send us data anymore. We are free to clean |
905 | * it. */ | 908 | * it. */ |
906 | Peers_cleanup_destroyed_channel (cls, channel, channel_ctx); | 909 | Peers_cleanup_destroyed_channel (cls, channel); |
907 | clean_peer (peer); | 910 | clean_peer (peer); |
908 | return; | 911 | return; |
909 | } | 912 | } |
@@ -1023,7 +1026,7 @@ client_respond (void *cls, | |||
1023 | size_needed = sizeof (struct GNUNET_RPS_CS_ReplyMessage) + | 1026 | size_needed = sizeof (struct GNUNET_RPS_CS_ReplyMessage) + |
1024 | num_peers * sizeof (struct GNUNET_PeerIdentity); | 1027 | num_peers * sizeof (struct GNUNET_PeerIdentity); |
1025 | 1028 | ||
1026 | GNUNET_assert (GNUNET_SERVER_MAX_MESSAGE_SIZE >= size_needed); | 1029 | GNUNET_assert (GNUNET_MAX_MESSAGE_SIZE >= size_needed); |
1027 | 1030 | ||
1028 | ev = GNUNET_MQ_msg_extra (out_msg, | 1031 | ev = GNUNET_MQ_msg_extra (out_msg, |
1029 | num_peers * sizeof (struct GNUNET_PeerIdentity), | 1032 | num_peers * sizeof (struct GNUNET_PeerIdentity), |
@@ -1048,7 +1051,6 @@ client_respond (void *cls, | |||
1048 | * Handle RPS request from the client. | 1051 | * Handle RPS request from the client. |
1049 | * | 1052 | * |
1050 | * @param cls closure | 1053 | * @param cls closure |
1051 | * @param client identification of the client | ||
1052 | * @param message the actual message | 1054 | * @param message the actual message |
1053 | */ | 1055 | */ |
1054 | static void | 1056 | static void |
@@ -1065,7 +1067,7 @@ handle_client_request (void *cls, | |||
1065 | size_needed = sizeof (struct GNUNET_RPS_CS_RequestMessage) + | 1067 | size_needed = sizeof (struct GNUNET_RPS_CS_RequestMessage) + |
1066 | num_peers * sizeof (struct GNUNET_PeerIdentity); | 1068 | num_peers * sizeof (struct GNUNET_PeerIdentity); |
1067 | 1069 | ||
1068 | if (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed) | 1070 | if (GNUNET_MAX_MESSAGE_SIZE < size_needed) |
1069 | { | 1071 | { |
1070 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1072 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1071 | "Message received from client has size larger than expected\n"); | 1073 | "Message received from client has size larger than expected\n"); |
@@ -1100,12 +1102,11 @@ handle_client_request (void *cls, | |||
1100 | * @brief Handle a message that requests the cancellation of a request | 1102 | * @brief Handle a message that requests the cancellation of a request |
1101 | * | 1103 | * |
1102 | * @param cls unused | 1104 | * @param cls unused |
1103 | * @param client the client that requests the cancellation | ||
1104 | * @param message the message containing the id of the request | 1105 | * @param message the message containing the id of the request |
1105 | */ | 1106 | */ |
1106 | static void | 1107 | static void |
1107 | handle_client_request_cancel (void *cls, | 1108 | handle_client_request_cancel (void *cls, |
1108 | const struct GNUNET_RPS_CS_RequestCancelMessage *msg) | 1109 | const struct GNUNET_RPS_CS_RequestCancelMessage *msg) |
1109 | { | 1110 | { |
1110 | struct ClientContext *cli_ctx = cls; | 1111 | struct ClientContext *cli_ctx = cls; |
1111 | struct ReplyCls *rep_cls; | 1112 | struct ReplyCls *rep_cls; |
@@ -1157,7 +1158,6 @@ check_client_seed (void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) | |||
1157 | * Handle seed from the client. | 1158 | * Handle seed from the client. |
1158 | * | 1159 | * |
1159 | * @param cls closure | 1160 | * @param cls closure |
1160 | * @param client identification of the client | ||
1161 | * @param message the actual message | 1161 | * @param message the actual message |
1162 | */ | 1162 | */ |
1163 | static void | 1163 | static void |
@@ -1172,7 +1172,7 @@ handle_client_seed (void *cls, | |||
1172 | num_peers = ntohl (msg->num_peers); | 1172 | num_peers = ntohl (msg->num_peers); |
1173 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 1173 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
1174 | //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | 1174 | //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); |
1175 | //GNUNET_memcpy (peers, &in_msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity)); | 1175 | //GNUNET_memcpy (peers, &msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity)); |
1176 | 1176 | ||
1177 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1177 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1178 | "Client seeded peers:\n"); | 1178 | "Client seeded peers:\n"); |
@@ -1200,18 +1200,15 @@ handle_client_seed (void *cls, | |||
1200 | * the channel is blocked for all other communication. | 1200 | * the channel is blocked for all other communication. |
1201 | * | 1201 | * |
1202 | * @param cls Closure | 1202 | * @param cls Closure |
1203 | * @param channel The channel the CHECK was received over | ||
1204 | * @param channel_ctx The context associated with this channel | ||
1205 | * @param msg The message header | 1203 | * @param msg The message header |
1206 | */ | 1204 | */ |
1207 | static int | 1205 | static void |
1208 | handle_peer_check (void *cls, | 1206 | handle_peer_check (void *cls, |
1209 | struct GNUNET_CADET_Channel *channel, | 1207 | const struct GNUNET_MessageHeader *msg) |
1210 | void **channel_ctx, | ||
1211 | const struct GNUNET_MessageHeader *msg) | ||
1212 | { | 1208 | { |
1213 | GNUNET_CADET_receive_done (channel); | 1209 | const struct GNUNET_PeerIdentity *peer = cls; |
1214 | return GNUNET_OK; | 1210 | |
1211 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | ||
1215 | } | 1212 | } |
1216 | 1213 | ||
1217 | /** | 1214 | /** |
@@ -1221,24 +1218,16 @@ handle_peer_check (void *cls, | |||
1221 | * in the temporary list for pushed PeerIDs. | 1218 | * in the temporary list for pushed PeerIDs. |
1222 | * | 1219 | * |
1223 | * @param cls Closure | 1220 | * @param cls Closure |
1224 | * @param channel The channel the PUSH was received over | ||
1225 | * @param channel_ctx The context associated with this channel | ||
1226 | * @param msg The message header | 1221 | * @param msg The message header |
1227 | */ | 1222 | */ |
1228 | static int | 1223 | static void |
1229 | handle_peer_push (void *cls, | 1224 | handle_peer_push (void *cls, |
1230 | struct GNUNET_CADET_Channel *channel, | 1225 | const struct GNUNET_MessageHeader *msg) |
1231 | void **channel_ctx, | ||
1232 | const struct GNUNET_MessageHeader *msg) | ||
1233 | { | 1226 | { |
1234 | const struct GNUNET_PeerIdentity *peer; | 1227 | const struct GNUNET_PeerIdentity *peer = cls; |
1235 | 1228 | ||
1236 | // (check the proof of work (?)) | 1229 | // (check the proof of work (?)) |
1237 | 1230 | ||
1238 | peer = (const struct GNUNET_PeerIdentity *) | ||
1239 | GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER); | ||
1240 | // FIXME wait for cadet to change this function | ||
1241 | |||
1242 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1231 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1243 | "Received PUSH (%s)\n", | 1232 | "Received PUSH (%s)\n", |
1244 | GNUNET_i2s (peer)); | 1233 | GNUNET_i2s (peer)); |
@@ -1261,23 +1250,20 @@ handle_peer_push (void *cls, | |||
1261 | tmp_att_peer); | 1250 | tmp_att_peer); |
1262 | add_peer_array_to_set (peer, 1, att_peer_set); | 1251 | add_peer_array_to_set (peer, 1, att_peer_set); |
1263 | } | 1252 | } |
1264 | GNUNET_CADET_receive_done (channel); | 1253 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); |
1265 | return GNUNET_OK; | ||
1266 | } | 1254 | } |
1267 | 1255 | ||
1268 | 1256 | ||
1269 | else if (2 == mal_type) | 1257 | else if (2 == mal_type) |
1270 | { /* We attack one single well-known peer - simply ignore */ | 1258 | { /* We attack one single well-known peer - simply ignore */ |
1271 | GNUNET_CADET_receive_done (channel); | 1259 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); |
1272 | return GNUNET_OK; | ||
1273 | } | 1260 | } |
1274 | #endif /* ENABLE_MALICIOUS */ | 1261 | #endif /* ENABLE_MALICIOUS */ |
1275 | 1262 | ||
1276 | /* Add the sending peer to the push_map */ | 1263 | /* Add the sending peer to the push_map */ |
1277 | CustomPeerMap_put (push_map, peer); | 1264 | CustomPeerMap_put (push_map, peer); |
1278 | 1265 | ||
1279 | GNUNET_CADET_receive_done (channel); | 1266 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); |
1280 | return GNUNET_OK; | ||
1281 | } | 1267 | } |
1282 | 1268 | ||
1283 | 1269 | ||
@@ -1287,24 +1273,15 @@ handle_peer_push (void *cls, | |||
1287 | * Reply with the view of PeerIDs. | 1273 | * Reply with the view of PeerIDs. |
1288 | * | 1274 | * |
1289 | * @param cls Closure | 1275 | * @param cls Closure |
1290 | * @param channel The channel the PULL REQUEST was received over | ||
1291 | * @param channel_ctx The context associated with this channel | ||
1292 | * @param msg The message header | 1276 | * @param msg The message header |
1293 | */ | 1277 | */ |
1294 | static int | 1278 | static void |
1295 | handle_peer_pull_request (void *cls, | 1279 | handle_peer_pull_request (void *cls, |
1296 | struct GNUNET_CADET_Channel *channel, | 1280 | const struct GNUNET_MessageHeader *msg) |
1297 | void **channel_ctx, | ||
1298 | const struct GNUNET_MessageHeader *msg) | ||
1299 | { | 1281 | { |
1300 | struct GNUNET_PeerIdentity *peer; | 1282 | struct GNUNET_PeerIdentity *peer = cls; |
1301 | const struct GNUNET_PeerIdentity *view_array; | 1283 | const struct GNUNET_PeerIdentity *view_array; |
1302 | 1284 | ||
1303 | peer = (struct GNUNET_PeerIdentity *) | ||
1304 | GNUNET_CADET_channel_get_info (channel, | ||
1305 | GNUNET_CADET_OPTION_PEER); | ||
1306 | // FIXME wait for cadet to change this function | ||
1307 | |||
1308 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); | 1285 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); |
1309 | 1286 | ||
1310 | #ifdef ENABLE_MALICIOUS | 1287 | #ifdef ENABLE_MALICIOUS |
@@ -1312,8 +1289,7 @@ handle_peer_pull_request (void *cls, | |||
1312 | || 3 == mal_type) | 1289 | || 3 == mal_type) |
1313 | { /* Try to maximise representation */ | 1290 | { /* Try to maximise representation */ |
1314 | send_pull_reply (peer, mal_peers, num_mal_peers); | 1291 | send_pull_reply (peer, mal_peers, num_mal_peers); |
1315 | GNUNET_CADET_receive_done (channel); | 1292 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); |
1316 | return GNUNET_OK; | ||
1317 | } | 1293 | } |
1318 | 1294 | ||
1319 | else if (2 == mal_type) | 1295 | else if (2 == mal_type) |
@@ -1322,101 +1298,93 @@ handle_peer_pull_request (void *cls, | |||
1322 | { | 1298 | { |
1323 | send_pull_reply (peer, mal_peers, num_mal_peers); | 1299 | send_pull_reply (peer, mal_peers, num_mal_peers); |
1324 | } | 1300 | } |
1325 | GNUNET_CADET_receive_done (channel); | 1301 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); |
1326 | return GNUNET_OK; | ||
1327 | } | 1302 | } |
1328 | #endif /* ENABLE_MALICIOUS */ | 1303 | #endif /* ENABLE_MALICIOUS */ |
1329 | 1304 | ||
1330 | view_array = View_get_as_array (); | 1305 | view_array = View_get_as_array (); |
1331 | |||
1332 | send_pull_reply (peer, view_array, View_size ()); | 1306 | send_pull_reply (peer, view_array, View_size ()); |
1333 | 1307 | ||
1334 | GNUNET_CADET_receive_done (channel); | 1308 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); |
1335 | return GNUNET_OK; | ||
1336 | } | 1309 | } |
1337 | 1310 | ||
1338 | 1311 | ||
1339 | /** | 1312 | /** |
1340 | * Handle PULL REPLY message from another peer. | ||
1341 | * | ||
1342 | * Check whether we sent a corresponding request and | 1313 | * Check whether we sent a corresponding request and |
1343 | * whether this reply is the first one. | 1314 | * whether this reply is the first one. |
1344 | * | 1315 | * |
1345 | * @param cls Closure | 1316 | * @param cls Closure |
1346 | * @param channel The channel the PUSH was received over | ||
1347 | * @param channel_ctx The context associated with this channel | ||
1348 | * @param msg The message header | 1317 | * @param msg The message header |
1349 | */ | 1318 | */ |
1350 | static int | 1319 | static int |
1351 | handle_peer_pull_reply (void *cls, | 1320 | check_peer_pull_reply (void *cls, |
1352 | struct GNUNET_CADET_Channel *channel, | 1321 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) |
1353 | void **channel_ctx, | ||
1354 | const struct GNUNET_MessageHeader *msg) | ||
1355 | { | 1322 | { |
1356 | struct GNUNET_RPS_P2P_PullReplyMessage *in_msg; | 1323 | struct GNUNET_PeerIdentity *sender = cls; |
1357 | struct GNUNET_PeerIdentity *peers; | ||
1358 | struct GNUNET_PeerIdentity *sender; | ||
1359 | uint32_t i; | ||
1360 | #ifdef ENABLE_MALICIOUS | ||
1361 | struct AttackedPeer *tmp_att_peer; | ||
1362 | #endif /* ENABLE_MALICIOUS */ | ||
1363 | 1324 | ||
1364 | /* Check for protocol violation */ | 1325 | if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->header.size)) |
1365 | if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size)) | ||
1366 | { | 1326 | { |
1367 | GNUNET_break_op (0); | 1327 | GNUNET_break_op (0); |
1368 | GNUNET_CADET_receive_done (channel); | ||
1369 | return GNUNET_SYSERR; | 1328 | return GNUNET_SYSERR; |
1370 | } | 1329 | } |
1371 | 1330 | ||
1372 | in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg; | 1331 | if ((ntohs (msg->header.size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / |
1373 | if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | 1332 | sizeof (struct GNUNET_PeerIdentity) != ntohl (msg->num_peers)) |
1374 | sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers)) | ||
1375 | { | 1333 | { |
1376 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1334 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1377 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", | 1335 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", |
1378 | ntohl (in_msg->num_peers), | 1336 | ntohl (msg->num_peers), |
1379 | (ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | 1337 | (ntohs (msg->header.size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / |
1380 | sizeof (struct GNUNET_PeerIdentity)); | 1338 | sizeof (struct GNUNET_PeerIdentity)); |
1381 | GNUNET_break_op (0); | 1339 | GNUNET_break_op (0); |
1382 | GNUNET_CADET_receive_done (channel); | ||
1383 | return GNUNET_SYSERR; | 1340 | return GNUNET_SYSERR; |
1384 | } | 1341 | } |
1385 | 1342 | ||
1386 | // Guess simply casting isn't the nicest way... | ||
1387 | // FIXME wait for cadet to change this function | ||
1388 | sender = (struct GNUNET_PeerIdentity *) | ||
1389 | GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER); | ||
1390 | |||
1391 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (sender)); | ||
1392 | |||
1393 | if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) | 1343 | if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) |
1394 | { | 1344 | { |
1395 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1345 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1396 | "Received a pull reply from a peer we didn't request one from!\n"); | 1346 | "Received a pull reply from a peer we didn't request one from!\n"); |
1397 | GNUNET_CADET_receive_done (channel); | ||
1398 | GNUNET_break_op (0); | 1347 | GNUNET_break_op (0); |
1399 | return GNUNET_OK; | 1348 | return GNUNET_SYSERR; |
1400 | } | 1349 | } |
1350 | return GNUNET_OK; | ||
1351 | } | ||
1352 | |||
1353 | /** | ||
1354 | * Handle PULL REPLY message from another peer. | ||
1355 | * | ||
1356 | * @param cls Closure | ||
1357 | * @param msg The message header | ||
1358 | */ | ||
1359 | static void | ||
1360 | handle_peer_pull_reply (void *cls, | ||
1361 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) | ||
1362 | { | ||
1363 | struct GNUNET_PeerIdentity *peers; | ||
1364 | struct GNUNET_PeerIdentity *sender = cls; | ||
1365 | uint32_t i; | ||
1366 | #ifdef ENABLE_MALICIOUS | ||
1367 | struct AttackedPeer *tmp_att_peer; | ||
1368 | #endif /* ENABLE_MALICIOUS */ | ||
1401 | 1369 | ||
1370 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (sender)); | ||
1402 | 1371 | ||
1403 | #ifdef ENABLE_MALICIOUS | 1372 | #ifdef ENABLE_MALICIOUS |
1404 | // We shouldn't even receive pull replies as we're not sending | 1373 | // We shouldn't even receive pull replies as we're not sending |
1405 | if (2 == mal_type) | 1374 | if (2 == mal_type) |
1406 | { | 1375 | { |
1407 | GNUNET_CADET_receive_done (channel); | 1376 | GNUNET_CADET_receive_done (Peers_get_recv_channel (sender)); |
1408 | return GNUNET_OK; | ||
1409 | } | 1377 | } |
1410 | #endif /* ENABLE_MALICIOUS */ | 1378 | #endif /* ENABLE_MALICIOUS */ |
1411 | 1379 | ||
1412 | /* Do actual logic */ | 1380 | /* Do actual logic */ |
1413 | peers = (struct GNUNET_PeerIdentity *) &in_msg[1]; | 1381 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
1414 | 1382 | ||
1415 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1383 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1416 | "PULL REPLY received, got following %u peers:\n", | 1384 | "PULL REPLY received, got following %u peers:\n", |
1417 | ntohl (in_msg->num_peers)); | 1385 | ntohl (msg->num_peers)); |
1418 | 1386 | ||
1419 | for (i = 0 ; i < ntohl (in_msg->num_peers) ; i++) | 1387 | for (i = 0; i < ntohl (msg->num_peers); i++) |
1420 | { | 1388 | { |
1421 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1389 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1422 | "%u. %s\n", | 1390 | "%u. %s\n", |
@@ -1466,8 +1434,7 @@ handle_peer_pull_reply (void *cls, | |||
1466 | Peers_unset_peer_flag (sender, Peers_PULL_REPLY_PENDING); | 1434 | Peers_unset_peer_flag (sender, Peers_PULL_REPLY_PENDING); |
1467 | clean_peer (sender); | 1435 | clean_peer (sender); |
1468 | 1436 | ||
1469 | GNUNET_CADET_receive_done (channel); | 1437 | GNUNET_CADET_receive_done (Peers_get_recv_channel (sender)); |
1470 | return GNUNET_OK; | ||
1471 | } | 1438 | } |
1472 | 1439 | ||
1473 | 1440 | ||
@@ -2273,15 +2240,24 @@ run (void *cls, | |||
2273 | const struct GNUNET_CONFIGURATION_Handle *c, | 2240 | const struct GNUNET_CONFIGURATION_Handle *c, |
2274 | struct GNUNET_SERVICE_Handle *service) | 2241 | struct GNUNET_SERVICE_Handle *service) |
2275 | { | 2242 | { |
2276 | static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | 2243 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
2277 | {&handle_peer_check , GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, | 2244 | GNUNET_MQ_hd_fixed_size (peer_check, |
2278 | sizeof (struct GNUNET_MessageHeader)}, | 2245 | GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, |
2279 | {&handle_peer_push , GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, | 2246 | struct GNUNET_MessageHeader, |
2280 | sizeof (struct GNUNET_MessageHeader)}, | 2247 | NULL), |
2281 | {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, | 2248 | GNUNET_MQ_hd_fixed_size (peer_push, |
2282 | sizeof (struct GNUNET_MessageHeader)}, | 2249 | GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, |
2283 | {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, 0}, | 2250 | struct GNUNET_MessageHeader, |
2284 | {NULL, 0, 0} | 2251 | NULL), |
2252 | GNUNET_MQ_hd_fixed_size (peer_pull_request, | ||
2253 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, | ||
2254 | struct GNUNET_MessageHeader, | ||
2255 | NULL), | ||
2256 | GNUNET_MQ_hd_var_size (peer_pull_reply, | ||
2257 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, | ||
2258 | struct GNUNET_RPS_P2P_PullReplyMessage, | ||
2259 | NULL), | ||
2260 | GNUNET_MQ_handler_end () | ||
2285 | }; | 2261 | }; |
2286 | 2262 | ||
2287 | int size; | 2263 | int size; |
@@ -2373,21 +2349,23 @@ run (void *cls, | |||
2373 | 2349 | ||
2374 | 2350 | ||
2375 | /* Initialise cadet */ | 2351 | /* Initialise cadet */ |
2376 | cadet_handle = GNUNET_CADET_connect (cfg, | 2352 | cadet_handle = GNUNET_CADET_connect (cfg); |
2377 | cls, | ||
2378 | &cleanup_destroyed_channel, | ||
2379 | cadet_handlers); | ||
2380 | GNUNET_assert (NULL != cadet_handle); | 2353 | GNUNET_assert (NULL != cadet_handle); |
2381 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS, | 2354 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS, |
2382 | strlen (GNUNET_APPLICATION_PORT_RPS), | 2355 | strlen (GNUNET_APPLICATION_PORT_RPS), |
2383 | &port); | 2356 | &port); |
2384 | GNUNET_CADET_open_port (cadet_handle, | 2357 | cadet_port = GNUNET_CADET_open_port (cadet_handle, |
2385 | &port, | 2358 | &port, |
2386 | &Peers_handle_inbound_channel, cls); | 2359 | &Peers_handle_inbound_channel, /* Connect handler */ |
2360 | NULL, /* cls */ | ||
2361 | NULL, /* WindowSize handler */ | ||
2362 | cleanup_destroyed_channel, /* Disconnect handler */ | ||
2363 | cadet_handlers); | ||
2387 | 2364 | ||
2388 | 2365 | ||
2389 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | 2366 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); |
2390 | Peers_initialise (fn_valid_peers, cadet_handle, &own_identity); | 2367 | Peers_initialise (fn_valid_peers, cadet_handle, cleanup_destroyed_channel, |
2368 | cadet_handlers, &own_identity); | ||
2391 | GNUNET_free (fn_valid_peers); | 2369 | GNUNET_free (fn_valid_peers); |
2392 | 2370 | ||
2393 | /* Initialise sampler */ | 2371 | /* Initialise sampler */ |