lt_rs/alerts/implementations/
peer_connect.rs

1use crate::alerts::PeerConnectAlert;
2use crate::alerts::peer_alert::{Endpoint, PeerId};
3use crate::alerts::types::{Direction, SocketType};
4use crate::ffi::alerts::peer_connect::ffi::{
5    peer_connect_alert_get_direction, peer_connect_alert_get_socket_type,
6};
7use crate::torrent_handle::TorrentHandle;
8
9impl PeerConnectAlert {
10    #[inline(always)]
11    pub fn handle(&self) -> TorrentHandle {
12        self.as_torrent_alert().handle()
13    }
14
15    #[inline(always)]
16    pub fn torrent_name<'a>(&'a self) -> &'a str {
17        self.as_torrent_alert().torrent_name()
18    }
19
20    #[inline(always)]
21    pub fn message(&self) -> String {
22        self.as_torrent_alert().message()
23    }
24
25    #[inline(always)]
26    pub fn pid(&self) -> PeerId {
27        self.as_peer_alert().peer_id()
28    }
29
30    #[inline(always)]
31    pub fn endpoint(&self) -> Endpoint {
32        self.as_peer_alert().endpoint()
33    }
34
35    #[inline(always)]
36    pub fn direction(&self) -> Direction {
37        Direction::from_u8(unsafe { peer_connect_alert_get_direction(self.0) })
38    }
39
40    #[inline(always)]
41    pub fn socket_type(&self) -> SocketType {
42        SocketType::from_u8(unsafe { peer_connect_alert_get_socket_type(self.0) })
43    }
44}