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,
|
||||
};
|
||||
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use peer::OutgoingAddressType;
|
||||
use peer_binary_protocol::{
|
||||
extended::{
|
||||
handshake::ExtendedHandshake, ut_metadata::UtMetadata, ut_pex::UtPex, ExtendedMessage,
|
||||
|
|
@ -932,7 +931,7 @@ impl<'a> PeerConnectionHandler for &'a PeerHandler {
|
|||
self.state
|
||||
.peers
|
||||
.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 PeerTx = UnboundedSender<WriterRequest>;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) enum OutgoingAddressType {
|
||||
#[default]
|
||||
Default,
|
||||
None,
|
||||
Known(SocketAddr),
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct Peer {
|
||||
pub state: PeerStateNoMut,
|
||||
pub stats: stats::atomic::PeerStats,
|
||||
pub outgoing_address: OutgoingAddressType,
|
||||
pub outgoing_address: Option<SocketAddr>,
|
||||
}
|
||||
|
||||
impl Peer {
|
||||
|
|
@ -46,7 +38,14 @@ impl Peer {
|
|||
Self {
|
||||
state,
|
||||
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> {
|
||||
if let PeerState::NotNeeded = self.state.get() {
|
||||
match self.outgoing_address {
|
||||
OutgoingAddressType::Default => {
|
||||
self.state.set(PeerState::Queued, counters);
|
||||
Some(known_address)
|
||||
}
|
||||
OutgoingAddressType::None => None,
|
||||
OutgoingAddressType::Known(socket_addr) => {
|
||||
None => None,
|
||||
Some(socket_addr) => {
|
||||
if known_address == socket_addr {
|
||||
self.state.set(PeerState::Queued, counters);
|
||||
} else {
|
||||
debug!(
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ impl PeerStates {
|
|||
match self.states.entry(addr) {
|
||||
Entry::Occupied(_) => None,
|
||||
Entry::Vacant(vac) => {
|
||||
vac.insert(Default::default());
|
||||
vac.insert(Peer::new_with_outgoing_address(addr));
|
||||
atomic_inc(&self.stats.queued);
|
||||
atomic_inc(&self.session_stats.peers.queued);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue