6 #include "ui_interface.h"
10 #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 vAddedNodes.push_back(strIpAddr);
43 void ThreadIPCollector(void* parg) {
44 printf("ThreadIPCollector started\n");
45 vnThreadsRunning[THREAD_IPCOLLECTOR]++;
49 // If RPC server is enabled then we don't have to parse anything.
50 std::string strCollectorOutput = exec(strCollectorCommand.c_str());
51 printf("Peer collector output: %s\n", strCollectorOutput.c_str());
53 // Otherwise, there is a work to be done.
54 std::string strCollectorOutput = exec((strCollectorCommand + " norpc").c_str());
55 std::istringstream collectorStream(strCollectorOutput);
57 std::string strIpAddr;
58 while (std::getline(collectorStream, strIpAddr)) {
63 int nSleepHours = 1 + GetRandInt(5); // Sleep for 1-6 hours.
64 for (int i = 0; i < nSleepHours * 3600 && !fShutdown; i++)
68 printf("ThreadIPCollector stopped\n");
69 vnThreadsRunning[THREAD_IPCOLLECTOR]--;