mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
ws: swarm: remove peer ValidUntil update task, just create when needed
This commit is contained in:
parent
36954e5f48
commit
d4c95d89c0
2 changed files with 2 additions and 19 deletions
|
|
@ -125,25 +125,8 @@ async fn handle_request_stream<S>(
|
||||||
S: futures_lite::Stream<Item = (InMessageMeta, InMessage)> + ::std::marker::Unpin,
|
S: futures_lite::Stream<Item = (InMessageMeta, InMessage)> + ::std::marker::Unpin,
|
||||||
{
|
{
|
||||||
let rng = Rc::new(RefCell::new(SmallRng::from_entropy()));
|
let rng = Rc::new(RefCell::new(SmallRng::from_entropy()));
|
||||||
|
|
||||||
let max_peer_age = config.cleaning.max_peer_age;
|
|
||||||
let peer_valid_until = Rc::new(RefCell::new(ValidUntil::new(
|
|
||||||
server_start_instant,
|
|
||||||
max_peer_age,
|
|
||||||
)));
|
|
||||||
|
|
||||||
// Periodically update peer_valid_until
|
|
||||||
TimerActionRepeat::repeat(enclose!((peer_valid_until) move || {
|
|
||||||
enclose!((peer_valid_until) move || async move {
|
|
||||||
*peer_valid_until.borrow_mut() = ValidUntil::new(server_start_instant, max_peer_age);
|
|
||||||
|
|
||||||
Some(Duration::from_secs(1))
|
|
||||||
})()
|
|
||||||
}));
|
|
||||||
|
|
||||||
let config = &config;
|
let config = &config;
|
||||||
let torrents = &torrents;
|
let torrents = &torrents;
|
||||||
let peer_valid_until = &peer_valid_until;
|
|
||||||
let rng = &rng;
|
let rng = &rng;
|
||||||
let out_message_senders = &out_message_senders;
|
let out_message_senders = &out_message_senders;
|
||||||
|
|
||||||
|
|
@ -160,7 +143,6 @@ async fn handle_request_stream<S>(
|
||||||
&mut rng.borrow_mut(),
|
&mut rng.borrow_mut(),
|
||||||
&mut out_messages,
|
&mut out_messages,
|
||||||
server_start_instant,
|
server_start_instant,
|
||||||
peer_valid_until.borrow().to_owned(),
|
|
||||||
meta,
|
meta,
|
||||||
request,
|
request,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,6 @@ impl TorrentMaps {
|
||||||
rng: &mut SmallRng,
|
rng: &mut SmallRng,
|
||||||
out_messages: &mut Vec<(OutMessageMeta, OutMessage)>,
|
out_messages: &mut Vec<(OutMessageMeta, OutMessage)>,
|
||||||
server_start_instant: ServerStartInstant,
|
server_start_instant: ServerStartInstant,
|
||||||
valid_until: ValidUntil,
|
|
||||||
request_sender_meta: InMessageMeta,
|
request_sender_meta: InMessageMeta,
|
||||||
request: AnnounceRequest,
|
request: AnnounceRequest,
|
||||||
) {
|
) {
|
||||||
|
|
@ -72,6 +71,8 @@ impl TorrentMaps {
|
||||||
self.ipv6.entry(request.info_hash).or_default()
|
self.ipv6.entry(request.info_hash).or_default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let valid_until = ValidUntil::new(server_start_instant, config.cleaning.max_peer_age);
|
||||||
|
|
||||||
// If there is already a peer with this peer_id, check that connection id
|
// If there is already a peer with this peer_id, check that connection id
|
||||||
// is same as that of request sender. Otherwise, ignore request. Since
|
// is same as that of request sender. Otherwise, ignore request. Since
|
||||||
// peers have access to each others peer_id's, they could send requests
|
// peers have access to each others peer_id's, they could send requests
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue