Persist discovered peers to config. (#246)

This commit is contained in:
Ravin Perera
2021-02-16 16:20:19 +05:30
committed by GitHub
parent 9d1163c8c3
commit 90641e0849
9 changed files with 41 additions and 16 deletions

View File

@@ -789,6 +789,21 @@ namespace conf
return 0;
}
/**
* Persists the specified known peers to the config file.
*/
int persist_known_peers_config(const std::vector<peer_properties> &peers)
{
if (peers.empty())
return 0;
const size_t max_count = conf::cfg.mesh.max_known_connections == 0
? peers.size()
: MIN(peers.size(), conf::cfg.mesh.max_known_connections);
cfg.mesh.known_peers = std::vector<peer_properties>(peers.begin(), peers.begin() + max_count);
return write_config(cfg);
}
/**
* Locks the config file. If already locked means there's another hpcore instance running in the same directory.
* If so, log error and return, Otherwise lock the config.