Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve multicast in non-ideal cases with connectivity with some of peers #2161

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<BLACKLIST_NUM_TO_POP>5</BLACKLIST_NUM_TO_POP>
<MAX_PEER_CONNECTION>100</MAX_PEER_CONNECTION>
<MAX_WHITELISTREQ_LIMIT>5</MAX_WHITELISTREQ_LIMIT>
<SENDJOBPEERS_TIMEOUT>5</SENDJOBPEERS_TIMEOUT>
</p2pcomm>
<pow>
<CUDA_GPU_MINE>false</CUDA_GPU_MINE>
Expand Down
1 change: 1 addition & 0 deletions constants_local.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<BLACKLIST_NUM_TO_POP>1</BLACKLIST_NUM_TO_POP>
<MAX_PEER_CONNECTION>100</MAX_PEER_CONNECTION>
<MAX_WHITELISTREQ_LIMIT>5</MAX_WHITELISTREQ_LIMIT>
<SENDJOBPEERS_TIMEOUT>5</SENDJOBPEERS_TIMEOUT>
</p2pcomm>
<pow>
<CUDA_GPU_MINE>false</CUDA_GPU_MINE>
Expand Down
2 changes: 2 additions & 0 deletions src/common/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ const unsigned int MAX_PEER_CONNECTION{
ReadConstantNumeric("MAX_PEER_CONNECTION", "node.p2pcomm.")};
const unsigned int MAX_WHITELISTREQ_LIMIT{
ReadConstantNumeric("MAX_WHITELISTREQ_LIMIT", "node.p2pcomm.")};
const unsigned int SENDJOBPEERS_TIMEOUT{
ReadConstantNumeric("SENDJOBPEERS_TIMEOUT", "node.p2pcomm.")};

// PoW constants
const bool CUDA_GPU_MINE{ReadConstantString("CUDA_GPU_MINE", "node.pow.") ==
Expand Down
1 change: 1 addition & 0 deletions src/common/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ extern const unsigned int MAX_READ_WATERMARK_IN_BYTES;
extern const unsigned int BLACKLIST_NUM_TO_POP;
extern const unsigned int MAX_PEER_CONNECTION;
extern const unsigned int MAX_WHITELISTREQ_LIMIT;
extern const unsigned int SENDJOBPEERS_TIMEOUT;

// PoW constants
extern const bool CUDA_GPU_MINE;
Expand Down
20 changes: 19 additions & 1 deletion src/libNetwork/P2PComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <sys/socket.h>
#include <unistd.h>
#include <cstring>
#include <future>
#include <memory>
#include <utility>

Expand Down Expand Up @@ -345,6 +346,7 @@ void SendJobPeer::DoSend() {

template <class T>
void SendJobPeers<T>::DoSend() {
LOG_MARKER();
vector<unsigned int> indexes(m_peers.size());

for (unsigned int i = 0; i < indexes.size(); i++) {
Expand All @@ -362,6 +364,7 @@ void SendJobPeers<T>::DoSend() {
<< hashStr.substr(0, 6) << "] BEGN");
}

vector<std::shared_ptr<std::future<void>>> runningSendTasks;
for (vector<unsigned int>::const_iterator curr = indexes.begin();
curr < indexes.end(); ++curr) {
const Peer& peer = m_peers.at(*curr);
Expand All @@ -373,9 +376,24 @@ void SendJobPeers<T>::DoSend() {
continue;
}

SendMessageCore(peer, m_message, m_startbyte, m_hash);
// Launch the thread.
auto hThread = make_shared<std::future<void>>(
std::async(std::launch::async, SendMessageCore, peer, m_message,
m_startbyte, m_hash));

// Park the thread if message sending taking more than expected time
auto status = hThread->wait_for(std::chrono::seconds(SENDJOBPEERS_TIMEOUT));

if (status == std::future_status::timeout) {
LOG_GENERAL(WARNING,
"Sending delayed for " << peer.GetPrintableIPAddress());
runningSendTasks.push_back(hThread);
}
}

// If any threads in runningSendTask exist, it will be blocked until it
// completes.

if ((m_startbyte == START_BYTE_BROADCAST) && (m_selfPeer != Peer())) {
LOG_STATE("[BROAD][" << std::setw(15) << std::left
<< m_selfPeer.GetPrintableIPAddress() << "]["
Expand Down