Minor cleanups.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3672 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2021-10-24 19:23:21 +00:00
parent f4f6bb8333
commit 08e32c0de4
5 changed files with 12 additions and 20 deletions

View File

@ -25,9 +25,9 @@
#include <time.h>
#include <uv.h>
static_assert(ID_BASE64_LEN == sodium_base64_ENCODED_LEN(9 + crypto_box_PUBLICKEYBYTES, sodium_base64_VARIANT_ORIGINAL), "ID_BASE64_LEN");
static_assert(ID_BIN_LEN == crypto_box_PUBLICKEYBYTES, "ID_BIN_LEN");
static_assert(BLOB_ID_LEN == (sodium_base64_ENCODED_LEN(crypto_hash_sha256_BYTES, sodium_base64_VARIANT_ORIGINAL) + 8), "BLOB_ID_LEN");
static_assert(k_id_base64_len == sodium_base64_ENCODED_LEN(9 + crypto_box_PUBLICKEYBYTES, sodium_base64_VARIANT_ORIGINAL), "k_id_base64_len");
static_assert(k_id_bin_len == crypto_box_PUBLICKEYBYTES, "k_id_bin_len");
static_assert(k_blob_id_len == (sodium_base64_ENCODED_LEN(crypto_hash_sha256_BYTES, sodium_base64_VARIANT_ORIGINAL) + 8), "k_blob_id_len");
const uint8_t k_ssb_network[] = {
0xd4, 0xa1, 0xcb, 0x88, 0xa6, 0x6f, 0x02, 0xf8,
@ -1981,7 +1981,7 @@ static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broad
}
}
char key[ID_BASE64_LEN];
char key[k_id_base64_len];
if (tf_ssb_id_bin_to_str(key, sizeof(key), broadcast->pub))
{
tf_ssb_connections_store(ssb->connections_tracker, broadcast->host, ntohs(broadcast->addr.sin_port), key);

View File

@ -26,7 +26,7 @@ static void _tf_ssb_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_change_t
{
case k_tf_ssb_change_create:
{
char key[ID_BASE64_LEN];
char key[k_id_base64_len];
if (tf_ssb_connection_get_host(connection) &&
*tf_ssb_connection_get_host(connection) &&
tf_ssb_connection_get_port(connection) &&
@ -39,7 +39,7 @@ static void _tf_ssb_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_change_t
break;
case k_tf_ssb_change_connect:
{
char key[ID_BASE64_LEN];
char key[k_id_base64_len];
if (tf_ssb_connection_get_id(connection, key, sizeof(key)))
{
tf_ssb_connections_set_succeeded(connections, tf_ssb_connection_get_host(connection), tf_ssb_connection_get_port(connection), key);
@ -83,10 +83,10 @@ static void _tf_ssb_connections_timer(uv_timer_t* timer)
{
char host[256];
int port;
char key[ID_BASE64_LEN];
char key[k_id_base64_len];
if (_tf_ssb_connections_get_next_connection(connections, host, sizeof(host), &port, key, sizeof(key)))
{
uint8_t key_bin[ID_BIN_LEN];
uint8_t key_bin[k_id_bin_len];
if (tf_ssb_id_str_to_bin(key_bin, key))
{
tf_ssb_connect(connections->ssb, host, port, key_bin);

View File

@ -117,7 +117,7 @@ bool tf_ssb_db_store_message(tf_ssb_t* ssb, JSContext* context, const char* id,
if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_int64(statement, 1, last_row_id) == SQLITE_OK &&
sqlite3_bind_int(statement, 2, BLOB_ID_LEN - 1) == SQLITE_OK)
sqlite3_bind_int(statement, 2, k_blob_id_len - 1) == SQLITE_OK)
{
int r = SQLITE_OK;
while ((r = sqlite3_step(statement)) == SQLITE_ROW)

View File

@ -5,10 +5,6 @@
#include <stddef.h>
#include <stdint.h>
#define ID_BASE64_LEN 57
#define ID_BIN_LEN 32
#define BLOB_ID_LEN 53
enum
{
k_ssb_rpc_flag_binary = 0x0,
@ -40,6 +36,7 @@ struct sockaddr_in;
enum {
k_id_base64_len = 57,
k_id_bin_len = 32,
k_blob_id_len = 53,
};
tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, sqlite3* db, const char* secrets_path);

View File

@ -1099,11 +1099,6 @@ JSValue _tf_task_sandbox_require(JSContext* context, JSValueConst this_val, int
return JS_UNDEFINED;
}
static JSValue _utf8Decode(JSContext* context, uint8_t* data, size_t length)
{
return JS_NewStringLen(context, (const char*)data, length);
}
static JSValue _tf_task_utf8Decode(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{
JSValue result = JS_NULL;
@ -1117,7 +1112,7 @@ static JSValue _tf_task_utf8Decode(JSContext* context, JSValueConst this_val, in
uint8_t* array = tf_try_get_array_buffer(context, &length, argv[0]);
if (array)
{
result = _utf8Decode(context, array, length);
result = JS_NewStringLen(context, (const char*)array, length);
}
else
{
@ -1130,7 +1125,7 @@ static JSValue _tf_task_utf8Decode(JSContext* context, JSValueConst this_val, in
array = tf_try_get_array_buffer(context, &size, buffer);
if (array)
{
result = _utf8Decode(context, array, size);
result = JS_NewStringLen(context, (const char*)array, size);
}
}
JS_FreeValue(context, buffer);