Introduce pubkey/unl tracking to Peer sessions. (#181)

* Adding pubkey in binary to comm sessions and is_unl flag to peer sessions.
* Removing display_name overloads and populating pubkey in user session.
* Changing peer session lookup key from uniqueid to pubkey (binary).
This commit is contained in:
Savinda Senevirathne
2020-12-02 13:05:06 +05:30
committed by GitHub
parent 596fd2b43c
commit f3055822ed
14 changed files with 81 additions and 85 deletions

View File

@@ -82,16 +82,16 @@ namespace p2p
if (p2p::validate_for_peer_msg_forwarding(session, container, content_message_type))
{
// Npl messages are forwarded only to trusted peers.
const bool only_to_trusted_peers = content_message_type == p2pmsg::Message_Npl_Message;
const bool unl_only = content_message_type == p2pmsg::Message_Npl_Message;
if (session.need_consensus_msg_forwarding)
{
// Forward messages received by weakly connected nodes to other peers.
p2p::broadcast_message(message, false, false, only_to_trusted_peers, &session);
p2p::broadcast_message(message, false, false, unl_only, &session);
}
else
{
// Forward message received from other nodes to weakly connected peers.
p2p::broadcast_message(message, false, true, only_to_trusted_peers, &session);
p2p::broadcast_message(message, false, true, unl_only, &session);
}
}
@@ -193,7 +193,7 @@ namespace p2p
if (ctx.collected_msgs.state_requests.size() < p2p::STATE_REQ_LIST_CAP)
{
std::string state_request_msg(reinterpret_cast<const char *>(content_ptr), content_size);
ctx.collected_msgs.state_requests.push_back(std::make_pair(session.uniqueid, std::move(state_request_msg)));
ctx.collected_msgs.state_requests.push_back(std::make_pair(session.pubkey, std::move(state_request_msg)));
}
else
{
@@ -211,7 +211,7 @@ namespace p2p
if (ctx.collected_msgs.state_responses.size() < p2p::STATE_RES_LIST_CAP)
{
std::string response(reinterpret_cast<const char *>(content_ptr), content_size);
ctx.collected_msgs.state_responses.push_back(std::make_pair(session.uniqueid, std::move(response)));
ctx.collected_msgs.state_responses.push_back(std::make_pair(session.pubkey, std::move(response)));
}
else
{
@@ -228,7 +228,7 @@ namespace p2p
if (ledger::sync_ctx.collected_history_requests.size() < ledger::HISTORY_REQ_LIST_CAP)
{
const p2p::history_request hr = p2pmsg::create_history_request_from_msg(*content->message_as_History_Request_Message(), container->lcl());
ledger::sync_ctx.collected_history_requests.push_back(std::make_pair(session.uniqueid, std::move(hr)));
ledger::sync_ctx.collected_history_requests.push_back(std::make_pair(session.pubkey, std::move(hr)));
}
else
{
@@ -360,9 +360,9 @@ namespace p2p
int handle_peer_close(const p2p::peer_comm_session &session)
{
{
// Erase the corresponding uniqueid peer connection if it's this session.
// Erase the corresponding pubkey peer connection if it's this session.
std::scoped_lock<std::mutex> lock(ctx.peer_connections_mutex);
const auto itr = ctx.peer_connections.find(session.uniqueid);
const auto itr = ctx.peer_connections.find(session.pubkey);
if (itr != ctx.peer_connections.end() && itr->second == &session)
{
ctx.peer_connections.erase(itr);