| 136 | } |
| 137 | |
| 138 | static CIPGroup *LoadIPDataFromWeb(const string &url, const string &groupname, int priority) { |
| 139 | try { |
| 140 | std::unique_ptr<CurlWrapper> curlWrapper = MakeCurl(); |
| 141 | curl_easy_setopt(curlWrapper->getHandle(), CURLOPT_SSL_CTX_FUNCTION, &ssl_context_setup); |
| 142 | |
| 143 | // This will block until the download is done. |
| 144 | std::string res = curlWrapper->fetchURL(url); |
| 145 | LogPrintf("IP list download succeeded from %s\n", url.c_str()); |
| 146 | |
| 147 | vector<CSubNet> subnets = ParseIPData(res); |
| 148 | if (subnets.size() > 0) { |
| 149 | CIPGroup *ipGroup = new CIPGroup; |
| 150 | ipGroup->header.name = groupname; |
| 151 | ipGroup->header.priority = priority; |
| 152 | ipGroup->subnets.assign(subnets.begin(), subnets.end()); |
| 153 | return ipGroup; |
| 154 | } |
| 155 | } |
| 156 | catch (const curl_error& e) { |
| 157 | LogPrintf("Failed to download IP priority data from %s: %s\n", |
| 158 | e.url.c_str(), e.what()); |
| 159 | } |
| 160 | return NULL; |
| 161 | } |
| 162 | |
| 163 | static CIPGroup *LoadTorIPsFromWeb() { |
| 164 | string ourip = "255.255.255.255"; |
no test coverage detected