From 98315cce738fbd1b57442641f7c0e3958142c9fd Mon Sep 17 00:00:00 2001 From: feiniks <36756310+feiniks@users.noreply.github.com> Date: Wed, 13 Mar 2024 19:38:44 +0800 Subject: [PATCH] Add option to build http server (#648) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add option to build httpserver * Add option to build libevhtp * Delete unused option --------- Co-authored-by: 杨赫然 --- common/fs-mgr.c | 10 ++-- common/merge-new.c | 2 + common/rpc-service.c | 10 ++++ configure.ac | 8 +++- server/access-file.c | 2 + server/access-file.h | 2 + server/http-server.c | 70 ++------------------------- server/http-server.h | 6 +-- server/index-blocks-mgr.c | 2 +- server/pack-dir.c | 2 + server/pack-dir.h | 2 + server/repo-mgr.c | 4 ++ server/seafile-session.c | 93 +++++++++++++++++++++++++++++++----- server/seafile-session.h | 7 +++ server/upload-file.c | 2 + server/upload-file.h | 2 + server/web-accesstoken-mgr.c | 4 +- server/zip-download-mgr.c | 5 +- server/zip-download-mgr.h | 3 ++ 19 files changed, 146 insertions(+), 90 deletions(-) diff --git a/common/fs-mgr.c b/common/fs-mgr.c index bb74809b..fe224afd 100644 --- a/common/fs-mgr.c +++ b/common/fs-mgr.c @@ -660,7 +660,7 @@ chunking_worker (gpointer vdata, gpointer user_data) if (chunk->result < 0) goto out; - idx = chunk->offset / seaf->http_server->fixed_block_size; + idx = chunk->offset / seaf->fixed_block_size; memcpy (data->blk_sha1s + idx * CHECKSUM_LENGTH, chunk->checksum, CHECKSUM_LENGTH); out: @@ -688,7 +688,7 @@ split_file_to_block (const char *repo_id, CDCDescriptor *chunk; int ret = 0; - n_blocks = (file_size + seaf->http_server->fixed_block_size - 1) / seaf->http_server->fixed_block_size; + n_blocks = (file_size + seaf->fixed_block_size - 1) / seaf->fixed_block_size; block_sha1s = g_new0 (uint8_t, n_blocks * CHECKSUM_LENGTH); if (!block_sha1s) { seaf_warning ("Failed to allocate block_sha1s.\n"); @@ -708,7 +708,7 @@ split_file_to_block (const char *repo_id, data.finished_tasks = finished_tasks; tpool = g_thread_pool_new (chunking_worker, &data, - seaf->http_server->max_indexing_threads, FALSE, NULL); + seaf->max_indexing_threads, FALSE, NULL); if (!tpool) { seaf_warning ("Failed to allocate thread pool\n"); ret = -1; @@ -719,7 +719,7 @@ split_file_to_block (const char *repo_id, guint64 len; guint64 left = (guint64)file_size; while (left > 0) { - len = ((left >= seaf->http_server->fixed_block_size) ? seaf->http_server->fixed_block_size : left); + len = ((left >= seaf->fixed_block_size) ? seaf->fixed_block_size : left); chunk = g_new0 (CDCDescriptor, 1); chunk->offset = offset; @@ -739,7 +739,7 @@ split_file_to_block (const char *repo_id, goto out; } if (indexed) - *indexed += seaf->http_server->fixed_block_size; + *indexed += seaf->fixed_block_size; if ((--n_pending) <= 0) { if (indexed) diff --git a/common/merge-new.c b/common/merge-new.c index a9edd585..ec97f0a4 100644 --- a/common/merge-new.c +++ b/common/merge-new.c @@ -1,3 +1,5 @@ +#include "common.h" + #include "seafile-session.h" #include "merge-new.h" #include "vc-common.h" diff --git a/common/rpc-service.c b/common/rpc-service.c index fc4b2f9d..239f2be6 100644 --- a/common/rpc-service.c +++ b/common/rpc-service.c @@ -1436,15 +1436,23 @@ seafile_web_query_access_token (const char *token, GError **error) char * seafile_query_zip_progress (const char *token, GError **error) { +#ifdef HAVE_EVHTP return zip_download_mgr_query_zip_progress (seaf->zip_download_mgr, token, error); +#else + return NULL; +#endif } int seafile_cancel_zip_task (const char *token, GError **error) { +#ifdef HAVE_EVHTP return zip_download_mgr_cancel_zip_task (seaf->zip_download_mgr, token); +#else + return 0; +#endif } int @@ -3751,7 +3759,9 @@ seafile_delete_repo_tokens_by_peer_id(const char *email, return -1; } +#ifdef HAVE_EVHTP seaf_http_server_invalidate_tokens(seaf->http_server, tokens); +#endif g_list_free_full (tokens, (GDestroyNotify)g_free); return 0; } diff --git a/configure.ac b/configure.ac index 93c445a3..d7acd854 100644 --- a/configure.ac +++ b/configure.ac @@ -91,10 +91,12 @@ AC_ARG_WITH(mysql, [MYSQL_CONFIG=$with_mysql], [MYSQL_CONFIG="default_mysql_config"]) +AC_ARG_ENABLE(httpserver, AC_HELP_STRING([--enable-httpserver], [enable httpserver]), + [compile_httpserver=$enableval],[compile_httpserver="yes"]) + AM_CONDITIONAL([COMPILE_TOOLS], [test "${compile_tools}" = "yes"]) AM_CONDITIONAL([COMPILE_PYTHON], [test "${compile_python}" = "yes"]) AM_CONDITIONAL([COMPILE_FUSE], [test "${compile_fuse}" = "yes"]) - AM_CONDITIONAL([WIN32], [test "$bwin32" = "true"]) AM_CONDITIONAL([MACOS], [test "$bmac" = "true"]) AM_CONDITIONAL([LINUX], [test "$blinux" = "true"]) @@ -260,6 +262,10 @@ if test "${compile_ldap}" = "yes"; then fi +if test "${compile_httpserver}" = "yes"; then + AC_DEFINE([HAVE_EVHTP], [1], [Define to 1 if httpserver is enabled.]) +fi + PKG_CHECK_MODULES(CURL, [libcurl >= $CURL_REQUIRED]) AC_SUBST(CURL_CFLAGS) AC_SUBST(CURL_LIBS) diff --git a/server/access-file.c b/server/access-file.c index 94927640..54b339bb 100644 --- a/server/access-file.c +++ b/server/access-file.c @@ -1,5 +1,6 @@ #include "common.h" +#ifdef HAVE_EVHTP #define DEBUG_FLAG SEAFILE_DEBUG_HTTP #include "log.h" @@ -1546,3 +1547,4 @@ access_file_init (evhtp_t *htp) return 0; } +#endif diff --git a/server/access-file.h b/server/access-file.h index 012e52ac..c89bb983 100644 --- a/server/access-file.h +++ b/server/access-file.h @@ -1,7 +1,9 @@ #ifndef ACCESS_FILE_H #define ACCESS_FILE_H +#ifdef HAVE_EVHTP int access_file_init (evhtp_t *htp); +#endif #endif diff --git a/server/http-server.c b/server/http-server.c index 79b9164d..77c137b6 100644 --- a/server/http-server.c +++ b/server/http-server.c @@ -1,5 +1,6 @@ #include "common.h" +#ifdef HAVE_EVHTP #include #include #include @@ -63,6 +64,7 @@ struct _HttpServer { evbase_t *evbase; evhtp_t *evhtp; + event_t *reap_timer; pthread_t thread_id; GHashTable *token_cache; @@ -74,8 +76,6 @@ struct _HttpServer { GHashTable *vir_repo_info_cache; pthread_mutex_t vir_repo_info_cache_lock; - event_t *reap_timer; - GThreadPool *compute_fs_obj_id_pool; GHashTable *fs_obj_ids; @@ -150,11 +150,7 @@ load_http_config (HttpServerStruct *htp_server, SeafileSession *session) char *host = NULL; int port = 0; int worker_threads; - int web_token_expire_time; - int fixed_block_size_mb; char *encoding; - int max_indexing_threads; - int max_index_processing_threads; char *cluster_shared_temp_file_mode = NULL; host = fileserver_config_get_string (session->config, HOST, &error); @@ -198,66 +194,6 @@ load_http_config (HttpServerStruct *htp_server, SeafileSession *session) } seaf_message ("fileserver: worker_threads = %d\n", htp_server->worker_threads); - fixed_block_size_mb = fileserver_config_get_integer (session->config, - "fixed_block_size", - &error); - if (error){ - htp_server->fixed_block_size = DEFAULT_FIXED_BLOCK_SIZE; - g_clear_error(&error); - } else { - if (fixed_block_size_mb <= 0) - htp_server->fixed_block_size = DEFAULT_FIXED_BLOCK_SIZE; - else - htp_server->fixed_block_size = fixed_block_size_mb * ((gint64)1 << 20); - } - seaf_message ("fileserver: fixed_block_size = %"G_GINT64_FORMAT"\n", - htp_server->fixed_block_size); - - web_token_expire_time = fileserver_config_get_integer (session->config, - "web_token_expire_time", - &error); - if (error){ - htp_server->web_token_expire_time = 3600; /* default 3600s */ - g_clear_error(&error); - } else { - if (web_token_expire_time <= 0) - htp_server->web_token_expire_time = 3600; /* default 3600s */ - else - htp_server->web_token_expire_time = web_token_expire_time; - } - seaf_message ("fileserver: web_token_expire_time = %d\n", - htp_server->web_token_expire_time); - - max_indexing_threads = fileserver_config_get_integer (session->config, - "max_indexing_threads", - &error); - if (error) { - htp_server->max_indexing_threads = DEFAULT_MAX_INDEXING_THREADS; - g_clear_error (&error); - } else { - if (max_indexing_threads <= 0) - htp_server->max_indexing_threads = DEFAULT_MAX_INDEXING_THREADS; - else - htp_server->max_indexing_threads = max_indexing_threads; - } - seaf_message ("fileserver: max_indexing_threads = %d\n", - htp_server->max_indexing_threads); - - max_index_processing_threads = fileserver_config_get_integer (session->config, - "max_index_processing_threads", - &error); - if (error) { - htp_server->max_index_processing_threads = DEFAULT_MAX_INDEX_PROCESSING_THREADS; - g_clear_error (&error); - } else { - if (max_index_processing_threads <= 0) - htp_server->max_index_processing_threads = DEFAULT_MAX_INDEX_PROCESSING_THREADS; - else - htp_server->max_index_processing_threads = max_index_processing_threads; - } - seaf_message ("fileserver: max_index_processing_threads= %d\n", - htp_server->max_index_processing_threads); - cluster_shared_temp_file_mode = fileserver_config_get_string (session->config, "cluster_shared_temp_file_mode", &error); @@ -3154,3 +3090,5 @@ seaf_http_server_invalidate_tokens (HttpServerStruct *htp_server, pthread_mutex_unlock (&htp_server->priv->token_cache_lock); return 0; } + +#endif diff --git a/server/http-server.h b/server/http-server.h index 3d725e4d..bcff4e56 100644 --- a/server/http-server.h +++ b/server/http-server.h @@ -1,6 +1,7 @@ #ifndef HTTP_SERVER_H #define HTTP_SERVER_H +#ifdef HAVE_EVHTP #include struct _SeafileSession; @@ -16,11 +17,7 @@ struct _HttpServerStruct { int bind_port; char *http_temp_dir; /* temp dir for file upload */ char *windows_encoding; - gint64 fixed_block_size; - int web_token_expire_time; - int max_indexing_threads; int worker_threads; - int max_index_processing_threads; int cluster_shared_temp_file_mode; }; @@ -38,5 +35,6 @@ seaf_http_server_invalidate_tokens (HttpServerStruct *htp_server, void send_statistic_msg (const char *repo_id, char *user, char *operation, guint64 bytes); +#endif #endif diff --git a/server/index-blocks-mgr.c b/server/index-blocks-mgr.c index e214678c..32cfbe60 100644 --- a/server/index-blocks-mgr.c +++ b/server/index-blocks-mgr.c @@ -74,7 +74,7 @@ index_blocks_mgr_new (SeafileSession *session) priv->idx_tpool = g_thread_pool_new (start_index_task, priv, - session->http_server->max_index_processing_threads, + session->max_index_processing_threads, FALSE, &error); if (!priv->idx_tpool) { if (error) { diff --git a/server/pack-dir.c b/server/pack-dir.c index 678458b2..df25d99d 100644 --- a/server/pack-dir.c +++ b/server/pack-dir.c @@ -1,4 +1,5 @@ #include "common.h" +#ifdef HAVE_EVHTP #define DEBUG_FLAG SEAFILE_DEBUG_HTTP #include "log.h" @@ -481,3 +482,4 @@ pack_files (const char *store_id, return ret; } +#endif diff --git a/server/pack-dir.h b/server/pack-dir.h index e925f9f3..04372171 100644 --- a/server/pack-dir.h +++ b/server/pack-dir.h @@ -1,5 +1,6 @@ #ifndef PACK_DIR_H #define PACK_DIR_H +#ifdef HAVE_EVHTP /* Pack a seafile directory to a zipped archive, saved in a temporary file. Return the path of this temporary file. @@ -23,5 +24,6 @@ pack_files (const char *store_id, SeafileCrypt *crypt, gboolean is_windows, Progress *progress); +#endif #endif diff --git a/server/repo-mgr.c b/server/repo-mgr.c index 84d4fe61..03acd42a 100644 --- a/server/repo-mgr.c +++ b/server/repo-mgr.c @@ -1553,7 +1553,9 @@ seaf_repo_manager_delete_token (SeafRepoManager *mgr, GList *tokens = NULL; tokens = g_list_append (tokens, g_strdup(token)); +#ifdef HAVE_EVHTP seaf_http_server_invalidate_tokens (seaf->http_server, tokens); +#endif g_list_free_full (tokens, (GDestroyNotify)g_free); return 0; @@ -1838,7 +1840,9 @@ seaf_repo_manager_delete_repo_tokens_by_email (SeafRepoManager *mgr, goto out; } +#ifdef HAVE_EVHTP seaf_http_server_invalidate_tokens (seaf->http_server, token_list); +#endif out: g_list_free_full (token_list, (GDestroyNotify)g_free); diff --git a/server/seafile-session.c b/server/seafile-session.c index bf586f5a..ee8c0751 100644 --- a/server/seafile-session.c +++ b/server/seafile-session.c @@ -30,6 +30,80 @@ #define DEFAULT_THREAD_POOL_SIZE 500 +#define DEFAULT_FIXED_BLOCK_SIZE ((gint64)1 << 23) /* 8MB */ + +static void +load_fileserver_config (SeafileSession *session) +{ + int web_token_expire_time; + int max_index_processing_threads; + int fixed_block_size_mb; + int max_indexing_threads; + + session->go_fileserver = g_key_file_get_boolean (session->config, + "fileserver", "use_go_fileserver", + NULL); + if (session->go_fileserver) { + char *type = NULL; + type = g_key_file_get_string (session->config, "database", "type", NULL); + if (!type || g_strcmp0 (type, "mysql") != 0) { + session->go_fileserver = FALSE; + } + g_free (type); + } + + web_token_expire_time = g_key_file_get_integer (session->config, + "fileserver", "web_token_expire_time", + NULL); + if (web_token_expire_time <= 0) { + session->web_token_expire_time = 3600; + } else { + session->web_token_expire_time = web_token_expire_time; + } + + seaf_message ("fileserver: web_token_expire_time = %d\n", + session->web_token_expire_time); + + max_index_processing_threads = g_key_file_get_integer (session->config, + "fileserver", "max_index_processing_threads", + NULL); + if (max_index_processing_threads <= 0) { + session->max_index_processing_threads = 3; + } else { + session->max_index_processing_threads = max_index_processing_threads; + } + + seaf_message ("fileserver: max_index_processing_threads= %d\n", + session->max_index_processing_threads); + + + fixed_block_size_mb = g_key_file_get_integer (session->config, + "fileserver", "fixed_block_size", + NULL); + if (fixed_block_size_mb <= 0){ + session->fixed_block_size = DEFAULT_FIXED_BLOCK_SIZE; + } else { + session->fixed_block_size = fixed_block_size_mb * ((gint64)1 << 20); + } + + seaf_message ("fileserver: fixed_block_size = %"G_GINT64_FORMAT"\n", + session->fixed_block_size); + + max_indexing_threads = g_key_file_get_integer (session->config, + "fileserver", "max_indexing_threads", + NULL); + if (max_indexing_threads <= 0) { + session->max_indexing_threads = 1; + } else { + session->max_indexing_threads = max_indexing_threads; + } + + seaf_message ("fileserver: max_indexing_threads = %d\n", + session->max_indexing_threads); + + return; +} + SeafileSession * seafile_session_new(const char *central_config_dir, const char *seafile_dir, @@ -115,17 +189,7 @@ seafile_session_new(const char *central_config_dir, "general", "cloud_mode", NULL); - session->go_fileserver = g_key_file_get_boolean (config, - "fileserver", "use_go_fileserver", - NULL); - if (session->go_fileserver) { - char *type = NULL; - type = g_key_file_get_string (config, "database", "type", NULL); - if (!type || g_strcmp0 (type, "mysql") != 0) { - session->go_fileserver = FALSE; - } - g_free (type); - } + load_fileserver_config (session); notif_enabled = g_key_file_get_boolean (config, "notification", "enabled", @@ -201,6 +265,7 @@ seafile_session_new(const char *central_config_dir, if (!session->mq_mgr) goto onerror; +#ifdef HAVE_EVHTP session->http_server = seaf_http_server_new (session); if (!session->http_server) goto onerror; @@ -208,6 +273,7 @@ seafile_session_new(const char *central_config_dir, session->zip_download_mgr = zip_download_mgr_new (); if (!session->zip_download_mgr) goto onerror; +#endif session->index_blocks_mgr = index_blocks_mgr_new (session); if (!session->index_blocks_mgr) @@ -324,10 +390,15 @@ seafile_session_start (SeafileSession *session) } if (!session->go_fileserver) { +#ifdef HAVE_EVHTP if (seaf_http_server_start (session->http_server) < 0) { seaf_warning ("Failed to start http server thread.\n"); return -1; } +#else + seaf_warning ("Failed to start http server thread, please use go fileserver.\n"); + return -1; +#endif } return 0; diff --git a/server/seafile-session.h b/server/seafile-session.h index 0aae960d..8b57093c 100644 --- a/server/seafile-session.h +++ b/server/seafile-session.h @@ -71,8 +71,10 @@ struct _SeafileSession { int cloud_mode; +#ifdef HAVE_EVHTP HttpServerStruct *http_server; ZipDownloadMgr *zip_download_mgr; +#endif IndexBlksMgr *index_blocks_mgr; gboolean create_tables; @@ -80,6 +82,11 @@ struct _SeafileSession { gboolean go_fileserver; + int web_token_expire_time; + int max_index_processing_threads; + gint64 fixed_block_size; + int max_indexing_threads; + // For notification server NotifManager *notif_mgr; char *private_key; diff --git a/server/upload-file.c b/server/upload-file.c index b3445f6a..7ba17656 100755 --- a/server/upload-file.c +++ b/server/upload-file.c @@ -1,5 +1,6 @@ #include "common.h" +#ifdef HAVE_EVHTP #define DEBUG_FLAG SEAFILE_DEBUG_HTTP #include "log.h" @@ -2702,3 +2703,4 @@ upload_file_init (evhtp_t *htp, const char *http_temp_dir) return 0; } +#endif diff --git a/server/upload-file.h b/server/upload-file.h index d2cac087..a048c5a8 100644 --- a/server/upload-file.h +++ b/server/upload-file.h @@ -1,7 +1,9 @@ #ifndef UPLOAD_FILE_H #define UPLOAD_FILE_H +#ifdef HAVE_EVHTP int upload_file_init (evhtp_t *evhtp, const char *http_temp_dir); +#endif #endif diff --git a/server/web-accesstoken-mgr.c b/server/web-accesstoken-mgr.c index 6f943f1b..d6504bd2 100644 --- a/server/web-accesstoken-mgr.c +++ b/server/web-accesstoken-mgr.c @@ -160,7 +160,7 @@ seaf_web_at_manager_get_access_token (SeafWebAccessTokenManager *mgr, pthread_mutex_lock (&mgr->priv->lock); t = gen_new_token (mgr->priv->access_token_hash); - expire = now + seaf->http_server->web_token_expire_time; + expire = now + seaf->web_token_expire_time; info = g_new0 (AccessInfo, 1); info->repo_id = g_strdup (repo_id); @@ -176,6 +176,7 @@ seaf_web_at_manager_get_access_token (SeafWebAccessTokenManager *mgr, pthread_mutex_unlock (&mgr->priv->lock); +#ifdef HAVE_EVHTP if (!seaf->go_fileserver) { if (strcmp(op, "download-dir") == 0 || strcmp(op, "download-multi") == 0 || @@ -202,6 +203,7 @@ seaf_web_at_manager_get_access_token (SeafWebAccessTokenManager *mgr, g_object_unref (webaccess); } } +#endif return t; } diff --git a/server/zip-download-mgr.c b/server/zip-download-mgr.c index 960daba3..30376ba5 100644 --- a/server/zip-download-mgr.c +++ b/server/zip-download-mgr.c @@ -1,7 +1,9 @@ +#include "common.h" + +#ifdef HAVE_EVHTP #include #include -#include "common.h" #include #include "utils.h" #include "log.h" @@ -651,3 +653,4 @@ zip_download_mgr_cancel_zip_task (ZipDownloadMgr *mgr, return 0; } +#endif diff --git a/server/zip-download-mgr.h b/server/zip-download-mgr.h index 4ac8a947..e11d7660 100644 --- a/server/zip-download-mgr.h +++ b/server/zip-download-mgr.h @@ -1,6 +1,8 @@ #ifndef ZIP_DOWNLOAD_MGR_H #define ZIP_DOWNLOAD_MGR_H +#ifdef HAVE_EVHTP + #include "seafile-object.h" struct ZipDownloadMgrPriv; @@ -33,5 +35,6 @@ zip_download_mgr_del_zip_progress (ZipDownloadMgr *mgr, int zip_download_mgr_cancel_zip_task (ZipDownloadMgr *mgr, const char *token); +#endif #endif