# # patch "ChangeLog" # from [cf64a1b3819ad5cc8319d99b94c1f873ff301acc] # to [a1e0648b11c4c0ce78ae51623480812edf30b7b2] # # patch "database.cc" # from [67dcca6acbccf335730ae029cadfde6adf7a67a5] # to [ce32421c060f79d8de74419e4d9249fee7da236b] # # patch "database.hh" # from [c908a66fe8da7740c8fe9920cf5e95def4334c71] # to [dc62f8b1975f2884f63949fd701072a409ce0740] # # patch "merkle_tree.cc" # from [618189095f626048644ebf41a3054d62d52c9775] # to [f296a2fde2b8f78c445e8c0bb2c466a78cf1238a] # # patch "merkle_tree.hh" # from [aa4d5bed0d7dee09fd72c2068c626061c30a6937] # to [b21803ec30a7332f483ca4fa796317f8f9d1c36f] # # patch "netsync.cc" # from [4445407943d97f20331f74dcd0caaeb384e24bce] # to [268b4567f362e2781c0bd6ed5c29ec009928700b] # ======================================================================== --- ChangeLog cf64a1b3819ad5cc8319d99b94c1f873ff301acc +++ ChangeLog a1e0648b11c4c0ce78ae51623480812edf30b7b2 @@ -1,3 +1,11 @@ +2005-10-10 Matt Johnston + + * netsync.cc, database.{cc,hh}: don't include unwanted branch + certs when building the merkle tree. + * merkle.hh: add variant of insert_into_merkle_tree + taking non-raw id. + * markle.cc: comment out unused bits + 2005-10-10 Nathaniel Smith * cert.{cc,hh} (get_user_key): New function, replacing ======================================================================== --- database.cc 67dcca6acbccf335730ae029cadfde6adf7a67a5 +++ database.cc ce32421c060f79d8de74419e4d9249fee7da236b @@ -1748,13 +1748,13 @@ put_cert(cert.inner(), "revision_certs"); } -void database::get_revision_cert_index(std::vector< std::pair, +void database::get_revision_cert_nobranch_index(std::vector< std::pair, std::pair > > & idx) { results res; fetch(res, 3, any_rows, "SELECT hash, id, keypair " - "FROM 'revision_certs'"); + "FROM 'revision_certs' WHERE name != 'branch'"); idx.clear(); idx.reserve(res.size()); ======================================================================== --- database.hh c908a66fe8da7740c8fe9920cf5e95def4334c71 +++ database.hh dc62f8b1975f2884f63949fd701072a409ce0740 @@ -353,7 +353,7 @@ void put_revision_cert(revision const & cert); // this variant has to be rather coarse and fast, for netsync's use - void get_revision_cert_index(std::vector< std::pair, + void get_revision_cert_nobranch_index(std::vector< std::pair, std::pair > > & idx); void get_revision_certs(std::vector< revision > & certs); ======================================================================== --- merkle_tree.cc 618189095f626048644ebf41a3054d62d52c9775 +++ merkle_tree.cc f296a2fde2b8f78c445e8c0bb2c466a78cf1238a @@ -395,8 +395,8 @@ I(constants::merkle_fanout_bits * (level + 1) <= constants::merkle_hash_length_in_bits); - hexenc hleaf; - encode_hexenc(leaf, hleaf); + //hexenc hleaf; + //encode_hexenc(leaf, hleaf); size_t slotnum; dynamic_bitset pref; ======================================================================== --- merkle_tree.hh aa4d5bed0d7dee09fd72c2068c626061c30a6937 +++ merkle_tree.hh b21803ec30a7332f483ca4fa796317f8f9d1c36f @@ -13,6 +13,7 @@ #include "app_state.hh" #include "numeric_vocab.hh" #include "vocab.hh" +#include "transforms.hh" // this file contains data structures and functions for managing merkle // trees. a merkle tree is a general construction whereby a range of K data @@ -105,6 +106,18 @@ id const & leaf, size_t level); +inline void +insert_into_merkle_tree(merkle_table & tab, + netcmd_item_type type, + bool live_p, + hexenc const & hex_leaf, + size_t level) +{ + id leaf; + decode_hexenc(hex_leaf, leaf); + insert_into_merkle_tree(tab, type, live_p, leaf, level); +} + // recalculates the hashes in the given tree. must be called after // insert_into_merkle_tree, and before using tree (but you can batch up // multiple calls to insert_into_merkle_tree and then only call this once). ======================================================================== --- netsync.cc 4445407943d97f20331f74dcd0caaeb384e24bce +++ netsync.cc 268b4567f362e2781c0bd6ed5c29ec009928700b @@ -3496,10 +3496,17 @@ base64 encoded_name; encode_base64(cert_value(names[i]),encoded_name); app.db.get_revision_certs(branch_cert_name, encoded_name, certs); - for (size_t j = 0; j < certs.size(); ++j) + for (vector< revision >::const_iterator j = certs.begin(); + j != certs.end(); j++) { - insert_with_parents(revision_id(idx(certs,j).inner().ident), + insert_with_parents(revision_id(j->inner().ident), revision_ids, app, revisions_ticker); + // branch certs go in here, others later on + hexenc hash; + cert_hash_code(j->inner(), hash); + insert_into_merkle_tree(*ctab, cert_item, true, hash, 0); + if (inserted_keys.find(j->inner().key) == inserted_keys.end()) + inserted_keys.insert(j->inner().key); } } } @@ -3528,48 +3535,47 @@ I(j != epochs.end()); epoch_id eid; epoch_hash_code(j->first, j->second, eid); - id raw_hash; - decode_hexenc(eid.inner(), raw_hash); - insert_into_merkle_tree(*etab, epoch_item, true, raw_hash(), 0); + insert_into_merkle_tree(*etab, epoch_item, true, eid.inner(), 0); } } - typedef std::vector< std::pair, - std::pair > > cert_idx; - - cert_idx idx; - // this also gets *all* certs, needed? - app.db.get_revision_cert_index(idx); - - // insert all certs and keys reachable via these revisions, - // except for branch certs that don't match the masks (since the other - // side will just discard them anyway) - for (cert_idx::const_iterator i = idx.begin(); i != idx.end(); ++i) + { + typedef std::vector< std::pair, + std::pair > > cert_idx; + + cert_idx idx; + app.db.get_revision_cert_nobranch_index(idx); + + // insert all non-branch certs reachable via these revisions + // (branch certs were inserted earlier) + for (cert_idx::const_iterator i = idx.begin(); i != idx.end(); ++i) + { + hexenc const & hash = i->first; + revision_id const & ident = i->second.first; + rsa_keypair_id const & key = i->second.second; + + if (revision_ids.find(ident) == revision_ids.end()) + continue; + + insert_into_merkle_tree(*ctab, cert_item, true, hash, 0); + ++certs_ticker; + if (inserted_keys.find(key) == inserted_keys.end()) + inserted_keys.insert(key); + } + } + + // insert all the keys + for (set::const_iterator key = inserted_keys.begin(); + key != inserted_keys.end(); key++) { - hexenc const & hash = i->first; - revision_id const & ident = i->second.first; - rsa_keypair_id const & key = i->second.second; - - if (revision_ids.find(ident) == revision_ids.end()) - continue; - - id raw_hash; - decode_hexenc(hash, raw_hash); - insert_into_merkle_tree(*ctab, cert_item, true, raw_hash(), 0); - ++certs_ticker; - if (inserted_keys.find(key) == inserted_keys.end()) + if (app.db.public_key_exists(*key)) { - if (app.db.public_key_exists(key)) - { - base64 pub_encoded; - app.db.get_key(key, pub_encoded); - hexenc keyhash; - key_hash_code(key, pub_encoded, keyhash); - decode_hexenc(keyhash, raw_hash); - insert_into_merkle_tree(*ktab, key_item, true, raw_hash(), 0); - ++keys_ticker; - } - inserted_keys.insert(key); + base64 pub_encoded; + app.db.get_key(*key, pub_encoded); + hexenc keyhash; + key_hash_code(*key, pub_encoded, keyhash); + insert_into_merkle_tree(*ktab, key_item, true, keyhash, 0); + ++keys_ticker; } }