mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
aquatic_udp: glommio: setup timer to update peer_valid_until
This commit is contained in:
parent
184a2c291b
commit
1dcc48ee67
2 changed files with 13 additions and 4 deletions
|
|
@ -15,6 +15,7 @@ path = "src/lib/lib.rs"
|
||||||
name = "aquatic_udp"
|
name = "aquatic_udp"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["with-glommio"]
|
||||||
with-glommio = ["glommio", "futures-lite"]
|
with-glommio = ["glommio", "futures-lite"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,16 @@ async fn handle_request_stream<S>(
|
||||||
{
|
{
|
||||||
let mut rng = SmallRng::from_entropy();
|
let mut rng = SmallRng::from_entropy();
|
||||||
|
|
||||||
// Needs to be updated periodically: use timer?
|
let max_peer_age = config.cleaning.max_peer_age;
|
||||||
let peer_valid_until = ValidUntil::new(config.cleaning.max_peer_age);
|
let peer_valid_until = Rc::new(RefCell::new(ValidUntil::new(max_peer_age)));
|
||||||
|
|
||||||
|
TimerActionRepeat::repeat(enclose!((peer_valid_until) move || {
|
||||||
|
enclose!((peer_valid_until) move || async move {
|
||||||
|
*peer_valid_until.borrow_mut() = ValidUntil::new(max_peer_age);
|
||||||
|
|
||||||
|
Some(Duration::from_secs(1))
|
||||||
|
})()
|
||||||
|
}));
|
||||||
|
|
||||||
while let Some((producer_index, request, addr)) = stream.next().await {
|
while let Some((producer_index, request, addr)) = stream.next().await {
|
||||||
let response = match addr.ip() {
|
let response = match addr.ip() {
|
||||||
|
|
@ -79,7 +87,7 @@ async fn handle_request_stream<S>(
|
||||||
&mut torrents.borrow_mut().ipv4,
|
&mut torrents.borrow_mut().ipv4,
|
||||||
request,
|
request,
|
||||||
ip,
|
ip,
|
||||||
peer_valid_until,
|
peer_valid_until.borrow().to_owned(),
|
||||||
),
|
),
|
||||||
IpAddr::V6(ip) => handle_announce_request(
|
IpAddr::V6(ip) => handle_announce_request(
|
||||||
&config,
|
&config,
|
||||||
|
|
@ -87,7 +95,7 @@ async fn handle_request_stream<S>(
|
||||||
&mut torrents.borrow_mut().ipv6,
|
&mut torrents.borrow_mut().ipv6,
|
||||||
request,
|
request,
|
||||||
ip,
|
ip,
|
||||||
peer_valid_until,
|
peer_valid_until.borrow().to_owned(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue