Tilde Friends
SSB

Classes

struct  _tf_ssb_stats_t
 
struct  _tf_ssb_blob_wants_t
 
struct  _tf_ssb_store_queue_t
 

Typedefs

typedef enum _tf_ssb_verify_flags_t tf_ssb_verify_flags_t
 
typedef enum _tf_ssb_change_t tf_ssb_change_t
 
typedef enum _tf_ssb_broadcast_origin_t tf_ssb_broadcast_origin_t
 
typedef enum _tf_ssb_message_flags_t tf_ssb_message_flags_t
 
typedef enum _tf_ssb_connect_flags_t tf_ssb_connect_flags_t
 
typedef struct _tf_ssb_t tf_ssb_t
 
typedef struct _tf_ssb_connection_t tf_ssb_connection_t
 
typedef struct _tf_ssb_ebt_t tf_ssb_ebt_t
 
typedef struct _tf_trace_t tf_trace_t
 
typedef struct sqlite3 sqlite3
 
typedef struct uv_loop_s uv_loop_t
 
typedef struct _tf_ssb_stats_t tf_ssb_stats_t
 
typedef struct _tf_ssb_blob_wants_t tf_ssb_blob_wants_t
 
typedef struct _tf_ssb_store_queue_t tf_ssb_store_queue_t
 
typedef void() tf_ssb_connect_callback_t(tf_ssb_connection_t *connection, const char *reason, void *user_data)
 
typedef void() tf_ssb_verify_strip_store_callback_t(const char *id, bool verified, bool is_new, void *user_data)
 
typedef void() tf_ssb_callback_cleanup_t(tf_ssb_t *ssb, void *user_data)
 
typedef void() tf_ssb_connections_changed_callback_t(tf_ssb_t *ssb, tf_ssb_change_t change, tf_ssb_connection_t *connection, void *user_data)
 
typedef void() tf_ssb_broadcasts_changed_callback_t(tf_ssb_t *ssb, void *user_data)
 
typedef void() tf_ssb_message_added_callback_t(tf_ssb_t *ssb, const char *author, int32_t sequence, const char *id, void *user_data)
 
typedef void() tf_ssb_blob_stored_callback_t(tf_ssb_t *ssb, const char *id, void *user_data)
 
typedef void() tf_ssb_blob_want_added_callback_t(tf_ssb_t *ssb, const char *id, void *user_data)
 
typedef void() tf_ssb_rpc_callback_t(tf_ssb_connection_t *connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t *message, size_t size, void *user_data)
 
typedef void() tf_ssb_scheduled_callback_t(tf_ssb_connection_t *connection, bool skip, void *user_data)
 

Enumerations

enum  {
  k_ssb_rpc_flag_binary = 0x0 , k_ssb_rpc_flag_utf8 = 0x1 , k_ssb_rpc_flag_json = 0x2 , k_ssb_rpc_mask_type = 0x3 ,
  k_ssb_rpc_flag_end_error = 0x4 , k_ssb_rpc_flag_stream = 0x8 , k_ssb_rpc_mask_message = 0xC , k_ssb_rpc_mask_send = 0xf ,
  k_ssb_rpc_flag_new_request = 0x10 , k_ssb_blob_bytes_max = 5 * 1024 * 1024 , k_ssb_peer_exchange_expires_seconds = 60 * 60 , k_max_private_message_recipients = 8
}
 
enum  _tf_ssb_verify_flags_t { k_tf_ssb_verify_flag_debug = 1 }
 
enum  _tf_ssb_change_t { k_tf_ssb_change_create , k_tf_ssb_change_connect , k_tf_ssb_change_remove , k_tf_ssb_change_update }
 
enum  _tf_ssb_broadcast_origin_t { k_tf_ssb_broadcast_origin_discovery , k_tf_ssb_broadcast_origin_room , k_tf_ssb_broadcast_origin_peer_exchange }
 
enum  _tf_ssb_message_flags_t { k_tf_ssb_message_flag_sequence_before_author = 1 }
 
enum  _tf_ssb_connect_flags_t { k_tf_ssb_connect_flag_one_shot = 0x1 , k_tf_ssb_connect_flag_do_not_store = 0x2 , k_tf_ssb_connect_flag_use_invite = 0x4 }
 
enum  { k_id_base64_len = 57 , k_id_bin_len = 32 , k_blob_id_len = 53 }
 

Functions

tf_ssb_ttf_ssb_create (uv_loop_t *loop, JSContext *context, const char *db_path, const char *network_key)
 
void tf_ssb_destroy (tf_ssb_t *ssb)
 
bool tf_ssb_is_shutting_down (tf_ssb_t *ssb)
 
void tf_ssb_start_periodic (tf_ssb_t *ssb)
 
void tf_ssb_set_verbose (tf_ssb_t *ssb, bool verbose)
 
void tf_ssb_set_quiet (tf_ssb_t *ssb, bool quiet)
 
sqlite3tf_ssb_acquire_db_reader (tf_ssb_t *ssb)
 
sqlite3tf_ssb_acquire_db_reader_restricted (tf_ssb_t *ssb)
 
void tf_ssb_release_db_reader (tf_ssb_t *ssb, sqlite3 *db)
 
sqlite3tf_ssb_acquire_db_writer (tf_ssb_t *ssb)
 
void tf_ssb_release_db_writer (tf_ssb_t *ssb, sqlite3 *db)
 
uv_loop_ttf_ssb_get_loop (tf_ssb_t *ssb)
 
void tf_ssb_generate_keys (tf_ssb_t *ssb)
 
void tf_ssb_generate_keys_buffer (char *out_public, size_t public_size, char *out_private, size_t private_size)
 
void tf_ssb_get_private_key (tf_ssb_t *ssb, uint8_t *out_private, size_t private_size)
 
void tf_ssb_set_trace (tf_ssb_t *ssb, tf_trace_t *trace)
 
tf_trace_ttf_ssb_get_trace (tf_ssb_t *ssb)
 
JSContexttf_ssb_get_context (tf_ssb_t *ssb)
 
void tf_ssb_broadcast_listener_start (tf_ssb_t *ssb, bool linger)
 
void tf_ssb_broadcast_sender_start (tf_ssb_t *ssb)
 
void tf_ssb_run (tf_ssb_t *ssb)
 
JSValue tf_ssb_sign_message (tf_ssb_t *ssb, const char *author, const uint8_t *private_key, JSValue message, const char *previous_id, int32_t previous_sequence)
 
bool tf_ssb_whoami (tf_ssb_t *ssb, char *out_id, size_t out_id_size)
 
void tf_ssb_visit_broadcasts (tf_ssb_t *ssb, void(*callback)(const char *host, const struct sockaddr_in *addr, tf_ssb_broadcast_origin_t origin, tf_ssb_connection_t *tunnel, const uint8_t *pub, void *user_data), void *user_data)
 
void tf_ssb_add_broadcast (tf_ssb_t *ssb, const char *connection, tf_ssb_broadcast_origin_t origin, int64_t expires_seconds)
 
const char ** tf_ssb_get_connection_ids (tf_ssb_t *ssb)
 
int tf_ssb_get_connections (tf_ssb_t *ssb, tf_ssb_connection_t **out_connections, int out_connections_count)
 
void tf_ssb_connect (tf_ssb_t *ssb, const char *host, int port, const uint8_t *key, int connect_flags, tf_ssb_connect_callback_t *callback, void *user_data)
 
void tf_ssb_connect_str (tf_ssb_t *ssb, const char *address, int connect_flags, tf_ssb_connect_callback_t *callback, void *user_data)
 
int tf_ssb_server_open (tf_ssb_t *ssb, int port)
 
int tf_ssb_server_get_port (tf_ssb_t *ssb)
 
void tf_ssb_server_close (tf_ssb_t *ssb)
 
void tf_ssb_close_all (tf_ssb_t *ssb, const char *reason)
 
void tf_ssb_send_close (tf_ssb_t *ssb)
 
bool tf_ssb_id_str_to_bin (uint8_t *bin, const char *str)
 
bool tf_ssb_id_bin_to_str (char *str, size_t str_size, const uint8_t *bin)
 
bool tf_ssb_verify_and_strip_signature (JSContext *context, JSValue val, int verify_flags, char *out_id, size_t out_id_size, char *out_signature, size_t out_signature_size, int *out_flags)
 
void tf_ssb_calculate_message_id (JSContext *context, JSValue message, char *out_id, size_t out_id_size)
 
void tf_ssb_verify_strip_and_store_message (tf_ssb_t *ssb, JSValue value, tf_ssb_verify_strip_store_callback_t *callback, void *user_data)
 
bool tf_ssb_connection_is_client (tf_ssb_connection_t *connection)
 
const char * tf_ssb_connection_get_host (tf_ssb_connection_t *connection)
 
int tf_ssb_connection_get_port (tf_ssb_connection_t *connection)
 
tf_ssb_connection_ttf_ssb_connection_get_tunnel (tf_ssb_connection_t *connection)
 
tf_ssb_ttf_ssb_connection_get_ssb (tf_ssb_connection_t *connection)
 
JSContexttf_ssb_connection_get_context (tf_ssb_connection_t *connection)
 
void tf_ssb_connection_close (tf_ssb_connection_t *connection, const char *reason)
 
bool tf_ssb_connection_is_connected (tf_ssb_connection_t *connection)
 
bool tf_ssb_connection_is_closing (tf_ssb_connection_t *connection)
 
int32_t tf_ssb_connection_next_request_number (tf_ssb_connection_t *connection)
 
tf_ssb_connection_ttf_ssb_connection_get (tf_ssb_t *ssb, const char *id)
 
bool tf_ssb_connection_get_id (tf_ssb_connection_t *connection, char *out_id, size_t out_id_size)
 
JSValue tf_ssb_connection_get_object (tf_ssb_connection_t *connection)
 
void tf_ssb_add_connections_changed_callback (tf_ssb_t *ssb, tf_ssb_connections_changed_callback_t *callback, tf_ssb_callback_cleanup_t *cleanup, void *user_data)
 
void tf_ssb_remove_connections_changed_callback (tf_ssb_t *ssb, tf_ssb_connections_changed_callback_t *callback, void *user_data)
 
void tf_ssb_add_broadcasts_changed_callback (tf_ssb_t *ssb, tf_ssb_broadcasts_changed_callback_t *callback, tf_ssb_callback_cleanup_t *cleanup, void *user_data)
 
void tf_ssb_remove_broadcasts_changed_callback (tf_ssb_t *ssb, tf_ssb_broadcasts_changed_callback_t *callback, void *user_data)
 
void tf_ssb_add_message_added_callback (tf_ssb_t *ssb, tf_ssb_message_added_callback_t *callback, tf_ssb_callback_cleanup_t *cleanup, void *user_data)
 
void tf_ssb_remove_message_added_callback (tf_ssb_t *ssb, tf_ssb_message_added_callback_t *callback, void *user_data)
 
void tf_ssb_notify_message_added (tf_ssb_t *ssb, const char *author, int32_t sequence, const char *id, JSValue message_with_keys)
 
void tf_ssb_add_blob_stored_callback (tf_ssb_t *ssb, tf_ssb_blob_stored_callback_t *callback, tf_ssb_callback_cleanup_t *cleanup, void *user_data)
 
void tf_ssb_remove_blob_stored_callback (tf_ssb_t *ssb, tf_ssb_blob_stored_callback_t *callback, void *user_data)
 
void tf_ssb_notify_blob_stored (tf_ssb_t *ssb, const char *id)
 
void tf_ssb_add_blob_want_added_callback (tf_ssb_t *ssb, tf_ssb_blob_want_added_callback_t *callback, tf_ssb_callback_cleanup_t *cleanup, void *user_data)
 
void tf_ssb_remove_blob_want_added_callback (tf_ssb_t *ssb, tf_ssb_blob_want_added_callback_t *callback, void *user_data)
 
void tf_ssb_notify_blob_want_added (tf_ssb_t *ssb, const char *id)
 
void tf_ssb_add_rpc_callback (tf_ssb_t *ssb, const char *name, tf_ssb_rpc_callback_t *callback, tf_ssb_callback_cleanup_t *cleanup, void *user_data)
 
void tf_ssb_remove_rpc_callback (tf_ssb_t *ssb, const char **name, tf_ssb_rpc_callback_t *callback, void *user_data)
 
bool tf_ssb_connection_rpc_send (tf_ssb_connection_t *connection, uint8_t flags, int32_t request_number, const char *new_request_name, const uint8_t *message, size_t size, tf_ssb_rpc_callback_t *callback, tf_ssb_callback_cleanup_t *cleanup, void *user_data)
 
bool tf_ssb_connection_rpc_send_json (tf_ssb_connection_t *connection, uint8_t flags, int32_t request_number, const char *new_request_name, JSValue message, tf_ssb_rpc_callback_t *callback, tf_ssb_callback_cleanup_t *cleanup, void *user_data)
 
bool tf_ssb_connection_rpc_send_error (tf_ssb_connection_t *connection, uint8_t flags, int32_t request_number, const char *error)
 
bool tf_ssb_connection_rpc_send_error_method_not_allowed (tf_ssb_connection_t *connection, uint8_t flags, int32_t request_number, const char *name)
 
void tf_ssb_connection_add_request (tf_ssb_connection_t *connection, int32_t request_number, const char *name, tf_ssb_rpc_callback_t *callback, tf_ssb_callback_cleanup_t *cleanup, void *user_data, tf_ssb_connection_t *dependent_connection)
 
void tf_ssb_connection_remove_request (tf_ssb_connection_t *connection, int32_t request_number)
 
JSValue tf_ssb_connection_requests_to_object (tf_ssb_connection_t *connection)
 
void tf_ssb_connection_schedule_idle (tf_ssb_connection_t *connection, const char *key, tf_ssb_scheduled_callback_t *callback, void *user_data)
 
void tf_ssb_connection_run_work (tf_ssb_connection_t *connection, void(*work_callback)(tf_ssb_connection_t *connection, void *user_data), void(*after_work_callback)(tf_ssb_connection_t *connection, int result, void *user_data), void *user_data)
 
void tf_ssb_run_work (tf_ssb_t *ssb, void(*work_callback)(tf_ssb_t *ssb, void *user_data), void(*after_work_callback)(tf_ssb_t *ssb, int result, void *user_data), void *user_data)
 
void tf_ssb_connection_add_new_message_request (tf_ssb_connection_t *connection, const char *author, int32_t request_number, bool keys)
 
void tf_ssb_connection_remove_new_message_request (tf_ssb_connection_t *connection, const char *author)
 
bool tf_ssb_connection_is_attendant (tf_ssb_connection_t *connection)
 
int32_t tf_ssb_connection_get_attendant_request_number (tf_ssb_connection_t *connection)
 
void tf_ssb_connection_set_attendant (tf_ssb_connection_t *connection, bool attendant, int request_number)
 
void tf_ssb_connection_set_endpoint (tf_ssb_connection_t *connection, bool endpoint, int request_number)
 
bool tf_ssb_connection_is_endpoint (tf_ssb_connection_t *connection)
 
int32_t tf_ssb_connection_get_endpoint_request_number (tf_ssb_connection_t *connection)
 
void tf_ssb_connection_clear_room_attendants (tf_ssb_connection_t *connection)
 
void tf_ssb_connection_add_room_attendant (tf_ssb_connection_t *connection, const char *id)
 
void tf_ssb_connection_remove_room_attendant (tf_ssb_connection_t *connection, const char *id)
 
tf_ssb_connection_ttf_ssb_connection_tunnel_create (tf_ssb_t *ssb, const char *portal_id, int32_t request_number, const char *target_id, int connect_flags)
 
int32_t tf_ssb_connection_get_ebt_request_number (tf_ssb_connection_t *connection)
 
void tf_ssb_connection_set_ebt_request_number (tf_ssb_connection_t *connection, int32_t request_number)
 
JSClassID tf_ssb_get_connection_class_id ()
 
void tf_ssb_get_stats (tf_ssb_t *ssb, tf_ssb_stats_t *out_stats)
 
tf_ssb_blob_wants_ttf_ssb_connection_get_blob_wants_state (tf_ssb_connection_t *connection)
 
void tf_ssb_record_thread_busy (tf_ssb_t *ssb, bool busy)
 
float tf_ssb_get_average_thread_percent (tf_ssb_t *ssb)
 
tf_ssb_store_queue_ttf_ssb_get_store_queue (tf_ssb_t *ssb)
 
void tf_ssb_ref (tf_ssb_t *ssb)
 
void tf_ssb_unref (tf_ssb_t *ssb)
 
void tf_ssb_set_main_thread (tf_ssb_t *ssb, bool main_thread)
 
bool tf_ssb_is_room (tf_ssb_t *ssb)
 
void tf_ssb_set_is_room (tf_ssb_t *ssb, bool is_room)
 
bool tf_ssb_is_replicator (tf_ssb_t *ssb)
 
void tf_ssb_set_is_replicator (tf_ssb_t *ssb, bool is_replicator)
 
bool tf_ssb_is_peer_exchange (tf_ssb_t *ssb)
 
void tf_ssb_set_is_peer_exchange (tf_ssb_t *ssb, bool is_peer_exchange)
 
const char * tf_ssb_get_room_name (tf_ssb_t *ssb)
 
void tf_ssb_set_room_name (tf_ssb_t *ssb, const char *room_name)
 
void tf_ssb_schedule_work (tf_ssb_t *ssb, int delay_ms, void(*callback)(tf_ssb_t *ssb, void *user_data), void *user_data)
 
bool tf_ssb_hmacsha256_verify (const char *public_key, const void *payload, size_t payload_length, const char *signature, bool signature_is_urlb64)
 
void tf_ssb_connection_adjust_read_backpressure (tf_ssb_connection_t *connection, int delta)
 
void tf_ssb_connection_adjust_write_count (tf_ssb_connection_t *connection, int delta)
 
const char * tf_ssb_connection_get_destroy_reason (tf_ssb_connection_t *connection)
 
bool tf_ssb_tunnel_create (tf_ssb_t *ssb, const char *portal_id, const char *target_id, int connect_flags)
 
void tf_ssb_sync_start (tf_ssb_t *ssb)
 
int tf_ssb_connection_get_flags (tf_ssb_connection_t *connection)
 
tf_ssb_ebt_ttf_ssb_connection_get_ebt (tf_ssb_connection_t *connection)
 
char * tf_ssb_private_message_encrypt (uint8_t *private_key, const char **recipients, int recipients_count, const char *message, size_t message_size)
 

Detailed Description

Everything about SSB, SHS, and MUXRPC happens here.

Typedef Documentation

◆ sqlite3

typedef struct sqlite3 sqlite3

An SQLite database handle.

◆ tf_ssb_blob_stored_callback_t

typedef void() tf_ssb_blob_stored_callback_t(tf_ssb_t *ssb, const char *id, void *user_data)

A callback called when a blob is added to the database.

Parameters
ssbThe SSB instance.
idThe blob identifier.
user_dataThe user data.

◆ tf_ssb_blob_want_added_callback_t

typedef void() tf_ssb_blob_want_added_callback_t(tf_ssb_t *ssb, const char *id, void *user_data)

A callback called when a blob is newly requested.

Parameters
ssbThe SSB instance.
idThe blob identity.
user_dataThe user data.

◆ tf_ssb_blob_wants_t

State about requesting blobs.

◆ tf_ssb_broadcast_origin_t

The origin of a broadcast entry.

◆ tf_ssb_broadcasts_changed_callback_t

typedef void() tf_ssb_broadcasts_changed_callback_t(tf_ssb_t *ssb, void *user_data)

A callback called when a new broadcast is received or one expires.

Parameters
ssbThe SSB instance.
user_dataThe user data.

◆ tf_ssb_callback_cleanup_t

typedef void() tf_ssb_callback_cleanup_t(tf_ssb_t *ssb, void *user_data)

A callback called when a callback is cleaned up.

Parameters
ssbThe SSB instance.
user_dataUser data.

◆ tf_ssb_change_t

The type of change to a set of connections.

◆ tf_ssb_connect_callback_t

typedef void() tf_ssb_connect_callback_t(tf_ssb_connection_t *connection, const char *reason, void *user_data)

Callback for completing establishing a connection.

Parameters
connectionThe established connection if successful or null.
reasonThe reason for failure if the connection failed.
user_dataUser data.

◆ tf_ssb_connect_flags_t

Flags affecting an SSB connection.

◆ tf_ssb_connection_t

typedef struct _tf_ssb_connection_t tf_ssb_connection_t

An SSB connection.

◆ tf_ssb_connections_changed_callback_t

typedef void() tf_ssb_connections_changed_callback_t(tf_ssb_t *ssb, tf_ssb_change_t change, tf_ssb_connection_t *connection, void *user_data)

A callback called when the connection list changes.

Parameters
ssbThe SSB instance.
changeThe type of change.
connectionThe connection that changed.
user_dataUser data.

◆ tf_ssb_ebt_t

typedef struct _tf_ssb_ebt_t tf_ssb_ebt_t

A connection's EBT state.

◆ tf_ssb_message_added_callback_t

typedef void() tf_ssb_message_added_callback_t(tf_ssb_t *ssb, const char *author, int32_t sequence, const char *id, void *user_data)

A callback called when a message is added to the database.

Parameters
ssbThe SSB instance.
authorThe author identity.
sequenceThe message sequence number.
idThe message identifier.
user_dataThe user data.

◆ tf_ssb_message_flags_t

Flags describing the structure of a message.

◆ tf_ssb_rpc_callback_t

typedef void() tf_ssb_rpc_callback_t(tf_ssb_connection_t *connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t *message, size_t size, void *user_data)

A function called when a MUXRPC request is made.

Parameters
connectionThe SSB connection.
flagsThe RPC flags.
request_numberThe request number.
argsRequest arguments.
messageThe raw message data.
sizeThe size of the raw message data.
user_dataUser data registered with the callback.

◆ tf_ssb_scheduled_callback_t

typedef void() tf_ssb_scheduled_callback_t(tf_ssb_connection_t *connection, bool skip, void *user_data)

A function scheduled to be run later.

Parameters
connectionThe owning connection.
skipWhether the work ought to be skipped, because it is being replaced.
user_dataUser data registered with the callback.

◆ tf_ssb_stats_t

Statistics about an SSB instance.

◆ tf_ssb_store_queue_t

A queue for storing messages.

◆ tf_ssb_t

typedef struct _tf_ssb_t tf_ssb_t

An SSB instance.

◆ tf_ssb_verify_flags_t

Flags affecting signature verification.

◆ tf_ssb_verify_strip_store_callback_t

typedef void() tf_ssb_verify_strip_store_callback_t(const char *id, bool verified, bool is_new, void *user_data)

A function called on completion of tf_ssb_verify_strip_and_store_message().

Parameters
idThe stored message identifier.
verifiedTrue if the message was verified successfully.
is_newTrue if the message was newly added to the database.
user_dataThe user data.

◆ tf_trace_t

typedef struct _tf_trace_t tf_trace_t

A trace instance.

◆ uv_loop_t

typedef struct uv_loop_s uv_loop_t

An event loop.

Enumeration Type Documentation

◆ _tf_ssb_broadcast_origin_t

The origin of a broadcast entry.

◆ _tf_ssb_change_t

The type of change to a set of connections.

◆ _tf_ssb_connect_flags_t

Flags affecting an SSB connection.

◆ _tf_ssb_message_flags_t

Flags describing the structure of a message.

Enumerator
k_tf_ssb_message_flag_sequence_before_author 

The sequence field precedes the author field if specified. The other way around, otherwise.

◆ _tf_ssb_verify_flags_t

Flags affecting signature verification.

Function Documentation

◆ tf_ssb_acquire_db_reader()

sqlite3 * tf_ssb_acquire_db_reader ( tf_ssb_t ssb)

Acquire an SQLite database for unrestricted reading. Release qith tf_ssb_release_db_reader().

Parameters
ssbThe SSB instance.
Returns
A database with full read access to the database.

◆ tf_ssb_acquire_db_reader_restricted()

sqlite3 * tf_ssb_acquire_db_reader_restricted ( tf_ssb_t ssb)

Acquire an SQLite database for restricted reading. Release qith tf_ssb_release_db_reader().

Parameters
ssbThe SSB instance.
Returns
A database with read access to a safe subset of the database.

◆ tf_ssb_acquire_db_writer()

sqlite3 * tf_ssb_acquire_db_writer ( tf_ssb_t ssb)

Acquire an SQLite database with full write access to the database. Release with tf_ssb_release_db_writer().

Parameters
ssbThe SSB instance.
Returns
The writable database.

◆ tf_ssb_add_blob_stored_callback()

void tf_ssb_add_blob_stored_callback ( tf_ssb_t ssb,
tf_ssb_blob_stored_callback_t callback,
tf_ssb_callback_cleanup_t cleanup,
void *  user_data 
)

Register a callback called when a blob is added to the database.

Parameters
ssbThe SSB instance.
callbackThe callback function.
cleanupA function to call when the callback is removed.
user_dataUser data to pass to the callback.

◆ tf_ssb_add_blob_want_added_callback()

void tf_ssb_add_blob_want_added_callback ( tf_ssb_t ssb,
tf_ssb_blob_want_added_callback_t callback,
tf_ssb_callback_cleanup_t cleanup,
void *  user_data 
)

Register a function to be called when a blob is newly requested.

Parameters
ssbThe SSB instance.
callbackThe callback.
cleanupA function to call when the callback is removed.
user_dataUser data to pass to the callback.

◆ tf_ssb_add_broadcast()

void tf_ssb_add_broadcast ( tf_ssb_t ssb,
const char *  connection,
tf_ssb_broadcast_origin_t  origin,
int64_t  expires_seconds 
)

Add a broadcast entry.

Parameters
ssbThe SSB instance.
connectionThe connection string to add.
originThe origin of the broadcast entry.
expires_secondsHow long the broadcast entry should last.

◆ tf_ssb_add_broadcasts_changed_callback()

void tf_ssb_add_broadcasts_changed_callback ( tf_ssb_t ssb,
tf_ssb_broadcasts_changed_callback_t callback,
tf_ssb_callback_cleanup_t cleanup,
void *  user_data 
)

Register a callback when broadcasts change.

Parameters
ssbThe SSB instance.
callbackThe callback function.
cleanupA function to call when the callback is removed.
user_dataUser data to pass to the callback.

◆ tf_ssb_add_connections_changed_callback()

void tf_ssb_add_connections_changed_callback ( tf_ssb_t ssb,
tf_ssb_connections_changed_callback_t callback,
tf_ssb_callback_cleanup_t cleanup,
void *  user_data 
)

Register a callback when the connection list changes.

Parameters
ssbThe SSB instance.
callbackThe callback to register.
cleanupThe cleanup callback to register.
user_dataUser data to pass to the callbacks.

◆ tf_ssb_add_message_added_callback()

void tf_ssb_add_message_added_callback ( tf_ssb_t ssb,
tf_ssb_message_added_callback_t callback,
tf_ssb_callback_cleanup_t cleanup,
void *  user_data 
)

Register a callback called when a message is added to the database.

Parameters
ssbThe SSB instance.
callbackThe callback function.
cleanupA function to call when the callback is removed.
user_dataUser data to pass to the callback.

◆ tf_ssb_add_rpc_callback()

void tf_ssb_add_rpc_callback ( tf_ssb_t ssb,
const char *  name,
tf_ssb_rpc_callback_t callback,
tf_ssb_callback_cleanup_t cleanup,
void *  user_data 
)

Register a MUXRPC callback by name.

Parameters
ssbThe SSB instance.
nameThe RPC name as a .-separated string.
callbackThe callback.
cleanupA function to be called when the callback is removed.
user_dataUser data to pass to the callback.

◆ tf_ssb_broadcast_listener_start()

void tf_ssb_broadcast_listener_start ( tf_ssb_t ssb,
bool  linger 
)

Begin listening for SSB discovery messages.

Parameters
ssbThe SSB instance.
lingerTrue if listening for broadcasts should keep the event loop alive.

◆ tf_ssb_broadcast_sender_start()

void tf_ssb_broadcast_sender_start ( tf_ssb_t ssb)

Begin sending SSB discovevry messages.

Parameters
ssbThe SSB instance.

◆ tf_ssb_calculate_message_id()

void tf_ssb_calculate_message_id ( JSContext context,
JSValue  message,
char *  out_id,
size_t  out_id_size 
)

Determine the message identifier.

Parameters
contextA JS context.
messageThe message.
[out]out_idA buffer to receive the identifier.
out_id_sizeThe size of out_id.

◆ tf_ssb_close_all()

void tf_ssb_close_all ( tf_ssb_t ssb,
const char *  reason 
)

Close all active SHS connections.

Parameters
ssbThe SSB instance.
reasonReason for the close.

◆ tf_ssb_connect()

void tf_ssb_connect ( tf_ssb_t ssb,
const char *  host,
int  port,
const uint8_t *  key,
int  connect_flags,
tf_ssb_connect_callback_t callback,
void *  user_data 
)

Establish an SHS connection with a host.

Parameters
ssbThe SSB instance.
hostThe host name or address.
portThe host's SHS port.
keyThe host's SSB identity.
connect_flagsFlags affecting the connection.
callbackCompletion callback.
user_dataUser data to be passed to the callback.

◆ tf_ssb_connect_str()

void tf_ssb_connect_str ( tf_ssb_t ssb,
const char *  address,
int  connect_flags,
tf_ssb_connect_callback_t callback,
void *  user_data 
)

Establish an SHS connection with a host by string address.

Parameters
ssbThe SSB instance.
addressThe address.
connect_flagsFlags affecting the connection.
callbackCompletion callback.
user_dataUser data to be passed to the callback.

◆ tf_ssb_connection_add_new_message_request()

void tf_ssb_connection_add_new_message_request ( tf_ssb_connection_t connection,
const char *  author,
int32_t  request_number,
bool  keys 
)

Register for new messages on a connection.

Parameters
connectionThe SHS connection.
authorThe author for whom to request new messages.
request_numberThe MUXRPC request on which to send new messages.
keysWhether to send with keys.

◆ tf_ssb_connection_add_request()

void tf_ssb_connection_add_request ( tf_ssb_connection_t connection,
int32_t  request_number,
const char *  name,
tf_ssb_rpc_callback_t callback,
tf_ssb_callback_cleanup_t cleanup,
void *  user_data,
tf_ssb_connection_t dependent_connection 
)

Register a callback to be called when a message is received for the given request number.

Parameters
connectionThe connection on which to register the callback.
request_numberThe request number.
nameThe name of the RPC request.
callbackThe callback.
cleanupThe function to call when the callback is removed.
user_dataUser data to pass to the callback.
dependent_connectionA connection, which, if removed, invalidates this request.

◆ tf_ssb_connection_add_room_attendant()

void tf_ssb_connection_add_room_attendant ( tf_ssb_connection_t connection,
const char *  id 
)

Add a room attendant.

Parameters
connectionThe SHS connection.
idThe attendant identifier.

◆ tf_ssb_connection_adjust_read_backpressure()

void tf_ssb_connection_adjust_read_backpressure ( tf_ssb_connection_t connection,
int  delta 
)

Adjust read backpressure. If it gets too high, TCP receive will be paused until it lowers.

Parameters
connectionThe connection on which to affect backpressure.
deltaThe change in backpressure. Higher will eventually pause receive. Lower will resume it.

◆ tf_ssb_connection_adjust_write_count()

void tf_ssb_connection_adjust_write_count ( tf_ssb_connection_t connection,
int  delta 
)

Adjust write count. Work scheduled by tf_ssb_connection_schedule_idle will only start when this reaches zero.

Parameters
connectionThe connection on which to affect backpressure.
deltaThe change in write count. Higher will pause processing scheduled idle work queue. Lower will resume it.

◆ tf_ssb_connection_clear_room_attendants()

void tf_ssb_connection_clear_room_attendants ( tf_ssb_connection_t connection)

Clear all attendants from a room.

Parameters
connectionThe SHS connection.

◆ tf_ssb_connection_close()

void tf_ssb_connection_close ( tf_ssb_connection_t connection,
const char *  reason 
)

Close a connection.

Parameters
connectionThe connection.
reasonHuman-readable reason for closing the connection.

◆ tf_ssb_connection_get()

tf_ssb_connection_t * tf_ssb_connection_get ( tf_ssb_t ssb,
const char *  id 
)

Get an active connection by its identity.

Parameters
ssbThe SSB instance.
idThe SSB identity.
Returns
The connection if found or NULL.

◆ tf_ssb_connection_get_attendant_request_number()

int32_t tf_ssb_connection_get_attendant_request_number ( tf_ssb_connection_t connection)

Get the request number used to notify of room attendant changes.

Parameters
connectionthe SHS connection.
Returns
A request number.

◆ tf_ssb_connection_get_blob_wants_state()

tf_ssb_blob_wants_t * tf_ssb_connection_get_blob_wants_state ( tf_ssb_connection_t connection)

Get information about requested blobs.

Parameters
connectionAn SHS connection.
Returns
Blob wants information.

◆ tf_ssb_connection_get_context()

JSContext * tf_ssb_connection_get_context ( tf_ssb_connection_t connection)

Get a connection's JS context.

Parameters
connectionThe connection.
Returns
The JS context.

◆ tf_ssb_connection_get_destroy_reason()

const char * tf_ssb_connection_get_destroy_reason ( tf_ssb_connection_t connection)

Get the reason why a connection is going away.

Parameters
connectionThe connection.
Returns
The reason or NULL.

◆ tf_ssb_connection_get_ebt()

tf_ssb_ebt_t * tf_ssb_connection_get_ebt ( tf_ssb_connection_t connection)

Get a connection's EBT state.

Parameters
connectionThe connection.
Returns
the EBT state for the connection.

◆ tf_ssb_connection_get_ebt_request_number()

int32_t tf_ssb_connection_get_ebt_request_number ( tf_ssb_connection_t connection)

Get the request number on which to send EBT responses.

Parameters
connectionThe SHS connection.
Returns
The request number.

◆ tf_ssb_connection_get_endpoint_request_number()

int32_t tf_ssb_connection_get_endpoint_request_number ( tf_ssb_connection_t connection)

Get the request number used to notify of tunnel endpoint changes.

Parameters
connectionthe SHS connection.
Returns
A request number.

◆ tf_ssb_connection_get_flags()

int tf_ssb_connection_get_flags ( tf_ssb_connection_t connection)

Get a connection's flags.

Parameters
connectionThe connection.

◆ tf_ssb_connection_get_host()

const char * tf_ssb_connection_get_host ( tf_ssb_connection_t connection)

Get the hostname of the remote end of a connection.

Parameters
connectionThe connection.
Returns
The hostname or address.

◆ tf_ssb_connection_get_id()

bool tf_ssb_connection_get_id ( tf_ssb_connection_t connection,
char *  out_id,
size_t  out_id_size 
)

Get the SSB identity of a connection.

Parameters
connectionThe connection.
[out]out_idA buffer to be populated with the identity.
out_id_sizeThe size of out_id.
Returns
True if the identity was retrieved.

◆ tf_ssb_connection_get_object()

JSValue tf_ssb_connection_get_object ( tf_ssb_connection_t connection)

Get the JS object representing a connection.

Parameters
connectionThe connection.
Returns
The object.

◆ tf_ssb_connection_get_port()

int tf_ssb_connection_get_port ( tf_ssb_connection_t connection)

Get a connection's remote port number.

Parameters
connectionThe connection.
Returns
The port number.

◆ tf_ssb_connection_get_ssb()

tf_ssb_t * tf_ssb_connection_get_ssb ( tf_ssb_connection_t connection)

Get a connection's SSB instance.

Parameters
connectionThe connection.
Returns
The SSB instance.

◆ tf_ssb_connection_get_tunnel()

tf_ssb_connection_t * tf_ssb_connection_get_tunnel ( tf_ssb_connection_t connection)

If a connection is a tunnel, get its parent connection.

Parameters
connectionThe connection.
Returns
The parent connection if the connection is tunneled or NULL.

◆ tf_ssb_connection_is_attendant()

bool tf_ssb_connection_is_attendant ( tf_ssb_connection_t connection)

Get whether we are an attendant on a room connection.

Parameters
connectionThe SHS connection.
Returns
True if this is an attendant connection.

◆ tf_ssb_connection_is_client()

bool tf_ssb_connection_is_client ( tf_ssb_connection_t connection)

Check if a connection is an outgoing connection.

Parameters
connectionThe connection.
Returns
True if the connection is outgoing.

◆ tf_ssb_connection_is_closing()

bool tf_ssb_connection_is_closing ( tf_ssb_connection_t connection)

Check whether a connection is in the process of closing.

Parameters
connectionThe connection.
Returns
True if the connection is closing.

◆ tf_ssb_connection_is_connected()

bool tf_ssb_connection_is_connected ( tf_ssb_connection_t connection)

Check whether a connection is connected.

Parameters
connectionThe connection.
Returns
True if the connection is alive.

◆ tf_ssb_connection_is_endpoint()

bool tf_ssb_connection_is_endpoint ( tf_ssb_connection_t connection)

Get whether we are a potential tunnel endpoint.

Parameters
connectionThe SHS connection.
Returns
True if this is an endpoint connection.

◆ tf_ssb_connection_next_request_number()

int32_t tf_ssb_connection_next_request_number ( tf_ssb_connection_t connection)

Get the next outgoing request number for a connection.

Parameters
connectionThe connection.
Returns
The next request number.

◆ tf_ssb_connection_remove_new_message_request()

void tf_ssb_connection_remove_new_message_request ( tf_ssb_connection_t connection,
const char *  author 
)

Remove a request for new messages on a connection.

Parameters
connectionthe SHS connection.
authorThe author for whom to no longer request new messages.

◆ tf_ssb_connection_remove_request()

void tf_ssb_connection_remove_request ( tf_ssb_connection_t connection,
int32_t  request_number 
)

Remove a callback registered to be called when a message is received for the given request number.

Parameters
connectionThe connection.
request_numberThe request number.

◆ tf_ssb_connection_remove_room_attendant()

void tf_ssb_connection_remove_room_attendant ( tf_ssb_connection_t connection,
const char *  id 
)

Remove a room attendant.

Parameters
connectionThe SHS connection.
idThe attendanr identifier.

◆ tf_ssb_connection_requests_to_object()

JSValue tf_ssb_connection_requests_to_object ( tf_ssb_connection_t connection)

Get a debug representation of active requests.

Parameters
connectionThe connection.
Returns
The active requests as a JS object.

◆ tf_ssb_connection_rpc_send()

bool tf_ssb_connection_rpc_send ( tf_ssb_connection_t connection,
uint8_t  flags,
int32_t  request_number,
const char *  new_request_name,
const uint8_t *  message,
size_t  size,
tf_ssb_rpc_callback_t callback,
tf_ssb_callback_cleanup_t cleanup,
void *  user_data 
)

Send a MUXRPC message.

Parameters
connectionThe connection on which to send the message.
flagsThe message flags.
request_numberThe request number.
new_request_nameThe name of the request if it is new.
messageThe message payload.
sizeThe size of the message.
callbackA callback to call if a response is received.
cleanupA callback to call if the callback is removed.
user_dataUser data to pass to the callback.
Returns
true If the message was queued to send, false if the connection or request were invalid.

◆ tf_ssb_connection_rpc_send_error()

bool tf_ssb_connection_rpc_send_error ( tf_ssb_connection_t connection,
uint8_t  flags,
int32_t  request_number,
const char *  error 
)

Send a MUXRPC error message.

Parameters
connectionThe connection on which to send the message.
flagsThe message flags.
request_numberThe request number.
errorThe error string.
Returns
true If the message was queued to send, false if the connection or request were invalid.

◆ tf_ssb_connection_rpc_send_error_method_not_allowed()

bool tf_ssb_connection_rpc_send_error_method_not_allowed ( tf_ssb_connection_t connection,
uint8_t  flags,
int32_t  request_number,
const char *  name 
)

Send a MUXRPC "method not allowed" error message.

Parameters
connectionThe connection on which to send the message.
flagsThe message flags.
request_numberThe request number.
nameThe name of the not-allowed method.
Returns
true If the message was queued to send, false if the connection or request were invalid.

◆ tf_ssb_connection_rpc_send_json()

bool tf_ssb_connection_rpc_send_json ( tf_ssb_connection_t connection,
uint8_t  flags,
int32_t  request_number,
const char *  new_request_name,
JSValue  message,
tf_ssb_rpc_callback_t callback,
tf_ssb_callback_cleanup_t cleanup,
void *  user_data 
)

Send a JSON MUXRPC message.

Parameters
connectionThe connection on which to send the message.
flagsThe message flags.
request_numberThe request number.
new_request_nameThe name of the request if it is new.
messageThe JS message payload.
callbackA callback to call if a response is received.
cleanupA callback to call if the callback is removed.
user_dataUser data to pass to the callback.
Returns
true If the message was queued to send, false if the connection or request were invalid.

◆ tf_ssb_connection_run_work()

void tf_ssb_connection_run_work ( tf_ssb_connection_t connection,
void(*)(tf_ssb_connection_t *connection, void *user_data)  work_callback,
void(*)(tf_ssb_connection_t *connection, int result, void *user_data)  after_work_callback,
void *  user_data 
)

Schedule work to run on a worker thread.

Parameters
connectionThe owning connection.
work_callbackThe callback to run on a thread.
after_work_callbackThe callback to run on the main thread when the work is complete.
user_dataUser data to pass to the callback.

◆ tf_ssb_connection_schedule_idle()

void tf_ssb_connection_schedule_idle ( tf_ssb_connection_t connection,
const char *  key,
tf_ssb_scheduled_callback_t callback,
void *  user_data 
)

Schedule work to be run when the connection is next idle.

Parameters
connectionThe owning connection.
keyA key identifying the work. If work by the same key already exists, the new request will be discarded.
callbackThe callback to call.
user_dataUser data to pass to the callback.

◆ tf_ssb_connection_set_attendant()

void tf_ssb_connection_set_attendant ( tf_ssb_connection_t connection,
bool  attendant,
int  request_number 
)

Register for attendant change notifications on a connection.

Parameters
connectionThe SHS connection.
attendantWhether this connection will be an attendant.
request_numberThe request number on which to send attendant changes.

◆ tf_ssb_connection_set_ebt_request_number()

void tf_ssb_connection_set_ebt_request_number ( tf_ssb_connection_t connection,
int32_t  request_number 
)

Set the request number on which to send EBT responses.

Parameters
connectionThe SHS connection.
request_numberThe request number.

◆ tf_ssb_connection_set_endpoint()

void tf_ssb_connection_set_endpoint ( tf_ssb_connection_t connection,
bool  endpoint,
int  request_number 
)

Register for endpoint change notifications on a connection.

Parameters
connectionThe SHS connection.
endpointWhether this connection will be an endpoint.
request_numberThe request number on which to send endpoint changes.

◆ tf_ssb_connection_tunnel_create()

tf_ssb_connection_t * tf_ssb_connection_tunnel_create ( tf_ssb_t ssb,
const char *  portal_id,
int32_t  request_number,
const char *  target_id,
int  connect_flags 
)

Create a tunnel.

Parameters
ssbThe SSB instance.
portal_idThe identity of the tunnel intermediary.
request_numberThe tunnel request.
target_idThe identity being tunneled to.
connect_flagsFlags affecting the connection.
Returns
The new tunnel connection.

◆ tf_ssb_create()

tf_ssb_t * tf_ssb_create ( uv_loop_t loop,
JSContext context,
const char *  db_path,
const char *  network_key 
)

Create an SSB instance.

Parameters
loopThe event loop to use or NULL to create a new one.
contextThe JS context to use or NULL to create a new one.
db_pathThe path to the SQLite database to use.
network_keyThe SSB network key to use or NULL to use the standard key.

◆ tf_ssb_destroy()

void tf_ssb_destroy ( tf_ssb_t ssb)

Destroy an SSB instance.

Parameters
ssbThe SSB instance to destroy.

◆ tf_ssb_generate_keys()

void tf_ssb_generate_keys ( tf_ssb_t ssb)

Generate a public/private key pair for the SSB instance.

Parameters
ssbThe SSB instance.

◆ tf_ssb_generate_keys_buffer()

void tf_ssb_generate_keys_buffer ( char *  out_public,
size_t  public_size,
char *  out_private,
size_t  private_size 
)

Generate a public/private key pair and store in buffers.

Parameters
[out]out_publicBuffer to receive the public key.
public_sizeSize of the public key buffer.
[out]out_privateBuffer to receive the private key.
private_sizeSize of the private key buffer.

◆ tf_ssb_get_average_thread_percent()

float tf_ssb_get_average_thread_percent ( tf_ssb_t ssb)

Get an estimate of utilization of all running threads.

Parameters
ssbThe SSB instance.
Returns
The utilization percent.

◆ tf_ssb_get_connection_class_id()

JSClassID tf_ssb_get_connection_class_id ( )

Get the JS class ID of the SSB connection class.

Returns
The class ID

◆ tf_ssb_get_connection_ids()

const char ** tf_ssb_get_connection_ids ( tf_ssb_t ssb)

Get the identities of all active connections.

Parameters
ssbThe SSB instance.
Returns
A NULL-terminated array of SSB identities. Free with tf_free().

◆ tf_ssb_get_connections()

int tf_ssb_get_connections ( tf_ssb_t ssb,
tf_ssb_connection_t **  out_connections,
int  out_connections_count 
)

Retrieve a list of active connections.

Parameters
ssbThe SSB instance.
[out]out_connectionsAn array to be populated with the connections.
out_connections_countThe size of the connections array.
Returns
The number of connections populated in out_connections.

◆ tf_ssb_get_context()

JSContext * tf_ssb_get_context ( tf_ssb_t ssb)

Get the SSB istance's JS context.

Parameters
ssbThe SSB instance.
Returns
The JS context.

◆ tf_ssb_get_loop()

uv_loop_t * tf_ssb_get_loop ( tf_ssb_t ssb)

Get the SSB instance's event loop.

Parameters
ssbThe SSB instance.
Returns
The loop.

◆ tf_ssb_get_private_key()

void tf_ssb_get_private_key ( tf_ssb_t ssb,
uint8_t *  out_private,
size_t  private_size 
)

Get the private key of the SSB instance.

Parameters
ssbThe SSB instance.
[out]out_privateBuffer to receive the private key.
private_sizeThe size of the private key buffer.

◆ tf_ssb_get_room_name()

const char * tf_ssb_get_room_name ( tf_ssb_t ssb)

Get the name of the room hosted by the running server.

Parameters
ssbThe SSB instance.
Returns
The room name or NULL.

◆ tf_ssb_get_stats()

void tf_ssb_get_stats ( tf_ssb_t ssb,
tf_ssb_stats_t out_stats 
)

Get general statistics about an SSB instance.

Parameters
ssbThe SSB instance.
[out]out_statsPopulated with performance statistics.

◆ tf_ssb_get_store_queue()

tf_ssb_store_queue_t * tf_ssb_get_store_queue ( tf_ssb_t ssb)

Get the queue of messages in the progress of being stored.

Parameters
ssbThe SSB instance.
Returns
The queue.

◆ tf_ssb_get_trace()

tf_trace_t * tf_ssb_get_trace ( tf_ssb_t ssb)

Get the SSB instance's trace instance.

Parameters
ssbThe SSB instance.
Returns
The trace instance.

◆ tf_ssb_hmacsha256_verify()

bool tf_ssb_hmacsha256_verify ( const char *  public_key,
const void *  payload,
size_t  payload_length,
const char *  signature,
bool  signature_is_urlb64 
)

Verify a signature.

Parameters
public_keyThe public key for which the message was signed.
payloadThe signed payload.
payload_lengthThe length of the signed payload in bytes.
signatureThe signature.
signature_is_urlb64True if the signature is in URL base64 format, otherwise standard base64.
Returns
true If the message was successfully verified.

◆ tf_ssb_id_bin_to_str()

bool tf_ssb_id_bin_to_str ( char *  str,
size_t  str_size,
const uint8_t *  bin 
)

Convert an SSB identity from binary to string.

Parameters
[out]strA buffer to receive the identity string.
str_sizeThe size of the string buffer.
binThe binary identity.
Returns
True if the conversion was successful.

◆ tf_ssb_id_str_to_bin()

bool tf_ssb_id_str_to_bin ( uint8_t *  bin,
const char *  str 
)

Convert an SSB identity from string to binary.

Parameters
[out]binA buffer to receive the binary identity.
strThe string identity.
Returns
True if the conversion was successful.

◆ tf_ssb_is_peer_exchange()

bool tf_ssb_is_peer_exchange ( tf_ssb_t ssb)

Get whether the running server participates in peer exchange.

Parameters
ssbThe SSB instance.
Returns
True if the server participates in peer exchange.

◆ tf_ssb_is_replicator()

bool tf_ssb_is_replicator ( tf_ssb_t ssb)

Get whether the running server supports replication of messages and blobs.

Parameters
ssbThe SSB instance.
Returns
True if the server is a replicator.

◆ tf_ssb_is_room()

bool tf_ssb_is_room ( tf_ssb_t ssb)

Get whether the running server is operating a room.

Parameters
ssbThe SSB instance.
Returns
True if the server is a room.

◆ tf_ssb_is_shutting_down()

bool tf_ssb_is_shutting_down ( tf_ssb_t ssb)

Checking if the SSB instance is in the process of shutting down.

Parameters
ssbThe SSB instance.
Returns
true If the SSB instance is shutting down.

◆ tf_ssb_notify_blob_stored()

void tf_ssb_notify_blob_stored ( tf_ssb_t ssb,
const char *  id 
)

Record that a new blob was stored.

Parameters
ssbThe SSB instance.
idThe identity of the newly stored blob.

◆ tf_ssb_notify_blob_want_added()

void tf_ssb_notify_blob_want_added ( tf_ssb_t ssb,
const char *  id 
)

Call all callbacks registered for when a blob is newly requested.

Parameters
ssbThe SSB instance.
idThe requested blob identity.

◆ tf_ssb_notify_message_added()

void tf_ssb_notify_message_added ( tf_ssb_t ssb,
const char *  author,
int32_t  sequence,
const char *  id,
JSValue  message_with_keys 
)

Call all callbacks registered for when a message is added to the database.

Parameters
ssbThe SSB instance.
authorThe message author's identity.
sequenceThe message sequence number.
idThe message identity added.
message_with_keysThe message added in the format required if keys are requested.

◆ tf_ssb_private_message_encrypt()

char * tf_ssb_private_message_encrypt ( uint8_t *  private_key,
const char **  recipients,
int  recipients_count,
const char *  message,
size_t  message_size 
)

Encrypt a private message to a set of recipients.

Parameters
private_keyThe private key of the author.
recipientsA list of recipient identities.
recipients_countThe number of recipients in recipients.
messageThe plain text to post.
message_sizeThe length in bytes of message.
Returns
A secret box string. Free with tf_free().

◆ tf_ssb_record_thread_busy()

void tf_ssb_record_thread_busy ( tf_ssb_t ssb,
bool  busy 
)

Record whether the calling thread is busy.

Parameters
ssbThe SSB instance.
busyTrue if the calling thread is now busy.

◆ tf_ssb_ref()

void tf_ssb_ref ( tf_ssb_t ssb)

Increment the SSB instance's ref count. Prevents it from being destroyed until it reaches zero.

Parameters
ssbThe SSB instance.

◆ tf_ssb_release_db_reader()

void tf_ssb_release_db_reader ( tf_ssb_t ssb,
sqlite3 db 
)

Release a database acquired with tf_ssb_acquire_db_reader() or tf_ssb_acquire_db_reader_restricted().

Parameters
ssbThe SSB instance.
dbThe database.

◆ tf_ssb_release_db_writer()

void tf_ssb_release_db_writer ( tf_ssb_t ssb,
sqlite3 db 
)

Release a database acquired with tf_ssb_acquire_db_writer().

Parameters
ssbThe SSB instance.
dbThe database.

◆ tf_ssb_remove_blob_stored_callback()

void tf_ssb_remove_blob_stored_callback ( tf_ssb_t ssb,
tf_ssb_blob_stored_callback_t callback,
void *  user_data 
)

Remove a callback registered for when a blob is added to the database.

Parameters
ssbThe SSB instance.
callbackThe callback function.
user_dataUser data registered with the callback.

◆ tf_ssb_remove_blob_want_added_callback()

void tf_ssb_remove_blob_want_added_callback ( tf_ssb_t ssb,
tf_ssb_blob_want_added_callback_t callback,
void *  user_data 
)

Remove a callback registered for when a blob is newly requested.

Parameters
ssbThe SSB instance.
callbackThe callback to remove.
user_dataThe user data registered with the callback.

◆ tf_ssb_remove_broadcasts_changed_callback()

void tf_ssb_remove_broadcasts_changed_callback ( tf_ssb_t ssb,
tf_ssb_broadcasts_changed_callback_t callback,
void *  user_data 
)

Remove a callback registered for when broadcasts changed.

Parameters
ssbThe SSB instance.
callbackThe callback function.
user_dataThe user data registered with the callback.

◆ tf_ssb_remove_connections_changed_callback()

void tf_ssb_remove_connections_changed_callback ( tf_ssb_t ssb,
tf_ssb_connections_changed_callback_t callback,
void *  user_data 
)

Remove a callback when the connection list changes.

Parameters
ssbThe SSB instance.
callbackThe callback.
user_dataThe user data registered with the callback.

◆ tf_ssb_remove_message_added_callback()

void tf_ssb_remove_message_added_callback ( tf_ssb_t ssb,
tf_ssb_message_added_callback_t callback,
void *  user_data 
)

Remove a callback registered for when a message is added to the database.

Parameters
ssbThe SSB instance.
callbackThe callback function.
user_dataUser data registered with the callback.

◆ tf_ssb_remove_rpc_callback()

void tf_ssb_remove_rpc_callback ( tf_ssb_t ssb,
const char **  name,
tf_ssb_rpc_callback_t callback,
void *  user_data 
)

Remove a MUXRPC callback.

Parameters
ssbThe SSB instance.
nameThe NULL-terminated name.
callbackThe callback to remove.
user_dataThe user data registered with the callback.

◆ tf_ssb_run()

void tf_ssb_run ( tf_ssb_t ssb)

Run the SSB instance until there is no work to do or stopped.

Parameters
ssbThe SSB instance.

◆ tf_ssb_run_work()

void tf_ssb_run_work ( tf_ssb_t ssb,
void(*)(tf_ssb_t *ssb, void *user_data)  work_callback,
void(*)(tf_ssb_t *ssb, int result, void *user_data)  after_work_callback,
void *  user_data 
)

Schedule work to run on a worker thread.

Parameters
ssbThe owning SSB instance.
work_callbackThe callback to run on a thread.
after_work_callbackThe callback to run on the main thread when the work is complete.
user_dataUser data to pass to the callback.

◆ tf_ssb_schedule_work()

void tf_ssb_schedule_work ( tf_ssb_t ssb,
int  delay_ms,
void(*)(tf_ssb_t *ssb, void *user_data)  callback,
void *  user_data 
)

Schedule work to be run after a time delay.

Parameters
ssbThe SSB instance.
delay_msThe duration to wait in milliseconds.
callbackThe callback to call to run the work.
user_dataUser data to pass to the callback.

◆ tf_ssb_send_close()

void tf_ssb_send_close ( tf_ssb_t ssb)

Send a graceful close message to all active SHS connections.

Parameters
ssbThe SSB instance.

◆ tf_ssb_server_close()

void tf_ssb_server_close ( tf_ssb_t ssb)

Stop listening for SHS connections.

Parameters
ssbThe SSB instance.

◆ tf_ssb_server_get_port()

int tf_ssb_server_get_port ( tf_ssb_t ssb)

Determine the port that a server is listening on.

Parameters
ssbThe SSB instance.
Returns
The port number, or 0 if not bound.

◆ tf_ssb_server_open()

int tf_ssb_server_open ( tf_ssb_t ssb,
int  port 
)

Begin listening for SHS connections on the given port.

Parameters
ssbThe SSB instance.
portThe port number.
Returns
The assigned port on success or 0 on failure.

◆ tf_ssb_set_is_peer_exchange()

void tf_ssb_set_is_peer_exchange ( tf_ssb_t ssb,
bool  is_peer_exchange 
)

Set whether the running server participates in peer exchange.

Parameters
ssbThe SSB instance.
is_peer_exchangeWhether to participate in peer exchange.

◆ tf_ssb_set_is_replicator()

void tf_ssb_set_is_replicator ( tf_ssb_t ssb,
bool  is_replicator 
)

Set whether the running server supports replication of messages and blobs.

Parameters
ssbThe SSB instance.
is_replicatorWhether to support replication.

◆ tf_ssb_set_is_room()

void tf_ssb_set_is_room ( tf_ssb_t ssb,
bool  is_room 
)

Set whether the running server is operating a room.

Parameters
ssbThe SSB instance.
is_roomWhether to run a room.

◆ tf_ssb_set_main_thread()

void tf_ssb_set_main_thread ( tf_ssb_t ssb,
bool  main_thread 
)

Record whether the calling thread is the main thread or not. Some operations are disallowed on the main thread for performance.

Parameters
ssbThe SSB instance.
main_threadWhether the calling thread is the main thread.

◆ tf_ssb_set_quiet()

void tf_ssb_set_quiet ( tf_ssb_t ssb,
bool  quiet 
)

Reduce logging verbosity.

Parameters
ssbThe SSB instance.
quietDisable unnecessary messages.

◆ tf_ssb_set_room_name()

void tf_ssb_set_room_name ( tf_ssb_t ssb,
const char *  room_name 
)

Set the name of the room hosted by the running server.

Parameters
ssbThe SSB instance.
room_nameThe name of the room.

◆ tf_ssb_set_trace()

void tf_ssb_set_trace ( tf_ssb_t ssb,
tf_trace_t trace 
)

Set the trace instance to use for the SSB instance.

Parameters
ssbThe SSB instance.
traceThe trace instance to use.

◆ tf_ssb_set_verbose()

void tf_ssb_set_verbose ( tf_ssb_t ssb,
bool  verbose 
)

Control logging verbosity.

Parameters
ssbThe SSB instance.
verboseTrue to log messages for every RPC message sent and received.

◆ tf_ssb_sign_message()

JSValue tf_ssb_sign_message ( tf_ssb_t ssb,
const char *  author,
const uint8_t *  private_key,
JSValue  message,
const char *  previous_id,
int32_t  previous_sequence 
)

Sign an SSB message.

Parameters
ssbThe SSB instance.
authorThe author's public key.
private_keyThe author's private key.
messageThe message to sign.
previous_idThe ID of the previous message in the feed. Optional.
previous_sequenceThe sequence number of the previous message in the feed. Optional.
Returns
The signed message.

◆ tf_ssb_start_periodic()

void tf_ssb_start_periodic ( tf_ssb_t ssb)

Start optional periodic work.

Parameters
ssbThe SSB instance.

◆ tf_ssb_sync_start()

void tf_ssb_sync_start ( tf_ssb_t ssb)

Initiate a one time sync operation.

Parameters
ssbThe SSB instance.

◆ tf_ssb_tunnel_create()

bool tf_ssb_tunnel_create ( tf_ssb_t ssb,
const char *  portal_id,
const char *  target_id,
int  connect_flags 
)

Initiate a tunnel connection.

Parameters
ssbThe SSB instance.
portal_idThe public key of the instance through which to tunnel.
target_idThe public key of the instance with which to establish a connection.
connect_flagsFlags affecting the connection.
Returns
true if the tunnel instance was found.

◆ tf_ssb_unref()

void tf_ssb_unref ( tf_ssb_t ssb)

Decrement the SSB instance's ref count. May destroy the instance when the count returns to zero.

Parameters
ssbThe SSB instance.

◆ tf_ssb_verify_and_strip_signature()

bool tf_ssb_verify_and_strip_signature ( JSContext context,
JSValue  val,
int  verify_flags,
char *  out_id,
size_t  out_id_size,
char *  out_signature,
size_t  out_signature_size,
int *  out_flags 
)

Verify a message's signature and remove the signature if successful.

Parameters
contextA JS context.
valThe message.
verify_flagsVerification options of type tf_ssb_verify_flags_t.
[out]out_idA buffer to receive the message's identity.
out_id_sizeThe size of out_id.
[out]out_signatureA buffer to receive the message's signature.
out_signature_sizeThe size of out_signature.
[out]out_flagstf_ssb_message_flags_t describing the message.
Returns
True if the signature is valid and was successfully extracted.

◆ tf_ssb_verify_strip_and_store_message()

void tf_ssb_verify_strip_and_store_message ( tf_ssb_t ssb,
JSValue  value,
tf_ssb_verify_strip_store_callback_t callback,
void *  user_data 
)

Verify a message's signature, remove the signature, and store the message in the database.

Parameters
ssbThe SSB instance.
valueThe message.
callbackA callback called when the operation completed.
user_dataUser data to pass to the callback.

◆ tf_ssb_visit_broadcasts()

void tf_ssb_visit_broadcasts ( tf_ssb_t ssb,
void(*)(const char *host, const struct sockaddr_in *addr, tf_ssb_broadcast_origin_t origin, tf_ssb_connection_t *tunnel, const uint8_t *pub, void *user_data)  callback,
void *  user_data 
)

Call a callback for each active host discovered by network discovery broadcast.

Parameters
ssbThe SSB instance.
callbackThe callback.
user_dataUser data for the callback.

◆ tf_ssb_whoami()

bool tf_ssb_whoami ( tf_ssb_t ssb,
char *  out_id,
size_t  out_id_size 
)

Get the server's identity.

Parameters
ssbThe SSB instance.
[out]out_idA buffer populated with the identity.
out_id_sizeThe size of the identity buffer.
Returns
True if the identity was successfully retrieved.