Skip to content

Commit

Permalink
feat: channel_port #43
Browse files Browse the repository at this point in the history
  • Loading branch information
editso committed Aug 30, 2022
1 parent bcaef15 commit 5b38388
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ panic = 'abort'

[features]
# 默认开启tokio异步 & clap参数解析器
default = ['fuso-rt-tokio', "fuso-api", "fuso-json", "fuso-kcp","fuso-clap", "bytes", "fuso-serde", "fuso-socks5", "fuso-crypt-rsa", "fuso-crypt-aes"]
default = ['fuso-rt-tokio', "fuso-api", "fuso-json", "fuso-kcp","fuso-clap", "bytes", "fuso-serde", "fuso-socks5", "fuso-crypt-rsa", "fuso-crypt-aes", "fus-log"]
# 只提供api,不提供web界面
fuso-api = ["axum", "fuso-rt-tokio"]
# web界面
Expand Down Expand Up @@ -141,7 +141,7 @@ fuso-crypt-aes = ["aes", "cbc"]
fuso-json = ["serde_json"]
# 客户端日志输出
fuc-log = ["env_logger"]

fus-log = ["env_logger"]

[[bin]]
name = "fuc"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ fuc --socks --su --s5p xxx --s5u xxx
如: 使用bash脚本将连接信息通知到tg
> fus --observer "/bin/bash:[telegram.sh]"
6. 指定客户端与服务端通信的端口
fus --channel-port 8888 ...
--channel-port: 可选的, 客户端与服务端通信端口, 默认随机
```


Expand Down
4 changes: 4 additions & 0 deletions src/bin/client/fuso_clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ struct FusoArgs {
/// 发送心跳延时
#[clap(long, default_value = "30", display_order = 14)]
heartbeat_delay: u64,
/// 通信端口
#[clap(long, default_value = "0", display_order = 15)]
channel_port: u16,
/// 日志级别
#[cfg(feature = "fuc-log")]
#[cfg(debug_assertions)]
Expand Down Expand Up @@ -117,6 +120,7 @@ pub async fn fuso_main() -> fuso::Result<()> {
.enable_kcp(args.kcp)
.enable_socks5(args.socks)
.enable_socks5_udp(args.socks_udp)
.channel_port(args.channel_port)
.set_socks5_password(args.socks_password)
.set_socks5_username(args.socks_username)
.build(
Expand Down
8 changes: 8 additions & 0 deletions src/net/penetrate/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct PenetrateClientBuilder<E, CF, S> {
upstream: Socket,
/// 下游地址, 也就是本地需要映射的地址
downstream: Socket,
channel_port: u16,
/// 创建连接等待时间, 超过视为超时
maximum_wait: Option<Duration>,
/// 重连延时
Expand Down Expand Up @@ -146,6 +147,7 @@ impl<E, CF, S> ClientBuilder<E, CF, S> {
name: String::from("anonymous"),
upstream: upstream.into(),
downstream: downstream.into(),
channel_port: 0,
client_builder: self,
maximum_wait: None,
maximum_retries: None,
Expand Down Expand Up @@ -216,6 +218,11 @@ where
self
}

pub fn channel_port(mut self, port: u16) -> Self {
self.channel_port = port;
self
}

pub fn build<A: Into<Socket>, C>(
self,
server_socket: A,
Expand All @@ -238,6 +245,7 @@ where
connector_provider: Arc::new(connector),
config: super::client::Config {
name: self.name,
channel_port: self.channel_port,
maximum_wait: self.maximum_wait.unwrap_or(Duration::from_secs(10)),
heartbeat_delay: self.heartbeat_delay.unwrap_or(Duration::from_secs(30)),
enable_kcp: self.enable_kcp,
Expand Down
4 changes: 3 additions & 1 deletion src/net/penetrate/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ pub struct Config {
pub(super) socks_username: Option<String>,
/// socks5密码
pub(super) socks_password: Option<String>,
/// 客户端与服务端通信端口
pub(super) channel_port: u16,
/// 是否启用socks5 udp转发
pub(super) enable_socks5_udp: bool,
pub(super) version: String,
Expand Down Expand Up @@ -114,7 +116,7 @@ where
let mut stream = stream;
let (visit_addr, route_addr) = socket;
let bind = Poto::Bind(Bind::Setup(
Socket::tcp(0).if_stream_mixed(config.enable_kcp || config.enable_socks5_udp),
Socket::tcp(config.channel_port).if_stream_mixed(config.enable_kcp || config.enable_socks5_udp),
visit_addr.clone(),
))
.bytes();
Expand Down

0 comments on commit 5b38388

Please sign in to comment.