# # # patch "ChangeLog" # from [f3678f17bb1983062e4ca586b5a01a9ebfd6933a] # to [a40995c268dcd6a4f4165982ccd7814bf53b9d85] # # patch "merkle_tree.cc" # from [7892d63a6614ece8b94d54e8674688eeb9dea008] # to [0e353f8460c079b618906210fb3abb23fc550944] # # patch "merkle_tree.hh" # from [92d813eec1d4aedec4a8f4aba15cb333372032bb] # to [1c8305b2f3e3d1e29742113f7f989c61c37487bd] # # patch "refiner.cc" # from [fc755a9526c0d0abac8c91375e05800b9983112d] # to [e2e2a951c54476c717d83d4429647733f46b6aeb] # ============================================================ --- ChangeLog f3678f17bb1983062e4ca586b5a01a9ebfd6933a +++ ChangeLog a40995c268dcd6a4f4165982ccd7814bf53b9d85 @@ -1,3 +1,11 @@ +2006-01-18 Timothy Brownawell + + * merkle_tree.{cc,hh}: Add a locate_item() function to find the + node and slot in a merkle_table that a given item is in. + * refiner.cc (refiner::process_refinement_command): If they have + a leaf and we have a subtree then if their leaf is in our subtree, + we need to tell them. + 2006-01-15 Richard Levitte * po/sv.po: Almost all translations done. I've left a few for ============================================================ --- merkle_tree.cc 7892d63a6614ece8b94d54e8674688eeb9dea008 +++ merkle_tree.cc 0e353f8460c079b618906210fb3abb23fc550944 @@ -411,7 +411,43 @@ } } +bool +locate_item(merkle_table & table, + id const & val, + size_t & slotnum, + merkle_ptr & mp) +{ + mp.reset(); + boost::dynamic_bitset pref; + for (size_t l = 0; l < constants::merkle_num_tree_levels; ++l) + { + pick_slot_and_prefix_for_value(val, l, slotnum, pref); + ostringstream oss; + to_block_range(pref, ostream_iterator(oss)); + prefix rawpref(oss.str()); + + merkle_table::const_iterator i = table.find(make_pair(rawpref, l)); + if (i == table.end() || + i->second->get_slot_state(slotnum) == empty_state) + return false; + + if (i->second->get_slot_state(slotnum) == leaf_state) + { + id slotval; + i->second->get_raw_slot(slotnum, slotval); + if (slotval == val) + { + mp = i->second; + return true; + } + else + return false; + } + } + return false; +} + void insert_into_merkle_tree(merkle_table & tab, netcmd_item_type type, ============================================================ --- merkle_tree.hh 92d813eec1d4aedec4a8f4aba15cb333372032bb +++ merkle_tree.hh 1c8305b2f3e3d1e29742113f7f989c61c37487bd @@ -92,10 +92,18 @@ std::string raw_sha1(std::string const & in); + +bool +locate_item(merkle_table & table, + id const & val, + size_t & slotnum, + merkle_ptr & mp); + + void -pick_slot_and_prefix_for_value(id const & val, - size_t level, - size_t & slotnum, +pick_slot_and_prefix_for_value(id const & val, + size_t level, + size_t & slotnum, boost::dynamic_bitset & pref); // Collect the items inside a subtree. ============================================================ --- refiner.cc fc755a9526c0d0abac8c91375e05800b9983112d +++ refiner.cc e2e2a951c54476c717d83d4429647733f46b6aeb @@ -221,7 +221,23 @@ { // Note any leaves they have. if (their_node.get_slot_state(slot) == leaf_state) - note_item_in_peer(their_node, slot); + { + note_item_in_peer(their_node, slot); + // If we have their leaf somewhere in our subtree, + // we need to tell them. + if (our_node->get_slot_state(slot) == subtree_state) + { + id their_slotval; + their_node.get_raw_slot(slot, their_slotval); + size_t snum; + merkle_ptr mp; + if (locate_item(table, their_slotval, snum, mp)) + { + cb.queue_refine_cmd(refinement_query, *mp); + ++queries_in_flight; + } + } + } // Compare any subtrees, if we both have subtrees. if (our_node->get_slot_state(slot) == subtree_state