Appending a message produces the ID. And bump the version.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4344 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-07-13 00:20:12 +00:00
parent c4a2d790a3
commit 18128303b6
7 changed files with 29 additions and 16 deletions

View File

@ -3,9 +3,9 @@
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
VERSION_CODE := 8
VERSION_NUMBER := 0.0.8
VERSION_NAME := The secret ingredient is love.
VERSION_CODE := 9
VERSION_NUMBER := 0.0.9-wip
VERSION_NAME := Failure is the only opportunity to begin again.
PROJECT = tildefriends
BUILD_DIR ?= out

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"
versionCode="8"
versionName="0.0.8">
versionCode="9"
versionName="0.0.9">
<uses-sdk android:minSdkVersion="26"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="Tilde Friends" android:usesCleartextTraffic="true" android:debuggable="true">

View File

@ -1666,7 +1666,7 @@ static bool _tf_ssb_connection_box_stream_recv(tf_ssb_connection_t* connection)
return true;
}
void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message)
bool tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message, char* out_id, size_t out_id_size)
{
char previous_id[crypto_hash_sha256_BYTES * 2];
int64_t previous_sequence = 0;
@ -1718,12 +1718,15 @@ void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const ui
JS_FreeCString(context, json);
JS_FreeValue(context, jsonval);
bool stored = false;
char id[sodium_base64_ENCODED_LEN(crypto_hash_sha256_BYTES, sodium_base64_VARIANT_ORIGINAL) + 7 + 1];
if (valid && tf_ssb_verify_and_strip_signature(ssb->context, root, id, sizeof(id), NULL, 0, NULL))
{
if (tf_ssb_db_store_message(ssb, ssb->context, id, root, signature_base64, false))
{
tf_ssb_notify_message_added(ssb, id);
snprintf(out_id, out_id_size, "%s", id);
stored = true;
}
else
{
@ -1735,7 +1738,13 @@ void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const ui
tf_printf("Failed to verify message signature.\n");
}
if (!stored && out_id && out_id_size)
{
*out_id = '\0';
}
JS_FreeValue(context, root);
return stored;
}
static void _tf_ssb_connection_dispatch_scheduled(tf_ssb_connection_t* connection)

View File

@ -87,7 +87,7 @@ JSContext* tf_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);
void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message);
bool tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message, char* out_id, size_t out_id_size);
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_connection_t* tunnel, const uint8_t* pub, void* user_data), void* user_data);

View File

@ -118,7 +118,9 @@ static JSValue _tf_ssb_appendMessageWithIdentity(JSContext* context, JSValueCons
uint8_t private_key[crypto_sign_SECRETKEYBYTES];
if (tf_ssb_db_identity_get_private_key(ssb, user, id, private_key, sizeof(private_key)))
{
tf_ssb_append_message_with_keys(ssb, id, private_key, argv[2]);
char id[k_id_base64_len] = { 0 };
tf_ssb_append_message_with_keys(ssb, id, private_key, argv[2], id, sizeof(id));
result = JS_NewString(context, id);
}
else
{

View File

@ -170,17 +170,19 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
b = tf_ssb_db_blob_store(ssb0, (const uint8_t*)k_blob, strlen(k_blob), blob_id, sizeof(blob_id), NULL);
assert(b);
char message_id[k_id_base64_len] = { 0 };
JSContext* context0 = tf_ssb_get_context(ssb0);
JSValue obj = JS_NewObject(context0);
JS_SetPropertyStr(context0, obj, "type", JS_NewString(context0, "post"));
JS_SetPropertyStr(context0, obj, "text", JS_NewString(context0, "Hello, world!"));
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj);
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj, message_id, sizeof(message_id));
JS_FreeValue(context0, obj);
printf("appended %s\n", message_id);
obj = JS_NewObject(context0);
JS_SetPropertyStr(context0, obj, "type", JS_NewString(context0, "post"));
JS_SetPropertyStr(context0, obj, "text", JS_NewString(context0, "First post."));
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj);
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj, NULL, 0);
JS_FreeValue(context0, obj);
obj = JS_NewObject(context0);
@ -191,7 +193,7 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
JS_SetPropertyStr(context0, mention, "link", JS_NewString(context0, blob_id));
JS_SetPropertyUint32(context0, mentions, 0, mention);
JS_SetPropertyStr(context0, obj, "mentions", mentions);
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj);
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj, NULL, 0);
JS_FreeValue(context0, obj);
uint8_t* b0;
@ -247,7 +249,7 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
obj = JS_NewObject(context0);
JS_SetPropertyStr(context0, obj, "type", JS_NewString(context0, "post"));
JS_SetPropertyStr(context0, obj, "text", JS_NewString(context0, "Message to self."));
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj);
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj, NULL, 0);
JS_FreeValue(context0, obj);
while (count0 == 0)
@ -497,7 +499,7 @@ void tf_ssb_test_following(const tf_test_options_t* options)
JS_SetPropertyStr(context, message, "type", JS_NewString(context, "contact")); \
JS_SetPropertyStr(context, message, "contact", JS_NewString(context, id)); \
JS_SetPropertyStr(context, message, "following", follow ? JS_TRUE : JS_FALSE); \
tf_ssb_append_message_with_keys(ssb, id, priv, message); \
tf_ssb_append_message_with_keys(ssb, id, priv, message, NULL, 0); \
JS_FreeValue(context, message); \
context = NULL
@ -573,7 +575,7 @@ void tf_ssb_test_bench(const tf_test_options_t* options)
JS_SetPropertyStr(tf_ssb_get_context(ssb0), obj, "text", JS_NewString(tf_ssb_get_context(ssb0), "Hello, world!"));
for (int i = 0; i < k_messages; i++)
{
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj);
tf_ssb_append_message_with_keys(ssb0, id0, priv0, obj, NULL, 0);
}
JS_FreeValue(tf_ssb_get_context(ssb0), obj);
clock_gettime(CLOCK_REALTIME, &end_time);

View File

@ -1,3 +1,3 @@
#define VERSION_NUMBER "0.0.8"
#define VERSION_NAME "The secret ingredient is love."
#define VERSION_NUMBER "0.0.9-wip"
#define VERSION_NAME "Failure is the only opportunity to begin again."