lt_rs/alerts/implementations/
invalid_request.rs

1use crate::alerts::InvalidRequestAlert;
2use crate::alerts::peer_alert::{Endpoint, PeerId};
3use crate::ffi::alerts::invalid_request::ffi::{
4    invalid_request_alert_get_peer_interested, invalid_request_alert_get_request,
5    invalid_request_alert_get_we_have, invalid_request_alert_get_withheld,
6};
7use crate::ffi::ffi::PeerRequest;
8use crate::torrent_handle::TorrentHandle;
9
10impl InvalidRequestAlert {
11    #[inline(always)]
12    pub fn handle(&self) -> TorrentHandle {
13        self.as_torrent_alert().handle()
14    }
15
16    #[inline(always)]
17    pub fn torrent_name<'a>(&'a self) -> &'a str {
18        self.as_torrent_alert().torrent_name()
19    }
20
21    #[inline(always)]
22    pub fn message(&self) -> String {
23        self.as_torrent_alert().message()
24    }
25
26    #[inline(always)]
27    pub fn pid(&self) -> PeerId {
28        self.as_peer_alert().peer_id()
29    }
30
31    #[inline(always)]
32    pub fn endpoint(&self) -> Endpoint {
33        self.as_peer_alert().endpoint()
34    }
35
36    /// The request we received from the peer
37    #[inline(always)]
38    pub fn request(&self) -> PeerRequest {
39        unsafe { invalid_request_alert_get_request(self.0) }
40    }
41
42    /// True if we have this piece
43    #[inline(always)]
44    pub fn we_have(&self) -> bool {
45        unsafe { invalid_request_alert_get_we_have(self.0) }
46    }
47
48    /// True if the peer indicated that it was interested to download before sending the request
49    #[inline(always)]
50    pub fn peer_interested(&self) -> bool {
51        unsafe { invalid_request_alert_get_peer_interested(self.0) }
52    }
53
54    /// If this is true, the peer is not allowed to download this piece because of super-seeding rules
55    #[inline(always)]
56    pub fn withheld(&self) -> bool {
57        unsafe { invalid_request_alert_get_withheld(self.0) }
58    }
59}