Commit 5ab08d3c authored by nanamicat's avatar nanamicat

online

parent eb9f9b66
Pipeline #42003 passed with stages
in 44 seconds
......@@ -37,7 +37,7 @@ async fn main() -> Result<()> {
// let routers_map: BTreeMap<u8, RouterData> = routers_data.iter().map(|r| (r.id, r.clone())).collect();
// let routers_map = Arc::new(routers_map);
let routers: BTreeMap<u8, Router> = routers_data.iter().map(|c| (c.id, Router::new(c, &connections))).collect();
let routers: BTreeMap<u8, Router> = routers_data.iter().map(|c| (c.id, Router::new(c, &routers_data, &connections))).collect();
let routers = Arc::new(RwLock::new(routers));
// let gateway_groups_data: Vec<GatewayGroup> = serde_json::from_str(&std::fs::read_to_string(
// "../import/data/GatewayGroup.json",
......
use crate::UpdatingState;
use crate::data::{ConnectionData, RouterData};
use crate::protocol::{Change, PeerQuality, Report};
use crate::quality::Quality;
use crate::settings::THROTTLE;
use crate::UpdatingState;
use serde::Serialize;
use std::collections::BTreeMap;
use std::net::SocketAddr;
......@@ -34,7 +34,7 @@ impl PartialEq<Self> for Router {
impl Eq for Router {}
impl Router {
pub fn new(data: &RouterData, connections: &BTreeMap<u8, BTreeMap<u8, ConnectionData>>) -> Self {
pub fn new(data: &RouterData, routers: &Vec<RouterData>, connections: &BTreeMap<u8, BTreeMap<u8, ConnectionData>>) -> Self {
Self {
id: data.id,
seq: 0,
......@@ -52,7 +52,7 @@ impl Router {
)
})
.collect(),
via: BTreeMap::new(),
via: routers.iter().filter(|r| r.id != data.id).map(|r| (r.id, r.id)).collect(),
plan: BTreeMap::new(),
time: Instant::now(),
addr: None,
......@@ -161,6 +161,7 @@ impl Router {
let mut current = self;
let mut next = via;
loop {
// 不通的情况 via 会标记为直连,实际不可达
match next.peers.get(&current.id) {
None => return Quality::UNREACHABLE,
Some(quality) => {
......@@ -179,8 +180,7 @@ impl Router {
current = next;
next = &routers[&current.via[&to.id]];
// via 如果不可达会指向自己
// 并且也检查环路
// 检查环路
if route.contains(&next) {
return Quality::UNREACHABLE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment