update: add pool loaded variable for better sync operation

This commit is contained in:
ngn 2024-07-13 14:08:18 +03:00
parent 21b49651db
commit 0ae3ffd929
6 changed files with 30 additions and 8 deletions

View File

@ -86,10 +86,10 @@ bool lm_ctx_install(
bool lm_ctx_remove(
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callback, void *data); // removes a single package
bool lm_ctx_check(
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_check_callback_t callback, void *data); // checks a single package
bool lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data); // syncs all the pools
void lm_ctx_ping(lm_ctx_t *ctx, lm_ctx_ping_callback_t callback, void *data); // pings all the pools
bool lm_ctx_serve(lm_ctx_t *ctx, char *addr, uint8_t threads); // serves all the pools
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_check_callback_t callback, void *data); // checks a single package
size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data); // syncs all the pools
void lm_ctx_ping(lm_ctx_t *ctx, lm_ctx_ping_callback_t callback, void *data); // pings all the pools
bool lm_ctx_serve(lm_ctx_t *ctx, char *addr, uint8_t threads); // serves all the pools
/* ####################
## pool fucntions ##

View File

@ -46,6 +46,6 @@ typedef struct lm_pool {
lm_pool_path_t paths;
lm_url_t url;
lm_pkg_t *pkg;
bool available;
char *name;
bool available, loaded;
} lm_pool_t;

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-11 13:49+0300\n"
"POT-Creation-Date: 2024-07-13 14:04+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View File

@ -161,6 +161,13 @@ bool lm_ctx_serve(lm_ctx_t *ctx, char *addr, uint8_t threads){
continue;
}
if(!pool->loaded){
pdebug(__func__, "requested pool (%s) is not loaded, closing connection", pool->name);
lm_mptp_init(&packet, false, MPTP_S2C_BRUH, true);
lm_mptp_server_send(sock, &packet, &saddr);
continue;
}
lm_pool_thread_arg_t *arg = malloc(sizeof(lm_pool_thread_arg_t));
memcpy(&arg->addr, &saddr, sizeof(struct sockaddr));

View File

@ -25,13 +25,14 @@ bool __lm_ctx_sync_callback(char *path, size_t current, size_t total, void *data
return cbdata->callback(cbdata->ctx, cbdata->pool, cbdata->state, current, total, data);
}
bool lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data){
size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data){
struct __lm_ctx_sync_cb_data cbdata = {
.ctx = ctx,
.callback = callback,
.data = data,
};
lm_pool_t *cur = ctx->pools;
size_t loaded_count = 0;
bool status = false;
while(NULL != cur){
@ -61,6 +62,10 @@ bool lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback,
callback(ctx, cur, SYNC_INFO_SUCCESS, 0, 0, data);
else if(NULL != callback && !status)
callback(ctx, cur, SYNC_INFO_FAIL, 0, 0, data);
if(status)
cur->loaded = true;
status = false;
cur = cur->next;
}
@ -72,6 +77,9 @@ bool lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback,
cbdata.pool = cur;
cbdata.state = SYNC_DOWNLOADING_LIST;
if(!cur->loaded)
goto next_list;
if(lm_pool_path_is_empty(cur)){
pdebug(__func__, "(%s) failed to load list, pool paths are empty", cur->name);
goto next_list;
@ -95,6 +103,12 @@ bool lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback,
callback(ctx, cur, SYNC_LIST_SUCCESS, 0, 0, data);
else if(NULL != callback && !status)
callback(ctx, cur, SYNC_LIST_FAIL, 0, 0, data);
if(!status)
cur->loaded = false;
else
loaded_count++;
status = false;
cur = cur->next;
}

View File

@ -10,7 +10,8 @@ lm_pool_t *lm_pool_new(char *name, char *url) {
lm_pool_t *pool = malloc(sizeof(lm_pool_t));
bzero(pool, sizeof(lm_pool_t));
pool->available = false;
pool->available = true;
pool->loaded = false;
pool->name = name;
if (NULL != url && !lm_url_init(&pool->url, url)) {