forked from cory/tildefriends
Replace all printfs with tf_printf, which redirects to android logging. Change into the files directory so that sqlite can do its thing. Getting closer.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4203 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
75
src/ssb.c
75
src/ssb.c
@ -1,5 +1,6 @@
|
||||
#include "ssb.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "mem.h"
|
||||
#include "ssb.connections.h"
|
||||
#include "ssb.db.h"
|
||||
@ -396,7 +397,7 @@ static void _tf_ssb_connection_close(tf_ssb_connection_t* connection, const char
|
||||
else if (connection->state == k_tf_ssb_state_verified ||
|
||||
connection->state == k_tf_ssb_state_server_verified)
|
||||
{
|
||||
printf("Connection %s %p is closing: %s.\n", connection->name, connection, reason);
|
||||
tf_printf("Connection %s %p is closing: %s.\n", connection->name, connection, reason);
|
||||
_tf_ssb_add_debug_close(connection->ssb, connection, reason);
|
||||
connection->state = k_tf_ssb_state_closing;
|
||||
_tf_ssb_connection_send_close(connection);
|
||||
@ -707,7 +708,7 @@ void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags,
|
||||
memcpy(combined + 1 + 2 * sizeof(uint32_t), message, size);
|
||||
if (connection->ssb->verbose)
|
||||
{
|
||||
printf(MAGENTA "%s RPC SEND" RESET " flags=%x RN=%d: [%zd B] %.*s\n", connection->name, flags, request_number, size, (flags & k_ssb_rpc_mask_type) == k_ssb_rpc_flag_binary ? 0 : (int)size, message);
|
||||
tf_printf(MAGENTA "%s RPC SEND" RESET " flags=%x RN=%d: [%zd B] %.*s\n", connection->name, flags, request_number, size, (flags & k_ssb_rpc_mask_type) == k_ssb_rpc_flag_binary ? 0 : (int)size, message);
|
||||
}
|
||||
_tf_ssb_connection_add_debug_message(connection, true, flags, request_number, message, size);
|
||||
_tf_ssb_connection_box_stream_send(connection, combined, 1 + 2 * sizeof(uint32_t) + size);
|
||||
@ -911,23 +912,23 @@ static bool _tf_ssb_verify_and_strip_signature_internal(JSContext* context, JSVa
|
||||
verified = r == 0;
|
||||
if (!verified)
|
||||
{
|
||||
//printf("crypto_sign_verify_detached fail (r=%d)\n", r);
|
||||
//tf_printf("crypto_sign_verify_detached fail (r=%d)\n", r);
|
||||
if (false)
|
||||
{
|
||||
printf("val=[%.*s]\n", (int)strlen(sigstr), sigstr);
|
||||
printf("sig=%.*s\n", (int)(sigkind - str), str);
|
||||
printf("public key=%.*s\n", (int)(type - author_id), author_id);
|
||||
tf_printf("val=[%.*s]\n", (int)strlen(sigstr), sigstr);
|
||||
tf_printf("sig=%.*s\n", (int)(sigkind - str), str);
|
||||
tf_printf("public key=%.*s\n", (int)(type - author_id), author_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("base64 decode sig fail [%.*s]\n", (int)(sigkind - str), str);
|
||||
tf_printf("base64 decode sig fail [%.*s]\n", (int)(sigkind - str), str);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("base64 decode author[%.*s] fail (%d)\n", (int)(type - author_id), author_id, r);
|
||||
tf_printf("base64 decode author[%.*s] fail (%d)\n", (int)(type - author_id), author_id, r);
|
||||
}
|
||||
|
||||
JS_FreeCString(context, author);
|
||||
@ -1435,7 +1436,7 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
|
||||
tf_ssb_id_bin_to_str(id, sizeof(id), connection->serverpub);
|
||||
if (connection->ssb->verbose)
|
||||
{
|
||||
printf(CYAN "%s RPC RECV" RESET " from %s flags=%x RN=%d: [%zd B] %.*s\n", connection->name, id, flags, request_number, size, (int)size, message);
|
||||
tf_printf(CYAN "%s RPC RECV" RESET " from %s flags=%x RN=%d: [%zd B] %.*s\n", connection->name, id, flags, request_number, size, (int)size, message);
|
||||
}
|
||||
JSContext* context = connection->ssb->context;
|
||||
JSValue val = JS_ParseJSON(context, (const char*)message, size, NULL);
|
||||
@ -1480,7 +1481,7 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to parse %.*s\n", (int)size, message);
|
||||
tf_printf("Failed to parse %.*s\n", (int)size, message);
|
||||
}
|
||||
|
||||
JS_FreeValue(context, val);
|
||||
@ -1489,7 +1490,7 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
|
||||
{
|
||||
if (connection->ssb->verbose)
|
||||
{
|
||||
printf(CYAN "%s RPC RECV" RESET " flags=%x RN=%d: %zd bytes\n", connection->name, flags, request_number, size);
|
||||
tf_printf(CYAN "%s RPC RECV" RESET " flags=%x RN=%d: %zd bytes\n", connection->name, flags, request_number, size);
|
||||
}
|
||||
tf_ssb_rpc_callback_t* callback = NULL;
|
||||
void* user_data = NULL;
|
||||
@ -1506,7 +1507,7 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No request callback for %p %d\n", connection, -request_number);
|
||||
tf_printf("No request callback for %p %d\n", connection, -request_number);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1674,12 +1675,12 @@ void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const ui
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("message not stored.\n");
|
||||
tf_printf("message not stored.\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to verify message signature.\n");
|
||||
tf_printf("Failed to verify message signature.\n");
|
||||
}
|
||||
|
||||
JS_FreeValue(context, root);
|
||||
@ -1950,7 +1951,7 @@ static void _tf_ssb_connection_on_connect(uv_connect_t* connect, int status)
|
||||
int result = uv_read_start(connect->handle, _tf_ssb_connection_on_tcp_alloc, _tf_ssb_connection_on_tcp_recv);
|
||||
if (result)
|
||||
{
|
||||
printf("uv_read_start => %s\n", uv_strerror(status));
|
||||
tf_printf("uv_read_start => %s\n", uv_strerror(status));
|
||||
_tf_ssb_connection_close(connection, "uv_read_start failed");
|
||||
}
|
||||
else
|
||||
@ -2082,7 +2083,7 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path
|
||||
|
||||
if (!_tf_ssb_load_keys(ssb))
|
||||
{
|
||||
printf("Generating a new keypair.\n");
|
||||
tf_printf("Generating a new keypair.\n");
|
||||
tf_ssb_db_identity_create(ssb, ":admin", ssb->pub, ssb->priv);
|
||||
}
|
||||
|
||||
@ -2339,14 +2340,14 @@ tf_ssb_connection_t* tf_ssb_connection_create(tf_ssb_t* ssb, const char* host, c
|
||||
{
|
||||
char id[k_id_base64_len];
|
||||
tf_ssb_id_bin_to_str(id, sizeof(id), public_key);
|
||||
printf("Not connecting to %s:%d, because we are already connected to %s (state = %d).\n", host, ntohs(addr->sin_port), id, connection->state);
|
||||
tf_printf("Not connecting to %s:%d, because we are already connected to %s (state = %d).\n", host, ntohs(addr->sin_port), id, connection->state);
|
||||
return NULL;
|
||||
}
|
||||
else if (memcmp(ssb->pub, public_key, k_id_bin_len) == 0)
|
||||
{
|
||||
char id[k_id_base64_len];
|
||||
tf_ssb_id_bin_to_str(id, sizeof(id), public_key);
|
||||
printf("Not connecting to %s:%d, because they appear to be ourselves %s.\n", host, ntohs(addr->sin_port), id);
|
||||
tf_printf("Not connecting to %s:%d, because they appear to be ourselves %s.\n", host, ntohs(addr->sin_port), id);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -2379,7 +2380,7 @@ tf_ssb_connection_t* tf_ssb_connection_create(tf_ssb_t* ssb, const char* host, c
|
||||
int result = uv_tcp_connect(&connection->connect, &connection->tcp, (const struct sockaddr*)addr, _tf_ssb_connection_on_connect);
|
||||
if (result)
|
||||
{
|
||||
printf("uv_tcp_connect(%s): %s\n", host, uv_strerror(result));
|
||||
tf_printf("uv_tcp_connect(%s): %s\n", host, uv_strerror(result));
|
||||
connection->connect.data = NULL;
|
||||
_tf_ssb_connection_destroy(connection, "connect failed");
|
||||
}
|
||||
@ -2478,7 +2479,7 @@ static void _tf_on_connect_getaddrinfo(uv_getaddrinfo_t* addrinfo, int result, s
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("getaddrinfo => %s\n", uv_strerror(result));
|
||||
tf_printf("getaddrinfo => %s\n", uv_strerror(result));
|
||||
}
|
||||
tf_free(connect);
|
||||
uv_freeaddrinfo(info);
|
||||
@ -2501,7 +2502,7 @@ void tf_ssb_connect(tf_ssb_t* ssb, const char* host, int port, const uint8_t* ke
|
||||
int r = uv_getaddrinfo(ssb->loop, &connect->req, _tf_on_connect_getaddrinfo, host, NULL, &(struct addrinfo) { .ai_family = AF_INET });
|
||||
if (r < 0)
|
||||
{
|
||||
printf("uv_getaddrinfo: %s\n", uv_strerror(r));
|
||||
tf_printf("uv_getaddrinfo: %s\n", uv_strerror(r));
|
||||
tf_free(connect);
|
||||
}
|
||||
}
|
||||
@ -2516,7 +2517,7 @@ static void _tf_ssb_on_connection(uv_stream_t* stream, int status)
|
||||
tf_ssb_t* ssb = stream->data;
|
||||
if (status < 0)
|
||||
{
|
||||
printf("uv_listen failed: %s\n", uv_strerror(status));
|
||||
tf_printf("uv_listen failed: %s\n", uv_strerror(status));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2560,13 +2561,13 @@ static void _tf_ssb_send_broadcast(tf_ssb_t* ssb, struct sockaddr_in* address)
|
||||
if (uv_tcp_getsockname(&ssb->server, &server_addr, &len) != 0 ||
|
||||
server_addr.sa_family != AF_INET)
|
||||
{
|
||||
printf("Unable to get server's address.\n");
|
||||
tf_printf("Unable to get server's address.\n");
|
||||
}
|
||||
|
||||
char address_str[256];
|
||||
if (uv_ip4_name(address, address_str, sizeof(address_str)) != 0)
|
||||
{
|
||||
printf("Unable to convert address to string.\n");
|
||||
tf_printf("Unable to convert address to string.\n");
|
||||
}
|
||||
|
||||
char fullid[k_id_base64_len];
|
||||
@ -2584,7 +2585,7 @@ static void _tf_ssb_send_broadcast(tf_ssb_t* ssb, struct sockaddr_in* address)
|
||||
int r = uv_udp_try_send(&ssb->broadcast_sender, &buf, 1, (struct sockaddr*)&broadcast_addr);
|
||||
if (r < 0)
|
||||
{
|
||||
printf("failed to send broadcast %d: %s\n", r, uv_strerror(r));
|
||||
tf_printf("failed to send broadcast %d: %s\n", r, uv_strerror(r));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2611,14 +2612,14 @@ void tf_ssb_server_open(tf_ssb_t* ssb, int port)
|
||||
{
|
||||
if (ssb->server.data)
|
||||
{
|
||||
printf("Already listening.\n");
|
||||
tf_printf("Already listening.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ssb->server.data = ssb;
|
||||
if (uv_tcp_init(ssb->loop, &ssb->server) != 0)
|
||||
{
|
||||
printf("uv_tcp_init failed\n");
|
||||
tf_printf("uv_tcp_init failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2628,19 +2629,19 @@ void tf_ssb_server_open(tf_ssb_t* ssb, int port)
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
if (uv_tcp_bind(&ssb->server, (struct sockaddr*)&addr, 0) != 0)
|
||||
{
|
||||
printf("uv_tcp_bind failed\n");
|
||||
tf_printf("uv_tcp_bind failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int status = uv_listen((uv_stream_t*)&ssb->server, SOMAXCONN, _tf_ssb_on_connection);
|
||||
if (status != 0)
|
||||
{
|
||||
printf("uv_listen failed: %s\n", uv_strerror(status));
|
||||
tf_printf("uv_listen failed: %s\n", uv_strerror(status));
|
||||
/* TODO: cleanup */
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Starting broadcasts.\n");
|
||||
tf_printf("Starting broadcasts.\n");
|
||||
uv_timer_start(&ssb->broadcast_timer, _tf_ssb_broadcast_timer, 2000, 2000);
|
||||
}
|
||||
|
||||
@ -2652,7 +2653,7 @@ void tf_ssb_server_close(tf_ssb_t* ssb)
|
||||
}
|
||||
|
||||
uv_timer_stop(&ssb->broadcast_timer);
|
||||
printf("Stopped broadcasts.\n");
|
||||
tf_printf("Stopped broadcasts.\n");
|
||||
}
|
||||
|
||||
bool tf_ssb_whoami(tf_ssb_t* ssb, char* out_id, size_t out_id_size)
|
||||
@ -2674,7 +2675,7 @@ static bool _tf_ssb_parse_broadcast(const char* in_broadcast, tf_ssb_broadcast_t
|
||||
}
|
||||
else if (strncmp(in_broadcast, "ws:", 3) == 0)
|
||||
{
|
||||
printf("Unsupported broadcast: %s\n", in_broadcast);
|
||||
tf_printf("Unsupported broadcast: %s\n", in_broadcast);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -2688,7 +2689,7 @@ void tf_ssb_connect_str(tf_ssb_t* ssb, const char* address)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unable to parse: %s\n", address);
|
||||
tf_printf("Unable to parse: %s\n", address);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2749,7 +2750,7 @@ static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broad
|
||||
char key[k_id_base64_len];
|
||||
if (tf_ssb_id_bin_to_str(key, sizeof(key), broadcast->pub))
|
||||
{
|
||||
printf("Received new broadcast: host=%s, pub=%s.\n", broadcast->host, key);
|
||||
tf_printf("Received new broadcast: host=%s, pub=%s.\n", broadcast->host, key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2850,13 +2851,13 @@ void tf_ssb_broadcast_listener_start(tf_ssb_t* ssb, bool linger)
|
||||
int result = uv_udp_bind(&ssb->broadcast_listener, (const struct sockaddr*)&addr, UV_UDP_REUSEADDR);
|
||||
if (result != 0)
|
||||
{
|
||||
printf("bind: %s\n", uv_strerror(result));
|
||||
tf_printf("bind: %s\n", uv_strerror(result));
|
||||
}
|
||||
|
||||
result = uv_udp_recv_start(&ssb->broadcast_listener, _tf_ssb_on_broadcast_listener_alloc, _tf_ssb_on_broadcast_listener_recv);
|
||||
if (result != 0)
|
||||
{
|
||||
printf("uv_udp_recv_start: %s\n", uv_strerror(result));
|
||||
tf_printf("uv_udp_recv_start: %s\n", uv_strerror(result));
|
||||
}
|
||||
|
||||
if (!linger)
|
||||
@ -3354,7 +3355,7 @@ bool tf_ssb_verify_strip_and_store_message(tf_ssb_t* ssb, JSValue value)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("failed to verify message\n");
|
||||
tf_printf("failed to verify message\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user