forked from cory/tildefriends
		
	More bugs.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3785 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		@@ -204,7 +204,7 @@ function ebtReplicateSendClock(request, have) {
 | 
			
		||||
	var message = {};
 | 
			
		||||
	var last_sent = request.connection.sent_clock || {};
 | 
			
		||||
	var ids = followingDeep(g_database, [me], 2).concat([request.connection.id]);
 | 
			
		||||
	if (!last_sent) {
 | 
			
		||||
	if (!Object.keys(last_sent).length) {
 | 
			
		||||
		for (let id of ids) {
 | 
			
		||||
			message[id] = get_latest_sequence_for_author(id);
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -1219,6 +1219,7 @@ void tf_ssb_connection_destroy(tf_ssb_connection_t* connection)
 | 
			
		||||
	}
 | 
			
		||||
	if (!JS_IsUndefined(connection->object))
 | 
			
		||||
	{
 | 
			
		||||
		JS_SetOpaque(connection->object, NULL);
 | 
			
		||||
		JS_FreeValue(ssb->context, connection->object);
 | 
			
		||||
		connection->object = JS_UNDEFINED;
 | 
			
		||||
	}
 | 
			
		||||
@@ -1884,6 +1885,7 @@ tf_ssb_connection_t* tf_ssb_connection_create(tf_ssb_t* ssb, const char* host, c
 | 
			
		||||
	uv_async_init(ssb->loop, &connection->async, _tf_ssb_connection_process_message_async);
 | 
			
		||||
 | 
			
		||||
	connection->object = JS_NewObjectClass(ssb->context, _connection_class_id);
 | 
			
		||||
	JS_SetOpaque(connection->object, connection);
 | 
			
		||||
	JS_SetPropertyStr(context, connection->object, "send_json", JS_NewCFunction(context, _tf_ssb_connection_send_json, "send_json", 2));
 | 
			
		||||
	char public_key_str[k_id_base64_len] = { 0 };
 | 
			
		||||
	if (tf_ssb_id_bin_to_str(public_key_str, sizeof(public_key_str), public_key))
 | 
			
		||||
@@ -1891,7 +1893,6 @@ tf_ssb_connection_t* tf_ssb_connection_create(tf_ssb_t* ssb, const char* host, c
 | 
			
		||||
		JS_SetPropertyStr(context, connection->object, "id", JS_NewString(context, public_key_str));
 | 
			
		||||
		JS_SetPropertyStr(context, connection->object, "is_client", JS_TRUE);
 | 
			
		||||
	}
 | 
			
		||||
	JS_SetOpaque(connection->object, connection);
 | 
			
		||||
 | 
			
		||||
	memcpy(connection->serverpub, public_key, sizeof(connection->serverpub));
 | 
			
		||||
 | 
			
		||||
@@ -1901,7 +1902,7 @@ tf_ssb_connection_t* tf_ssb_connection_create(tf_ssb_t* ssb, const char* host, c
 | 
			
		||||
	if (result)
 | 
			
		||||
	{
 | 
			
		||||
		printf("uv_tcp_connect(%s): %s\n", host, uv_strerror(result));
 | 
			
		||||
		JS_FreeValue(ssb->context, connection->object);
 | 
			
		||||
		tf_ssb_connection_destroy(connection);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
#include "ssb.db.h"
 | 
			
		||||
#include "ssb.js.h"
 | 
			
		||||
#include "tests.h"
 | 
			
		||||
#include "util.js.h"
 | 
			
		||||
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
@@ -10,6 +11,8 @@
 | 
			
		||||
#include <sqlite3.h>
 | 
			
		||||
#include <uv.h>
 | 
			
		||||
 | 
			
		||||
#include "quickjs-libc.h"
 | 
			
		||||
 | 
			
		||||
void tf_ssb_test_id_conversion(const tf_test_options_t* options)
 | 
			
		||||
{
 | 
			
		||||
	printf("Testing id conversion.\n");
 | 
			
		||||
@@ -74,6 +77,30 @@ static void _message_added(tf_ssb_t* ssb, const char* id, void* user_data)
 | 
			
		||||
	++*(int*)user_data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void _ssb_test_idle(uv_idle_t* idle)
 | 
			
		||||
{
 | 
			
		||||
	tf_ssb_t* ssb = idle->data;
 | 
			
		||||
	JSRuntime* runtime = JS_GetRuntime(tf_ssb_get_context(ssb));
 | 
			
		||||
	while (JS_IsJobPending(runtime))
 | 
			
		||||
	{
 | 
			
		||||
		JSContext* context = NULL;
 | 
			
		||||
		int r = JS_ExecutePendingJob(runtime, &context);
 | 
			
		||||
		JSValue result = JS_GetException(context);
 | 
			
		||||
		if (context)
 | 
			
		||||
		{
 | 
			
		||||
			tf_util_report_error(context, result);
 | 
			
		||||
		}
 | 
			
		||||
		if (r < 0)
 | 
			
		||||
		{
 | 
			
		||||
			js_std_dump_error(context);
 | 
			
		||||
		}
 | 
			
		||||
		else if (r == 0)
 | 
			
		||||
		{
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void tf_ssb_test_ssb(const tf_test_options_t* options)
 | 
			
		||||
{
 | 
			
		||||
	printf("Testing SSB.\n");
 | 
			
		||||
@@ -91,6 +118,14 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
 | 
			
		||||
	tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db1, NULL);
 | 
			
		||||
	tf_ssb_register(tf_ssb_get_context(ssb1), ssb1);
 | 
			
		||||
 | 
			
		||||
	uv_idle_t idle0 = { .data = ssb0 };
 | 
			
		||||
	uv_idle_init(&loop, &idle0);
 | 
			
		||||
	uv_idle_start(&idle0, _ssb_test_idle);
 | 
			
		||||
 | 
			
		||||
	uv_idle_t idle1 = { .data = ssb1 };
 | 
			
		||||
	uv_idle_init(&loop, &idle1);
 | 
			
		||||
	uv_idle_start(&idle1, _ssb_test_idle);
 | 
			
		||||
 | 
			
		||||
	test_t test = {
 | 
			
		||||
		.ssb0 = ssb0,
 | 
			
		||||
		.ssb1 = ssb1,
 | 
			
		||||
@@ -181,6 +216,9 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
 | 
			
		||||
 | 
			
		||||
	tf_ssb_send_close(ssb1);
 | 
			
		||||
 | 
			
		||||
	uv_close((uv_handle_t*)&idle0, NULL);
 | 
			
		||||
	uv_close((uv_handle_t*)&idle1, NULL);
 | 
			
		||||
 | 
			
		||||
	uv_run(&loop, UV_RUN_DEFAULT);
 | 
			
		||||
 | 
			
		||||
	tf_ssb_destroy(ssb0);
 | 
			
		||||
 
 | 
			
		||||
@@ -1382,8 +1382,10 @@ tf_task_t* tf_task_create()
 | 
			
		||||
	uv_unref((uv_handle_t*)&task->trace_timer);
 | 
			
		||||
	task->idle.data = task;
 | 
			
		||||
	uv_idle_init(&task->_loop, &task->idle);
 | 
			
		||||
	uv_unref((uv_handle_t*)&task->idle);
 | 
			
		||||
	task->prepare.data = task;
 | 
			
		||||
	uv_prepare_init(&task->_loop, &task->prepare);
 | 
			
		||||
	uv_unref((uv_handle_t*)&task->prepare);
 | 
			
		||||
	uv_idle_start(&task->idle, _tf_task_run_jobs_idle);
 | 
			
		||||
	return task;
 | 
			
		||||
}
 | 
			
		||||
@@ -1487,7 +1489,10 @@ void tf_task_activate(tf_task_t* task)
 | 
			
		||||
 | 
			
		||||
void tf_task_run(tf_task_t* task)
 | 
			
		||||
{
 | 
			
		||||
	uv_run(&task->_loop, UV_RUN_DEFAULT);
 | 
			
		||||
	do
 | 
			
		||||
	{
 | 
			
		||||
		uv_run(&task->_loop, UV_RUN_DEFAULT);
 | 
			
		||||
	} while (_tf_task_run_jobs(task));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void tf_task_set_trusted(tf_task_t* task, bool trusted)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user