mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
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:
committed by
GitHub
parent
efbd775fa1
commit
e90e9bb5dd
25
src/unl.cpp
25
src/unl.cpp
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user