diff options
author | Julius Bünger <buenger@mytum.de> | 2015-03-25 17:16:56 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-03-25 17:16:56 +0000 |
commit | 5cb13d5450a39d93c04a35cb52811455694d0bfd (patch) | |
tree | 51bbaa9ac6b3e4a691f03dadeac8619698432251 /src | |
parent | 4edbbc4b4a548d90ac53fe448514b6bbccee3b87 (diff) | |
download | gnunet-5cb13d5450a39d93c04a35cb52811455694d0bfd.tar.gz gnunet-5cb13d5450a39d93c04a35cb52811455694d0bfd.zip |
correct handling of act_malicious messages from client
Diffstat (limited to 'src')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 9d60ee8f5..b0551df37 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -1335,6 +1335,11 @@ handle_peer_pull_reply (void *cls, | |||
1335 | } | 1335 | } |
1336 | 1336 | ||
1337 | 1337 | ||
1338 | static void | ||
1339 | do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
1340 | |||
1341 | static void | ||
1342 | do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
1338 | 1343 | ||
1339 | 1344 | ||
1340 | #ifdef ENABLE_MALICIOUS | 1345 | #ifdef ENABLE_MALICIOUS |
@@ -1346,22 +1351,18 @@ handle_peer_pull_reply (void *cls, | |||
1346 | * @param channel_ctx The context associated with this channel | 1351 | * @param channel_ctx The context associated with this channel |
1347 | * @param msg The message header | 1352 | * @param msg The message header |
1348 | */ | 1353 | */ |
1349 | static int | 1354 | static void |
1350 | handle_peer_act_malicious (void *cls, | 1355 | handle_client_act_malicious (void *cls, |
1351 | struct GNUNET_CADET_Channel *channel, | 1356 | struct GNUNET_SERVER_Client *client, |
1352 | void **channel_ctx, | 1357 | const struct GNUNET_MessageHeader *msg) |
1353 | const struct GNUNET_MessageHeader *msg) | ||
1354 | { | 1358 | { |
1355 | struct GNUNET_RPS_CS_ActMaliciousMessage *in_msg; | 1359 | struct GNUNET_RPS_CS_ActMaliciousMessage *in_msg; |
1356 | struct GNUNET_PeerIdentity *sender; | ||
1357 | struct PeerContext *sender_ctx; | ||
1358 | struct GNUNET_PeerIdentity *peers; | 1360 | struct GNUNET_PeerIdentity *peers; |
1359 | 1361 | ||
1360 | /* Check for protocol violation */ | 1362 | /* Check for protocol violation */ |
1361 | if (sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage) > ntohs (msg->size)) | 1363 | if (sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage) > ntohs (msg->size)) |
1362 | { | 1364 | { |
1363 | GNUNET_break_op (0); | 1365 | GNUNET_break_op (0); |
1364 | return GNUNET_SYSERR; | ||
1365 | } | 1366 | } |
1366 | 1367 | ||
1367 | in_msg = (struct GNUNET_RPS_CS_ActMaliciousMessage *) msg; | 1368 | in_msg = (struct GNUNET_RPS_CS_ActMaliciousMessage *) msg; |
@@ -1374,19 +1375,6 @@ handle_peer_act_malicious (void *cls, | |||
1374 | (ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) / | 1375 | (ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) / |
1375 | sizeof (struct GNUNET_PeerIdentity)); | 1376 | sizeof (struct GNUNET_PeerIdentity)); |
1376 | GNUNET_break_op (0); | 1377 | GNUNET_break_op (0); |
1377 | return GNUNET_SYSERR; | ||
1378 | } | ||
1379 | |||
1380 | sender = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info ( | ||
1381 | (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER); | ||
1382 | // Guess simply casting isn't the nicest way... | ||
1383 | // FIXME wait for cadet to change this function | ||
1384 | sender_ctx = get_peer_ctx (peer_map, sender); | ||
1385 | |||
1386 | if (GNUNET_YES == get_peer_flag (sender_ctx, PULL_REPLY_PENDING)) | ||
1387 | { | ||
1388 | GNUNET_break_op (0); | ||
1389 | return GNUNET_OK; | ||
1390 | } | 1378 | } |
1391 | 1379 | ||
1392 | 1380 | ||
@@ -1394,9 +1382,11 @@ handle_peer_act_malicious (void *cls, | |||
1394 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 1382 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
1395 | num_mal_peers = ntohl (in_msg->num_peers); | 1383 | num_mal_peers = ntohl (in_msg->num_peers); |
1396 | mal_type = ntohl (in_msg->type); | 1384 | mal_type = ntohl (in_msg->type); |
1385 | num_attacked_peers = 0; | ||
1386 | attacked_peers = NULL; | ||
1397 | 1387 | ||
1398 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1388 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1399 | "Now acting malicious type %" PRIX32 "\n", | 1389 | "Now acting malicious type %" PRIu32 "\n", |
1400 | mal_type); | 1390 | mal_type); |
1401 | 1391 | ||
1402 | if (1 == mal_type) | 1392 | if (1 == mal_type) |
@@ -1404,7 +1394,7 @@ handle_peer_act_malicious (void *cls, | |||
1404 | num_mal_peers = ntohl (in_msg->num_peers); | 1394 | num_mal_peers = ntohl (in_msg->num_peers); |
1405 | mal_peers = GNUNET_new_array (num_mal_peers, | 1395 | mal_peers = GNUNET_new_array (num_mal_peers, |
1406 | struct GNUNET_PeerIdentity); | 1396 | struct GNUNET_PeerIdentity); |
1407 | memcpy (mal_peers, peers, num_mal_peers); | 1397 | memcpy (mal_peers, peers, num_mal_peers * sizeof (struct GNUNET_PeerIdentity)); |
1408 | 1398 | ||
1409 | /* Substitute do_round () with do_mal_round () */ | 1399 | /* Substitute do_round () with do_mal_round () */ |
1410 | GNUNET_SCHEDULER_cancel (do_round_task); | 1400 | GNUNET_SCHEDULER_cancel (do_round_task); |
@@ -1416,7 +1406,9 @@ handle_peer_act_malicious (void *cls, | |||
1416 | mal_peers = GNUNET_new_array (num_mal_peers, | 1406 | mal_peers = GNUNET_new_array (num_mal_peers, |
1417 | struct GNUNET_PeerIdentity); | 1407 | struct GNUNET_PeerIdentity); |
1418 | memcpy (mal_peers, peers, num_mal_peers); | 1408 | memcpy (mal_peers, peers, num_mal_peers); |
1419 | attacked_peer = peers[num_mal_peers]; | 1409 | |
1410 | GNUNET_array_grow (attacked_peers, num_attacked_peers, 1); | ||
1411 | memcpy (attacked_peers, &peers[num_mal_peers], 1 * sizeof (struct GNUNET_PeerIdentity)); | ||
1420 | 1412 | ||
1421 | /* Substitute do_round () with do_mal_round () */ | 1413 | /* Substitute do_round () with do_mal_round () */ |
1422 | GNUNET_SCHEDULER_cancel (do_round_task); | 1414 | GNUNET_SCHEDULER_cancel (do_round_task); |
@@ -1436,7 +1428,6 @@ handle_peer_act_malicious (void *cls, | |||
1436 | GNUNET_break (0); | 1428 | GNUNET_break (0); |
1437 | } | 1429 | } |
1438 | 1430 | ||
1439 | return GNUNET_OK; | ||
1440 | } | 1431 | } |
1441 | 1432 | ||
1442 | 1433 | ||
@@ -1448,9 +1439,27 @@ handle_peer_act_malicious (void *cls, | |||
1448 | static void | 1439 | static void |
1449 | do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1440 | do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1450 | { | 1441 | { |
1442 | uint32_t num_pushes; | ||
1443 | uint32_t i; | ||
1444 | unsigned int rand_delay; | ||
1445 | struct GNUNET_TIME_Relative half_round_interval; | ||
1446 | struct GNUNET_TIME_Relative time_next_round; | ||
1447 | |||
1451 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously.\n"); | 1448 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously.\n"); |
1452 | 1449 | ||
1453 | /* Do stuff */ | 1450 | /* Do malicious actions */ |
1451 | if (1 == mal_type) | ||
1452 | { /* Try to maximise representation */ | ||
1453 | num_pushes = min (min (push_limit, /* FIXME: attacked peer */ num_mal_peers), GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); | ||
1454 | for (i = 0 ; i < num_pushes ; i++) | ||
1455 | { /* Send PUSH to attacked peer */ | ||
1456 | //GNUNET_CONTAINER_multihashmap_iterator_create | ||
1457 | } | ||
1458 | } | ||
1459 | else if (2 == mal_type) | ||
1460 | { /* Try to partition the network */ | ||
1461 | /* Send as many pushes to attacked peer as possible */ | ||
1462 | } | ||
1454 | 1463 | ||
1455 | /* Compute random time value between .5 * round_interval and 1.5 *round_interval */ | 1464 | /* Compute random time value between .5 * round_interval and 1.5 *round_interval */ |
1456 | half_round_interval = GNUNET_TIME_relative_divide (round_interval, 2); | 1465 | half_round_interval = GNUNET_TIME_relative_divide (round_interval, 2); |
@@ -1973,9 +1982,12 @@ cleanup_channel (void *cls, | |||
1973 | rps_start (struct GNUNET_SERVER_Handle *server) | 1982 | rps_start (struct GNUNET_SERVER_Handle *server) |
1974 | { | 1983 | { |
1975 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1984 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
1976 | {&handle_client_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST, | 1985 | {&handle_client_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST, |
1977 | sizeof (struct GNUNET_RPS_CS_RequestMessage)}, | 1986 | sizeof (struct GNUNET_RPS_CS_RequestMessage)}, |
1978 | {&handle_client_seed, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_SEED, 0}, | 1987 | {&handle_client_seed, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_SEED, 0}, |
1988 | #ifdef ENABLE_MALICIOUS | ||
1989 | {&handle_client_act_malicious, NULL, GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS , 0}, | ||
1990 | #endif /* ENABLE_MALICIOUS */ | ||
1979 | {NULL, NULL, 0, 0} | 1991 | {NULL, NULL, 0, 0} |
1980 | }; | 1992 | }; |
1981 | 1993 | ||
@@ -2069,9 +2081,6 @@ run (void *cls, | |||
2069 | {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, | 2081 | {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, |
2070 | sizeof (struct GNUNET_MessageHeader)}, | 2082 | sizeof (struct GNUNET_MessageHeader)}, |
2071 | {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0}, | 2083 | {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0}, |
2072 | #if ENABLE_MALICIOUS | ||
2073 | {&handle_peer_act_malicious, GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS , 0}, | ||
2074 | #endif /* ENABLE_MALICIOUS */ | ||
2075 | {NULL, 0, 0} | 2084 | {NULL, 0, 0} |
2076 | }; | 2085 | }; |
2077 | 2086 | ||