Skip to content

Commit 87a0619

Browse files
committed
feat(shadowsocks-service): Better coding style with cfg_if (#1982)
1 parent 84bb832 commit 87a0619

File tree

1 file changed

+17
-4
lines changed
  • crates/shadowsocks-service/src/manager

1 file changed

+17
-4
lines changed

crates/shadowsocks-service/src/manager/server.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::path::PathBuf;
55
use std::{collections::HashMap, io, net::SocketAddr, sync::Arc, time::Duration};
66

7+
use cfg_if::cfg_if;
78
use log::{error, info, trace};
89
use shadowsocks::{
910
ManagerListener, ServerAddr,
@@ -476,10 +477,22 @@ impl Manager {
476477
return Ok(AddResponse(err));
477478
}
478479
},
479-
#[cfg(feature = "aead-cipher")]
480-
None => self.svr_cfg.method.unwrap_or(CipherKind::CHACHA20_POLY1305),
481-
#[cfg(not(feature = "aead-cipher"))]
482-
None => return Ok(AddResponse("method is required".to_string())),
480+
None => match self.svr_cfg.method {
481+
Some(m) => m,
482+
None => {
483+
cfg_if! {
484+
if #[cfg(feature = "aead-cipher")] {
485+
// If AEAD cipher is enabled, use chacha20-poly1305 as default method
486+
// NOTE: This behavior is defined in shadowsocks-libev's `manager.c`
487+
CipherKind::CHACHA20_POLY1305
488+
} else {
489+
// AEAD cipher is disabled, default method is not defined in any standard or implementations.
490+
// TODO: Complete this after discussion.
491+
return Ok(AddResponse("method is required".to_string()));
492+
}
493+
}
494+
}
495+
},
483496
};
484497

485498
let mut svr_cfg = match ServerConfig::new(addr, req.password.clone(), method) {

0 commit comments

Comments
 (0)