Skip to content

Commit

Permalink
feat: let old nodes open ws listen by default
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Dec 5, 2024
1 parent 9df053c commit 8fbad87
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

33 changes: 32 additions & 1 deletion network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,38 @@ impl NetworkService {
let p2p_control: ServiceAsyncControl = p2p_control.clone().into();
handle.spawn_task(async move {
#[cfg(not(target_family = "wasm"))]
for addr in &config.listen_addresses {
let listen_addresses = {
let mut addresses = config
.listen_addresses
.clone()
.into_iter()
.collect::<HashSet<_>>()
.into_iter()
.collect::<Vec<_>>();
if config.reuse_tcp_with_ws {
let has_ws = addresses
.iter()
.any(|a| matches!(find_type(a), TransportType::Ws));
if !has_ws {
let ws_listen = {
let mut addr = addresses
.iter()
.find(|a| matches!(find_type(a), TransportType::Tcp))
.expect("Tcp listen must exsit")
.clone();
addr.push(Protocol::Ws);
addr
};
addresses.push(ws_listen);
}

addresses
} else {
addresses
}
};
#[cfg(not(target_family = "wasm"))]
for addr in &listen_addresses {
match p2p_service.listen(addr.to_owned()).await {
Ok(listen_address) => {
info!("Listen on address: {}", listen_address);
Expand Down
2 changes: 2 additions & 0 deletions resource/ckb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ bootnodes = [] # {{
# whitelist_peers = []
### Enable `SO_REUSEPORT` feature to reuse port on Linux, not supported on other OS yet
# reuse_port_on_linux = true
### Allow ckb to upgrade tcp listening to tcp + ws listening when only tcp listening is found
# reuse_tcp_with_ws = true

max_peers = 125
max_outbound_peers = 8
Expand Down
3 changes: 3 additions & 0 deletions util/app-config/src/configs/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ pub struct Config {
/// Network use reuse port or not
#[serde(default = "default_reuse")]
pub reuse_port_on_linux: bool,
/// Allow ckb to upgrade tcp listening to tcp + ws listening when only tcp listening is found
#[serde(default = "default_reuse")]
pub reuse_tcp_with_ws: bool,
/// Chain synchronization config options.
#[serde(default)]
pub sync: SyncConfig,
Expand Down

0 comments on commit 8fbad87

Please sign in to comment.