From cbc21cfbe644536f9770e52a1cf200828f0cd609 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 14 Jan 2021 02:45:10 +0000 Subject: [PATCH] Don't connect to ourselves or duplicates. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3641 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ssb.c b/src/ssb.c index 72b2d4b6..9014fff2 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -1700,6 +1700,20 @@ static void _tf_on_connect_getaddrinfo(uv_getaddrinfo_t* addrinfo, int result, s void tf_ssb_connect(tf_ssb_t* ssb, const char* host, int port, const uint8_t* key) { + for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next) { + if (memcmp(connection->serverpub, key, k_id_bin_len) == 0) { + char id[k_id_base64_len]; + tf_ssb_id_bin_to_str(id, sizeof(id), key); + printf("Not connecting to %s:%d, because we are already connected to %s.", host, port, key); + return; + } else if (memcmp(key, ssb->pub, k_id_bin_len) == 0) { + char id[k_id_base64_len]; + tf_ssb_id_bin_to_str(id, sizeof(id), key); + printf("Not connecting to %s:%d, because they appear to be ourselves %s.", host, port, key); + return; + } + } + connect_t* connect = malloc(sizeof(connect_t)); *connect = (connect_t) { .ssb = ssb,