Skip to content

Commit

Permalink
log server tunnel allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
akiroz committed Jan 28, 2024
1 parent 841f3de commit a2f1fbc
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 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.3.4"
version = "3.3.5"
license = "MIT"
description = "IP Tunneling over MQTT"
repository = "https://github.com/akiroz/zika"
Expand Down
3 changes: 1 addition & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::config;
use crate::remote;
use crate::ip_iter::SizedIpv4NetworkIterator;


type TunSink = SplitSink<Framed<AsyncDevice, TunPacketCodec>, TunPacket>;

pub struct Client {
Expand Down Expand Up @@ -81,7 +80,7 @@ impl Client {
if !ip_network.contains(bind_addr) {
panic!("tunnel bind_addr outside subnet");
}
log::info!("bind {:?} -> {:?}", &bind_addr, &topic);
log::info!("bind {:?} -> {} ({})", &bind_addr, topic_base, base64_id);

let subscribe_result = remote.subscribe(topic.clone()).await;
if let Err(err) = subscribe_result {
Expand Down
6 changes: 3 additions & 3 deletions src/lookup_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ where
}
}

pub fn get_forward(&mut self, a: &A) -> B {
pub fn get_forward(&mut self, a: &A) -> (bool, B) {
match self.forward.get(a) {
Some(b) => *b,
Some(b) => (true, *b),
None => {
let b = self
.pool
Expand All @@ -48,7 +48,7 @@ where
}
}
self.reverse.insert(b, a.clone());
b
(false, b)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Remote {
let mut properties: PublishProperties = Default::default();
let topic_to_send = if let Some(ref mut pool) = client.alias_pool {
let already_sent_alias = pool.contains(topic);
let alias = pool.get_forward(topic);
let (_exists, alias) = pool.get_forward(topic);
properties.topic_alias = Some(alias);
if already_sent_alias { "" } else { topic }
} else { // Alias not used
Expand Down
10 changes: 5 additions & 5 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ impl Server {
// mqtt -> tun
async fn handle_remote_message(&self, tun_sink: &mut TunSink, id: &[u8], msg: &[u8]) -> Result<(), Box<dyn StdError>> {
let base64_id = general_purpose::URL_SAFE_NO_PAD.encode(id);
let topic_base = &self.topic;
let topic = format!("{topic_base}/{base64_id}");
let ip: Ipv4Addr = {
let (existing_tunnel, ip) = {
let mut ip_pool = self.ip_pool.lock().await;
let ip = ip_pool.get_forward(&topic).into();
ip
ip_pool.get_forward(&base64_id)
};
if !existing_tunnel {
log::info!("alloc tunnel {} (IP {})", base64_id, ip);
}
let pkt = nat::do_nat(msg, ip, self.local_addr)?;
tun_sink.send(TunPacket::new(pkt)).await?;
Ok(())
Expand Down

0 comments on commit a2f1fbc

Please sign in to comment.