Skip to content

Commit 4f33466

Browse files
committed
Add timeout for connections and receive attempts
1 parent 8e1aa85 commit 4f33466

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

dcc_client/dcc_client/Main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ int main()
274274
p2p.keepPeersAlive = (bool)walletConfig["keepAlive"];
275275
p2p.isServer = (bool)walletConfig["isServer"];
276276
p2p.InitPeerList();
277+
if(p2p.isServer == false)
278+
p2p.RandomizePeer();
277279
// Start the P2P listener thread
278280
std::thread t1(&P2P::ListenerThread, &p2p, 10);
279281
// Start the P2P sender thread

dcc_client/dcc_client/P2PClient.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ void P2P::ListenerThread(int update_interval)
243243
std::string totalMessage = "";
244244
std::map<int, std::string> messageParts = std::map<int, std::string>();
245245
int maxSegments = 0;
246+
uint32_t noreceipt = 0; // A counter that increments each time tick there is no message
246247

247248
while (!stop_thread_1)
248249
{
@@ -263,6 +264,8 @@ void P2P::ListenerThread(int update_interval)
263264

264265
if (iResult > 0) {
265266

267+
noreceipt = 0;
268+
266269
// Get the IPV4 address:port pair of the received data. If it
267270
// matches the expected one, continue. If it does not, then
268271
// stop. If the current one is blank or has disconnected,
@@ -277,7 +280,7 @@ void P2P::ListenerThread(int update_interval)
277280
p2pConnections[fromIPString]->life = 0;
278281

279282
// If not currently connected, accept this connection.
280-
if ((otherAddrStr == "" || otherAddrStr == "0.0.0.0:0") && otherAddrStr != clientIPPort){
283+
if (otherAddrStr == "" || otherAddrStr == "0.0.0.0:0"){
281284
if (WalletSettingValues::verbose >= 4)
282285
console::WriteLine("\nConversation Started", console::greenFGColor, "");
283286

@@ -587,6 +590,17 @@ void P2P::ListenerThread(int update_interval)
587590

588591
}
589592
}
593+
else if(noreceipt >= 100){
594+
if(WalletSettingValues::verbose >= 4 && otherAddrStr != "")
595+
console::WriteLine("noreceipt timeout check");
596+
messageStatus = idle;
597+
messageAttempt = 0;
598+
otherAddrStr = "";
599+
noreceipt = 0;
600+
}
601+
else{
602+
noreceipt++;
603+
}
590604
#if WINDOWS
591605
else if (WSAGetLastError() != WSAETIMEDOUT && WalletSettingValues::verbose >= 5) {
592606
console::NetworkErrorPrint();
@@ -1092,13 +1106,15 @@ void P2P::SenderThread()
10921106
console::NetworkErrorPrint();
10931107
console::WriteLine("!! No peers seem to be online. Please try again later. !!", console::redFGColor, "");
10941108
differentPeerAttempts = 0;
1109+
otherAddrStr = "";
10951110
reqDat = -1;
10961111
}
10971112
}
10981113
// Otherwise, this is the answerer, so stop trying to reply to the original asker.
10991114
else {
11001115
role = -1;
11011116
messageStatus = idle;
1117+
otherAddrStr = "";
11021118
if(WalletSettingValues::verbose >= 5){
11031119
console::NetworkErrorPrint();
11041120
console::WriteLine("Asking peer went offline.", console::redFGColor, "");
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)