Skip to main content

Overview

The Settings struct contains all configuration parameters needed to initialize and run a TAPLE node. Settings are divided into network-related and node-specific categories.

Settings Struct

The main configuration structure that groups all settings.
pub struct Settings {
    pub network: NetworkSettings,
    pub node: NodeSettings,
}

Fields

network
NetworkSettings
P2P network configuration parameters. See NetworkSettings below.
node
NodeSettings
General node configuration parameters. See NodeSettings below.

Default Implementation

let settings = Settings::default();
Creates a Settings instance with default values for all fields.

NetworkSettings

P2P network configuration parameters of a TAPLE node.
pub struct NetworkSettings {
    pub listen_addr: Vec<ListenAddr>,
    pub known_nodes: Vec<String>,
    pub external_address: Vec<String>,
}

Fields

listen_addr
Vec<ListenAddr>
required
List of Multiaddr to listen on. See ListenAddr for address format.
known_nodes
Vec<String>
List of bootstrap nodes to connect to. Each entry should be in the format /ip4/127.0.0.1/tcp/40040/p2p/12D3KooW...
external_address
Vec<String>
List of external addresses to advertise to other nodes. Useful when behind NAT or firewalls.

Default Values

NetworkSettings {
    listen_addr: vec![ListenAddr::IP4 {
        addr: Some(Ipv4Addr::new(0, 0, 0, 0)),
        port: Some(40040),
    }],
    known_nodes: vec![],
    external_address: vec![],
}

Usage Example

use taple_core::commons::settings::{NetworkSettings, ListenAddr};
use std::net::Ipv4Addr;

let network_settings = NetworkSettings {
    listen_addr: vec![ListenAddr::IP4 {
        addr: Some(Ipv4Addr::new(0, 0, 0, 0)),
        port: Some(50000),
    }],
    known_nodes: vec![
        "/ip4/172.17.0.1/tcp/40040/p2p/12D3KooWLXexpg81PjdjnrhmHUxN7U5EtfXJgr9cahei1SJ9Ub3B".to_string(),
    ],
    external_address: vec![
        "/ip4/192.168.1.100/tcp/50000".to_string(),
    ],
};

NodeSettings

General settings of a TAPLE node.
pub struct NodeSettings {
    pub key_derivator: KeyDerivator,
    pub secret_key: String,
    pub digest_derivator: DigestDerivator,
    pub replication_factor: f64,
    pub timeout: u32,
    pub passvotation: u8,
    #[cfg(feature = "evaluation")]
    pub smartcontracts_directory: String,
}

Fields

key_derivator
KeyDerivator
required
The cryptographic algorithm to use for key derivation. Available options:
  • KeyDerivator::Ed25519 - Edwards-curve Digital Signature Algorithm
  • KeyDerivator::Secp256k1 - ECDSA using secp256k1 curve
secret_key
String
required
The secret key to be used by the node in hexadecimal format. Must match the specified key_derivator algorithm.
digest_derivator
DigestDerivator
required
The hash algorithm to use for generating event and subject identifiers. Available options:
  • DigestDerivator::Blake3_256 - BLAKE3 with 256-bit output
  • DigestDerivator::Blake3_512 - BLAKE3 with 512-bit output
  • DigestDerivator::SHA2_256 - SHA-2 with 256-bit output
  • DigestDerivator::SHA2_512 - SHA-2 with 512-bit output
  • DigestDerivator::SHA3_256 - SHA-3 with 256-bit output
  • DigestDerivator::SHA3_512 - SHA-3 with 512-bit output
replication_factor
f64
default:"0.25"
Percentage of network nodes receiving protocol messages in one iteration. Value must be between 0.0 and 1.0.
  • 0.25 means 25% of known nodes will receive messages
  • 1.0 means all nodes will receive messages (full broadcast)
timeout
u32
default:"3000"
Timeout in milliseconds to be used between protocol iterations.
passvotation
u8
default:"0"
Automatic voting behavior:
  • 0 - Normal voting (manual approval required)
  • 1 - Always accept votes automatically
  • 2 - Always reject votes automatically
smartcontracts_directory
String
default:"./contracts"
Directory path where smart contracts are stored. Only available when the evaluation feature is enabled.

Default Values

NodeSettings {
    key_derivator: KeyDerivator::Ed25519,
    secret_key: String::from(""),
    digest_derivator: DigestDerivator::Blake3_256,
    replication_factor: 0.25,
    timeout: 3000,
    passvotation: 0,
    #[cfg(feature = "evaluation")]
    smartcontracts_directory: "./contracts".into(),
}

Usage Example

use taple_core::commons::settings::NodeSettings;
use taple_core::commons::identifier::derive::KeyDerivator;
use taple_core::commons::identifier::derive::digest::DigestDerivator;

let node_settings = NodeSettings {
    key_derivator: KeyDerivator::Ed25519,
    secret_key: "a2a452a85b90b22bbd35ea5addca267e270e636245cd56244c0c4fae4ab8c0fa".to_string(),
    digest_derivator: DigestDerivator::Blake3_256,
    replication_factor: 0.5,
    timeout: 5000,
    passvotation: 0,
    smartcontracts_directory: "./my-contracts".to_string(),
};

ListenAddr

Represents a valid listening address for TAPLE. Internally constituted as a MultiAddr.
pub enum ListenAddr {
    Memory { port: Option<u32> },
    IP4 {
        addr: Option<std::net::Ipv4Addr>,
        port: Option<u32>,
    },
    IP6 {
        addr: Option<std::net::Ipv6Addr>,
        port: Option<u32>,
    },
}

Variants

Memory
{ port: Option<u32> }
Represents in-memory addressing for testing purposes.
IP4
{ addr: Option<Ipv4Addr>, port: Option<u32> }
Represents an IPv4 address.
IP6
{ addr: Option<Ipv6Addr>, port: Option<u32> }
Represents an IPv6 address.

Default

ListenAddr::IP4 {
    addr: Some(Ipv4Addr::new(0, 0, 0, 0)),
    port: Some(40040),
}

Methods

get_port

Returns the port number of the listening address.
pub fn get_port(&self) -> Option<u32>

increment_port

Increments the port by the specified offset.
pub fn increment_port(&mut self, offset: u32)
offset
u32
required
The value to add to the current port.

to_string

Converts the listening address to MultiAddr format string.
pub fn to_string(&self) -> Result<String, ListenAddrErrors>
multiaddr
String
The address in MultiAddr format (e.g., /ip4/0.0.0.0/tcp/40040).

Usage Examples

use taple_core::commons::settings::ListenAddr;
use std::net::{Ipv4Addr, Ipv6Addr};

// IPv4 address
let addr = ListenAddr::IP4 {
    addr: Some(Ipv4Addr::new(127, 0, 0, 1)),
    port: Some(8080),
};
let multiaddr = addr.to_string()?; // "/ip4/127.0.0.1/tcp/8080"

// IPv6 address
let addr = ListenAddr::IP6 {
    addr: Some(Ipv6Addr::LOCALHOST),
    port: Some(8080),
};

// Memory address (for testing)
let addr = ListenAddr::Memory { port: Some(1234) };

// Increment port
let mut addr = ListenAddr::default();
addr.increment_port(10); // Port becomes 40050

String Conversion

You can create a ListenAddr from a string in MultiAddr format:
use std::convert::TryFrom;

let addr = ListenAddr::try_from("/ip4/0.0.0.0/tcp/40040".to_string())?;
let addr = ListenAddr::try_from("/ip6/::1/tcp/8080".to_string())?;
let addr = ListenAddr::try_from("/memory/1234".to_string())?;

VotationType

Enum representing automatic voting behavior.
pub enum VotationType {
    Normal,
    AlwaysAccept,
    AlwaysReject,
}

Variants

Normal
VotationType
Manual voting required for each request.
AlwaysAccept
VotationType
Automatically accept all voting requests.
AlwaysReject
VotationType
Automatically reject all voting requests.

Conversion from u8

impl From<u8> for VotationType {
    fn from(passvotation: u8) -> Self {
        match passvotation {
            2 => Self::AlwaysReject,
            1 => Self::AlwaysAccept,
            _ => Self::Normal,
        }
    }
}

Complete Configuration Example

Here’s a complete example of configuring a TAPLE node:
use taple_core::commons::settings::{Settings, NetworkSettings, NodeSettings, ListenAddr};
use taple_core::commons::identifier::derive::KeyDerivator;
use taple_core::commons::identifier::derive::digest::DigestDerivator;
use std::net::Ipv4Addr;

let settings = Settings {
    network: NetworkSettings {
        listen_addr: vec![
            ListenAddr::IP4 {
                addr: Some(Ipv4Addr::new(0, 0, 0, 0)),
                port: Some(50000),
            }
        ],
        known_nodes: vec![
            "/ip4/172.17.0.1/tcp/40040/p2p/12D3KooWRS3QVwqBtNp7rUCG4SF3nBrinQqJYC1N5qc1Wdr4jrze".to_string(),
        ],
        external_address: vec![],
    },
    node: NodeSettings {
        key_derivator: KeyDerivator::Ed25519,
        secret_key: "a2a452a85b90b22bbd35ea5addca267e270e636245cd56244c0c4fae4ab8c0fa".to_string(),
        digest_derivator: DigestDerivator::Blake3_256,
        replication_factor: 0.25,
        timeout: 3000,
        passvotation: 0,
        smartcontracts_directory: "./contracts".to_string(),
    },
};

// Use settings to build a node
let (node, api) = Node::build(settings, database)?;

Configuration from File

Settings can be loaded from configuration files using the config crate:
use config::{Config, File};
use taple_core::commons::settings::Settings;

let config = Config::builder()
    .add_source(File::with_name("config.toml"))
    .build()?;

let settings: Settings = config.try_deserialize()?;
Example config.toml:
[network]
listen_addr = ["/ip4/0.0.0.0/tcp/40040"]
knownnodes = [
    "/ip4/172.17.0.1/tcp/40040/p2p/12D3KooWRS3QVwqBtNp7rUCG4SF3nBrinQqJYC1N5qc1Wdr4jrze"
]
externaladdress = []

[node]
keyderivator = "Ed25519"
secretkey = "a2a452a85b90b22bbd35ea5addca267e270e636245cd56244c0c4fae4ab8c0fa"
digestderivator = "Blake3_256"
replication_factor = 0.25
timeout = 3000
passvotation = 0
smartcontracts_directory = "./contracts"

Source Reference

For more details, see the source code at core/src/commons/settings/mod.rs:10-297.

Build docs developers (and LLMs) love