| 744 | } |
| 745 | |
| 746 | pub fn update_latency(host: &str, latency: i64) { |
| 747 | ONLINE.lock().unwrap().insert(host.to_owned(), latency); |
| 748 | let mut host = "".to_owned(); |
| 749 | let mut delay = i64::MAX; |
| 750 | for (tmp_host, tmp_delay) in ONLINE.lock().unwrap().iter() { |
| 751 | if tmp_delay > &0 && tmp_delay < &delay { |
| 752 | delay = *tmp_delay; |
| 753 | host = tmp_host.to_string(); |
| 754 | } |
| 755 | } |
| 756 | if !host.is_empty() { |
| 757 | let mut config = CONFIG2.write().unwrap(); |
| 758 | if host != config.rendezvous_server { |
| 759 | log::debug!("Update rendezvous_server in config to {}", host); |
| 760 | log::debug!("{:?}", *ONLINE.lock().unwrap()); |
| 761 | config.rendezvous_server = host; |
| 762 | config.store(); |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | pub fn set_id(id: &str) { |
| 768 | let mut config = CONFIG.write().unwrap(); |