2 Commits

Author SHA1 Message Date
e55548b105 Fix Haiku.
Some checks failed
Build Tilde Friends / Build-All (push) Failing after 5m16s
2024-08-08 12:51:41 -04:00
cea3f7e33c Fix OpenBSD.
Some checks failed
Build Tilde Friends / Build-All (push) Failing after 4m50s
2024-08-08 12:40:33 -04:00
2 changed files with 24 additions and 22 deletions

View File

@ -34,7 +34,7 @@
#define CARES_TYPEOF_ARES_SSIZE_T ssize_t #define CARES_TYPEOF_ARES_SSIZE_T ssize_t
#endif #endif
#if !defined(__ANDROID__) && !defined(__APPLE__) && !defined(_WIN32) #if !defined(__ANDROID__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__OpenBSD__) && !defined(__HAIKU__)
#define GETSERVBYNAME_R_ARGS 6 #define GETSERVBYNAME_R_ARGS 6
#define GETSERVBYPORT_R_ARGS 6 #define GETSERVBYPORT_R_ARGS 6
#define HAVE_GETSERVBYNAME_R 1 #define HAVE_GETSERVBYNAME_R 1
@ -42,11 +42,18 @@
#define HAVE_PIPE2 1 #define HAVE_PIPE2 1
#endif #endif
#if !defined(__APPLE__) && !defined(_WIN32) #if defined(__OpenBSD__) || defined(__HAIKU__)
#define GETSERVBYNAME_R_ARGS 4
#define GETSERVBYPORT_R_ARGS 4
#endif
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(__OpenBSD__)
#define HAVE_MALLOC_H 1 #define HAVE_MALLOC_H 1
#if !defined(__HAIKU__)
#define HAVE_SYS_RANDOM_H 1
#define HAVE_EPOLL 1 #define HAVE_EPOLL 1
#define HAVE_SYS_EPOLL_H 1 #define HAVE_SYS_EPOLL_H 1
#define HAVE_SYS_RANDOM_H 1 #endif
#endif #endif
#if !defined(__WIN32) #if !defined(__WIN32)
@ -78,7 +85,9 @@
#define HAVE_GETENV 1 #define HAVE_GETENV 1
#define HAVE_GETHOSTNAME 1 #define HAVE_GETHOSTNAME 1
#define HAVE_GETNAMEINFO 1 #define HAVE_GETNAMEINFO 1
#if !defined(__HAIKU__)
#define HAVE_GETRANDOM 1 #define HAVE_GETRANDOM 1
#endif
#define HAVE_GETTIMEOFDAY 1 #define HAVE_GETTIMEOFDAY 1
#define HAVE_IF_INDEXTONAME 1 #define HAVE_IF_INDEXTONAME 1
#define HAVE_IF_NAMETOINDEX 1 #define HAVE_IF_NAMETOINDEX 1
@ -129,7 +138,9 @@
#define HAVE_IFADDRS_H 1 #define HAVE_IFADDRS_H 1
#define HAVE_UNISTD_H 1 #define HAVE_UNISTD_H 1
#define HAVE_WRITEV 1 #define HAVE_WRITEV 1
#if !defined(__HAIKU__)
#define HAVE_ARC4RANDOM_BUF 1 #define HAVE_ARC4RANDOM_BUF 1
#endif
#define HAVE_GETIFADDRS 1 #define HAVE_GETIFADDRS 1
#define HAVE_STAT 1 #define HAVE_STAT 1
#define CARES_RANDOM_FILE "/dev/urandom" #define CARES_RANDOM_FILE "/dev/urandom"

View File

@ -77,9 +77,6 @@ enum
k_tf_ssb_rpc_message_body_length_max = 1 * 1024 * 1024, k_tf_ssb_rpc_message_body_length_max = 1 * 1024 * 1024,
k_debug_close_message_count = 256, k_debug_close_message_count = 256,
k_debug_close_connection_count = 32, k_debug_close_connection_count = 32,
k_seed_expire_seconds = 10 * 60,
k_seed_check_interval_seconds = 5 * 50,
k_udp_discovery_expires_seconds = 10,
}; };
typedef struct _tf_ssb_broadcast_t tf_ssb_broadcast_t; typedef struct _tf_ssb_broadcast_t tf_ssb_broadcast_t;
@ -119,7 +116,6 @@ typedef struct _tf_ssb_broadcast_t
tf_ssb_broadcast_t* next; tf_ssb_broadcast_t* next;
time_t ctime; time_t ctime;
time_t mtime; time_t mtime;
time_t expires_at;
char host[256]; char host[256];
struct sockaddr_in addr; struct sockaddr_in addr;
tf_ssb_connection_t* tunnel_connection; tf_ssb_connection_t* tunnel_connection;
@ -266,7 +262,6 @@ typedef struct _tf_ssb_t
bool is_room; bool is_room;
char* room_name; char* room_name;
char seeds_host[256]; char seeds_host[256];
time_t last_seed_check;
tf_ssb_timer_t** timers; tf_ssb_timer_t** timers;
int timers_count; int timers_count;
@ -362,7 +357,7 @@ static JSClassID _connection_class_id;
static int s_connection_index; static int s_connection_index;
static int s_tunnel_index; static int s_tunnel_index;
static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broadcast, int expires_seconds); static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broadcast);
static void _tf_ssb_connection_client_send_hello(tf_ssb_connection_t* connection); static void _tf_ssb_connection_client_send_hello(tf_ssb_connection_t* connection);
static void _tf_ssb_connection_close(tf_ssb_connection_t* connection, const char* reason); static void _tf_ssb_connection_close(tf_ssb_connection_t* connection, const char* reason);
static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const char* reason); static void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const char* reason);
@ -2951,7 +2946,7 @@ static void _tf_ssb_update_seeds_after_work(tf_ssb_t* ssb, int status, void* use
tf_ssb_broadcast_t broadcast = { 0 }; tf_ssb_broadcast_t broadcast = { 0 };
if (_tf_ssb_parse_broadcast(seeds->seeds[i], &broadcast)) if (_tf_ssb_parse_broadcast(seeds->seeds[i], &broadcast))
{ {
_tf_ssb_add_broadcast(ssb, &broadcast, k_seed_expire_seconds); _tf_ssb_add_broadcast(ssb, &broadcast);
} }
tf_free(seeds->seeds[i]); tf_free(seeds->seeds[i]);
} }
@ -2976,12 +2971,11 @@ static void _tf_ssb_broadcast_timer(uv_timer_t* timer)
uv_free_interface_addresses(info, count); uv_free_interface_addresses(info, count);
} }
time_t now = time(NULL);
if (*ssb->seeds_host && now - ssb->last_seed_check > k_seed_check_interval_seconds)
{
seeds_t* seeds = tf_malloc(sizeof(seeds_t)); seeds_t* seeds = tf_malloc(sizeof(seeds_t));
*seeds = (seeds_t) { 0 }; *seeds = (seeds_t) { 0 };
ssb->last_seed_check = now;
if (*ssb->seeds_host)
{
tf_ssb_run_work(ssb, _tf_ssb_update_seeds_work, _tf_ssb_update_seeds_after_work, seeds); tf_ssb_run_work(ssb, _tf_ssb_update_seeds_work, _tf_ssb_update_seeds_after_work, seeds);
} }
} }
@ -3096,7 +3090,7 @@ static void _tf_ssb_notify_broadcasts_changed(tf_ssb_t* ssb)
} }
} }
static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broadcast, int expires_seconds) static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broadcast)
{ {
if (memcmp(broadcast->pub, ssb->pub, sizeof(ssb->pub)) == 0) if (memcmp(broadcast->pub, ssb->pub, sizeof(ssb->pub)) == 0)
{ {
@ -3110,7 +3104,6 @@ static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broad
if (node->tunnel_connection == broadcast->tunnel_connection && memcmp(node->pub, broadcast->pub, sizeof(node->pub)) == 0) if (node->tunnel_connection == broadcast->tunnel_connection && memcmp(node->pub, broadcast->pub, sizeof(node->pub)) == 0)
{ {
node->mtime = time(NULL); node->mtime = time(NULL);
node->expires_at = node->mtime + expires_seconds;
return; return;
} }
} }
@ -3123,7 +3116,6 @@ static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broad
node->addr.sin_addr.s_addr == broadcast->addr.sin_addr.s_addr && memcmp(node->pub, broadcast->pub, sizeof(node->pub)) == 0) node->addr.sin_addr.s_addr == broadcast->addr.sin_addr.s_addr && memcmp(node->pub, broadcast->pub, sizeof(node->pub)) == 0)
{ {
node->mtime = time(NULL); node->mtime = time(NULL);
node->expires_at = node->mtime + expires_seconds;
return; return;
} }
} }
@ -3140,7 +3132,6 @@ static void _tf_ssb_add_broadcast(tf_ssb_t* ssb, const tf_ssb_broadcast_t* broad
node->next = ssb->broadcasts; node->next = ssb->broadcasts;
node->ctime = time(NULL); node->ctime = time(NULL);
node->mtime = node->ctime; node->mtime = node->ctime;
node->expires_at = node->mtime + expires_seconds;
ssb->broadcasts = node; ssb->broadcasts = node;
ssb->broadcasts_count++; ssb->broadcasts_count++;
@ -3166,7 +3157,7 @@ static void _tf_ssb_on_broadcast_listener_recv(uv_udp_t* handle, ssize_t nread,
tf_ssb_broadcast_t broadcast = { 0 }; tf_ssb_broadcast_t broadcast = { 0 };
if (_tf_ssb_parse_broadcast(entry, &broadcast)) if (_tf_ssb_parse_broadcast(entry, &broadcast))
{ {
_tf_ssb_add_broadcast(ssb, &broadcast, k_udp_discovery_expires_seconds); _tf_ssb_add_broadcast(ssb, &broadcast);
} }
entry = strtok_r(NULL, k_delim, &state); entry = strtok_r(NULL, k_delim, &state);
} }
@ -3197,7 +3188,7 @@ static void _tf_ssb_broadcast_cleanup_timer(uv_timer_t* timer)
time_t now = time(NULL); time_t now = time(NULL);
for (tf_ssb_broadcast_t** it = &ssb->broadcasts; *it;) for (tf_ssb_broadcast_t** it = &ssb->broadcasts; *it;)
{ {
if (!(*it)->tunnel_connection && now > (*it)->expires_at) if (!(*it)->tunnel_connection && (*it)->mtime < now - 10)
{ {
tf_ssb_broadcast_t* node = *it; tf_ssb_broadcast_t* node = *it;
*it = node->next; *it = node->next;
@ -3613,7 +3604,7 @@ void tf_ssb_connection_add_room_attendant(tf_ssb_connection_t* connection, const
.tunnel_connection = connection, .tunnel_connection = connection,
}; };
tf_ssb_id_str_to_bin(broadcast.pub, id); tf_ssb_id_str_to_bin(broadcast.pub, id);
_tf_ssb_add_broadcast(connection->ssb, &broadcast, 0); _tf_ssb_add_broadcast(connection->ssb, &broadcast);
} }
void tf_ssb_connection_remove_room_attendant(tf_ssb_connection_t* connection, const char* id) void tf_ssb_connection_remove_room_attendant(tf_ssb_connection_t* connection, const char* id)