Overview
ThePeers 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.Result containing the Peers instance, or an error if creation fails.
Example
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.The initial capacity for the peer collection. Allocating capacity upfront can reduce memory reallocations as peers are added.
Result containing the Peers instance, or an error if creation fails.
Example
Managing peers
insert()
Inserts a new peer into the set.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.Reference to the peer’s public key, used for cryptographic identification and verification.
The capabilities configuration for this peer. See PeerCapabilities for available options.
Result indicating success or failure. Returns an error if the address format is invalid.
Example
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.