Skip to content

Commit

Permalink
feat: default listen on ws port
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Nov 26, 2024
1 parent 80cfe48 commit fdb3704
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
7 changes: 7 additions & 0 deletions ckb-bin/src/subcommand/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,18 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> {

let log_to_file = args.log_to_file.to_string();
let log_to_stdout = args.log_to_stdout.to_string();
let ws_port = (args
.p2p_port
.parse::<u16>()
.unwrap_or_default()
.saturating_add(1))
.to_string();
let mut context = TemplateContext::new(
&args.chain,
vec![
("rpc_port", args.rpc_port.as_str()),
("p2p_port", args.p2p_port.as_str()),
("ws_port", ws_port.as_str()),
("log_to_file", log_to_file.as_str()),
("log_to_stdout", log_to_stdout.as_str()),
("block_assembler", block_assembler.as_str()),
Expand Down
4 changes: 2 additions & 2 deletions resource/ckb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ cache_size = 268435456
options_file = "default.db-options"

[network]
listen_addresses = ["/ip4/0.0.0.0/tcp/8115"] # {{
# _ => listen_addresses = ["/ip4/0.0.0.0/tcp/{p2p_port}"]
listen_addresses = ["/ip4/0.0.0.0/tcp/8115", "/ip4/0.0.0.0/tcp/8118/ws"] # {{
# _ => listen_addresses = ["/ip4/0.0.0.0/tcp/{p2p_port}", "/ip4/0.0.0.0/tcp/{ws_port}/ws"]
# }}
### Specify the public and routable network addresses
# public_addresses = []
Expand Down
20 changes: 17 additions & 3 deletions util/app-config/src/tests/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn test_export_dev_config_files() {
vec![
("rpc_port", "7000"),
("p2p_port", "8000"),
("ws_port", "8001"),
("log_to_file", "true"),
("log_to_stdout", "true"),
("block_assembler", ""),
Expand Down Expand Up @@ -86,6 +87,7 @@ fn test_log_to_stdout_only() {
vec![
("rpc_port", "7000"),
("p2p_port", "8000"),
("ws_port", "8001"),
("log_to_file", "false"),
("log_to_stdout", "true"),
("block_assembler", ""),
Expand Down Expand Up @@ -126,6 +128,7 @@ fn test_export_testnet_config_files() {
vec![
("rpc_port", "7000"),
("p2p_port", "8000"),
("ws_port", "8001"),
("log_to_file", "true"),
("log_to_stdout", "true"),
("block_assembler", ""),
Expand All @@ -148,7 +151,10 @@ fn test_export_testnet_config_files() {
);
assert_eq!(
ckb_config.network.listen_addresses,
vec!["/ip4/0.0.0.0/tcp/8000".parse().unwrap()]
vec![
"/ip4/0.0.0.0/tcp/8000".parse().unwrap(),
"/ip4/0.0.0.0/tcp/8001/ws".parse().unwrap()
]
);
assert_eq!(ckb_config.network.connect_outbound_interval_secs, 15);
assert_eq!(ckb_config.rpc.listen_address, "127.0.0.1:7000");
Expand Down Expand Up @@ -179,6 +185,7 @@ fn test_export_integration_config_files() {
vec![
("rpc_port", "7000"),
("p2p_port", "8000"),
("ws_port", "8001"),
("log_to_file", "true"),
("log_to_stdout", "true"),
("block_assembler", ""),
Expand All @@ -200,7 +207,10 @@ fn test_export_integration_config_files() {
);
assert_eq!(
ckb_config.network.listen_addresses,
vec!["/ip4/0.0.0.0/tcp/8000".parse().unwrap()]
vec![
"/ip4/0.0.0.0/tcp/8000".parse().unwrap(),
"/ip4/0.0.0.0/tcp/8001/ws".parse().unwrap()
]
);
assert_eq!(ckb_config.rpc.listen_address, "127.0.0.1:7000");
}
Expand Down Expand Up @@ -230,6 +240,7 @@ fn test_export_dev_config_files_assembly() {
vec![
("rpc_port", "7000"),
("p2p_port", "8000"),
("ws_port", "8001"),
("log_to_file", "true"),
("log_to_stdout", "true"),
("block_assembler", ""),
Expand All @@ -252,7 +263,10 @@ fn test_export_dev_config_files_assembly() {
);
assert_eq!(
ckb_config.network.listen_addresses,
vec!["/ip4/0.0.0.0/tcp/8000".parse().unwrap()]
vec![
"/ip4/0.0.0.0/tcp/8000".parse().unwrap(),
"/ip4/0.0.0.0/tcp/8001/ws".parse().unwrap()
]
);
assert_eq!(ckb_config.network.connect_outbound_interval_secs, 15);
assert_eq!(ckb_config.rpc.listen_address, "127.0.0.1:7000");
Expand Down
1 change: 1 addition & 0 deletions util/app-config/src/tests/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn no_deprecated_fields_in_bundled_ckb_app_config() {
vec![
("rpc_port", "7000"),
("p2p_port", "8000"),
("ws_port", "8001"),
("log_to_file", "true"),
("log_to_stdout", "true"),
("block_assembler", ""),
Expand Down

0 comments on commit fdb3704

Please sign in to comment.