Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ postcard = { version = "1.1.3", features = ["use-std"] }
rmp-serde = "1"

# Byte utilities
bytes = "1"
bytes = { version = "1", features = ["serde"] }
hex = "0.4"

# Logging (optional — behind `logging` feature flag, mirroring ant-node)
Expand Down
17 changes: 12 additions & 5 deletions src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! This module defines the wire protocol messages for chunk operations
//! using postcard serialization for compact, fast encoding.

use bytes::Bytes;
use serde::{Deserialize, Serialize};

/// Protocol identifier for chunk operations.
Expand Down Expand Up @@ -121,12 +122,18 @@ impl ChunkMessage {
// =============================================================================

/// Request to store a chunk.
///
/// `content` is held as `bytes::Bytes` so that callers fanning the same
/// chunk out to multiple recipients (e.g. close-group replication) share a
/// single backing buffer via refcount instead of deep-copying the 4 MB
/// payload per peer. Wire format is unchanged: `Bytes` serializes as a
/// byte sequence, identical to `Vec<u8>` under postcard/serde.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChunkPutRequest {
/// The content-addressed identifier (BLAKE3 of content).
pub address: XorName,
/// The chunk data.
pub content: Vec<u8>,
pub content: Bytes,
/// Optional payment proof (serialized `ProofOfPayment`).
/// Required for new chunks unless already verified.
pub payment_proof: Option<Vec<u8>>,
Expand All @@ -135,7 +142,7 @@ pub struct ChunkPutRequest {
impl ChunkPutRequest {
/// Create a new PUT request.
#[must_use]
pub fn new(address: XorName, content: Vec<u8>) -> Self {
pub fn new(address: XorName, content: Bytes) -> Self {
Self {
address,
content,
Expand All @@ -145,7 +152,7 @@ impl ChunkPutRequest {

/// Create a new PUT request with payment proof.
#[must_use]
pub fn with_payment(address: XorName, content: Vec<u8>, payment_proof: Vec<u8>) -> Self {
pub fn with_payment(address: XorName, content: Bytes, payment_proof: Vec<u8>) -> Self {
Self {
address,
content,
Expand Down Expand Up @@ -386,7 +393,7 @@ mod tests {
#[test]
fn test_put_request_encode_decode() {
let address = [0xAB; 32];
let content = vec![1, 2, 3, 4, 5];
let content = Bytes::from_static(&[1, 2, 3, 4, 5]);
let request = ChunkPutRequest::new(address, content.clone());
let msg = ChunkMessage {
request_id: 42,
Expand All @@ -409,7 +416,7 @@ mod tests {
#[test]
fn test_put_request_with_payment() {
let address = [0xAB; 32];
let content = vec![1, 2, 3, 4, 5];
let content = Bytes::from_static(&[1, 2, 3, 4, 5]);
let payment = vec![10, 20, 30];
let request = ChunkPutRequest::with_payment(address, content.clone(), payment.clone());

Expand Down
Loading