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
This commit is contained in:
Cory McWilliams 2021-12-20 17:00:25 +00:00
parent b15cf901ad
commit 8075bdfe99
3 changed files with 11 additions and 7 deletions

View File

@ -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);
}
});
});
});

View File

@ -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;

View File

@ -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];