Expose stored connections to script, and only store connections that were explicitly requested.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4131 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-01-18 00:37:45 +00:00
parent 45a5202456
commit 0f11f497ed
5 changed files with 110 additions and 3 deletions

View File

@ -2388,6 +2388,9 @@ void tf_ssb_connect(tf_ssb_t* ssb, const char* host, int port, const uint8_t* ke
.port = port,
.req.data = connect,
};
char id[k_id_base64_len] = { 0 };
tf_ssb_id_bin_to_str(id, sizeof(id), key);
tf_ssb_connections_store(ssb->connections_tracker, host, port, id);
snprintf(connect->host, sizeof(connect->host), "%s", host);
memcpy(connect->key, key, k_id_bin_len);
int r = uv_getaddrinfo(ssb->loop, &connect->req, _tf_on_connect_getaddrinfo, host, NULL, &(struct addrinfo) { .ai_family = AF_INET });
@ -2639,9 +2642,8 @@ 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))
{
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);
}
printf("Received new broadcast: host=%s, pub=%s.\n", broadcast->host, key);
}
tf_ssb_broadcast_t* node = tf_malloc(sizeof(tf_ssb_broadcast_t));