Skip to content

Commit 021e904

Browse files
committed
Refactor configuration loading and network address parsing for improved readability. Simplify the logic in load_or_default method and enhance variable naming in the bootstrap peers loop.
1 parent d55d5cb commit 021e904

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/infrastructure/config.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ impl Default for AppConfig {
7575
impl AppConfig {
7676
/// Load configuration from file or create default
7777
pub fn load_or_default(config_path: Option<&str>) -> Self {
78-
if let Some(path) = config_path {
79-
if let Ok(content) = std::fs::read_to_string(path) {
80-
if let Ok(config) = serde_json::from_str(&content) {
81-
return config;
82-
}
83-
}
78+
if let Some(config) = config_path
79+
.and_then(|path| std::fs::read_to_string(path).ok())
80+
.and_then(|content| serde_json::from_str(&content).ok())
81+
{
82+
return config;
8483
}
8584
Self::default()
8685
}

src/infrastructure/network.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ impl LibP2pNetworkService {
146146
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
147147
];
148148

149-
for addr in &bootstrap_peers {
150-
if let Ok(addr) = addr.parse::<Multiaddr>() {
149+
for addr_str in &bootstrap_peers {
150+
if let Ok(addr) = addr_str.parse::<Multiaddr>() {
151151
if let Some(peer_id) = addr.iter().find_map(|p| {
152152
if let libp2p::multiaddr::Protocol::P2p(peer_id) = p {
153153
Some(peer_id)
@@ -234,12 +234,12 @@ impl LibP2pNetworkService {
234234
// Trigger Kademlia bootstrap once we start listening
235235
if !bootstrap_attempted {
236236
if let SwarmEvent::NewListenAddr { .. } = event {
237-
if let Err(e) = swarm.behaviour_mut().kademlia.bootstrap() {
238-
warn!("Kademlia bootstrap failed: {:?}", e);
239-
} else {
240-
info!("Kademlia bootstrap initiated successfully");
241-
bootstrap_attempted = true;
242-
}
237+
if let Err(e) = swarm.behaviour_mut().kademlia.bootstrap() {
238+
warn!("Kademlia bootstrap failed: {:?}", e);
239+
} else {
240+
info!("Kademlia bootstrap initiated successfully");
241+
bootstrap_attempted = true;
242+
}
243243
}
244244
}
245245

0 commit comments

Comments
 (0)