MCPcopy Create free account
hub / github.com/adysec/tracker / check_http_tracker

Function check_http_tracker

tracker-checker/src/main.rs:175–236  ·  view source on GitHub ↗
(url: &str, timeout: Duration)

Source from the content-addressed store, hash-verified

173}
174
175fn check_http_tracker(url: &str, timeout: Duration) -> (Status, Option<u64>) {
176 let client = match Client::builder().timeout(timeout).build() {
177 Ok(c) => c,
178 Err(_) => return (Status::Dead, None),
179 };
180
181 let mut rng = rand::thread_rng();
182 let peer_id_random: String = (0..12)
183 .map(|_| (rng.gen_range(0u8..=9) + b'0') as char)
184 .collect();
185 let peer_id = format!("-RS0001-{peer_id_random}");
186
187 let started = Instant::now();
188 let response = match client
189 .get(url)
190 .query(&[
191 ("info_hash", "00000000000000000000"),
192 ("peer_id", peer_id.as_str()),
193 ("port", "6881"),
194 ("uploaded", "0"),
195 ("downloaded", "0"),
196 ("left", "0"),
197 ("compact", "1"),
198 ("event", "started"),
199 ])
200 .send()
201 {
202 Ok(r) => r,
203 Err(_) => return (Status::Dead, None),
204 };
205 let ping_ms = Some(started.elapsed().as_millis() as u64);
206
207 let status_code = response.status();
208 let body = response.bytes().unwrap_or_default().to_vec();
209
210 if is_parked_or_expired_domain(&body) {
211 return (Status::Invalid, ping_ms);
212 }
213
214 if bdecode_simple(&body) {
215 return (Status::Alive, ping_ms);
216 }
217
218 if status_code == StatusCode::OK {
219 let head = String::from_utf8_lossy(&body[..body.len().min(200)]).to_lowercase();
220 if head.contains("<html") || head.contains("<body") || head.contains("<head") {
221 return (Status::Invalid, ping_ms);
222 }
223 if body.len() > 50_000 {
224 return (Status::Invalid, ping_ms);
225 }
226 return (Status::Dead, ping_ms);
227 }
228
229 if status_code == StatusCode::BAD_REQUEST || status_code == StatusCode::FORBIDDEN {
230 if bdecode_simple(&body) {
231 return (Status::Alive, ping_ms);
232 }

Callers 1

validate_trackerFunction · 0.85

Calls 2

bdecode_simpleFunction · 0.85

Tested by

no test coverage detected