1 // Copyright (c) 2012-2016 The Novacoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or https://opensource.org/licenses/mit-license.php.
11 #define pclose _pclose
14 std::string strCollectorCommand;
16 std::string exec(const char* cmd) {
17 std::string result = "";
22 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
29 bool AddPeer(std::string &strIpAddr) {
31 std::vector<std::string>::iterator it = vAddedNodes.begin();
32 for(; it != vAddedNodes.end(); it++) {
33 if (strIpAddr == *it) break;
35 if (it != vAddedNodes.end())
38 printf("Adding node %s\n", strIpAddr.c_str());
39 vAddedNodes.push_back(strIpAddr);
44 void ThreadIPCollector(void* parg) {
45 printf("ThreadIPCollector started\n");
46 vnThreadsRunning[THREAD_IPCOLLECTOR]++;
48 std::string strExecutableFilePath = "";
50 size_t nameEnd = strCollectorCommand.rfind(".app");
51 if (nameEnd != std::string::npos) {
52 size_t nameBeginning = strCollectorCommand.rfind("/");
53 if (nameBeginning == std::string::npos)
56 std::string strFileName = strCollectorCommand.substr(nameBeginning, nameEnd - nameBeginning);
57 strExecutableFilePath = strCollectorCommand + "/Contents/MacOS/" + strFileName;
60 strExecutableFilePath = strCollectorCommand;
62 strExecutableFilePath = strCollectorCommand;
65 if (!strExecutableFilePath.empty())
69 // If RPC server is enabled then we don't have to parse anything.
70 std::string strCollectorOutput = exec(strExecutableFilePath.c_str());
71 printf("Peer collector output: %s\n", strCollectorOutput.c_str());
73 // Otherwise, there is a work to be done.
74 std::string strCollectorOutput = exec((strExecutableFilePath + " norpc").c_str());
75 std::istringstream collectorStream(strCollectorOutput);
77 std::string strIpAddr;
78 while (std::getline(collectorStream, strIpAddr)) {
83 int nSleepHours = 1 + GetRandInt(5); // Sleep for 1-6 hours.
84 for (int i = 0; i < nSleepHours * 3600 && !fShutdown; i++)
89 printf("ThreadIPCollector stopped\n");
90 vnThreadsRunning[THREAD_IPCOLLECTOR]--;