mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_udp: add (failing) test for writing ipv6 announce responses
This commit is contained in:
parent
819821edf0
commit
0107b3a77e
1 changed files with 36 additions and 0 deletions
|
|
@ -155,6 +155,10 @@ impl TorrentMaps {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::{IpAddr, Ipv6Addr};
|
||||
|
||||
use crate::{common::MAX_PACKET_SIZE, config::Config};
|
||||
|
||||
#[test]
|
||||
fn test_peer_status_from_event_and_bytes_left() {
|
||||
use crate::common::*;
|
||||
|
|
@ -175,4 +179,36 @@ mod tests {
|
|||
assert_eq!(Seeding, f(AnnounceEvent::None, NumberOfBytes(0)));
|
||||
assert_eq!(Leeching, f(AnnounceEvent::None, NumberOfBytes(1)));
|
||||
}
|
||||
|
||||
// Assumes that announce response with maximum amount of ipv6 peers will
|
||||
// be the longest
|
||||
#[test]
|
||||
fn test_max_package_size() {
|
||||
use aquatic_udp_protocol::*;
|
||||
|
||||
let config = Config::default();
|
||||
|
||||
let peers = ::std::iter::repeat(ResponsePeer {
|
||||
ip_address: IpAddr::V6(Ipv6Addr::new(1, 1, 1, 1, 1, 1, 1, 1)),
|
||||
port: Port(1),
|
||||
})
|
||||
.take(config.protocol.max_response_peers)
|
||||
.collect();
|
||||
|
||||
let response = Response::Announce(AnnounceResponse {
|
||||
transaction_id: TransactionId(1),
|
||||
announce_interval: AnnounceInterval(1),
|
||||
seeders: NumberOfPeers(1),
|
||||
leechers: NumberOfPeers(1),
|
||||
peers,
|
||||
});
|
||||
|
||||
let mut buf = Vec::new();
|
||||
|
||||
response.write(&mut buf, IpVersion::IPv6).unwrap();
|
||||
|
||||
println!("Buffer len: {}", buf.len());
|
||||
|
||||
assert!(buf.len() <= MAX_PACKET_SIZE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue