mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +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
|
|
@ -1,13 +1,13 @@
|
|||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
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};
|
||||
use either::Either;
|
||||
use smartstring::{LazyCompact, SmartString};
|
||||
|
||||
pub use aquatic_common::{convert_ipv4_mapped_ipv6, ValidUntil};
|
||||
pub use aquatic_common::ValidUntil;
|
||||
|
||||
use aquatic_http_protocol::common::*;
|
||||
use aquatic_http_protocol::response::ResponsePeer;
|
||||
|
|
@ -31,13 +31,13 @@ pub struct ConnectionId(pub usize);
|
|||
pub enum ChannelRequest {
|
||||
Announce {
|
||||
request: AnnounceRequest,
|
||||
peer_addr: SocketAddr,
|
||||
peer_addr: CanonicalSocketAddr,
|
||||
connection_id: ConnectionId,
|
||||
response_consumer_id: ConsumerId,
|
||||
},
|
||||
Scrape {
|
||||
request: ScrapeRequest,
|
||||
peer_addr: SocketAddr,
|
||||
peer_addr: CanonicalSocketAddr,
|
||||
connection_id: ConnectionId,
|
||||
response_consumer_id: ConsumerId,
|
||||
},
|
||||
|
|
@ -47,12 +47,12 @@ pub enum ChannelRequest {
|
|||
pub enum ChannelResponse {
|
||||
Announce {
|
||||
response: AnnounceResponse,
|
||||
peer_addr: SocketAddr,
|
||||
peer_addr: CanonicalSocketAddr,
|
||||
connection_id: ConnectionId,
|
||||
},
|
||||
Scrape {
|
||||
response: ScrapeResponse,
|
||||
peer_addr: SocketAddr,
|
||||
peer_addr: CanonicalSocketAddr,
|
||||
connection_id: ConnectionId,
|
||||
},
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ impl ChannelResponse {
|
|||
Self::Scrape { connection_id, .. } => *connection_id,
|
||||
}
|
||||
}
|
||||
pub fn get_peer_addr(&self) -> SocketAddr {
|
||||
pub fn get_peer_addr(&self) -> CanonicalSocketAddr {
|
||||
match self {
|
||||
Self::Announce { peer_addr, .. } => *peer_addr,
|
||||
Self::Scrape { peer_addr, .. } => *peer_addr,
|
||||
|
|
@ -82,7 +82,7 @@ pub struct ConnectionMeta {
|
|||
/// Index of socket worker responsible for this connection. Required for
|
||||
/// sending back response through correct channel to correct worker.
|
||||
pub response_consumer_id: ConsumerId,
|
||||
pub peer_addr: SocketAddr,
|
||||
pub peer_addr: CanonicalSocketAddr,
|
||||
/// Connection id local to socket worker
|
||||
pub connection_id: ConnectionId,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,11 +159,7 @@ pub fn handle_announce_request(
|
|||
meta: ConnectionMeta,
|
||||
request: AnnounceRequest,
|
||||
) -> AnnounceResponse {
|
||||
let peer_ip = convert_ipv4_mapped_ipv6(meta.peer_addr.ip());
|
||||
|
||||
::log::debug!("peer ip: {:?}", peer_ip);
|
||||
|
||||
match peer_ip {
|
||||
match meta.peer_addr.get().ip() {
|
||||
IpAddr::V4(peer_ip_address) => {
|
||||
let torrent_data: &mut TorrentData<Ipv4Addr> =
|
||||
torrent_maps.ipv4.entry(request.info_hash).or_default();
|
||||
|
|
@ -323,7 +319,7 @@ pub fn handle_scrape_request(
|
|||
files: BTreeMap::new(),
|
||||
};
|
||||
|
||||
let peer_ip = convert_ipv4_mapped_ipv6(meta.peer_addr.ip());
|
||||
let peer_ip = meta.peer_addr.get().ip();
|
||||
|
||||
// If request.info_hashes is empty, don't return scrape for all
|
||||
// torrents, even though reference server does it. It is too expensive.
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use aquatic_common::access_list::{create_access_list_cache, AccessListArcSwap, AccessListCache};
|
||||
use aquatic_common::CanonicalSocketAddr;
|
||||
use aquatic_http_protocol::common::InfoHash;
|
||||
use aquatic_http_protocol::request::{Request, RequestParseError, ScrapeRequest};
|
||||
use aquatic_http_protocol::response::{
|
||||
|
|
@ -170,7 +170,7 @@ struct Connection {
|
|||
response_receiver: LocalReceiver<ChannelResponse>,
|
||||
response_consumer_id: ConsumerId,
|
||||
stream: TlsStream<TcpStream>,
|
||||
peer_addr: SocketAddr,
|
||||
peer_addr: CanonicalSocketAddr,
|
||||
connection_id: ConnectionId,
|
||||
request_buffer: [u8; REQUEST_BUFFER_SIZE],
|
||||
request_buffer_position: usize,
|
||||
|
|
@ -191,6 +191,7 @@ impl Connection {
|
|||
let peer_addr = stream
|
||||
.peer_addr()
|
||||
.map_err(|err| anyhow::anyhow!("Couldn't get peer addr: {:?}", err))?;
|
||||
let peer_addr = CanonicalSocketAddr::new(peer_addr);
|
||||
|
||||
let tls_acceptor: TlsAcceptor = tls_config.into();
|
||||
let stream = tls_acceptor.accept(stream).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue