From 10f9fc86e88425a19e8d7fbf37323a9881933b6d Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Thu, 21 Jun 2018 04:14:14 -0700 Subject: [PATCH] skip directories and .DS_Store on MacOS, remove some dead code --- llarp/nodedb.cpp | 75 +++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index c7b9adb0d..2db9e6fd9 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -47,6 +47,24 @@ struct llarp_nodedb return entries.find(pk) != entries.end(); } +/* + bool + Has(const byte_t *pk) + { + llarp::PubKey test(pk); + auto itr = this->entries.begin(); + while(itr != this->entries.end()) + { + llarp::Info("Has byte_t [", test.size(), "] vs [", itr->first.size(), "]"); + if (memcmp(test.data(), itr->first.data(), 32) == 0) { + llarp::Info("Match"); + } + itr++; + } + return entries.find(pk) != entries.end(); + } +*/ + bool pubKeyExists(llarp_rc *rc) { @@ -167,8 +185,9 @@ struct llarp_nodedb auto itr = i.begin(); while(itr != itr.end()) { - if(loadfile(*itr)) + if (fs::is_regular_file(itr->symlink_status()) && loadfile(*itr)) sz++; + ++itr; } return sz; @@ -177,49 +196,26 @@ struct llarp_nodedb bool loadfile(const fs::path &fpath) { +#if __APPLE__ && __MACH__ + // skip .DS_Store files + if (strstr(fpath.c_str(), ".DS_Store") != 0) { + return false; + } +#endif llarp_rc *rc = llarp_rc_read(fpath.c_str()); - if (rc) + if (!rc) { - if(llarp_rc_verify_sig(crypto, rc)) - { - llarp::PubKey pk(rc->pubkey); - entries[pk] = *rc; - return true; - } + llarp::Error("Signature read failed", fpath); + return false; } - /* - std::ifstream f(fpath, std::ios::binary); - if(!f.is_open()) - return false; - - byte_t tmp[MAX_RC_SIZE]; - - auto buf = llarp::StackBuffer< decltype(tmp) >(tmp); - f.seekg(0, std::ios::end); - size_t sz = f.tellg(); - f.seekg(0, std::ios::beg); - - if(sz > buf.sz) - return false; - - // TODO: error checking - f.read((char *)buf.base, sz); - buf.sz = sz; - - llarp_rc rc; - llarp::Zero(&rc, sizeof(llarp_rc)); - if(llarp_rc_bdecode(&rc, &buf)) + if(!llarp_rc_verify_sig(crypto, rc)) { - if(llarp_rc_verify_sig(crypto, &rc)) - { - llarp::PubKey pk(rc.pubkey); - entries[pk] = rc; - return true; - } + llarp::Error("Signature verify failed", fpath); + return false; } - llarp_rc_free(&rc); - */ - return false; + llarp::PubKey pk(rc->pubkey); + entries[pk] = *rc; + return true; } bool iterate() { @@ -414,6 +410,7 @@ llarp_nodedb_async_load_rc(struct llarp_async_load_rc *job) struct llarp_rc * llarp_nodedb_get_rc(struct llarp_nodedb *n, const byte_t *pk) { + //llarp::Info("llarp_nodedb_get_rc [", pk, "]"); if(n->Has(pk)) return n->getRC(pk); else