mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
bittorrent_udp: improve code formatting and imports
This commit is contained in:
parent
fe85901021
commit
b32046e768
4 changed files with 41 additions and 43 deletions
|
|
@ -1,23 +1,23 @@
|
||||||
use crate::types;
|
use crate::types::AnnounceEvent;
|
||||||
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn event_from_i32(i: i32) -> types::AnnounceEvent {
|
pub fn event_from_i32(i: i32) -> AnnounceEvent {
|
||||||
match i {
|
match i {
|
||||||
1 => types::AnnounceEvent::Completed,
|
1 => AnnounceEvent::Completed,
|
||||||
2 => types::AnnounceEvent::Started,
|
2 => AnnounceEvent::Started,
|
||||||
3 => types::AnnounceEvent::Stopped,
|
3 => AnnounceEvent::Stopped,
|
||||||
_ => types::AnnounceEvent::None
|
_ => AnnounceEvent::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn event_to_i32(event: types::AnnounceEvent) -> i32 {
|
pub fn event_to_i32(event: AnnounceEvent) -> i32 {
|
||||||
match event {
|
match event {
|
||||||
types::AnnounceEvent::None => 0,
|
AnnounceEvent::None => 0,
|
||||||
types::AnnounceEvent::Completed => 1,
|
AnnounceEvent::Completed => 1,
|
||||||
types::AnnounceEvent::Started => 2,
|
AnnounceEvent::Started => 2,
|
||||||
types::AnnounceEvent::Stopped => 3
|
AnnounceEvent::Stopped => 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
use std::net;
|
use std::net::IpAddr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||||
|
|
@ -45,8 +44,8 @@ pub struct PeerKey (pub u32);
|
||||||
|
|
||||||
#[derive(Hash, PartialEq, Eq, Clone, Debug)]
|
#[derive(Hash, PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct ResponsePeer {
|
pub struct ResponsePeer {
|
||||||
pub ip_address: net::IpAddr,
|
pub ip_address: IpAddr,
|
||||||
pub port: Port,
|
pub port: Port,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,30 +13,30 @@ pub enum AnnounceEvent {
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct ConnectRequest {
|
pub struct ConnectRequest {
|
||||||
pub transaction_id: TransactionId
|
pub transaction_id: TransactionId
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct AnnounceRequest {
|
pub struct AnnounceRequest {
|
||||||
pub connection_id: ConnectionId,
|
pub connection_id: ConnectionId,
|
||||||
pub transaction_id: TransactionId,
|
pub transaction_id: TransactionId,
|
||||||
pub info_hash: InfoHash,
|
pub info_hash: InfoHash,
|
||||||
pub peer_id: PeerId,
|
pub peer_id: PeerId,
|
||||||
pub bytes_downloaded: NumberOfBytes,
|
pub bytes_downloaded: NumberOfBytes,
|
||||||
pub bytes_uploaded: NumberOfBytes,
|
pub bytes_uploaded: NumberOfBytes,
|
||||||
pub bytes_left: NumberOfBytes,
|
pub bytes_left: NumberOfBytes,
|
||||||
pub event: AnnounceEvent,
|
pub event: AnnounceEvent,
|
||||||
pub ip_address: Option<Ipv4Addr>,
|
pub ip_address: Option<Ipv4Addr>,
|
||||||
pub key: PeerKey,
|
pub key: PeerKey,
|
||||||
pub peers_wanted: NumberOfPeers,
|
pub peers_wanted: NumberOfPeers,
|
||||||
pub port: Port
|
pub port: Port
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct ScrapeRequest {
|
pub struct ScrapeRequest {
|
||||||
pub connection_id: ConnectionId,
|
pub connection_id: ConnectionId,
|
||||||
pub transaction_id: TransactionId,
|
pub transaction_id: TransactionId,
|
||||||
pub info_hashes: Vec<InfoHash>
|
pub info_hashes: Vec<InfoHash>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,38 @@
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
||||||
pub struct TorrentScrapeStatistics {
|
pub struct TorrentScrapeStatistics {
|
||||||
pub seeders: NumberOfPeers,
|
pub seeders: NumberOfPeers,
|
||||||
pub completed: NumberOfDownloads,
|
pub completed: NumberOfDownloads,
|
||||||
pub leechers: NumberOfPeers
|
pub leechers: NumberOfPeers
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct ConnectResponse {
|
pub struct ConnectResponse {
|
||||||
pub connection_id: ConnectionId,
|
pub connection_id: ConnectionId,
|
||||||
pub transaction_id: TransactionId
|
pub transaction_id: TransactionId
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct AnnounceResponse {
|
pub struct AnnounceResponse {
|
||||||
pub transaction_id: TransactionId,
|
pub transaction_id: TransactionId,
|
||||||
pub announce_interval: AnnounceInterval,
|
pub announce_interval: AnnounceInterval,
|
||||||
pub leechers: NumberOfPeers,
|
pub leechers: NumberOfPeers,
|
||||||
pub seeders: NumberOfPeers,
|
pub seeders: NumberOfPeers,
|
||||||
pub peers: Vec<ResponsePeer>
|
pub peers: Vec<ResponsePeer>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct ScrapeResponse {
|
pub struct ScrapeResponse {
|
||||||
pub transaction_id: TransactionId,
|
pub transaction_id: TransactionId,
|
||||||
pub torrent_stats: Vec<TorrentScrapeStatistics>
|
pub torrent_stats: Vec<TorrentScrapeStatistics>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct ErrorResponse {
|
pub struct ErrorResponse {
|
||||||
pub transaction_id: TransactionId,
|
pub transaction_id: TransactionId,
|
||||||
pub message: String
|
pub message: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue