35#include "librats/util/rats_export.h"
50#define RATS_ENUM_BASE : int
96#define RATS_TRANSPORT_MASK_TCP 0x1u
97#define RATS_TRANSPORT_MASK_UDP 0x2u
153#define RATS_FALLBACK_NEVER 0xFFFFFFFFu
287#define RATS_LIVE_MAX_LIFETIME_MS 30000u
288#define RATS_LIVE_MAX_PAYLOAD (4u * 1024u * 1024u)
304 const void* data,
size_t len, uint32_t lifetime_ms);
308 size_t len, uint32_t lifetime_ms);
351typedef void (*
rats_message_cb)(
void* user,
const char* peer_id,
const void* data,
size_t len);
417typedef void (*
rats_topic_cb)(
void* user,
const char* peer_id,
const char* topic,
418 const void* data,
size_t len);
432typedef void (*
rats_json_cb)(
void* user,
const char* peer_id,
const char* json);
471 const char* name, uint64_t size,
int is_directory);
474 int success,
const char* path);
488 uint64_t* transfer_id);
490 uint64_t* transfer_id);
495 const char* dest_path);
556 const char* save_path);
569RATS_API
void rats_version(
int* major,
int* minor,
int* patch,
int* build);
rats_error_t rats_enable_port_mapping(rats_t node, int upnp, int natpmp)
Ask the router to forward the listen port, over UPnP IGD and/or NAT-PMP (non-zero enables each; both ...
void(* rats_peer_cb)(void *user, const char *peer_id)
rats_error_t rats_subscribe(rats_t node, const char *topic, rats_topic_cb cb, void *user)
Subscribe to a topic; one handler per topic, a second subscribe replaces it.
rats_nat_mapping_t rats_nat_mapping(rats_t node)
What the mesh has shown about this node's NAT, from where UDP peers report seeing its socket.
const char * rats_protocol(rats_t node)
The protocol bound into the handshake.
rats_error_t rats_start(rats_t node)
Open the sockets, start the I/O threads and every enabled subsystem.
@ RATS_DIRECTION_OUTBOUND
@ RATS_SECURITY_PLAINTEXT
char ** rats_observed_addresses(rats_t node, size_t *count)
Our own addresses as peers report seeing us ("ip:port", our listen port).
rats_error_t rats_off_json(rats_t node, const char *type)
Remove every handler of type.
rats_error_t rats_send_directory(rats_t node, const char *peer_id, const char *path, uint64_t *transfer_id)
rats_error_t rats_on_peer_writable(rats_t node, rats_peer_cb cb, void *user)
A peer whose queue had filled has drained back under its mark.
rats_error_t rats_on_peer_disconnected(rats_t node, rats_disconnect_cb cb, void *user)
void rats_version(int *major, int *minor, int *patch, int *build)
Version components; any pointer may be NULL.
void rats_set_log_file(const char *path)
Also write logs to path; NULL or "" stops file logging.
const char * rats_close_reason_str(rats_close_reason_t reason)
Static name of a close reason, e.g.
rats_error_t rats_broadcast_json(rats_t node, const char *type, const char *json)
void(* rats_path_cb)(void *user, const char *peer_id, const rats_path_stats_t *stats)
rats_error_t rats_enable_json(rats_t node)
Enable before start.
rats_error_t rats_enable_reconnect_lost(rats_t node, uint32_t lost_for_ms)
rats_enable_reconnect(), and a peer lost — its connection closed by neither side: gone quiet past the...
rats_error_t rats_on_dial_failed(rats_t node, rats_dial_failed_cb cb, void *user)
A dial to a numeric address failed over every transport tried — one made by rats_connect() or by a di...
void(* rats_message_cb)(void *user, const char *peer_id, const void *data, size_t len)
struct rats_node * rats_t
rats_error_t rats_unsubscribe(rats_t node, const char *topic)
@ RATS_NAT_ENDPOINT_INDEPENDENT
@ RATS_NAT_ENDPOINT_DEPENDENT
uint16_t rats_listen_port(rats_t node)
The bound listen port (the real one when 0 was asked for); 0 before start.
size_t rats_max_peers(rats_t node)
rats_error_t rats_enable_hole_punch(rats_t node, int serve_rendezvous)
UDP hole punching: reach a peer behind a NAT by having a peer both sides share arrange for the two to...
rats_error_t rats_resume_file(rats_t node, const char *peer_id, uint64_t transfer_id)
@ RATS_CLOSE_CONNECT_FAILED
@ RATS_CLOSE_SLOW_CONSUMER
@ RATS_CLOSE_HANDSHAKE_FAILED
@ RATS_CLOSE_DIAL_SUPERSEDED
@ RATS_CLOSE_PROTOCOL_ERROR
@ RATS_CLOSE_IDLE_TIMEOUT
rats_error_t rats_on_file_progress(rats_t node, rats_file_progress_cb cb, void *user)
rats_error_t rats_remove_reconnect(rats_t node, const char *host, uint16_t port)
Stop keeping an address connected and forget it.
rats_error_t rats_on_peer_path(rats_t node, rats_path_cb cb, void *user)
A path sample of every connected peer, every path_sample_ms (100 ms if 0).
void(* rats_topic_cb)(void *user, const char *peer_id, const char *topic, const void *data, size_t len)
rats_error_t rats_on_json(rats_t node, const char *type, rats_json_cb cb, void *user)
Add a handler for messages of type.
void(* rats_file_complete_cb)(void *user, const char *peer_id, uint64_t transfer_id, int success, const char *path)
rats_error_t rats_on_peer_connected(rats_t node, rats_peer_cb cb, void *user)
rats_error_t rats_send_file(rats_t node, const char *peer_id, const char *path, uint64_t *transfer_id)
Offer a file or a directory tree to a connected peer; the transfer id is written to *transfer_id (whi...
rats_error_t rats_add_reconnect(rats_t node, const char *host, uint16_t port)
Keep an address connected.
rats_error_t rats_send(rats_t node, const char *peer_id, const char *channel, const void *data, size_t len, uint32_t lifetime_ms)
Queue bytes for one peer on a named channel.
rats_error_t rats_enable_dht(rats_t node, uint16_t dht_port, const char *discovery_key)
Mainline DHT: announce and search a key, dialing the peers found.
int64_t rats_peer_rtt_ms(rats_t node, const char *peer_id)
Last measured round trip to a peer in ms; -1 if unknown (ping not enabled, no answer yet).
rats_error_t rats_on(rats_t node, const char *channel, rats_message_cb cb, void *user)
Messages arriving on a named channel.
rats_error_t rats_path_stats(rats_t node, const char *peer_id, rats_path_stats_t *out)
The latest path sample for a peer.
char ** rats_peer_ids(rats_t node, size_t *count)
Ids of the connected peers: an array of *count strings, NULL when there are none.
rats_error_t rats_accept_file(rats_t node, const char *peer_id, uint64_t transfer_id, const char *dest_path)
Answer an offer.
rats_error_t rats_once_json(rats_t node, const char *type, rats_json_cb cb, void *user)
Like rats_on_json(); the handler is removed after its first message.
void(* rats_file_offer_cb)(void *user, const char *peer_id, uint64_t transfer_id, const char *name, uint64_t size, int is_directory)
rats_error_t rats_peer_info(rats_t node, const char *peer_id, rats_peer_info_t *out)
Fill out for a connected peer.
void(* rats_disconnect_cb)(void *user, const char *peer_id, rats_close_reason_t reason)
@ RATS_ERR_ALREADY_STARTED
rats_error_t rats_publish(rats_t node, const char *topic, const void *data, size_t len)
Publish to every subscriber of the topic.
rats_t rats_create(const rats_config_t *config)
Create a node.
rats_error_t rats_enable_peer_exchange(rats_t node)
Peer exchange: connected peers trade the addresses of peers they hold, so a node needs one contact to...
void(* rats_file_progress_cb)(void *user, const rats_file_progress_t *progress)
rats_error_t rats_disconnect(rats_t node, const char *peer_id)
Close the connection to a peer.
rats_error_t rats_on_file_offer(rats_t node, rats_file_offer_cb cb, void *user)
rats_error_t rats_bt_add_magnet(rats_t node, const char *magnet_uri, const char *save_path)
Start a download from a magnet link (metadata is fetched from peers).
const char * rats_version_string(void)
Library version with the build number, e.g.
rats_error_t rats_enable_ping(rats_t node)
Enable before start.
rats_error_t rats_punch_peer(rats_t node, const char *peer_id)
Start punching to a peer.
rats_error_t rats_enable_bittorrent(rats_t node, const rats_bt_config_t *config)
Enable before start.
rats_error_t rats_enable_relay(rats_t node, int serve)
Relaying: reach a peer nothing else can, through a node both ends are connected to.
rats_error_t rats_enable_mdns(rats_t node)
mDNS discovery on the local network.
uint32_t rats_abi(void)
(major << 16) | (minor << 8) | patch.
rats_error_t rats_enable_pubsub(rats_t node)
Enable before start.
rats_error_t rats_on_file_complete(rats_t node, rats_file_complete_cb cb, void *user)
int rats_peer_writable(rats_t node, const char *peer_id)
1 while the peer's send queue has room, 0 when it does not or the peer is not connected.
const char * rats_error_str(rats_error_t err)
Static name of an error code, e.g.
const char * rats_local_id(rats_t node)
Our peer id as hex.
void rats_strings_free(char **strings, size_t count)
Free an array from rats_peer_ids() / rats_observed_addresses().
rats_error_t rats_enable_file_transfer(rats_t node, const char *temp_dir)
Enable before start.
rats_error_t rats_pause_file(rats_t node, const char *peer_id, uint64_t transfer_id)
uint32_t rats_transports(rats_t node)
Transports actually running, as RATS_TRANSPORT_MASK_* bits.
void rats_stop(rats_t node)
Close every connection and stop.
void(* rats_json_cb)(void *user, const char *peer_id, const char *json)
rats_error_t rats_connect_via_relay(rats_t node, const char *peer_id)
Start a relayed connection to a peer.
void rats_set_log_level(rats_log_level_t level)
rats_error_t rats_bt_add_torrent_file(rats_t node, const char *torrent_path, const char *save_path)
Start a download from a .torrent file.
rats_error_t rats_send_json(rats_t node, const char *peer_id, const char *type, const char *json)
json must be valid JSON text (else RATS_ERR_INVALID_ARG).
rats_error_t rats_bt_remove_torrent(rats_t node, const char *info_hash_hex)
Remove a torrent by its 40-char hex info-hash.
rats_error_t rats_connect(rats_t node, const char *host, uint16_t port)
Dial host:port (a literal or a hostname).
size_t rats_peer_count(rats_t node)
rats_error_t rats_broadcast(rats_t node, const char *channel, const void *data, size_t len, uint32_t lifetime_ms)
rats_send() to every connected peer.
void(* rats_dial_failed_cb)(void *user, const char *address)
rats_error_t rats_cancel_file(rats_t node, const char *peer_id, uint64_t transfer_id)
Control a running transfer from either side.
rats_error_t rats_enable_reconnect(rats_t node)
Re-dial dropped peers with exponential backoff.
const char * rats_git_describe(void)
git describe of the build, e.g.
rats_error_t rats_reject_file(rats_t node, const char *peer_id, uint64_t transfer_id)
void rats_set_max_peers(rats_t node, size_t max_peers)
Cap on established peers (0 = unlimited).
void rats_destroy(rats_t node)
Stop the node if running and free it.
rats_bt_encryption_t outgoing_encryption
rats_bt_encryption_t incoming_encryption
const char * download_path
rats_transport_t preferred_transport
uint32_t udp_idle_timeout_ms
size_t udp_receive_window
int disable_network_monitor
rats_congestion_t congestion_control
size_t udp_receive_budget
const char * bind_address
uint32_t transport_fallback_ms
uint64_t bytes_transferred
rats_direction_t direction
double rate_bytes_per_sec
rats_file_status_t status
uint64_t live_repair_bytes
rats_transport_t transport
rats_direction_t direction