Peer struct knows its addr
This commit is contained in:
parent
adc2ca97b3
commit
fa3e8d949b
2 changed files with 8 additions and 2 deletions
|
|
@ -381,6 +381,7 @@ impl TorrentStateLive {
|
||||||
Entry::Vacant(vac) => {
|
Entry::Vacant(vac) => {
|
||||||
atomic_inc(&self.peers.stats.seen);
|
atomic_inc(&self.peers.stats.seen);
|
||||||
let peer = Peer::new_live_for_incoming_connection(
|
let peer = Peer::new_live_for_incoming_connection(
|
||||||
|
*vac.key(),
|
||||||
Id20::new(checked_peer.handshake.peer_id),
|
Id20::new(checked_peer.handshake.peer_id),
|
||||||
tx.clone(),
|
tx.clone(),
|
||||||
&self.peers,
|
&self.peers,
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,9 @@ 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)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct Peer {
|
pub(crate) struct Peer {
|
||||||
|
pub addr: SocketAddr,
|
||||||
pub state: PeerStateNoMut,
|
pub state: PeerStateNoMut,
|
||||||
pub stats: stats::atomic::PeerStats,
|
pub stats: stats::atomic::PeerStats,
|
||||||
pub outgoing_address: Option<SocketAddr>,
|
pub outgoing_address: Option<SocketAddr>,
|
||||||
|
|
@ -27,6 +28,7 @@ pub(crate) struct Peer {
|
||||||
|
|
||||||
impl Peer {
|
impl Peer {
|
||||||
pub fn new_live_for_incoming_connection(
|
pub fn new_live_for_incoming_connection(
|
||||||
|
addr: SocketAddr,
|
||||||
peer_id: Id20,
|
peer_id: Id20,
|
||||||
tx: PeerTx,
|
tx: PeerTx,
|
||||||
counters: &PeerStates,
|
counters: &PeerStates,
|
||||||
|
|
@ -36,6 +38,7 @@ impl Peer {
|
||||||
counter.inc(&state.0);
|
counter.inc(&state.0);
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
|
addr,
|
||||||
state,
|
state,
|
||||||
stats: Default::default(),
|
stats: Default::default(),
|
||||||
outgoing_address: None,
|
outgoing_address: None,
|
||||||
|
|
@ -44,8 +47,10 @@ impl Peer {
|
||||||
|
|
||||||
pub fn new_with_outgoing_address(addr: SocketAddr) -> Self {
|
pub fn new_with_outgoing_address(addr: SocketAddr) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
addr,
|
||||||
outgoing_address: Some(addr),
|
outgoing_address: Some(addr),
|
||||||
..Default::default()
|
stats: Default::default(),
|
||||||
|
state: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue