makefile and service
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use lru::LruCache;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::num::NonZeroUsize;
|
||||
use tracing::{debug, info};
|
||||
|
||||
pub struct FakeIpStore {
|
||||
cache: LruCache<String, Ipv4Addr>,
|
||||
@@ -12,6 +13,7 @@ const START_IP: u32 = 0x64400001; // 100.64.0.1 (IP for Service Networks/Shared
|
||||
|
||||
impl FakeIpStore {
|
||||
pub fn new() -> Self {
|
||||
info!("Initializing FakeIpStore starting at 100.64.0.1");
|
||||
Self {
|
||||
cache: LruCache::new(NonZeroUsize::new(2000).unwrap()),
|
||||
rev_cache: LruCache::new(NonZeroUsize::new(2000).unwrap()),
|
||||
@@ -21,16 +23,24 @@ impl FakeIpStore {
|
||||
|
||||
pub fn get_or_assign(&mut self, host: &str) -> Ipv4Addr {
|
||||
if let Some(&ip) = self.cache.get(host) {
|
||||
debug!(host = %host, ip = %ip, "Cache hit: IP already assigned");
|
||||
return ip;
|
||||
}
|
||||
let ip = Ipv4Addr::from(self.next_ip);
|
||||
self.next_ip += 1;
|
||||
self.cache.put(host.to_string(), ip);
|
||||
self.rev_cache.put(ip, host.to_string());
|
||||
info!(host = %host, ip = %ip, "Assigned new fake IP");
|
||||
ip
|
||||
}
|
||||
|
||||
pub fn lookup_by_ip(&self, ip: &Ipv4Addr) -> Option<String> {
|
||||
self.rev_cache.peek(ip).cloned()
|
||||
if let Some(host) = self.rev_cache.peek(ip) {
|
||||
debug!(ip = %ip, host = %host, "Reverse lookup successful");
|
||||
Some(host.clone())
|
||||
} else {
|
||||
debug!(ip = %ip, "Reverse lookup miss");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ async fn main() {
|
||||
let config = Config::new(smoltcp::wire::HardwareAddress::Ip);
|
||||
|
||||
let mut caps = DeviceCapabilities::default();
|
||||
let remote_address: String = "172.18.151.121:4443".into();
|
||||
let remote_address: String = "62.60.244.156:443".into();
|
||||
caps.max_transmission_unit = 1500;
|
||||
caps.medium = smoltcp::phy::Medium::Ip;
|
||||
|
||||
|
||||
@@ -64,7 +64,6 @@ impl Device for VirtTunDevice {
|
||||
|
||||
fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
|
||||
if let Ok(buffer) = self.in_buf.try_recv() {
|
||||
trace!("--- TUN RX: {} bytes ---", buffer.len()); // Посмотри, что именно прилетает
|
||||
let rx = Self::RxToken {
|
||||
buffer,
|
||||
phantom_device: PhantomData,
|
||||
|
||||
Reference in New Issue
Block a user