Skip to content

Commit adf5bd1

Browse files
committed
style: Apply rustfmt formatting
1 parent 6c1eb12 commit adf5bd1

12 files changed

Lines changed: 245 additions & 124 deletions

File tree

crates/aingle_minimal/src/error.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ pub enum Error {
7979
#[derive(Debug, Clone)]
8080
pub enum CryptoError {
8181
/// Invalid key format or length.
82-
InvalidKey { expected_len: usize, actual_len: usize },
82+
InvalidKey {
83+
expected_len: usize,
84+
actual_len: usize,
85+
},
8386
/// Signature verification failed.
8487
InvalidSignature,
8588
/// Key generation failed.
@@ -225,8 +228,15 @@ impl std::fmt::Display for Error {
225228
impl std::fmt::Display for CryptoError {
226229
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
227230
match self {
228-
CryptoError::InvalidKey { expected_len, actual_len } => {
229-
write!(f, "Invalid key: expected {} bytes, got {}", expected_len, actual_len)
231+
CryptoError::InvalidKey {
232+
expected_len,
233+
actual_len,
234+
} => {
235+
write!(
236+
f,
237+
"Invalid key: expected {} bytes, got {}",
238+
expected_len, actual_len
239+
)
230240
}
231241
CryptoError::InvalidSignature => write!(f, "Invalid signature"),
232242
CryptoError::KeyGenerationFailed(s) => write!(f, "Key generation failed: {}", s),
@@ -735,7 +745,13 @@ mod tests {
735745
#[test]
736746
fn test_crypto_error_display() {
737747
assert_eq!(
738-
format!("{}", CryptoError::InvalidKey { expected_len: 32, actual_len: 16 }),
748+
format!(
749+
"{}",
750+
CryptoError::InvalidKey {
751+
expected_len: 32,
752+
actual_len: 16
753+
}
754+
),
739755
"Invalid key: expected 32 bytes, got 16"
740756
);
741757
assert_eq!(

crates/aingle_minimal/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ pub mod network;
207207
pub mod node;
208208
pub mod ota;
209209
pub mod power;
210+
#[cfg(feature = "quic")]
211+
pub mod quic;
210212
pub mod sensors;
211213
#[cfg(feature = "smart_agents")]
212214
pub mod smart;
@@ -216,8 +218,6 @@ pub mod types;
216218
pub mod wallet;
217219
#[cfg(feature = "webrtc")]
218220
pub mod webrtc;
219-
#[cfg(feature = "quic")]
220-
pub mod quic;
221221

222222
// Storage - trait is always available
223223
pub mod storage_trait;
@@ -243,8 +243,6 @@ pub use storage_trait::{StorageBackend, StorageStats};
243243
pub use bluetooth::{BleConfig, BleManager, BlePeer, BleState, BleStats};
244244
#[cfg(feature = "coap")]
245245
pub use coap::{CoapConfig, CoapServer};
246-
#[cfg(feature = "quic")]
247-
pub use quic::{QuicConfig, QuicServer};
248246
pub use config::{Config, GossipConfig, MeshMode, PowerMode, StorageConfig, TransportConfig};
249247
pub use discovery::{DiscoveredPeer, Discovery};
250248
#[cfg(feature = "coap")]
@@ -259,6 +257,8 @@ pub use memory::IoTMemory;
259257
pub use node::{MinimalNode, PeerRecord};
260258
pub use ota::{OtaManager, UpdateChannel, UpdateInfo, UpdateState};
261259
pub use power::{BatteryInfo, PowerManager, PowerProfile};
260+
#[cfg(feature = "quic")]
261+
pub use quic::{QuicConfig, QuicServer};
262262
pub use sensors::{CalibrationParams, Sensor, SensorManager, SensorReading, SensorType};
263263
#[cfg(feature = "smart_agents")]
264264
pub use smart::{IoTPolicyBuilder, SensorAdapter, SmartNode, SmartNodeConfig, SmartNodeStats};

crates/aingle_minimal/src/main.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,9 @@ fn main() -> Result<()> {
137137
let cli = Cli::parse();
138138

139139
// Initialize logging
140-
env_logger::Builder::from_env(
141-
env_logger::Env::default().default_filter_or(&cli.log_level),
142-
)
143-
.format_timestamp_millis()
144-
.init();
140+
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(&cli.log_level))
141+
.format_timestamp_millis()
142+
.init();
145143

146144
match cli.command {
147145
Some(Commands::Run {
@@ -169,7 +167,10 @@ fn main() -> Result<()> {
169167
Some(Commands::Info) => show_info(),
170168
Some(Commands::Config { action }) => config_action(action),
171169
Some(Commands::Version) => show_version(),
172-
Some(Commands::Bench { entries, iterations }) => run_benchmark(entries, iterations),
170+
Some(Commands::Bench {
171+
entries,
172+
iterations,
173+
}) => run_benchmark(entries, iterations),
173174
None => {
174175
// Default: show help
175176
print_banner();
@@ -240,10 +241,7 @@ fn run_node(
240241
}
241242

242243
// Update transport config
243-
config.transport = aingle_minimal::TransportConfig::Coap {
244-
bind_addr,
245-
port,
246-
};
244+
config.transport = aingle_minimal::TransportConfig::Coap { bind_addr, port };
247245

248246
// Print configuration
249247
println!("\nConfiguration:");
@@ -316,7 +314,10 @@ fn show_info() -> Result<()> {
316314
println!("Build Information:");
317315
println!(" Version: {}", aingle_minimal::VERSION);
318316
println!(" MSRV: {}", aingle_minimal::MSRV);
319-
println!(" Memory budget: {} KB", aingle_minimal::MEMORY_BUDGET / 1024);
317+
println!(
318+
" Memory budget: {} KB",
319+
aingle_minimal::MEMORY_BUDGET / 1024
320+
);
320321
println!();
321322

322323
println!("Features:");
@@ -408,7 +409,10 @@ fn print_config(config: &Config) {
408409
println!("\nGossip:");
409410
println!(" max_peers: {}", config.gossip.max_peers);
410411
println!(" loop_delay: {:?}", config.gossip.loop_delay);
411-
println!(" output_target_mbps: {}", config.gossip.output_target_mbps);
412+
println!(
413+
" output_target_mbps: {}",
414+
config.gossip.output_target_mbps
415+
);
412416
println!("\nStorage:");
413417
println!(" db_path: {}", config.storage.db_path);
414418
println!(" backend: {:?}", config.storage.backend);
@@ -430,13 +434,21 @@ fn print_config(config: &Config) {
430434
println!(" mode: {:?}", mode);
431435
}
432436
#[cfg(feature = "webrtc")]
433-
aingle_minimal::TransportConfig::WebRtc { stun_server, signaling_port, .. } => {
437+
aingle_minimal::TransportConfig::WebRtc {
438+
stun_server,
439+
signaling_port,
440+
..
441+
} => {
434442
println!(" type: WebRTC");
435443
println!(" stun_server: {}", stun_server);
436444
println!(" signaling_port: {}", signaling_port);
437445
}
438446
#[cfg(feature = "ble")]
439-
aingle_minimal::TransportConfig::Ble { device_name, mesh_relay, tx_power } => {
447+
aingle_minimal::TransportConfig::Ble {
448+
device_name,
449+
mesh_relay,
450+
tx_power,
451+
} => {
440452
println!(" type: Bluetooth LE");
441453
println!(" device_name: {}", device_name);
442454
println!(" mesh_relay: {}", mesh_relay);
@@ -450,7 +462,10 @@ fn show_version() -> Result<()> {
450462
println!();
451463
println!("Build info:");
452464
println!(" Rust MSRV: {}", aingle_minimal::MSRV);
453-
println!(" Target memory: {} KB", aingle_minimal::MEMORY_BUDGET / 1024);
465+
println!(
466+
" Target memory: {} KB",
467+
aingle_minimal::MEMORY_BUDGET / 1024
468+
);
454469

455470
#[cfg(debug_assertions)]
456471
println!(" Profile: debug");

crates/aingle_minimal/src/network.rs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,7 @@ impl MeshManager {
207207
}
208208

209209
/// Wrap a message for mesh relay
210-
pub fn wrap_for_relay(
211-
node_id: &str,
212-
message: Message,
213-
ttl: Option<u8>,
214-
) -> Message {
210+
pub fn wrap_for_relay(node_id: &str, message: Message, ttl: Option<u8>) -> Message {
215211
let message_id = Self::generate_message_id(node_id);
216212
Message::MeshRelay {
217213
message_id,
@@ -639,12 +635,7 @@ impl Network {
639635
return Err(e);
640636
}
641637

642-
log::debug!(
643-
"RPC call {} to {}: method={}",
644-
request_id,
645-
addr,
646-
method
647-
);
638+
log::debug!("RPC call {} to {}: method={}", request_id, addr, method);
648639

649640
// Wait for response with timeout
650641
match smol::future::or(
@@ -698,11 +689,7 @@ impl Network {
698689
let elapsed = pending.sent_at.elapsed();
699690

700691
if let Err(e) = pending.response_tx.try_send(response) {
701-
log::warn!(
702-
"Failed to deliver RPC response {}: {:?}",
703-
request_id,
704-
e
705-
);
692+
log::warn!("Failed to deliver RPC response {}: {:?}", request_id, e);
706693
} else {
707694
log::debug!(
708695
"RPC {} response delivered (method={}, elapsed={:?})",
@@ -1703,7 +1690,13 @@ mod tests {
17031690
assert!(json.contains("get_status"));
17041691

17051692
let parsed: Message = serde_json::from_str(&json).unwrap();
1706-
if let Message::RemoteCall { request_id, from, method, payload } = parsed {
1693+
if let Message::RemoteCall {
1694+
request_id,
1695+
from,
1696+
method,
1697+
payload,
1698+
} = parsed
1699+
{
17071700
assert_eq!(request_id, "rpc-123");
17081701
assert_eq!(from, "node-abc");
17091702
assert_eq!(method, "get_status");
@@ -1727,7 +1720,12 @@ mod tests {
17271720
assert!(json.contains("true"));
17281721

17291722
let parsed: Message = serde_json::from_str(&json).unwrap();
1730-
if let Message::RemoteCallResponse { request_id, success, data } = parsed {
1723+
if let Message::RemoteCallResponse {
1724+
request_id,
1725+
success,
1726+
data,
1727+
} = parsed
1728+
{
17311729
assert_eq!(request_id, "rpc-456");
17321730
assert!(success);
17331731
assert_eq!(data, b"result data".to_vec());
@@ -1763,12 +1761,9 @@ mod tests {
17631761

17641762
smol::block_on(async {
17651763
let addr: SocketAddr = "127.0.0.1:5683".parse().unwrap();
1766-
let result = network.send_remote_call(
1767-
&addr,
1768-
"test_method",
1769-
vec![],
1770-
Duration::from_secs(1),
1771-
).await;
1764+
let result = network
1765+
.send_remote_call(&addr, "test_method", vec![], Duration::from_secs(1))
1766+
.await;
17721767

17731768
// Without CoAP feature, should return error
17741769
assert!(result.is_err());
@@ -1798,8 +1793,7 @@ mod tests {
17981793
fn test_mesh_manager_process_relay_new() {
17991794
let mut mesh = MeshManager::new();
18001795

1801-
let (should_process, should_relay, new_ttl) =
1802-
mesh.process_relay("msg-1", 5);
1796+
let (should_process, should_relay, new_ttl) = mesh.process_relay("msg-1", 5);
18031797

18041798
assert!(should_process);
18051799
assert!(should_relay);
@@ -1835,8 +1829,7 @@ mod tests {
18351829
fn test_mesh_manager_process_relay_ttl_one() {
18361830
let mut mesh = MeshManager::new();
18371831

1838-
let (should_process, should_relay, new_ttl) =
1839-
mesh.process_relay("msg-1", 1);
1832+
let (should_process, should_relay, new_ttl) = mesh.process_relay("msg-1", 1);
18401833

18411834
assert!(should_process);
18421835
assert!(!should_relay); // TTL=0 after decrement, no relay

crates/aingle_minimal/src/node.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -817,14 +817,21 @@ impl MinimalNode {
817817
for record in peer_records {
818818
// Skip peers with very low quality or that haven't been seen in > 24 hours
819819
if record.quality < 10 {
820-
log::debug!("Skipping low-quality peer: {} (quality={})", record.addr, record.quality);
820+
log::debug!(
821+
"Skipping low-quality peer: {} (quality={})",
822+
record.addr,
823+
record.quality
824+
);
821825
continue;
822826
}
823827

824828
let age_secs = now.saturating_sub(record.last_seen_secs);
825829
if age_secs > 24 * 60 * 60 {
826-
log::debug!("Skipping stale peer: {} (last seen {} hours ago)",
827-
record.addr, age_secs / 3600);
830+
log::debug!(
831+
"Skipping stale peer: {} (last seen {} hours ago)",
832+
record.addr,
833+
age_secs / 3600
834+
);
828835
continue;
829836
}
830837

@@ -1372,7 +1379,9 @@ mod tests {
13721379
}];
13731380

13741381
let json = serde_json::to_string(&records).unwrap();
1375-
node.storage.set_metadata(PEERS_METADATA_KEY, &json).unwrap();
1382+
node.storage
1383+
.set_metadata(PEERS_METADATA_KEY, &json)
1384+
.unwrap();
13761385

13771386
// Load peers - should skip the low-quality peer
13781387
node.load_peers().unwrap();
@@ -1402,7 +1411,9 @@ mod tests {
14021411
}];
14031412

14041413
let json = serde_json::to_string(&records).unwrap();
1405-
node.storage.set_metadata(PEERS_METADATA_KEY, &json).unwrap();
1414+
node.storage
1415+
.set_metadata(PEERS_METADATA_KEY, &json)
1416+
.unwrap();
14061417

14071418
// Load peers - should skip the stale peer
14081419
node.load_peers().unwrap();
@@ -1431,7 +1442,9 @@ mod tests {
14311442
}];
14321443

14331444
let json = serde_json::to_string(&records).unwrap();
1434-
node.storage.set_metadata(PEERS_METADATA_KEY, &json).unwrap();
1445+
node.storage
1446+
.set_metadata(PEERS_METADATA_KEY, &json)
1447+
.unwrap();
14351448

14361449
// Load peers - should accept the good peer
14371450
node.load_peers().unwrap();
@@ -1460,7 +1473,9 @@ mod tests {
14601473
}];
14611474

14621475
let json = serde_json::to_string(&records).unwrap();
1463-
node.storage.set_metadata(PEERS_METADATA_KEY, &json).unwrap();
1476+
node.storage
1477+
.set_metadata(PEERS_METADATA_KEY, &json)
1478+
.unwrap();
14641479

14651480
// Load peers - should succeed but skip invalid address
14661481
let result = node.load_peers();

crates/aingle_minimal/src/ota.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ impl UpdateInfo {
8383
/// Check if update is newer than current version
8484
pub fn is_newer(&self, current_version: &str) -> bool {
8585
// Use proper semver comparison
86-
match (Version::parse(&self.version), Version::parse(current_version)) {
86+
match (
87+
Version::parse(&self.version),
88+
Version::parse(current_version),
89+
) {
8790
(Ok(update_ver), Ok(current)) => update_ver > current,
8891
// Fallback to string comparison if parsing fails
8992
_ => self.version.as_str() > current_version,

0 commit comments

Comments
 (0)