Commit 43872183 authored by nanamicat's avatar nanamicat

fix

parent 6c839e92
Pipeline #42417 failed with stages
in 5 minutes and 44 seconds
......@@ -180,7 +180,7 @@ version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e"
dependencies = [
"getrandom",
"getrandom 0.2.16",
"once_cell",
"tiny-keccak",
]
......@@ -327,6 +327,18 @@ dependencies = [
"wasi",
]
[[package]]
name = "getrandom"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasip2",
]
[[package]]
name = "hashbrown"
version = "0.14.5"
......@@ -648,6 +660,12 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "railgun-routing-server"
version = "0.1.0"
......@@ -667,20 +685,19 @@ dependencies = [
[[package]]
name = "rand"
version = "0.8.5"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core",
......@@ -688,11 +705,11 @@ dependencies = [
[[package]]
name = "rand_core"
version = "0.6.4"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
"getrandom 0.3.4",
]
[[package]]
......@@ -1126,6 +1143,15 @@ version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasip2"
version = "1.0.1+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "windows-link"
version = "0.2.1"
......@@ -1224,6 +1250,12 @@ dependencies = [
"memchr",
]
[[package]]
name = "wit-bindgen"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]]
name = "yaml-rust2"
version = "0.10.4"
......
......@@ -16,4 +16,4 @@ bincode = "2.0.1"
tower-http = { version = "0.6.8", features = ["cors"] }
tracing = "0.1.44"
tracing-subscriber = "0.3.22"
rand = "0.8"
rand = "0.9.2"
......@@ -3,8 +3,8 @@ use crate::data::RouterData;
use crate::protocol::{Downlink, Uplink};
use crate::router::Router;
use crate::settings::{Settings, TIMEOUT};
use ::config::Config;
use anyhow::{Context, Result};
use ::config::Config;
use config::Environment;
use net::SocketAddr;
use std::collections::BTreeMap;
......@@ -81,10 +81,12 @@ async fn main() -> Result<()> {
if updating.router_id != 0 && !routers.get(&updating.router_id).context("router not found")?.is_online() {
updating.router_id = 0;
}
tracing::info!("recv {:?}", uplink);
// 处理收到的消息
if let Some(router) = routers.get_mut(&uplink.id)
&& let Some(downlink) = router.on_message(&mut uplink, addr, &mut updating, now)
{
tracing::info!("sync to {}: {:?}", router.id, downlink);
send(&downlink, &mut buf, &socket, &addr).await?;
} else if updating.router_id == 0
&& let Some(router) = routers.get(&uplink.id)
......@@ -92,8 +94,9 @@ async fn main() -> Result<()> {
{
updating.router_id = router.id;
updating.message = downlink;
tracing::info!("command to {}: {:?}", router.id, updating.message);
send(&updating.message, &mut buf, &socket, &addr).await?;
routers.get_mut(&uplink.id).expect("").version += 1;
routers.get_mut(&uplink.id).context("router not found")?.version += 1;
}
}
}
......
......@@ -42,13 +42,4 @@ impl Quality {
cost: 0,
}
}
pub fn from(other: PeerQuality, cost: u32) -> Quality {
Quality {
delay: other.delay as i32,
jitter: other.jitter as u32,
reliability: other.reliability as f32 / 255.0,
cost,
}
}
}
......@@ -59,7 +59,7 @@ impl Router {
}
pub fn online(&mut self, addr: SocketAddr, now: Instant) {
if self.addr == None {
if self.addr.is_none() {
tracing::info!("router {} online", self.id);
}
self.addr = Some(addr);
......@@ -67,7 +67,7 @@ impl Router {
}
pub fn offline(&mut self) {
if self.addr != None {
if self.addr.is_some() {
tracing::info!("router {} offline", self.id);
}
self.addr = None;
......@@ -108,6 +108,8 @@ impl Router {
self.online(addr, now);
if updating.router_id == self.id {
updating.router_id = 0;
self.via.append(&mut updating.message.via);
self.plan.append(&mut updating.message.plan);
}
None
} else if !self.is_online() {
......@@ -142,11 +144,9 @@ impl Router {
.map(|r| (r, self.route_quality(to, r, routers, connections).metric()))
.collect();
let (best_router, best_metric) = candidate.iter().min_by_key(|(_, m)| m).unwrap();
if *best_metric == i32::MAX && current_router != to {
let best_router = if *best_metric == i32::MAX { to } else { best_router };
// 无论如何都不可达就标记为直连
changed_via.insert(to.id, to.id);
} else if current_router != *best_router && *best_metric + THROTTLE < current_metric {
if current_router != best_router && (*best_metric == i32::MAX || *best_metric + THROTTLE < current_metric) {
changed_via.insert(to.id, best_router.id);
}
}
......
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