forked from cory/tildefriends
		
	No more secrets in ~/.config, and speed up some tests.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4002 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		
							
								
								
									
										14
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/main.c
									
									
									
									
									
								
							| @@ -213,7 +213,7 @@ static int _tf_command_import(const char* file, int argc, char* argv[]) | |||||||
| 	{ | 	{ | ||||||
| 		sqlite3_open(args.db_path, &db); | 		sqlite3_open(args.db_path, &db); | ||||||
| 	} | 	} | ||||||
| 	tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db, NULL); | 	tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db); | ||||||
| 	if (extra_count) | 	if (extra_count) | ||||||
| 	{ | 	{ | ||||||
| 		for (int i = 0; i < extra_count; i++) | 		for (int i = 0; i < extra_count; i++) | ||||||
| @@ -280,7 +280,7 @@ static int _tf_command_export(const char* file, int argc, char* argv[]) | |||||||
| 	{ | 	{ | ||||||
| 		sqlite3_open(args.db_path, &db); | 		sqlite3_open(args.db_path, &db); | ||||||
| 	} | 	} | ||||||
| 	tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db, NULL); | 	tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db); | ||||||
| 	if (extra_count) | 	if (extra_count) | ||||||
| 	{ | 	{ | ||||||
| 		for (int i = 0; i < extra_count; i++) | 		for (int i = 0; i < extra_count; i++) | ||||||
| @@ -333,7 +333,6 @@ typedef struct tf_run_args_t { | |||||||
| 	int http_port; | 	int http_port; | ||||||
| 	int https_port; | 	int https_port; | ||||||
| 	const char* db_path; | 	const char* db_path; | ||||||
| 	const char* secrets_path; |  | ||||||
| 	int count; | 	int count; | ||||||
| 	const char* args; | 	const char* args; | ||||||
| 	bool help; | 	bool help; | ||||||
| @@ -356,18 +355,13 @@ static int _tf_run_task(const tf_run_args_t* args, int index) | |||||||
| 	tf_task_set_https_port(task, args->https_port ? args->https_port + index : 0); | 	tf_task_set_https_port(task, args->https_port ? args->https_port + index : 0); | ||||||
| 	tf_task_set_args(task, args->args); | 	tf_task_set_args(task, args->args); | ||||||
| 	const char* db_path = args->db_path; | 	const char* db_path = args->db_path; | ||||||
| 	const char* secrets_path = args->secrets_path; |  | ||||||
| 	char db_path_buffer[256]; | 	char db_path_buffer[256]; | ||||||
| 	char secrets_path_buffer[256]; |  | ||||||
| 	if (index) | 	if (index) | ||||||
| 	{ | 	{ | ||||||
| 		snprintf(db_path_buffer, sizeof(db_path_buffer), "%s.%d", args->db_path, index); | 		snprintf(db_path_buffer, sizeof(db_path_buffer), "%s.%d", args->db_path, index); | ||||||
| 		db_path = db_path_buffer; | 		db_path = db_path_buffer; | ||||||
| 		snprintf(secrets_path_buffer, sizeof(secrets_path_buffer), "%s.%d", args->secrets_path, index); |  | ||||||
| 		secrets_path = secrets_path_buffer; |  | ||||||
| 	} | 	} | ||||||
| 	tf_task_set_db_path(task, db_path); | 	tf_task_set_db_path(task, db_path); | ||||||
| 	tf_task_set_secrets_path(task, secrets_path); |  | ||||||
| 	tf_task_activate(task); | 	tf_task_activate(task); | ||||||
| 	if (args->ssb_port) | 	if (args->ssb_port) | ||||||
| 	{ | 	{ | ||||||
| @@ -396,7 +390,6 @@ static int _tf_command_run(const char* file, int argc, char* argv[]) | |||||||
| 		{ "http-port", 'p', offsetof(tf_run_args_t, http_port), NULL, XOPT_TYPE_INT, NULL, "Port on which to run Tilde Friends web server (default: 12345)." }, | 		{ "http-port", 'p', offsetof(tf_run_args_t, http_port), NULL, XOPT_TYPE_INT, NULL, "Port on which to run Tilde Friends web server (default: 12345)." }, | ||||||
| 		{ "https-port", 'q', offsetof(tf_run_args_t, https_port), NULL, XOPT_TYPE_INT, NULL, "Port on which to run secure Tilde Friends web server (default: 12346)." }, | 		{ "https-port", 'q', offsetof(tf_run_args_t, https_port), NULL, XOPT_TYPE_INT, NULL, "Port on which to run secure Tilde Friends web server (default: 12346)." }, | ||||||
| 		{ "db-path", 'd', offsetof(tf_run_args_t, db_path), NULL, XOPT_TYPE_STRING, NULL, "Sqlite database path (default: db.sqlite)." }, | 		{ "db-path", 'd', offsetof(tf_run_args_t, db_path), NULL, XOPT_TYPE_STRING, NULL, "Sqlite database path (default: db.sqlite)." }, | ||||||
| 		{ "secrets-path", 'i', offsetof(tf_run_args_t, secrets_path), NULL, XOPT_TYPE_STRING, NULL, "Secrets/identity path." }, |  | ||||||
| 		{ "count", 'n', offsetof(tf_run_args_t, count), NULL, XOPT_TYPE_INT, NULL, "Number of instances to run." }, | 		{ "count", 'n', offsetof(tf_run_args_t, count), NULL, XOPT_TYPE_INT, NULL, "Number of instances to run." }, | ||||||
| 		{ "args", 'a', offsetof(tf_run_args_t, args), NULL, XOPT_TYPE_STRING, NULL, "Arguments of the form key=value,foo=bar,verbose=true." }, | 		{ "args", 'a', offsetof(tf_run_args_t, args), NULL, XOPT_TYPE_STRING, NULL, "Arguments of the form key=value,foo=bar,verbose=true." }, | ||||||
| 		{ "help", 'h', offsetof(tf_run_args_t, help), NULL, XOPT_TYPE_BOOL, NULL, "Shows this help message." }, | 		{ "help", 'h', offsetof(tf_run_args_t, help), NULL, XOPT_TYPE_BOOL, NULL, "Shows this help message." }, | ||||||
| @@ -411,7 +404,6 @@ static int _tf_command_run(const char* file, int argc, char* argv[]) | |||||||
| 		.https_port = 12346, | 		.https_port = 12346, | ||||||
| 		.ssb_port = 8009, | 		.ssb_port = 8009, | ||||||
| 		.db_path = "db.sqlite", | 		.db_path = "db.sqlite", | ||||||
| 		.secrets_path = "/.config/tildefriends/secret", |  | ||||||
| 	}; | 	}; | ||||||
| 	const char** extras = NULL; | 	const char** extras = NULL; | ||||||
| 	int extra_count = 0; | 	int extra_count = 0; | ||||||
| @@ -555,7 +547,7 @@ static int _tf_command_post(const char* file, int argc, char* argv[]) | |||||||
| 		return 2; | 		return 2; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, NULL, NULL); | 	tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, NULL); | ||||||
| 	tf_ssb_broadcast_listener_start(ssb, false); | 	tf_ssb_broadcast_listener_start(ssb, false); | ||||||
| 	tf_ssb_append_post(ssb, args.message); | 	tf_ssb_append_post(ssb, args.message); | ||||||
| 	tf_ssb_destroy(ssb); | 	tf_ssb_destroy(ssb); | ||||||
|   | |||||||
							
								
								
									
										156
									
								
								src/ssb.c
									
									
									
									
									
								
							
							
						
						
									
										156
									
								
								src/ssb.c
									
									
									
									
									
								
							| @@ -39,8 +39,6 @@ const uint8_t k_ssb_network[] = { | |||||||
| 	0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb | 	0x08, 0x39, 0xb7, 0x55, 0x84, 0x5a, 0x9f, 0xfb | ||||||
| }; | }; | ||||||
|  |  | ||||||
| const char* k_secrets_path = "/.config/tildefriends/secret"; |  | ||||||
|  |  | ||||||
| typedef enum { | typedef enum { | ||||||
| 	k_tf_ssb_state_invalid, | 	k_tf_ssb_state_invalid, | ||||||
| 	k_tf_ssb_state_connected, | 	k_tf_ssb_state_connected, | ||||||
| @@ -138,8 +136,6 @@ typedef struct _tf_ssb_t | |||||||
| 	sqlite3* db; | 	sqlite3* db; | ||||||
| 	bool owns_db; | 	bool owns_db; | ||||||
|  |  | ||||||
| 	const char* secrets_path; |  | ||||||
|  |  | ||||||
| 	uv_loop_t own_loop; | 	uv_loop_t own_loop; | ||||||
| 	uv_loop_t* loop; | 	uv_loop_t* loop; | ||||||
| 	uv_udp_t broadcast_listener; | 	uv_udp_t broadcast_listener; | ||||||
| @@ -1367,7 +1363,6 @@ void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const char* rea | |||||||
| 	} | 	} | ||||||
| 	while (connection->requests) | 	while (connection->requests) | ||||||
| 	{ | 	{ | ||||||
| 		printf("%d %d\n", connection->requests_count, connection->requests->request_number); |  | ||||||
| 		_tf_ssb_connection_remove_request(connection, connection->requests->request_number); | 		_tf_ssb_connection_remove_request(connection, connection->requests->request_number); | ||||||
| 	} | 	} | ||||||
| 	if (!JS_IsUndefined(connection->object)) | 	if (!JS_IsUndefined(connection->object)) | ||||||
| @@ -1551,139 +1546,22 @@ static void _tf_ssb_connection_on_connect(uv_connect_t* connect, int status) | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static void _load_keys_callback(const char* identity, void* user_data) | ||||||
|  | { | ||||||
|  | 	tf_ssb_t* ssb = user_data; | ||||||
|  | 	if (*ssb->pub) | ||||||
|  | 	{ | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	tf_ssb_id_str_to_bin(ssb->pub, identity); | ||||||
|  | 	tf_ssb_db_identity_get_private_key(ssb, ":admin", identity, ssb->priv, sizeof(ssb->priv)); | ||||||
|  | } | ||||||
|  |  | ||||||
| static bool _tf_ssb_load_keys(tf_ssb_t* ssb) | static bool _tf_ssb_load_keys(tf_ssb_t* ssb) | ||||||
| { | { | ||||||
| 	const char* home = getenv("HOME"); | 	tf_ssb_db_identity_visit(ssb, ":admin", _load_keys_callback, ssb); | ||||||
| 	if (!home) | 	return *ssb->pub != '\0' && *ssb->priv != '\0'; | ||||||
| 	{ |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	bool result = false; |  | ||||||
| 	char* json = NULL; |  | ||||||
| 	size_t path_size = strlen(home) + strlen(ssb->secrets_path) + 1; |  | ||||||
| 	char* path = tf_malloc(path_size); |  | ||||||
| 	snprintf(path, path_size, "%s%s", home, ssb->secrets_path); |  | ||||||
|  |  | ||||||
| 	FILE* file = fopen(path, "rb"); |  | ||||||
| 	if (!file) |  | ||||||
| 	{ |  | ||||||
| 		printf("Failed to open %s: %s.\n", path, strerror(errno)); |  | ||||||
| 		goto failed; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if (fseek(file, 0, SEEK_END) != 0) |  | ||||||
| 	{ |  | ||||||
| 		printf("Failed to seek %s: %s\n.", path, strerror(errno)); |  | ||||||
| 		goto failed; |  | ||||||
| 	} |  | ||||||
| 	long len = ftell(file); |  | ||||||
| 	if (len < 0 || |  | ||||||
| 		fseek(file, 0, SEEK_SET) != 0) |  | ||||||
| 	{ |  | ||||||
| 		printf("Failed to seek %s: %s\n.", path, strerror(errno)); |  | ||||||
| 		goto failed; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	json = tf_malloc(len + 1); |  | ||||||
| 	if (fread(json, 1, len, file) != (size_t)len) |  | ||||||
| 	{ |  | ||||||
| 		printf("Failed to read %s: %s\n.", path, strerror(errno)); |  | ||||||
| 		goto failed; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	json[len] = '\0'; |  | ||||||
|  |  | ||||||
| 	JSContext* context = ssb->context; |  | ||||||
| 	JSValue root = JS_ParseJSON(context, (const char*)json, len, NULL); |  | ||||||
|  |  | ||||||
| 	JSValue pubvalue = JS_GetPropertyStr(context, root, "public"); |  | ||||||
| 	size_t pubstrlen = 0; |  | ||||||
| 	const char* pubstr = JS_ToCStringLen(context, &pubstrlen, pubvalue); |  | ||||||
| 	size_t privstrlen = 0; |  | ||||||
| 	JSValue privvalue = JS_GetPropertyStr(context, root, "private"); |  | ||||||
| 	const char* privstr = JS_ToCStringLen(context, &privstrlen, privvalue); |  | ||||||
|  |  | ||||||
| 	if (pubstr && privstr) |  | ||||||
| 	{ |  | ||||||
| 		result = |  | ||||||
| 			base64c_decode((const uint8_t*)pubstr, pubstrlen - strlen(".ed25519"), ssb->pub, sizeof(ssb->pub)) != 0 && |  | ||||||
| 			base64c_decode((const uint8_t*)privstr, privstrlen - strlen(".ed25519"), ssb->priv, sizeof(ssb->priv)) != 0; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	JS_FreeCString(context, pubstr); |  | ||||||
| 	JS_FreeCString(context, privstr); |  | ||||||
|  |  | ||||||
| 	JS_FreeValue(context, pubvalue); |  | ||||||
| 	JS_FreeValue(context, privvalue); |  | ||||||
|  |  | ||||||
| 	JS_FreeValue(context, root); |  | ||||||
|  |  | ||||||
| failed: |  | ||||||
| 	if (json) |  | ||||||
| 	{ |  | ||||||
| 		tf_free(json); |  | ||||||
| 	} |  | ||||||
| 	if (file) |  | ||||||
| 	{ |  | ||||||
| 		fclose(file); |  | ||||||
| 	} |  | ||||||
| 	if (path) |  | ||||||
| 	{ |  | ||||||
| 		tf_free(path); |  | ||||||
| 	} |  | ||||||
| 	return result; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static bool _tf_ssb_save_keys(tf_ssb_t* ssb) |  | ||||||
| { |  | ||||||
| 	bool result = false; |  | ||||||
| 	char private_base64[crypto_sign_SECRETKEYBYTES * 2]; |  | ||||||
| 	char public_base64[crypto_sign_PUBLICKEYBYTES * 2]; |  | ||||||
| 	char private[crypto_sign_SECRETKEYBYTES * 2 + 16]; |  | ||||||
| 	char public[crypto_sign_PUBLICKEYBYTES * 2 + 16]; |  | ||||||
| 	char id[crypto_sign_PUBLICKEYBYTES * 2 + 16]; |  | ||||||
| 	base64c_encode(ssb->pub, sizeof(ssb->pub), (uint8_t*)public_base64, sizeof(public_base64)); |  | ||||||
| 	base64c_encode(ssb->priv, sizeof(ssb->priv), (uint8_t*)private_base64, sizeof(private_base64)); |  | ||||||
|  |  | ||||||
| 	snprintf(private, sizeof(private), "%s.ed25519", private_base64); |  | ||||||
| 	snprintf(public, sizeof(public), "%s.ed25519", public_base64); |  | ||||||
| 	snprintf(id, sizeof(id), "@%s.ed25519", public_base64); |  | ||||||
|  |  | ||||||
| 	const char* home = getenv("HOME"); |  | ||||||
| 	if (!home) |  | ||||||
| 	{ |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	size_t path_size = strlen(home) + strlen(ssb->secrets_path) + 1; |  | ||||||
| 	char* path = tf_malloc(path_size); |  | ||||||
| 	snprintf(path, path_size, "%s%s", home, ssb->secrets_path); |  | ||||||
|  |  | ||||||
| 	JSContext* context = ssb->context; |  | ||||||
| 	JSValue root = JS_NewObject(context); |  | ||||||
| 	JS_SetPropertyStr(context, root, "curve", JS_NewString(context, "ed25519")); |  | ||||||
| 	JS_SetPropertyStr(context, root, "public", JS_NewString(context, public)); |  | ||||||
| 	JS_SetPropertyStr(context, root, "private", JS_NewString(context, private)); |  | ||||||
| 	JS_SetPropertyStr(context, root, "id", JS_NewString(context, id)); |  | ||||||
|  |  | ||||||
| 	JSValue jsonval = JS_JSONStringify(context, root, JS_NULL, JS_NewInt32(context, 2)); |  | ||||||
| 	size_t len = 0; |  | ||||||
| 	const char* json = JS_ToCStringLen(context, &len, jsonval); |  | ||||||
|  |  | ||||||
| 	FILE* file = fopen(path, "wb"); |  | ||||||
| 	if (file) |  | ||||||
| 	{ |  | ||||||
| 		result = fwrite(json, 1, len, file) == len; |  | ||||||
| 		fclose(file); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	JS_FreeCString(context, json); |  | ||||||
| 	JS_FreeValue(context, jsonval); |  | ||||||
| 	JS_FreeValue(context, root); |  | ||||||
|  |  | ||||||
| 	tf_free(path); |  | ||||||
| 	return result; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static void _tf_ssb_trace_timer(uv_timer_t* timer) | static void _tf_ssb_trace_timer(uv_timer_t* timer) | ||||||
| @@ -1738,11 +1616,10 @@ void tf_ssb_get_stats(tf_ssb_t* ssb, tf_ssb_stats_t* out_stats) | |||||||
| 	ssb->rpc_out = 0; | 	ssb->rpc_out = 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, sqlite3* db, const char* secrets_path) | tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, sqlite3* db) | ||||||
| { | { | ||||||
| 	tf_ssb_t* ssb = tf_malloc(sizeof(tf_ssb_t)); | 	tf_ssb_t* ssb = tf_malloc(sizeof(tf_ssb_t)); | ||||||
| 	memset(ssb, 0, sizeof(*ssb)); | 	memset(ssb, 0, sizeof(*ssb)); | ||||||
| 	ssb->secrets_path = secrets_path ? secrets_path : k_secrets_path; |  | ||||||
| 	if (context) | 	if (context) | ||||||
| 	{ | 	{ | ||||||
| 		ssb->context = context; | 		ssb->context = context; | ||||||
| @@ -1805,8 +1682,7 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, sqlite3* db, const | |||||||
| 	if (!_tf_ssb_load_keys(ssb)) | 	if (!_tf_ssb_load_keys(ssb)) | ||||||
| 	{ | 	{ | ||||||
| 		printf("Generating a new keypair.\n"); | 		printf("Generating a new keypair.\n"); | ||||||
| 		tf_ssb_generate_keys(ssb); | 		tf_ssb_db_identity_create(ssb, ":admin", ssb->pub, ssb->priv); | ||||||
| 		_tf_ssb_save_keys(ssb); |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	ssb->connections_tracker = tf_ssb_connections_create(ssb); | 	ssb->connections_tracker = tf_ssb_connections_create(ssb); | ||||||
|   | |||||||
							
								
								
									
										18
									
								
								src/ssb.db.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/ssb.db.c
									
									
									
									
									
								
							| @@ -815,6 +815,24 @@ int tf_ssb_db_identity_get_count_for_user(tf_ssb_t* ssb, const char* user) | |||||||
| 	return count; | 	return count; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | bool tf_ssb_db_identity_create(tf_ssb_t* ssb, const char* user, uint8_t* out_public_key, uint8_t* out_private_key) | ||||||
|  | { | ||||||
|  | 	int count = tf_ssb_db_identity_get_count_for_user(ssb, user); | ||||||
|  | 	if (count < 16) | ||||||
|  | 	{ | ||||||
|  | 		char public[512]; | ||||||
|  | 		char private[512]; | ||||||
|  | 		tf_ssb_generate_keys_buffer(public, sizeof(public), private, sizeof(private)); | ||||||
|  | 		if (tf_ssb_db_identity_add(ssb, user, public, private)) | ||||||
|  | 		{ | ||||||
|  | 			tf_ssb_id_str_to_bin(out_public_key, public); | ||||||
|  | 			tf_ssb_id_str_to_bin(out_private_key, private);  | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return false; | ||||||
|  | } | ||||||
|  |  | ||||||
| bool tf_ssb_db_identity_add(tf_ssb_t* ssb, const char* user, const char* public_key, const char* private_key) | bool tf_ssb_db_identity_add(tf_ssb_t* ssb, const char* user, const char* public_key, const char* private_key) | ||||||
| { | { | ||||||
| 	bool added = false; | 	bool added = false; | ||||||
|   | |||||||
| @@ -19,6 +19,7 @@ typedef struct sqlite3 sqlite3; | |||||||
| bool tf_ssb_db_check(sqlite3* db, const char* author); | bool tf_ssb_db_check(sqlite3* db, const char* author); | ||||||
|  |  | ||||||
| int tf_ssb_db_identity_get_count_for_user(tf_ssb_t* ssb, const char* user); | int tf_ssb_db_identity_get_count_for_user(tf_ssb_t* ssb, const char* user); | ||||||
|  | bool tf_ssb_db_identity_create(tf_ssb_t* ssb, const char* user, uint8_t* out_public_key, uint8_t* out_private_key); | ||||||
| bool tf_ssb_db_identity_add(tf_ssb_t* ssb, const char* user, const char* public_key, const char* private_key); | bool tf_ssb_db_identity_add(tf_ssb_t* ssb, const char* user, const char* public_key, const char* private_key); | ||||||
| void tf_ssb_db_identity_visit(tf_ssb_t* ssb, const char* user, void (*callback)(const char* identity, void* user_data), void* user_data); | void tf_ssb_db_identity_visit(tf_ssb_t* ssb, const char* user, void (*callback)(const char* identity, void* user_data), void* user_data); | ||||||
| void tf_ssb_db_identity_visit_all(tf_ssb_t* ssb, void (*callback)(const char* identity, void* user_data), void* user_data); | void tf_ssb_db_identity_visit_all(tf_ssb_t* ssb, void (*callback)(const char* identity, void* user_data), void* user_data); | ||||||
|   | |||||||
| @@ -57,7 +57,7 @@ typedef struct _tf_ssb_stats_t | |||||||
| 	} callbacks; | 	} callbacks; | ||||||
| } tf_ssb_stats_t; | } tf_ssb_stats_t; | ||||||
|  |  | ||||||
| tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, sqlite3* db, const char* secrets_path); | tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, sqlite3* db); | ||||||
| void tf_ssb_destroy(tf_ssb_t* ssb); | void tf_ssb_destroy(tf_ssb_t* ssb); | ||||||
|  |  | ||||||
| sqlite3* tf_ssb_get_db(tf_ssb_t* ssb); | sqlite3* tf_ssb_get_db(tf_ssb_t* ssb); | ||||||
| @@ -71,11 +71,13 @@ tf_trace_t* tf_ssb_get_trace(tf_ssb_t* ssb); | |||||||
|  |  | ||||||
| JSContext* tf_ssb_get_context(tf_ssb_t* ssb); | JSContext* tf_ssb_get_context(tf_ssb_t* ssb); | ||||||
|  |  | ||||||
|  | /* TODO: Delete. */ | ||||||
|  | void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message); | ||||||
|  | void tf_ssb_append_post(tf_ssb_t* ssb, const char* text); | ||||||
|  |  | ||||||
| void tf_ssb_broadcast_listener_start(tf_ssb_t* ssb, bool linger); | void tf_ssb_broadcast_listener_start(tf_ssb_t* ssb, bool linger); | ||||||
| void tf_ssb_run(tf_ssb_t* ssb); | void tf_ssb_run(tf_ssb_t* ssb); | ||||||
| void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message); |  | ||||||
| void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message); | void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message); | ||||||
| void tf_ssb_append_post(tf_ssb_t* ssb, const char* text); |  | ||||||
| bool tf_ssb_whoami(tf_ssb_t* ssb, 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 struct sockaddr_in* addr, const uint8_t* pub, void* user_data), void* user_data); | void tf_ssb_visit_broadcasts(tf_ssb_t* ssb, void (*callback)(const struct sockaddr_in* addr, const uint8_t* pub, void* user_data), void* user_data); | ||||||
|   | |||||||
| @@ -121,9 +121,9 @@ void tf_ssb_test_ssb(const tf_test_options_t* options) | |||||||
| 	uv_loop_t loop = { 0 }; | 	uv_loop_t loop = { 0 }; | ||||||
| 	uv_loop_init(&loop); | 	uv_loop_init(&loop); | ||||||
|  |  | ||||||
| 	tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, db0, NULL); | 	tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, db0); | ||||||
| 	tf_ssb_register(tf_ssb_get_context(ssb0), ssb0); | 	tf_ssb_register(tf_ssb_get_context(ssb0), ssb0); | ||||||
| 	tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db1, NULL); | 	tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db1); | ||||||
| 	tf_ssb_register(tf_ssb_get_context(ssb1), ssb1); | 	tf_ssb_register(tf_ssb_get_context(ssb1), ssb1); | ||||||
|  |  | ||||||
| 	uv_idle_t idle0 = { .data = ssb0 }; | 	uv_idle_t idle0 = { .data = ssb0 }; | ||||||
| @@ -251,13 +251,13 @@ void tf_ssb_test_following(const tf_test_options_t* options) | |||||||
| 	uv_loop_t loop = { 0 }; | 	uv_loop_t loop = { 0 }; | ||||||
| 	uv_loop_init(&loop); | 	uv_loop_init(&loop); | ||||||
|  |  | ||||||
| 	tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, db0, NULL); | 	tf_ssb_t* ssb0 = tf_ssb_create(&loop, NULL, db0); | ||||||
| 	tf_ssb_generate_keys(ssb0); | 	tf_ssb_generate_keys(ssb0); | ||||||
|  |  | ||||||
| 	tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db0, NULL); | 	tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, db0); | ||||||
| 	tf_ssb_generate_keys(ssb1); | 	tf_ssb_generate_keys(ssb1); | ||||||
|  |  | ||||||
| 	tf_ssb_t* ssb2 = tf_ssb_create(&loop, NULL, db0, NULL); | 	tf_ssb_t* ssb2 = tf_ssb_create(&loop, NULL, db0); | ||||||
| 	tf_ssb_generate_keys(ssb2); | 	tf_ssb_generate_keys(ssb2); | ||||||
|  |  | ||||||
| 	char id0[k_id_base64_len] = { 0 }; | 	char id0[k_id_base64_len] = { 0 }; | ||||||
|   | |||||||
| @@ -121,7 +121,6 @@ typedef struct _tf_task_t | |||||||
| 	int _http_port; | 	int _http_port; | ||||||
| 	int _https_port; | 	int _https_port; | ||||||
| 	char _db_path[256]; | 	char _db_path[256]; | ||||||
| 	char _secrets_path[256]; |  | ||||||
| 	const char* _args; | 	const char* _args; | ||||||
|  |  | ||||||
| 	promise_stack_t* _promise_stacks; | 	promise_stack_t* _promise_stacks; | ||||||
| @@ -851,7 +850,6 @@ const char* _tf_task_get_message_type(tf_task_message_t type) | |||||||
| 	case kInvokeExport: return "kInvokeExport"; | 	case kInvokeExport: return "kInvokeExport"; | ||||||
| 	case kReleaseExport: return "kReleaseExport"; | 	case kReleaseExport: return "kReleaseExport"; | ||||||
| 	case kReleaseImport: return "kReleaseImport"; | 	case kReleaseImport: return "kReleaseImport"; | ||||||
| 	case kSetRequires: return "kSetRequires"; |  | ||||||
| 	case kActivate: return "kActivate"; | 	case kActivate: return "kActivate"; | ||||||
| 	case kExecute: return "kExecute"; | 	case kExecute: return "kExecute"; | ||||||
| 	case kKill: return "kKill"; | 	case kKill: return "kKill"; | ||||||
| @@ -1565,7 +1563,7 @@ void tf_task_activate(tf_task_t* task) | |||||||
| 		JS_SetPropertyStr(context, global, "TlsContext", tf_tls_context_register(context)); | 		JS_SetPropertyStr(context, global, "TlsContext", tf_tls_context_register(context)); | ||||||
| 		tf_file_register(context); | 		tf_file_register(context); | ||||||
|  |  | ||||||
| 		task->_ssb = tf_ssb_create(&task->_loop, task->_context, task->_db, *task->_secrets_path ? task->_secrets_path : NULL); | 		task->_ssb = tf_ssb_create(&task->_loop, task->_context, task->_db); | ||||||
| 		tf_ssb_set_trace(task->_ssb, task->_trace); | 		tf_ssb_set_trace(task->_ssb, task->_trace); | ||||||
| 		tf_ssb_register(context, task->_ssb); | 		tf_ssb_register(context, task->_ssb); | ||||||
|  |  | ||||||
| @@ -1786,11 +1784,6 @@ void tf_task_set_db_path(tf_task_t* task, const char* db_path) | |||||||
| 	snprintf(task->_db_path, sizeof(task->_db_path), "%s", db_path); | 	snprintf(task->_db_path, sizeof(task->_db_path), "%s", db_path); | ||||||
| } | } | ||||||
|  |  | ||||||
| void tf_task_set_secrets_path(tf_task_t* task, const char* secrets_path) |  | ||||||
| { |  | ||||||
| 	snprintf(task->_secrets_path, sizeof(task->_secrets_path), "%s", secrets_path); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void tf_task_set_args(tf_task_t* task, const char* args) | void tf_task_set_args(tf_task_t* task, const char* args) | ||||||
| { | { | ||||||
| 	task->_args = args; | 	task->_args = args; | ||||||
|   | |||||||
| @@ -24,7 +24,6 @@ typedef enum _tf_task_message_t { | |||||||
| 	kInvokeExport, | 	kInvokeExport, | ||||||
| 	kReleaseExport, | 	kReleaseExport, | ||||||
| 	kReleaseImport, | 	kReleaseImport, | ||||||
| 	kSetRequires, |  | ||||||
| 	kActivate, | 	kActivate, | ||||||
| 	kExecute, | 	kExecute, | ||||||
| 	kKill, | 	kKill, | ||||||
| @@ -42,7 +41,6 @@ void tf_task_set_ssb_port(tf_task_t* task, int port); | |||||||
| void tf_task_set_http_port(tf_task_t* task, int port); | void tf_task_set_http_port(tf_task_t* task, int port); | ||||||
| void tf_task_set_https_port(tf_task_t* task, int port); | void tf_task_set_https_port(tf_task_t* task, int port); | ||||||
| void tf_task_set_db_path(tf_task_t* task, const char* path); | void tf_task_set_db_path(tf_task_t* task, const char* path); | ||||||
| void tf_task_set_secrets_path(tf_task_t* task, const char* path); |  | ||||||
| void tf_task_set_args(tf_task_t* task, const char* args); | void tf_task_set_args(tf_task_t* task, const char* args); | ||||||
| void tf_task_activate(tf_task_t* task); | void tf_task_activate(tf_task_t* task); | ||||||
| void tf_task_run(tf_task_t* task); | void tf_task_run(tf_task_t* task); | ||||||
|   | |||||||
| @@ -52,7 +52,6 @@ static JSValue _taskstub_activate(JSContext* context, JSValueConst this_val, int | |||||||
| static JSValue _taskstub_execute(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | static JSValue _taskstub_execute(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | ||||||
| static JSValue _taskstub_setImports(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | static JSValue _taskstub_setImports(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | ||||||
| static JSValue _taskstub_getExports(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | static JSValue _taskstub_getExports(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | ||||||
| static JSValue _taskstub_setRequires(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); |  | ||||||
| static JSValue _taskstub_kill(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | static JSValue _taskstub_kill(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | ||||||
| static JSValue _taskstub_get_on_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | static JSValue _taskstub_get_on_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | ||||||
| static JSValue _taskstub_set_on_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | static JSValue _taskstub_set_on_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); | ||||||
| @@ -113,7 +112,6 @@ static JSValue _taskstub_create(JSContext* context, JSValueConst this_val, int a | |||||||
| 	JS_SetPropertyStr(context, taskObject, "execute", JS_NewCFunction(context, _taskstub_execute, "execute", 1)); | 	JS_SetPropertyStr(context, taskObject, "execute", JS_NewCFunction(context, _taskstub_execute, "execute", 1)); | ||||||
| 	JS_SetPropertyStr(context, taskObject, "setImports", JS_NewCFunction(context, _taskstub_setImports, "setImports", 1)); | 	JS_SetPropertyStr(context, taskObject, "setImports", JS_NewCFunction(context, _taskstub_setImports, "setImports", 1)); | ||||||
| 	JS_SetPropertyStr(context, taskObject, "getExports", JS_NewCFunction(context, _taskstub_getExports, "getExports", 0)); | 	JS_SetPropertyStr(context, taskObject, "getExports", JS_NewCFunction(context, _taskstub_getExports, "getExports", 0)); | ||||||
| 	JS_SetPropertyStr(context, taskObject, "setRequires", JS_NewCFunction(context, _taskstub_setRequires, "setRequires", 1)); |  | ||||||
| 	JS_SetPropertyStr(context, taskObject, "kill", JS_NewCFunction(context, _taskstub_kill, "kill", 0)); | 	JS_SetPropertyStr(context, taskObject, "kill", JS_NewCFunction(context, _taskstub_kill, "kill", 0)); | ||||||
| 	JS_SetPropertyStr(context, taskObject, "loadFile", JS_NewCFunction(context, _taskstub_loadFile, "loadFile", 1)); | 	JS_SetPropertyStr(context, taskObject, "loadFile", JS_NewCFunction(context, _taskstub_loadFile, "loadFile", 1)); | ||||||
|  |  | ||||||
| @@ -328,17 +326,6 @@ static JSValue _taskstub_setImports(JSContext* context, JSValueConst this_val, i | |||||||
| 	return JS_UNDEFINED; | 	return JS_UNDEFINED; | ||||||
| } | } | ||||||
|  |  | ||||||
| static JSValue _taskstub_setRequires(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) |  | ||||||
| { |  | ||||||
| 	tf_taskstub_t* stub = JS_GetOpaque(this_val, _classId); |  | ||||||
| 	void* buffer; |  | ||||||
| 	size_t size; |  | ||||||
| 	tf_serialize_store(tf_task_get(context), stub, &buffer, &size, argv[0]); |  | ||||||
| 	tf_packetstream_send(stub->_stream, kSetRequires, (char*)buffer, size); |  | ||||||
| 	tf_free(buffer); |  | ||||||
| 	return JS_UNDEFINED; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static JSValue _taskstub_loadFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) | static JSValue _taskstub_loadFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) | ||||||
| { | { | ||||||
| 	tf_taskstub_t* stub = JS_GetOpaque(this_val, _classId); | 	tf_taskstub_t* stub = JS_GetOpaque(this_val, _classId); | ||||||
|   | |||||||
							
								
								
									
										44
									
								
								src/tests.c
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								src/tests.c
									
									
									
									
									
								
							| @@ -22,7 +22,7 @@ static void _test_nop(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	(void)result; | 	(void)result; | ||||||
| @@ -53,7 +53,7 @@ static void _test_child(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	(void)result; | 	(void)result; | ||||||
| @@ -95,7 +95,7 @@ static void _test_promise(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	(void)result; | 	(void)result; | ||||||
| @@ -141,7 +141,7 @@ static void _test_promise_remote_throw(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	(void)result; | 	(void)result; | ||||||
| @@ -189,7 +189,7 @@ static void _test_promise_remote_reject(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	(void)result; | 	(void)result; | ||||||
| @@ -235,7 +235,7 @@ static void _test_database(const tf_test_options_t* options) | |||||||
| 	unlink("out/testdb.sqlite"); | 	unlink("out/testdb.sqlite"); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=out/testdb.sqlite -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: --db-path=out/testdb.sqlite -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -256,7 +256,7 @@ static void _test_this(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -289,7 +289,7 @@ static void _test_await(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -325,14 +325,14 @@ static void _test_import(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| 	assert(WIFEXITED(result)); | 	assert(WIFEXITED(result)); | ||||||
| 	assert(WEXITSTATUS(result) == 0); | 	assert(WEXITSTATUS(result) == 0); | ||||||
|  |  | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/bad.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/bad.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	result = system(command); | 	result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -355,7 +355,7 @@ static void _test_exit(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -375,7 +375,7 @@ static void _test_icu(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -427,7 +427,7 @@ static void _test_uint8array(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -453,14 +453,14 @@ static void _test_socket(const tf_test_options_t* options) | |||||||
| 		"print('noDelay', s.noDelay);\n" | 		"print('noDelay', s.noDelay);\n" | ||||||
| 		"s.noDelay = true;\n" | 		"s.noDelay = true;\n" | ||||||
| 		"s.connect('www.unprompted.com', 80).then(function() {\n" | 		"s.connect('www.unprompted.com', 80).then(function() {\n" | ||||||
| 		"	print('connected', s.isConnected);\n" | 		"	print('connected', 'www.unprompted.com', 80, s.isConnected);\n" | ||||||
| 		"	print(s.peerName);\n" | 		"	print(s.peerName);\n" | ||||||
| 		"	s.read(function(data) {\n" | 		"	s.read(function(data) {\n" | ||||||
| 		"		print('read', data ? data.length : null);\n" | 		"		print('read', data ? data.length : null);\n" | ||||||
| 		"	});\n" | 		"	});\n" | ||||||
| 		"	s.write('GET / HTTP/1.0\\r\\n\\r\\n');\n" | 		"	s.write('GET / HTTP/1.0\\r\\n\\r\\n');\n" | ||||||
| 		"}).then(function() {\n" | 		"}).then(function(e) {\n" | ||||||
| 		"	print('closed');\n" | 		"	print('closed 1');\n" | ||||||
| 		"});\n" | 		"});\n" | ||||||
| 		"\n" | 		"\n" | ||||||
| 		"var s2 = new Socket();\n" | 		"var s2 = new Socket();\n" | ||||||
| @@ -473,7 +473,7 @@ static void _test_socket(const tf_test_options_t* options) | |||||||
| 		"print('noDelay', s2.noDelay);\n" | 		"print('noDelay', s2.noDelay);\n" | ||||||
| 		"s2.noDelay = true;\n" | 		"s2.noDelay = true;\n" | ||||||
| 		"s2.connect('www.unprompted.com', 443).then(function() {\n" | 		"s2.connect('www.unprompted.com', 443).then(function() {\n" | ||||||
| 		"	print('connected');\n" | 		"	print('connected', 'www.unprompted.com', 443);\n" | ||||||
| 		"	s2.read(function(data) {\n" | 		"	s2.read(function(data) {\n" | ||||||
| 		"		print('read', data ? data.length : null);\n" | 		"		print('read', data ? data.length : null);\n" | ||||||
| 		"	});\n" | 		"	});\n" | ||||||
| @@ -498,7 +498,7 @@ static void _test_socket(const tf_test_options_t* options) | |||||||
| 		"print('noDelay', s3.noDelay);\n" | 		"print('noDelay', s3.noDelay);\n" | ||||||
| 		"s3.noDelay = true;\n" | 		"s3.noDelay = true;\n" | ||||||
| 		"s3.connect('0.0.0.0', 443).then(function() {\n" | 		"s3.connect('0.0.0.0', 443).then(function() {\n" | ||||||
| 		"	print('connected');\n" | 		"	print('connected', '0.0.0.0', 443);\n" | ||||||
| 		"	s3.read(function(data) {\n" | 		"	s3.read(function(data) {\n" | ||||||
| 		"		print('read', data ? data.length : null);\n" | 		"		print('read', data ? data.length : null);\n" | ||||||
| 		"	});\n" | 		"	});\n" | ||||||
| @@ -516,7 +516,7 @@ static void _test_socket(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -575,7 +575,7 @@ static void _test_file(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -607,7 +607,7 @@ static void _test_sign(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
| @@ -630,7 +630,7 @@ static void _test_b64(const tf_test_options_t* options) | |||||||
| 	fclose(file); | 	fclose(file); | ||||||
|  |  | ||||||
| 	char command[256]; | 	char command[256]; | ||||||
| 	snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path); | 	snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path); | ||||||
| 	printf("%s\n", command); | 	printf("%s\n", command); | ||||||
| 	int result = system(command); | 	int result = system(command); | ||||||
| 	printf("returned %d\n", WEXITSTATUS(result)); | 	printf("returned %d\n", WEXITSTATUS(result)); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user