8 Commits

Author SHA1 Message Date
052663efbe ssb: Proof of concept to try to stay connected to a handful of peers. #130
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 37m27s
2025-06-28 13:47:58 -04:00
8f84ff2611 ssb: Collapse contact group users to only icons.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 36m44s
2025-06-27 12:46:15 -04:00
37e1c5d97b core: Use crypto_generichash. We don't need to roll our own FNV32a.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 36m37s
2025-06-25 21:10:05 -04:00
cef526bcf3 ssb: Fix the tab cycling order.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 37m34s
2025-06-25 20:23:01 -04:00
6af36cafa9 ssb: Wait, I don't think we need to close any connections here.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
2025-06-25 20:10:22 -04:00
fca859d93d ssb: Are we inadvertantly closing connections when an inner tunnel request ends?
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
2025-06-25 20:00:44 -04:00
2178300d8d welcome: +PeachCloud.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 36m44s
2025-06-25 18:49:43 -04:00
636bdcce6b build: Start work on 0.0.33. nix => 0.0.32.
Some checks failed
Build Tilde Friends / Build-All (push) Has been cancelled
2025-06-25 18:34:59 -04:00
20 changed files with 118 additions and 62 deletions

View File

@ -16,9 +16,9 @@ MAKEFLAGS += --no-builtin-rules
## LD := Linker.
## ANDROID_SDK := Path to the Android SDK.
VERSION_CODE := 38
VERSION_CODE_IOS := 14
VERSION_NUMBER := 0.0.32
VERSION_CODE := 39
VERSION_CODE_IOS := 15
VERSION_NUMBER := 0.0.33-wip
VERSION_NAME := This program kills fascists.
IPHONEOS_VERSION_MIN=14.0
@ -650,6 +650,7 @@ SODIUM_SOURCES := \
deps/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20_ref2.c \
deps/libsodium/src/libsodium/crypto_core/salsa/ref/core_salsa_ref.c \
deps/libsodium/src/libsodium/crypto_core/softaes/softaes.c \
deps/libsodium/src/libsodium/crypto_generichash/crypto_generichash.c \
deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c \
deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c \
deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/generichash_blake2b.c \

View File

@ -1,5 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "🦀",
"previous": "&Rn4Eg5ev5qhrYRnwxPB0DiEwO7VdGMDGp7tL/W7bRZo=.sha256"
"previous": "&lOCyez82jwCUs8R/Ynx2nBK598+qDZ7RhGnWOaNQO9U=.sha256"
}

View File

@ -23,6 +23,8 @@ class TfElement extends LitElement {
url: {type: String},
private_messages: {type: Array},
recent_reactions: {type: Array},
is_administrator: {type: Boolean},
stay_connected: {type: Boolean},
};
}
@ -73,6 +75,10 @@ class TfElement extends LitElement {
async initial_load() {
let whoami = await tfrpc.rpc.getActiveIdentity();
let ids = (await tfrpc.rpc.getIdentities()) || [];
this.is_administrator = await tfrpc.rpc.isAdministrator();
this.stay_connected =
this.is_administrator &&
(await tfrpc.rpc.globalSettingsGet('stay_connected'));
this.url = await tfrpc.rpc.url();
this.whoami = whoami ?? (ids.length ? ids[0] : undefined);
this.guest = !this.whoami?.length;
@ -131,8 +137,8 @@ class TfElement extends LitElement {
let channel_names = [
'',
'@',
'🔐',
'👍',
'🔐',
...this.channels.map((x) => '#' + x),
];
let index = channel_names.indexOf(this.hash.substring(1));
@ -658,6 +664,18 @@ class TfElement extends LitElement {
tfrpc.rpc.sync();
}
async toggle_stay_connected() {
let stay_connected = await tfrpc.rpc.globalSettingsGet('stay_connected');
let new_stay_connected = !this.stay_connected;
try {
if (new_stay_connected != stay_connected) {
await tfrpc.rpc.globalSettingsSet('stay_connected', new_stay_connected);
}
} finally {
this.stay_connected = await tfrpc.rpc.globalSettingsGet('stay_connected');
}
}
render() {
let self = this;
@ -680,14 +698,26 @@ class TfElement extends LitElement {
class="w3-bar w3-theme-l1"
style="position: static; top: 0; z-index: 10"
>
<button
class=${'w3-bar-item w3-button w3-circle w3-ripple' +
(this.connections?.some((x) => x.flags.one_shot) ? ' w3-spin' : '')}
style="width: 1.5em; height: 1.5em; padding: 8px"
@click=${this.refresh}
>
</button>
${this.is_administrator
? html`
<button
class=${'w3-bar-item w3-button w3-circle w3-ripple' +
(this.connections?.some((x) => x.flags.one_shot)
? ' w3-spin'
: '')}
style="width: 1.5em; height: 1.5em; padding: 8px"
@click=${this.refresh}
>
</button>
<button
class="w3-bar-item w3-button w3-ripple"
@click=${this.toggle_stay_connected}
>
${this.stay_connected ? '🔗' : '⛓️‍💥'}
</button>
`
: undefined}
${Object.entries(k_tabs).map(
([k, v]) => html`
<button

View File

@ -686,7 +686,11 @@ class TfMessageElement extends LitElement {
${x.action}
${x.users.map(
(y) => html`
<tf-user id=${y} .users=${this.users}></tf-user>
<tf-user
id=${y}
.users=${this.users}
icon_only="true"
></tf-user>
`
)}
</div>

View File

@ -7,6 +7,7 @@ class TfUserElement extends LitElement {
return {
id: {type: String},
fallback_name: {type: String},
icon_only: {type: Boolean},
users: {type: Object},
};
}
@ -17,6 +18,7 @@ class TfUserElement extends LitElement {
super();
this.id = null;
this.fallback_name = null;
this.icon_only = false;
this.users = {};
}
@ -32,9 +34,11 @@ class TfUserElement extends LitElement {
>😎</span
>`;
let name = this.users?.[this.id]?.name;
name = html`<a target="_top" href=${'#' + this.id}
>${name ?? this.fallback_name ?? this.id}</a
>`;
name = this.icon_only
? undefined
: html`<a target="_top" href=${'#' + this.id}
>${name ?? this.fallback_name ?? this.id}</a
>`;
if (user) {
let image_link = user.image;
@ -48,6 +52,7 @@ class TfUserElement extends LitElement {
class=${'w3-theme-l4 ' + shape}
style="width: 2em; height: 2em; vertical-align: middle; object-fit: cover"
src="/${image_link}/view"
alt=${name ?? this.fallback_name ?? this.id}
/>`;
}
}

View File

@ -1,5 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "👋",
"previous": "&fY3YUKPuH/wqOgKPVNJu1vWEHCXf5fToL2qiVXMRmxc=.sha256"
"previous": "&3puDxDNnf6C+YXpFysYLgxFMAy54/AO9V7Xpja6qO/k=.sha256"
}

View File

@ -76,7 +76,8 @@
<h2>First-time user checklist:</h2>
<ol type="1" style="text-align: left">
<li>
<a href="https://dev.tildefriends.net/cory/tildefriends/releases"
<a
href="https://dev.tildefriends.net/cory/tildefriends/releases/latest"
>Download</a
>
Tilde Friends or use
@ -84,7 +85,7 @@
>https://www.tildefriends.net/</a
>.
<div class="w3-cell-row">
<div class="w3-container w3-cell">
<div class="w3-container w3-cell w3-mobile">
<h3>Mobile</h3>
<p>
<a
@ -113,7 +114,7 @@
</p>
<p>Just launch the app.</p>
</div>
<div class="w3-container w3-cell">
<div class="w3-container w3-cell w3-mobile">
<h3>Web</h3>
<p>
<a
@ -128,8 +129,19 @@
>
to take it for a spin right away.
</p>
<h3>PeachCloud</h3>
<p>
Tilde Friends is also a part of 🍑☁️<a
href="https://peach-docs.commoninternet.net/"
>PeachCloud</a
>, which is available on
<a href="https://apps.yunohost.org/app/peachpub"
>YunoHost</a
>
for accessible self-hosting.
</p>
</div>
<div class="w3-container w3-cell">
<div class="w3-container w3-cell w3-mobile">
<h3>Desktop</h3>
<p>
<a

View File

@ -25,14 +25,14 @@
}:
pkgs.stdenv.mkDerivation rec {
pname = "tildefriends";
version = "0.0.31";
version = "0.0.32";
src = pkgs.fetchFromGitea {
domain = "dev.tildefriends.net";
owner = "cory";
repo = "tildefriends";
rev = "v${version}";
hash = "sha256-c2ZKVNikI5jN5GQuvp7S53qqnRZniSrJMF1FUZdVNPI=";
hash = "sha256-Dk0NOEQIg2LeENySK0+MgpZEtfsClGq6dZL+eOOpE0U=";
fetchSubmodules = true;
};

View File

@ -61,6 +61,7 @@ options:
autologin (default: false): Whether mobile autologin is supported.
broadcast (default: true): Send network discovery broadcasts.
discovery (default: true): Receive network discovery broadcasts.
stay_connected (default: false): Whether to attempt to keep several peer connections open.
-o, --one-proc Run everything in one process (unsafely!).
-z, --zip path Zip archive from which to load files.
-v, --verbose Log raw messages.

8
flake.lock generated
View File

@ -20,16 +20,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1748037224,
"narHash": "sha256-92vihpZr6dwEMV6g98M5kHZIttrWahb9iRPBm1atcPk=",
"lastModified": 1750622754,
"narHash": "sha256-kMhs+YzV4vPGfuTpD3mwzibWUE6jotw5Al2wczI0Pv8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f09dede81861f3a83f7f06641ead34f02f37597f",
"rev": "c7ab75210cb8cb16ddd8f290755d9558edde7ee1",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.11",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}

View File

@ -2,7 +2,7 @@
description = "Tilde Friends is a platform for making, running, and sharing web applications.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
};

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unprompted.tildefriends"
android:versionCode="38"
android:versionName="0.0.32">
android:versionCode="39"
android:versionName="0.0.33-wip">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application

View File

@ -13,13 +13,13 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.32</string>
<string>0.0.33</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>14</string>
<string>15</string>
<key>DTPlatformName</key>
<string>iphoneos</string>
<key>LSRequiresIPhoneOS</key>

View File

@ -3,6 +3,7 @@
#include "util.js.h"
#include "quickjs.h"
#include "sodium/crypto_generichash.h"
#include "sqlite3.h"
#include "uv.h"
@ -154,11 +155,11 @@ static void _tf_mem_summarize(void* ptr, size_t size, int frames_count, void* co
{
summary_t* summary = user_data;
tf_mem_allocation_t allocation = {
.stack_hash = tf_util_fnv32a(frames, sizeof(void*) * frames_count, 0),
.count = 1,
.size = size,
.frames_count = frames_count,
};
crypto_generichash((void*)&allocation.stack_hash, sizeof(allocation.stack_hash), (const void*)frames, sizeof(void*) * frames_count, NULL, 0);
memcpy(allocation.frames, frames, sizeof(void*) * frames_count);
int index = tf_util_insert_index(&allocation, summary->allocations, summary->count, sizeof(tf_mem_allocation_t), _tf_mem_hash_stack_compare);

View File

@ -2,6 +2,7 @@
#include "log.h"
#include "mem.h"
#include "ssb.db.h"
#include "ssb.h"
#include "util.js.h"
@ -51,15 +52,19 @@ static void _tf_ssb_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_change_t
}
}
static bool _tf_ssb_connections_get_next_connection(tf_ssb_connections_t* connections, char* host, size_t host_size, int* port, char* key, size_t key_size)
static bool _tf_ssb_connections_get_next_connection(
tf_ssb_connections_t* connections, char* host, size_t host_size, int* port, char* key, size_t key_size, bool* out_stay_connected)
{
bool result = false;
sqlite3_stmt* statement;
sqlite3* db = tf_ssb_acquire_db_reader(connections->ssb);
tf_ssb_db_get_global_setting_bool(db, "stay_connected", out_stay_connected);
if (sqlite3_prepare_v2(db, "SELECT host, port, key FROM connections WHERE last_attempt IS NULL OR (strftime('%s', 'now') - last_attempt > ?1) ORDER BY last_attempt LIMIT 1",
-1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_int(statement, 1, 60000) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
if (sqlite3_bind_int(statement, 1, *out_stay_connected ? 15 : 60000) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
{
tf_string_set(host, host_size, (const char*)sqlite3_column_text(statement, 0));
*port = sqlite3_column_int(statement, 1);
@ -80,6 +85,8 @@ typedef struct _tf_ssb_connections_get_next_t
{
tf_ssb_connections_t* connections;
bool ready;
bool stay_connected;
bool full;
char host[256];
int port;
char key[k_id_base64_len];
@ -92,7 +99,7 @@ static void _tf_ssb_connections_get_next_work(tf_ssb_t* ssb, void* user_data)
{
return;
}
next->ready = _tf_ssb_connections_get_next_connection(next->connections, next->host, sizeof(next->host), &next->port, next->key, sizeof(next->key));
next->ready = _tf_ssb_connections_get_next_connection(next->connections, next->host, sizeof(next->host), &next->port, next->key, sizeof(next->key), &next->stay_connected);
}
static void _tf_ssb_connections_get_next_after_work(tf_ssb_t* ssb, int status, void* user_data)
@ -100,12 +107,20 @@ static void _tf_ssb_connections_get_next_after_work(tf_ssb_t* ssb, int status, v
tf_ssb_connections_get_next_t* next = user_data;
if (next->ready)
{
/*
** Might be a duplicate connection or otherwise discarded by
** tf_ssb_connect() before we otherwise set attempted, so do it
** here.
*/
tf_ssb_connections_set_attempted(next->connections, next->host, next->port, next->key);
uint8_t key_bin[k_id_bin_len];
if (tf_ssb_id_str_to_bin(key_bin, next->key))
{
tf_ssb_connect(ssb, next->host, next->port, key_bin, k_tf_ssb_connect_flag_do_not_store, NULL, NULL);
}
}
uv_timer_set_repeat(&next->connections->timer, next->stay_connected ? (next->full ? 2000 : 200) : (next->full ? 10000 : 2000));
tf_free(next);
}
@ -124,6 +139,7 @@ static void _tf_ssb_connections_timer(uv_timer_t* timer)
tf_ssb_connections_get_next_t* next = tf_malloc(sizeof(tf_ssb_connections_get_next_t));
*next = (tf_ssb_connections_get_next_t) {
.connections = connections,
.full = count + 1 == tf_countof(active),
};
tf_ssb_run_work(connections->ssb, _tf_ssb_connections_get_next_work, _tf_ssb_connections_get_next_after_work, next);
}

View File

@ -332,8 +332,6 @@ static void _tf_ssb_rpc_tunnel_callback(tf_ssb_connection_t* connection, uint8_t
JS_FreeValue(context, stack_val);
JS_FreeValue(context, message_val);
tf_ssb_connection_close(tun->connection, buffer);
}
else
{

View File

@ -22,6 +22,7 @@
#include "ares.h"
#include "backtrace.h"
#include "quickjs.h"
#include "sodium/crypto_generichash.h"
#include "sqlite3.h"
#include "unzip.h"
#include "uv.h"
@ -1255,6 +1256,8 @@ static void _tf_task_free_promise(tf_task_t* task, promiseid_t id)
JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise)
{
uint32_t stack_hash = 0;
crypto_generichash_state state;
crypto_generichash_init(&state, NULL, 0, sizeof(stack_hash));
if (task->_promise_stack_debug)
{
JSValue error = JS_ThrowInternalError(task->_context, "promise callstack");
@ -1262,16 +1265,17 @@ JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise)
JSValue stack_value = JS_GetPropertyStr(task->_context, exception, "stack");
size_t length = 0;
const char* stack = JS_ToCStringLen(task->_context, &length, stack_value);
stack_hash = tf_util_fnv32a((const void*)stack, (int)length, 0);
crypto_generichash_update(&state, (const void*)stack, (int)length);
void* buffer[31];
int count = tf_util_backtrace(buffer, sizeof(buffer) / sizeof(*buffer));
stack_hash = tf_util_fnv32a((const void*)buffer, sizeof(void*) * count, stack_hash);
crypto_generichash_update(&state, (const void*)buffer, sizeof(void*) * count);
_add_promise_stack(task, stack_hash, stack, buffer, count);
JS_FreeCString(task->_context, stack);
JS_FreeValue(task->_context, stack_value);
JS_FreeValue(task->_context, exception);
JS_FreeValue(task->_context, error);
}
crypto_generichash_final(&state, (void*)&stack_hash, sizeof(stack_hash));
promiseid_t promise_id;
do

View File

@ -400,6 +400,10 @@ static const setting_t k_settings[] = {
{ .name = "autologin", .type = "boolean", .description = "Whether mobile autologin is supported.", .default_value = { .kind = k_kind_bool, .bool_value = TF_IS_MOBILE != 0 } },
{ .name = "broadcast", .type = "boolean", .description = "Send network discovery broadcasts.", .default_value = { .kind = k_kind_bool, .bool_value = true } },
{ .name = "discovery", .type = "boolean", .description = "Receive network discovery broadcasts.", .default_value = { .kind = k_kind_bool, .bool_value = true } },
{ .name = "stay_connected",
.type = "boolean",
.description = "Whether to attempt to keep several peer connections open.",
.default_value = { .kind = k_kind_bool, .bool_value = false } },
};
static const setting_t* _util_get_setting(const char* name, tf_setting_kind_t kind)
@ -691,17 +695,6 @@ bool tf_util_is_mobile()
return TF_IS_MOBILE != 0;
}
uint32_t tf_util_fnv32a(const void* buffer, int length, uint32_t start)
{
uint32_t result = 0x811c9dc5;
for (int i = 0; i < length; i++)
{
result ^= ((const uint8_t*)buffer)[i];
result += (result << 1) + (result << 4) + (result << 7) + (result << 8) + (result << 24);
}
return result;
}
size_t tf_string_set(char* buffer, size_t size, const char* string)
{
size_t length = string ? strlen(string) : 0;

View File

@ -224,15 +224,6 @@ void tf_util_document_settings(const char* line_prefix);
*/
bool tf_util_is_mobile();
/**
** Compute a 32-bit hash of a buffer.
** @param buffer The data.
** @param length The size of the buffer in bytes.
** @param start The hash seed.
** @return The computed hash.
*/
uint32_t tf_util_fnv32a(const void* buffer, int length, uint32_t start);
/**
** Populate a string buffer, truncating if necessary.
** @param buffer The buffer.

View File

@ -1,2 +1,2 @@
#define VERSION_NUMBER "0.0.32"
#define VERSION_NUMBER "0.0.33-wip"
#define VERSION_NAME "This program kills fascists."