mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Unl change announcement to connected users. (#224)
Introduced json and bson messages for unl list announcement. When the unl set is modified send a json or bson unl list message (according to the user protocol) to all the connected users.
This commit is contained in:
@@ -15,6 +15,7 @@ namespace msg::usrmsg::json
|
||||
constexpr const char *SEP_COLON = "\":\"";
|
||||
constexpr const char *SEP_COMMA_NOQUOTE = ",\"";
|
||||
constexpr const char *SEP_COLON_NOQUOTE = "\":";
|
||||
constexpr const char *DOUBLE_QUOTE = "\"";
|
||||
|
||||
// std::vector overload to concatonate string.
|
||||
std::vector<uint8_t> &operator+=(std::vector<uint8_t> &vec, std::string_view sv)
|
||||
@@ -312,6 +313,41 @@ namespace msg::usrmsg::json
|
||||
msg += "]}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs unl list container message.
|
||||
* @param msg String reference to copy the generated json message string into.
|
||||
* Message format:
|
||||
* {
|
||||
* "type": "unl_change",
|
||||
* ["<pubkey1>{[ed prefix][64 characters]}", ...], // Hex pubkey list of unl nodes.
|
||||
* }
|
||||
* @param unl_list The unl node pubkey list to be put in the message.
|
||||
*/
|
||||
void create_unl_list_container(std::vector<uint8_t> &msg, const ::std::set<std::string> &unl_list)
|
||||
{
|
||||
msg.reserve((69 * unl_list.size()) + 30);
|
||||
msg += "{\"";
|
||||
msg += msg::usrmsg::FLD_TYPE;
|
||||
msg += SEP_COLON;
|
||||
msg += msg::usrmsg::MSGTYPE_UNL_CHANGE;
|
||||
msg += SEP_COMMA;
|
||||
msg += msg::usrmsg::FLD_UNL;
|
||||
msg += "\":[";
|
||||
|
||||
int i = 0;
|
||||
for (std::string_view unl : unl_list)
|
||||
{
|
||||
msg += DOUBLE_QUOTE;
|
||||
msg += util::to_hex(unl);
|
||||
msg += DOUBLE_QUOTE;
|
||||
if (i < unl_list.size() - 1)
|
||||
msg += ",";
|
||||
i++;
|
||||
}
|
||||
|
||||
msg += "]}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the user handshake response with the original challenge issued to the user
|
||||
* and the user public key contained in the response.
|
||||
|
||||
Reference in New Issue
Block a user