diff --git a/include/ctx.h b/include/ctx.h index 52032cd..af59eb6 100644 --- a/include/ctx.h +++ b/include/ctx.h @@ -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 ## diff --git a/include/types.h b/include/types.h index 313a04c..156ebe0 100644 --- a/include/types.h +++ b/include/types.h @@ -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; diff --git a/locale/tr/LC_MESSAGES/libmp.po b/locale/tr/LC_MESSAGES/libmp.po index 0b1b1d9..e20e5e5 100644 --- a/locale/tr/LC_MESSAGES/libmp.po +++ b/locale/tr/LC_MESSAGES/libmp.po @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/src/ctx/serve.c b/src/ctx/serve.c index a653a76..a88fb7c 100644 --- a/src/ctx/serve.c +++ b/src/ctx/serve.c @@ -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)); diff --git a/src/ctx/sync.c b/src/ctx/sync.c index 590f204..57f3f72 100644 --- a/src/ctx/sync.c +++ b/src/ctx/sync.c @@ -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; } diff --git a/src/pool/pool.c b/src/pool/pool.c index d937231..0c65127 100644 --- a/src/pool/pool.c +++ b/src/pool/pool.c @@ -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)) {