mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
Remove dead code in llarp_nodedb::Insert()
This commit is contained in:
parent
eadfeefafc
commit
702c130020
|
@ -149,46 +149,17 @@ llarp_nodedb::UpdateAsyncIfNewer(llarp::RouterContact rc,
|
|||
return false;
|
||||
}
|
||||
|
||||
/// insert and write to disk
|
||||
/// insert
|
||||
bool
|
||||
llarp_nodedb::Insert(const llarp::RouterContact &rc, bool writeToDisk)
|
||||
llarp_nodedb::Insert(const llarp::RouterContact &rc)
|
||||
{
|
||||
if(writeToDisk)
|
||||
{
|
||||
std::array< byte_t, MAX_RC_SIZE > tmp;
|
||||
llarp_buffer_t buf(tmp);
|
||||
|
||||
if(!rc.BEncode(&buf))
|
||||
return false;
|
||||
|
||||
buf.sz = buf.cur - buf.base;
|
||||
auto filepath = getRCFilePath(rc.pubkey);
|
||||
llarp::LogDebug("saving RC.pubkey ", filepath);
|
||||
auto optional_ofs = llarp::util::OpenFileStream< std::ofstream >(
|
||||
filepath,
|
||||
std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
|
||||
if(!optional_ofs)
|
||||
return false;
|
||||
auto &ofs = optional_ofs.value();
|
||||
ofs.write((char *)buf.base, buf.sz);
|
||||
ofs.flush();
|
||||
ofs.close();
|
||||
if(!ofs)
|
||||
{
|
||||
llarp::LogError("Failed to write: ", filepath);
|
||||
return false;
|
||||
}
|
||||
llarp::LogDebug("saved RC.pubkey: ", filepath);
|
||||
}
|
||||
{
|
||||
llarp::util::Lock lock(&access);
|
||||
auto itr = entries.find(rc.pubkey.as_array());
|
||||
if(itr != entries.end())
|
||||
entries.erase(itr);
|
||||
entries.emplace(rc.pubkey.as_array(), rc);
|
||||
LogDebug("Added or updated RC for ", llarp::RouterID(rc.pubkey),
|
||||
" to nodedb. Current nodedb count is: ", entries.size());
|
||||
}
|
||||
llarp::util::Lock lock(&access);
|
||||
auto itr = entries.find(rc.pubkey.as_array());
|
||||
if(itr != entries.end())
|
||||
entries.erase(itr);
|
||||
entries.emplace(rc.pubkey.as_array(), rc);
|
||||
LogDebug("Added or updated RC for ", llarp::RouterID(rc.pubkey),
|
||||
" to nodedb. Current nodedb count is: ", entries.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,13 +97,12 @@ struct llarp_nodedb
|
|||
std::string
|
||||
getRCFilePath(const llarp::RouterID &pubkey) const;
|
||||
|
||||
/// insert and optionally write to disk
|
||||
/// insert without writing to disk
|
||||
bool
|
||||
Insert(const llarp::RouterContact &rc, bool writeToDisk = false)
|
||||
LOCKS_EXCLUDED(access);
|
||||
Insert(const llarp::RouterContact &rc) LOCKS_EXCLUDED(access);
|
||||
|
||||
/// unconditional insert and write to disk in background
|
||||
/// updates the inserted time of the entry
|
||||
/// invokes Insert() asynchronously with an optional completion
|
||||
/// callback
|
||||
void
|
||||
InsertAsync(llarp::RouterContact rc,
|
||||
std::shared_ptr< llarp::Logic > l = nullptr,
|
||||
|
|
Loading…
Reference in a new issue