Limiting NPL message broadcasting and forwarding to trusted nodes. (#173)

* Limiting NPL message broadcasting and forwarding to trusted nodes.
* Error fix in read_iosocket.
This commit is contained in:
Savinda Senevirathne
2020-11-30 11:11:40 +05:30
committed by GitHub
parent efbd775fa1
commit e90e9bb5dd
6 changed files with 46 additions and 14 deletions

View File

@@ -2,6 +2,7 @@
#include "hplog.hpp"
#include "conf.hpp"
#include "unl.hpp"
#include "crypto.hpp"
/**
* Manages the UNL public keys of this node.
@@ -43,8 +44,30 @@ namespace unl
return json_list;
}
bool exists(const std::string &bin_pubkey)
/**
* Check whether the given pubkey is in the unl list.
* @param pubkey Pubkey to check for existence.
* @param is_in_hex Whether the given pubkey is in hex format.
* @return Return true if the given pubkey is in the unl list.
*/
bool exists(const std::string &pubkey, const bool is_in_hex)
{
std::string bin_pubkey = pubkey;
if (is_in_hex)
{
// If the given pubkey is in hex format, convert the public key to binary.
std::string temp_bin_pubkey;
temp_bin_pubkey.resize(crypto::PFXD_PUBKEY_BYTES);
if (util::hex2bin(
reinterpret_cast<unsigned char *>(temp_bin_pubkey.data()),
temp_bin_pubkey.length(),
pubkey) != 0)
{
LOG_ERROR << "Error decoding hex pubkey.\n";
return false;
}
bin_pubkey.swap(temp_bin_pubkey);
}
std::shared_lock lock(unl_mutex);
return list.find(bin_pubkey) != list.end();
}