From 6ff33191bba8d44076c18ce293c1aa6be7e8130a Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 8 Jan 2023 13:48:28 +0000 Subject: [PATCH] Try to make the tests not mingle with other instances. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4109 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.c | 36 ++++++++++++++++++++++-------------- src/ssb.h | 1 + src/task.c | 1 + 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/ssb.c b/src/ssb.c index ce82bdfa..35d7180b 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -1836,20 +1836,6 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, sqlite3* db) ssb->broadcast_timer.data = ssb; uv_timer_init(ssb->loop, &ssb->broadcast_timer); - ssb->broadcast_sender.data = ssb; - uv_udp_init(ssb->loop, &ssb->broadcast_sender); - struct sockaddr_in broadcast_from = { - .sin_family = AF_INET, - .sin_addr.s_addr = INADDR_ANY, - }; - uv_udp_bind(&ssb->broadcast_sender, (struct sockaddr*)&broadcast_from, 0); - uv_udp_set_broadcast(&ssb->broadcast_sender, 1); - - ssb->trace_timer.data = ssb; - uv_timer_init(ssb->loop, &ssb->trace_timer); - uv_timer_start(&ssb->trace_timer, _tf_ssb_trace_timer, 100, 100); - uv_unref((uv_handle_t*)&ssb->trace_timer); - if (!_tf_ssb_load_keys(ssb)) { printf("Generating a new keypair.\n"); @@ -2653,6 +2639,28 @@ void tf_ssb_broadcast_listener_start(tf_ssb_t* ssb, bool linger) uv_timer_start(&ssb->broadcast_cleanup_timer, _tf_ssb_broadcast_cleanup_timer, 2000, 2000); } +void tf_ssb_broadcast_sender_start(tf_ssb_t* ssb) +{ + if (ssb->broadcast_sender.data) + { + return; + } + + ssb->broadcast_sender.data = ssb; + uv_udp_init(ssb->loop, &ssb->broadcast_sender); + struct sockaddr_in broadcast_from = { + .sin_family = AF_INET, + .sin_addr.s_addr = INADDR_ANY, + }; + uv_udp_bind(&ssb->broadcast_sender, (struct sockaddr*)&broadcast_from, 0); + uv_udp_set_broadcast(&ssb->broadcast_sender, 1); + + ssb->trace_timer.data = ssb; + uv_timer_init(ssb->loop, &ssb->trace_timer); + uv_timer_start(&ssb->trace_timer, _tf_ssb_trace_timer, 100, 100); + uv_unref((uv_handle_t*)&ssb->trace_timer); +} + void tf_ssb_append_post(tf_ssb_t* ssb, const char* text) { JSValue obj = JS_NewObject(ssb->context); diff --git a/src/ssb.h b/src/ssb.h index 1b6d41f9..fdf660aa 100644 --- a/src/ssb.h +++ b/src/ssb.h @@ -83,6 +83,7 @@ void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message); void tf_ssb_append_post(tf_ssb_t* ssb, const char* text); void tf_ssb_broadcast_listener_start(tf_ssb_t* ssb, bool linger); +void tf_ssb_broadcast_sender_start(tf_ssb_t* ssb); void tf_ssb_run(tf_ssb_t* ssb); void tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const uint8_t* private_key, JSValue message); bool tf_ssb_whoami(tf_ssb_t* ssb, char* out_id, size_t out_id_size); diff --git a/src/task.c b/src/task.c index 8e6c1921..db564737 100644 --- a/src/task.c +++ b/src/task.c @@ -1563,6 +1563,7 @@ void tf_task_activate(tf_task_t* task) if (task->_ssb_port) { tf_ssb_broadcast_listener_start(task->_ssb, false); + tf_ssb_broadcast_sender_start(task->_ssb); tf_ssb_server_open(task->_ssb, task->_ssb_port); }