Skip to content

Commit

Permalink
Code move
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Oct 12, 2023
1 parent 5edd0eb commit 66f41d8
Show file tree
Hide file tree
Showing 16 changed files with 3,412 additions and 3,205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//
use super::router::*;
use super::super::router::*;
use super::tables::{Tables, TablesLock};
use super::{resource::*, tables};
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::sync::Arc;
Expand All @@ -28,26 +30,26 @@ use zenoh_transport::stats::TransportStats;
use zenoh_transport::{Primitives, TransportMulticast};

pub struct FaceState {
pub(super) id: usize,
pub(super) zid: ZenohId,
pub(super) whatami: WhatAmI,
pub(crate) id: usize,
pub(crate) zid: ZenohId,
pub(crate) whatami: WhatAmI,
#[cfg(feature = "stats")]
pub(super) stats: Option<Arc<TransportStats>>,
pub(super) primitives: Arc<dyn Primitives + Send + Sync>,
pub(super) link_id: usize,
pub(super) local_mappings: HashMap<ExprId, Arc<Resource>>,
pub(super) remote_mappings: HashMap<ExprId, Arc<Resource>>,
pub(super) local_subs: HashSet<Arc<Resource>>,
pub(super) remote_subs: HashSet<Arc<Resource>>,
pub(super) local_qabls: HashMap<Arc<Resource>, QueryableInfo>,
pub(super) remote_qabls: HashSet<Arc<Resource>>,
pub(super) next_qid: RequestId,
pub(super) pending_queries: HashMap<RequestId, Arc<Query>>,
pub(super) mcast_group: Option<TransportMulticast>,
pub(crate) stats: Option<Arc<TransportStats>>,
pub(crate) primitives: Arc<dyn Primitives + Send + Sync>,
pub(crate) link_id: usize,
pub(crate) local_mappings: HashMap<ExprId, Arc<Resource>>,
pub(crate) remote_mappings: HashMap<ExprId, Arc<Resource>>,
pub(crate) local_subs: HashSet<Arc<Resource>>,
pub(crate) remote_subs: HashSet<Arc<Resource>>,
pub(crate) local_qabls: HashMap<Arc<Resource>, QueryableInfo>,
pub(crate) remote_qabls: HashSet<Arc<Resource>>,
pub(crate) next_qid: RequestId,
pub(crate) pending_queries: HashMap<RequestId, Arc<Query>>,
pub(crate) mcast_group: Option<TransportMulticast>,
}

impl FaceState {
pub(super) fn new(
pub(crate) fn new(
id: usize,
zid: ZenohId,
whatami: WhatAmI,
Expand Down Expand Up @@ -78,7 +80,7 @@ impl FaceState {

#[inline]
#[allow(clippy::trivially_copy_pass_by_ref)]
pub(super) fn get_mapping(
pub(crate) fn get_mapping(
&self,
prefixid: &ExprId,
mapping: Mapping,
Expand All @@ -89,16 +91,22 @@ impl FaceState {
}
}

pub(super) fn get_next_local_id(&self) -> ExprId {
pub(crate) fn get_next_local_id(&self) -> ExprId {
let mut id = 1;
while self.local_mappings.get(&id).is_some() || self.remote_mappings.get(&id).is_some() {
id += 1;
}
id
}

pub(super) fn get_router(&self, tables: &Tables, nodeid: &u64) -> Option<ZenohId> {
match tables.routers_net.as_ref().unwrap().get_link(self.link_id) {
pub(crate) fn get_router(&self, tables: &Tables, nodeid: &u64) -> Option<ZenohId> {
match tables
.hat
.routers_net
.as_ref()
.unwrap()
.get_link(self.link_id)
{
Some(link) => match link.get_zid(nodeid) {
Some(router) => Some(*router),
None => {
Expand All @@ -119,8 +127,14 @@ impl FaceState {
}
}

pub(super) fn get_peer(&self, tables: &Tables, nodeid: &u64) -> Option<ZenohId> {
match tables.peers_net.as_ref().unwrap().get_link(self.link_id) {
pub(crate) fn get_peer(&self, tables: &Tables, nodeid: &u64) -> Option<ZenohId> {
match tables
.hat
.peers_net
.as_ref()
.unwrap()
.get_link(self.link_id)
{
Some(link) => match link.get_zid(nodeid) {
Some(router) => Some(*router),
None => {
Expand Down Expand Up @@ -185,7 +199,7 @@ impl Primitives for Face {
(WhatAmI::Router, WhatAmI::Peer)
| (WhatAmI::Peer, WhatAmI::Router)
| (WhatAmI::Peer, WhatAmI::Peer) => {
if rtables.full_net(WhatAmI::Peer) {
if rtables.hat.full_net(WhatAmI::Peer) {
if let Some(peer) = self
.state
.get_peer(&rtables, &(msg.ext_nodeid.node_id as u64))
Expand Down Expand Up @@ -238,7 +252,7 @@ impl Primitives for Face {
(WhatAmI::Router, WhatAmI::Peer)
| (WhatAmI::Peer, WhatAmI::Router)
| (WhatAmI::Peer, WhatAmI::Peer) => {
if rtables.full_net(WhatAmI::Peer) {
if rtables.hat.full_net(WhatAmI::Peer) {
if let Some(peer) = self
.state
.get_peer(&rtables, &(msg.ext_nodeid.node_id as u64))
Expand Down Expand Up @@ -289,7 +303,7 @@ impl Primitives for Face {
(WhatAmI::Router, WhatAmI::Peer)
| (WhatAmI::Peer, WhatAmI::Router)
| (WhatAmI::Peer, WhatAmI::Peer) => {
if rtables.full_net(WhatAmI::Peer) {
if rtables.hat.full_net(WhatAmI::Peer) {
if let Some(peer) = self
.state
.get_peer(&rtables, &(msg.ext_nodeid.node_id as u64))
Expand Down Expand Up @@ -342,7 +356,7 @@ impl Primitives for Face {
(WhatAmI::Router, WhatAmI::Peer)
| (WhatAmI::Peer, WhatAmI::Router)
| (WhatAmI::Peer, WhatAmI::Peer) => {
if rtables.full_net(WhatAmI::Peer) {
if rtables.hat.full_net(WhatAmI::Peer) {
if let Some(peer) = self
.state
.get_peer(&rtables, &(msg.ext_nodeid.node_id as u64))
Expand Down Expand Up @@ -432,7 +446,7 @@ impl Primitives for Face {
}

fn send_close(&self) {
super::router::close_face(&self.tables, &Arc::downgrade(&self.state));
tables::close_face(&self.tables, &Arc::downgrade(&self.state));
}
}

Expand Down
24 changes: 24 additions & 0 deletions zenoh/src/net/routing/dispatcher/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Copyright (c) 2023 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

//! ⚠️ WARNING ⚠️
//!
//! This module is intended for Zenoh's internal use.
//!
//! [Click here for Zenoh's documentation](../zenoh/index.html)
pub mod face;
pub mod pubsub;
pub mod queries;
pub mod resource;
pub mod tables;
Loading

0 comments on commit 66f41d8

Please sign in to comment.