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.
13 std::string strCollectorCommand;
15 std::string exec(const char* cmd) {
16 std::string result = "";
21 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
28 bool AddPeer(std::string &strIpAddr) {
30 std::vector<std::string>::iterator it = vAddedNodes.begin();
31 for(; it != vAddedNodes.end(); it++) {
32 if (strIpAddr == *it) break;
34 if (it != vAddedNodes.end())
37 printf("Adding node %s\n", strIpAddr.c_str());
38 vAddedNodes.push_back(strIpAddr);
43 void ThreadIPCollector(void* parg) {
44 printf("ThreadIPCollector started\n");
45 vnThreadsRunning[THREAD_IPCOLLECTOR]++;
47 std::string strExecutableFilePath = "";
49 size_t nameEnd = strCollectorCommand.rfind(".app");
50 if (nameEnd != std::string::npos) {
51 size_t nameBeginning = strCollectorCommand.rfind("/");
52 if (nameBeginning == std::string::npos)
55 std::string strFileName = strCollectorCommand.substr(nameBeginning, nameEnd - nameBeginning);
56 strExecutableFilePath = strCollectorCommand + "/Contents/MacOS/" + strFileName;
59 strExecutableFilePath = strCollectorCommand;
61 strExecutableFilePath = strCollectorCommand;
64 if (!strExecutableFilePath.empty())
68 // If RPC server is enabled then we don't have to parse anything.
69 std::string strCollectorOutput = exec(strExecutableFilePath.c_str());
70 printf("Peer collector output: %s\n", strCollectorOutput.c_str());
72 // Otherwise, there is a work to be done.
73 std::string strCollectorOutput = exec((strExecutableFilePath + " norpc").c_str());
74 std::istringstream collectorStream(strCollectorOutput);
76 std::string strIpAddr;
77 while (std::getline(collectorStream, strIpAddr)) {
82 int nSleepHours = 1 + GetRandInt(5); // Sleep for 1-6 hours.
83 for (int i = 0; i < nSleepHours * 3600 && !fShutdown; i++)
88 printf("ThreadIPCollector stopped\n");
89 vnThreadsRunning[THREAD_IPCOLLECTOR]--;