Skip to content

Commit

Permalink
Add CLI switch to enable tunelling
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Oct 30, 2024
1 parent 4041e40 commit 3f4f994
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shvbroker"
version = "3.1.4"
version = "3.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
7 changes: 7 additions & 0 deletions src/bin/shvbroker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ struct CliOpts {
/// Allow writing to access database
#[arg(short = 'b', long)]
use_access_db: bool,
/// Enable broker tunneling feature
#[arg(long)]
tunneling: bool,
/// SHV2 compatibility mode
#[arg(long = "shv2")]
shv2_compatibility: bool,
Expand All @@ -38,6 +41,7 @@ pub(crate) fn main() -> shvrpc::Result<()> {
let cli = CliOpts::augment_args(cli);
let cli_matches = cli.get_matches();
let cli_use_access_db_set = cli_matches.try_get_one::<bool>("use_access_db").is_ok();
let cli_tunelling_set = cli_matches.try_get_one::<bool>("tunneling").is_ok();
let cli_shv2_set = cli_matches.try_get_one::<bool>("shv2_compatibility").is_ok();
let cli_opts = CliOpts::from_arg_matches(&cli_matches).map_err(|err| err.exit()).unwrap();

Expand Down Expand Up @@ -84,6 +88,9 @@ pub(crate) fn main() -> shvrpc::Result<()> {
info!("Using default config");
BrokerConfig::default()
};
if cli_tunelling_set {
config.tunnelling.enabled = cli_opts.tunneling;
}
if cli_shv2_set {
config.shv2_compatibility = cli_opts.shv2_compatibility;
}
Expand Down
4 changes: 3 additions & 1 deletion src/brokerimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,9 @@ impl BrokerImpl {
broker.nodes.insert(path.into(), node);
};
add_node(DIR_APP, Box::new(AppNode::new()));
add_node(".app/tunnel", Box::new(TunnelNode::new()));
if config.tunnelling.enabled {
add_node(".app/tunnel", Box::new(TunnelNode::new()));
}
add_node(DIR_BROKER, Box::new(BrokerNode::new()));
add_node(DIR_BROKER_CURRENT_CLIENT, Box::new(BrokerCurrentClientNode::new()));
add_node(DIR_BROKER_ACCESS_MOUNTS, Box::new(BrokerAccessMountsNode::new()));
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ pub struct BrokerConfig {
pub connections: Vec<BrokerConnectionConfig>,
#[serde(default)]
pub access: AccessConfig,
#[serde(default)]
pub tunnelling: TunnellingConfig,
}
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
pub struct TunnellingConfig {
#[serde(default)]
pub enabled:bool,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum ConnectionKind {
Expand Down Expand Up @@ -199,6 +206,7 @@ impl Default for BrokerConfig {
("test-child-broker".into(), Mount{ mount_point: "test/child-broker".to_string(), description: "Testing child broker mount-point".to_string() }),
]),
},
tunnelling: Default::default(),
}
}
}
3 changes: 2 additions & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ async fn test_broker_loop() {

#[async_std::test]
async fn test_tunnel_loop() {
let config = BrokerConfig::default();
let mut config = BrokerConfig::default();
config.tunnelling.enabled = true;
let access = config.access.clone();
let broker = BrokerImpl::new(&config, access, None);
let broker_sender = broker.command_sender.clone();
Expand Down

0 comments on commit 3f4f994

Please sign in to comment.