Skip to content

Commit

Permalink
fix run with config, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
KKRainbow committed May 17, 2024
1 parent 7532a7c commit 06b2c18
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[![GitHub](https://img.shields.io/github/license/KKRainbow/EasyTier)](https://github.com/KKRainbow/EasyTier/blob/main/LICENSE)
[![GitHub last commit](https://img.shields.io/github/last-commit/KKRainbow/EasyTier)](https://github.com/KKRainbow/EasyTier/commits/main)
[![GitHub issues](https://img.shields.io/github/issues/KKRainbow/EasyTier)](https://github.com/KKRainbow/EasyTier/issues)
[![GitHub actions](https://github.com/KKRainbow/EasyTier/actions/workflows/rust.yml/badge.svg)](https://github.com/KKRainbow/EasyTier/actions/)
[![GitHub Core Actions](https://github.com/KKRainbow/EasyTier/actions/workflows/core.yml/badge.svg)](https://github.com/EasyTier/EasyTier/actions/workflows/core.yml)
[![GitHub GUI Actions](https://github.com/KKRainbow/EasyTier/actions/workflows/gui.yml/badge.svg)](https://github.com/EasyTier/EasyTier/actions/workflows/gui.yml)

[简体中文](/README_CN.md) | [English](/README.md)

Expand Down Expand Up @@ -259,6 +260,7 @@ Before using the Client Config, you need to modify the Interface Address and Pee
- [ZeroTier](https://www.zerotier.com/): A global virtual network for connecting devices.
- [TailScale](https://tailscale.com/): A VPN solution aimed at simplifying network configuration.
- [vpncloud](https://github.com/dswd/vpncloud): A P2P Mesh VPN
- [Candy](https://github.com/lanthora/candy): A reliable, low-latency, and anti-censorship virtual private network

# License

Expand Down
4 changes: 3 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[![GitHub](https://img.shields.io/github/license/KKRainbow/EasyTier)](https://github.com/KKRainbow/EasyTier/blob/main/LICENSE)
[![GitHub last commit](https://img.shields.io/github/last-commit/KKRainbow/EasyTier)](https://github.com/KKRainbow/EasyTier/commits/main)
[![GitHub issues](https://img.shields.io/github/issues/KKRainbow/EasyTier)](https://github.com/KKRainbow/EasyTier/issues)
[![GitHub actions](https://github.com/KKRainbow/EasyTier/actions/workflows/rust.yml/badge.svg)](https://github.com/KKRainbow/EasyTier/actions/)
[![GitHub Core Actions](https://github.com/KKRainbow/EasyTier/actions/workflows/core.yml/badge.svg)](https://github.com/EasyTier/EasyTier/actions/workflows/core.yml)
[![GitHub GUI Actions](https://github.com/KKRainbow/EasyTier/actions/workflows/gui.yml/badge.svg)](https://github.com/EasyTier/EasyTier/actions/workflows/gui.yml)

[简体中文](/README_CN.md) | [English](/README.md)

Expand Down Expand Up @@ -262,6 +263,7 @@ connected_clients:
- [ZeroTier](https://www.zerotier.com/): 一个全球虚拟网络,用于连接设备。
- [TailScale](https://tailscale.com/): 一个旨在简化网络配置的 VPN 解决方案。
- [vpncloud](https://github.com/dswd/vpncloud): 一个 P2P Mesh VPN
- [Candy](https://github.com/lanthora/candy): 可靠、低延迟、抗审查的虚拟专用网络

# 许可证

Expand Down
9 changes: 8 additions & 1 deletion easytier/src/common/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,14 @@ impl TomlConfigLoader {
pub fn new(config_path: &PathBuf) -> Result<Self, anyhow::Error> {
let config_str = std::fs::read_to_string(config_path)
.with_context(|| format!("failed to read config file: {:?}", config_path))?;
Self::new_from_str(&config_str)
let ret = Self::new_from_str(&config_str)?;
let old_ns = ret.get_network_identity();
ret.set_network_identity(NetworkIdentity::new(
old_ns.network_name,
old_ns.network_secret.unwrap_or_default(),
));

Ok(ret)
}
}

Expand Down
17 changes: 17 additions & 0 deletions easytier/src/instance/virtual_nic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ impl VirtualNic {
}
#[cfg(test)]
mod tests {
use std::net::Ipv4Addr;

use cidr::Cidr;

use crate::common::{error::Error, global_ctx::tests::get_mock_global_ctx};

use super::VirtualNic;
Expand Down Expand Up @@ -403,4 +407,17 @@ mod tests {
// println!("ret: {:?}", tmp.unwrap());
// }
}

#[tokio::test]
async fn inet_test() {
let ipv4: Ipv4Addr = "10.1.1.2".parse().unwrap();
let inet = cidr::Ipv4Inet::new(ipv4, 24).unwrap();
let network = inet.network();
network.iter()..for_each(|ip| {
if ip.address() == network.first_address() {
println!("ip: {:?}", ip);
}
});
println!("inet: {:?}, net: {:?}", inet, inet.network());
}
}
3 changes: 3 additions & 0 deletions easytier/src/tunnel/packet_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ const PAYLOAD_OFFSET_FOR_NIC_PACKET: usize = max(
WG_TUNNEL_HEADER_SIZE,
) + PEER_MANAGER_HEADER_SIZE;

// UDP Tunnel: TUN MTU + 24 (Easy) + 20 (Encrypted) + 8(UDP) + 20(IP) = TUN MTU + 72
// TCP Tunnel: TUN MTU + 20 (Easy) + 20 (Encrypted) + 20(TCP) + 20(IP) = TUN MTU + 80

const INVALID_OFFSET: usize = usize::MAX;

const fn get_converted_offset(old_hdr_size: usize, new_hdr_size: usize) -> usize {
Expand Down

0 comments on commit 06b2c18

Please sign in to comment.