Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions lib-network/src/blockchain_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ use anyhow::Result;
use lib_crypto::PublicKey;
use crate::types::mesh_message::ZhtpMeshMessage;
use crate::protocols::NetworkProtocol;
use crate::mtu::{
BLE_CHUNK_SIZE, BLUETOOTH_CLASSIC_CHUNK_SIZE, WIFI_DIRECT_CHUNK_SIZE, DEFAULT_CHUNK_SIZE,
};
use std::time::Duration;

/// Chunk sizes based on protocol capabilities
pub const BLE_CHUNK_SIZE: usize = 200; // Conservative for BLE GATT (247-byte MTU)
pub const CLASSIC_CHUNK_SIZE: usize = 1000; // Bluetooth Classic RFCOMM (larger MTU)
pub const WIFI_CHUNK_SIZE: usize = 1400; // WiFi Direct (can handle more)
pub const DEFAULT_CHUNK_SIZE: usize = 200; // Safe fallback
/// Re-export chunk sizes for backward compatibility
#[deprecated(since = "0.1.0", note = "Use crate::mtu::BLE_CHUNK_SIZE instead")]
pub const BLE_CHUNK_SIZE_COMPAT: usize = BLE_CHUNK_SIZE;

#[deprecated(since = "0.1.0", note = "Use crate::mtu::BLUETOOTH_CLASSIC_CHUNK_SIZE instead")]
pub const CLASSIC_CHUNK_SIZE: usize = BLUETOOTH_CLASSIC_CHUNK_SIZE;

#[deprecated(since = "0.1.0", note = "Use crate::mtu::WIFI_DIRECT_CHUNK_SIZE instead")]
pub const WIFI_CHUNK_SIZE: usize = WIFI_DIRECT_CHUNK_SIZE;
Comment on lines +54 to +62
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backward compatibility aliases are incomplete. The old module exported BLE_CHUNK_SIZE and WIFI_CHUNK_SIZE as public constants, but the new code doesn't provide deprecated aliases for these names. Code importing blockchain_sync::BLE_CHUNK_SIZE or blockchain_sync::WIFI_CHUNK_SIZE will fail to compile. Add deprecated pub const definitions for these missing names.

Copilot uses AI. Check for mistakes.

/// Security constraints - Original limits
pub const MAX_CHUNK_BUFFER_SIZE: usize = 10_000_000; // 10MB max buffer per request
Expand Down Expand Up @@ -82,11 +89,13 @@ pub const MAX_REQUESTS_PER_PEER: usize = 10;

/// Get optimal chunk size for protocol
pub fn get_chunk_size_for_protocol(protocol: &NetworkProtocol) -> usize {
use crate::mtu::Protocol;

match protocol {
NetworkProtocol::BluetoothLE => BLE_CHUNK_SIZE,
NetworkProtocol::BluetoothClassic => CLASSIC_CHUNK_SIZE,
NetworkProtocol::WiFiDirect => WIFI_CHUNK_SIZE,
NetworkProtocol::TCP | NetworkProtocol::UDP => WIFI_CHUNK_SIZE,
NetworkProtocol::BluetoothLE => Protocol::BluetoothLE.chunk_size(),
NetworkProtocol::BluetoothClassic => Protocol::BluetoothClassic.chunk_size(),
NetworkProtocol::WiFiDirect => Protocol::WiFiDirect.chunk_size(),
NetworkProtocol::TCP | NetworkProtocol::UDP => Protocol::Udp.chunk_size(),
_ => DEFAULT_CHUNK_SIZE,
}
}
Expand Down
16 changes: 8 additions & 8 deletions lib-network/src/discovery/lorawan_hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async fn test_serial_lorawan_module(port: &str, chip_type: &str) -> Result<LoRaW
class_a: true,
otaa_support: true,
abp_support: true,
max_payload_size: 242,
max_payload_size: crate::mtu::LORAWAN_MAX_PAYLOAD,
spreading_factors: vec![7, 8, 9, 10, 11, 12],
..Default::default()
},
Expand Down Expand Up @@ -376,7 +376,7 @@ async fn detect_i2c_lorawan(address: &str) -> Result<LoRaWANHardware> {
class_a: true,
otaa_support: true,
abp_support: true,
max_payload_size: 242,
max_payload_size: crate::mtu::LORAWAN_MAX_PAYLOAD,
spreading_factors: vec![7, 8, 9, 10, 11, 12],
..Default::default()
},
Expand Down Expand Up @@ -414,7 +414,7 @@ async fn detect_raspberry_pi_lorawan_hat() -> Result<LoRaWANHardware> {
class_c: true,
otaa_support: true,
abp_support: true,
max_payload_size: 242,
max_payload_size: crate::mtu::LORAWAN_MAX_PAYLOAD,
spreading_factors: vec![7, 8, 9, 10, 11, 12],
..Default::default()
},
Expand Down Expand Up @@ -445,7 +445,7 @@ fn create_sx127x_hardware(chip_name: &str, spi_path: &str) -> LoRaWANHardware {
class_c: true,
otaa_support: true,
abp_support: true,
max_payload_size: 242,
max_payload_size: crate::mtu::LORAWAN_MAX_PAYLOAD,
spreading_factors: vec![6, 7, 8, 9, 10, 11, 12],
..Default::default()
},
Expand All @@ -466,7 +466,7 @@ fn create_sx130x_hardware(chip_name: &str, spi_path: &str) -> LoRaWANHardware {
class_c: true,
otaa_support: true,
abp_support: true,
max_payload_size: 242,
max_payload_size: crate::mtu::LORAWAN_MAX_PAYLOAD,
spreading_factors: vec![7, 8, 9, 10, 11, 12],
..Default::default()
},
Expand Down Expand Up @@ -509,7 +509,7 @@ async fn detect_windows_lorawan() -> Result<LoRaWANHardware> {
class_a: true,
otaa_support: true,
abp_support: true,
max_payload_size: 242,
max_payload_size: crate::mtu::LORAWAN_MAX_PAYLOAD,
spreading_factors: vec![7, 8, 9, 10],
..Default::default()
},
Expand Down Expand Up @@ -559,7 +559,7 @@ async fn test_windows_com_lorawan(port_name: &str) -> Result<LoRaWANHardware> {
class_a: true,
otaa_support: true,
abp_support: true,
max_payload_size: 242,
max_payload_size: crate::mtu::LORAWAN_MAX_PAYLOAD,
spreading_factors: vec![7, 8, 9, 10],
..Default::default()
},
Expand Down Expand Up @@ -632,7 +632,7 @@ async fn test_macos_usb_lorawan(device_path: &str) -> Result<LoRaWANHardware> {
class_a: true,
otaa_support: true,
abp_support: true,
max_payload_size: 242,
max_payload_size: crate::mtu::LORAWAN_MAX_PAYLOAD,
spreading_factors: vec![7, 8, 9, 10, 11, 12],
..Default::default()
},
Expand Down
Loading
Loading