-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathscrape.rs
More file actions
620 lines (514 loc) · 24.4 KB
/
scrape.rs
File metadata and controls
620 lines (514 loc) · 24.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
//! The `scrape` service.
//!
//! The service is responsible for handling the `scrape` requests.
//!
//! It delegates the `scrape` logic to the [`ScrapeHandler`] and it returns the
//! [`ScrapeData`].
//!
//! It also sends an [`http_tracker_core::statistics::event::Event`]
//! because events are specific for the HTTP tracker.
use std::sync::Arc;
use bittorrent_http_tracker_protocol::v1::requests::scrape::Scrape;
use bittorrent_http_tracker_protocol::v1::services::peer_ip_resolver::{
resolve_remote_client_addr, ClientIpSources, PeerIpResolutionError, RemoteClientAddr,
};
use bittorrent_tracker_core::authentication::service::AuthenticationService;
use bittorrent_tracker_core::authentication::{self, Key};
use bittorrent_tracker_core::error::{ScrapeError, TrackerCoreError, WhitelistError};
use bittorrent_tracker_core::scrape_handler::ScrapeHandler;
use torrust_tracker_configuration::Core;
use torrust_tracker_primitives::core::ScrapeData;
use torrust_tracker_primitives::service_binding::ServiceBinding;
use crate::event::{ConnectionContext, Event};
/// The HTTP tracker `scrape` service.
///
/// The service sends an statistics event that increments:
///
/// - The number of TCP `announce` requests handled by the HTTP tracker.
/// - The number of TCP `scrape` requests handled by the HTTP tracker.
///
/// # Errors
///
/// This function will return an error if:
///
/// - There is an error when resolving the client IP address.
pub struct ScrapeService {
core_config: Arc<Core>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
opt_http_stats_event_sender: crate::event::sender::Sender,
}
impl ScrapeService {
#[must_use]
pub fn new(
core_config: Arc<Core>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
opt_http_stats_event_sender: crate::event::sender::Sender,
) -> Self {
Self {
core_config,
scrape_handler,
authentication_service,
opt_http_stats_event_sender,
}
}
/// Handles a scrape request.
///
/// When the peer is not authenticated and the tracker is running in `private`
/// mode, the tracker returns empty stats for all the torrents.
///
/// # Errors
///
/// This function will return an error if:
///
/// - There is an error when resolving the client IP address.
pub async fn handle_scrape(
&self,
scrape_request: &Scrape,
client_ip_sources: &ClientIpSources,
server_service_binding: &ServiceBinding,
maybe_key: Option<Key>,
) -> Result<ScrapeData, HttpScrapeError> {
let scrape_data = if self.authentication_is_required() && !self.is_authenticated(maybe_key).await {
ScrapeData::zeroed(&scrape_request.info_hashes)
} else {
self.scrape_handler.handle_scrape(&scrape_request.info_hashes).await?
};
let remote_client_addr = resolve_remote_client_addr(&self.core_config.net.on_reverse_proxy.into(), client_ip_sources)?;
self.send_event(remote_client_addr, server_service_binding.clone()).await;
Ok(scrape_data)
}
fn authentication_is_required(&self) -> bool {
self.core_config.private
}
async fn is_authenticated(&self, maybe_key: Option<Key>) -> bool {
if let Some(key) = maybe_key {
return self.authentication_service.authenticate(&key).await.is_ok();
}
false
}
async fn send_event(&self, remote_client_addr: RemoteClientAddr, server_service_binding: ServiceBinding) {
if let Some(http_stats_event_sender) = self.opt_http_stats_event_sender.as_deref() {
let event = Event::TcpScrape {
connection: ConnectionContext::new(remote_client_addr, server_service_binding),
};
tracing::debug!("Sending TcpScrape event: {:?}", event);
http_stats_event_sender.send(event).await;
}
}
}
/// Errors related to announce requests.
#[derive(thiserror::Error, Debug, Clone)]
pub enum HttpScrapeError {
#[error("Error resolving peer IP: {source}")]
PeerIpResolutionError { source: PeerIpResolutionError },
#[error("Tracker core error: {source}")]
TrackerCoreError { source: TrackerCoreError },
}
impl From<PeerIpResolutionError> for HttpScrapeError {
fn from(peer_ip_resolution_error: PeerIpResolutionError) -> Self {
Self::PeerIpResolutionError {
source: peer_ip_resolution_error,
}
}
}
impl From<TrackerCoreError> for HttpScrapeError {
fn from(tracker_core_error: TrackerCoreError) -> Self {
Self::TrackerCoreError {
source: tracker_core_error,
}
}
}
impl From<ScrapeError> for HttpScrapeError {
fn from(announce_error: ScrapeError) -> Self {
Self::TrackerCoreError {
source: announce_error.into(),
}
}
}
impl From<WhitelistError> for HttpScrapeError {
fn from(whitelist_error: WhitelistError) -> Self {
Self::TrackerCoreError {
source: whitelist_error.into(),
}
}
}
impl From<authentication::key::Error> for HttpScrapeError {
fn from(whitelist_error: authentication::key::Error) -> Self {
Self::TrackerCoreError {
source: whitelist_error.into(),
}
}
}
#[cfg(test)]
mod tests {
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::Arc;
use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes, PeerId};
use bittorrent_primitives::info_hash::InfoHash;
use bittorrent_tracker_core::announce_handler::AnnounceHandler;
use bittorrent_tracker_core::authentication::key::repository::in_memory::InMemoryKeyRepository;
use bittorrent_tracker_core::authentication::service::AuthenticationService;
use bittorrent_tracker_core::databases::setup::initialize_database;
use bittorrent_tracker_core::scrape_handler::ScrapeHandler;
use bittorrent_tracker_core::statistics::persisted::downloads::DatabaseDownloadsMetricRepository;
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
use bittorrent_tracker_core::whitelist::authorization::WhitelistAuthorization;
use bittorrent_tracker_core::whitelist::repository::in_memory::InMemoryWhitelist;
use futures::future::BoxFuture;
use mockall::mock;
use torrust_tracker_configuration::Configuration;
use torrust_tracker_events::sender::SendError;
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch};
use crate::event::Event;
use crate::tests::sample_info_hash;
struct Container {
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
}
fn initialize_services_with_configuration(config: &Configuration) -> Container {
let database = initialize_database(&config.core);
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(WhitelistAuthorization::new(&config.core, &in_memory_whitelist.clone()));
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
let db_downloads_metric_repository = Arc::new(DatabaseDownloadsMetricRepository::new(&database));
let in_memory_key_repository = Arc::new(InMemoryKeyRepository::default());
let authentication_service = Arc::new(AuthenticationService::new(&config.core, &in_memory_key_repository));
let announce_handler = Arc::new(AnnounceHandler::new(
&config.core,
&whitelist_authorization,
&in_memory_torrent_repository,
&db_downloads_metric_repository,
));
let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository));
Container {
announce_handler,
scrape_handler,
authentication_service,
}
}
fn sample_info_hashes() -> Vec<InfoHash> {
vec![sample_info_hash()]
}
fn sample_peer() -> peer::Peer {
peer::Peer {
peer_id: PeerId(*b"-qB00000000000000000"),
peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)), 8080),
updated: DurationSinceUnixEpoch::new(1_669_397_478_934, 0),
uploaded: NumberOfBytes::new(0),
downloaded: NumberOfBytes::new(0),
left: NumberOfBytes::new(0),
event: AnnounceEvent::Started,
}
}
mock! {
HttpStatsEventSender {}
impl torrust_tracker_events::sender::Sender for HttpStatsEventSender {
type Event = Event;
fn send(&self, event: Event) -> BoxFuture<'static,Option<Result<usize,SendError<Event> > > > ;
}
}
mod with_real_data {
use std::future;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::sync::Arc;
use bittorrent_http_tracker_protocol::v1::requests::scrape::Scrape;
use bittorrent_http_tracker_protocol::v1::services::peer_ip_resolver::{ClientIpSources, RemoteClientAddr, ResolvedIp};
use bittorrent_tracker_core::announce_handler::PeersWanted;
use mockall::predicate::eq;
use torrust_tracker_events::bus::SenderStatus;
use torrust_tracker_primitives::core::ScrapeData;
use torrust_tracker_primitives::service_binding::{Protocol, ServiceBinding};
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_test_helpers::configuration;
use crate::event::bus::EventBus;
use crate::event::sender::Broadcaster;
use crate::event::{ConnectionContext, Event};
use crate::services::scrape::tests::{
initialize_services_with_configuration, sample_info_hashes, sample_peer, MockHttpStatsEventSender,
};
use crate::services::scrape::ScrapeService;
use crate::tests::sample_info_hash;
#[tokio::test]
async fn it_should_return_the_scrape_data_for_a_torrent() {
let configuration = configuration::ephemeral_public();
let core_config = Arc::new(configuration.core.clone());
// HTTP core stats
let http_core_broadcaster = Broadcaster::default();
let http_stats_event_bus = Arc::new(EventBus::new(SenderStatus::Disabled, http_core_broadcaster.clone()));
let http_stats_event_sender = http_stats_event_bus.sender();
let container = initialize_services_with_configuration(&configuration);
let info_hash = sample_info_hash();
let info_hashes = vec![info_hash];
// Announce a new peer to force scrape data to contain non zeroed data
let mut peer = sample_peer();
let original_peer_ip = peer.ip();
container
.announce_handler
.handle_announcement(&info_hash, &mut peer, &original_peer_ip, &PeersWanted::AsManyAsPossible)
.await
.unwrap();
let scrape_request = Scrape {
info_hashes: info_hashes.clone(),
};
let client_ip_sources = ClientIpSources {
right_most_x_forwarded_for: None,
connection_info_socket_address: Some(SocketAddr::new(original_peer_ip, 8080)),
};
let server_socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070);
let server_service_binding = ServiceBinding::new(Protocol::HTTP, server_socket_addr).unwrap();
let scrape_service = Arc::new(ScrapeService::new(
core_config.clone(),
container.scrape_handler.clone(),
container.authentication_service.clone(),
http_stats_event_sender.clone(),
));
let scrape_data = scrape_service
.handle_scrape(&scrape_request, &client_ip_sources, &server_service_binding, None)
.await
.unwrap();
let mut expected_scrape_data = ScrapeData::empty();
expected_scrape_data.add_file(
&info_hash,
SwarmMetadata {
complete: 1,
downloaded: 0,
incomplete: 0,
},
);
assert_eq!(scrape_data, expected_scrape_data);
}
#[tokio::test]
async fn it_should_send_the_tcp_4_scrape_event_when_the_peer_uses_ipv4() {
let config = configuration::ephemeral();
let mut http_stats_event_sender_mock = MockHttpStatsEventSender::new();
http_stats_event_sender_mock
.expect_send()
.with(eq(Event::TcpScrape {
connection: ConnectionContext::new(
RemoteClientAddr::new(
ResolvedIp::FromSocketAddr(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1))),
Some(8080),
),
ServiceBinding::new(Protocol::HTTP, SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070)).unwrap(),
),
}))
.times(1)
.returning(|_| Box::pin(future::ready(Some(Ok(1)))));
let http_stats_event_sender: crate::event::sender::Sender = Some(Arc::new(http_stats_event_sender_mock));
let container = initialize_services_with_configuration(&config);
let peer_ip = IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1));
let scrape_request = Scrape {
info_hashes: sample_info_hashes(),
};
let client_ip_sources = ClientIpSources {
right_most_x_forwarded_for: None,
connection_info_socket_address: Some(SocketAddr::new(peer_ip, 8080)),
};
let server_socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070);
let server_service_binding = ServiceBinding::new(Protocol::HTTP, server_socket_addr).unwrap();
let scrape_service = Arc::new(ScrapeService::new(
Arc::new(config.core),
container.scrape_handler.clone(),
container.authentication_service.clone(),
http_stats_event_sender.clone(),
));
scrape_service
.handle_scrape(&scrape_request, &client_ip_sources, &server_service_binding, None)
.await
.unwrap();
}
#[tokio::test]
async fn it_should_send_the_tcp_6_scrape_event_when_the_peer_uses_ipv6() {
let server_socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070);
let server_service_binding = ServiceBinding::new(Protocol::HTTP, server_socket_addr).unwrap();
let config = configuration::ephemeral();
let mut http_stats_event_sender_mock = MockHttpStatsEventSender::new();
http_stats_event_sender_mock
.expect_send()
.with(eq(Event::TcpScrape {
connection: ConnectionContext::new(
RemoteClientAddr::new(
ResolvedIp::FromSocketAddr(IpAddr::V6(Ipv6Addr::new(
0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969,
))),
Some(8080),
),
server_service_binding,
),
}))
.times(1)
.returning(|_| Box::pin(future::ready(Some(Ok(1)))));
let http_stats_event_sender: crate::event::sender::Sender = Some(Arc::new(http_stats_event_sender_mock));
let container = initialize_services_with_configuration(&config);
let peer_ip = IpAddr::V6(Ipv6Addr::new(0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969));
let scrape_request = Scrape {
info_hashes: sample_info_hashes(),
};
let client_ip_sources = ClientIpSources {
right_most_x_forwarded_for: None,
connection_info_socket_address: Some(SocketAddr::new(peer_ip, 8080)),
};
let server_socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070);
let server_service_binding = ServiceBinding::new(Protocol::HTTP, server_socket_addr).unwrap();
let scrape_service = Arc::new(ScrapeService::new(
Arc::new(config.core),
container.scrape_handler.clone(),
container.authentication_service.clone(),
http_stats_event_sender.clone(),
));
scrape_service
.handle_scrape(&scrape_request, &client_ip_sources, &server_service_binding, None)
.await
.unwrap();
}
}
mod with_zeroed_data {
use std::future;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::sync::Arc;
use bittorrent_http_tracker_protocol::v1::requests::scrape::Scrape;
use bittorrent_http_tracker_protocol::v1::services::peer_ip_resolver::{ClientIpSources, RemoteClientAddr, ResolvedIp};
use bittorrent_tracker_core::announce_handler::PeersWanted;
use mockall::predicate::eq;
use torrust_tracker_events::bus::SenderStatus;
use torrust_tracker_primitives::core::ScrapeData;
use torrust_tracker_primitives::service_binding::{Protocol, ServiceBinding};
use torrust_tracker_test_helpers::configuration;
use crate::event::bus::EventBus;
use crate::event::sender::Broadcaster;
use crate::event::{ConnectionContext, Event};
use crate::services::scrape::tests::{
initialize_services_with_configuration, sample_info_hashes, sample_peer, MockHttpStatsEventSender,
};
use crate::services::scrape::ScrapeService;
use crate::tests::sample_info_hash;
#[tokio::test]
async fn it_should_return_the_zeroed_scrape_data_when_the_tracker_is_running_in_private_mode_and_the_peer_is_not_authenticated(
) {
let config = configuration::ephemeral_private();
let container = initialize_services_with_configuration(&config);
// HTTP core stats
let http_core_broadcaster = Broadcaster::default();
let http_stats_event_bus = Arc::new(EventBus::new(SenderStatus::Disabled, http_core_broadcaster.clone()));
let http_stats_event_sender = http_stats_event_bus.sender();
let info_hash = sample_info_hash();
let info_hashes = vec![info_hash];
// Announce a new peer to force scrape data to contain non zeroed data
let mut peer = sample_peer();
let original_peer_ip = peer.ip();
container
.announce_handler
.handle_announcement(&info_hash, &mut peer, &original_peer_ip, &PeersWanted::AsManyAsPossible)
.await
.unwrap();
let scrape_request = Scrape {
info_hashes: sample_info_hashes(),
};
let client_ip_sources = ClientIpSources {
right_most_x_forwarded_for: None,
connection_info_socket_address: Some(SocketAddr::new(original_peer_ip, 8080)),
};
let server_socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070);
let server_service_binding = ServiceBinding::new(Protocol::HTTP, server_socket_addr).unwrap();
let scrape_service = Arc::new(ScrapeService::new(
Arc::new(config.core),
container.scrape_handler.clone(),
container.authentication_service.clone(),
http_stats_event_sender.clone(),
));
let scrape_data = scrape_service
.handle_scrape(&scrape_request, &client_ip_sources, &server_service_binding, None)
.await
.unwrap();
let expected_scrape_data = ScrapeData::zeroed(&info_hashes);
assert_eq!(scrape_data, expected_scrape_data);
}
#[tokio::test]
async fn it_should_send_the_tcp_4_scrape_event_when_the_peer_uses_ipv4() {
let config = configuration::ephemeral();
let container = initialize_services_with_configuration(&config);
let mut http_stats_event_sender_mock = MockHttpStatsEventSender::new();
http_stats_event_sender_mock
.expect_send()
.with(eq(Event::TcpScrape {
connection: ConnectionContext::new(
RemoteClientAddr::new(
ResolvedIp::FromSocketAddr(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1))),
Some(8080),
),
ServiceBinding::new(Protocol::HTTP, SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070)).unwrap(),
),
}))
.times(1)
.returning(|_| Box::pin(future::ready(Some(Ok(1)))));
let http_stats_event_sender: crate::event::sender::Sender = Some(Arc::new(http_stats_event_sender_mock));
let peer_ip = IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1));
let scrape_request = Scrape {
info_hashes: sample_info_hashes(),
};
let client_ip_sources = ClientIpSources {
right_most_x_forwarded_for: None,
connection_info_socket_address: Some(SocketAddr::new(peer_ip, 8080)),
};
let server_socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070);
let server_service_binding = ServiceBinding::new(Protocol::HTTP, server_socket_addr).unwrap();
let scrape_service = Arc::new(ScrapeService::new(
Arc::new(config.core),
container.scrape_handler.clone(),
container.authentication_service.clone(),
http_stats_event_sender.clone(),
));
scrape_service
.handle_scrape(&scrape_request, &client_ip_sources, &server_service_binding, None)
.await
.unwrap();
}
#[tokio::test]
async fn it_should_send_the_tcp_6_scrape_event_when_the_peer_uses_ipv6() {
let server_socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070);
let server_service_binding = ServiceBinding::new(Protocol::HTTP, server_socket_addr).unwrap();
let config = configuration::ephemeral();
let container = initialize_services_with_configuration(&config);
let mut http_stats_event_sender_mock = MockHttpStatsEventSender::new();
http_stats_event_sender_mock
.expect_send()
.with(eq(Event::TcpScrape {
connection: ConnectionContext::new(
RemoteClientAddr::new(
ResolvedIp::FromSocketAddr(IpAddr::V6(Ipv6Addr::new(
0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969,
))),
Some(8080),
),
server_service_binding,
),
}))
.times(1)
.returning(|_| Box::pin(future::ready(Some(Ok(1)))));
let http_stats_event_sender: crate::event::sender::Sender = Some(Arc::new(http_stats_event_sender_mock));
let peer_ip = IpAddr::V6(Ipv6Addr::new(0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969));
let scrape_request = Scrape {
info_hashes: sample_info_hashes(),
};
let client_ip_sources = ClientIpSources {
right_most_x_forwarded_for: None,
connection_info_socket_address: Some(SocketAddr::new(peer_ip, 8080)),
};
let server_socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070);
let server_service_binding = ServiceBinding::new(Protocol::HTTP, server_socket_addr).unwrap();
let scrape_service = Arc::new(ScrapeService::new(
Arc::new(config.core),
container.scrape_handler.clone(),
container.authentication_service.clone(),
http_stats_event_sender.clone(),
));
scrape_service
.handle_scrape(&scrape_request, &client_ip_sources, &server_service_binding, None)
.await
.unwrap();
}
}
}