lt_rs/alerts/implementations/
tracker_error.rs

1use crate::{
2    alerts::{TrackerErrorAlert, operation::Operation, protocol_version::ProtocolVersion},
3    errors::LtrsError,
4    ffi::alerts::tracker_error::ffi::{
5        tracker_error_alert_get_error, tracker_error_alert_get_failure_reason,
6        tracker_error_alert_get_op, tracker_error_alert_get_times_in_row,
7        tracker_error_alert_get_version,
8    },
9    torrent_handle::TorrentHandle,
10};
11
12impl TrackerErrorAlert {
13    #[inline(always)]
14    pub fn handle(&self) -> TorrentHandle {
15        self.as_torrent_alert().handle()
16    }
17
18    #[inline(always)]
19    pub fn torrent_name<'a>(&'a self) -> &'a str {
20        self.as_torrent_alert().torrent_name()
21    }
22
23    #[inline(always)]
24    pub fn message(&self) -> String {
25        self.as_torrent_alert().message()
26    }
27
28    #[inline(always)]
29    pub fn tracker_url<'a>(&'a self) -> &'a str {
30        self.as_tracker_alert().tracker_url()
31    }
32
33    #[inline(always)]
34    pub fn local_endpoint(&self) {
35        self.as_tracker_alert().local_endpoint()
36    }
37
38    #[inline(always)]
39    pub fn failure_reason(&self) -> &str {
40        unsafe { tracker_error_alert_get_failure_reason(self.0) }
41    }
42
43    /// How many times in a row this tracker has failed.
44    #[inline(always)]
45    pub fn times_in_row(&self) -> i32 {
46        unsafe { tracker_error_alert_get_times_in_row(self.0) }
47    }
48
49    #[inline(always)]
50    pub fn error(&self) -> LtrsError {
51        unsafe { tracker_error_alert_get_error(self.0) }.into()
52    }
53
54    #[inline(always)]
55    pub fn op(&self) -> Operation {
56        unsafe { tracker_error_alert_get_op(self.0) }.into()
57    }
58
59    /// The bittorrent protocol version that was announced
60    #[inline(always)]
61    pub fn version(&self) -> ProtocolVersion {
62        ProtocolVersion::from_u8(unsafe { tracker_error_alert_get_version(self.0) })
63    }
64}