aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-02-17 03:38:37 +0000
committerJulius Bünger <buenger@mytum.de>2015-02-17 03:38:37 +0000
commit9678cbd3c4826dda99eb5aff900bee602f5b25ec (patch)
treeb3cdcd57a7f19bee6751458809ebd8793dcc8ed0 /src
parentf4215c5cfa1a76c75aee6ceff1da057f2fa20c2a (diff)
downloadgnunet-9678cbd3c4826dda99eb5aff900bee602f5b25ec.tar.gz
gnunet-9678cbd3c4826dda99eb5aff900bee602f5b25ec.zip
- fixed uninitialised memory, logic
Diffstat (limited to 'src')
-rw-r--r--src/rps/gnunet-service-rps.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 489e415c6..0ec80d3a4 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -454,7 +454,6 @@ rem_from_list (struct GNUNET_PeerIdentity **peer_list,
454 "Removing peer %s from list at %p\n", 454 "Removing peer %s from list at %p\n",
455 GNUNET_i2s (peer), 455 GNUNET_i2s (peer),
456 tmp); 456 tmp);
457 print_peer_list (tmp, *list_size);
458 457
459 for ( i = 0 ; i < *list_size ; i++ ) 458 for ( i = 0 ; i < *list_size ; i++ )
460 { 459 {
@@ -556,6 +555,8 @@ get_peer_ctx (struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
556 ctx->recv_channel = NULL; 555 ctx->recv_channel = NULL;
557 ctx->outstanding_ops = NULL; 556 ctx->outstanding_ops = NULL;
558 ctx->num_outstanding_ops = 0; 557 ctx->num_outstanding_ops = 0;
558 ctx->is_live_task = NULL;
559 ctx->peer_id = *peer;
559 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, 560 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx,
560 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 561 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
561 } 562 }
@@ -596,7 +597,7 @@ peer_is_live (struct PeerContext *peer_ctx)
596 { /* Call outstanding operations */ 597 { /* Call outstanding operations */
597 unsigned int i; 598 unsigned int i;
598 599
599 for ( i = 0 ; i < peer_ctx->num_outstanding_ops ; i++ ) 600 for (i = 0 ; i < peer_ctx->num_outstanding_ops ; i++)
600 peer_ctx->outstanding_ops[i].op (peer_ctx->outstanding_ops[i].op_cls, peer); 601 peer_ctx->outstanding_ops[i].op (peer_ctx->outstanding_ops[i].op_cls, peer);
601 GNUNET_array_grow (peer_ctx->outstanding_ops, peer_ctx->num_outstanding_ops, 0); 602 GNUNET_array_grow (peer_ctx->outstanding_ops, peer_ctx->num_outstanding_ops, 0);
602 } 603 }
@@ -658,6 +659,7 @@ get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
658 /* If we don't know whether peer is live, 659 /* If we don't know whether peer is live,
659 * get notified when we know it is live. */ 660 * get notified when we know it is live. */
660 if (GNUNET_YES != get_peer_flag (ctx, VALID) 661 if (GNUNET_YES != get_peer_flag (ctx, VALID)
662 && NULL != ctx->is_live_task
661 && NULL == ctx->recv_channel 663 && NULL == ctx->recv_channel
662 && NULL == ctx->is_live_task) 664 && NULL == ctx->is_live_task)
663 { 665 {
@@ -806,6 +808,9 @@ insert_in_gossip_list_scheduled (const struct PeerContext *peer_ctx)
806 void 808 void
807insert_in_sampler (void *cls, const struct GNUNET_PeerIdentity *peer) 809insert_in_sampler (void *cls, const struct GNUNET_PeerIdentity *peer)
808{ 810{
811 LOG (GNUNET_ERROR_TYPE_DEBUG,
812 "Updating samplers with peer %s from insert_in_sampler()\n",
813 GNUNET_i2s (peer));
809 RPS_sampler_update (prot_sampler, peer); 814 RPS_sampler_update (prot_sampler, peer);
810 RPS_sampler_update (client_sampler, peer); 815 RPS_sampler_update (client_sampler, peer);
811} 816}
@@ -1066,7 +1071,7 @@ handle_client_seed (void *cls,
1066 { 1071 {
1067 GNUNET_break_op (0); 1072 GNUNET_break_op (0);
1068 GNUNET_SERVER_receive_done (client, 1073 GNUNET_SERVER_receive_done (client,
1069 GNUNET_SYSERR); 1074 GNUNET_SYSERR);
1070 } 1075 }
1071 in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message; 1076 in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message;
1072 if ((ntohs (message->size) - sizeof (struct GNUNET_RPS_CS_SeedMessage)) / 1077 if ((ntohs (message->size) - sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
@@ -1074,13 +1079,20 @@ handle_client_seed (void *cls,
1074 { 1079 {
1075 GNUNET_break_op (0); 1080 GNUNET_break_op (0);
1076 GNUNET_SERVER_receive_done (client, 1081 GNUNET_SERVER_receive_done (client,
1077 GNUNET_SYSERR); 1082 GNUNET_SYSERR);
1078 } 1083 }
1079 1084
1080 in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message; 1085 in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message;
1081 peers = (struct GNUNET_PeerIdentity *) &message[1]; 1086 peers = (struct GNUNET_PeerIdentity *) &message[1];
1082 1087
1088 LOG (GNUNET_ERROR_TYPE_DEBUG,
1089 "Client seeded peers:\n");
1090 print_peer_list (peers, ntohl (in_msg->num_peers));
1091
1083 for ( i = 0 ; i < ntohl (in_msg->num_peers) ; i++ ) 1092 for ( i = 0 ; i < ntohl (in_msg->num_peers) ; i++ )
1093 LOG (GNUNET_ERROR_TYPE_DEBUG,
1094 "Updating samplers with seed %" PRIX32 ": %s\n",
1095 GNUNET_i2s (&peers[i]));
1084 RPS_sampler_update (prot_sampler, &peers[i]); 1096 RPS_sampler_update (prot_sampler, &peers[i]);
1085 RPS_sampler_update (client_sampler, &peers[i]); 1097 RPS_sampler_update (client_sampler, &peers[i]);
1086 1098
@@ -1427,6 +1439,9 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1427 /* Update samplers */ 1439 /* Update samplers */
1428 for ( i = 0 ; i < push_list_size ; i++ ) 1440 for ( i = 0 ; i < push_list_size ; i++ )
1429 { 1441 {
1442 LOG (GNUNET_ERROR_TYPE_DEBUG,
1443 "Updating with peer %s from push list\n",
1444 GNUNET_i2s (&push_list[i]));
1430 RPS_sampler_update (prot_sampler, &push_list[i]); 1445 RPS_sampler_update (prot_sampler, &push_list[i]);
1431 RPS_sampler_update (client_sampler, &push_list[i]); 1446 RPS_sampler_update (client_sampler, &push_list[i]);
1432 // TODO set in_flag? 1447 // TODO set in_flag?
@@ -1434,6 +1449,9 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1434 1449
1435 for ( i = 0 ; i < pull_list_size ; i++ ) 1450 for ( i = 0 ; i < pull_list_size ; i++ )
1436 { 1451 {
1452 LOG (GNUNET_ERROR_TYPE_DEBUG,
1453 "Updating with peer %s from pull list\n",
1454 GNUNET_i2s (&pull_list[i]));
1437 RPS_sampler_update (prot_sampler, &push_list[i]); 1455 RPS_sampler_update (prot_sampler, &push_list[i]);
1438 RPS_sampler_update (client_sampler, &push_list[i]); 1456 RPS_sampler_update (client_sampler, &push_list[i]);
1439 // TODO set in_flag? 1457 // TODO set in_flag?
@@ -1586,22 +1604,21 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1586 1604
1587 send = peer_ctx->send_channel; 1605 send = peer_ctx->send_channel;
1588 peer_ctx->send_channel = NULL; 1606 peer_ctx->send_channel = NULL;
1589 recv = peer_ctx->send_channel;
1590 peer_ctx->recv_channel = NULL;
1591
1592 if (NULL != send 1607 if (NULL != send
1593 && channel != send) 1608 && channel != send)
1594 { 1609 {
1595 GNUNET_CADET_channel_destroy (send); 1610 GNUNET_CADET_channel_destroy (send);
1596 } 1611 }
1597 1612
1613 recv = peer_ctx->send_channel;
1614 peer_ctx->recv_channel = NULL;
1598 if (NULL != recv 1615 if (NULL != recv
1599 && channel != recv) 1616 && channel != recv)
1600 { 1617 {
1601 GNUNET_CADET_channel_destroy (recv); 1618 GNUNET_CADET_channel_destroy (recv);
1602 } 1619 }
1603 1620
1604 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_remove_all (peer_map, key)) 1621 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, key))
1605 LOG (GNUNET_ERROR_TYPE_WARNING, "removing peer from peer_map failed\n"); 1622 LOG (GNUNET_ERROR_TYPE_WARNING, "removing peer from peer_map failed\n");
1606 else 1623 else
1607 GNUNET_free (peer_ctx); 1624 GNUNET_free (peer_ctx);
@@ -1641,6 +1658,9 @@ shutdown_task (void *cls,
1641 GNUNET_CADET_disconnect (cadet_handle); 1658 GNUNET_CADET_disconnect (cadet_handle);
1642 RPS_sampler_destroy (prot_sampler); 1659 RPS_sampler_destroy (prot_sampler);
1643 RPS_sampler_destroy (client_sampler); 1660 RPS_sampler_destroy (client_sampler);
1661 LOG (GNUNET_ERROR_TYPE_DEBUG,
1662 "Size of the peermap: %u\n",
1663 GNUNET_CONTAINER_multipeermap_size (peer_map));
1644 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (peer_map)); 1664 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (peer_map));
1645 GNUNET_CONTAINER_multipeermap_destroy (peer_map); 1665 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
1646 GNUNET_array_grow (gossip_list, gossip_list_size, 0); 1666 GNUNET_array_grow (gossip_list, gossip_list_size, 0);
@@ -1679,16 +1699,18 @@ handle_inbound_channel (void *cls,
1679 enum GNUNET_CADET_ChannelOption options) 1699 enum GNUNET_CADET_ChannelOption options)
1680{ 1700{
1681 struct PeerContext *peer_ctx; 1701 struct PeerContext *peer_ctx;
1702 struct GNUNET_PeerIdentity peer;
1682 1703
1704 peer = *initiator;
1683 LOG (GNUNET_ERROR_TYPE_DEBUG, 1705 LOG (GNUNET_ERROR_TYPE_DEBUG,
1684 "New channel was established to us (Peer %s).\n", 1706 "New channel was established to us (Peer %s).\n",
1685 GNUNET_i2s (initiator)); 1707 GNUNET_i2s (&peer));
1686 1708
1687 GNUNET_assert (NULL != channel); 1709 GNUNET_assert (NULL != channel);
1688 1710
1689 // we might not even store the recv_channel 1711 // we might not even store the recv_channel
1690 1712
1691 peer_ctx = get_peer_ctx (peer_map, initiator); 1713 peer_ctx = get_peer_ctx (peer_map, &peer);
1692 // FIXME what do we do if a channel is established twice? 1714 // FIXME what do we do if a channel is established twice?
1693 // overwrite? Clean old channel? ...? 1715 // overwrite? Clean old channel? ...?
1694 //if (NULL != peer_ctx->recv_channel) 1716 //if (NULL != peer_ctx->recv_channel)
@@ -1699,7 +1721,7 @@ handle_inbound_channel (void *cls,
1699 1721
1700 peer_ctx->mq = NULL; 1722 peer_ctx->mq = NULL;
1701 1723
1702 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, initiator, peer_ctx, 1724 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, &peer, peer_ctx,
1703 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 1725 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1704 1726
1705 peer_is_live (peer_ctx); 1727 peer_is_live (peer_ctx);