Skip to main content

Overview

The Peers struct represents a unique set of peers in the network, where each peer is identified by their network address and public key. This struct is used to configure and manage the peer list for a Tashi Vertex session.

Creating a peers collection

new()

Creates a new empty set of peers.
pub fn new() -> crate::Result<Self>
Returns Returns a Result containing the Peers instance, or an error if creation fails. Example
use tashi_vertex::Peers;

let peers = Peers::new()?;

with_capacity()

Creates a new empty set of peers with the specified initial capacity. This can improve performance when you know the approximate number of peers in advance.
pub fn with_capacity(capacity: usize) -> crate::Result<Self>
Parameters
capacity
usize
required
The initial capacity for the peer collection. Allocating capacity upfront can reduce memory reallocations as peers are added.
Returns Returns a Result containing the Peers instance, or an error if creation fails. Example
use tashi_vertex::Peers;

// Create a peers collection with capacity for 10 peers
let peers = Peers::with_capacity(10)?;

Managing peers

insert()

Inserts a new peer into the set.
pub fn insert(
    &mut self,
    address: &str,
    public: &KeyPublic,
    capabilities: PeerCapabilities,
) -> crate::Result<()>
Parameters
address
&str
required
The network address of the peer. Must be a valid IPv4 or IPv6 address including the port number (e.g., "192.168.1.100:8080" or "[2001:db8::1]:8080"). DNS lookup is not performed.
public
&KeyPublic
required
Reference to the peer’s public key, used for cryptographic identification and verification.
capabilities
PeerCapabilities
required
The capabilities configuration for this peer. See PeerCapabilities for available options.
Returns Returns a Result indicating success or failure. Returns an error if the address format is invalid. Example
use tashi_vertex::{Peers, KeyPublic, PeerCapabilities};

let mut peers = Peers::new()?;
let peer_key: KeyPublic = "BASE58_PUBLIC_KEY".parse()?;

let capabilities = PeerCapabilities {
    no_order: false,
    no_logic: false,
    public: true,
    unkickable: false,
};

peers.insert("192.168.1.100:8080", &peer_key, capabilities)?;
The address must be a valid IPv4 or IPv6 address with a port number. Domain names are not supported and will not be resolved.

Address format requirements

When adding peers to the collection, the address string must follow these requirements:
  • IPv4 format: "address:port" (e.g., "192.168.1.100:8080")
  • IPv6 format: "[address]:port" (e.g., "[2001:db8::1]:8080")
  • Port number is required
  • DNS hostnames are not supported
  • No DNS lookup is performed
For optimal performance when creating a peer collection with a known number of peers, use with_capacity() instead of new() to pre-allocate the required memory.

Build docs developers (and LLMs) love