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
+2 -2
View File
@@ -6,7 +6,7 @@ use netrunner_logger::{debug, error};
use tokio::net::UdpSocket;
use tokio::sync::mpsc;
pub async fn run_tcp_bridge<R, W>(
pub(crate) async fn run_tcp_bridge<R, W>(
stream_id: u32,
mut reader: R,
mut writer: W,
@@ -72,7 +72,7 @@ pub async fn run_tcp_bridge<R, W>(
muxer.remove_stream(stream_id);
}
pub async fn run_udp_bridge(
pub(crate) async fn run_udp_bridge(
stream_id: u32,
socket: UdpSocket,
muxer: Muxer,
+4 -4
View File
@@ -38,10 +38,10 @@ pub trait TunnelHandler {
}
pub struct Connection {
pub inbound: OwnedReadHalf,
pub outbound: OwnedWriteHalf,
pub read_buf: BytesMut,
pub codec: Codec,
pub(crate) inbound: OwnedReadHalf,
pub(crate) outbound: OwnedWriteHalf,
pub(crate) read_buf: BytesMut,
pub(crate) codec: Codec,
}
impl Connection {
+1 -1
View File
@@ -14,7 +14,7 @@ use crate::{
nrxp::{codec::Codec, errors::ErrorAction, frame::FrameType},
};
pub struct TunnelEngine {
pub(crate) struct TunnelEngine {
pub inbound: OwnedReadHalf,
pub outbound: OwnedWriteHalf,
pub codec: Codec,
+3 -3
View File
@@ -16,17 +16,17 @@ use crate::{
},
};
pub struct StreamHandler {
pub(crate) struct StreamHandler {
muxer: Muxer,
role: ConnectionRole,
}
impl StreamHandler {
pub fn new(muxer: Muxer, role: ConnectionRole) -> Self {
pub(crate) fn new(muxer: Muxer, role: ConnectionRole) -> Self {
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;
match frame.header.frame_type {
+7 -5
View File
@@ -1,5 +1,7 @@
mod bridge;
pub mod connection;
pub mod engine;
pub mod handler;
pub mod muxer;
mod bridge; // Все модули делаем приватными
mod connection;
mod engine;
mod handler;
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;
pub struct IdGenerator {
struct IdGenerator {
counter: AtomicU32,
}
+3 -1
View File
@@ -1,2 +1,4 @@
pub mod connection;
mod connection;
pub mod network;
pub use connection::{ClientHandler, ConnectionRole, ServerHandler, TunnelHandler};
+1 -3
View File
@@ -1,9 +1,7 @@
use std::sync::OnceLock;
use crate::{
net::connection::connection::{
ClientHandler, Connection, ConnectionRole, ServerHandler, TunnelHandler,
},
net::connection::{ClientHandler, Connection, ConnectionRole, ServerHandler, TunnelHandler},
nrxp::frame::{FRAME_HEADER_SIZE, MAX_PADDING_SIZE},
};
use netrunner_logger::{error, info};