mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
Use CanonicalSocketAddr in ws and http; remove old option from common
This commit is contained in:
parent
380ca222de
commit
8889ab586c
9 changed files with 36 additions and 62 deletions
|
|
@ -16,7 +16,7 @@ pub fn handle_announce_request(
|
|||
request_sender_meta: ConnectionMeta,
|
||||
request: AnnounceRequest,
|
||||
) {
|
||||
let torrent_data: &mut TorrentData = if request_sender_meta.converted_peer_ip.is_ipv4() {
|
||||
let torrent_data: &mut TorrentData = if request_sender_meta.peer_addr.is_ipv4() {
|
||||
torrent_maps.ipv4.entry(request.info_hash).or_default()
|
||||
} else {
|
||||
torrent_maps.ipv6.entry(request.info_hash).or_default()
|
||||
|
|
@ -25,11 +25,9 @@ pub fn handle_announce_request(
|
|||
// If there is already a peer with this peer_id, check that socket
|
||||
// addr is same as that of request sender. Otherwise, ignore request.
|
||||
// Since peers have access to each others peer_id's, they could send
|
||||
// requests using them, causing all sorts of issues. Checking naive
|
||||
// (non-converted) socket addresses is enough, since state is split
|
||||
// on converted peer ip.
|
||||
// requests using them, causing all sorts of issues.
|
||||
if let Some(previous_peer) = torrent_data.peers.get(&request.peer_id) {
|
||||
if request_sender_meta.naive_peer_addr != previous_peer.connection_meta.naive_peer_addr {
|
||||
if request_sender_meta.peer_addr != previous_peer.connection_meta.peer_addr {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -167,7 +165,7 @@ pub fn handle_scrape_request(
|
|||
files: HashMap::with_capacity(num_to_take),
|
||||
};
|
||||
|
||||
let torrent_map: &mut TorrentMap = if meta.converted_peer_ip.is_ipv4() {
|
||||
let torrent_map: &mut TorrentMap = if meta.peer_addr.is_ipv4() {
|
||||
&mut torrent_maps.ipv4
|
||||
} else {
|
||||
&mut torrent_maps.ipv6
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ pub mod handlers;
|
|||
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
||||
use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap, AccessListCache};
|
||||
use aquatic_common::AHashIndexMap;
|
||||
use aquatic_common::{AHashIndexMap, CanonicalSocketAddr};
|
||||
|
||||
pub use aquatic_common::ValidUntil;
|
||||
|
||||
|
|
@ -30,10 +29,7 @@ pub struct ConnectionMeta {
|
|||
/// sending back response through correct channel to correct worker.
|
||||
pub out_message_consumer_id: ConsumerId,
|
||||
pub connection_id: ConnectionId,
|
||||
/// Peer address as received from socket, meaning it wasn't converted to
|
||||
/// an IPv4 address if it was a IPv4-mapped IPv6 address
|
||||
pub naive_peer_addr: SocketAddr,
|
||||
pub converted_peer_ip: IpAddr,
|
||||
pub peer_addr: CanonicalSocketAddr,
|
||||
pub pending_scrape_id: Option<PendingScrapeId>,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue