encapsulation of net logic in core

This commit is contained in:
2026-03-26 12:13:43 +07:00
parent 6a0eafd2f5
commit cb837c08f2
12 changed files with 26 additions and 25 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{
net::engine::{EngineBuilder, EngineConfig}, net::engine::{EngineBuilder, EngineConfig},
tun::routing::reset_platform_routing, tun::routing::reset_platform_routing,
}; };
use netrunner_core::net::connection::connection::ConnectionRole; use netrunner_core::net::ConnectionRole;
use netrunner_core::net::network::Network; use netrunner_core::net::network::Network;
use netrunner_logger::{error, info}; use netrunner_logger::{error, info};
use std::sync::{Arc, OnceLock}; use std::sync::{Arc, OnceLock};
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::tun::{routing::reset_platform_routing, tun::Tun};
use net::engine::{EngineBuilder, EngineConfig}; use net::engine::{EngineBuilder, EngineConfig};
// Импортируем компоненты локального прокси // Импортируем компоненты локального прокси
use netrunner_core::net::connection::connection::ConnectionRole; use netrunner_core::net::ConnectionRole;
use netrunner_core::net::network::Network; use netrunner_core::net::network::Network;
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
+1 -2
View File
@@ -1,5 +1,4 @@
use netrunner_core::net::connection::connection::ClientHandler; use netrunner_core::net::ClientHandler;
use netrunner_core::net::connection::muxer::Muxer;
use smoltcp::iface::PollResult; use smoltcp::iface::PollResult;
use smoltcp::time::Instant; use smoltcp::time::Instant;
use smoltcp::wire::{IpAddress, IpCidr}; use smoltcp::wire::{IpAddress, IpCidr};
+2 -2
View File
@@ -6,7 +6,7 @@ use netrunner_logger::{debug, error};
use tokio::net::UdpSocket; use tokio::net::UdpSocket;
use tokio::sync::mpsc; use tokio::sync::mpsc;
pub async fn run_tcp_bridge<R, W>( pub(crate) async fn run_tcp_bridge<R, W>(
stream_id: u32, stream_id: u32,
mut reader: R, mut reader: R,
mut writer: W, mut writer: W,
@@ -72,7 +72,7 @@ pub async fn run_tcp_bridge<R, W>(
muxer.remove_stream(stream_id); muxer.remove_stream(stream_id);
} }
pub async fn run_udp_bridge( pub(crate) async fn run_udp_bridge(
stream_id: u32, stream_id: u32,
socket: UdpSocket, socket: UdpSocket,
muxer: Muxer, muxer: Muxer,
+4 -4
View File
@@ -38,10 +38,10 @@ pub trait TunnelHandler {
} }
pub struct Connection { pub struct Connection {
pub inbound: OwnedReadHalf, pub(crate) inbound: OwnedReadHalf,
pub outbound: OwnedWriteHalf, pub(crate) outbound: OwnedWriteHalf,
pub read_buf: BytesMut, pub(crate) read_buf: BytesMut,
pub codec: Codec, pub(crate) codec: Codec,
} }
impl Connection { impl Connection {
+1 -1
View File
@@ -14,7 +14,7 @@ use crate::{
nrxp::{codec::Codec, errors::ErrorAction, frame::FrameType}, nrxp::{codec::Codec, errors::ErrorAction, frame::FrameType},
}; };
pub struct TunnelEngine { pub(crate) struct TunnelEngine {
pub inbound: OwnedReadHalf, pub inbound: OwnedReadHalf,
pub outbound: OwnedWriteHalf, pub outbound: OwnedWriteHalf,
pub codec: Codec, pub codec: Codec,
+3 -3
View File
@@ -16,17 +16,17 @@ use crate::{
}, },
}; };
pub struct StreamHandler { pub(crate) struct StreamHandler {
muxer: Muxer, muxer: Muxer,
role: ConnectionRole, role: ConnectionRole,
} }
impl StreamHandler { impl StreamHandler {
pub fn new(muxer: Muxer, role: ConnectionRole) -> Self { pub(crate) fn new(muxer: Muxer, role: ConnectionRole) -> Self {
Self { muxer, role } Self { muxer, role }
} }
pub async fn handle(&self, frame: Frame) { pub(crate) async fn handle(&self, frame: Frame) {
let stream_id = frame.header.stream_id; let stream_id = frame.header.stream_id;
match frame.header.frame_type { match frame.header.frame_type {
+7 -5
View File
@@ -1,5 +1,7 @@
mod bridge; mod bridge; // Все модули делаем приватными
pub mod connection; mod connection;
pub mod engine; mod engine;
pub mod handler; mod handler;
pub mod muxer; mod muxer;
pub use connection::{ClientHandler, Connection, ConnectionRole, ServerHandler, TunnelHandler};
+1 -1
View File
@@ -6,7 +6,7 @@ use tokio::sync::mpsc::{error::SendError, Sender};
use crate::nrxp::frame::FrameType; use crate::nrxp::frame::FrameType;
pub struct IdGenerator { struct IdGenerator {
counter: AtomicU32, counter: AtomicU32,
} }
+3 -1
View File
@@ -1,2 +1,4 @@
pub mod connection; mod connection;
pub mod network; pub mod network;
pub use connection::{ClientHandler, ConnectionRole, ServerHandler, TunnelHandler};
+1 -3
View File
@@ -1,9 +1,7 @@
use std::sync::OnceLock; use std::sync::OnceLock;
use crate::{ use crate::{
net::connection::connection::{ net::connection::{ClientHandler, Connection, ConnectionRole, ServerHandler, TunnelHandler},
ClientHandler, Connection, ConnectionRole, ServerHandler, TunnelHandler,
},
nrxp::frame::{FRAME_HEADER_SIZE, MAX_PADDING_SIZE}, nrxp::frame::{FRAME_HEADER_SIZE, MAX_PADDING_SIZE},
}; };
use netrunner_logger::{error, info}; use netrunner_logger::{error, info};
+1 -1
View File
@@ -1,5 +1,5 @@
use clap::Parser; use clap::Parser;
use netrunner_core::net::{connection::connection::ConnectionRole, network::Network}; use netrunner_core::net::{network::Network, ConnectionRole};
use netrunner_logger::Logger; use netrunner_logger::Logger;
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]