lt_rs/alerts/tracker_alert.rs
1use std::marker::PhantomData;
2
3use crate::{
4 alerts::{
5 DhtReplyAlert, ScrapeFailedAlert, ScrapeReplyAlert, TrackerAnnounceAlert,
6 TrackerErrorAlert, TrackerReplyAlert, TrackerWarningAlert, TrackeridAlert,
7 },
8 ffi::{alerts::tracker_alert::ffi::tracker_alert_get_tracker_url, ffi},
9};
10
11pub struct TrackerAlertRaw<'a>(*mut ffi::tracker_alert, PhantomData<&'a ()>);
12
13impl<'a> TrackerAlertRaw<'a> {
14 pub(crate) fn new(alert: *mut ffi::tracker_alert) -> TrackerAlertRaw<'a> {
15 TrackerAlertRaw(alert, PhantomData)
16 }
17
18 pub(crate) fn tracker_url(&self) -> &'a str {
19 unsafe { tracker_alert_get_tracker_url(self.0) }
20 }
21
22 pub(crate) fn local_endpoint(&self) {
23 unimplemented!()
24 }
25}
26
27pub enum TrackerAlert {
28 /// This alert is generated on tracker time outs, premature disconnects,
29 /// invalid response or a HTTP response other than "200 OK". From the alert
30 /// you can get the handle to the torrent the tracker belongs to.
31 ///
32 /// ## Alert Category
33 /// [`AlertCategory::Tracker`] [`AlertCategory::Error`]
34 /// ## Alert Priority
35 /// [`AlertPriority::High`]
36 TrackerError(TrackerErrorAlert),
37 /// This alert is triggered if the tracker reply contains a warning field.
38 /// Usually this means that the tracker announce was successful, but the
39 /// tracker has a message to the client.
40 ///
41 /// ## Alert Category
42 /// [`AlertCategory::Tracker`] [`AlertCategory::Error`]
43 /// ## Alert Priority
44 /// [`AlertPriority::Normal`]
45 TrackerWarning(TrackerWarningAlert),
46 /// This alert is generated when a scrape request succeeds.
47 ///
48 /// ## Alert Category
49 /// [`AlertCategory::Tracker`]
50 /// ## Alert Priority
51 /// [`AlertPriority::Critical`]
52 ScrapeReply(ScrapeReplyAlert),
53 /// If a scrape request fails, this alert is generated. This might be due
54 /// to the tracker timing out, refusing connection or returning an http response
55 /// code indicating an error.
56 ///
57 /// ## Alert Category
58 /// [`AlertCategory::Tracker`] [`AlertCategory::Error`]
59 /// ## Alert Priority
60 /// [`AlertPriority::Critical`]
61 ScrapeFailed(ScrapeFailedAlert),
62 /// This alert is only for informational purpose. It is generated when a tracker announce
63 /// succeeds. It is generated regardless what kind of tracker was used, be it UDP, HTTP or
64 /// the DHT.
65 ///
66 /// ## Alert Category
67 /// [`AlertCategory::Tracker`]
68 /// ## Alert Priority
69 /// [`AlertPriority::Normal`]
70 TrackerReply(TrackerReplyAlert),
71 /// This alert is generated each time the DHT receives peers from a node. ``num_peers``
72 /// is the number of peers we received in this packet. Typically these packets are
73 /// received from multiple DHT nodes, and so the alerts are typically generated
74 /// a few at a time.
75 ///
76 /// ## Alert Category
77 /// [`AlertCategory::Dht`] [`AlertCategory::Tracker`]
78 /// ## Alert Priority
79 /// [`AlertPriority::Normal`]
80 DhtReply(DhtReplyAlert),
81 /// This alert is generated each time a tracker announce is sent (or attempted to be sent).
82 /// There are no extra data members in this alert. The url can be found in the base class
83 /// however.
84 ///
85 /// ## Alert Category
86 /// [`AlertCategory::Tracker`]
87 /// ## Alert Priority
88 /// [`AlertPriority::Normal`]
89 TrackerAnnounce(TrackerAnnounceAlert),
90 /// This alert is posted whenever a tracker responds with a ``trackerid``.
91 /// The tracker ID is like a cookie. libtorrent will store the tracker ID
92 /// for this tracker and repeat it in subsequent announces.
93 ///
94 /// ## Alert Category
95 /// [`AlertCategory::Status`]
96 /// ## Alert Priority
97 /// [`AlertPriority::Normal`]
98 Trackerid(TrackeridAlert),
99}