From 6c3a9191dc718d31bc250b7ab10844adeee831dd Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Tue, 10 Mar 2015 12:20:25 +0000 Subject: - several minor fixes --- .gitignore | 1 + src/rps/gnunet-service-rps.c | 22 +++++++++++++++------- src/rps/rps.h | 16 ++++++++-------- src/rps/rps_api.c | 8 ++------ src/rps/test_rps.conf | 3 ++- src/rps/test_rps_malicious_1.c | 5 ++++- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 9755bb9a7..1f0941569 100644 --- a/.gitignore +++ b/.gitignore @@ -1004,6 +1004,7 @@ # /src/rps/ /src/rps/rps.conf /src/rps/test_rps_multipeer +/src/rps/test_rps_malicious* /src/rps/Makefile.in /src/rps/Makefile /src/rps/.deps diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 923540db0..4e9f795c3 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -379,7 +379,7 @@ static uint32_t num_mal_peers; /** * If type is 2 this is the attacked peer */ -struct struct GNUNET_PeerIdentity attacked_peer; +static struct GNUNET_PeerIdentity attacked_peer; #endif /* ENABLE_MALICIOUS */ @@ -1057,7 +1057,7 @@ handle_client_request (void *cls, msg = (struct GNUNET_RPS_CS_RequestMessage *) message; num_peers = ntohl (msg->num_peers); - size_needed = sizeof (struct GNUNET_RPS_CS_ReplyMessage) + + size_needed = sizeof (struct GNUNET_RPS_CS_RequestMessage) + num_peers * sizeof (struct GNUNET_PeerIdentity); if (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed) @@ -1303,7 +1303,7 @@ handle_peer_pull_reply (void *cls, || NULL != peer_ctx->recv_channel) { if (GNUNET_NO == in_arr (pull_list, pull_list_size, &peers[i]) - && GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peers[i])) + && 0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peers[i])) GNUNET_array_append (pull_list, pull_list_size, peers[i]); } else if (GNUNET_NO == insert_in_pull_list_scheduled (peer_ctx)) @@ -1339,12 +1339,13 @@ handle_peer_act_malicious (void *cls, void **channel_ctx, const struct GNUNET_MessageHeader *msg) { + struct GNUNET_RPS_CS_ActMaliciousMessage *in_msg; + struct GNUNET_PeerIdentity *sender; + struct PeerContext *sender_ctx; struct GNUNET_PeerIdentity *peers; - LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REPLY received\n"); - /* Check for protocol violation */ - if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size)) + if (sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage) > ntohs (msg->size)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -1375,11 +1376,16 @@ handle_peer_act_malicious (void *cls, return GNUNET_OK; } + /* Do actual logic */ peers = (struct GNUNET_PeerIdentity *) &msg[1]; - num_peers = ntohl (in_msg->num_peers); + num_mal_peers = ntohl (in_msg->num_peers); mal_type = ntohl (in_msg->type); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Now acting malicious type %" PRIX32 "\n", + mal_type); + if (1 == mal_type) { /* Try to maximise representation */ num_mal_peers = ntohl (in_msg->num_peers); @@ -1395,6 +1401,8 @@ handle_peer_act_malicious (void *cls, memcpy (mal_peers, peers, num_mal_peers); attacked_peer = peers[num_mal_peers]; } + + return GNUNET_OK; } #endif /* ENABLE_MALICIOUS */ diff --git a/src/rps/rps.h b/src/rps/rps.h index eace8d5f1..0fbd2fb60 100644 --- a/src/rps/rps.h +++ b/src/rps/rps.h @@ -24,6 +24,7 @@ */ #include "gnunet_rps_service.h" +//#define ENABLE_MALICIOUS 1 /** * Mesh port used by RPS. @@ -71,16 +72,15 @@ struct GNUNET_RPS_CS_RequestMessage */ struct GNUNET_MessageHeader header; - /** - * Number of random peer requested - */ - uint32_t num_peers GNUNET_PACKED; - /** * Identifyer of the message. */ uint64_t n GNUNET_PACKED; + /** + * Number of random peer requested + */ + uint32_t num_peers GNUNET_PACKED; }; /** @@ -101,7 +101,7 @@ struct GNUNET_RPS_CS_ReplyMessage /** * Number of random peer replied */ - uint64_t num_peers GNUNET_PACKED; + uint32_t num_peers GNUNET_PACKED; /* Followed by num_peers * GNUNET_PeerIdentity */ }; @@ -119,7 +119,7 @@ struct GNUNET_RPS_CS_SeedMessage /** * Number of peers */ - uint64_t num_peers GNUNET_PACKED; + uint32_t num_peers GNUNET_PACKED; /* Followed by num_peers * GNUNET_PeerIdentity */ }; @@ -147,7 +147,7 @@ struct GNUNET_RPS_CS_ActMaliciousMessage /** * Number of peers */ - uint64_t num_peers GNUNET_PACKED; + uint32_t num_peers GNUNET_PACKED; /* Followed by num_peers * GNUNET_PeerIdentity */ }; diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 30f0a75c5..91612c2f7 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c @@ -128,18 +128,14 @@ handle_reply (void *cls, const struct GNUNET_MessageHeader *message) { struct GNUNET_RPS_CS_ReplyMessage *msg; - //struct cb_cls_pack *pack; - //struct GNUNET_RPS_Handle *h; struct GNUNET_PeerIdentity *peers; struct GNUNET_RPS_Request_Handle *rh; /* Give the peers back */ msg = (struct GNUNET_RPS_CS_ReplyMessage *) message; - //pack = (struct cb_cls_pack *) cls; - //h = (struct GNUNET_RPS_Handle *) cls; peers = (struct GNUNET_PeerIdentity *) &msg[1]; rh = &req_handlers[msg->n]; - rh->ready_cb((rh)->ready_cb_cls, msg->num_peers, peers); + rh->ready_cb((rh)->ready_cb_cls, msg->num_peers, peers); // FIXME? ntohl () /* Disconnect */ //GNUNET_CLIENT_disconnect(pack->service_conn); @@ -270,7 +266,7 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, { ev = GNUNET_MQ_msg_extra (msg, num_peers_max * sizeof (struct GNUNET_PeerIdentity), GNUNET_MESSAGE_TYPE_RPS_CS_SEED); - msg->num_peers = ntohl (num_peers_max); + msg->num_peers = htonl (num_peers_max); memcpy (&msg[1], tmp_peer_pointer, num_peers_max * sizeof (struct GNUNET_PeerIdentity)); GNUNET_MQ_send (h->mq, ev); diff --git a/src/rps/test_rps.conf b/src/rps/test_rps.conf index 9db6711ea..45f62133a 100644 --- a/src/rps/test_rps.conf +++ b/src/rps/test_rps.conf @@ -23,7 +23,8 @@ HOSTNAME = localhost OPERATION_TIMEOUT = 60 s MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 1 -OVERLAY_TOPOLOGY = CLIQUE +#OVERLAY_TOPOLOGY = CLIQUE +OVERLAY_TOPOLOGY = SMALL_WORLD SCALE_FREE_TOPOLOGY_CAP = OVERLAY_RANDOM_LINKS = 5 diff --git a/src/rps/test_rps_malicious_1.c b/src/rps/test_rps_malicious_1.c index 304e46973..a30607d87 100644 --- a/src/rps/test_rps_malicious_1.c +++ b/src/rps/test_rps_malicious_1.c @@ -242,8 +242,11 @@ rps_connect_adapter (void *cls, h = GNUNET_RPS_connect (cfg); #if ENABLE_MALICIOUS + GNUNET_assert (1 >= portion + && 0 < portion); + num_mal_peers = round (portion * NUM_PEERS); - GNUNET_RPS_act_malicious (h, htonl (1), htonl (num_mal_peers), rps_peer_ids); + GNUNET_RPS_act_malicious (h, htonl (1), num_mal_peers, rps_peer_ids); #endif /* ENABLE_MALICIOUS */ return h; -- cgit v1.2.3