mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
udp: use action 1 for IPv6 announce responses; refactor protocol code
According to BEP015, action 1 is to be used.
This commit is contained in:
parent
8e7f8425f9
commit
903010dbe1
6 changed files with 99 additions and 213 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::hash::Hash;
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -14,22 +14,6 @@ use crate::config::Config;
|
|||
|
||||
pub const MAX_PACKET_SIZE: usize = 8192;
|
||||
|
||||
pub trait Ip: Hash + PartialEq + Eq + Clone + Copy {
|
||||
fn ip_addr(self) -> IpAddr;
|
||||
}
|
||||
|
||||
impl Ip for Ipv4Addr {
|
||||
fn ip_addr(self) -> IpAddr {
|
||||
IpAddr::V4(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ip for Ipv6Addr {
|
||||
fn ip_addr(self) -> IpAddr {
|
||||
IpAddr::V6(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PendingScrapeRequest {
|
||||
pub slab_key: usize,
|
||||
|
|
@ -50,8 +34,8 @@ pub enum ConnectedRequest {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum ConnectedResponse {
|
||||
AnnounceIpv4(AnnounceResponseIpv4),
|
||||
AnnounceIpv6(AnnounceResponseIpv6),
|
||||
AnnounceIpv4(AnnounceResponse<Ipv4Addr>),
|
||||
AnnounceIpv6(AnnounceResponse<Ipv6Addr>),
|
||||
Scrape(PendingScrapeResponse),
|
||||
}
|
||||
|
||||
|
|
@ -234,14 +218,14 @@ mod tests {
|
|||
|
||||
let config = Config::default();
|
||||
|
||||
let peers = ::std::iter::repeat(ResponsePeerIpv6 {
|
||||
let peers = ::std::iter::repeat(ResponsePeer {
|
||||
ip_address: Ipv6Addr::new(1, 1, 1, 1, 1, 1, 1, 1),
|
||||
port: Port(1),
|
||||
})
|
||||
.take(config.protocol.max_response_peers)
|
||||
.collect();
|
||||
|
||||
let response = Response::AnnounceIpv6(AnnounceResponseIpv6 {
|
||||
let response = Response::AnnounceIpv6(AnnounceResponse {
|
||||
transaction_id: TransactionId(1),
|
||||
announce_interval: AnnounceInterval(1),
|
||||
seeders: NumberOfPeers(1),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue