fix #367
Some checks failed
EasyTier Core / pre_job (push) Has been cancelled
EasyTier GUI / pre_job (push) Has been cancelled
EasyTier Mobile / pre_job (push) Has been cancelled
EasyTier Test / pre_job (push) Has been cancelled
EasyTier Core / build (freebsd-13.2-x86_64, 13.2, ubuntu-latest, x86_64-unknown-freebsd) (push) Has been cancelled
EasyTier Core / build (linux-aarch64, ubuntu-latest, aarch64-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-arm, ubuntu-latest, arm-unknown-linux-musleabi) (push) Has been cancelled
EasyTier Core / build (linux-armhf, ubuntu-latest, arm-unknown-linux-musleabihf) (push) Has been cancelled
EasyTier Core / build (linux-armv7, ubuntu-latest, armv7-unknown-linux-musleabi) (push) Has been cancelled
EasyTier Core / build (linux-armv7hf, ubuntu-latest, armv7-unknown-linux-musleabihf) (push) Has been cancelled
EasyTier Core / build (linux-mips, ubuntu-latest, mips-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-mipsel, ubuntu-latest, mipsel-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (linux-x86_64, ubuntu-latest, x86_64-unknown-linux-musl) (push) Has been cancelled
EasyTier Core / build (macos-aarch64, macos-latest, aarch64-apple-darwin) (push) Has been cancelled
EasyTier Core / build (macos-x86_64, macos-latest, x86_64-apple-darwin) (push) Has been cancelled
EasyTier Core / build (windows-x86_64, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
EasyTier Core / core-result (push) Has been cancelled
EasyTier GUI / build-gui (linux-aarch64, aarch64-unknown-linux-gnu, ubuntu-latest, aarch64-unknown-linux-musl) (push) Has been cancelled
EasyTier GUI / build-gui (linux-x86_64, x86_64-unknown-linux-gnu, ubuntu-latest, x86_64-unknown-linux-musl) (push) Has been cancelled
EasyTier GUI / build-gui (macos-aarch64, aarch64-apple-darwin, macos-latest, aarch64-apple-darwin) (push) Has been cancelled
EasyTier GUI / build-gui (macos-x86_64, x86_64-apple-darwin, macos-latest, x86_64-apple-darwin) (push) Has been cancelled
EasyTier GUI / build-gui (windows-x86_64, x86_64-pc-windows-msvc, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
EasyTier GUI / gui-result (push) Has been cancelled
EasyTier Mobile / build-mobile (android, ubuntu-latest, android) (push) Has been cancelled
EasyTier Mobile / mobile-result (push) Has been cancelled
EasyTier Test / test (push) Has been cancelled

introduce my peer route id and peer id is duplicated only when peer
route id is not same.

this problem occurs because update_self may increase my peer info
version and propagate to ther nodes.
This commit is contained in:
sijie.sun 2024-09-29 23:24:37 +08:00 committed by Sijie.Sun
parent c7895963e4
commit 984ed8f6cf
2 changed files with 29 additions and 9 deletions

View File

@ -117,10 +117,16 @@ impl RoutePeerInfo {
version: 0, version: 0,
easytier_version: EASYTIER_VERSION.to_string(), easytier_version: EASYTIER_VERSION.to_string(),
feature_flag: None, feature_flag: None,
peer_route_id: 0,
} }
} }
pub fn update_self(&self, my_peer_id: PeerId, global_ctx: &ArcGlobalCtx) -> Self { pub fn update_self(
&self,
my_peer_id: PeerId,
peer_route_id: u64,
global_ctx: &ArcGlobalCtx,
) -> Self {
let mut new = Self { let mut new = Self {
peer_id: my_peer_id, peer_id: my_peer_id,
inst_id: Some(global_ctx.get_id().into()), inst_id: Some(global_ctx.get_id().into()),
@ -143,6 +149,7 @@ impl RoutePeerInfo {
easytier_version: EASYTIER_VERSION.to_string(), easytier_version: EASYTIER_VERSION.to_string(),
feature_flag: Some(global_ctx.get_feature_flags()), feature_flag: Some(global_ctx.get_feature_flags()),
peer_route_id,
}; };
let need_update_periodically = if let Ok(Ok(d)) = let need_update_periodically = if let Ok(Ok(d)) =
@ -296,6 +303,7 @@ impl SyncedRouteInfo {
fn check_duplicate_peer_id( fn check_duplicate_peer_id(
&self, &self,
my_peer_id: PeerId, my_peer_id: PeerId,
my_peer_route_id: u64,
dst_peer_id: PeerId, dst_peer_id: PeerId,
route_infos: &Vec<RoutePeerInfo>, route_infos: &Vec<RoutePeerInfo>,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -310,7 +318,7 @@ impl SyncedRouteInfo {
} }
} }
if info.peer_id == dst_peer_id { if info.peer_id == dst_peer_id && info.peer_route_id != my_peer_route_id {
if info.version < self.get_peer_info_version_with_default(info.peer_id) { if info.version < self.get_peer_info_version_with_default(info.peer_id) {
// if dst peer send to us with lower version info of dst peer, dst peer id is duplicated // if dst peer send to us with lower version info of dst peer, dst peer id is duplicated
return Err(Error::DuplicatePeerId); return Err(Error::DuplicatePeerId);
@ -323,10 +331,11 @@ impl SyncedRouteInfo {
fn update_peer_infos( fn update_peer_infos(
&self, &self,
my_peer_id: PeerId, my_peer_id: PeerId,
my_peer_route_id: u64,
dst_peer_id: PeerId, dst_peer_id: PeerId,
peer_infos: &Vec<RoutePeerInfo>, peer_infos: &Vec<RoutePeerInfo>,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.check_duplicate_peer_id(my_peer_id, dst_peer_id, peer_infos)?; self.check_duplicate_peer_id(my_peer_id, my_peer_route_id, dst_peer_id, peer_infos)?;
for mut route_info in peer_infos.iter().map(Clone::clone) { for mut route_info in peer_infos.iter().map(Clone::clone) {
// time between peers may not be synchronized, so update last_update to local now. // time between peers may not be synchronized, so update last_update to local now.
// note only last_update with larger version will be updated to local saved peer info. // note only last_update with larger version will be updated to local saved peer info.
@ -391,12 +400,17 @@ impl SyncedRouteInfo {
} }
} }
fn update_my_peer_info(&self, my_peer_id: PeerId, global_ctx: &ArcGlobalCtx) -> bool { fn update_my_peer_info(
&self,
my_peer_id: PeerId,
my_peer_route_id: u64,
global_ctx: &ArcGlobalCtx,
) -> bool {
let mut old = self let mut old = self
.peer_infos .peer_infos
.entry(my_peer_id) .entry(my_peer_id)
.or_insert(RoutePeerInfo::new()); .or_insert(RoutePeerInfo::new());
let new = old.update_self(my_peer_id, &global_ctx); let new = old.update_self(my_peer_id, my_peer_route_id, &global_ctx);
let new_version = new.version; let new_version = new.version;
let old_version = old.version; let old_version = old.version;
*old = new; *old = new;
@ -885,6 +899,7 @@ impl Drop for SyncRouteSession {
struct PeerRouteServiceImpl { struct PeerRouteServiceImpl {
my_peer_id: PeerId, my_peer_id: PeerId,
my_peer_route_id: u64,
global_ctx: ArcGlobalCtx, global_ctx: ArcGlobalCtx,
sessions: DashMap<PeerId, Arc<SyncRouteSession>>, sessions: DashMap<PeerId, Arc<SyncRouteSession>>,
@ -904,6 +919,7 @@ impl Debug for PeerRouteServiceImpl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PeerRouteServiceImpl") f.debug_struct("PeerRouteServiceImpl")
.field("my_peer_id", &self.my_peer_id) .field("my_peer_id", &self.my_peer_id)
.field("my_peer_route_id", &self.my_peer_route_id)
.field("network", &self.global_ctx.get_network_identity()) .field("network", &self.global_ctx.get_network_identity())
.field("sessions", &self.sessions) .field("sessions", &self.sessions)
.field("route_table", &self.route_table) .field("route_table", &self.route_table)
@ -922,6 +938,7 @@ impl PeerRouteServiceImpl {
fn new(my_peer_id: PeerId, global_ctx: ArcGlobalCtx) -> Self { fn new(my_peer_id: PeerId, global_ctx: ArcGlobalCtx) -> Self {
PeerRouteServiceImpl { PeerRouteServiceImpl {
my_peer_id, my_peer_id,
my_peer_route_id: rand::random(),
global_ctx, global_ctx,
sessions: DashMap::new(), sessions: DashMap::new(),
@ -977,10 +994,11 @@ impl PeerRouteServiceImpl {
} }
fn update_my_peer_info(&self) -> bool { fn update_my_peer_info(&self) -> bool {
if self if self.synced_route_info.update_my_peer_info(
.synced_route_info self.my_peer_id,
.update_my_peer_info(self.my_peer_id, &self.global_ctx) self.my_peer_route_id,
{ &self.global_ctx,
) {
self.update_route_table_and_cached_local_conn_bitmap(); self.update_route_table_and_cached_local_conn_bitmap();
return true; return true;
} }
@ -1677,6 +1695,7 @@ impl RouteSessionManager {
if let Some(peer_infos) = &peer_infos { if let Some(peer_infos) = &peer_infos {
service_impl.synced_route_info.update_peer_infos( service_impl.synced_route_info.update_peer_infos(
my_peer_id, my_peer_id,
service_impl.my_peer_route_id,
from_peer_id, from_peer_id,
peer_infos, peer_infos,
)?; )?;

View File

@ -19,6 +19,7 @@ message RoutePeerInfo {
string easytier_version = 10; string easytier_version = 10;
common.PeerFeatureFlag feature_flag = 11; common.PeerFeatureFlag feature_flag = 11;
uint64 peer_route_id = 12;
} }
message PeerIdVersion { message PeerIdVersion {