Skip to content

Commit 696ca05

Browse files
committed
Make initial connect message also contain the announce info for less messaging time
1 parent 7a5a85e commit 696ca05

File tree

5 files changed

+44
-7289
lines changed

5 files changed

+44
-7289
lines changed

dcc_client/dcc_client/P2PClient.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,31 @@ void P2P::ListenerThread(int update_interval)
369369
std::string messagePrefix = "";
370370

371371
// If the peer is requesting to connect
372-
if (totalMessage == "peer~connect") {
372+
if (StringStartsWith(totalMessage, "peer~connect")) {
373+
role = 0;
373374
if (WalletSettingValues::verbose >= 4) {
374375
console::DebugPrint();
375376
console::WriteLine("Received initial connection from ("+otherAddrStr+")", console::greenFGColor, "");
376377
}
378+
messagePrefix += "peer~connect~";
379+
json announcedInfo = json::parse(totalMessage.substr(messagePrefix.size()));
380+
// Add peer to collection of connections if not there yet
381+
AddToPeerList(otherAddrStr);
382+
383+
p2pConnections[otherAddrStr]->height = announcedInfo["height"];
384+
p2pConnections[otherAddrStr]->peerList = announcedInfo["peerList"];
385+
p2pConnections[otherAddrStr]->testedOnline = true;
386+
387+
if (WalletSettingValues::verbose >= 7) {
388+
console::WriteLine("answer peerconnect", console::greenFGColor, "");
389+
}
390+
377391
messageStatus = announce;
378392
//messageStatus = await_first_success; // Awaiting confirmation status
379393
messageAttempt = 0;
380394
differentPeerAttempts = 0;
381395

382396
CONNECTED_TO_PEER = true;
383-
384-
// Add peer to collection of connections
385-
AddToPeerList(otherAddrStr);
386-
387-
p2pConnections[otherAddrStr]->testedOnline = true;
388397
}
389398
// If the peer is ending the connection
390399
else if (totalMessage == "peer~disconnect") {
@@ -833,11 +842,34 @@ void P2P::SenderThread()
833842

834843
// If doing initial connect request
835844
if (messageStatus == initial_connect_request) {
836-
role = 0;
837-
msg = "peer~connect";
838-
if (WalletSettingValues::verbose >= 7) {
839-
console::Write(msg + "\n");
845+
//role = 0;
846+
//msg = "peer~connect";
847+
//if (WalletSettingValues::verbose >= 7) {
848+
// console::Write(msg + "\n");
849+
//}
850+
//role = 1;
851+
namespace fs = std::filesystem;
852+
std::vector<std::string> delugeHashes = std::vector<std::string>();
853+
for (auto deluge : fs::directory_iterator("./wwwdata/deluges/")){
854+
std::ifstream delugeFile(deluge.path());
855+
if (delugeFile.is_open()) {
856+
std::stringstream delugeFilebuf;
857+
delugeFilebuf << delugeFile.rdbuf();
858+
json delugeJson = json::parse(delugeFilebuf.str());
859+
delugeFile.close();
860+
delugeHashes.push_back((std::string)delugeJson["_totalHash"]);
861+
}
840862
}
863+
864+
blockchainLength = FileCount("./wwwdata/blockchain/");
865+
866+
json infoCompilation = json();
867+
infoCompilation = {
868+
{"height", blockchainLength},
869+
{"peerList", GeneratePeerList()},
870+
{"delugeHashes", delugeHashes},
871+
};
872+
msg = "peer~answer~" + infoCompilation.dump();
841873
mySendTo(localSocket, msg, msg.length(), 0, (sockaddr*)&otherAddr, otherSize);
842874
}
843875
// If doing disconnect request
Binary file not shown.
12.5 KB
Binary file not shown.

tags.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
939054
1+
971455

0 commit comments

Comments
 (0)