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
This commit is contained in:
Cory McWilliams 2023-01-08 13:48:28 +00:00
parent 513eb88a53
commit 6ff33191bb
3 changed files with 24 additions and 14 deletions

View File

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

View File

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

View File

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