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