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:
Chalith Desaman
2021-01-19 11:33:27 +05:30
committed by GitHub
parent cf02108576
commit 73f5eea451
12 changed files with 109 additions and 0 deletions

View File

@@ -133,6 +133,31 @@ namespace msg::usrmsg::bson
encoder.flush();
}
/**
* Constructs unl list container message.
* @param msg String reference to copy the generated bson message string into.
* Message format:
* {
* "type": "unl_change",
* "unl": ["<pubkey1>{[1byte(11101101) prefix][32byte]}", ...], // Binary 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)
{
jsoncons::bson::bson_bytes_encoder encoder(msg);
encoder.begin_object();
encoder.key(msg::usrmsg::FLD_TYPE);
encoder.string_value(msg::usrmsg::MSGTYPE_UNL_CHANGE);
encoder.key(msg::usrmsg::FLD_UNL);
encoder.begin_array();
for (std::string_view unl : unl_list)
encoder.byte_string_value(unl);
encoder.end_array();
encoder.end_object();
encoder.flush();
}
/**
* Parses a bson message sent by a user.
* @param d BSON document to which the parsed bson should be loaded.