Make outgoing addr Option
This commit is contained in:
parent
23bd537dd7
commit
7640218488
3 changed files with 15 additions and 20 deletions
|
|
@ -66,7 +66,6 @@ use librqbit_core::{
|
||||||
torrent_metainfo::TorrentMetaV1Info,
|
torrent_metainfo::TorrentMetaV1Info,
|
||||||
};
|
};
|
||||||
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||||
use peer::OutgoingAddressType;
|
|
||||||
use peer_binary_protocol::{
|
use peer_binary_protocol::{
|
||||||
extended::{
|
extended::{
|
||||||
handshake::ExtendedHandshake, ut_metadata::UtMetadata, ut_pex::UtPex, ExtendedMessage,
|
handshake::ExtendedHandshake, ut_metadata::UtMetadata, ut_pex::UtPex, ExtendedMessage,
|
||||||
|
|
@ -932,7 +931,7 @@ impl<'a> PeerConnectionHandler for &'a PeerHandler {
|
||||||
self.state
|
self.state
|
||||||
.peers
|
.peers
|
||||||
.with_peer_mut(self.addr, "update outgoing addr", |peer| {
|
.with_peer_mut(self.addr, "update outgoing addr", |peer| {
|
||||||
peer.outgoing_address = OutgoingAddressType::Known(outgoing_addr)
|
peer.outgoing_address = Some(outgoing_addr)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,11 @@ pub(crate) type InflightRequest = ChunkInfo;
|
||||||
pub(crate) type PeerRx = UnboundedReceiver<WriterRequest>;
|
pub(crate) type PeerRx = UnboundedReceiver<WriterRequest>;
|
||||||
pub(crate) type PeerTx = UnboundedSender<WriterRequest>;
|
pub(crate) type PeerTx = UnboundedSender<WriterRequest>;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub(crate) enum OutgoingAddressType {
|
|
||||||
#[default]
|
|
||||||
Default,
|
|
||||||
None,
|
|
||||||
Known(SocketAddr),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub(crate) struct Peer {
|
pub(crate) struct Peer {
|
||||||
pub state: PeerStateNoMut,
|
pub state: PeerStateNoMut,
|
||||||
pub stats: stats::atomic::PeerStats,
|
pub stats: stats::atomic::PeerStats,
|
||||||
pub outgoing_address: OutgoingAddressType,
|
pub outgoing_address: Option<SocketAddr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Peer {
|
impl Peer {
|
||||||
|
|
@ -46,7 +38,14 @@ impl Peer {
|
||||||
Self {
|
Self {
|
||||||
state,
|
state,
|
||||||
stats: Default::default(),
|
stats: Default::default(),
|
||||||
outgoing_address: OutgoingAddressType::None,
|
outgoing_address: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_with_outgoing_address(addr: SocketAddr) -> Self {
|
||||||
|
Self {
|
||||||
|
outgoing_address: Some(addr),
|
||||||
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,18 +56,15 @@ impl Peer {
|
||||||
) -> Option<SocketAddr> {
|
) -> Option<SocketAddr> {
|
||||||
if let PeerState::NotNeeded = self.state.get() {
|
if let PeerState::NotNeeded = self.state.get() {
|
||||||
match self.outgoing_address {
|
match self.outgoing_address {
|
||||||
OutgoingAddressType::Default => {
|
None => None,
|
||||||
self.state.set(PeerState::Queued, counters);
|
Some(socket_addr) => {
|
||||||
Some(known_address)
|
|
||||||
}
|
|
||||||
OutgoingAddressType::None => None,
|
|
||||||
OutgoingAddressType::Known(socket_addr) => {
|
|
||||||
if known_address == socket_addr {
|
if known_address == socket_addr {
|
||||||
self.state.set(PeerState::Queued, counters);
|
self.state.set(PeerState::Queued, counters);
|
||||||
} else {
|
} else {
|
||||||
debug!(
|
debug!(
|
||||||
peer = known_address.to_string(),
|
peer = known_address.to_string(),
|
||||||
"peer will by retried on different address {}", socket_addr
|
outgoing_addr = socket_addr.to_string(),
|
||||||
|
"peer will by retried on different address",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Some(socket_addr)
|
Some(socket_addr)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ impl PeerStates {
|
||||||
match self.states.entry(addr) {
|
match self.states.entry(addr) {
|
||||||
Entry::Occupied(_) => None,
|
Entry::Occupied(_) => None,
|
||||||
Entry::Vacant(vac) => {
|
Entry::Vacant(vac) => {
|
||||||
vac.insert(Default::default());
|
vac.insert(Peer::new_with_outgoing_address(addr));
|
||||||
atomic_inc(&self.stats.queued);
|
atomic_inc(&self.stats.queued);
|
||||||
atomic_inc(&self.session_stats.peers.queued);
|
atomic_inc(&self.session_stats.peers.queued);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue