Skip to content

Commit

Permalink
Add error messages when failed to start server
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelErr committed Dec 30, 2021
1 parent bff9273 commit 8fbc0c3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fourth"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
authors = ["LI Rui <[email protected]>"]
license = "Apache-2.0"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ upstream:
内置两个的upstream:ban(立即中断连接)、echo(返回读到的数据)。更详细的配置可以参考[示例配置](./example-config.yaml)。
注意:[::]会默认同时绑定IPv4和IPv6。
## 性能测试
在4C2G的服务器上测试:
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn verify_config(config: ParsedConfig) -> Result<ParsedConfig, ConfigError> {
}

for key in &upstream_names {
if !used_upstreams.contains(key) {
if !used_upstreams.contains(key) && !key.eq("echo") && !key.eq("ban") {
warn!("Upstream {} not used", key);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ mod servers;
use crate::config::Config;
use crate::servers::Server;

use std::env;
use log::{debug, error};
use std::env;

fn main() {
let config_path = env::var("FOURTH_CONFIG").unwrap_or_else(|_| "/etc/fourth/config.yaml".to_string());
let config_path =
env::var("FOURTH_CONFIG").unwrap_or_else(|_| "/etc/fourth/config.yaml".to_string());

let config = match Config::new(&config_path) {
Ok(config) => config,
Expand All @@ -23,6 +24,6 @@ fn main() {
let mut server = Server::new(config.base);
debug!("{:?}", server);

let res = server.run();
error!("Server returned an error: {:?}", res);
let _ = server.run();
error!("Server ended with errors");
}
10 changes: 8 additions & 2 deletions src/servers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,16 @@ impl Server {
let handle = tokio::spawn(async move {
match config.protocol.as_ref() {
"tcp" => {
let _ = tcp::proxy(config).await;
let res = tcp::proxy(config.clone()).await;
if res.is_err() {
error!("Failed to start {}: {}", config.name, res.err().unwrap());
}
}
"kcp" => {
let _ = kcp::proxy(config).await;
let res = kcp::proxy(config.clone()).await;
if res.is_err() {
error!("Failed to start {}: {}", config.name, res.err().unwrap());
}
}
_ => {
error!("Invalid protocol: {}", config.protocol)
Expand Down

0 comments on commit 8fbc0c3

Please sign in to comment.