Skip to content

Commit

Permalink
use standalone librealm
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrchien committed Oct 15, 2022
1 parent fb5cc93 commit 161027d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 48 deletions.
56 changes: 44 additions & 12 deletions Cargo.lock

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

36 changes: 30 additions & 6 deletions src/bin.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use std::env;
use cfg_if::cfg_if;

use realm_core::dns;

use realm::cmd;
use realm::conf::{Config, FullConf, LogConf, DnsConf, EndpointInfo};
use realm::relay;
use realm::ENV_CONFIG;

cfg_if! {
Expand Down Expand Up @@ -95,7 +92,7 @@ fn setup_dns(dns: DnsConf) {
println!("dns: {}", &dns);

let (conf, opts) = dns.build();
dns::build(conf, opts);
realm::core::dns::build(conf, opts);
}

fn execute(eps: Vec<EndpointInfo>) {
Expand All @@ -105,7 +102,7 @@ fn execute(eps: Vec<EndpointInfo>) {
.enable_all()
.build()
.unwrap()
.block_on(relay::run(eps))
.block_on(run(eps))
}

#[cfg(not(feature = "multi-thread"))]
Expand All @@ -114,6 +111,33 @@ fn execute(eps: Vec<EndpointInfo>) {
.enable_all()
.build()
.unwrap()
.block_on(relay::run(eps))
.block_on(run(eps))
}
}

async fn run(endpoints: Vec<EndpointInfo>) {
use realm::core::tcp::run_tcp;
use realm::core::udp::run_udp;
use futures::future::join_all;

let mut workers = Vec::with_capacity(2 * endpoints.len());

for EndpointInfo {
endpoint,
no_tcp,
use_udp,
} in endpoints
{
if use_udp {
workers.push(tokio::spawn(run_udp(endpoint.clone())));
}

if !no_tcp {
workers.push(tokio::spawn(run_tcp(endpoint)));
}
}

workers.shrink_to_fit();

join_all(workers).await;
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod cmd;
pub mod conf;
pub mod relay;
pub mod consts;
pub use realm_core as core;

pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const ENV_CONFIG: &str = "REALM_CONF";
29 changes: 0 additions & 29 deletions src/relay.rs

This file was deleted.

0 comments on commit 161027d

Please sign in to comment.