forward original peer info in ospf route (#589)

prost doesn't support unknown field, and these info may be lost when
they go through a old version node.
This commit is contained in:
Sijie.Sun
2025-01-27 20:38:22 +08:00
committed by GitHub
parent 08546925cc
commit 4aea0821dd
10 changed files with 318 additions and 37 deletions
+3
View File
@@ -9,3 +9,6 @@ pub mod web;
#[cfg(test)]
pub mod tests;
const DESCRIPTOR_POOL_BYTES: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/file_descriptor_set.bin"));
+10 -3
View File
@@ -192,7 +192,7 @@ impl Client {
async fn call(
&self,
ctrl: Self::Controller,
mut ctrl: Self::Controller,
method: <Self::Descriptor as ServiceDescriptor>::Method,
input: bytes::Bytes,
) -> Result<bytes::Bytes> {
@@ -224,7 +224,11 @@ impl Client {
};
let rpc_req = RpcRequest {
request: input.into(),
request: if let Some(raw_input) = ctrl.get_raw_input() {
raw_input.into()
} else {
input.into()
},
timeout_ms: ctrl.timeout_ms(),
..Default::default()
};
@@ -280,7 +284,10 @@ impl Client {
return Err(err.into());
}
Ok(bytes::Bytes::from(rpc_resp.response))
let raw_output = Bytes::from(rpc_resp.response.clone());
ctrl.set_raw_output(raw_output.clone());
Ok(raw_output)
}
}
+12 -9
View File
@@ -13,7 +13,7 @@ use crate::{
common::{join_joinset_background, PeerId},
proto::{
common::{self, CompressionAlgoPb, RpcCompressionInfo, RpcPacket, RpcRequest, RpcResponse},
rpc_types::error::Result,
rpc_types::{controller::Controller, error::Result},
},
tunnel::{
mpsc::{MpscTunnel, MpscTunnelSender},
@@ -155,16 +155,19 @@ impl Server {
};
let rpc_request = RpcRequest::decode(Bytes::from(body))?;
let timeout_duration = std::time::Duration::from_millis(rpc_request.timeout_ms as u64);
let ctrl = RpcController::default();
Ok(timeout(
let mut ctrl = RpcController::default();
let raw_req = Bytes::from(rpc_request.request);
ctrl.set_raw_input(raw_req.clone());
let ret = timeout(
timeout_duration,
reg.call_method(
packet.descriptor.unwrap(),
ctrl,
Bytes::from(rpc_request.request),
),
reg.call_method(packet.descriptor.unwrap(), ctrl.clone(), raw_req),
)
.await??)
.await??;
if let Some(raw_output) = ctrl.get_raw_output() {
Ok(raw_output)
} else {
Ok(ret)
}
}
async fn handle_rpc(sender: MpscTunnelSender, packet: RpcPacket, reg: Arc<ServiceRegistry>) {
+43 -1
View File
@@ -1,4 +1,9 @@
pub trait Controller: Send + Sync + 'static {
use std::sync::{Arc, Mutex};
use bytes::Bytes;
// Controller must impl clone and all cloned controllers share the same data
pub trait Controller: Send + Sync + Clone + 'static {
fn timeout_ms(&self) -> i32 {
5000
}
@@ -10,12 +15,29 @@ pub trait Controller: Send + Sync + 'static {
fn trace_id(&self) -> i32 {
0
}
fn set_raw_input(&mut self, _raw_input: Bytes) {}
fn get_raw_input(&self) -> Option<Bytes> {
None
}
fn set_raw_output(&mut self, _raw_output: Bytes) {}
fn get_raw_output(&self) -> Option<Bytes> {
None
}
}
#[derive(Debug)]
pub struct BaseControllerRawData {
pub raw_input: Option<Bytes>,
pub raw_output: Option<Bytes>,
}
#[derive(Debug, Clone)]
pub struct BaseController {
pub timeout_ms: i32,
pub trace_id: i32,
pub raw_data: Arc<Mutex<BaseControllerRawData>>,
}
impl Controller for BaseController {
@@ -34,6 +56,22 @@ impl Controller for BaseController {
fn trace_id(&self) -> i32 {
self.trace_id
}
fn set_raw_input(&mut self, raw_input: Bytes) {
self.raw_data.lock().unwrap().raw_input = Some(raw_input);
}
fn get_raw_input(&self) -> Option<Bytes> {
self.raw_data.lock().unwrap().raw_input.clone()
}
fn set_raw_output(&mut self, raw_output: Bytes) {
self.raw_data.lock().unwrap().raw_output = Some(raw_output);
}
fn get_raw_output(&self) -> Option<Bytes> {
self.raw_data.lock().unwrap().raw_output.clone()
}
}
impl Default for BaseController {
@@ -41,6 +79,10 @@ impl Default for BaseController {
Self {
timeout_ms: 5000,
trace_id: 0,
raw_data: Arc::new(Mutex::new(BaseControllerRawData {
raw_input: None,
raw_output: None,
})),
}
}
}