From 8075bdfe996e0b11121ddd34adb06e61e55c7e1a Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 20 Dec 2021 17:00:25 +0000 Subject: [PATCH] Avoid a message storm, and reduce log spam a bit. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3691 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/ssb.js | 10 +++++++--- src/ssb.c | 7 ++++--- src/ssb.js.c | 1 - 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/core/ssb.js b/core/ssb.js index 4b31cfa0..3bc8631c 100644 --- a/core/ssb.js +++ b/core/ssb.js @@ -176,10 +176,14 @@ ssb.addRpc(['createHistoryStream'], function(request) { 'SELECT previous, author, id, sequence, timestamp, hash, content, signature FROM messages WHERE author = ?1 AND sequence >= ?2 ORDER BY sequence', [id, seq ?? 0], sendMessage); - ssb.addEventListener('message', function(id) { + ssb.addEventListener('message', function(message_id) { ssb.sqlStream( 'SELECT previous, author, id, sequence, timestamp, hash, content, signature FROM messages WHERE id = ?1', - [id], - sendMessage); + [message_id], + function (row) { + if (row.author == id) { + sendMessage(row); + } + }); }); }); diff --git a/src/ssb.c b/src/ssb.c index eebabe00..367b6f4f 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -959,7 +959,7 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t } else { - const char* k_unsupported = "{\"message\": \"unsupported message\", \"name\": \"Error\", \"stack\": \"none\", \"args\": []}"; + const char* k_unsupported = "{\"message\": \"unsupported message\", \"name\": \"Error\", \"stack\": \"none\"}"; tf_ssb_connection_rpc_send(connection, k_ssb_rpc_flag_json | k_ssb_rpc_flag_end_error | (flags & k_ssb_rpc_flag_stream), -request_number, (const uint8_t*)k_unsupported, strlen(k_unsupported), NULL, NULL); } @@ -1868,7 +1868,6 @@ static void _tf_ssb_send_broadcast(tf_ssb_t* ssb, struct sockaddr_in* address) char message[512]; snprintf(message, sizeof(message), "net:%s:%d~shs:%s", address_str, ntohs(((struct sockaddr_in*)&server_addr)->sin_port), fullid); - printf("Broadcasting %s\n", message); uv_buf_t buf = { .base = message, .len = strlen(message) }; @@ -1935,6 +1934,7 @@ void tf_ssb_server_open(tf_ssb_t* ssb, int port) return; } + printf("Starting broadcasts.\n"); uv_timer_start(&ssb->broadcast_timer, _tf_ssb_broadcast_timer, 2000, 2000); } @@ -1946,6 +1946,7 @@ void tf_ssb_server_close(tf_ssb_t* ssb) } uv_timer_stop(&ssb->broadcast_timer); + printf("Stopped broadcasts.\n"); } bool tf_ssb_whoami(tf_ssb_t* ssb, char* out_id, size_t out_id_size) @@ -2034,6 +2035,7 @@ static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broad tf_ssb_connections_store(ssb->connections_tracker, broadcast->host, ntohs(broadcast->addr.sin_port), key); } + printf("Received new broadcast: host=%s, pub=%s.\n", broadcast->host, key); tf_ssb_broadcast_t* node = malloc(sizeof(tf_ssb_broadcast_t)); *node = *broadcast; node->next = ssb->broadcasts; @@ -2054,7 +2056,6 @@ static void _tf_ssb_on_broadcast_listener_recv(uv_udp_t* handle, ssize_t nread, tf_ssb_t* ssb = handle->data; ((char*)buf->base)[nread] = '\0'; - printf("RECV %d %.*s\n", (int)nread, (int)nread, buf->base); const char* k_delim = ";"; char* state = NULL; diff --git a/src/ssb.js.c b/src/ssb.js.c index f5a057fc..9775c828 100644 --- a/src/ssb.js.c +++ b/src/ssb.js.c @@ -19,7 +19,6 @@ static JSClassID _tf_ssb_classId; static JSValue _tf_ssb_whoami(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) { tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId); - printf("WHOAMI on %p\n", ssb); if (ssb) { char id[512];