aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2016-09-27 14:44:15 +0000
committerJulius Bünger <buenger@mytum.de>2016-09-27 14:44:15 +0000
commit94adb0e8c48d47e13e7319bb0fe228263b15abbf (patch)
treefe6ed0d4166cfd3ff6e71759ed7236fa07137a12 /src/rps
parentd8adc612eea2b4aa5304ac662af54538aba8c4bf (diff)
downloadgnunet-94adb0e8c48d47e13e7319bb0fe228263b15abbf.tar.gz
gnunet-94adb0e8c48d47e13e7319bb0fe228263b15abbf.zip
-fix rps service: handle client service types correctly
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-service-rps.c135
1 files changed, 77 insertions, 58 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 031997781..68c0688af 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -1123,6 +1123,33 @@ handle_client_request_cancel (void *cls,
1123 1123
1124 1124
1125/** 1125/**
1126 * @brief This function is called, when the client seeds peers.
1127 * It verifies that @a msg is well-formed.
1128 *
1129 * @param cls the closure (#ClientContext)
1130 * @param msg the message
1131 * @return #GNUNET_OK if @a msg is well-formed
1132 */
1133static int
1134check_client_seed (void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg)
1135{
1136 struct ClientContext *cli_ctx = cls;
1137 uint16_t msize = ntohs (msg->header.size);
1138 uint32_t num_peers = ntohl (msg->num_peers);
1139
1140 msize -= sizeof (struct GNUNET_RPS_CS_SeedMessage);
1141 if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
1142 (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
1143 {
1144 GNUNET_break (0);
1145 GNUNET_SERVICE_client_drop (cli_ctx->client);
1146 return GNUNET_SYSERR;
1147 }
1148 return GNUNET_OK;
1149}
1150
1151
1152/**
1126 * Handle seed from the client. 1153 * Handle seed from the client.
1127 * 1154 *
1128 * @param cls closure 1155 * @param cls closure
@@ -1131,35 +1158,18 @@ handle_client_request_cancel (void *cls,
1131 */ 1158 */
1132static void 1159static void
1133handle_client_seed (void *cls, 1160handle_client_seed (void *cls,
1134 const struct GNUNET_MessageHeader *message) 1161 const struct GNUNET_RPS_CS_SeedMessage *msg)
1135{ 1162{
1136 struct ClientContext *cli_ctx = cls; 1163 struct ClientContext *cli_ctx = cls;
1137 struct GNUNET_RPS_CS_SeedMessage *in_msg;
1138 struct GNUNET_PeerIdentity *peers; 1164 struct GNUNET_PeerIdentity *peers;
1139 uint32_t num_peers; 1165 uint32_t num_peers;
1140 uint32_t i; 1166 uint32_t i;
1141 1167
1142 if (sizeof (struct GNUNET_RPS_CS_SeedMessage) > ntohs (message->size)) 1168 num_peers = ntohl (msg->num_peers);
1143 { 1169 peers = (struct GNUNET_PeerIdentity *) &msg[1];
1144 GNUNET_SERVICE_client_drop (cli_ctx->client);
1145 GNUNET_break_op (0);
1146 return;
1147 }
1148
1149 in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message;
1150 num_peers = ntohl (in_msg->num_peers);
1151 peers = (struct GNUNET_PeerIdentity *) &in_msg[1];
1152 //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); 1170 //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
1153 //GNUNET_memcpy (peers, &in_msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity)); 1171 //GNUNET_memcpy (peers, &in_msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity));
1154 1172
1155 if ((ntohs (message->size) - sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
1156 sizeof (struct GNUNET_PeerIdentity) != num_peers)
1157 {
1158 GNUNET_break_op (0);
1159 GNUNET_SERVICE_client_drop (cli_ctx->client);
1160 return;
1161 }
1162
1163 LOG (GNUNET_ERROR_TYPE_DEBUG, 1173 LOG (GNUNET_ERROR_TYPE_DEBUG,
1164 "Client seeded peers:\n"); 1174 "Client seeded peers:\n");
1165 print_peer_list (peers, num_peers); 1175 print_peer_list (peers, num_peers);
@@ -1172,9 +1182,6 @@ handle_client_seed (void *cls,
1172 GNUNET_i2s (&peers[i])); 1182 GNUNET_i2s (&peers[i]));
1173 1183
1174 got_peer (&peers[i]); 1184 got_peer (&peers[i]);
1175
1176 //RPS_sampler_update (prot_sampler, &peers[i]);
1177 //RPS_sampler_update (client_sampler, &peers[i]);
1178 } 1185 }
1179 1186
1180 ////GNUNET_free (peers); 1187 ////GNUNET_free (peers);
@@ -1557,8 +1564,40 @@ do_round (void *cls);
1557static void 1564static void
1558do_mal_round (void *cls); 1565do_mal_round (void *cls);
1559 1566
1560
1561#ifdef ENABLE_MALICIOUS 1567#ifdef ENABLE_MALICIOUS
1568
1569
1570/**
1571 * @brief This function is called, when the client tells us to act malicious.
1572 * It verifies that @a msg is well-formed.
1573 *
1574 * @param cls the closure (#ClientContext)
1575 * @param msg the message
1576 * @return #GNUNET_OK if @a msg is well-formed
1577 */
1578static int
1579check_client_act_malicious (void *cls,
1580 const struct GNUNET_RPS_CS_ActMaliciousMessage *msg)
1581{
1582 struct ClientContext *cli_ctx = cls;
1583 uint16_t msize = ntohs (msg->header.size);
1584 uint32_t num_peers = ntohl (msg->num_peers);
1585
1586 msize -= sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage);
1587 if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) ||
1588 (msize % sizeof (struct GNUNET_PeerIdentity) != 0) )
1589 {
1590 LOG (GNUNET_ERROR_TYPE_ERROR,
1591 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
1592 ntohl (msg->num_peers),
1593 (msize / sizeof (struct GNUNET_PeerIdentity)));
1594 GNUNET_break (0);
1595 GNUNET_SERVICE_client_drop (cli_ctx->client);
1596 return GNUNET_SYSERR;
1597 }
1598 return GNUNET_OK;
1599}
1600
1562/** 1601/**
1563 * Turn RPS service to act malicious. 1602 * Turn RPS service to act malicious.
1564 * 1603 *
@@ -1568,51 +1607,29 @@ do_mal_round (void *cls);
1568 */ 1607 */
1569static void 1608static void
1570handle_client_act_malicious (void *cls, 1609handle_client_act_malicious (void *cls,
1571 const struct GNUNET_MessageHeader *msg) 1610 const struct GNUNET_RPS_CS_ActMaliciousMessage *msg)
1572{ 1611{
1573 struct ClientContext *cli_ctx = cls; 1612 struct ClientContext *cli_ctx = cls;
1574 struct GNUNET_RPS_CS_ActMaliciousMessage *in_msg;
1575 struct GNUNET_PeerIdentity *peers; 1613 struct GNUNET_PeerIdentity *peers;
1576 uint32_t num_mal_peers_sent; 1614 uint32_t num_mal_peers_sent;
1577 uint32_t num_mal_peers_old; 1615 uint32_t num_mal_peers_old;
1578 1616
1579 /* Check for protocol violation */
1580 if (sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage) > ntohs (msg->size))
1581 {
1582 GNUNET_SERVICE_client_continue (cli_ctx->client);
1583 GNUNET_break_op (0);
1584 }
1585
1586 in_msg = (struct GNUNET_RPS_CS_ActMaliciousMessage *) msg;
1587 if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) /
1588 sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers))
1589 {
1590 LOG (GNUNET_ERROR_TYPE_ERROR,
1591 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
1592 ntohl (in_msg->num_peers),
1593 (ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) /
1594 sizeof (struct GNUNET_PeerIdentity));
1595 GNUNET_SERVICE_client_continue (cli_ctx->client);
1596 GNUNET_break_op (0);
1597 }
1598
1599
1600 /* Do actual logic */ 1617 /* Do actual logic */
1601 peers = (struct GNUNET_PeerIdentity *) &msg[1]; 1618 peers = (struct GNUNET_PeerIdentity *) &msg[1];
1602 mal_type = ntohl (in_msg->type); 1619 mal_type = ntohl (msg->type);
1603 if (NULL == mal_peer_set) 1620 if (NULL == mal_peer_set)
1604 mal_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO); 1621 mal_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO);
1605 1622
1606 LOG (GNUNET_ERROR_TYPE_DEBUG, 1623 LOG (GNUNET_ERROR_TYPE_DEBUG,
1607 "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n", 1624 "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n",
1608 mal_type, 1625 mal_type,
1609 ntohl (in_msg->num_peers)); 1626 ntohl (msg->num_peers));
1610 1627
1611 if (1 == mal_type) 1628 if (1 == mal_type)
1612 { /* Try to maximise representation */ 1629 { /* Try to maximise representation */
1613 /* Add other malicious peers to those we already know */ 1630 /* Add other malicious peers to those we already know */
1614 1631
1615 num_mal_peers_sent = ntohl (in_msg->num_peers); 1632 num_mal_peers_sent = ntohl (msg->num_peers);
1616 num_mal_peers_old = num_mal_peers; 1633 num_mal_peers_old = num_mal_peers;
1617 GNUNET_array_grow (mal_peers, 1634 GNUNET_array_grow (mal_peers,
1618 num_mal_peers, 1635 num_mal_peers,
@@ -1636,7 +1653,7 @@ handle_client_act_malicious (void *cls,
1636 { /* Try to partition the network */ 1653 { /* Try to partition the network */
1637 /* Add other malicious peers to those we already know */ 1654 /* Add other malicious peers to those we already know */
1638 1655
1639 num_mal_peers_sent = ntohl (in_msg->num_peers) - 1; 1656 num_mal_peers_sent = ntohl (msg->num_peers) - 1;
1640 num_mal_peers_old = num_mal_peers; 1657 num_mal_peers_old = num_mal_peers;
1641 GNUNET_array_grow (mal_peers, 1658 GNUNET_array_grow (mal_peers,
1642 num_mal_peers, 1659 num_mal_peers,
@@ -1656,7 +1673,7 @@ handle_client_act_malicious (void *cls,
1656 1673
1657 /* Store the one attacked peer */ 1674 /* Store the one attacked peer */
1658 GNUNET_memcpy (&attacked_peer, 1675 GNUNET_memcpy (&attacked_peer,
1659 &in_msg->attacked_peer, 1676 &msg->attacked_peer,
1660 sizeof (struct GNUNET_PeerIdentity)); 1677 sizeof (struct GNUNET_PeerIdentity));
1661 /* Set the flag of the attacked peer to valid to avoid problems */ 1678 /* Set the flag of the attacked peer to valid to avoid problems */
1662 if (GNUNET_NO == Peers_check_peer_known (&attacked_peer)) 1679 if (GNUNET_NO == Peers_check_peer_known (&attacked_peer))
@@ -2227,12 +2244,14 @@ client_disconnect_cb (void *cls,
2227 2244
2228 GNUNET_assert (client == cli_ctx->client); 2245 GNUNET_assert (client == cli_ctx->client);
2229 if (NULL == client) 2246 if (NULL == client)
2230 {/* shutdown task */ 2247 {/* shutdown task - destroy all clients */
2231 while (NULL != cli_ctx_head) 2248 while (NULL != cli_ctx_head)
2232 destroy_cli_ctx (cli_ctx_head); 2249 destroy_cli_ctx (cli_ctx_head);
2233 } 2250 }
2234 else 2251 else
2235 { 2252 { /* destroy this client */
2253 LOG (GNUNET_ERROR_TYPE_DEBUG,
2254 "Client disconnected. Destroy its context.\n");
2236 destroy_cli_ctx (cli_ctx); 2255 destroy_cli_ctx (cli_ctx);
2237 } 2256 }
2238} 2257}
@@ -2421,14 +2440,14 @@ GNUNET_SERVICE_MAIN
2421 GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST_CANCEL, 2440 GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST_CANCEL,
2422 struct GNUNET_RPS_CS_RequestCancelMessage, 2441 struct GNUNET_RPS_CS_RequestCancelMessage,
2423 NULL), 2442 NULL),
2424 GNUNET_MQ_hd_fixed_size (client_seed, 2443 GNUNET_MQ_hd_var_size (client_seed,
2425 GNUNET_MESSAGE_TYPE_RPS_CS_SEED, 2444 GNUNET_MESSAGE_TYPE_RPS_CS_SEED,
2426 struct GNUNET_MessageHeader, 2445 struct GNUNET_RPS_CS_SeedMessage,
2427 NULL), 2446 NULL),
2428#ifdef ENABLE_MALICIOUS 2447#ifdef ENABLE_MALICIOUS
2429 GNUNET_MQ_hd_fixed_size (client_act_malicious, 2448 GNUNET_MQ_hd_var_size (client_act_malicious,
2430 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS, 2449 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS,
2431 struct GNUNET_MessageHeader, 2450 struct GNUNET_RPS_CS_ActMaliciousMessage,
2432 NULL), 2451 NULL),
2433#endif /* ENABLE_MALICIOUS */ 2452#endif /* ENABLE_MALICIOUS */
2434 GNUNET_MQ_handler_end()); 2453 GNUNET_MQ_handler_end());