some events fire correctly
Some checks are pending
continuous-integration/drone/push Build was killed
Some checks are pending
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
34e04ae726
commit
edf635ca9b
@ -28,10 +28,6 @@ pub(crate) fn gen_events(
|
||||
.collect::<HashMap<&str, (Option<&Peer>, Option<&Peer>)>>()
|
||||
};
|
||||
for (_id, (prev, cur)) in side_by_side {
|
||||
/*if id != "HhRgEL2xsnEIqThSTUKLGaTXusorM1MFdjSSYvzBynY=" {
|
||||
continue;
|
||||
}*/
|
||||
println!("{} p {} c {}", _id, prev.is_some(), cur.is_some());
|
||||
match (prev, cur) {
|
||||
(Some(prev), Some(cur)) if prev.endpoint != cur.endpoint => {
|
||||
if let (Some(prev_addr), Some(_)) = (prev.endpoint, cur.endpoint) {
|
||||
@ -39,27 +35,23 @@ pub(crate) fn gen_events(
|
||||
}
|
||||
}
|
||||
(Some(prev), Some(cur)) => {
|
||||
//shake > timeout && prev.shake < timeout -> listeners.iter().for_each(|l| l.disconnected(&cur));
|
||||
//shake < timeout && (prev.shake is none || prev.shake > timeout) -> listeners.iter().for_each(|l| l.connected(&cur));
|
||||
if let (Some(shake), Some(pshake)) = (cur.last_handshake, prev.last_handshake) {
|
||||
if shake > timeout && pshake < timeout {
|
||||
let timedout = |peer: &Peer| match peer.last_handshake_rel() {
|
||||
Some(shake) if shake < timeout => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
//if _id == "HhRgEL2xsnEIqThSTUKLGaTXusorM1MFdjSSYvzBynY=" { dbg!((cur.last_handshake_rel(),timedout(&prev) , timedout(&cur))); }
|
||||
|
||||
if !timedout(&prev) && timedout(&cur) {
|
||||
listeners.disconnected(&cur);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some(shake) = cur.last_handshake {
|
||||
if shake > timeout && prev
|
||||
.last_handshake
|
||||
.map(|shake| shake > timeout)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
|
||||
if timedout(&prev) && !timedout(&cur) {
|
||||
listeners.connected(&cur);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
(None, Some(cur)) => listeners.added(&cur),
|
||||
(Some(prev), None) => listeners.removed(&prev),
|
||||
(None, Some(cur)) => (), //listeners.added(&cur),
|
||||
(Some(prev), None) => (), //listeners.removed(&prev),
|
||||
(None, Some(_cur)) => (),
|
||||
(Some(_prev), None) => (),
|
||||
fail => {
|
||||
@ -156,12 +148,13 @@ mod test {
|
||||
let key = b2h(bkey);
|
||||
Peer::from_kv(&vec![
|
||||
("public_key".to_string(), key.clone()),
|
||||
(
|
||||
/*(
|
||||
"last_handshake_time_nsec".to_string(),
|
||||
(1000 * 1000 * 1).to_string(),
|
||||
),
|
||||
),*/
|
||||
("endpoint".to_string(), "1.1.1.1:22222".to_string()),
|
||||
]).unwrap()
|
||||
])
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -184,7 +177,7 @@ mod test {
|
||||
assert!(calls.borrow().len() == 1);
|
||||
|
||||
let (listener, calls) = listeners();
|
||||
gen_events(&prev, &cur, &listener, time::Duration::from_secs(3));
|
||||
gen_events(&prev, &cur, &listener, time::Duration::from_secs(10));
|
||||
assert_eq!(
|
||||
vec![["rem", &peer.public_key].join(" ")],
|
||||
calls.borrow().clone()
|
||||
@ -200,7 +193,7 @@ mod test {
|
||||
|
||||
prev.insert(peer_prev.public_key.clone(), peer_prev.clone());
|
||||
|
||||
gen_events(&prev, &cur, &listener, time::Duration::from_secs(3));
|
||||
gen_events(&prev, &cur, &listener, time::Duration::from_secs(10));
|
||||
|
||||
assert_eq!(
|
||||
vec![["rom", &peer.public_key].join(" ")],
|
||||
@ -211,14 +204,25 @@ mod test {
|
||||
|
||||
let mut peer_prev = peer.clone();
|
||||
|
||||
peer_cur.last_handshake = Some(time::Duration::from_secs(1));
|
||||
peer_cur.last_handshake = Some(time::Duration::from_secs(5));
|
||||
|
||||
cur.insert(peer_cur.public_key.clone(), peer_cur);
|
||||
cur.insert(peer_cur.public_key.clone(), peer_cur.clone());
|
||||
prev.insert(peer_prev.public_key.clone(), peer_prev.clone());
|
||||
|
||||
gen_events(&cur, &prev, &listener, time::Duration::from_secs(3));
|
||||
gen_events(&cur, &prev, &listener, time::Duration::from_secs(10));
|
||||
|
||||
assert_eq!(
|
||||
vec![["rom", &peer.public_key].join(" ")],
|
||||
vec![["con", &peer.public_key].join(" ")],
|
||||
calls.borrow().clone()
|
||||
);
|
||||
|
||||
calls.borrow_mut().clear();
|
||||
|
||||
//Other way around should be a disconnect
|
||||
gen_events(&prev, &cur, &listener, time::Duration::from_secs(3));
|
||||
|
||||
assert_eq!(
|
||||
vec![["dis", &peer.public_key].join(" ")],
|
||||
calls.borrow().clone()
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user