Updated nodejs contract lib for streamed input reading. (#110)

This commit is contained in:
Ravin Perera
2020-08-21 15:27:25 +05:30
committed by GitHub
parent baf5d8b14a
commit 465573ad29
7 changed files with 93 additions and 50 deletions

View File

@@ -321,22 +321,23 @@ namespace cons
*/
void broadcast_nonunl_proposal()
{
std::lock_guard<std::mutex> lock(p2p::ctx.collected_msgs.nonunl_proposals_mutex);
if (usr::ctx.users.empty())
return;
// Construct NUP.
p2p::nonunl_proposal nup;
for (auto &[sid, user] : usr::ctx.users)
{
std::list<usr::user_input> user_inputs;
user_inputs.splice(user_inputs.end(), user.submitted_inputs);
std::lock_guard<std::mutex>(usr::ctx.users_mutex);
for (auto &[sid, user] : usr::ctx.users)
{
std::list<usr::user_input> user_inputs;
user_inputs.splice(user_inputs.end(), user.submitted_inputs);
// We should create an entry for each user pubkey, even if the user has no inputs. This is
// because this data map will be used to track connected users as well in addition to inputs.
nup.user_inputs.try_emplace(user.pubkey, std::move(user_inputs));
// We should create an entry for each user pubkey, even if the user has no inputs. This is
// because this data map will be used to track connected users as well in addition to inputs.
nup.user_inputs.try_emplace(user.pubkey, std::move(user_inputs));
}
}
flatbuffers::FlatBufferBuilder fbuf(1024);

View File

@@ -75,7 +75,8 @@ namespace p2p
return -1;
}
// Converting the binary pub key into hexa decimal string this will be used as the key in storing peer sessions
// Converting the binary pub key into hexadecimal string.
// This will be used as the lookup key in storing peer sessions.
std::string pubkeyhex;
util::bin2hex(pubkeyhex, reinterpret_cast<const unsigned char *>(challenge_resp.pubkey.data()), challenge_resp.pubkey.length());
@@ -145,7 +146,7 @@ namespace p2p
/**
* Broadcasts the given message to all currently connected outbound peers.
* @param msg Peer outbound message to be broadcasted.
* @param fbuf Peer outbound message to be broadcasted.
* @param send_to_self Whether to also send the message to self (this node).
*/
void broadcast_message(const flatbuffers::FlatBufferBuilder &fbuf, const bool send_to_self)
@@ -173,7 +174,7 @@ namespace p2p
/**
* Sends the given message to self (this node).
* @param msg Peer outbound message to be sent to self.
* @param fbuf Peer outbound message to be sent to self.
*/
void send_message_to_self(const flatbuffers::FlatBufferBuilder &fbuf)
{
@@ -194,7 +195,7 @@ namespace p2p
/**
* Sends the given message to a random peer (except self).
* @param msg Peer outbound message to be sent to peer.
* @param fbuf Peer outbound message to be sent to peer.
*/
void send_message_to_random_peer(const flatbuffers::FlatBufferBuilder &fbuf)
{

View File

@@ -52,7 +52,7 @@ namespace usr
struct connected_context
{
// Connected (authenticated) user list.
// Map key: User socket session id (<ip:port>)
// Map key: User socket session id.
std::unordered_map<std::string, usr::connected_user> users;
std::mutex users_mutex; // Mutex for users access race conditions.