mirror of
https://github.com/bolucat/Archive.git
synced 2025-10-05 16:18:04 +08:00
Update On Wed Nov 27 19:38:22 CET 2024
This commit is contained in:
@@ -94,7 +94,6 @@ impl ServerIdent {
|
||||
max_server_rtt: Duration,
|
||||
check_window: Duration,
|
||||
) -> ServerIdent {
|
||||
#[allow(unused_mut)]
|
||||
let mut connect_opts = context.connect_opts_ref().clone();
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
|
@@ -104,6 +104,9 @@ pub async fn run(config: Config) -> io::Result<()> {
|
||||
server_builder.set_dns_resolver(r.clone());
|
||||
}
|
||||
|
||||
let mut connect_opts = connect_opts.clone();
|
||||
let accept_opts = accept_opts.clone();
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
if let Some(fwmark) = inst.outbound_fwmark {
|
||||
connect_opts.fwmark = Some(fwmark);
|
||||
@@ -117,8 +120,8 @@ pub async fn run(config: Config) -> io::Result<()> {
|
||||
connect_opts.bind_interface = Some(bind_interface);
|
||||
}
|
||||
|
||||
server_builder.set_connect_opts(connect_opts.clone());
|
||||
server_builder.set_accept_opts(accept_opts.clone());
|
||||
server_builder.set_connect_opts(connect_opts);
|
||||
server_builder.set_accept_opts(accept_opts);
|
||||
|
||||
if let Some(c) = config.udp_max_associations {
|
||||
server_builder.set_udp_capacity(c);
|
||||
|
@@ -24,7 +24,7 @@ use super::{context::ServiceContext, tcprelay::TcpServer, udprelay::UdpServer};
|
||||
|
||||
/// Shadowsocks Server Builder
|
||||
pub struct ServerBuilder {
|
||||
context: Arc<ServiceContext>,
|
||||
context: ServiceContext,
|
||||
svr_cfg: ServerConfig,
|
||||
udp_expiry_duration: Option<Duration>,
|
||||
udp_capacity: Option<usize>,
|
||||
@@ -35,11 +35,11 @@ pub struct ServerBuilder {
|
||||
impl ServerBuilder {
|
||||
/// Create a new server builder from configuration
|
||||
pub fn new(svr_cfg: ServerConfig) -> ServerBuilder {
|
||||
ServerBuilder::with_context(Arc::new(ServiceContext::new()), svr_cfg)
|
||||
ServerBuilder::with_context(ServiceContext::new(), svr_cfg)
|
||||
}
|
||||
|
||||
/// Create a new server builder with context
|
||||
pub fn with_context(context: Arc<ServiceContext>, svr_cfg: ServerConfig) -> ServerBuilder {
|
||||
fn with_context(context: ServiceContext, svr_cfg: ServerConfig) -> ServerBuilder {
|
||||
ServerBuilder {
|
||||
context,
|
||||
svr_cfg,
|
||||
@@ -62,8 +62,7 @@ impl ServerBuilder {
|
||||
|
||||
/// Set `ConnectOpts`
|
||||
pub fn set_connect_opts(&mut self, opts: ConnectOpts) {
|
||||
let context = Arc::get_mut(&mut self.context).expect("cannot set ConnectOpts on a shared context");
|
||||
context.set_connect_opts(opts)
|
||||
self.context.set_connect_opts(opts)
|
||||
}
|
||||
|
||||
/// Set UDP association's expiry duration
|
||||
@@ -88,14 +87,12 @@ impl ServerBuilder {
|
||||
|
||||
/// Set customized DNS resolver
|
||||
pub fn set_dns_resolver(&mut self, resolver: Arc<DnsResolver>) {
|
||||
let context = Arc::get_mut(&mut self.context).expect("cannot set DNS resolver on a shared context");
|
||||
context.set_dns_resolver(resolver)
|
||||
self.context.set_dns_resolver(resolver)
|
||||
}
|
||||
|
||||
/// Set access control list
|
||||
pub fn set_acl(&mut self, acl: Arc<AccessControl>) {
|
||||
let context = Arc::get_mut(&mut self.context).expect("cannot set ACL on a shared context");
|
||||
context.set_acl(acl);
|
||||
self.context.set_acl(acl);
|
||||
}
|
||||
|
||||
/// Set `AcceptOpts` for accepting new connections
|
||||
@@ -105,14 +102,12 @@ impl ServerBuilder {
|
||||
|
||||
/// Try to connect IPv6 addresses first if hostname could be resolved to both IPv4 and IPv6
|
||||
pub fn set_ipv6_first(&mut self, ipv6_first: bool) {
|
||||
let context = Arc::get_mut(&mut self.context).expect("cannot set ipv6_first on a shared context");
|
||||
context.set_ipv6_first(ipv6_first);
|
||||
self.context.set_ipv6_first(ipv6_first);
|
||||
}
|
||||
|
||||
/// Set security config
|
||||
pub fn set_security_config(&mut self, security: &SecurityConfig) {
|
||||
let context = Arc::get_mut(&mut self.context).expect("cannot set security on a shared context");
|
||||
context.set_security_config(security)
|
||||
self.context.set_security_config(security)
|
||||
}
|
||||
|
||||
/// Start the server
|
||||
@@ -121,6 +116,8 @@ impl ServerBuilder {
|
||||
/// 2. Starts TCP server (listener)
|
||||
/// 3. Starts UDP server (listener)
|
||||
pub async fn build(mut self) -> io::Result<Server> {
|
||||
let context = Arc::new(self.context);
|
||||
|
||||
let mut plugin = None;
|
||||
|
||||
if let Some(plugin_cfg) = self.svr_cfg.plugin() {
|
||||
@@ -131,14 +128,14 @@ impl ServerBuilder {
|
||||
|
||||
let mut tcp_server = None;
|
||||
if self.svr_cfg.mode().enable_tcp() {
|
||||
let server = TcpServer::new(self.context.clone(), self.svr_cfg.clone(), self.accept_opts.clone()).await?;
|
||||
let server = TcpServer::new(context.clone(), self.svr_cfg.clone(), self.accept_opts.clone()).await?;
|
||||
tcp_server = Some(server);
|
||||
}
|
||||
|
||||
let mut udp_server = None;
|
||||
if self.svr_cfg.mode().enable_udp() {
|
||||
let server = UdpServer::new(
|
||||
self.context.clone(),
|
||||
context.clone(),
|
||||
self.svr_cfg.clone(),
|
||||
self.udp_expiry_duration,
|
||||
self.udp_capacity,
|
||||
@@ -149,7 +146,7 @@ impl ServerBuilder {
|
||||
}
|
||||
|
||||
Ok(Server {
|
||||
context: self.context,
|
||||
context,
|
||||
svr_cfg: self.svr_cfg,
|
||||
tcp_server,
|
||||
udp_server,
|
||||
|
Reference in New Issue
Block a user