195 releases (16 breaking)

new 0.17.15 Nov 12, 2024
0.17.13 Oct 29, 2024
0.17.6 Jul 29, 2024
0.16.1 Mar 28, 2024
0.4.1 Jul 31, 2023

#614 in Network programming

Download history 469/week @ 2024-07-27 264/week @ 2024-08-03 333/week @ 2024-08-10 202/week @ 2024-08-17 395/week @ 2024-08-24 206/week @ 2024-08-31 353/week @ 2024-09-07 302/week @ 2024-09-14 474/week @ 2024-09-21 609/week @ 2024-09-28 472/week @ 2024-10-05 312/week @ 2024-10-12 513/week @ 2024-10-19 511/week @ 2024-10-26 514/week @ 2024-11-02 384/week @ 2024-11-09

1,970 downloads per month
Used in 16 crates (13 directly)

GPL-3.0 license

450KB
8K SLoC

sn_protocol

Overview

The sn_protocol directory contains the core protocol logic for the Safe Network. It includes various modules that handle different aspects of the protocol, such as error handling, messages, and storage.

Table of Contents

Error Handling

The error.rs file contains the definitions for various errors that can occur within the protocol.

Error Types

  • ChunkNotFound(ChunkAddress): Indicates that a chunk was not found.
    • Example: Result::Err(Error::ChunkNotFound(chunk_address))
  • ChunkNotStored(XorName): Indicates that a chunk was not stored.
    • Example: Result::Err(Error::ChunkNotStored(xor_name))
  • RegisterNotFound(Box<RegisterAddress>): Indicates that a register was not found.
    • Example: Result::Err(Error::RegisterNotFound(register_address))
  • SpendNotFound(SpendAddress): Indicates that a spend was not found.
    • Example: Result::Err(Error::SpendNotFound(cash_note_address))
  • DoubleSpendAttempt(Box<SignedSpend>, Box<SignedSpend>): Indicates a double spend attempt.
    • Example: Result::Err(Error::DoubleSpendAttempt(spend1, spend2))

Messages

The messages module contains different types of messages that can be sent or received within the protocol.

Cmd Messages

Cmd::Replicate

  • Description: Write operation to notify peer fetch a list of NetworkAddress from the holder.
  • Parameters:
    • holder: NetworkAddress: Holder of the replication keys.
    • keys: Vec<NetworkAddress>: Keys of the copy that shall be replicated.

Query Messages

Query::GetStoreCost

  • Description: Retrieve the cost of storing a record at the given address.
  • Parameters:
    • address: NetworkAddress: The address where the record will be stored.

Response Messages

QueryResponse::GetStoreCost

  • Description: The store cost in nanos for storing the next record.
  • Parameters:
    • store_cost: Result<Token>: The cost of storing the record.
    • payment_address: PublicAddress: The address to pay the store cost to.

CmdResponse::Replicate

  • Description: Response to replication cmd.
  • Parameters:
    • Result<()>: The result of the replication command.

Storage

The storage module handles the storage aspects of the protocol.

API Calls

  • ChunkAddress: Address of a chunk in the network.
  • SpendAddress: Address of a CashNote's Spend in the network.
  • Header: Header information for storage items.

Protobuf Definitions

The safenode_proto directory contains the Protocol Buffers definitions for the Safe Network.

Files

  • req_resp_types.proto: Definitions for request and response types.
  • safenode.proto: Main Protocol Buffers definitions for the Safe Network.

Dependencies

~50–67MB
~1.5M SLoC