Skip to content

Commit

Permalink
minor style adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
akiroz committed Jan 15, 2024
1 parent 302261d commit a67b98c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zika"
version = "3.2.0"
version = "3.2.1"
license = "MIT"
description = "IP Tunneling over MQTT"
repository = "https://github.com/akiroz/zika"
Expand Down
12 changes: 6 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ impl Client {
let mut tunnels = Vec::with_capacity(client_config.tunnels.len());
let mut rng = thread_rng();
for client_tunnel_config in &client_config.tunnels {
let random_id: Vec<u8> = (&mut rng)
.sample_iter(Standard)
.take(client_tunnel_config.id_length)
.collect();
let id_len = client_tunnel_config.id_length;
let random_id: Vec<u8> = (0..id_len).map(|_| rng.sample(Standard)).collect();
let base64_id = general_purpose::URL_SAFE_NO_PAD.encode(&random_id);
let topic_base = &client_tunnel_config.topic;
let topic = format!("{topic_base}/{base64_id}");
let bind_addr = client_tunnel_config.bind_addr;

if bind_addr == local_addr {
panic!("tunnel bind_addr == local_addr, first address in subnet is reserved");
}
if !ip_network.contains(bind_addr) {
log::warn!("skipping {:?} (outside subnet)", bind_addr);
continue;
panic!("tunnel bind_addr outside subnet");
}
log::info!("bind {:?} -> {:?}", &bind_addr, &topic);

Expand Down
9 changes: 2 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core::time::Duration;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use rand::{thread_rng, Rng, distributions::Alphanumeric};
use rustls::{Certificate, PrivateKey, RootCertStore};
use serde::Deserialize;
use std::fs::{read_to_string, File};
Expand Down Expand Up @@ -106,11 +105,7 @@ impl MqttBroker {
base_mqtt_options: &Option<MqttOptions>,
) -> rumqttc::v5::MqttOptions {
let mut rng = thread_rng();
let random_id: String = (&mut rng)
.sample_iter(Alphanumeric)
.take(7)
.map(char::from)
.collect();
let random_id: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
let mut options = rumqttc::v5::MqttOptions::new(random_id, &self.host, self.port);
let mqtt_options = match (base_mqtt_options, self.options.clone()) {
(Some(b), Some(opts)) => Some(b.merge_with_option(opts)),
Expand Down

0 comments on commit a67b98c

Please sign in to comment.