Back to Site
Loading...
Searching...
No Matches
librats Namespace Reference

Namespaces

namespace  bencode
 Utility functions.
 
namespace  network_utils
 
namespace  SearchNodeFlags
 Search node state flags (bitfield) Flags can be combined to track the full history of a node in a search.
 

Classes

class  BencodeDecoder
 Bencode decoder. More...
 
class  BencodeValue
 Represents a bencoded value which can be: More...
 
struct  DeferredCallbacks
 Deferred callbacks structure for avoiding deadlock Callbacks are collected while holding the mutex, then invoked after releasing it. More...
 
class  DhtClient
 DHT Kademlia implementation. More...
 
struct  DhtNode
 DHT Node information Based on libtorrent's node_entry with fail_count and RTT tracking. More...
 
struct  DirectoryEntry
 
struct  DirectoryMetadata
 Directory transfer metadata. More...
 
struct  DnsHeader
 
struct  DnsMessage
 
struct  DnsQuestion
 
struct  DnsResourceRecord
 
struct  FileChunk
 File transfer chunk information. More...
 
struct  FileMetadata
 File metadata for transfers. More...
 
struct  FileTransferConfig
 File transfer configuration. More...
 
class  FileTransferManager
 File transfer manager class Handles efficient chunked file transfers with resume capability. More...
 
struct  FileTransferProgress
 File transfer progress information. More...
 
class  GossipSub
 Main GossipSub implementation class. More...
 
struct  GossipSubConfig
 GossipSub configuration parameters. More...
 
struct  IceCandidate
 ICE candidate. More...
 
struct  IceCandidatePair
 ICE candidate pair. More...
 
struct  IceConfig
 ICE configuration. More...
 
class  IceManager
 ICE-lite Manager for NAT traversal. More...
 
struct  IceServer
 STUN/TURN server configuration. More...
 
struct  KrpcMessage
 KRPC Message structure. More...
 
struct  KrpcNode
 KRPC Node information. More...
 
class  KrpcProtocol
 KRPC Protocol implementation. More...
 
class  Logger
 
class  MdnsClient
 
struct  MdnsService
 
struct  MessageHeader
 Message header structure for librats messages Fixed 8-byte header format: [0-3]: Magic number "RATS" (4 bytes) [4]: Message data type (1 byte) [5-7]: Reserved for future use (3 bytes) More...
 
struct  MessageMetadata
 Message metadata for tracking and deduplication. More...
 
struct  Peer
 UDP peer information. More...
 
struct  PeerScore
 Peer scoring metrics for mesh management. More...
 
class  RatsClient
 RatsClient - Core peer-to-peer networking client. More...
 
struct  RatsPeer
 RatsPeer struct - comprehensive information about a connected rats peer. More...
 
struct  ReconnectConfig
 ReconnectConfig - Configuration for automatic peer reconnection. More...
 
struct  ReconnectInfo
 ReconnectInfo - Information about a peer pending reconnection. More...
 
class  SHA1
 
struct  StunAttribute
 STUN attribute base class. More...
 
class  StunClient
 STUN Client for NAT traversal. More...
 
struct  StunClientConfig
 STUN client configuration. More...
 
struct  StunError
 STUN error information. More...
 
struct  StunMappedAddress
 STUN mapped address (result of binding request) More...
 
struct  StunMessage
 STUN message structure. More...
 
struct  StunResult
 STUN transaction result. More...
 
struct  SystemInfo
 
class  ThreadManager
 ThreadManager - Manages background threads with graceful shutdown. More...
 
struct  TopicSubscription
 Topic subscription information. More...
 

Typedefs

using MessageValidator = std::function< ValidationResult(const std::string &topic, const std::string &message, const std::string &sender_peer_id)>
 Callback types for GossipSub.
 
using MessageHandler = std::function< void(const std::string &topic, const std::string &message, const std::string &sender_peer_id)>
 
using PeerJoinedHandler = std::function< void(const std::string &topic, const std::string &peer_id)>
 
using PeerLeftHandler = std::function< void(const std::string &topic, const std::string &peer_id)>
 
using FileTransferProgressCallback = std::function< void(const FileTransferProgress &)>
 Callback function types for file transfer events.
 
using FileTransferCompletedCallback = std::function< void(const std::string &transfer_id, bool success, const std::string &error_message)>
 
using FileTransferRequestCallback = std::function< bool(const std::string &peer_id, const FileMetadata &metadata, const std::string &transfer_id)>
 
using DirectoryTransferProgressCallback = std::function< void(const std::string &transfer_id, const std::string &current_file, uint64_t files_completed, uint64_t total_files, uint64_t bytes_completed, uint64_t total_bytes)>
 
using FileRequestCallback = std::function< bool(const std::string &peer_id, const std::string &file_path, const std::string &transfer_id)>
 
using DirectoryRequestCallback = std::function< bool(const std::string &peer_id, const std::string &directory_path, bool recursive, const std::string &transfer_id)>
 
using NodeId = std::array< uint8_t, NODE_ID_SIZE >
 
using InfoHash = std::array< uint8_t, NODE_ID_SIZE >
 
using PeerDiscoveryCallback = std::function< void(const std::vector< Peer > &peers, const InfoHash &info_hash)>
 Peer discovery callback.
 
using SpiderAnnounceCallback = std::function< void(const InfoHash &info_hash, const Peer &peer)>
 Spider mode callback Called when a peer announces they have a torrent (announce_peer request received)
 
using IceCandidatesCallback = std::function< void(const std::vector< IceCandidate > &)>
 Callback when candidates are gathered.
 
using IceGatheringStateCallback = std::function< void(IceGatheringState)>
 Callback when gathering state changes.
 
using IceConnectionStateCallback = std::function< void(IceConnectionState)>
 Callback when connection state changes.
 
using IceNewCandidateCallback = std::function< void(const IceCandidate &)>
 Callback when a new candidate is discovered (trickle ICE)
 
using IceSelectedPairCallback = std::function< void(const IceCandidatePair &)>
 Callback when ICE completes with selected pair.
 
using MdnsServiceCallback = std::function< void(const MdnsService &service, bool is_new)>
 
using BencodeDict = std::unordered_map< std::string, BencodeValue >
 
using BencodeList = std::vector< BencodeValue >
 

Enumerations

enum class  MessageDataType : uint8_t { BINARY = 0x01 , STRING = 0x02 , JSON = 0x03 }
 Message data types for librats message headers. More...
 
enum class  GossipSubMessageType {
  SUBSCRIBE , UNSUBSCRIBE , PUBLISH , GOSSIP ,
  GRAFT , PRUNE , IHAVE , IWANT ,
  HEARTBEAT
}
 GossipSub message types. More...
 
enum class  ValidationResult { ACCEPT , REJECT , IGNORE_MSG }
 Message validation result. More...
 
enum class  FileTransferStatus {
  PENDING , STARTING , IN_PROGRESS , PAUSED ,
  COMPLETED , FAILED , CANCELLED , RESUMING
}
 File transfer status codes. More...
 
enum class  FileTransferDirection { SENDING , RECEIVING }
 File transfer direction. More...
 
enum class  StunMessageClass : uint8_t { Request = 0x00 , Indication = 0x01 , SuccessResponse = 0x02 , ErrorResponse = 0x03 }
 STUN message class (2 bits) More...
 
enum class  StunMethod : uint16_t {
  Binding = 0x001 , Allocate = 0x003 , Refresh = 0x004 , Send = 0x006 ,
  Data = 0x007 , CreatePermission = 0x008 , ChannelBind = 0x009
}
 STUN method (12 bits, only Binding is defined in RFC 5389) More...
 
enum class  StunMessageType : uint16_t {
  BindingRequest = 0x0001 , BindingIndication = 0x0011 , BindingSuccessResponse = 0x0101 , BindingErrorResponse = 0x0111 ,
  AllocateRequest = 0x0003 , AllocateSuccessResponse = 0x0103 , AllocateErrorResponse = 0x0113 , RefreshRequest = 0x0004 ,
  RefreshSuccessResponse = 0x0104 , RefreshErrorResponse = 0x0114 , SendIndication = 0x0016 , DataIndication = 0x0017 ,
  CreatePermissionRequest = 0x0008 , CreatePermissionSuccessResponse = 0x0108 , CreatePermissionErrorResponse = 0x0118 , ChannelBindRequest = 0x0009 ,
  ChannelBindSuccessResponse = 0x0109 , ChannelBindErrorResponse = 0x0119
}
 Combined STUN message type (method + class) More...
 
enum class  StunAttributeType : uint16_t {
  MappedAddress = 0x0001 , Username = 0x0006 , MessageIntegrity = 0x0008 , ErrorCode = 0x0009 ,
  UnknownAttributes = 0x000A , Realm = 0x0014 , Nonce = 0x0015 , XorMappedAddress = 0x0020 ,
  ChannelNumber = 0x000C , Lifetime = 0x000D , XorPeerAddress = 0x0012 , Data = 0x0013 ,
  XorRelayedAddress = 0x0016 , RequestedTransport = 0x0019 , DontFragment = 0x001A , Software = 0x8022 ,
  AlternateServer = 0x8023 , Fingerprint = 0x8028
}
 
enum class  StunAddressFamily : uint8_t { IPv4 = 0x01 , IPv6 = 0x02 }
 
enum class  StunErrorCode : uint16_t {
  TryAlternate = 300 , BadRequest = 400 , Unauthorized = 401 , Forbidden = 403 ,
  UnknownAttribute = 420 , StaleNonce = 438 , ServerError = 500 , AllocationMismatch = 437 ,
  WrongCredentials = 441 , UnsupportedTransportProtocol = 442 , AllocationQuotaReached = 486 , InsufficientCapacity = 508
}
 
enum class  IceCandidateType { Host , ServerReflexive , PeerReflexive , Relay }
 ICE candidate type. More...
 
enum class  IceTransportProtocol { UDP , TCP }
 ICE candidate transport protocol. More...
 
enum class  IceConnectionState {
  New , Gathering , Checking , Connected ,
  Completed , Failed , Disconnected , Closed
}
 ICE connection state. More...
 
enum class  IceGatheringState { New , Gathering , Complete }
 ICE gathering state. More...
 
enum class  IceCandidatePairState {
  Frozen , Waiting , InProgress , Succeeded ,
  Failed
}
 ICE candidate pair state. More...
 
enum class  DnsRecordType : uint16_t {
  A = 1 , PTR = 12 , TXT = 16 , AAAA = 28 ,
  SRV = 33
}
 
enum class  DnsRecordClass : uint16_t { CLASS_IN = 1 , CLASS_IN_FLUSH = 0x8001 }
 
enum class  MdnsFlags : uint16_t { QUERY = 0x0000 , RESPONSE = 0x8000 , AUTHORITATIVE = 0x8400 }
 
enum class  LogLevel { DEBUG = 0 , INFO = 1 , WARN = 2 , ERROR = 3 }
 
enum class  KrpcMessageType { Query , Response , Error }
 KRPC Message types. More...
 
enum class  KrpcQueryType { Ping , FindNode , GetPeers , AnnouncePeer }
 KRPC Query types. More...
 
enum class  KrpcErrorCode { GenericError = 201 , ServerError = 202 , ProtocolError = 203 , MethodUnknown = 204 }
 KRPC Error codes. More...
 

Functions

std::unique_ptr< RatsClientcreate_rats_client (int listen_port)
 
const char * rats_get_library_version_string ()
 
void rats_get_library_version (int *major, int *minor, int *patch, int *build)
 
const char * rats_get_library_git_describe ()
 
uint32_t rats_get_library_abi ()
 
NodeId string_to_node_id (const std::string &str)
 Utility functions.
 
std::string node_id_to_string (const NodeId &id)
 Convert NodeId to string.
 
NodeId hex_to_node_id (const std::string &hex)
 Convert hex string to NodeId.
 
std::string node_id_to_hex (const NodeId &id)
 Convert NodeId to hex string.
 
uint32_t stun_crc32 (const uint8_t *data, size_t length)
 Compute CRC32 for STUN FINGERPRINT attribute Uses CRC-32 as defined in RFC 5389 (ISO 3309)
 
std::array< uint8_t, 20 > stun_hmac_sha1 (const std::vector< uint8_t > &key, const std::vector< uint8_t > &data)
 Compute HMAC-SHA1 for MESSAGE-INTEGRITY attribute.
 
std::vector< uint8_t > stun_compute_long_term_key (const std::string &username, const std::string &realm, const std::string &password)
 Compute long-term credential key: MD5(username:realm:password)
 
StunMappedAddress stun_xor_address (const StunMappedAddress &addr, const std::array< uint8_t, STUN_TRANSACTION_ID_SIZE > &transaction_id)
 XOR an address with the magic cookie and transaction ID Used for XOR-MAPPED-ADDRESS encoding/decoding.
 
std::vector< std::pair< std::string, uint16_t > > get_public_stun_servers ()
 Get a list of well-known public STUN servers.
 
bool init_socket_library ()
 Initialize the socket library.
 
void cleanup_socket_library ()
 Cleanup the socket library.
 
socket_t create_tcp_client (const std::string &host, int port, int timeout_ms=0)
 Create a TCP client socket and connect to a server using dual stack (IPv6 with IPv4 fallback)
 
socket_t create_tcp_client_v4 (const std::string &host, int port, int timeout_ms=0)
 Create a TCP client socket and connect to a server using IPv4 only.
 
socket_t create_tcp_client_v6 (const std::string &host, int port, int timeout_ms=0)
 Create a TCP client socket and connect to a server using IPv6 only.
 
socket_t create_tcp_server (int port, int backlog=5, const std::string &bind_address="")
 Create a TCP server socket and bind to a port using dual stack (IPv6 with IPv4 support)
 
socket_t create_tcp_server_v4 (int port, int backlog=5, const std::string &bind_address="")
 Create a TCP server socket and bind to a port using IPv4 only.
 
socket_t create_tcp_server_v6 (int port, int backlog=5, const std::string &bind_address="")
 Create a TCP server socket and bind to a port using IPv6 only.
 
socket_t accept_client (socket_t server_socket)
 Accept a client connection on a server socket.
 
std::string get_peer_address (socket_t socket)
 Get the peer address (IP:port) from a connected socket.
 
int send_tcp_data (socket_t socket, const std::vector< uint8_t > &data)
 Send data through a TCP socket.
 
std::vector< uint8_t > receive_tcp_data (socket_t socket, size_t buffer_size=1024)
 Receive data from a TCP socket.
 
int send_tcp_message_framed (socket_t socket, const std::vector< uint8_t > &message)
 Send a framed message with length prefix through a TCP socket.
 
std::vector< uint8_t > receive_exact_bytes (socket_t socket, size_t num_bytes)
 Receive exact number of bytes from a TCP socket (blocking until complete)
 
std::vector< uint8_t > receive_tcp_message_framed (socket_t socket)
 Receive a complete framed message from a TCP socket.
 
int send_tcp_string (socket_t socket, const std::string &data)
 Send string data through a TCP socket (converts to binary)
 
std::string receive_tcp_string (socket_t socket, size_t buffer_size=1024)
 Receive data from a TCP socket as string.
 
int send_tcp_string_framed (socket_t socket, const std::string &message)
 Send a framed string message through a TCP socket.
 
std::string receive_tcp_string_framed (socket_t socket)
 Receive a complete framed string message from a TCP socket.
 
socket_t create_udp_socket (int port=0, const std::string &bind_address="")
 Create a UDP socket with dual stack support (IPv6 with IPv4 support)
 
socket_t create_udp_socket_v4 (int port=0, const std::string &bind_address="")
 Create a UDP socket with IPv4 support only.
 
socket_t create_udp_socket_v6 (int port=0, const std::string &bind_address="")
 Create a UDP socket with IPv6 support only.
 
int send_udp_data (socket_t socket, const std::vector< uint8_t > &data, const Peer &peer)
 Send UDP data to a peer.
 
int send_udp_data_to (socket_t socket, const std::vector< uint8_t > &data, const std::string &hostname, int port)
 Send UDP data to a hostname and port directly.
 
std::vector< uint8_t > receive_udp_data (socket_t socket, size_t buffer_size, Peer &sender_peer)
 Receive UDP data from a peer.
 
std::vector< uint8_t > receive_udp_data_with_timeout (socket_t socket, size_t buffer_size, int timeout_ms, std::string *sender_ip=nullptr, int *sender_port=nullptr)
 Receive UDP data with timeout support.
 
void close_socket (socket_t socket, bool force=false)
 Close a socket.
 
bool is_valid_socket (socket_t socket)
 Check if a socket is valid.
 
bool set_socket_nonblocking (socket_t socket)
 Set socket to non-blocking mode.
 
bool set_socket_blocking (socket_t socket)
 Set socket to blocking mode.
 
bool is_tcp_socket (socket_t socket)
 Check if a socket is a TCP socket.
 
bool connect_with_timeout (socket_t socket, struct sockaddr *addr, socklen_t addr_len, int timeout_ms)
 Connect to a socket address with timeout.
 
int get_ephemeral_port (socket_t socket)
 Get the ephemeral port that a socket is bound to.
 
bool file_or_directory_exists (const char *path)
 
bool directory_exists (const char *path)
 
bool file_exists (const char *path)
 
bool create_file (const char *path, const char *content)
 
bool create_file_binary (const char *path, const void *data, size_t size)
 
bool append_to_file (const char *path, const char *content)
 
char * read_file_text (const char *path, size_t *size_out=nullptr)
 
void * read_file_binary (const char *path, size_t *size_out)
 
bool create_directory (const char *path)
 
bool create_directories (const char *path)
 
int64_t get_file_size (const char *path)
 
bool is_file (const char *path)
 
bool is_directory (const char *path)
 
bool delete_file (const char *path)
 
bool delete_directory (const char *path)
 
bool copy_file (const char *src_path, const char *dest_path)
 
bool move_file (const char *src_path, const char *dest_path)
 
uint64_t get_file_modified_time (const char *path)
 
std::string get_file_extension (const char *path)
 
std::string get_filename_from_path (const char *path)
 
std::string get_parent_directory (const char *path)
 
bool write_file_chunk (const char *path, uint64_t offset, const void *data, size_t size)
 
bool read_file_chunk (const char *path, uint64_t offset, void *buffer, size_t size)
 
bool create_file_with_size (const char *path, uint64_t size)
 
bool rename_file (const char *old_path, const char *new_path)
 
bool list_directory (const char *path, std::vector< DirectoryEntry > &entries)
 
std::string combine_paths (const std::string &base, const std::string &relative)
 
bool validate_path (const char *path, bool check_write_access=false)
 
void free_file_buffer (void *buffer)
 
bool get_current_directory (char *buffer, size_t buffer_size)
 
bool set_current_directory (const char *path)
 
bool file_or_directory_exists (const std::string &path)
 
bool file_exists (const std::string &path)
 
bool directory_exists (const std::string &path)
 
bool create_file (const std::string &path, const std::string &content)
 
std::string read_file_text_cpp (const std::string &path)
 
uint64_t get_file_modified_time (const std::string &path)
 
std::string get_file_extension (const std::string &path)
 
std::string get_filename_from_path (const std::string &path)
 
std::string get_parent_directory (const std::string &path)
 
bool write_file_chunk (const std::string &path, uint64_t offset, const void *data, size_t size)
 
bool read_file_chunk (const std::string &path, uint64_t offset, void *buffer, size_t size)
 
bool create_file_with_size (const std::string &path, uint64_t size)
 
bool rename_file (const std::string &old_path, const std::string &new_path)
 
bool validate_path (const std::string &path, bool check_write_access=false)
 
SystemInfo get_system_info ()
 
std::string get_os_name ()
 
std::string get_os_version ()
 
std::string get_architecture ()
 
std::string get_hostname ()
 
std::string get_cpu_model ()
 
int get_cpu_cores ()
 
int get_cpu_logical_cores ()
 
uint64_t get_total_memory_mb ()
 
uint64_t get_available_memory_mb ()
 
bool supports_unicode ()
 
void print_system_info ()
 

Variables

constexpr size_t NODE_ID_SIZE = 20
 
constexpr size_t K_BUCKET_SIZE = 8
 
constexpr size_t ALPHA = 3
 
constexpr int DHT_PORT = 6881
 
constexpr uint32_t STUN_MAGIC_COOKIE = 0x2112A442
 STUN Magic Cookie (fixed value per RFC 5389)
 
constexpr size_t STUN_HEADER_SIZE = 20
 STUN header size in bytes.
 
constexpr size_t STUN_TRANSACTION_ID_SIZE = 12
 STUN transaction ID size in bytes.
 
constexpr uint16_t STUN_DEFAULT_PORT = 3478
 Default STUN port.
 
constexpr uint16_t STUNS_DEFAULT_PORT = 5349
 STUN over TLS default port.
 
constexpr size_t STUN_MAX_MESSAGE_SIZE = 1500
 Maximum STUN message size (RFC 5389 recommends path MTU, typically ~1500)
 
constexpr int STUN_DEFAULT_RTO_MS = 500
 Default retransmission timeout (ms)
 
constexpr int STUN_MAX_RETRANSMISSIONS = 7
 Maximum retransmissions.
 
constexpr uint32_t ICE_PRIORITY_HOST = 126
 Default ICE candidate priority for host candidates.
 
constexpr uint32_t ICE_PRIORITY_SRFLX = 100
 Default ICE candidate priority for server-reflexive candidates

 
constexpr uint32_t ICE_PRIORITY_RELAY = 0
 Default ICE candidate priority for relay candidates.
 
constexpr int ICE_CHECK_TIMEOUT_MS = 500
 Connectivity check timeout (ms)
 
constexpr int ICE_CHECK_MAX_RETRIES = 5
 Maximum connectivity check retries.
 
const uint16_t MDNS_PORT = 5353
 
const std::string MDNS_MULTICAST_IPv4 = "224.0.0.251"
 
const std::string MDNS_MULTICAST_IPv6 = "ff02::fb"
 
const std::string LIBRATS_SERVICE_TYPE = "_librats._tcp.local."
 
const std::string LIBRATS_SERVICE_INSTANCE_SUFFIX = ".local."
 

Typedef Documentation

◆ BencodeDict

using librats::BencodeDict = typedef std::unordered_map<std::string, BencodeValue>

Definition at line 23 of file bencode.h.

◆ BencodeList

using librats::BencodeList = typedef std::vector<BencodeValue>

Definition at line 24 of file bencode.h.

◆ DirectoryRequestCallback

using librats::DirectoryRequestCallback = typedef std::function<bool(const std::string& peer_id, const std::string& directory_path, bool recursive, const std::string& transfer_id)>

Definition at line 179 of file file_transfer.h.

◆ DirectoryTransferProgressCallback

using librats::DirectoryTransferProgressCallback = typedef std::function<void(const std::string& transfer_id, const std::string& current_file, uint64_t files_completed, uint64_t total_files, uint64_t bytes_completed, uint64_t total_bytes)>

Definition at line 177 of file file_transfer.h.

◆ FileRequestCallback

using librats::FileRequestCallback = typedef std::function<bool(const std::string& peer_id, const std::string& file_path, const std::string& transfer_id)>

Definition at line 178 of file file_transfer.h.

◆ FileTransferCompletedCallback

using librats::FileTransferCompletedCallback = typedef std::function<void(const std::string& transfer_id, bool success, const std::string& error_message)>

Definition at line 175 of file file_transfer.h.

◆ FileTransferProgressCallback

using librats::FileTransferProgressCallback = typedef std::function<void(const FileTransferProgress&)>

Callback function types for file transfer events.

Definition at line 174 of file file_transfer.h.

◆ FileTransferRequestCallback

using librats::FileTransferRequestCallback = typedef std::function<bool(const std::string& peer_id, const FileMetadata& metadata, const std::string& transfer_id)>

Definition at line 176 of file file_transfer.h.

◆ IceCandidatesCallback

using librats::IceCandidatesCallback = typedef std::function<void(const std::vector<IceCandidate>&)>

Callback when candidates are gathered.

Definition at line 260 of file ice.h.

◆ IceConnectionStateCallback

using librats::IceConnectionStateCallback = typedef std::function<void(IceConnectionState)>

Callback when connection state changes.

Definition at line 266 of file ice.h.

◆ IceGatheringStateCallback

using librats::IceGatheringStateCallback = typedef std::function<void(IceGatheringState)>

Callback when gathering state changes.

Definition at line 263 of file ice.h.

◆ IceNewCandidateCallback

using librats::IceNewCandidateCallback = typedef std::function<void(const IceCandidate&)>

Callback when a new candidate is discovered (trickle ICE)

Definition at line 269 of file ice.h.

◆ IceSelectedPairCallback

using librats::IceSelectedPairCallback = typedef std::function<void(const IceCandidatePair&)>

Callback when ICE completes with selected pair.

Definition at line 272 of file ice.h.

◆ InfoHash

typedef std::array< uint8_t, 20 > librats::InfoHash

Definition at line 50 of file dht.h.

◆ MdnsServiceCallback

using librats::MdnsServiceCallback = typedef std::function<void(const MdnsService& service, bool is_new)>

Definition at line 122 of file mdns.h.

◆ MessageHandler

using librats::MessageHandler = typedef std::function<void(const std::string& topic, const std::string& message, const std::string& sender_peer_id)>

Definition at line 160 of file gossipsub.h.

◆ MessageValidator

using librats::MessageValidator = typedef std::function<ValidationResult(const std::string& topic, const std::string& message, const std::string& sender_peer_id)>

Callback types for GossipSub.

Definition at line 159 of file gossipsub.h.

◆ NodeId

typedef std::array< uint8_t, 20 > librats::NodeId

Definition at line 49 of file dht.h.

◆ PeerDiscoveryCallback

using librats::PeerDiscoveryCallback = typedef std::function<void(const std::vector<Peer>& peers, const InfoHash& info_hash)>

Peer discovery callback.

Definition at line 128 of file dht.h.

◆ PeerJoinedHandler

using librats::PeerJoinedHandler = typedef std::function<void(const std::string& topic, const std::string& peer_id)>

Definition at line 161 of file gossipsub.h.

◆ PeerLeftHandler

using librats::PeerLeftHandler = typedef std::function<void(const std::string& topic, const std::string& peer_id)>

Definition at line 162 of file gossipsub.h.

◆ SpiderAnnounceCallback

using librats::SpiderAnnounceCallback = typedef std::function<void(const InfoHash& info_hash, const Peer& peer)>

Spider mode callback Called when a peer announces they have a torrent (announce_peer request received)

Parameters
info_hashThe info hash being announced
peerThe peer that is announcing (with the port they specified)

Definition at line 137 of file dht.h.

Enumeration Type Documentation

◆ DnsRecordClass

enum class librats::DnsRecordClass : uint16_t
strong
Enumerator
CLASS_IN 
CLASS_IN_FLUSH 

Definition at line 42 of file mdns.h.

◆ DnsRecordType

enum class librats::DnsRecordType : uint16_t
strong
Enumerator
PTR 
TXT 
AAAA 
SRV 

Definition at line 33 of file mdns.h.

◆ FileTransferDirection

enum class librats::FileTransferDirection
strong

File transfer direction.

Enumerator
SENDING 
RECEIVING 

Definition at line 39 of file file_transfer.h.

◆ FileTransferStatus

enum class librats::FileTransferStatus
strong

File transfer status codes.

Enumerator
PENDING 
STARTING 
IN_PROGRESS 
PAUSED 
COMPLETED 
FAILED 
CANCELLED 
RESUMING 

Definition at line 25 of file file_transfer.h.

◆ GossipSubMessageType

enum class librats::GossipSubMessageType
strong

GossipSub message types.

Enumerator
SUBSCRIBE 
UNSUBSCRIBE 
PUBLISH 
GOSSIP 
GRAFT 
PRUNE 
IHAVE 
IWANT 
HEARTBEAT 

Definition at line 25 of file gossipsub.h.

◆ IceCandidatePairState

enum class librats::IceCandidatePairState
strong

ICE candidate pair state.

Enumerator
Frozen 

Not yet checked.

Waiting 

Waiting to be checked.

InProgress 

Check in progress.

Succeeded 

Check succeeded.

Failed 

Check failed.

Definition at line 156 of file ice.h.

◆ IceCandidateType

enum class librats::IceCandidateType
strong

ICE candidate type.

Enumerator
Host 

Local interface address.

ServerReflexive 

Address discovered via STUN (public address)

PeerReflexive 

Address discovered during connectivity checks.

Relay 

TURN relay address.

Definition at line 55 of file ice.h.

◆ IceConnectionState

enum class librats::IceConnectionState
strong

ICE connection state.

Enumerator
New 

Initial state.

Gathering 

Gathering candidates.

Checking 

Performing connectivity checks.

Connected 

At least one valid pair found.

Completed 

ICE processing complete.

Failed 

ICE processing failed.

Disconnected 

Connection lost.

Closed 

ICE agent closed.

Definition at line 73 of file ice.h.

◆ IceGatheringState

enum class librats::IceGatheringState
strong

ICE gathering state.

Enumerator
New 

Not started.

Gathering 

Gathering in progress.

Complete 

Gathering complete.

Definition at line 87 of file ice.h.

◆ IceTransportProtocol

enum class librats::IceTransportProtocol
strong

ICE candidate transport protocol.

Enumerator
UDP 
TCP 

Definition at line 65 of file ice.h.

◆ KrpcErrorCode

enum class librats::KrpcErrorCode
strong

KRPC Error codes.

Enumerator
GenericError 
ServerError 
ProtocolError 
MethodUnknown 

Definition at line 38 of file krpc.h.

◆ KrpcMessageType

enum class librats::KrpcMessageType
strong

KRPC Message types.

Enumerator
Query 
Response 
Error 

Definition at line 19 of file krpc.h.

◆ KrpcQueryType

enum class librats::KrpcQueryType
strong

KRPC Query types.

Enumerator
Ping 
FindNode 
GetPeers 
AnnouncePeer 

Definition at line 28 of file krpc.h.

◆ LogLevel

enum class librats::LogLevel
strong
Enumerator
DEBUG 
INFO 
WARN 
ERROR 

Definition at line 28 of file logger.h.

◆ MdnsFlags

enum class librats::MdnsFlags : uint16_t
strong
Enumerator
QUERY 
RESPONSE 
AUTHORITATIVE 

Definition at line 48 of file mdns.h.

◆ MessageDataType

enum class librats::MessageDataType : uint8_t
strong

Message data types for librats message headers.

Enumerator
BINARY 
STRING 
JSON 

Definition at line 134 of file librats.h.

◆ StunAddressFamily

enum class librats::StunAddressFamily : uint8_t
strong
Enumerator
IPv4 
IPv6 

Definition at line 148 of file stun.h.

◆ StunAttributeType

enum class librats::StunAttributeType : uint16_t
strong
Enumerator
MappedAddress 
Username 
MessageIntegrity 
ErrorCode 
UnknownAttributes 
Realm 
Nonce 
XorMappedAddress 
ChannelNumber 
Lifetime 
XorPeerAddress 
Data 
XorRelayedAddress 
RequestedTransport 
DontFragment 
Software 
AlternateServer 
Fingerprint 

Definition at line 118 of file stun.h.

◆ StunErrorCode

enum class librats::StunErrorCode : uint16_t
strong
Enumerator
TryAlternate 
BadRequest 
Unauthorized 
Forbidden 
UnknownAttribute 
StaleNonce 
ServerError 
AllocationMismatch 
WrongCredentials 
UnsupportedTransportProtocol 
AllocationQuotaReached 
InsufficientCapacity 

Definition at line 157 of file stun.h.

◆ StunMessageClass

enum class librats::StunMessageClass : uint8_t
strong

STUN message class (2 bits)

Enumerator
Request 
Indication 
SuccessResponse 
ErrorResponse 

Definition at line 58 of file stun.h.

◆ StunMessageType

enum class librats::StunMessageType : uint16_t
strong

Combined STUN message type (method + class)

Enumerator
BindingRequest 
BindingIndication 
BindingSuccessResponse 
BindingErrorResponse 
AllocateRequest 
AllocateSuccessResponse 
AllocateErrorResponse 
RefreshRequest 
RefreshSuccessResponse 
RefreshErrorResponse 
SendIndication 
DataIndication 
CreatePermissionRequest 
CreatePermissionSuccessResponse 
CreatePermissionErrorResponse 
ChannelBindRequest 
ChannelBindSuccessResponse 
ChannelBindErrorResponse 

Definition at line 82 of file stun.h.

◆ StunMethod

enum class librats::StunMethod : uint16_t
strong

STUN method (12 bits, only Binding is defined in RFC 5389)

Enumerator
Binding 
Allocate 
Refresh 
Send 
Data 
CreatePermission 
ChannelBind 

Definition at line 68 of file stun.h.

◆ ValidationResult

enum class librats::ValidationResult
strong

Message validation result.

Enumerator
ACCEPT 
REJECT 
IGNORE_MSG 

Definition at line 150 of file gossipsub.h.

Function Documentation

◆ accept_client()

socket_t librats::accept_client ( socket_t  server_socket)

Accept a client connection on a server socket.

Parameters
server_socketThe server socket handle
Returns
Client socket handle, or INVALID_SOCKET_VALUE on error

◆ append_to_file()

bool librats::append_to_file ( const char *  path,
const char *  content 
)

◆ cleanup_socket_library()

void librats::cleanup_socket_library ( )

Cleanup the socket library.

◆ close_socket()

void librats::close_socket ( socket_t  socket,
bool  force = false 
)

Close a socket.

Parameters
socketThe socket handle to close

◆ combine_paths()

std::string librats::combine_paths ( const std::string &  base,
const std::string &  relative 
)

◆ connect_with_timeout()

bool librats::connect_with_timeout ( socket_t  socket,
struct sockaddr *  addr,
socklen_t  addr_len,
int  timeout_ms 
)

Connect to a socket address with timeout.

Parameters
socketThe socket handle (should be non-blocking)
addrThe socket address structure
addr_lenLength of the address structure
timeout_msConnection timeout in milliseconds
Returns
true if connected successfully, false on timeout or error

◆ copy_file()

bool librats::copy_file ( const char *  src_path,
const char *  dest_path 
)

◆ create_directories()

bool librats::create_directories ( const char *  path)

◆ create_directory()

bool librats::create_directory ( const char *  path)

◆ create_file() [1/2]

bool librats::create_file ( const char *  path,
const char *  content 
)

Referenced by create_file().

◆ create_file() [2/2]

bool librats::create_file ( const std::string &  path,
const std::string &  content 
)
inline

Definition at line 77 of file fs.h.

References create_file().

◆ create_file_binary()

bool librats::create_file_binary ( const char *  path,
const void *  data,
size_t  size 
)

◆ create_file_with_size() [1/2]

bool librats::create_file_with_size ( const char *  path,
uint64_t  size 
)

Referenced by create_file_with_size().

◆ create_file_with_size() [2/2]

bool librats::create_file_with_size ( const std::string &  path,
uint64_t  size 
)
inline

Definition at line 100 of file fs.h.

References create_file_with_size().

◆ create_rats_client()

std::unique_ptr< RatsClient > librats::create_rats_client ( int  listen_port)

◆ create_tcp_client()

socket_t librats::create_tcp_client ( const std::string &  host,
int  port,
int  timeout_ms = 0 
)

Create a TCP client socket and connect to a server using dual stack (IPv6 with IPv4 fallback)

Parameters
hostThe hostname or IP address to connect to
portThe port number to connect to
timeout_msConnection timeout in milliseconds (0 for blocking)
Returns
Socket handle, or INVALID_SOCKET_VALUE on error

◆ create_tcp_client_v4()

socket_t librats::create_tcp_client_v4 ( const std::string &  host,
int  port,
int  timeout_ms = 0 
)

Create a TCP client socket and connect to a server using IPv4 only.

Parameters
hostThe hostname or IP address to connect to
portThe port number to connect to
timeout_msConnection timeout in milliseconds (0 for blocking)
Returns
Socket handle, or INVALID_SOCKET_VALUE on error

◆ create_tcp_client_v6()

socket_t librats::create_tcp_client_v6 ( const std::string &  host,
int  port,
int  timeout_ms = 0 
)

Create a TCP client socket and connect to a server using IPv6 only.

Parameters
hostThe hostname or IPv6 address to connect to
portThe port number to connect to
timeout_msConnection timeout in milliseconds (0 for blocking)
Returns
Socket handle, or INVALID_SOCKET_VALUE on error

◆ create_tcp_server()

socket_t librats::create_tcp_server ( int  port,
int  backlog = 5,
const std::string &  bind_address = "" 
)

Create a TCP server socket and bind to a port using dual stack (IPv6 with IPv4 support)

Parameters
portThe port number to bind to
backlogThe maximum number of pending connections
bind_addressThe interface IP address to bind to (empty for all interfaces)
Returns
Socket handle, or INVALID_SOCKET_VALUE on error

◆ create_tcp_server_v4()

socket_t librats::create_tcp_server_v4 ( int  port,
int  backlog = 5,
const std::string &  bind_address = "" 
)

Create a TCP server socket and bind to a port using IPv4 only.

Parameters
portThe port number to bind to
backlogThe maximum number of pending connections
bind_addressThe interface IP address to bind to (empty for all interfaces)
Returns
Socket handle, or INVALID_SOCKET_VALUE on error

◆ create_tcp_server_v6()

socket_t librats::create_tcp_server_v6 ( int  port,
int  backlog = 5,
const std::string &  bind_address = "" 
)

Create a TCP server socket and bind to a port using IPv6 only.

Parameters
portThe port number to bind to
backlogThe maximum number of pending connections
bind_addressThe interface IP address to bind to (empty for all interfaces)
Returns
Socket handle, or INVALID_SOCKET_VALUE on error

◆ create_udp_socket()

socket_t librats::create_udp_socket ( int  port = 0,
const std::string &  bind_address = "" 
)

Create a UDP socket with dual stack support (IPv6 with IPv4 support)

Parameters
portThe port to bind to (0 for any available port)
bind_addressThe interface IP address to bind to (empty for all interfaces)
Returns
UDP socket handle, or INVALID_SOCKET_VALUE on error

◆ create_udp_socket_v4()

socket_t librats::create_udp_socket_v4 ( int  port = 0,
const std::string &  bind_address = "" 
)

Create a UDP socket with IPv4 support only.

Parameters
portThe port to bind to (0 for any available port)
bind_addressThe interface IP address to bind to (empty for all interfaces)
Returns
UDP socket handle, or INVALID_SOCKET_VALUE on error

◆ create_udp_socket_v6()

socket_t librats::create_udp_socket_v6 ( int  port = 0,
const std::string &  bind_address = "" 
)

Create a UDP socket with IPv6 support only.

Parameters
portThe port to bind to (0 for any available port)
bind_addressThe interface IP address to bind to (empty for all interfaces)
Returns
UDP socket handle, or INVALID_SOCKET_VALUE on error

◆ delete_directory()

bool librats::delete_directory ( const char *  path)

◆ delete_file()

bool librats::delete_file ( const char *  path)

◆ directory_exists() [1/2]

bool librats::directory_exists ( const char *  path)

Referenced by directory_exists().

◆ directory_exists() [2/2]

bool librats::directory_exists ( const std::string &  path)
inline

Definition at line 76 of file fs.h.

References directory_exists().

◆ file_exists() [1/2]

bool librats::file_exists ( const char *  path)

Referenced by file_exists().

◆ file_exists() [2/2]

bool librats::file_exists ( const std::string &  path)
inline

Definition at line 75 of file fs.h.

References file_exists().

◆ file_or_directory_exists() [1/2]

bool librats::file_or_directory_exists ( const char *  path)

◆ file_or_directory_exists() [2/2]

bool librats::file_or_directory_exists ( const std::string &  path)
inline

Definition at line 74 of file fs.h.

References file_or_directory_exists().

◆ free_file_buffer()

void librats::free_file_buffer ( void *  buffer)

Referenced by read_file_text_cpp().

◆ get_architecture()

std::string librats::get_architecture ( )

◆ get_available_memory_mb()

uint64_t librats::get_available_memory_mb ( )

◆ get_cpu_cores()

int librats::get_cpu_cores ( )

◆ get_cpu_logical_cores()

int librats::get_cpu_logical_cores ( )

◆ get_cpu_model()

std::string librats::get_cpu_model ( )

◆ get_current_directory()

bool librats::get_current_directory ( char *  buffer,
size_t  buffer_size 
)

◆ get_ephemeral_port()

int librats::get_ephemeral_port ( socket_t  socket)

Get the ephemeral port that a socket is bound to.

Parameters
socketThe socket handle to get the ephemeral port for
Returns
The ephemeral port, or 0 if the socket is not bound to an ephemeral port

◆ get_file_extension() [1/2]

std::string librats::get_file_extension ( const char *  path)

Referenced by get_file_extension().

◆ get_file_extension() [2/2]

std::string librats::get_file_extension ( const std::string &  path)
inline

Definition at line 91 of file fs.h.

References get_file_extension().

◆ get_file_modified_time() [1/2]

uint64_t librats::get_file_modified_time ( const char *  path)

Referenced by get_file_modified_time().

◆ get_file_modified_time() [2/2]

uint64_t librats::get_file_modified_time ( const std::string &  path)
inline

Definition at line 90 of file fs.h.

References get_file_modified_time().

◆ get_file_size()

int64_t librats::get_file_size ( const char *  path)

◆ get_filename_from_path() [1/2]

std::string librats::get_filename_from_path ( const char *  path)

Referenced by get_filename_from_path().

◆ get_filename_from_path() [2/2]

std::string librats::get_filename_from_path ( const std::string &  path)
inline

Definition at line 92 of file fs.h.

References get_filename_from_path().

◆ get_hostname()

std::string librats::get_hostname ( )

◆ get_os_name()

std::string librats::get_os_name ( )

◆ get_os_version()

std::string librats::get_os_version ( )

◆ get_parent_directory() [1/2]

std::string librats::get_parent_directory ( const char *  path)

Referenced by get_parent_directory().

◆ get_parent_directory() [2/2]

std::string librats::get_parent_directory ( const std::string &  path)
inline

Definition at line 93 of file fs.h.

References get_parent_directory().

◆ get_peer_address()

std::string librats::get_peer_address ( socket_t  socket)

Get the peer address (IP:port) from a connected socket.

Parameters
socketThe connected socket handle
Returns
Peer address string in format "IP:port", or empty string on error

◆ get_public_stun_servers()

std::vector< std::pair< std::string, uint16_t > > librats::get_public_stun_servers ( )

Get a list of well-known public STUN servers.

◆ get_system_info()

SystemInfo librats::get_system_info ( )

◆ get_total_memory_mb()

uint64_t librats::get_total_memory_mb ( )

◆ hex_to_node_id()

NodeId librats::hex_to_node_id ( const std::string &  hex)

Convert hex string to NodeId.

Parameters
hexThe hex string to convert (must be 40 characters)
Returns
NodeId

◆ init_socket_library()

bool librats::init_socket_library ( )

Initialize the socket library.

Returns
true if successful, false otherwise

◆ is_directory()

bool librats::is_directory ( const char *  path)

◆ is_file()

bool librats::is_file ( const char *  path)

◆ is_tcp_socket()

bool librats::is_tcp_socket ( socket_t  socket)

Check if a socket is a TCP socket.

Parameters
socketThe socket handle to check
Returns
true if TCP socket, false otherwise

◆ is_valid_socket()

bool librats::is_valid_socket ( socket_t  socket)

Check if a socket is valid.

Parameters
socketThe socket handle to check
Returns
true if valid, false otherwise

◆ list_directory()

bool librats::list_directory ( const char *  path,
std::vector< DirectoryEntry > &  entries 
)

◆ move_file()

bool librats::move_file ( const char *  src_path,
const char *  dest_path 
)

◆ node_id_to_hex()

std::string librats::node_id_to_hex ( const NodeId id)

Convert NodeId to hex string.

Parameters
idThe NodeId to convert
Returns
Hex string representation

◆ node_id_to_string()

std::string librats::node_id_to_string ( const NodeId id)

Convert NodeId to string.

Parameters
idThe NodeId to convert
Returns
String representation

◆ print_system_info()

void librats::print_system_info ( )

◆ rats_get_library_abi()

uint32_t librats::rats_get_library_abi ( )

◆ rats_get_library_git_describe()

const char * librats::rats_get_library_git_describe ( )

◆ rats_get_library_version()

void librats::rats_get_library_version ( int *  major,
int *  minor,
int *  patch,
int *  build 
)

◆ rats_get_library_version_string()

const char * librats::rats_get_library_version_string ( )

◆ read_file_binary()

void * librats::read_file_binary ( const char *  path,
size_t *  size_out 
)

◆ read_file_chunk() [1/2]

bool librats::read_file_chunk ( const char *  path,
uint64_t  offset,
void *  buffer,
size_t  size 
)

Referenced by read_file_chunk().

◆ read_file_chunk() [2/2]

bool librats::read_file_chunk ( const std::string &  path,
uint64_t  offset,
void *  buffer,
size_t  size 
)
inline

Definition at line 97 of file fs.h.

References read_file_chunk().

◆ read_file_text()

char * librats::read_file_text ( const char *  path,
size_t *  size_out = nullptr 
)

Referenced by read_file_text_cpp().

◆ read_file_text_cpp()

std::string librats::read_file_text_cpp ( const std::string &  path)
inline

Definition at line 80 of file fs.h.

References free_file_buffer(), and read_file_text().

◆ receive_exact_bytes()

std::vector< uint8_t > librats::receive_exact_bytes ( socket_t  socket,
size_t  num_bytes 
)

Receive exact number of bytes from a TCP socket (blocking until complete)

Parameters
socketThe socket handle
num_bytesNumber of bytes to receive
Returns
Received binary data, empty vector on error or connection close

◆ receive_tcp_data()

std::vector< uint8_t > librats::receive_tcp_data ( socket_t  socket,
size_t  buffer_size = 1024 
)

Receive data from a TCP socket.

Parameters
socketThe socket handle
buffer_sizeMaximum number of bytes to receive
Returns
Received binary data, empty vector on error

◆ receive_tcp_message_framed()

std::vector< uint8_t > librats::receive_tcp_message_framed ( socket_t  socket)

Receive a complete framed message from a TCP socket.

Parameters
socketThe socket handle
Returns
Complete binary message, empty vector on error or connection close

◆ receive_tcp_string()

std::string librats::receive_tcp_string ( socket_t  socket,
size_t  buffer_size = 1024 
)

Receive data from a TCP socket as string.

Parameters
socketThe socket handle
buffer_sizeMaximum number of bytes to receive
Returns
Received data as string, empty string on error

◆ receive_tcp_string_framed()

std::string librats::receive_tcp_string_framed ( socket_t  socket)

Receive a complete framed string message from a TCP socket.

Parameters
socketThe socket handle
Returns
Complete message as string, empty string on error or connection close

◆ receive_udp_data()

std::vector< uint8_t > librats::receive_udp_data ( socket_t  socket,
size_t  buffer_size,
Peer sender_peer 
)

Receive UDP data from a peer.

Parameters
socketThe UDP socket handle
buffer_sizeMaximum number of bytes to receive
sender_peerOutput parameter for the sender's peer info
Returns
Received data, empty vector on error

◆ receive_udp_data_with_timeout()

std::vector< uint8_t > librats::receive_udp_data_with_timeout ( socket_t  socket,
size_t  buffer_size,
int  timeout_ms,
std::string *  sender_ip = nullptr,
int *  sender_port = nullptr 
)

Receive UDP data with timeout support.

Parameters
socketThe UDP socket handle
buffer_sizeMaximum number of bytes to receive
timeout_msTimeout in milliseconds (0 for non-blocking, -1 for blocking)
sender_ipOptional output parameter for sender IP address
sender_portOptional output parameter for sender port
Returns
Received data, empty vector on timeout or error

◆ rename_file() [1/2]

bool librats::rename_file ( const char *  old_path,
const char *  new_path 
)

Referenced by rename_file().

◆ rename_file() [2/2]

bool librats::rename_file ( const std::string &  old_path,
const std::string &  new_path 
)
inline

Definition at line 101 of file fs.h.

References rename_file().

◆ send_tcp_data()

int librats::send_tcp_data ( socket_t  socket,
const std::vector< uint8_t > &  data 
)

Send data through a TCP socket.

Parameters
socketThe socket handle
dataThe binary data to send
Returns
Number of bytes sent, or -1 on error

◆ send_tcp_message_framed()

int librats::send_tcp_message_framed ( socket_t  socket,
const std::vector< uint8_t > &  message 
)

Send a framed message with length prefix through a TCP socket.

Parameters
socketThe socket handle
messageThe binary message to send
Returns
Total bytes sent (including length prefix), or -1 on error

◆ send_tcp_string()

int librats::send_tcp_string ( socket_t  socket,
const std::string &  data 
)

Send string data through a TCP socket (converts to binary)

Parameters
socketThe socket handle
dataThe string data to send
Returns
Number of bytes sent, or -1 on error

◆ send_tcp_string_framed()

int librats::send_tcp_string_framed ( socket_t  socket,
const std::string &  message 
)

Send a framed string message through a TCP socket.

Parameters
socketThe socket handle
messageThe string message to send
Returns
Total bytes sent (including length prefix), or -1 on error

◆ send_udp_data()

int librats::send_udp_data ( socket_t  socket,
const std::vector< uint8_t > &  data,
const Peer peer 
)

Send UDP data to a peer.

Parameters
socketThe UDP socket handle
dataThe data to send
peerThe destination peer
Returns
Number of bytes sent, or -1 on error

◆ send_udp_data_to()

int librats::send_udp_data_to ( socket_t  socket,
const std::vector< uint8_t > &  data,
const std::string &  hostname,
int  port 
)

Send UDP data to a hostname and port directly.

Parameters
socketThe UDP socket handle
dataThe data to send
hostnameThe destination hostname or IP address
portThe destination port
Returns
Number of bytes sent, or -1 on error

◆ set_current_directory()

bool librats::set_current_directory ( const char *  path)

◆ set_socket_blocking()

bool librats::set_socket_blocking ( socket_t  socket)

Set socket to blocking mode.

Parameters
socketThe socket handle
Returns
true if successful, false otherwise

◆ set_socket_nonblocking()

bool librats::set_socket_nonblocking ( socket_t  socket)

Set socket to non-blocking mode.

Parameters
socketThe socket handle
Returns
true if successful, false otherwise

◆ string_to_node_id()

NodeId librats::string_to_node_id ( const std::string &  str)

Utility functions.

Convert string to NodeId

Parameters
strThe string to convert (must be 20 bytes)
Returns
NodeId

◆ stun_compute_long_term_key()

std::vector< uint8_t > librats::stun_compute_long_term_key ( const std::string &  username,
const std::string &  realm,
const std::string &  password 
)

Compute long-term credential key: MD5(username:realm:password)

◆ stun_crc32()

uint32_t librats::stun_crc32 ( const uint8_t *  data,
size_t  length 
)

Compute CRC32 for STUN FINGERPRINT attribute Uses CRC-32 as defined in RFC 5389 (ISO 3309)

◆ stun_hmac_sha1()

std::array< uint8_t, 20 > librats::stun_hmac_sha1 ( const std::vector< uint8_t > &  key,
const std::vector< uint8_t > &  data 
)

Compute HMAC-SHA1 for MESSAGE-INTEGRITY attribute.

Parameters
keyThe key (typically: MD5(username:realm:password))
dataThe message data to authenticate
Returns
20-byte HMAC-SHA1 result

◆ stun_xor_address()

StunMappedAddress librats::stun_xor_address ( const StunMappedAddress addr,
const std::array< uint8_t, STUN_TRANSACTION_ID_SIZE > &  transaction_id 
)

XOR an address with the magic cookie and transaction ID Used for XOR-MAPPED-ADDRESS encoding/decoding.

◆ supports_unicode()

bool librats::supports_unicode ( )

◆ validate_path() [1/2]

bool librats::validate_path ( const char *  path,
bool  check_write_access = false 
)

Referenced by validate_path().

◆ validate_path() [2/2]

bool librats::validate_path ( const std::string &  path,
bool  check_write_access = false 
)
inline

Definition at line 104 of file fs.h.

References validate_path().

◆ write_file_chunk() [1/2]

bool librats::write_file_chunk ( const char *  path,
uint64_t  offset,
const void *  data,
size_t  size 
)

Referenced by write_file_chunk().

◆ write_file_chunk() [2/2]

bool librats::write_file_chunk ( const std::string &  path,
uint64_t  offset,
const void *  data,
size_t  size 
)
inline

Definition at line 94 of file fs.h.

References write_file_chunk().

Variable Documentation

◆ ALPHA

constexpr size_t librats::ALPHA = 3
constexpr

Definition at line 46 of file dht.h.

◆ DHT_PORT

constexpr int librats::DHT_PORT = 6881
constexpr

Definition at line 47 of file dht.h.

◆ ICE_CHECK_MAX_RETRIES

constexpr int librats::ICE_CHECK_MAX_RETRIES = 5
constexpr

Maximum connectivity check retries.

Definition at line 46 of file ice.h.

◆ ICE_CHECK_TIMEOUT_MS

constexpr int librats::ICE_CHECK_TIMEOUT_MS = 500
constexpr

Connectivity check timeout (ms)

Definition at line 43 of file ice.h.

◆ ICE_PRIORITY_HOST

constexpr uint32_t librats::ICE_PRIORITY_HOST = 126
constexpr

Default ICE candidate priority for host candidates.

Definition at line 34 of file ice.h.

◆ ICE_PRIORITY_RELAY

constexpr uint32_t librats::ICE_PRIORITY_RELAY = 0
constexpr

Default ICE candidate priority for relay candidates.

Definition at line 40 of file ice.h.

◆ ICE_PRIORITY_SRFLX

constexpr uint32_t librats::ICE_PRIORITY_SRFLX = 100
constexpr

Default ICE candidate priority for server-reflexive candidates

Definition at line 37 of file ice.h.

◆ K_BUCKET_SIZE

constexpr size_t librats::K_BUCKET_SIZE = 8
constexpr

Definition at line 45 of file dht.h.

◆ LIBRATS_SERVICE_INSTANCE_SUFFIX

const std::string librats::LIBRATS_SERVICE_INSTANCE_SUFFIX = ".local."

Definition at line 30 of file mdns.h.

◆ LIBRATS_SERVICE_TYPE

const std::string librats::LIBRATS_SERVICE_TYPE = "_librats._tcp.local."

Definition at line 29 of file mdns.h.

◆ MDNS_MULTICAST_IPv4

const std::string librats::MDNS_MULTICAST_IPv4 = "224.0.0.251"

Definition at line 27 of file mdns.h.

◆ MDNS_MULTICAST_IPv6

const std::string librats::MDNS_MULTICAST_IPv6 = "ff02::fb"

Definition at line 28 of file mdns.h.

◆ MDNS_PORT

const uint16_t librats::MDNS_PORT = 5353

Definition at line 26 of file mdns.h.

◆ NODE_ID_SIZE

constexpr size_t librats::NODE_ID_SIZE = 20
constexpr

Definition at line 44 of file dht.h.

◆ STUN_DEFAULT_PORT

constexpr uint16_t librats::STUN_DEFAULT_PORT = 3478
constexpr

Default STUN port.

Definition at line 37 of file stun.h.

◆ STUN_DEFAULT_RTO_MS

constexpr int librats::STUN_DEFAULT_RTO_MS = 500
constexpr

Default retransmission timeout (ms)

Definition at line 46 of file stun.h.

◆ STUN_HEADER_SIZE

constexpr size_t librats::STUN_HEADER_SIZE = 20
constexpr

STUN header size in bytes.

Definition at line 31 of file stun.h.

◆ STUN_MAGIC_COOKIE

constexpr uint32_t librats::STUN_MAGIC_COOKIE = 0x2112A442
constexpr

STUN Magic Cookie (fixed value per RFC 5389)

Definition at line 28 of file stun.h.

◆ STUN_MAX_MESSAGE_SIZE

constexpr size_t librats::STUN_MAX_MESSAGE_SIZE = 1500
constexpr

Maximum STUN message size (RFC 5389 recommends path MTU, typically ~1500)

Definition at line 43 of file stun.h.

◆ STUN_MAX_RETRANSMISSIONS

constexpr int librats::STUN_MAX_RETRANSMISSIONS = 7
constexpr

Maximum retransmissions.

Definition at line 49 of file stun.h.

◆ STUN_TRANSACTION_ID_SIZE

constexpr size_t librats::STUN_TRANSACTION_ID_SIZE = 12
constexpr

STUN transaction ID size in bytes.

Definition at line 34 of file stun.h.

◆ STUNS_DEFAULT_PORT

constexpr uint16_t librats::STUNS_DEFAULT_PORT = 5349
constexpr

STUN over TLS default port.

Definition at line 40 of file stun.h.